ATLAS Offline Software
TopoASCIIReader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 // TopoASCIIReader.cpp
5 
7 
8 #include <iostream>
9 
10 using namespace std;
11 
12 // default constructor
14  m_verbosity(verbose)
15 {
16 }
17 
18 // destructor
20  m_fs.close();
21 }
22 
23 // load input file
24 void TCS::TopoASCIIReader::loadInput(const std::string & input) {
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());
31  m_inputFile = input;
32 }
33 
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 }
41 
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 }
210 
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 }
219 
221  cout << "File summary for" << m_inputFile << endl;
222  cout << "Number of Events: " << m_nEvents << endl;
223 }
224 
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 }
TCS::LateMuonTOB
Definition: LateMuonTOB.h:13
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
et
Extra patterns decribing particle interation process.
verify_menu_config.results
results
Definition: verify_menu_config.py:67
TCS::MuonNextBCTOB::setEtaDouble
void setEtaDouble(double eta)
Definition: MuonNextBCTOB.h:51
TCS::MuonTOB
Definition: MuonTOB.h:14
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
TCS::eTauTOB::setEtaDouble
void setEtaDouble(double eta)
Definition: eTauTOB.h:50
TCS::jEmTOB::setEtaDouble
void setEtaDouble(double eta)
Definition: jEmTOB.h:50
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TCS::jEmTOB::setPhiDouble
void setPhiDouble(double phi)
Definition: jEmTOB.h:51
TCS::TopoASCIIReader::reset
void reset()
Definition: TopoASCIIReader.cxx:225
TCS::MetTOB
Definition: MetTOB.h:13
TCS::eEmTOB::setRhad
void setRhad(unsigned int th)
Definition: eEmTOB.h:55
TCS::TopoASCIIReader::loadInput
void loadInput(const std::string &input)
Definition: TopoASCIIReader.cxx:24
TCS::TopoASCIIReader::~TopoASCIIReader
~TopoASCIIReader()
Definition: TopoASCIIReader.cxx:19
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TopoASCIIReader.h
TCS::MuonNextBCTOB::setPhiDouble
void setPhiDouble(double phi)
Definition: MuonNextBCTOB.h:52
TCS::TopoASCIIReader::TopoASCIIReader
TopoASCIIReader(int verbose=0)
Definition: TopoASCIIReader.cxx:13
TCS::eEmTOB::setWstot
void setWstot(unsigned int th)
Definition: eEmTOB.h:56
TCS::ClusterTOB::setPhiDouble
void setPhiDouble(double phi)
Definition: ClusterTOB.h:51
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
TCS::ClusterTOB::setEtaDouble
void setEtaDouble(double eta)
Definition: ClusterTOB.h:50
TCS::eTauTOB::setRCore
void setRCore(unsigned int th)
Definition: eTauTOB.h:53
PixelByteStreamErrors::BCID
@ BCID
Definition: PixelByteStreamErrors.h:13
TCS::TopoASCIIReader::printFileSummary
void printFileSummary()
Definition: TopoASCIIReader.cxx:220
TCS::jJetTOB
Definition: jJetTOB.h:16
met
Definition: IMETSignificance.h:24
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
TCS::eTauTOB
Definition: eTauTOB.h:13
TCS::jLJetTOB
Definition: jLJetTOB.h:16
TCS::TopoASCIIReader::getNextEvent
bool getNextEvent()
Definition: TopoASCIIReader.cxx:42
TCS::eEmTOB
Definition: eEmTOB.h:13
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
TCS::jTauTOB
Definition: jTauTOB.h:16
TCS::MuonNextBCTOB
Definition: MuonNextBCTOB.h:13
TCS_EXCEPTION
#define TCS_EXCEPTION(MSG)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Exception.h:14
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
TCS::TopoASCIIReader::validateInput
void validateInput()
Definition: TopoASCIIReader.cxx:34
TCS::eEmTOB::setReta
void setReta(unsigned int th)
Definition: eEmTOB.h:54
TCS::jTauTOB::setPhiDouble
void setPhiDouble(double phi)
Definition: jTauTOB.h:49
TCS::eEmTOB::setPhiDouble
void setPhiDouble(double phi)
Definition: eEmTOB.h:52
TCS::gLJetTOB
Definition: gLJetTOB.h:18
TCS::jEmTOB
Definition: jEmTOB.h:16
TCS::LateMuonTOB::setEtaDouble
void setEtaDouble(double eta)
Definition: LateMuonTOB.h:66
TCS::eEmTOB::setEtaDouble
void setEtaDouble(double eta)
Definition: eEmTOB.h:51
TCS::gJetTOB
Definition: gJetTOB.h:18
TCS::eTauTOB::setRHad
void setRHad(unsigned int th)
Definition: eTauTOB.h:54
TCS::JetTOB
Definition: JetTOB.h:18
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
TCS::eTauTOB::setPhiDouble
void setPhiDouble(double phi)
Definition: eTauTOB.h:51
TCS::ClusterTOB
Definition: ClusterTOB.h:13
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
TCS::LateMuonTOB::setPhiDouble
void setPhiDouble(double phi)
Definition: LateMuonTOB.h:67
TCS::TopoASCIIReader::printEvent
void printEvent()
Definition: TopoASCIIReader.cxx:211
TCS::jTauTOB::setEtaDouble
void setEtaDouble(double eta)
Definition: jTauTOB.h:48