master
a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models
Loading...
Searching...
No Matches
LhcoParser.hpp
Go to the documentation of this file.
1
/*
2
* LhcoParser.hpp
3
*
4
* Created on: Jun 29, 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 LHCOPARSER_HPP_
15
#define LHCOPARSER_HPP_
16
17
#include "
BOLlib/include/BOLlib.hpp
"
18
#include "
LhcoEvent.hpp
"
19
20
namespace
LHPC
21
{
22
// this is a class for reading in a LHCO format file & parsing the events
23
// from it.
24
class
LhcoParser
25
{
26
public
:
27
LhcoParser
( std::string
const
eventFileName =
""
,
28
bool
const
isVerbose
=
true
);
29
~LhcoParser
();
30
31
bool
32
openFile
( std::string
const
& eventFileName );
33
// this opens the file with the given name as the source of its events &
34
// returns true, unless the file could not be opened.
35
bool
36
readNextEvent
();
37
// this reads in the next event in the event file, & returns true if
38
// successful.
39
LHCO::LhcoEvent
const
&
40
getEvent
()
const
;
41
// this returns the last parsed event.
42
43
44
protected
:
45
bool
isVerbose
;
46
BOL::CommentedTextParser
fileParser
;
47
LHCO::LhcoEvent
currentEvent
;
48
bool
fileIsOpenAndNotYetAtEndOfFile
;
49
std::string
currentLine
;
50
int
lineNumber
;
51
52
bool
53
lookForFirstEvent
();
54
// this reads in to the 1st non-commented line that begins with '0' with
55
// optional whitespace before it & at least 1 whitespace-type character
56
// following it. it returns true if it found such a line, which it also
57
// assigns to currentLine.
58
};
59
60
61
62
63
64
inline
bool
65
LhcoParser::openFile
( std::string
const
& eventFileName )
66
// this opens the file with the given name as the source of its events &
67
// returns true, unless the file could not be opened. it also reads in up to
68
// the 1st event (preparing currentEvent with the 1st "line 0" of an event).
69
{
70
fileIsOpenAndNotYetAtEndOfFile
=
fileParser
.
openFile
( eventFileName );
71
if
(
fileIsOpenAndNotYetAtEndOfFile
)
72
{
73
fileIsOpenAndNotYetAtEndOfFile
=
lookForFirstEvent
();
74
if
(
fileIsOpenAndNotYetAtEndOfFile
)
75
{
76
lineNumber
=
currentEvent
.
recordLine
(
currentLine
);
77
}
78
}
79
return
fileIsOpenAndNotYetAtEndOfFile
;
80
}
81
82
inline
LHCO::LhcoEvent
const
&
83
LhcoParser::getEvent
() const
84
// this returns the last parsed event.
85
{
86
return
currentEvent
;
87
}
88
89
inline
bool
90
LhcoParser::lookForFirstEvent
()
91
// this reads in to the 1st non-commented line that begins with '0' with
92
// optional whitespace before it & at least 1 whitespace-type character
93
// following it. it returns true if it found such a line, which it also
94
// assigns to currentLine.
95
{
96
if
(
fileIsOpenAndNotYetAtEndOfFile
)
97
{
98
bool
notYetFoundFirstLineOfAnEvent(
true
);
99
while
(
fileIsOpenAndNotYetAtEndOfFile
100
&&
101
notYetFoundFirstLineOfAnEvent )
102
{
103
fileIsOpenAndNotYetAtEndOfFile
104
=
fileParser
.
readJustNextValidLine
(
currentLine
);
105
if
(
fileIsOpenAndNotYetAtEndOfFile
)
106
{
107
notYetFoundFirstLineOfAnEvent
108
= ( 0.0 !=
BOL::StringParser::stringToDouble
(
currentLine
) );
109
// stringToDouble(...) takes the 1st number found in the string.
110
}
111
}
112
// this loop ends as soon as a line starting with 0 was found, or if the
113
// end of the file was reached.
114
}
115
return
fileIsOpenAndNotYetAtEndOfFile
;
116
}
117
118
}
119
120
#endif
/* LHCOPARSER_HPP_ */
BOLlib.hpp
LhcoEvent.hpp
BOL::CommentedTextParser
Definition
CommentedTextParser.hpp:28
BOL::CommentedTextParser::readJustNextValidLine
bool readJustNextValidLine(std::string &stringToFill)
Definition
CommentedTextParser.hpp:77
BOL::CommentedTextParser::openFile
bool openFile(std::string const &fileName)
Definition
CommentedTextParser.hpp:146
BOL::StringParser::stringToDouble
static double stringToDouble(std::string const &stringToInterpret)
Definition
StringParser.hpp:422
LHPC::LHCO::LhcoEvent
Definition
LhcoEvent.hpp:27
LHPC::LHCO::LhcoEvent::recordLine
int recordLine(std::string const &lineAsString)
Definition
LhcoEvent.cpp:82
LHPC::LhcoParser
Definition
LhcoParser.hpp:25
LHPC::LhcoParser::lineNumber
int lineNumber
Definition
LhcoParser.hpp:50
LHPC::LhcoParser::fileParser
BOL::CommentedTextParser fileParser
Definition
LhcoParser.hpp:46
LHPC::LhcoParser::currentLine
std::string currentLine
Definition
LhcoParser.hpp:49
LHPC::LhcoParser::readNextEvent
bool readNextEvent()
Definition
LhcoParser.cpp:41
LHPC::LhcoParser::lookForFirstEvent
bool lookForFirstEvent()
Definition
LhcoParser.hpp:90
LHPC::LhcoParser::isVerbose
bool isVerbose
Definition
LhcoParser.hpp:45
LHPC::LhcoParser::openFile
bool openFile(std::string const &eventFileName)
Definition
LhcoParser.hpp:65
LHPC::LhcoParser::fileIsOpenAndNotYetAtEndOfFile
bool fileIsOpenAndNotYetAtEndOfFile
Definition
LhcoParser.hpp:48
LHPC::LhcoParser::currentEvent
LHCO::LhcoEvent currentEvent
Definition
LhcoParser.hpp:47
LHPC::LhcoParser::getEvent
LHCO::LhcoEvent const & getEvent() const
Definition
LhcoParser.hpp:83
LHPC::LhcoParser::~LhcoParser
~LhcoParser()
Definition
LhcoParser.cpp:34
LHPC
Definition
FourMomentum.hpp:24
LHPC
include
LHCO
LhcoParser.hpp
Generated on Tue Aug 4 2026 for $\texttt{HEPfit}$ using
1.9.8