ATLAS Offline Software
BSFilePeeker.cxx
Go to the documentation of this file.
1 //Dear emacs, this is -*-c++-*-
2 /*
3  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4 */
5 
6 #include <iostream>
7 #include <string>
8 #include <unistd.h>
9 #include "EventStorage/pickDataReader.h"
10 #include "FileMetaData.h"
12 
13 class BSFilePeeker {
14 
15 public:
16  BSFilePeeker(const std::string& filename);
17 
18  const FileMetaData& get() const {return m_fmd;}
19 
20 private:
21 
22  bool extractValue(const std::string& source, const std::string& key, std::string& value);
23 
25 
26 };
27 
28 
29 bool BSFilePeeker::extractValue(const std::string& source, const std::string& key, std::string& value) {
30 
31  const size_t sep=source.find(':');
32  if (sep==std::string::npos || source.compare(0,sep,key)!=0) {
33  return false;
34  }
35  else {
36  value=source.substr(sep+1);
37  return true;
38  }
39 }
40 
41 BSFilePeeker::BSFilePeeker(const std::string& fName) {
42 
44  DataReader *pDR = pickDataReader(fName);
45 
46  if(!pDR) {
47  std::cerr << "Problem opening or reading the bytestream file "
48  << fName << std::endl;
49  return;
50  }
51 
52  if(!pDR->good()) {
53  std::cerr << "No events in file "<< fName << std::endl;
54  }
55 
56  m_fmd.m_runNumbers.insert(pDR->runNumber());
57  m_fmd.m_lbNumbers.insert(pDR->lumiblockNumber());
58  m_fmd.m_project=pDR->projectTag();
59  m_fmd.m_stream=pDR->stream();
60  m_fmd.m_nEvents=pDR->eventsInFile();
61  m_fmd.m_beamEnergy=pDR->beamEnergy()*1000;
62  m_fmd.m_guid=pDR->GUID();
63 
64  const unsigned bt=pDR->beamType();
65 
66  //Accoring to info from Rainer and Guiseppe the beam type is
67  //0: No beam
68  //1: protons
69  //2: ions
70  switch (bt) {
71  case 0:
72  m_fmd.m_beamType="cosmics";
73  break;
74  case 1:
75  case 2: //actally heavy-ion
76  m_fmd.m_beamType="collisions";
77  break;
78  default:
79  std::cerr << "WARNING: Unexpected beam type integer in BS file. Got " << bt << std::endl;
80  m_fmd.m_beamType="unknown";
81  }
82 
83 
84  m_fmd.m_isMC=false; //Generaly, BS-files are real data
85  const std::vector<std::string> fmds=pDR->freeMetaDataStrings();
86  std::string eventTypeMD;
87  for (const std::string& fm : fmds) {
88  extractValue(fm,"GeoAtlas",m_fmd.m_geoTag);
89  extractValue(fm,"IOVDbGlobalTag",m_fmd.m_condTag);
90  extractValue(fm,"Event type",eventTypeMD);
91  }
92 
93  if (eventTypeMD.find("is sim")!=std::string::npos) {
94  m_fmd.m_isMC=true; //This is a simulated bytestream file
95  }
96 
97 
98  m_fmd.m_valid=true;
99  delete pDR;
100 }
101 
102 
103 int main ATLAS_NOT_THREAD_SAFE (int argc, char** argv) {
104 
105  bool verbose=false;
106  bool kvDump=false;
107  int c;
108 
109  while ((c = getopt (argc, argv, "vk")) != -1) {
110  switch (c) {
111  case 'v':
112  verbose=true;
113  break;
114  case 'k':
115  kvDump=true;
116  break;
117  default:
118  std::cerr << "Unkown command line option" << std::endl;
119  return -1;
120  }
121  }
122 
123 
124  const int nfiles=argc-optind;
125  if (nfiles<=0) {
126  std::cerr << "Expected at least one file name as parameter" << std::endl;
127  return -1;
128  }
129 
130 
131  std::vector<FileMetaData> output;
132 
133  for (int iFile=optind;iFile<argc;++iFile) {
134  const std::string filename(argv[iFile]);
135  if (verbose) std::cout << "Checking file " << filename << std::endl;
136 
137  BSFilePeeker bsfp(filename);
138 
139  output.push_back(bsfp.get());
140  }//end loop over input file names
141 
142 
143  if (kvDump) {
144  for (const auto& o : output) o.keyValueDump();
145  }
146  else {
147  for (const auto& o : output) o.dump();
148  }
149 
150  return 0;
151 }
FileMetaData::m_lbNumbers
std::set< unsigned > m_lbNumbers
Definition: Tools/FilePeeker/src/FileMetaData.h:19
BSFilePeeker
Definition: BSFilePeeker.cxx:13
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
rootconvert.fName
string fName
Definition: rootconvert.py:5
FileMetaData
Definition: Tools/FilePeeker/src/FileMetaData.h:14
athena.value
value
Definition: athena.py:124
FileMetaData::m_beamType
std::string m_beamType
Definition: Tools/FilePeeker/src/FileMetaData.h:33
main
int main(int, char **)
Main class for all the CppUnit test classes
Definition: CppUnit_SGtestdriver.cxx:141
FileMetaData::m_beamEnergy
unsigned m_beamEnergy
Definition: Tools/FilePeeker/src/FileMetaData.h:32
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
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
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
FileMetaData.h
BSFilePeeker::get
const FileMetaData & get() const
Definition: BSFilePeeker.cxx:18
merge.output
output
Definition: merge.py:17
grepfile.sep
sep
Definition: grepfile.py:38
ATLAS_NOT_THREAD_SAFE
int main ATLAS_NOT_THREAD_SAFE(int argc, char **argv)
Definition: BSFilePeeker.cxx:103
BSFilePeeker::m_fmd
FileMetaData m_fmd
Definition: BSFilePeeker.cxx:24
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
BSFilePeeker::extractValue
bool extractValue(const std::string &source, const std::string &key, std::string &value)
Definition: BSFilePeeker.cxx:29
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
FileMetaData::m_condTag
std::string m_condTag
Definition: Tools/FilePeeker/src/FileMetaData.h:24
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
copySelective.source
string source
Definition: copySelective.py:32
FileMetaData::m_fileName
std::string m_fileName
Definition: Tools/FilePeeker/src/FileMetaData.h:17
FileMetaData::m_runNumbers
std::set< unsigned > m_runNumbers
Definition: Tools/FilePeeker/src/FileMetaData.h:18
BSFilePeeker::BSFilePeeker
BSFilePeeker(const std::string &filename)
Definition: BSFilePeeker.cxx:41
FileMetaData::m_nEvents
unsigned m_nEvents
Definition: Tools/FilePeeker/src/FileMetaData.h:30
checker_macros.h
Define macros for attributes used to control the static checker.
python.compressB64.c
def c
Definition: compressB64.py:93
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37