ATLAS Offline Software
Loading...
Searching...
No Matches
iLumiCalc.cxx File Reference
#include "iLumiCalc.h"
#include "CxxUtils/checker_macros.h"
#include "CollectionSvc/CollectionService.h"
#include "CollectionSvc/ICollection.h"
#include "DataModelRoot/RootType.h"
#include "TTree.h"
#include "TList.h"
#include "TObjString.h"
#include "TString.h"
#include <TKey.h>
#include <typeinfo>
#include <list>

Go to the source code of this file.

Functions

void print_usage ()
int main (int argc, char *argv[])

Variables

 ATLAS_NO_CHECK_FILE_THREAD_SAFETY

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 47 of file iLumiCalc.cxx.

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

◆ print_usage()

void print_usage ( )

Definition at line 28 of file iLumiCalc.cxx.

28 {
29
30 std::cout << std::endl;
31 std::cout << " --->>> i L U M I C A L C <<<---"<< std::endl;
32 std::cout << std::endl;
33 std::cout << "iLumiCalc: this c++ program calculates integrated luminosity" << std::endl ;
34 std::cout << "by looping over a list of lumiblocks, given a set of input options." << std::endl;
35 std::cout << "Input file can be either an xml file, or a TAG file." << std::endl;
36 std::cout << std::endl;
37 std::cout << "Type: iLumiCalc --help for the complete list of options" << std::endl ;
38 std::cout << std::endl;
39 std::cout << "Further help: https://twiki.cern.ch/twiki/bin/view/Atlas/CoolLumiCalc"<< std::endl;
40 std::cout << std::endl;
41 exit(-1);
42
43}

Variable Documentation

◆ ATLAS_NO_CHECK_FILE_THREAD_SAFETY

ATLAS_NO_CHECK_FILE_THREAD_SAFETY

Definition at line 8 of file iLumiCalc.cxx.