a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
MultipleDoublyIndexed.hpp
Go to the documentation of this file.
1/*
2 * MultipleDoublyIndexed.hpp
3 *
4 * Created on: Apr 1, 2012 (really!)
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 MULTIPLEDOUBLYINDEXED_HPP_
15#define MULTIPLEDOUBLYINDEXED_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 MultipleDoublyIndexed : public IndexedInterpreter< ValueClass >
31 {
32 public:
34 virtual
36
37 std::list< ValueClass* >
38 operator()( std::pair< int, int > const& indexPair );
39 /* this returns a std::list of pointers to the ValueClass instances
40 * mapped to by indexPair.first & indexPair.second. if there is no
41 * element at the sought indices, an empty std::list is returned.
42 */
43 std::list< ValueClass const* >
44 operator()( std::pair< int, int > const& indexPair ) const;
45 // const version of above.
46 std::list< ValueClass* >
47 operator()( int const firstIndex,
48 int const secondIndex )
49 { return (*this)( std::make_pair( firstIndex,
50 secondIndex ) ); }
51 std::list< ValueClass const* >
52 operator()( int const firstIndex,
53 int const secondIndex ) const
54 { return (*this)( std::make_pair( firstIndex,
55 secondIndex ) ); }
56 std::multimap< std::pair< int, int >, ValueClass >&
58 std::multimap< std::pair< int, int >, ValueClass > const&
59 getValueMap() const;
60 bool
61 hasEntry( std::pair< int, int > const& indexPair ) const;
62 // this returns true if there is an entry at the sought indices.
63 bool
64 hasEntry( int const firstIndex,
65 int const secondIndex ) const
66 { return hasEntry( std::make_pair( firstIndex,
67 secondIndex ) ); }
68 virtual std::string const&
70 // see base version's description.
71 virtual void
73 // derived classes should clear their interpreted values.
74
75
76 protected:
77 typedef typename
78 std::multimap< std::pair< int, int >, ValueClass >::const_iterator
80
81 std::multimap< std::pair< int, int >, ValueClass > valueMap;
82 std::pair< std::pair< int, int >, ValueClass > valueRecorder;
83
84 virtual void
86 };
87
88
89
90
91
92 template< class ValueClass >
93 inline
95 IndexedInterpreter< ValueClass >(),
96 valueMap(),
97 valueRecorder()
98 {
99 // just an initialization list.
100 }
101
102 template< class ValueClass >
103 inline
105 {
106 // does nothing.
107 }
108
109 template< class ValueClass >
110 inline std::list< ValueClass* >
112 std::pair< int, int > const& indexPair )
113 /* this returns a std::list of pointers to the ValueClass instances
114 * mapped to by indexPair.first & indexPair.second. if there is no
115 * element at the sought indices, an empty std::list is returned.
116 */
117 {
118 std::list< ValueClass* > returnList;
119 std::pair< mapIterator, mapIterator >
120 rangeIterators( valueMap.equal_range( indexPair ) );
121 while( rangeIterators.first != rangeIterators.second )
122 {
123 returnList.push_back( &(rangeIterators.first->second) );
124 ++(rangeIterators.first);
125 }
126 return returnList;
127 }
128
129 template< class ValueClass >
130 inline std::list< ValueClass const* >
132 std::pair< int, int > const& indexPair ) const
133 // const version of above.
134 {
135 std::list< ValueClass const* > returnList;
136 std::pair< mapIterator, mapIterator >
137 rangeIterators( valueMap.equal_range( indexPair ) );
138 while( rangeIterators.first != rangeIterators.second )
139 {
140 returnList.push_back( &(rangeIterators.first->second) );
141 ++(rangeIterators.first);
142 }
143 return returnList;
144 }
145
146 template< class ValueClass >
147 inline std::multimap< std::pair< int, int >, ValueClass >&
149 {
150 return valueMap;
151 }
152
153 template< class ValueClass >
154 inline std::multimap< std::pair< int, int >, ValueClass > const&
156 {
157 return valueMap;
158 }
159
160 template< class ValueClass >
161 inline bool
163 std::pair< int, int > const& indexPair ) const
164 // this returns true if there is an entry at soughtIndex.
165 {
166 return ( 0 < valueMap.count( indexPair ) );
167 }
168
169 template< class ValueClass >
170 inline std::string const&
172 // see base version's description.
173 {
174 this->stringInterpretation.clear();
175 mapIterator valueFinder( valueMap.begin() );
176 while( valueFinder != valueMap.end() )
177 {
178 this->indexPrintingVector[ 0 ] = valueFinder->first.first;
179 this->indexPrintingVector[ 1 ] = valueFinder->first.second;
180 this->stringInterpretation.append( this->indicesToPrintingString() );
181 this->stringInterpretation.append( this->valueToPrintingString(
182 valueFinder->second ) );
183 /* negative particle codes can be avoided in any block, I think.
184 * well, the exact format is only specified for the MASS block, &
185 * in that case, negative particle codes can be avoided, since the
186 * charge-conjugate just has the same mass. if the charge-conjugate
187 * pair has a mass splitting, I think they are defined with 2
188 * separate codes. if negative codes end up here, it's not my
189 * fault...
190 */
191 this->stringInterpretation.append( "\n" );
192 ++valueFinder;
193 }
194 return this->stringInterpretation;
195 }
196
197 template< class ValueClass >
198 inline void
200 {
201 valueMap.clear();
202 }
203
204 template< class ValueClass >
205 inline void
207 {
208 for( int whichLine( this->currentStringBlock->getNumberOfBodyLines() );
209 0 < whichLine;
210 --whichLine )
211 {
212 this->currentWord.assign( BOL::StringParser::firstWordOf(
213 (*(this->currentStringBlock))[ whichLine ].first,
214 &(this->lineRemainderA),
216 if( !(this->currentWord.empty()) )
217 {
218 valueRecorder.first.first
219 = BOL::StringParser::stringToInt( this->currentWord );
220 this->currentWord.assign( BOL::StringParser::firstWordOf(
221 this->lineRemainderA,
222 &(this->lineRemainderB),
224 if( !(this->currentWord.empty()) )
225 {
226 valueRecorder.first.second
227 = BOL::StringParser::stringToInt( this->currentWord );
228 valueRecorder.second
229 = this->stringToValue( BOL::StringParser::trimFromFrontAndBack(
230 this->lineRemainderB,
232 valueMap.insert( valueRecorder );
233 }
234 }
235 }
236 }
237
238 }
239
240 }
241
242}
243
244#endif /* MULTIPLEDOUBLYINDEXED_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::pair< std::pair< int, int >, ValueClass > valueRecorder
std::list< ValueClass * > operator()(int const firstIndex, int const secondIndex)
std::list< ValueClass const * > operator()(int const firstIndex, int const secondIndex) const
std::multimap< std::pair< int, int >, ValueClass > valueMap
bool hasEntry(std::pair< int, int > const &indexPair) const
std::list< ValueClass * > operator()(std::pair< int, int > const &indexPair)
bool hasEntry(int const firstIndex, int const secondIndex) const
std::multimap< std::pair< int, int >, ValueClass > & getValueMap()
std::multimap< std::pair< int, int >, ValueClass >::const_iterator mapIterator