a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
BaseStringBlock.hpp
Go to the documentation of this file.
1/*
2 * BaseStringBlock.hpp
3 *
4 * Created on: Mar 3, 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 BASEBLOCKASSTRINGS_HPP_
15#define BASEBLOCKASSTRINGS_HPP_
16
17#include <string>
18#include <list>
20
21namespace LHPC
22{
23 namespace SLHA
24 {
25 namespace BlockClass
26 {
27 // this class holds a SLHA block as a set of pairs of strings (data with
28 // comment).
30 {
31 public:
32 static std::string const blockIdentifierString;
33 static std::string const decayIdentifierString;
34
35 static bool
36 findScaleIndices( double const soughtScale,
37 std::list< std::pair< int, double > > const& scaleOrderedIndices,
38 int& indexForLowerScale,
39 int& indexForUpperScale,
40 double& fractionFromLowerScale );
41 /* this looks for the pair of indices with energy scales closest to
42 * soughtScale from scaleOrderedIndices (which is assumed to already be
43 * ordered by scale).
44 * if scaleOrderedIndices is empty, none of the references given are
45 * changed & false is returned.
46 * if there is only one copy of the block, both indexForLowerScale &
47 * indexForUpperScale are set to 1, fractionFromLowerScale is set to
48 * NaN, & true is returned.
49 * if there are 2 or more copies of the block, indexForLowerScale &
50 * indexForUpperScale are set as described below,
51 * fractionFromLowerScale is set to be
52 * ( ( soughtScale - [ scale of copy with lower scale ] )
53 * / [ difference of copy scales ] ), & true is returned.
54 * fractionFromLowerScale will thus be between 0.0 & 1.0 if there are
55 * copies with scales above & below soughtScale, but may be negative if
56 * soughtScale is lower than the lowest scale of the copies, or greater
57 * than 1.0 if soughtScale is higher than the highest scale of the
58 * copies.
59 * since the copies of the block with different scales are not
60 * necessarily recorded in order of scale, indexForLowerScale will not
61 * necessarily be smaller in value than indexForUpperScale.
62 * indexForLowerScale & indexForUpperScale are set as follows:
63 * if soughtScale is lower than the lowest scale of the copies,
64 * indexForLowerScale is set to the index of the copy with lowest
65 * scale, & indexForUpperScale is set to the index of the copy with the
66 * next lowest scale.
67 * if soughtScale is higher than the highest scale of the copies,
68 * indexForUpperScale is set to the index of the copy with highest
69 * scale, & indexForLowerScale is set to the index of the copy with the
70 * next highest scale.
71 * otherwise, indexForLowerScale is set to the index of the copy with
72 * highest scale which is still lower than soughtScale, &
73 * indexForUpperScale is set to the index of the copy with lowest scale
74 * which is still higher than soughtScale.
75 */
76
79
81 recordHeader( std::string const& headerString,
82 std::string const& commentString,
83 double const blockScale );
84 // this sets the block to be just a header, so subsequent
85 // recordBodyLine(...) calls write the block anew.
86 void
87 recordBodyLine( std::string const& dataString,
88 std::string const& commentString );
89 /* this records dataString & commentString in stringPairArray &
90 * then copies dataString into comparisonString, trims it of
91 * whitespace, & calls interpretBodyLine() if comparisonString is not
92 * then empty.
93 */
94 int
96 // this returns the number of body lines, so the size of
97 // stringPairArray minus 1.
98 std::pair< std::string, std::string >&
99 operator[]( int const whichLine );
100 /* the std::pair< std::string, std::string > at index 0 is the block
101 * name (with optional scale & anything else that appeared before the
102 * '#') paired with its comment, & the rest of the
103 * std::pair< std::string, std::string >s are the data lines paired
104 * with their comments as recorded.
105 */
106 std::pair< std::string, std::string > const&
107 operator[]( int const whichLine ) const;
108 // const version of above.
109 double
110 getScale() const;
111
112
113 protected:
117 /* the std::pair< std::string, std::string > at index 0 is the block
118 * name (with optional scale & anything else that appeared before the
119 * '#') paired with its comment, & the rest of the
120 * std::pair< std::string, std::string >s are the data lines paired
121 * with their comments as recorded.
122 */
124 };
125
126
127
128
129
130 inline BaseStringBlock*
131 BaseStringBlock::recordHeader( std::string const& headerString,
132 std::string const& commentString,
133 double const blockScale )
134 {
135 stringPairArray.setSize( 1 );
136 stringPairArray.getFront().first.assign( headerString );
137 stringPairArray.getFront().second.assign( commentString );
138 this->blockScale = blockScale;
139 return this;
140 }
141
142 inline void
143 BaseStringBlock::recordBodyLine( std::string const& dataString,
144 std::string const& commentString )
145 /* this records dataString & commentString in stringPairArray & then
146 * copies dataString into comparisonString, trims it of whitespace, &
147 * calls interpretBodyLine() if comparisonString is not then empty.
148 */
149 {
150 stringPairArray.newEnd().first.assign( dataString );
151 stringPairArray.getBack().second.assign( commentString );
152 }
153
154 inline std::pair< std::string, std::string >&
155 BaseStringBlock::operator[]( int const whichLine )
156 /* the std::pair< std::string, std::string > at index 0 is the block
157 * name (with optional scale & anything else that appeared before the
158 * '#') paired with its comment, & the rest of the
159 * std::pair< std::string, std::string >s are the data lines paired
160 * with their comments as recorded.
161 */
162 {
163 return stringPairArray[ whichLine ];
164 }
165
166 inline std::pair< std::string, std::string > const&
167 BaseStringBlock::operator[]( int const whichLine ) const
168 // const version of above.
169 {
170 return stringPairArray[ whichLine ];
171 }
172
173 inline int
175 // this returns the number of body lines, so the size of
176 // stringPairArray minus 1.
177 {
178 return stringPairArray.getLastIndex();
179 }
180
181 inline double
183 {
184 return blockScale;
185 }
186
187 }
188
189 }
190
191}
192
193#endif /* BASEBLOCKASSTRINGS_HPP_ */
static bool findScaleIndices(double const soughtScale, std::list< std::pair< int, double > > const &scaleOrderedIndices, int &indexForLowerScale, int &indexForUpperScale, double &fractionFromLowerScale)
static std::string const blockIdentifierString
BaseStringBlock * recordHeader(std::string const &headerString, std::string const &commentString, double const blockScale)
std::pair< std::string, std::string > & operator[](int const whichLine)
static std::string const decayIdentifierString
void recordBodyLine(std::string const &dataString, std::string const &commentString)
BOL::VectorlikeArray< std::pair< std::string, std::string > > stringPairArray