a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
SlhaSimplisticInterpreter.hpp
Go to the documentation of this file.
1/*
2 * SlhaSimplisticInterpreter.hpp
3 *
4 * Created on: Sep 13, 2012
5 * Author: Ben O'Leary (benjamin.oleary@gmail.com)
6 */
7
8#ifndef SLHASIMPLISTICINTERPRETER_HPP_
9#define SLHASIMPLISTICINTERPRETER_HPP_
10
11#include <string>
12#include <sstream>
13#include <vector>
14#include <map>
15#include "SlhaParser.hpp"
17
18namespace LHPC
19{
20 /* this is a class for an object that reads in an SLHA file & then returns
21 * strings interpreting given keys as block names with sets of index
22 * integers. it also includes functionality to interpret the string as a
23 * double or an int.
24 */
26 {
27 public:
28 SlhaSimplisticInterpreter( std::string const& slhaFilename );
30
31 std::string
32 operator()( std::string blockNameAndIndices );
33 std::string
34 withMap( std::string blockNameAndIndices );
35 double
36 getDouble( std::string blockNameAndIndices );
37 int
38 getInt( std::string blockNameAndIndices );
39 double
40 getLowestScale( std::string const& blockName ) const;
41 bool
42 readFile( std::string const& slhaFileName );
43 // this opens the file with name given by slhaFileName with slhaParser.
44
45
46 protected:
48 std::stringstream stringParser;
49 std::map< std::string, std::string > keyedResults;
50 std::map< std::string, std::string >::iterator mapIterator;
51
52 std::stringstream&
53 getStringParser( std::string const& newStringForParser );
54 };
55
56
57
58
59 inline std::string
60 SlhaSimplisticInterpreter::withMap( std::string blockNameAndIndices )
61 {
62 mapIterator = keyedResults.find( blockNameAndIndices );
63 if( keyedResults.end() == mapIterator )
64 {
65 mapIterator = keyedResults.insert( keyedResults.begin(),
66 std::pair< std::string, std::string >(
67 blockNameAndIndices,
68 (*this)( blockNameAndIndices ) ) );
69 }
70 return mapIterator->second;
71 }
72
73 inline double
74 SlhaSimplisticInterpreter::getDouble( std::string blockNameAndIndices )
75 {
76 double returnValue( 0.0 );
77 getStringParser( (*this)( blockNameAndIndices ) ) >> returnValue;
78 return returnValue;
79 }
80
81 inline int
82 SlhaSimplisticInterpreter::getInt( std::string blockNameAndIndices )
83 {
84 int returnValue( 0 );
85 getStringParser( (*this)( blockNameAndIndices ) ) >> returnValue;
86 return returnValue;
87 }
88
89 inline double
91 std::string const& blockName ) const
92 {
93 return (*slhaParser.getBlockAsStrings( blockName ))[ 0 ].getScale();
94 }
95
96 inline bool
97 SlhaSimplisticInterpreter::readFile( std::string const& slhaFileName )
98 // this opens the file with name given by slhaFileName with slhaParser.
99 {
100 keyedResults.clear();
101 return slhaParser.readFile( slhaFileName );
102 }
103
104 inline std::stringstream&
106 std::string const& newStringForParser )
107 {
108 stringParser.clear();
109 stringParser.str( newStringForParser );
110 return stringParser;
111 }
112
113} /* namespace LHPC */
114#endif /* SLHASIMPLISTICINTERPRETER_HPP_ */
SLHA::SameNameBlockSet * getBlockAsStrings(std::string blockName)
Definition: SlhaParser.hpp:132
bool readFile(std::string const &slhaFileName)
Definition: SlhaParser.cpp:167
SlhaSimplisticInterpreter(std::string const &slhaFilename)
std::string withMap(std::string blockNameAndIndices)
std::string operator()(std::string blockNameAndIndices)
std::stringstream & getStringParser(std::string const &newStringForParser)
int getInt(std::string blockNameAndIndices)
std::map< std::string, std::string > keyedResults
double getDouble(std::string blockNameAndIndices)
bool readFile(std::string const &slhaFileName)
double getLowestScale(std::string const &blockName) const
std::map< std::string, std::string >::iterator mapIterator