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