ATLAS Offline Software
Loading...
Searching...
No Matches
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
14
15public:
16 BSFilePeeker(const std::string& filename);
17
18 const FileMetaData& get() const {return m_fmd;}
19
20private:
21
22 bool extractValue(const std::string& source, const std::string& key, std::string& value);
23
25
26};
27
28
29bool 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
41BSFilePeeker::BSFilePeeker(const std::string& fName) {
42
43 m_fmd.m_fileName=fName;
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
103int 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}
int main(int, char **)
Main class for all the CppUnit test classes.
Define macros for attributes used to control the static checker.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
bool extractValue(const std::string &source, const std::string &key, std::string &value)
BSFilePeeker(const std::string &filename)
FileMetaData m_fmd
const FileMetaData & get() const
bool verbose
Definition hcg.cxx:73