a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
SameNameBlockSet.hpp
Go to the documentation of this file.
1/*
2 * SameNameBlockSet.hpp
3 *
4 * Created on: Mar 4, 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 SAMENAMEBLOCKSET_HPP_
15#define SAMENAMEBLOCKSET_HPP_
16
17#include <string>
18#include <list>
20#include "BaseStringBlock.hpp"
21
22namespace LHPC
23{
24 namespace SLHA
25 {
26 typedef
28
29 /* instances of this class hold together all copies of a block which have
30 * the same name (if there are 2 or more copies, it is assumed that they
31 * have different energy scale values).
32 */
34 {
35 public:
36 SameNameBlockSet( std::string const& blockName );
38
39 std::string const&
40 getName() const;
41 // this returns the name in uppercase.
42 bool
43 nameMatches( std::string const& nameToCompare ) const;
44 // this returns true if nameToCompare matches blockNameInUppercase
45 // ignoring case.
46 bool
47 hasRecordedScale( double const soughtScale,
48 int& indexForLowerScale,
49 int& indexForUpperScale,
50 double& fractionFromLowerScale );
51 /* this looks for the pair of blocks with energy scales closest to
52 * soughtScale.
53 * if there are no recorded copies of this block, none of the references
54 * given are changed & false is returned.
55 * if there is only one copy of the block, both indexForLowerScale &
56 * indexForUpperScale are set to 1, fractionFromLowerScale is set to NaN,
57 * & true is returned.
58 * if there are 2 or more copies of the block, indexForLowerScale &
59 * indexForUpperScale are set as described below, fractionFromLowerScale
60 * is set to be
61 * ( ( soughtScale - [ scale of copy with lower scale ] )
62 * / [ difference of copy scales ] ), & true is returned.
63 * fractionFromLowerScale will thus be between 0.0 & 1.0 if there are
64 * copies with scales above & below soughtScale, but may be negative if
65 * soughtScale is lower than the lowest scale of the copies, or greater
66 * than 1.0 if soughtScale is higher than the highest scale of the
67 * copies.
68 * since the copies of the block with different scales are not
69 * necessarily recorded in order of scale, indexForLowerScale will not
70 * necessarily be smaller in value than indexForUpperScale.
71 * indexForLowerScale & indexForUpperScale are set as follows:
72 * if soughtScale is lower than the lowest scale of the copies,
73 * indexForLowerScale is set to the index of the copy with lowest scale,
74 * & indexForUpperScale is set to the index of the copy with the next
75 * lowest scale.
76 * if soughtScale is higher than the highest scale of the copies,
77 * indexForUpperScale is set to the index of the copy with highest scale,
78 * & indexForLowerScale is set to the index of the copy with the next
79 * highest scale.
80 * otherwise, indexForLowerScale is set to the index of the copy with
81 * highest scale which is still lower than soughtScale, &
82 * indexForUpperScale is set to the index of the copy with lowest scale
83 * which is still higher than soughtScale.
84 */
86 operator[]( int whichScaleIndex );
87 /* the BaseStringBlocks are indexed in the order in which they were
88 * read. the index starts at 1 rather than 0, as well. if 0 is given as
89 * the argument, the index corresponding to the copy with the lowest
90 * scale is used.
91 */
93 operator[]( int whichScaleIndex ) const;
94 // const version of above.
95 int
97 int
98 getLowestScaleIndex() const;
99 void
100 clearEntries();
101 // this clears all the data that this block set has recorded.
102 void
103 recordHeader( std::string const& headerString,
104 std::string const& commentString,
105 double const blockScale );
106 // this prepares a new BaseBlockAsString for the impending block being
107 // read as strings.
108 void
109 recordBodyLine( std::string const& dataString,
110 std::string const& commentString );
111 // this sends the lines to the last BaseBlockAsString prepared by
112 // recordHeader( ... ).
113 void
115 // this pushes currentStringBlock to all the observers so that they
116 // interpret it.
117
118
119 protected:
122 std::list< std::pair< int, double > > scaleOrderedIndices;
123 std::list< std::pair< int, double > >::iterator scaleIndexIterator;
126 };
127
128
129
130
131
132 inline std::string const&
134 // this returns the name in uppercase.
135 {
137 }
138
139 inline bool
140 SameNameBlockSet::nameMatches( std::string const& nameToCompare ) const
141 // this returns true if nameToCompare matches blockNameInUppercase
142 // ignoring case.
143 {
144 return BOL::StringParser::stringsMatchIgnoringCase( blockNameInUppercase,
145 nameToCompare );
146 }
147
148 inline bool
149 SameNameBlockSet::hasRecordedScale( double const soughtScale,
150 int& indexForLowerScale,
151 int& indexForUpperScale,
152 double& fractionFromLowerScale )
153 /* this looks for the pair of blocks with energy scales closest to
154 * soughtScale.
155 * if there are no recorded copies of this block, none of the references
156 * given are changed & false is returned.
157 * if there is only one copy of the block, both indexForLowerScale &
158 * indexForUpperScale are set to 1, fractionFromLowerScale is set to NaN,
159 * & true is returned.
160 * if there are 2 or more copies of the block, indexForLowerScale &
161 * indexForUpperScale are set as described below, fractionFromLowerScale
162 * is set to be
163 * ( ( soughtScale - [ scale of copy with lower scale ] )
164 * / [ difference of copy scales ] ), & true is returned.
165 * fractionFromLowerScale will thus be between 0.0 & 1.0 if there are
166 * copies with scales above & below soughtScale, but may be negative if
167 * soughtScale is lower than the lowest scale of the copies, or greater
168 * than 1.0 if soughtScale is higher than the highest scale of the
169 * copies.
170 * since the copies of the block with different scales are not
171 * necessarily recorded in order of scale, indexForLowerScale will not
172 * necessarily be smaller in value than indexForUpperScale.
173 * indexForLowerScale & indexForUpperScale are set as follows:
174 * if soughtScale is lower than the lowest scale of the copies,
175 * indexForLowerScale is set to the index of the copy with lowest scale,
176 * & indexForUpperScale is set to the index of the copy with the next
177 * lowest scale.
178 * if soughtScale is higher than the highest scale of the copies,
179 * indexForUpperScale is set to the index of the copy with highest scale,
180 * & indexForLowerScale is set to the index of the copy with the next
181 * highest scale.
182 * otherwise, indexForLowerScale is set to the index of the copy with
183 * highest scale which is still lower than soughtScale, &
184 * indexForUpperScale is set to the index of the copy with lowest scale
185 * which is still higher than soughtScale.
186 */
187 {
190 indexForLowerScale,
191 indexForUpperScale,
192 fractionFromLowerScale );
193 }
194
196 SameNameBlockSet::operator[]( int whichScaleIndex )
197 /* the BaseStringBlocks are indexed in the order in which they were
198 * read. the index starts at 1 rather than 0, as well. if 0 is given as
199 * the argument, the index corresponding to the copy with the lowest
200 * scale is used.
201 */
202 {
203 if( 0 == whichScaleIndex )
204 {
206 }
207 else
208 {
209 return stringBlocks[ (--whichScaleIndex) ];
210 }
211 }
212
213 inline BlockClass::BaseStringBlock const&
214 SameNameBlockSet::operator[]( int whichScaleIndex ) const
215 // const version of above.
216 {
217 if( 0 == whichScaleIndex )
218 {
219 return stringBlocks[ lowestScaleIndex ];
220 }
221 else
222 {
223 return stringBlocks[ (--whichScaleIndex) ];
224 }
225 }
226
227 inline int
229 {
230 return stringBlocks.getSize();
231 }
232
233 inline int
235 {
236 return lowestScaleIndex;
237 }
238
239 inline void
241 // this clears all the data that this block set has recorded.
242 {
243 stringBlocks.clearEntries();
244 scaleOrderedIndices.clear();
245 lowestScaleIndex = -1;
247 // respondToObservedSignal() has been over-ridden for the observers so
248 // that this clears their entries.
249 }
250
251 inline void
252 SameNameBlockSet::recordBodyLine( std::string const& dataString,
253 std::string const& commentString )
254 // this sends the lines to the last BaseBlockAsString prepared by
255 // recordHeader( ... ).
256 {
258 commentString );
259 }
260
261 inline void
263 // this pushes currentStringBlock to all the observers so that they
264 // interpret it.
265 {
267 }
268
269 }
270
271}
272
273#endif /* SAMENAMEBLOCKSET_HPP_ */
virtual void updateObservers()
static bool stringsMatchIgnoringCase(std::string const &firstString, std::string const &secondString)
static bool findScaleIndices(double const soughtScale, std::list< std::pair< int, double > > const &scaleOrderedIndices, int &indexForLowerScale, int &indexForUpperScale, double &fractionFromLowerScale)
void recordBodyLine(std::string const &dataString, std::string const &commentString)
void recordHeader(std::string const &headerString, std::string const &commentString, double const blockScale)
BlockClass::BaseStringBlock * currentStringBlock
bool nameMatches(std::string const &nameToCompare) const
std::list< std::pair< int, double > >::iterator scaleIndexIterator
std::string const & getName() const
std::list< std::pair< int, double > > scaleOrderedIndices
void recordBodyLine(std::string const &dataString, std::string const &commentString)
BlockClass::BaseStringBlock & operator[](int whichScaleIndex)
bool hasRecordedScale(double const soughtScale, int &indexForLowerScale, int &indexForUpperScale, double &fractionFromLowerScale)
BOL::VectorlikeArray< BlockClass::BaseStringBlock > stringBlocks
SameNameBlockSet(std::string const &blockName)
BOL::PushingObserved< BlockClass::BaseStringBlock > StringBlockPusher