ATLAS Offline Software
Loading...
Searching...
No Matches
TCS::TopoASCIIReader Class Reference

#include <TopoASCIIReader.h>

Collaboration diagram for TCS::TopoASCIIReader:

Public Member Functions

 TopoASCIIReader (int verbose=0)
 ~TopoASCIIReader ()
void loadInput (const std::string &input)
void validateInput ()
void setVerbosity (int verbosity)
void setInputEvent (TCS::TopoInputEvent *evt)
bool getNextEvent ()
void printEvent ()
void printFileSummary ()
void reset ()

Private Attributes

std::ifstream m_fs
std::string m_inputFile { "" }
TCS::TopoInputEventm_event { nullptr }
int m_verbosity { 0 }
int m_nEvents { 0 }

Detailed Description

Definition at line 27 of file TopoASCIIReader.h.

Constructor & Destructor Documentation

◆ TopoASCIIReader()

TCS::TopoASCIIReader::TopoASCIIReader ( int verbose = 0)

Definition at line 13 of file TopoASCIIReader.cxx.

13 :
15{
16}
bool verbose
Definition hcg.cxx:73

◆ ~TopoASCIIReader()

TCS::TopoASCIIReader::~TopoASCIIReader ( )

Definition at line 19 of file TopoASCIIReader.cxx.

19 {
20 m_fs.close();
21}

Member Function Documentation

◆ getNextEvent()

bool TCS::TopoASCIIReader::getNextEvent ( )

Definition at line 42 of file TopoASCIIReader.cxx.

