ATLAS Offline Software
Loading...
Searching...
No Matches
iLumiCalc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "iLumiCalc.h"
6
9
12#include "StorageSvc/DbType.h"
13
15
16#include "TTree.h"
17#include "TList.h"
18#include "TObjString.h"
19#include "TString.h"
20#include <TKey.h>
21
22#include <typeinfo>
23#include <list>
24
25// ToDo: make this whole code in
26// object oriented way...
27
28
29//______________________________________________________________
31
32 std::cout << std::endl;
33 std::cout << " --->>> i L U M I C A L C <<<---"<< std::endl;
34 std::cout << std::endl;
35 std::cout << "iLumiCalc: this c++ program calculates integrated luminosity" << std::endl ;
36 std::cout << "by looping over a list of lumiblocks, given a set of input options." << std::endl;
37 std::cout << "Input file can be either an xml file, or a TAG file." << std::endl;
38 std::cout << std::endl;
39 std::cout << "Type: iLumiCalc --help for the complete list of options" << std::endl ;
40 std::cout << std::endl;
41 std::cout << "Further help: https://twiki.cern.ch/twiki/bin/view/Atlas/CoolLumiCalc"<< std::endl;
42 std::cout << std::endl;
43 exit(-1);
44
45}
46
47//______________________________________________________________________________
48// coverity[uncaught_except]
49int main(int argc, char * argv[]){
50
51 if (argc == 1)print_usage();
52
53 // schedule for time info
54 TStopwatch timer;
55 timer.Start();
56
57 // Parse command-line options
58 // ==========================
59
60 gengetopt_args_info args_info;
61 cmdline_parser (argc, argv, &args_info);
62
63 // Output Level
64 bool verbose = args_info.verbose_flag;
65 bool quiet = args_info.quiet_flag;
66 if (verbose && quiet) {
67 logger << Root::kWARNING << "Can't specify verbose and quiet, using verbose" << Root::GEndl;
68 quiet = false;
69 }
70
73
74 // Other flags
75 bool makeplots = args_info.plots_flag;
76 bool collisionlists = args_info.xml_collisionlist_flag;
77
78 // parse for any output xml file name
79 xmloutfile = "";
80 if(args_info.xml_out_given){
81 xmloutfile = args_info.xml_out_arg;
82 }
83
84 //
85 // Parameters to control luminosty calculation
86 // ===========================================
87
88 float scalel1trigrate = float(args_info.scale_lumi_arg); // = 1 by default
89 if (scalel1trigrate != 1.) {
90 logger << Root::kWARNING << "Luminoisty scaled by factor: " << scalel1trigrate << Root::GEndl;
91 }
92
93 // Use online folder
94 bool online = args_info.online_flag;
95 if (online) {
96 logger << Root::kINFO << "Luminosity read from online folders" << Root::GEndl;
97 }
98
99 // Luminosity tag
100 std::string lumitag = args_info.lumitag_arg;
101 if (online) {
102 logger << Root::kWARNING << "Lumitag: " << lumitag << " ignored due to --online " << Root::GEndl;
103 } else {
104 logger << Root::kINFO << "Lumitag: " << lumitag << Root::GEndl;
105 }
106
107 // LAr noise bursts
108 bool uselar = args_info.lar_flag;
109 std::string lartag = args_info.lartag_arg;
110 if (uselar) {
111 logger << Root::kINFO << "LAr noise burst inefficiency will be calculated from " << lartag << Root::GEndl;
112 }
113
114 // Online Beamspot validity
115 bool usebeamspot = args_info.beamspot_flag;
116 std::string beamspottag = args_info.beamspottag_arg;
117 if (usebeamspot) {
118 logger << Root::kINFO << "Livetime will include online beamspot validity requirement from " << beamspottag << Root::GEndl;
119 }
120
121 // Luminosity channel
122 // ==================
123
124 std::string lumimethod;
125 int lumichannel = -1;
126
127 // Check for online exceptions
128 if (online && args_info.lumimethod_given){
129 logger << Root::kERROR << "Sorry, the online database doesn't have luminosity method names, use --lumichannel instead!" << Root::GEndl;
130 exit(-1);
131 }
132
133 if (args_info.lumimethod_given && args_info.lumichannel_given == 0) {
134 lumimethod = args_info.lumimethod_arg;
135 logger << Root::kINFO << "Lumimethod: " << lumimethod << Root::GEndl;
136 } else if (args_info.lumimethod_given == 0 && args_info.lumichannel_given) {
137 lumichannel = args_info.lumichannel_arg;
138 logger << Root::kINFO << "Lumichannel: " << lumichannel << Root::GEndl;
139 } else if (args_info.lumimethod_given && args_info.lumichannel_given) {
140 lumichannel = args_info.lumichannel_arg;
141 logger << Root::kINFO << "Both lumimethod and lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
142 } else if (args_info.lumimethod_given == 0 && args_info.lumichannel_given == 0) {
143 if (online) {
144 lumichannel = args_info.lumichannel_arg;
145 logger << Root::kINFO << "No lumimethod or lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
146 } else {
147 lumimethod = args_info.lumimethod_arg;
148 logger << Root::kINFO << "No lumimethod or lumichannel is given, defaulting to Lumimethod: " << lumimethod << Root::GEndl;
149 }
150 }
151
152
153 // Handle triggers
154 // ===============
155 if(args_info.trigger_given == 0) {
156 logger << Root::kINFO << "No trigger specified, proceeding with --trigger=None" << Root::GEndl;
157 triggerchain.push_back("None");
158 } else {
159 if (args_info.trigger_given > 1) {
160 logger << Root::kINFO << "Processing Triggers: ";
161 } else {
162 logger << Root::kINFO << "Processing Trigger: ";
163 }
164
165 for(unsigned int i = 0; i < args_info.trigger_given; ++i){
166 triggerchain.push_back(args_info.trigger_arg[i]);
167 logger << Root::kINFO << args_info.trigger_arg[i] << ", ";
168 }
169 logger << Root::GEndl;
170 }
171
172 // Livetime triggers
173 // =================
174 bool uselivetrigger = false;
175 livetrigger = args_info.livetrigger_arg; // Default if not specified on command line
176
177 if (args_info.livetrigger_given || !args_info.trigger_given) {
178 // Either livetime trigger specified, or no prescale triggers specified
179 uselivetrigger = true;
180 logger << Root::kINFO << "Trigger used for livetime: " << livetrigger << Root::GEndl;
181 } else {
182 // Prescale not specified AND trigger list given
183 logger << Root::kINFO << "Prescale trigger chains will be used for livetime " << Root::GEndl;
184 }
185
186
187 // Parse the run number list
188 // =========================
189
190 // Run list has pair of first, last allowed run inclusive
191 std::list<std::pair<unsigned int, unsigned int> > runList;
192 runList.clear();
193
194 // Comma-separated lists already get split by options parser. Just need to look for ranges here.
195 for (unsigned int i=0; i<args_info.runnumber_given; i++) {
196
197 // Split by hyphens to find run range
198 std::string full(args_info.runnumber_arg[i]);
199
200 size_t found = full.find('-');
201
202 unsigned int val1, val2;
203 if (found != std::string::npos) {
204 val1 = atoi(full.substr(0, found).c_str());
205 val2 = atoi(full.substr(found+1, std::string::npos).c_str());
206 } else {
207 val1 = atoi(full.c_str());
208 val2 = val1;
209 }
210 if (val1 == 0) val1 = minrunnum; // Set to min run number
211 if (val2 == 0) val2 = maxrunnum; // Set to max run number
212
213 // std::cout << "Parsed [" << full << "] into (" << val1 << ", " << val2 << ")" << std::endl;
214 runList.push_back( std::pair<unsigned int, unsigned int>(val1, val2) );
215 }
216
217 // std::cout << "Parsed Run List:" << std::endl;
218 // for (std::list<std::pair<unsigned int, unsigned int> >::iterator it = runList.begin(); it != runList.end(); it++)
219 // std::cout << it->first << " " << it->second << std::endl;
220
221 // Now determine the input data source
222 // ===================================
223
224 // what shall be the resource for LumiBlockCollection
225 unsigned int runtype = 0; // 0 - no input file --> COOL, 1 - TAG input file, 2 - AOD input file, 3 - XML input file, 4 - ROOT input file
226
227 // TAG File
228 //============================================
229 if(args_info.tag_given > 0 && args_info.xml_given == 0 && args_info.root_given == 0){
230 runtype = 1;
231 std::cout << args_info.tag_given << " TAG file(s) is given..." << std::endl;
232 for(unsigned int i = 0; i < args_info.tag_given; ++i){
233 tagfile.push_back(args_info.tag_arg[i]);
234 }
235 // Try to see if file(s) exist
236 for(std::vector<std::string>::iterator it = tagfile.begin(); it != tagfile.end(); ++it){
237 if(!FileExists((*it))){
238 logger << Root::kWARNING << "Problem: file ["<< (*it) <<"] may not exist. Will try anyways..." << Root::GEndl;
239 }
240 }
241 //std::cout << "RunType: " << runtype << std::endl;
242
243 }
244
245 // XML File
246 //============================================
247 if(args_info.tag_given == 0 && args_info.xml_given > 0 && args_info.root_given == 0){
248 runtype = 3;
249 for(unsigned int i = 0; i < args_info.xml_given; ++i){
250 xmlfile.push_back(args_info.xml_arg[i]);
251 }
252 // Try to see if file(s) exist
253 for(std::vector<std::string>::iterator it = xmlfile.begin(); it != xmlfile.end(); ++it){
254 if(! FileExists((*it))){
255 logger << Root::kWARNING << "Problem: file ["<< (*it) <<"] may not exist. Will try anyways..." << Root::GEndl;
256 }
257 }
258 //std::cout << "RunType: " << runtype << std::endl;
259 }
260
261 // ROOT File -- ttree attached mode
262 //============================================
263 if((args_info.root_given >0 || args_info.tree_given > 0) && args_info.d3pd_dir_given == 0 && args_info.xml_given == 0 && args_info.tag_given == 0){
264 if((args_info.root_given == 0 && args_info.tree_given > 0) || (args_info.root_given > 0 && args_info.tree_given == 0 )){
265 logger << Root::kERROR << "Please provide BOTH --root=\"myfile.root\" AND --tree=\"mytreename\" OR --d3pd_dir=\"mydirname\" options " << Root::GEndl;
266 exit(-1);
267 }
268
269 runtype = 4;
270 for(unsigned int i = 0; i < args_info.root_given; ++i){
271 rootfile.push_back(args_info.root_arg[i]);
272 }
273 if(args_info.tree_given){
274 treename = args_info.tree_arg;
275 }else{
276 logger << Root::kERROR << "In Root file mode Tree name (--d3p_dir=\"mytreename\") must also be provided" << Root::GEndl;
277 }
278 for(std::vector<std::string>::iterator it = rootfile.begin(); it != rootfile.end(); ++it){
279 if(!FileExists((*it))){
280 logger << Root::kWARNING << "Problem: file ["<< (*it) <<"] may not exist. Will try anyways..." << Root::GEndl;
281 }
282 }
283 }
284
285 // ROOT File -- d3pd TDirectory mode
286 //============================================
287 if((args_info.root_given >0 || args_info.d3pd_dir_given > 0) && args_info.tree_given == 0 && args_info.xml_given == 0 && args_info.tag_given == 0){
288 if((args_info.root_given == 0 && args_info.d3pd_dir_given > 0) || (args_info.root_given > 0 && args_info.d3pd_dir_given == 0 )){
289 logger << Root::kERROR << "Please provide BOTH --root=\"myfile.root\" AND --d3pd_dir=\"myd3pddirname\" options" << Root::GEndl;
290 exit(-1);
291 }
292
293 runtype = 5;
294 for(unsigned int i = 0; i < args_info.root_given; ++i){
295 rootfile.push_back(args_info.root_arg[i]);
296 }
297 if(args_info.d3pd_dir_given){
298 d3pddirname = args_info.d3pd_dir_arg;
299 }else{
300 logger << Root::kWARNING << "In D3PD Root file mode Directory name (--d3pd_dir=\"mylumidir\") must also be provided" << Root::GEndl;
301 logger << Root::kWARNING << "Ommitted, using default name \"Lumi\"" << Root::GEndl;
302 d3pddirname= "Lumi";
303 }
304
305 for(std::vector<std::string>::iterator it = rootfile.begin(); it != rootfile.end(); ++it){
306 if(!FileExists((*it))){
307 logger << Root::kWARNING << "Problem: file ["<< (*it) <<"] may not exist. Will try anyways..." << Root::GEndl;
308 }
309 }
310 }
311
312 // Full command line mode
313 //============================================
314 if (runtype == 0) {
315
316 // Nothing else specified, try run numbers
317 if (!args_info.runnumber_given) {
318 logger << Root::kERROR << "No input data specified!" << Root::GEndl;
319 exit(-1);
320 }
321
322 std::list<std::pair<unsigned int, unsigned int> >::iterator itr = runList.begin();
323
324 // Decode run IOV pairs
325 for (; itr != runList.end(); ++itr) {
326 // Dont allow open-ended IOVs
327 if ((itr->first == minrunnum) || (itr->second == maxrunnum)) {
328 logger << Root::kERROR << "Can't use open-ended run ranges to specify sample!" << Root::GEndl;
329 exit(-1);
330 }
331
332 for (unsigned int runnum = itr->first; runnum <= itr->second; runnum++)
333 runnumber.push_back(runnum);
334
335 }
336
337 // Also add in lumi block ranges
338 if (args_info.lbstart_given ==0) {
339 for (unsigned int i=0; i<runnumber.size(); i++) {
340 lbstart.push_back(minlbstart);
341 }
342 } else {
343 for (unsigned int i=0; i<args_info.lbstart_given; i++) {
344 lbstart.push_back(args_info.lbstart_arg[i]);
345 }
346 }
347
348 if (args_info.lbend_given ==0) {
349 for (unsigned int i=0; i<runnumber.size(); i++) {
350 lbend.push_back(maxlbend);
351 }
352 } else {
353 for (unsigned int i=0; i<args_info.lbend_given; i++) {
354 lbend.push_back(args_info.lbend_arg[i]);
355 }
356 }
357
358 }
359
360
361 // Finish parsing
362 //============================================
363 cmdline_parser_free (&args_info); /* release allocated memory */
364
365
366 //==========================================================================
367 // Set up LumiBlockCollection for the different scenarios
368 std::vector< xAOD::LumiBlockRangeContainer* > iovcVec;
369 std::vector< std::vector<std::string> > triggerchainVec;
370 Root::TGRLCollection grlcollection;
372 TString version("30"); // [0-10): ATLRunQuery, [10-20): ntuple production, [20-30): xml merging, [30-40): LumiCalc
373
374 //==========================================================================
375 // User defined IOVRange in command line
376 if (runtype == 0) {
377
378 logger << Root::kINFO << "Proceeding with command-line run list" << Root::GEndl;
379 if (lbstart.size() != lbend.size()) {
380 logger << Root::kERROR << "number of lbstart and lbend values must match!" << Root::GEndl;
381 exit(-1);
382 }
383
384 if (runnumber.size() > 1 && (runnumber.size() != lbstart.size())) {
385 logger << Root::kERROR << "number of lbstart and lbend values must match number of runs with multiple runs specified!" << Root::GEndl;
386 exit(-1);
387 }
388
389 /*
390 std::cout << "runlist length: " << runnumber.size() << std::endl;
391 for (unsigned int i=0; i<runnumber.size(); i++) {
392 std::cout << runnumber[i] << std::endl;
393 }
394 */
395
396 uint32_t lbstart_val;
397 uint32_t lbend_val;
398
401 iovc->setStore( iovcAux );
402
403 std::vector<uint32_t>::iterator itstart;
404 std::vector<uint32_t>::iterator itend;
405 std::vector<uint32_t>::iterator itrun;
406
407 if (runnumber.size() == 1) {
408
409 logger << Root::kINFO << "Runnumber [" << runnumber[0] << "]" << Root::GEndl;
410 for(itstart = lbstart.begin(), itend = lbend.begin();
411 itstart != lbstart.end() && itend != lbend.end(); ++itstart,++itend) {
412 lbstart_val = (*itstart);
413 lbend_val = (*itend);
414 logger << Root::kINFO << "lbstart-lbend [" << lbstart_val << "-" << lbend_val << "]" << Root::GEndl;
415 if (lbstart_val > lbend_val) {
416 logger << Root::kERROR << "lbstart > lbend! Should be: lbstart < = lbend" << Root::GEndl;
417 exit(-1);
418 } else {
420 iovc->push_back(iovr); // Must put this in container first
422 iovr->setStartLumiBlockNumber(lbstart_val);
423 iovr->setStopRunNumber(runnumber[0]);
424 iovr->setStopLumiBlockNumber(lbend_val);
425 }
426 }
427
428 } else if (runnumber.size() > 1) {
429
430 for(itrun = runnumber.begin(), itstart = lbstart.begin(), itend = lbend.begin();
431 itrun != runnumber.end() && itstart != lbstart.end() && itend != lbend.end();
432 ++itrun, ++itstart, ++itend) {
433 logger << Root::kINFO << "Runnumbers [" << *itrun << "]" << Root::GEndl;
434 logger << Root::kINFO << "lbstart-lbend [" << *itstart << "-" << *itend << "]" << Root::GEndl;
436 iovc->push_back(iovr); // Must put this in container first
437 iovr->setStartRunNumber(*itrun);
438 iovr->setStartLumiBlockNumber(*itstart);
439 iovr->setStopRunNumber(*itrun);
440 iovr->setStopLumiBlockNumber(*itend);
441 }
442 }
443
444 iovcVec.push_back(iovc); // take over iovc for usage below
445 triggerchainVec.push_back(triggerchain); // cmd-line triggerchain
446 std::map<TString,TString> metadata;
447 for (unsigned int j=0; j<triggerchain.size(); ++j)
448 metadata[Form("TriggerName%d",j)] = TString(triggerchain[j]);
449 grlcollection.push_back( *converter.GetGRLObject(*iovc,metadata,version) );
450 }
451
452
453 //==========================================================================
454 // Fetch up xAOD::LumiBlockRangeContainer from input TAG file
455 if (runtype == 1) {
456 // open TAG files to build xAOD::LumiBlockRangeContainer
457 logger << Root::kINFO << "Being in TAG file mode..." << Root::GEndl;
458
460 for(std::vector<std::string>::iterator it = tagfile.begin(); it != tagfile.end(); ++it){
461 logger << Root::kINFO << "Processing file: <" << (*it) << ">" << Root::GEndl;
462 int n = (*it).find(".root");
463 std::string tagfilename = (*it).substr(0,n);
464
465 // get Value for a Key
466 pool::CollectionService collectionService;
467 pool::ICollection* collection = collectionService.open(tagfilename, pool::ROOT_StorageType.type(), tagfilename);
468 if(collection == NULL) {
469 logger << Root::kERROR << "ICollection is NULL, exiting... " << Root::GEndl;
470 exit(-1);
471 }
472 }
473 // do sorting of all grl objects
474 reader.Interpret();
475 grlcollection = reader.GetMergedGRLCollection();
476
477 for (unsigned int j=0; j<grlcollection.size(); ++j) {
478 iovcVec.push_back( converter.GetLumiBlockRangeContainer(grlcollection[j]) );
479 // default: trigger names taken from xml metadata. Overwrite any existing cmd-line triggers.
480 if ( grlcollection[j].HasTriggerInfo() ) {
481 triggerchainVec.push_back(grlcollection[j].GetTriggerList()); // use existing trigger names
482 if (!triggerchain.empty())
483 logger << Root::kWARNING << "Input goodruns-list(s) <" << grlcollection[j].GetName()
484 << "> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
485 } else { // use cmdline trigger names
486 triggerchainVec.push_back(triggerchain) ;
487 for (unsigned int k=0; k<triggerchain.size(); ++k)
488 grlcollection[j].AddMetaData( Form("TriggerName%d",k),TString(triggerchain[k]) );
489 }
490 }
491 }
492
493 //==========================================================================
494 // Fetch up xAOD::LumiBlockRangeContainer from input XML file
495 if(runtype == 3){
496 // open XML files to build xAOD::LumiBlockRangeContainer
497 logger << Root::kINFO << "Being in XML file mode..." << Root::GEndl;
499 // looping over XML files
500 for(std::vector<std::string>::iterator it = xmlfile.begin(); it != xmlfile.end(); ++it){
501 logger << Root::kINFO << "Processing file: <" << (*it) << ">" << Root::GEndl;
502 reader.AddXMLFile(*it);
503 }
504 reader.Interpret();
505 grlcollection = reader.GetMergedGRLCollection();
506
507 for (unsigned int j=0; j<grlcollection.size(); ++j) {
508 iovcVec.push_back( converter.GetLumiBlockRangeContainer(grlcollection[j]) );
509 // default: trigger names taken from xml metadata. Overwrite any existing cmd-line triggers.
510 if ( grlcollection[j].HasTriggerInfo() ) {
511 triggerchainVec.push_back(grlcollection[j].GetTriggerList()); // use existing trigger names
512 if (!triggerchain.empty())
513 logger << Root::kWARNING << "Input goodruns-list(s) <" << grlcollection[j].GetName()
514 << "> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
515 } else { // use cmdline trigger names
516 triggerchainVec.push_back(triggerchain) ;
517 for (unsigned int k=0; k<triggerchain.size(); ++k)
518 grlcollection[j].AddMetaData( Form("TriggerName%d",k),TString(triggerchain[k]) );
519 }
520 }
521 }
522
523
524 //==========================================================================
525 // Fetch up xAOD::LumiBlockRangeContainer from input ROOT files - Tree mode
526 if(runtype == 4){
527 // open ntuples to fetch xmlstrings
528 logger << Root::kINFO << "Being in ROOT ntuple file mode..." << Root::GEndl;
529
531
532 for(std::vector<std::string>::iterator it = rootfile.begin(); it != rootfile.end(); ++it){
533 logger << Root::kINFO << "Processing root file: <" << (*it) << ">" << Root::GEndl;
534 std::string filename = (*it);
535 TFile* file = TFile::Open(filename.c_str());
536 TTree * tree = NULL;
537 TList * list = NULL;
538 tree = dynamic_cast<TTree*>(file->Get(treename.c_str()));
539 if(tree == 0){
540 logger << Root::kERROR << "Tree: " << treename << " doesn't exist in file " << std::move(filename) << Root::GEndl;
541 exit(-1);
542 }else{
543 list = tree->GetUserInfo() ;
544
545 // add xml string to TGoodRunsListReader. Sort out strings below
546 for(int j=0; j<list->GetEntries();++j) {
547 TObjString* objstr = dynamic_cast<TObjString*>(list->At(j));
548 if (objstr==0) continue;
549 if ( objstr->GetString().BeginsWith("<?xml version=\"1.0\"?") &&
550 objstr->GetString().Contains("DOCTYPE LumiRangeCollection") ) // xml identifier
551 reader.AddXMLString(objstr->GetString());
552 }
553 }
554 file->Close();
555 }
556
557 // do sorting of all grl objects
558 reader.Interpret();
559 grlcollection = reader.GetMergedGRLCollection();
560
561 for (unsigned int j=0; j<grlcollection.size(); ++j) {
562 iovcVec.push_back( converter.GetLumiBlockRangeContainer(grlcollection[j]) );
563 // default: trigger names taken from xml metadata. Overwrite any existing cmd-line triggers.
564 if ( grlcollection[j].HasTriggerInfo() ) {
565 triggerchainVec.push_back(grlcollection[j].GetTriggerList()); // use existing trigger names
566 if (!triggerchain.empty())
567 logger << Root::kWARNING << "Input goodruns-list(s) <" << grlcollection[j].GetName()
568 << "> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
569 } else { // use cmdline trigger names
570 triggerchainVec.push_back(triggerchain) ;
571 for (unsigned int k=0; k<triggerchain.size(); ++k)
572 grlcollection[j].AddMetaData( Form("TriggerName%d",k),TString(triggerchain[k]) );
573 }
574 }
575 }
576
577 //==========================================================================
578 // Fetch up xAOD::LumiBlockRangeContainer from input ROOT files - D3PD mode
579 if(runtype == 5){
580 // open ntuples to fetch xmlstrings
581 logger << Root::kINFO << "Being in ROOT D3PD ntuple file mode..." << Root::GEndl;
582
584
585 for(std::vector<std::string>::iterator it = rootfile.begin(); it != rootfile.end(); ++it){
586 logger << Root::kINFO << "Processing root file: <" << (*it) << ">" << Root::GEndl;
587 std::string filename = (*it);
588 TList* list = NULL;
589 TFile* file = TFile::Open(filename.c_str());
590 TDirectoryFile * dir = NULL;
591 logger << Root::kINFO << "Using Directory name: " << d3pddirname.c_str() << Root::GEndl;
592 dir = dynamic_cast<TDirectoryFile*>(file->GetDirectory(d3pddirname.c_str()));
593 if(!dir){
594 //coverity[copy_constructor_call]
595 logger << Root::kERROR << "Directory [" << d3pddirname << "] doesn't exist in file " << filename << Root::GEndl;
596 exit(-1);
597 }else{
598 TObjString* objstr = 0;
599 std::map<TString,int> keymap;
600 list = dir->GetListOfKeys();
601 // add xml string to TGoodRunsListReader. Sort out strings below
602 for(int j=0; j<list->GetEntries();j++) {
603 if ( keymap.find(list->At(j)->GetName())==keymap.end() ) { keymap[list->At(j)->GetName()] = 1; }
604 else { keymap[list->At(j)->GetName()] = keymap[list->At(j)->GetName()]+1; }
605 if(verbose)logger << Root::kINFO << "Found obj key: \"" << Form("%s;%d",list->At(j)->GetName(),keymap[list->At(j)->GetName()]) << "\"" << Root::GEndl;
606 objstr = dynamic_cast<TObjString*>(dir->Get( Form("%s;%d",list->At(j)->GetName(),keymap[list->At(j)->GetName()]) ));
607 if (objstr!=0){
608 if(verbose)logger << Root::kINFO << "with obj: " << objstr->GetString() << Root::GEndl;
609 if ( objstr->GetString().BeginsWith("<?xml version=\"1.0\"?") &&
610 objstr->GetString().Contains("DOCTYPE LumiRangeCollection") ){ // xml identifier
611 reader.AddXMLString(objstr->GetString());
612 }else{
613 logger << Root::kERROR << "XML string is not in expected format: " << objstr->GetString() << ". Skipped." << Root::GEndl;
614 //exit(-1);
615 }
616 }else{
617 logger << Root::kERROR << "No obj found with key \"" << list->At(j)->GetName() << "\"" << Root::GEndl;
618 exit(-1);
619 }
620 }// end for cycle
621 }
622 file->Close();
623 }
624 // do sorting of all grl objects
625
626 reader.Interpret();
627 grlcollection = reader.GetMergedGRLCollection();
628 for (unsigned int j=0; j<grlcollection.size(); ++j) {
629 iovcVec.push_back( converter.GetLumiBlockRangeContainer(grlcollection[j]) );
630 // default: trigger names taken from xml metadata. Overwrite any existing cmd-line triggers.
631 if ( grlcollection[j].HasTriggerInfo() ) {
632 triggerchainVec.push_back(grlcollection[j].GetTriggerList()); // use existing trigger names
633 if (!triggerchain.empty())
634 logger << Root::kWARNING << "Input goodruns-list(s) <" << grlcollection[j].GetName()
635 << "> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
636 } else { // use cmdline trigger names
637 triggerchainVec.push_back(triggerchain) ;
638 for (unsigned int k=0; k<triggerchain.size(); ++k)
639 grlcollection[j].AddMetaData( Form("TriggerName%d",k),TString(triggerchain[k]) );
640 }
641 }
642 }
643
644 //==========================================================================
645 // Run Lumi Calculation is all is well - i.e. runtype != 999
646 if(runtype != 999){
647
648 //
649 // If runtype != 0 and a run range has been specified, use that to filter runs
650 // ===========================================================================
651 if (runtype != 0 && runList.size() > 0) {
652 std::vector<xAOD::LumiBlockRangeContainer*>::iterator iovIt = iovcVec.begin();
653 for (;iovIt != iovcVec.end(); ++iovIt) {
654
655 xAOD::LumiBlockRangeContainer::iterator it = (*iovIt)->begin();
656 while (it != (*iovIt)->end()) {
657
658 unsigned int runnum = (*it)->startRunNumber() ;
659
660 bool found = false;
661 std::list<std::pair<unsigned int, unsigned int> >::iterator runIt = runList.begin();
662 for (; runIt != runList.end(); ++runIt) {
663 if (runnum < runIt->first) continue;
664 if (runnum > runIt->second) continue;
665 found = true;
666 break;
667 }
668
669 if (!found) {
670 logger << Root::kDEBUG << "Skipping run " << (*it)->startRunNumber() << " LB [" << (*it)->startLumiBlockNumber() << "-" << (*it)->stopLumiBlockNumber() << "] due to command-line run range" << Root::GEndl;
671 (*iovIt)->erase(it);
672
673 it = (*iovIt)->begin();
674
675 } else {
676 // logger << Root::kDEBUG << "Keeping run " << runnum << " due to command-line run range" << Root::GEndl;
677 ++it;
678 }
679 }
680
681 }
682
683 }
684
685
686 LumiCalculator lumicalc;
687 for (unsigned int j=0; j<iovcVec.size(); ++j) {
688 xAOD::LumiBlockRangeContainer* iovc = iovcVec[j];
689 triggerchain = triggerchainVec[j];
690
691 for(std::vector<std::string>::iterator it = triggerchain.begin(); it != triggerchain.end(); ++it){
692 if(!iovc->empty()){
693 logger << Root::kINFO << "--------------------------------------------" << Root::GEndl;
694 TTree tree("LumiMetaData","LumiMetaData");
695 lumicalc.setTree(&tree);
696 lumicalc.UseLumiTag(lumitag);
697 if(lumimethod != "")lumicalc.UseLumiMethod(lumimethod);
698 if(lumichannel != -1)lumicalc.UseLumiChannel(lumichannel);
699 lumicalc.UseMC(false);
700 lumicalc.UseOnlineLumi(online);
701 lumicalc.Verbose(verbose);
702 lumicalc.MakePlots(makeplots);
703 lumicalc.MakeCollList(collisionlists);
704 lumicalc.ScaleL1TrigRate(scalel1trigrate);
705 lumicalc.UseLiveTrigger(uselivetrigger, livetrigger);
706 lumicalc.UseLArNoiseDB(uselar, lartag);
707 lumicalc.UseBeamspot(usebeamspot, beamspottag);
708 lumicalc.IntegrateLumi(iovc, (*it));
709 logger << Root::kINFO << "--------------------------------------------" << Root::GEndl;
710
711 // Write out some summary information for 'quiet' mode
712 if (quiet) {
713 lumicalc.printSummary(std::cout);
714 }
715 }
716 }
717 }
718
719 //==========================================================================
720 // write out complete xml file for all lb collections together
721 grlcollection.SetVersion(version);
722 if(!grlcollection.empty()){
723 TString xmlfile = "ilumicalc_merged_";
724 if (xmloutfile.empty()) {
725 if (grlcollection.size()==1) { xmlfile += grlcollection[0].GetSuggestedName() + ".xml"; }
726 else { xmlfile += "grls.xml"; }
727 } else { xmlfile = xmloutfile; }
728 converter.CreateXMLFile(grlcollection,xmlfile);
729 }
730 }
731
732 //==========================================================================
733 // Print timing info
734 timer.Stop();
735 logger << Root::kINFO << "Real time: " << std::setw(5) << timer.RealTime() << " s" << Root::GEndl;
736 logger << Root::kINFO << "CPU time: " << std::setw(5) << timer.CpuTime() << " s" << Root::GEndl;
737
738 return 0;
739
740}
Define macros for attributes used to control the static checker.
#define ATLAS_NO_CHECK_FILE_THREAD_SAFETY
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
bool empty() const noexcept
Returns true if the collection is empty.
Root::TGoodRunsList * GetGRLObject(const xAOD::LumiBlockRangeContainer &lbc, const grlmetadatamap &metadata=grlmetadatamap(), const char *version="") const
xAOD::LumiBlockRangeContainer * GetLumiBlockRangeContainer(const Root::TGoodRunsList &grl, std::map< TString, TString > &metadata, TString &version)
void CreateXMLFile(const Root::TGoodRunsList &grl, const TString &xmlfilename="", const TString &prefix="")
void UseOnlineLumi(bool online)
void UseLumiChannel(int chan)
void UseLumiMethod(const std::string &method)
void setTree(TTree *tree=0)
void UseLArNoiseDB(bool lar, const std::string &lardb)
void ScaleL1TrigRate(const float &rate)
void UseMC(bool mc=true)
void UseLiveTrigger(bool live, std::string &livetrigger)
void printSummary(std::ostream &os)
void Verbose(bool verbose=true)
void UseBeamspot(bool bs, const std::string &bstag)
void MakePlots(bool plots)
void MakeCollList(bool collList)
void UseLumiTag(const std::string &tag)
void SetVersion(const TString &version)
static void SetMinLevel(TMsgLevel minLevel)
Definition TMsgLogger.h:92
A service for creating, accessing and managing an ensemble of collections of event references.
virtual ICollection * open(const std::string &name, const DbType &type, const std::string &connection="", ISession *session=0) const
Retrieves a handle to an existing collection or collection fragment for read or update transactions,...
An interface to a storage technology specific collection of event references and attributes.
Definition ICollection.h:23
void setStopRunNumber(uint32_t value)
Set the run number of the stop time of the range.
void setStartRunNumber(uint32_t value)
Set the run number of the start time of the range.
void setStartLumiBlockNumber(uint32_t value)
Set the luminosity block of the start time of the range.
void setStopLumiBlockNumber(uint32_t value)
Set the luminosity block of the stop time of the range.
int cmdline_parser(int argc, char **argv, struct gengetopt_args_info *args_info)
The command line parser.
Definition cmdline.cxx:659
void cmdline_parser_free(struct gengetopt_args_info *args_info)
Deallocates the string fields of the gengetopt_args_info structure (but does not deallocate the struc...
Definition cmdline.cxx:502
bool verbose
Definition hcg.cxx:73
int main()
Definition hello.cxx:18
void print_usage()
Definition iLumiCalc.cxx:30
static uint32_t minlbstart
Definition iLumiCalc.h:40
bool FileExists(const std::string &strFilename)
Definition iLumiCalc.h:163
static std::vector< std::string > triggerchain
Definition iLumiCalc.h:34
static std::vector< uint32_t > lbstart
Definition iLumiCalc.h:38
static std::vector< uint32_t > runnumber
Definition iLumiCalc.h:37
static std::vector< std::string > tagfile
Definition iLumiCalc.h:27
static std::vector< std::string > xmlfile
Definition iLumiCalc.h:29
static std::vector< std::string > rootfile
Definition iLumiCalc.h:30
static uint32_t maxrunnum
Definition iLumiCalc.h:43
static uint32_t minrunnum
Definition iLumiCalc.h:42
static Root::TMsgLogger logger("iLumiCalc")
static uint32_t maxlbend
Definition iLumiCalc.h:41
static std::string livetrigger
Definition iLumiCalc.h:35
static std::vector< uint32_t > lbend
Definition iLumiCalc.h:39
static std::string d3pddirname
Definition iLumiCalc.h:32
static std::string treename
Definition iLumiCalc.h:31
static std::string xmloutfile
Definition iLumiCalc.h:33
@ kERROR
Definition TMsgLogger.h:42
@ kWARNING
Definition TMsgLogger.h:41
@ kDEBUG
Definition TMsgLogger.h:39
@ kINFO
Definition TMsgLogger.h:40
static const DbType ROOT_StorageType
Definition DbType.h:99
LumiBlockRange_v1 LumiBlockRange
Declare the latest version of the class.
LumiBlockRangeContainer_v1 LumiBlockRangeContainer
Declare the latest version of the container.
LumiBlockRangeAuxContainer_v1 LumiBlockRangeAuxContainer
Declare the latest version of the auxiliary container.
Where the command line options are stored.
Definition cmdline.h:43
char * lumimethod_arg
Luminosity estimate method by string (default='ATLAS_PREFERRED').
Definition cmdline.h:93
int lar_flag
Calculate LAr defect fraction (default=off).
Definition cmdline.h:104
char ** runnumber_arg
Run number, range, or comma separated list, e.g.
Definition cmdline.h:46
char * lumitag_arg
Offline luminosity database tag (default='OflLumi-8TeV-002').
Definition cmdline.h:85
int online_flag
Use online luminosity estimates instead of offline database (default=off).
Definition cmdline.h:88
char ** root_arg
Input ROOT file name.
Definition cmdline.h:74
char * tree_arg
Name of TTree in input ROOT file to which Lumi string is attached.
Definition cmdline.h:79
int quiet_flag
Quiet output level (default=off).
Definition cmdline.h:126
char ** xml_arg
Input XML file name.
Definition cmdline.h:61
unsigned int root_given
Whether root was given.
Definition cmdline.h:137
char * d3pd_dir_arg
Name of TDirectory in input ROOT file where Lumi string is stored.
Definition cmdline.h:82
unsigned int xml_out_given
Whether xml_out was given.
Definition cmdline.h:151
unsigned int tree_given
Whether tree was given.
Definition cmdline.h:138
char * lartag_arg
LAr noise burst database tag (default='LARBadChannelsOflEventVeto-UPD4-01').
Definition cmdline.h:106
double scale_lumi_arg
Scale luminosity with a constant value (default='1.0').
Definition cmdline.h:114
int * lbstart_arg
LumiBlock number begin.
Definition cmdline.h:51
char * xml_out_arg
Output XML file name.
Definition cmdline.h:117
unsigned int lbend_given
Whether lbend was given.
Definition cmdline.h:133
unsigned int livetrigger_given
Whether livetrigger was given.
Definition cmdline.h:145
int lumichannel_arg
Luminosity estimate method by value (default='0').
Definition cmdline.h:90
unsigned int xml_given
Whether xml was given.
Definition cmdline.h:134
unsigned int lumimethod_given
Whether lumimethod was given.
Definition cmdline.h:143
int * lbend_arg
LumiBlock number end.
Definition cmdline.h:56
char ** trigger_arg
Trigger chain name used for prescale calculation.
Definition cmdline.h:96
char ** tag_arg
Input TAG file name.
Definition cmdline.h:69
int verbose_flag
Verbose output level (default=off).
Definition cmdline.h:124
unsigned int lumichannel_given
Whether lumichannel was given.
Definition cmdline.h:142
char * beamspottag_arg
Online beamspot database tag (default='IndetBeamposOnl-HLT-UPD1-001-00').
Definition cmdline.h:111
unsigned int trigger_given
Whether trigger was given.
Definition cmdline.h:144
unsigned int lbstart_given
Whether lbstart was given.
Definition cmdline.h:132
unsigned int runnumber_given
Whether runnumber was given.
Definition cmdline.h:131
char * livetrigger_arg
L1 Trigger used for livetime calculation (default='L1_EM30').
Definition cmdline.h:101
int xml_collisionlist_flag
Output XML file of lists of collision candidates (default=off).
Definition cmdline.h:120
int plots_flag
Create some plots on demand (default=off).
Definition cmdline.h:122
unsigned int tag_given
Whether tag was given.
Definition cmdline.h:136
int beamspot_flag
Require online beamspot valid in trigger livefraction (default=off).
Definition cmdline.h:109
unsigned int d3pd_dir_given
Whether d3pd_dir was given.
Definition cmdline.h:139
TChain * tree
TFile * file