ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PoolFilePeeker Class Reference
Collaboration diagram for PoolFilePeeker:

Public Member Functions

 PoolFilePeeker (const char *tf, const bool vbs=false)
 
const FileMetaDataget () const
 

Private Member Functions

template<typename T >
bool findBranch (TBranch *br, const std::string &nametag, const std::string &type, std::pair< bool, T * > &destination) const
 

Private Attributes

FileMetaData m_fmd
 

Detailed Description

Definition at line 29 of file PoolFilePeeker.cxx.

Constructor & Destructor Documentation

◆ PoolFilePeeker()

PoolFilePeeker::PoolFilePeeker ( const char *  tf,
const bool  vbs = false 
)

Definition at line 67 of file PoolFilePeeker.cxx.

67  {
68 
69 
71 
73  std::unique_ptr<TFile> tf(TFile::Open(filename));
74  if (!tf || tf->IsZombie()) {
75  std::cerr << "Failed to open file " << filename << std::endl;
76  return;
77  }
79 
80  if (vbs) std::cout << "Time to open input file: " << std::chrono::duration_cast<std::chrono::milliseconds>(stop-start).count() << " msec" << std::endl;
81 
82 
83  TTree* md=(TTree*)tf->Get("MetaData");
84 
85  if (!md) return;
86 
87  std::pair<bool,EventStreamInfo_p3*> esi{false,nullptr};
88  std::pair<bool,EventStreamInfo_p2*> esi2{false,nullptr};
89  std::pair<bool,IOVMetaDataContainer_p1*> taginfo{false,nullptr};
90  std::pair<bool,IOVMetaDataContainer_p1*> genparam{false,nullptr};
91  std::pair<bool,IOVMetaDataContainer_p1*> simparam{false,nullptr};
92  std::pair<bool,IOVMetaDataContainer_p1*> digiparam{false,nullptr};
93 #ifndef SIMULATIONBASE
94  std::pair<bool,ByteStreamMetadataContainer_p1*> bmdc{false,nullptr};
95 #endif // not SIMULATIONBASE
96  TObjArray* mdBranches=md->GetListOfBranches();
97  const size_t mdnBranches=mdBranches->GetEntriesFast();
98  for (size_t i=0;i<mdnBranches;++i) {
99  TBranch* br=(TBranch*)mdBranches->At(i);
100  if (vbs) std::cout << "Branch "<< br->GetName() << " of type " << br->GetClassName() << std::endl;
101 #ifndef SIMULATIONBASE
102  if (findBranch(br,"ByteStreamMetadata","ByteStreamMetadataContainer_p1",bmdc)) continue;
103 #endif // not SIMULATIONBASE
104  if (findBranch(br,"_TagInfo","IOVMetaDataContainer_p1",taginfo)) continue;
105  if (findBranch(br,"_Generation_Parameters","IOVMetaDataContainer_p1",genparam)) continue;
106  if (findBranch(br,"_Simulation_Parameters","IOVMetaDataContainer_p1",simparam)) continue;
107  if (findBranch(br,"_Digitization_Parameters","IOVMetaDataContainer_p1",digiparam)) continue;
108  if (findBranch(br,"Stream","EventStreamInfo_p3",esi)) continue;
109  if (findBranch(br,"Stream","EventStreamInfo_p2",esi2)) continue;
110  }//end loop over branches
111 
112 
113  //Get the event!
114  md->GetEntry(0);
115 
116  m_fmd.m_valid=true;
117 
118  if (genparam.first) {
119  if (vbs) std::cout << " Got IOVMetaDataContainer for /Generation/Parameters " << std::endl;
120  for (const auto& idx : genparam.second->m_payload.m_attrIndexes) {
121  const unsigned short nameIdx=idx.nameIndex();
122  if (idx.typeIndex()==IOVPayloadContainer_p1::ATTR_STRING) {
123  const unsigned short iObj=idx.objIndex();
124  const std::string objKey=genparam.second->m_payload.m_attrName[nameIdx];
125  const std::string objValue=genparam.second->m_payload.m_string[iObj];
126  if (vbs) std::cout << "Genparam: " << objKey << " : " << objValue << std::endl;
127 
128  }
129  }//end loop over genparam
130  delete genparam.second;
131  genparam.second=nullptr;
132  }//end if have genparam
133 
134  if (simparam.first) {
135  if (vbs) std::cout << " Got IOVMetaDataContainer for /Simulation/Parameters " << std::endl;
136  for (const auto& idx : simparam.second->m_payload.m_attrIndexes) {
137  const unsigned short nameIdx=idx.nameIndex();
138  if (idx.typeIndex()==IOVPayloadContainer_p1::ATTR_STRING) {
139  const unsigned short iObj=idx.objIndex();
140  const std::string objKey=simparam.second->m_payload.m_attrName[nameIdx];
141  const std::string objValue=simparam.second->m_payload.m_string[iObj];
142  if (vbs) std::cout << "Simparam: " << objKey << " : " << objValue << std::endl;
143  if (objKey=="TRTRangeCut") {
144  std::string::size_type sz; // alias of size_t
145  m_fmd.m_trtRangeCut=std::stod(objValue,&sz);
146  }
147  if (objKey=="beamType") {
148  m_fmd.m_beamType=objValue;
149  }
150 
151  }
152  }//end loop over simparam
153  delete simparam.second;
154  simparam.second=nullptr;
155  }//end if have simparam
156 
157  if (digiparam.first) {
158  if (vbs) std::cout << " Got IOVMetaDataContainer for /Digitization/Parameters " << std::endl;
159  for (const auto& idx : digiparam.second->m_payload.m_attrIndexes) {
160  const unsigned short nameIdx=idx.nameIndex();
161  if (idx.typeIndex()==IOVPayloadContainer_p1::ATTR_STRING) {
162  const unsigned short iObj=idx.objIndex();
163  const std::string objKey=digiparam.second->m_payload.m_attrName[nameIdx];
164  const std::string objValue=digiparam.second->m_payload.m_string[iObj];
165  if (vbs) std::cout << "Digiparam: " << objKey << " : " << objValue << std::endl;
166  if (objKey=="IOVDbGlobalTag") {
167  m_fmd.m_condTag=objValue;
168  }
169  if (objKey=="DetDescrVersion") {
170  m_fmd.m_geoTag=objValue;
171  }
172  if (objKey=="beamType") {
173  m_fmd.m_beamType=objValue;
174  }
175 
176  }
177  }//end loop over digiparam
178  delete digiparam.second;
179  digiparam.second=nullptr;
180  }//end if have digiparam
181 
182  if (taginfo.first) {
183  if (vbs) std::cout << " Got IOVMetaDataContainer for TagInfo " << std::endl;
184  for (const auto& idx : taginfo.second->m_payload.m_attrIndexes) {
185  //const unsigned short typeIdx=idx.typeIndex();
186  const unsigned short nameIdx=idx.nameIndex();
187  if (idx.typeIndex()==IOVPayloadContainer_p1::ATTR_STRING) {
188  const unsigned short iObj=idx.objIndex();
189  const std::string objKey=taginfo.second->m_payload.m_attrName[nameIdx];
190  const std::string objValue=taginfo.second->m_payload.m_string[iObj];
191  if (vbs) std::cout << "Taginfo: " << objKey << " : " << objValue << std::endl;
192  if (objKey=="IOVDbGlobalTag") {
193  m_fmd.m_condTag=objValue;
194  }
195  if (objKey=="GeoAtlas") {
196  m_fmd.m_geoTag=objValue;
197  }
198  if (objKey=="beam_energy") {
199  m_fmd.m_beamEnergy=atoi(objValue.c_str());
200  }
201  if (objKey=="beam_type") {
202  m_fmd.m_beamType=objValue;
203  }
204 
205  }
206  }//end loop over taginfo
207  delete taginfo.second;
208  taginfo.second=nullptr;
209  }//end if have taginfo
210 
211  if (esi.first) {
212  if (vbs) std::cout << " Got EventStreamInfo_p3" << std::endl;
213  m_fmd.m_runNumbers.insert(esi.second->m_runNumbers.begin(),
214  esi.second->m_runNumbers.end());
215  m_fmd.m_lbNumbers.insert(esi.second->m_lumiBlockNumbers.begin(),
216  esi.second->m_lumiBlockNumbers.end());
217 
218 
219 
220  const std::vector<std::pair<unsigned int, std::string> >& itemList=esi.second->m_itemList;
221  for (const auto& kw : itemList) {
222  m_fmd.m_sgKeys.push_back(kw.second);
223  }
224 
225  delete esi.second;
226  esi.second=nullptr;
227 
228  }
229  else if (esi2.first) { //Have legacy version of EventStreamInfo
230  m_fmd.m_valid=true;
231  if (vbs) std::cout << " Got legacy EventStreamInfo_p2" << std::endl;
232  m_fmd.m_runNumbers.insert(esi2.second->m_runNumbers.begin(),
233  esi2.second->m_runNumbers.end());
234  m_fmd.m_lbNumbers.insert(esi.second->m_lumiBlockNumbers.begin(),
235  esi2.second->m_lumiBlockNumbers.end());
236  delete esi2.second;
237  esi2.second=nullptr;
238  }
239 
240 
241  std::set<unsigned> bmc_runNumbers;
242 #ifndef SIMULATIONBASE
243  if (bmdc.first) {
244  if (vbs) std::cout << " Got ByteStreamMetadataContainer" << std::endl;
245  m_fmd.m_isMC=false; //The presence of a ByteStreamMetaDataContainer indicates real data
246  for (const auto& bmd : *bmdc.second) {
247  bmc_runNumbers.insert(bmd.m_runNumber);
248  if (m_fmd.m_stream.size()==0) {
249  m_fmd.m_stream=bmd.m_stream;
250  }
251  else if (m_fmd.m_stream!=bmd.m_stream) {
252  std::cerr << "Conflicting stream names in file! Got " <<
253  m_fmd.m_stream << " and " << bmd.m_stream << std::endl;
254  m_fmd.m_valid=false;
255  }
256  if (m_fmd.m_project.size()==0) {
257  m_fmd.m_project=bmd.m_project;
258  }
259  else if (m_fmd.m_project!=bmd.m_project) {
260  std::cerr << "Conflicting project names in file! Got " <<
261  m_fmd.m_project << " and " << bmd.m_project << std::endl;
262  m_fmd.m_valid=false;
263  }
264 
265  const std::vector<std::string>& freeMDs=bmd.m_freeMetaDataStrings;
266  for (const std::string& freeMD : freeMDs) {
267  if (freeMD.compare(0,11,"Event type:")==0 && freeMD.find("is sim")!=std::string::npos) {
268  m_fmd.m_isMC=true; //This is made of a simulated bytestream file
269  break;
270  }
271  }
272  }
273  delete bmdc.second;
274  bmdc.second=nullptr;
275  }//end if have ByteStream Meta Data
276 #endif // not SIMULATIONBASE
277 
278  //We may have gotten run-numbers twice (once form ByteStream MD and once form EventStreamInfo)
279  //Cross-check:
280  if (m_fmd.m_runNumbers.size()==0 && bmc_runNumbers.size()) {
281  //Unlikly case, run-number only via ByteStream metadata
282  m_fmd.m_runNumbers=std::move(bmc_runNumbers);
283  }
284  else if (m_fmd.m_runNumbers.size() && bmc_runNumbers.size()) {
285  //Both filled - cross-check!
286  if (m_fmd.m_runNumbers != bmc_runNumbers) {
287  std::cerr << "Mismatching run numbers in file metadata!" << std::endl;
288  std::cerr << "EventStreamInfo: ";
289  std::copy(m_fmd.m_runNumbers.begin(),m_fmd.m_runNumbers.end(),std::ostream_iterator<unsigned>(std::cerr, " "));
290  std::cerr << std::endl;
291  std::cerr << "ByteStreamEventInfo: ";
292  std::copy(bmc_runNumbers.begin(),bmc_runNumbers.end(),std::ostream_iterator<unsigned>(std::cerr, " "));
293  std::cerr << std::endl;
294  m_fmd.m_valid=false;
295  }
296  }
297 
298  //Get the GUID:
299  TTree* params=(TTree*)tf->Get("##Params");
300  const unsigned nParamsEntries=params->GetEntries();
301 
302  char dbStr[1024];
303  params->SetBranchAddress("db_string",&dbStr);
304 
305  const std::string starter("[NAME=FID][VALUE=");
306  for (unsigned i=0;i<nParamsEntries;++i) {
307  params->GetEntry(i);
308  //Model: [NAME=FID][VALUE=41DB894B-C39C-BF47-81E9-C52658B117BF]
309  const std::string field(dbStr);
310 
311  if (field.compare(starter)) {
312  m_fmd.m_guid=field.substr(starter.size(),field.size()-starter.size()-1);
313  break;
314  }
315  }//end loop over params-entries
316 
317  //Get number of events for CollectionTree
318  TTree* tt=(TTree*)tf->Get("CollectionTree");
319  if (!tt) {
320  std::cerr << "Failed to read collectionTree" << std::endl;
321  m_fmd.m_valid=false;
322  }
323  else {
324  m_fmd.m_nEvents=tt->GetEntries();
325  }
326 
327  return;
328 }