42 {
43
44 // clear info from previous event
45 string type = "default";
46 string currentLine;
47 m_event->clear();
48
49 // run through single event
50 while((currentLine != "<end_file>") && (currentLine != "</file>")) {
51
52 // get next data line
53 std::getline(m_fs, currentLine);
54 if(m_verbosity>0)
55 cout << currentLine << endl;
56
57 // process these lines
58
59 if(currentLine == "<end_file>" || currentLine == "</file>") return false;
60 if(currentLine == "<end_event>" || currentLine == "</event>") break;
61 if(currentLine == "<cluster>" || currentLine == "<eEm>" || currentLine == "<eTau>" || currentLine == "<jet>" || currentLine == "<jTau>" || currentLine == "<jEm>" || currentLine == "<jLJet>" || currentLine == "<gLJet>" || currentLine == "<jJet>" || currentLine == "<gJet>" || currentLine == "<muon>" || currentLine == "<lateMuon>" || currentLine == "<muonNextBC>" || currentLine == "<tau>" || currentLine == "<met>" || currentLine == "<info>") type = currentLine;
62 if(currentLine == "</cluster>" || currentLine == "</eEm>" || currentLine == "</eTau>" || currentLine == "</jet>" || currentLine == "</jTau>" || currentLine == "</jEm>" || currentLine == "</jLJet>" || currentLine == "</gLJet>" || currentLine == "</jJet>" || currentLine == "</gJet>" || currentLine == "</muon>" || currentLine == "</lateMuon>" || currentLine == "</muonNextBC>" || currentLine == "</tau>" || currentLine == "</met>" || currentLine == "</info>") { type = ""; continue; }
63 if(currentLine == "<begin_file>" || currentLine == "<file>" || currentLine == "<begin_event>" || currentLine == "<event>" || currentLine == "<cluster>" || currentLine == "<eEm>" || currentLine == "<eTau>" || currentLine == "<jet>" || currentLine == "<jTau>" || currentLine == "<jEm>" || currentLine == "<jLJet>" || currentLine == "<gLJet>" || currentLine == "<jJet>" || currentLine == "<gJet>" || currentLine == "<muon>" || currentLine == "<lateMuon>" || currentLine == "<muonNextBC>" || currentLine == "<tau>" || currentLine == "<met>" || currentLine == "<info>") continue;
64
65 // use stream iterators to copy the stream to a vector as whitespace separated strings
66 std::stringstream ss(currentLine);
67 std::istream_iterator<std::string> it(ss);
68 std::istream_iterator<std::string> end;
69 std::vector<std::string> results(it, end);
70
71 //std::cout << results.size() << std::endl;
72 // skip over whitespace
73 if(results.size() == 0) continue;
74
75 // convert whitespace separated strings of results into ints
76 if(type == "<cluster>") {
77 TCS::ClusterTOB cl( TCS::ClusterTOB(atoi(results.at(0).c_str()),atoi(results.at(1).c_str()),atoi(results.at(2).c_str()),atoi(results.at(3).c_str())));
78 if(results.size()==6) {
79 cl.setEtaDouble( atof(results.at(4).c_str()) );
80 cl.setPhiDouble( atof(results.at(5).c_str()) );
81 }
82 m_event->addCluster(cl);
83 } else if(type == "<eEm>") {
84 TCS::eEmTOB eEm( TCS::eEmTOB( atoi(results.at(0).c_str()),atoi(results.at(4).c_str()),atoi(results.at(5).c_str()) ));
85 if(results.size()==8) {
86 eEm.setEtaDouble( atof(results.at(6).c_str()) );
87 eEm.setPhiDouble( atof(results.at(7).c_str()) );
88 eEm.setReta( atof(results.at(1).c_str()) );
89 eEm.setRhad( atof(results.at(2).c_str()) );
90 eEm.setWstot( atof(results.at(3).c_str()) );
91 }
92 m_event->addeEm(eEm);
93 } else if(type == "<eTau>") {
94 TCS::eTauTOB eTau( atoi(results.at(0).c_str()),atoi(results.at(3).c_str()),atoi(results.at(4).c_str()) );
95 if(results.size()==7) {
96 eTau.setEtaDouble( atof(results.at(5).c_str()) );
97 eTau.setPhiDouble( atof(results.at(6).c_str()) );
98 eTau.setRCore( atof(results.at(1).c_str()) );
99 eTau.setRHad( atof(results.at(2).c_str()) );
100 }
101 m_event->addeTau(eTau);
102 } else if(type == "<tau>") {
103 TCS::ClusterTOB tau( TCS::ClusterTOB(atoi(results.at(0).c_str()),atoi(results.at(1).c_str()),atoi(results.at(2).c_str()),atoi(results.at(3).c_str())));
104 if(results.size()==6) {
105 tau.setEtaDouble( atof(results.at(4).c_str()) );
106 tau.setPhiDouble( atof(results.at(5).c_str()) );
107 }
108 m_event->addTau(tau);
109 } else if(type == "<jet>") {
110 TCS::JetTOB jet( atoi(results.at(0).c_str()),atoi(results.at(1).c_str()),atoi(results.at(2).c_str()),atoi(results.at(3).c_str()) );
111 if(results.size()==6) {
112 jet.setEtaDouble( atof(results.at(4).c_str()) );
113 jet.setPhiDouble( atof(results.at(5).c_str()) );
114 }
115 m_event->addJet( jet );
116 } else if(type == "<jTau>") {
117 TCS::jTauTOB tau( atoi(results.at(0).c_str()),0,atoi(results.at(1).c_str()),atoi(results.at(2).c_str()) );
118 if(results.size()==5) {
119 tau.setEtaDouble( atof(results.at(3).c_str()) );
120 tau.setPhiDouble( atof(results.at(4).c_str()) );
121 }
122 m_event->addjTau( tau );
123 } else if(type == "<jEm>") {
124 TCS::jEmTOB jEm( atoi(results.at(0).c_str()), atoi(results.at(1).c_str()), atoi(results.at(2).c_str()));
125 if(results.size()==5){
126 jEm.setEtaDouble(atof(results.at(3).c_str()));
127 jEm.setPhiDouble(atof(results.at(4).c_str()));
128 }
129 m_event->addjEm( jEm );
130 } else if(type == "<jLJet>") {
131 TCS::jLJetTOB jet( atoi(results.at(0).c_str()),atoi(results.at(1).c_str()),atoi(results.at(2).c_str()) );
132 if(results.size()==5) {
133 jet.setEtaDouble( atof(results.at(3).c_str()) );
134 jet.setPhiDouble( atof(results.at(4).c_str()) );
135 }
136 m_event->addjLJet( jet );
137 } else if(type == "<gLJet>") {
138 TCS::gLJetTOB jet( atoi(results.at(0).c_str()),atoi(results.at(1).c_str()),atoi(results.at(2).c_str()) );
139 if(results.size()==5) {
140 jet.setEtaDouble( atof(results.at(3).c_str()) );
141 jet.setPhiDouble( atof(results.at(4).c_str()) );
142 }
143 m_event->addgLJet( jet );
144 } else if(type == "<jJet>") {
145 TCS::jJetTOB jet( atoi(results.at(0).c_str()),atoi(results.at(1).c_str()),atoi(results.at(2).c_str()) );
146 if(results.size()==5) {
147 jet.setEtaDouble( atof(results.at(3).c_str()) );
148 jet.setPhiDouble( atof(results.at(4).c_str()) );
149 }
150 m_event->addjJet( jet );
151 } else if(type == "<gJet>") {
152 TCS::gJetTOB jet( atoi(results.at(0).c_str()),atoi(results.at(1).c_str()),atoi(results.at(2).c_str()) );
153 if(results.size()==5) {
154 jet.setEtaDouble( atof(results.at(3).c_str()) );
155 jet.setPhiDouble( atof(results.at(4).c_str()) );
156 }
157 m_event->addgJet( jet );
158 } else if(type == "<muon>") {
159 unsigned int et = atoi(results.at(0).c_str());
160 int eta = atoi(results.at(1).c_str());
161 int phi = atoi(results.at(2).c_str());
162 TCS::MuonTOB muon( et, 0, eta, static_cast<unsigned int>(phi) );
163 if(results.size()==5) {
164 muon.setEtaDouble( atof(results.at(3).c_str()) );
165 muon.setPhiDouble( atof(results.at(4).c_str()) );
166 }
167 m_event->addMuon( muon );
168 } else if(type == "<lateMuon>") {
169 unsigned int et = atoi(results.at(0).c_str());
170 int eta = atoi(results.at(1).c_str());
171 int phi = atoi(results.at(2).c_str());
172 TCS::LateMuonTOB latemuon( et, 0, eta, phi );
173 if(results.size()==5) {
174 latemuon.setEtaDouble( atof(results.at(3).c_str()) );
175 latemuon.setPhiDouble( atof(results.at(4).c_str()) );
176 }
177 m_event->addLateMuon( latemuon );
178 } else if(type == "<muonNextBC>") {
179 unsigned int et = atoi(results.at(0).c_str());
180 int eta = atoi(results.at(1).c_str());
181 int phi = atoi(results.at(2).c_str());
182 TCS::MuonNextBCTOB nextbcmuon( et, 0, eta, phi );
183 if(results.size()==5) {
184 nextbcmuon.setEtaDouble( atof(results.at(3).c_str()) );
185 nextbcmuon.setPhiDouble( atof(results.at(4).c_str()) );
186 }
187 m_event->addMuonNextBC( nextbcmuon );
188 } else if(type == "<met>") {
189 int ex = atoi(results.at(0).c_str());
190 int ey = atoi(results.at(1).c_str());
191 int et = atoi(results.at(2).c_str());
192 TCS::MetTOB met( ex, ey, et );
193 m_event->setMET( met );
194 } else if(type == "<info>") {
195 uint32_t runNo = atol(results.at(0).c_str());
196 uint32_t evtNo = atol(results.at(1).c_str());
197 uint32_t lumiB = atol(results.at(2).c_str());
198 uint32_t BCID = atol(results.at(3).c_str());
199 m_event->setEventInfo(runNo, evtNo, lumiB, BCID);
200 } else {
201 TCS_EXCEPTION( "TOB for this event is of unknown type " << type<<": '"<<currentLine<<"'");
202
203 }
204 } // end read event
205
206 m_nEvents+=1;
207
208 return true;
209}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
float et(const xAOD::jFexSRJetRoI *j)
static Double_t ss
TCS::TopoInputEvent * m_event
double atof(std::string_view str)
Converts a string into a double / float.
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
setEventNumber uint32_t

