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