a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
MultipleTriplyIndexed.hpp
Go to the documentation of this file.
1/*
2 * MultipleTriplyIndexed.hpp
3 *
4 * Created on: Apr 7, 2012
5 * Author: Ben O'Leary (benjamin.oleary@gmail.com)
6 * Copyright 2012 Ben O'Leary
7 *
8 * This file is part of LesHouchesParserClasses, released under the
9 * GNU General Public License. Please see the accompanying
10 * README.LHPC_CPP.txt file for a full list of files, brief documentation
11 * on how to use these classes, and further details on the license.
12 */
13
14#ifndef MULTIPLETRIPLYINDEXED_HPP_
15#define MULTIPLETRIPLYINDEXED_HPP_
16
17#include <map>
18#include <list>
20
21namespace LHPC
22{
23 namespace SLHA
24 {
25 namespace InterpreterClass
26 {
27 // this template class interprets SLHA blocks that have a single int
28 // index with a single ValueClass value.
29 template< class ValueClass >
30 class MultipleTriplyIndexed : public IndexedInterpreter< ValueClass >
31 {
32 public:
34 virtual
36
37 std::list< ValueClass* >
39 std::pair< std::pair< int, int >, int > const& indexTriple );
40 /* this returns a std::list of pointers to the ValueClass instances
41 * mapped to by indexTriple.first & indexTriple.second. if there is no
42 * element at the sought indices, an empty std::list is returned.
43 */
44 std::list< ValueClass const* >
46 std::pair< std::pair< int, int >, int > const& indexTriple ) const;
47 // const version of above.
48 std::list< ValueClass* >
49 operator()( int const firstIndex,
50 int const secondIndex,
51 int const thirdIndex )
52 { return (*this)( std::make_pair( std::make_pair( firstIndex,
53 secondIndex ),
54 thirdIndex ) ); }
55 std::list< ValueClass const* >
56 operator()( int const firstIndex,
57 int const secondIndex,
58 int const thirdIndex ) const
59 { return (*this)( std::make_pair( std::make_pair( firstIndex,
60 secondIndex ),
61 thirdIndex ) ); }
62 std::multimap< std::pair< std::pair< int, int >, int >, ValueClass >&
64 std::multimap< std::pair< std::pair< int, int >, int >,
65 ValueClass > const&
66 getValueMap() const;
67 bool
69 std::pair< std::pair< int, int >, int > const& indexTriple ) const;
70 // this returns true if there is an entry at the sought indices.
71 bool
72 hasEntry( int const firstIndex,
73 int const secondIndex,
74 int const thirdIndex ) const
75 { return hasEntry( std::make_pair( std::make_pair( firstIndex,
76 secondIndex ),
77 thirdIndex ) ); }
78 virtual std::string const&
80 // see base version's description.
81 virtual void
83 // derived classes should clear their interpreted values.
84
85
86 protected:
87 typedef typename
88 std::multimap< std::pair< std::pair< int, int >, int >,
89 ValueClass >::const_iterator mapIterator;
90
91 std::multimap< std::pair< std::pair< int, int >, int >, ValueClass >
93 std::pair< std::pair< std::pair< int, int >, int >, ValueClass >
95
96 virtual void
98 };
99
100
101
102
103
104 template< class ValueClass >
105 inline
107 IndexedInterpreter< ValueClass >(),
108 valueMap(),
109 valueRecorder()
110 {
111 // just an initialization list.
112 }
113
114 template< class ValueClass >
115 inline
117 {
118 // does nothing.
119 }
120
121 template< class ValueClass >
122 inline std::list< ValueClass* >
124 std::pair< std::pair< int, int >, int > const& indexTriple )
125 /* this returns a std::list of pointers to the ValueClass instances
126 * mapped to by indexTriple.first & indexTriple.second. if there is no
127 * element at the sought indices, an empty std::list is returned.
128 */
129 {
130 std::list< ValueClass* > returnList;
131 std::pair< mapIterator, mapIterator >
132 rangeIterators( valueMap.equal_range( indexTriple ) );
133 while( rangeIterators.first != rangeIterators.second )
134 {
135 returnList.push_back( &(rangeIterators.first->second) );
136 ++(rangeIterators.first);
137 }
138 return returnList;
139 }
140
141 template< class ValueClass >
142 inline std::list< ValueClass const* >
144 std::pair< std::pair< int, int >, int > const& indexTriple ) const
145 // const version of above.
146 {
147 std::list< ValueClass const* > returnList;
148 std::pair< mapIterator, mapIterator >
149 rangeIterators( valueMap.equal_range( indexTriple ) );
150 while( rangeIterators.first != rangeIterators.second )
151 {
152 returnList.push_back( &(rangeIterators.first->second) );
153 ++(rangeIterators.first);
154 }
155 return returnList;
156 }
157
158 template< class ValueClass >
159 inline std::multimap< std::pair< std::pair< int, int >, int >,
160 ValueClass >&
162 {
163 return valueMap;
164 }
165
166 template< class ValueClass >
167 inline std::multimap< std::pair< std::pair< int, int >, int >,
168 ValueClass > const&
170 {
171 return valueMap;
172 }
173
174 template< class ValueClass >
175 inline bool
177 std::pair< std::pair< int, int >, int > const& indexTriple ) const
178 // this returns true if there is an entry at soughtIndex.
179 {
180 return ( 0 < valueMap.count( indexTriple ) );
181 }
182
183 template< class ValueClass >
184 inline std::string const&
186 // see base version's description.
187 {
188 this->stringInterpretation.clear();
189 mapIterator valueFinder( valueMap.begin() );
190 while( valueFinder != valueMap.end() )
191 {
192 this->indexPrintingVector[ 0 ] = valueFinder->first.first.first;
193 this->indexPrintingVector[ 1 ] = valueFinder->first.first.second;
194 this->indexPrintingVector[ 2 ] = valueFinder->first.second;
195 this->stringInterpretation.append( this->indicesToPrintingString() );
196 this->stringInterpretation.append( this->valueToPrintingString(
197 valueFinder->second ) );
198 /* negative particle codes can be avoided in any block, I think.
199 * well, the exact format is only specified for the MASS block, &
200 * in that case, negative particle codes can be avoided, since the
201 * charge-conjugate just has the same mass. if the charge-conjugate
202 * pair has a mass splitting, I think they are defined with 2
203 * separate codes. if negative codes end up here, it's not my
204 * fault...
205 */
206 this->stringInterpretation.append( "\n" );
207 ++valueFinder;
208 }
209 return this->stringInterpretation;
210 }
211
212 template< class ValueClass >
213 inline void
215 {
216 valueMap.clear();
217 }
218
219 template< class ValueClass >
220 inline void
222 {
223 for( int whichLine( this->currentStringBlock->getNumberOfBodyLines() );
224 0 < whichLine;
225 --whichLine )
226 {
227 this->currentWord.assign( BOL::StringParser::firstWordOf(
228 (*(this->currentStringBlock))[ whichLine ].first,
229 &(this->lineRemainderA),
231 if( !(this->currentWord.empty()) )
232 {
233 valueRecorder.first.first.first
234 = BOL::StringParser::stringToInt( this->currentWord );
235 this->currentWord.assign( BOL::StringParser::firstWordOf(
236 this->lineRemainderA,
237 &(this->lineRemainderB),
239 if( !(this->currentWord.empty()) )
240 {
241 valueRecorder.first.first.second
242 = BOL::StringParser::stringToInt( this->currentWord );
243 this->currentWord.assign( BOL::StringParser::firstWordOf(
244 this->lineRemainderB,
245 &(this->lineRemainderA),
247 if( !(this->currentWord.empty()) )
248 {
249 valueRecorder.first.second
250 = BOL::StringParser::stringToInt( this->currentWord );
251 valueRecorder.second
252 = this->stringToValue( BOL::StringParser::trimFromFrontAndBack(
253 this->lineRemainderA,
255 valueMap.insert( valueRecorder );
256 }
257 }
258 }
259 }
260 }
261
262 }
263
264 }
265
266}
267
268#endif /* MULTIPLETRIPLYINDEXED_HPP_ */
static std::string firstWordOf(std::string const &stringToParse, std::string *const remainderString=NULL, std::string const &separatorChars=whitespaceChars)
static std::string const whitespaceAndNewlineChars
static std::string trimFromFrontAndBack(std::string const &stringToTrim, std::string const &charsToTrim=whitespaceAndNewlineChars)
static int stringToInt(std::string const &stringToInterpret)
std::list< ValueClass * > operator()(int const firstIndex, int const secondIndex, int const thirdIndex)
bool hasEntry(int const firstIndex, int const secondIndex, int const thirdIndex) const
std::multimap< std::pair< std::pair< int, int >, int >, ValueClass > & getValueMap()
std::list< ValueClass * > operator()(std::pair< std::pair< int, int >, int > const &indexTriple)
std::pair< std::pair< std::pair< int, int >, int >, ValueClass > valueRecorder
bool hasEntry(std::pair< std::pair< int, int >, int > const &indexTriple) const
std::list< ValueClass const * > operator()(int const firstIndex, int const secondIndex, int const thirdIndex) const
std::multimap< std::pair< std::pair< int, int >, int >, ValueClass > valueMap
std::multimap< std::pair< std::pair< int, int >, int >, ValueClass >::const_iterator mapIterator