a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
SlhaParser.hpp
Go to the documentation of this file.
1/*
2 * SlhaParser.hpp
3 *
4 * Created on: Jan 11, 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 SLHAPARSER_HPP_
15#define SLHAPARSER_HPP_
16
17#include <string>
18#include <map>
20#include "../MEC/MassSpectrum.hpp"
21#include "../MEC/RunningConstant.hpp"
22#include "../MEC/RunningConstantError.hpp"
23#include "../MEC/SpectrumUpdater.hpp"
24#include "BlockTypes.hpp"
25
26namespace LHPC
27{
28 // this is a class for reading in a SLHA format file & parsing the data from
29 // it.
30 class SlhaParser : public BOL::PushingObserved< SpectrumUpdater >
31 {
32 public:
33 static void
34 copyWithoutBlock( std::string const& originalFilename,
35 std::string const& blockToStrip,
36 std::string const& copyFilename );
37
39 bool const isVerbose = true);
40 virtual
42
43 virtual void
44 registerBlock( SLHA::BaseSlhaBlock& blockToUpdate );
45 // this registers blockToUpdate so that its data get updated every time a
46 // new block of the appropriate name is read.
47 void
48 registerSpectrum( MassSpectrum& spectrumToUpdate );
49 // this adds a pointer to spectrumToUpdate to spectraToUpdate so that its
50 // data get updated during each readFile().
51 bool
52 readFile( std::string const& slhaFileName );
53 /* this opens the file with name given by slhaFileName, parses its data
54 * into strings, & passes each registered SlhaBlock & each BaseSlhaDecay
55 * its appropriate string to interpret.
56 */
58 getBlockAsStrings( std::string blockName );
60 getBlockAsStrings( std::string blockName ) const;
61
62
63 protected:
64 bool const isVerbose;
67 std::map< std::string, SLHA::SameNameBlockSet* > blockMap;
68 std::map< std::string, SLHA::SameNameBlockSet* >::iterator
70 std::pair< std::string, SLHA::SameNameBlockSet* > mapInserter;
72 std::string dataString;
73 std::string commentString;
74 std::string firstWordOfLine;
79 std::multimap< int, RunningConstant > const* fmassMap;
82 std::multimap< int, RunningConstantError > const* fmasserrMap;
85 std::map< int, double > const* massMap;
87
88 void
90 // this goes through all the blocks in blockMap & calls their
91 // clearEntries() member functions.
92 void
94 // this ensures that if there is a spectrum to update, there are both
95 // blocks for MASS & FMASS.
96 void
98 // this parses the block header line & sets currentBlockPointer
99 // appropriately, & calls checkForBlockScaleOrDecayWidth().
100 void
102 // this parses the decay header line & sets currentBlockPointer
103 // appropriately, & calls checkForBlockScaleOrDecayWidth().
104 void
106 // this interprets the current line as a decay for the spectrum.
107 void
109 // this sets up the common parsing of the line being read.
110 void
112 // this reads the masses from the FMASS & MASS blocks into the spectrum, if
113 // necessary.
114 void
116 // this sets up the common parsing of the line being read.
117 };
118
119
120
121
122
123 inline void
125 // this adds a pointer to spectrumToUpdate to spectraToUpdate so that its
126 // data get updated during each readFile().
127 {
128 registerObserver( &spectrumToUpdate );
129 }
130
132 SlhaParser::getBlockAsStrings( std::string blockName )
133 {
135 blockMapIterator = blockMap.find( blockName );
136 if( blockMap.end() == blockMapIterator )
137 {
138 return NULL;
139 }
140 else
141 {
142 return blockMapIterator->second;
143 }
144 }
145
146 inline SLHA::SameNameBlockSet const*
147 SlhaParser::getBlockAsStrings( std::string blockName ) const
148 {
150 std::map< std::string, SLHA::SameNameBlockSet* >::const_iterator
151 constBlockMapIterator( blockMap.find( blockName ) );
152 if( blockMap.end() == constBlockMapIterator )
153 {
154 return NULL;
155 }
156 else
157 {
158 return constBlockMapIterator->second;
159 }
160 }
161
162 inline void
164 // this goes through all the blocks in blockMap & calls their clearEntries()
165 // member functions.
166 {
167 /* observingSpectrumUpdater is set so that only decays will be updated
168 * in the observing spectra until later, when the mass map pointers will be
169 * set so that the masses can be recorded.
170 */
174 // the MassSpectrum class over-rides respondToObservedSignal() to call its
175 // clearMassesAndDecays() function.
176 blockMapIterator = blockMap.begin();
177 while( blockMap.end() != blockMapIterator )
178 {
179 blockMapIterator->second->clearEntries();
181 }
182 currentBlockPointer = NULL;
183 }
184
185 inline void
187 // this parses the block header line & sets currentMassEigenstate
188 // appropriately, & records its decay width.
189 {
191 if( !(observerList.empty())
192 &&
193 ( 3 == wordsOfLine.getSize() ) )
194 // if there is a spectrum for recording decays, & if the line has the
195 // right number of entries ("DECAY", particle code, decay width)...
196 {
198 wordsOfLine[ 2 ] );
199 }
200 }
201
202 inline void
204 // this interprets the current line as a decay for the spectrum.
205 {
206 wordsOfLine.clearEntries();
210 if( !(wordsOfLine.isEmpty()) )
211 // if there is a decay to record...
212 {
214 }
215 }
216
217 inline void
219 // this either pushes a read decay to the observing spectra or gets the
220 // read block to be pushed to its observers.
221 {
222 if( NULL != currentBlockPointer )
223 {
225 currentBlockPointer = NULL;
226 }
228 {
231 }
232 }
233
234 inline void
236 // this reads the masses from the FMASS & MASS blocks into the spectrum, if
237 // necessary.
238 {
239 if( !(observerList.empty()) )
240 {
246 }
247 }
248
249 inline void
251 // this sets up the common parsing of the line being read.
252 {
254 wordsOfLine.clearEntries();
258 }
259
260}
261
262#endif /* SLHAPARSER_HPP_ */
std::list< observerWithBool > observerList
virtual void registerObserver(PushedToObserver< SpectrumUpdater > *const joiningObserver)
static std::string const whitespaceChars
static void transformToUppercase(std::string &stringToTransform)
static void parseByChar(std::string const &stringToParse, VectorlikeArray< std::string > &destinationArray, std::string const &divisionCharSet=whitespaceChars)
virtual std::multimap< int, RunningConstant > const * getFmassMap() const
virtual std::map< int, double > const * getMassMap() const
virtual std::multimap< int, RunningConstantError > const * getFmasserrMap() const
void checkForMassBlocksForSpectrum()
Definition: SlhaParser.cpp:215
virtual void registerBlock(SLHA::BaseSlhaBlock &blockToUpdate)
Definition: SlhaParser.cpp:120
void registerSpectrum(MassSpectrum &spectrumToUpdate)
Definition: SlhaParser.hpp:124
std::map< int, double > const * massMap
Definition: SlhaParser.hpp:85
std::string firstWordOfLine
Definition: SlhaParser.hpp:74
BOL::VectorlikeArray< std::string > wordsOfLine
Definition: SlhaParser.hpp:75
SLHA::SameNameBlockSet * currentBlockPointer
Definition: SlhaParser.hpp:71
std::multimap< int, RunningConstant > const * fmassMap
Definition: SlhaParser.hpp:79
SLHA::BaseSlhaBlock * fmassBlockPointer
Definition: SlhaParser.hpp:78
virtual ~SlhaParser()
Definition: SlhaParser.cpp:99
std::multimap< int, RunningConstantError > const * fmasserrMap
Definition: SlhaParser.hpp:82
SLHA::BaseSlhaBlock * massBlockPointer
Definition: SlhaParser.hpp:84
std::map< std::string, SLHA::SameNameBlockSet * > blockMap
Definition: SlhaParser.hpp:67
SLHA::SameNameBlockSet * getBlockAsStrings(std::string blockName)
Definition: SlhaParser.hpp:132
std::pair< std::string, SLHA::SameNameBlockSet * > mapInserter
Definition: SlhaParser.hpp:70
void prepareForEitherBlockOrDecay()
Definition: SlhaParser.hpp:250
std::map< std::string, SLHA::SameNameBlockSet * >::iterator blockMapIterator
Definition: SlhaParser.hpp:69
SlhaParser(bool const shouldRecordBlocksNotRegistered=true, bool const isVerbose=true)
Definition: SlhaParser.cpp:69
bool readFile(std::string const &slhaFileName)
Definition: SlhaParser.cpp:167
bool const isVerbose
Definition: SlhaParser.hpp:64
void prepareToReadNewDecay()
Definition: SlhaParser.hpp:186
std::string commentString
Definition: SlhaParser.hpp:73
bool const shouldRecordBlocksNotRegistered
Definition: SlhaParser.hpp:65
SpectrumUpdater observingSpectrumUpdater
Definition: SlhaParser.hpp:76
void recordDecayLine()
Definition: SlhaParser.hpp:203
void prepareToReadNewBlock()
Definition: SlhaParser.cpp:299
SLHA::BaseSlhaBlock * fmasserrBlockPointer
Definition: SlhaParser.hpp:81
void ensureSpectraRecordMasses()
Definition: SlhaParser.hpp:235
BOL::CommentedTextParser fileParser
Definition: SlhaParser.hpp:66
std::string dataString
Definition: SlhaParser.hpp:72
static void copyWithoutBlock(std::string const &originalFilename, std::string const &blockToStrip, std::string const &copyFilename)
Definition: SlhaParser.cpp:19
void finishUpEitherBlockOrDecay()
Definition: SlhaParser.hpp:218
void recordDecayHeader(std::string const &decayerCode, std::string const &decayWidth)
void recordDecayLine(BOL::VectorlikeArray< std::string > const &decayLine)
void setFmasserrMap(std::multimap< int, RunningConstantError > const *fmasserrMap)
void setFmassMap(std::multimap< int, RunningConstant > const *fmassMap)
void setMassMap(std::map< int, double > const *massMap)