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