Member Function Documentation

◆ findBranch()

template<typename T >
bool PoolFilePeeker::findBranch ( TBranch *  br,
const std::string &  nametag,
const std::string &  type,
std::pair< bool, T * > &  destination 
) const
private

Definition at line 48 of file PoolFilePeeker.cxx.

49  {
50  const std::string brName(br->GetName());
51  const std::string brType(br->GetClassName());
52  if (brName.find(nametag)!=std::string::npos && brType==type) {
53  if (destination.first) {
54  std::cerr << "WARNING: Found more than one " << type << " labelled '" << nametag << "'. Ignoring " << brName << std::endl;
55  }
56  else {
57  destination.first=true;
58  br->SetAddress(&destination.second);
59  }
60  return true;
61  }
62  else
63  return false;
64 }

◆ get()

const FileMetaData& PoolFilePeeker::get ( ) const
inline

Definition at line 34 of file PoolFilePeeker.cxx.

34 {return m_fmd;}

Member Data Documentation

◆ m_fmd

FileMetaData PoolFilePeeker::m_fmd
private

Definition at line 41 of file PoolFilePeeker.cxx.


The documentation for this class was generated from the following file:
FileMetaData::m_lbNumbers
std::set< unsigned > m_lbNumbers
Definition: Tools/FilePeeker/src/FileMetaData.h:19
fitman.sz
sz
Definition: fitman.py:527
checkxAOD.brName
brName
Definition: Tools/PyUtils/bin/checkxAOD.py:125
FileMetaData::m_isMC
bool m_isMC
Definition: Tools/FilePeeker/src/FileMetaData.h:37
FileMetaData::m_guid
std::string m_guid
Definition: Tools/FilePeeker/src/FileMetaData.h:28
PoolFilePeeker::findBranch
bool findBranch(TBranch *br, const std::string &nametag, const std::string &type, std::pair< bool, T * > &destination) const
Definition: PoolFilePeeker.cxx:48
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
FileMetaData::m_beamType
std::string m_beamType
Definition: Tools/FilePeeker/src/FileMetaData.h:33
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
python.handimod.now
now
Definition: handimod.py:675
FileMetaData::m_beamEnergy
unsigned m_beamEnergy
Definition: Tools/FilePeeker/src/FileMetaData.h:32
lumiFormat.i
int i
Definition: lumiFormat.py:85
FileMetaData::m_trtRangeCut
double m_trtRangeCut
Definition: Tools/FilePeeker/src/FileMetaData.h:35
FileMetaData::m_geoTag
std::string m_geoTag
Definition: Tools/FilePeeker/src/FileMetaData.h:25
FileMetaData::m_stream
std::string m_stream
Definition: Tools/FilePeeker/src/FileMetaData.h:22
FileMetaData::m_sgKeys
std::vector< std::string > m_sgKeys
Definition: Tools/FilePeeker/src/FileMetaData.h:41
PoolFilePeeker::m_fmd
FileMetaData m_fmd
Definition: PoolFilePeeker.cxx:41
FileMetaData::m_project
std::string m_project
Definition: Tools/FilePeeker/src/FileMetaData.h:21
FileMetaData::m_valid
bool m_valid
Definition: Tools/FilePeeker/src/FileMetaData.h:39
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
FileMetaData::m_condTag
std::string m_condTag
Definition: Tools/FilePeeker/src/FileMetaData.h:24
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
IOVPayloadContainer_p1::ATTR_STRING
@ ATTR_STRING
Definition: IOVPayloadContainer_p1.h:45
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
calibdata.copy
bool copy
Definition: calibdata.py:27
FileMetaData::m_fileName
std::string m_fileName
Definition: Tools/FilePeeker/src/FileMetaData.h:17
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
FileMetaData::m_runNumbers
std::set< unsigned > m_runNumbers
Definition: Tools/FilePeeker/src/FileMetaData.h:18
FileMetaData::m_nEvents
unsigned m_nEvents
Definition: Tools/FilePeeker/src/FileMetaData.h:30
TileDCSDataPlotter.tt
tt
Definition: TileDCSDataPlotter.py:874
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355