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