◆ loadInput()

void TCS::TopoASCIIReader::loadInput ( const std::string & input)

Definition at line 24 of file TopoASCIIReader.cxx.

24 {
25 if(input=="") {
26 TCS_EXCEPTION("Specify the location of the ascii input file");
27 }
28
29 cout << "TopoASCIIReader: Opening file " << input << endl;
30 m_fs.open(input.c_str());
32}

◆ printEvent()

void TCS::TopoASCIIReader::printEvent ( )

Definition at line 211 of file TopoASCIIReader.cxx.

211 {
212 cout << "Print Event" << endl;
213 if(m_event != NULL) {
214 cout << *m_event << endl;
215 } else {
216 TCS_EXCEPTION( "event returns NULL value(s) wehn trying to print!" );
217 }
218}

◆ printFileSummary()

void TCS::TopoASCIIReader::printFileSummary ( )

Definition at line 220 of file TopoASCIIReader.cxx.

220 {
221 cout << "File summary for" << m_inputFile << endl;
222 cout << "Number of Events: " << m_nEvents << endl;
223}

◆ reset()

void TCS::TopoASCIIReader::reset ( )

Definition at line 225 of file TopoASCIIReader.cxx.

225 {
226 cout << "TopoASCIIReader reset" << endl;
227 m_fs.close();
228 m_inputFile="";
229 m_event=NULL;
230 m_verbosity=0;
231 m_nEvents=0;
232}

◆ setInputEvent()

void TCS::TopoASCIIReader::setInputEvent ( TCS::TopoInputEvent * evt)
inline

Definition at line 45 of file TopoASCIIReader.h.

◆ setVerbosity()

void TCS::TopoASCIIReader::setVerbosity ( int verbosity)
inline

Definition at line 43 of file TopoASCIIReader.h.

◆ validateInput()

void TCS::TopoASCIIReader::validateInput ( )

Definition at line 34 of file TopoASCIIReader.cxx.

34 {
35 if(!m_fs) {
36 TCS_EXCEPTION("Error opening input file!");
37 } else {
38 cout << "File " << m_inputFile << " loaded and ready to parse." << endl;
39 }
40}

Member Data Documentation

◆ m_event

TCS::TopoInputEvent* TCS::TopoASCIIReader::m_event { nullptr }
private

Definition at line 63 of file TopoASCIIReader.h.

63{ nullptr };

◆ m_fs

std::ifstream TCS::TopoASCIIReader::m_fs
private

Definition at line 61 of file TopoASCIIReader.h.

◆ m_inputFile

std::string TCS::TopoASCIIReader::m_inputFile { "" }
private

Definition at line 62 of file TopoASCIIReader.h.

62{ "" };

◆ m_nEvents

int TCS::TopoASCIIReader::m_nEvents { 0 }
private

Definition at line 67 of file TopoASCIIReader.h.

67{ 0 };

◆ m_verbosity

int TCS::TopoASCIIReader::m_verbosity { 0 }
private

Definition at line 64 of file TopoASCIIReader.h.

64{ 0 };

The documentation for this class was generated from the following files: