ATLAS Offline Software
Functions | Variables
iLumiCalc.cxx File Reference
#include "iLumiCalc.h"
#include "CxxUtils/checker_macros.h"
#include "CollectionBase/CollectionService.h"
#include "CollectionBase/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 
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
419  iovr->setStartRunNumber(runnumber[0]);
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  logger << Root::kERROR << "Directory [" << d3pddirname << "] doesn't exist in file " << filename << Root::GEndl;
596  exit(-1);
597  }else{
598  TObjString* objstr = 0;
599  std::map<TString,int> keymap;
600  list = dir->GetListOfKeys();
601  // add xml string to TGoodRunsListReader. Sort out strings below
602  for(int j=0; j<list->GetEntries();j++) {
603  if ( keymap.find(list->At(j)->GetName())==keymap.end() ) { keymap[list->At(j)->GetName()] = 1; }
604  else { keymap[list->At(j)->GetName()] = keymap[list->At(j)->GetName()]+1; }
605  if(verbose)logger << Root::kINFO << "Found obj key: \"" << Form("%s;%d",list->At(j)->GetName(),keymap[list->At(j)->GetName()]) << "\"" << Root::GEndl;
606  objstr = dynamic_cast<TObjString*>(dir->Get( Form("%s;%d",list->At(j)->GetName(),keymap[list->At(j)->GetName()]) ));
607  if (objstr!=0){
608  if(verbose)logger << Root::kINFO << "with obj: " << objstr->GetString() << Root::GEndl;
609  if ( objstr->GetString().BeginsWith("<?xml version=\"1.0\"?") &&
610  objstr->GetString().Contains("DOCTYPE LumiRangeCollection") ){ // xml identifier
611  reader.AddXMLString(objstr->GetString());
612  }else{
613  logger << Root::kERROR << "XML string is not in expected format: " << objstr->GetString() << ". Skipped." << Root::GEndl;
614  //exit(-1);
615  }
616  }else{
617  logger << Root::kERROR << "No obj found with key \"" << list->At(j)->GetName() << "\"" << Root::GEndl;
618  exit(-1);
619  }
620  }// end for cycle
621  }
622  file->Close();
623  }
624  // do sorting of all grl objects
625 
626  reader.Interpret();
627  grlcollection = reader.GetMergedGRLCollection();
628  for (unsigned int j=0; j<grlcollection.size(); ++j) {
629  iovcVec.push_back( converter.GetLumiBlockRangeContainer(grlcollection[j]) );
630  // default: trigger names taken from xml metadata. Overwrite any existing cmd-line triggers.
631  if ( grlcollection[j].HasTriggerInfo() ) {
632  triggerchainVec.push_back(grlcollection[j].GetTriggerList()); // use existing trigger names
633  if (!triggerchain.empty())
634  logger << Root::kWARNING << "Input goodruns-list(s) <" << grlcollection[j].GetName()
635  << "> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
636  } else { // use cmdline trigger names
637  triggerchainVec.push_back(triggerchain) ;
638  for (unsigned int k=0; k<triggerchain.size(); ++k)
639  grlcollection[j].AddMetaData( Form("TriggerName%d",k),TString(triggerchain[k]) );
640  }
641  }
642  }
643 
644  //==========================================================================
645  // Run Lumi Calculation is all is well - i.e. runtype != 999
646  if(runtype != 999){
647 
648  //
649  // If runtype != 0 and a run range has been specified, use that to filter runs
650  // ===========================================================================
651  if (runtype != 0 && runList.size() > 0) {
653  for (;iovIt != iovcVec.end(); ++iovIt) {
654 
655  xAOD::LumiBlockRangeContainer::iterator it = (*iovIt)->begin();
656  while (it != (*iovIt)->end()) {
657 
658  unsigned int runnum = (*it)->startRunNumber() ;
659 
660  bool found = false;
661  std::list<std::pair<unsigned int, unsigned int> >::iterator runIt = runList.begin();
662  for (; runIt != runList.end(); ++runIt) {
663  if (runnum < runIt->first) continue;
664  if (runnum > runIt->second) continue;
665  found = true;
666  break;
667  }
668 
669  if (!found) {
670  logger << Root::kDEBUG << "Skipping run " << (*it)->startRunNumber() << " LB [" << (*it)->startLumiBlockNumber() << "-" << (*it)->stopLumiBlockNumber() << "] due to command-line run range" << Root::GEndl;
671  (*iovIt)->erase(it);
672 
673  it = (*iovIt)->begin();
674 
675  } else {
676  // logger << Root::kDEBUG << "Keeping run " << runnum << " due to command-line run range" << Root::GEndl;
677  ++it;
678  }
679  }
680 
681  }
682 
683  }
684 
685 
686  LumiCalculator lumicalc;
687  for (unsigned int j=0; j<iovcVec.size(); ++j) {
688  xAOD::LumiBlockRangeContainer* iovc = iovcVec[j];
689  triggerchain = triggerchainVec[j];
690 
691  for(std::vector<std::string>::iterator it = triggerchain.begin(); it != triggerchain.end(); ++it){
692  if(!iovc->empty()){
693  logger << Root::kINFO << "--------------------------------------------" << Root::GEndl;
694  TTree tree("LumiMetaData","LumiMetaData");
695  lumicalc.setTree(&tree);
696  lumicalc.UseLumiTag(lumitag);
697  if(lumimethod != "")lumicalc.UseLumiMethod(lumimethod);
698  if(lumichannel != -1)lumicalc.UseLumiChannel(lumichannel);
699  lumicalc.UseMC(false);
700  lumicalc.UseOnlineLumi(online);
701  lumicalc.Verbose(verbose);
702  lumicalc.MakePlots(makeplots);
703  lumicalc.MakeCollList(collisionlists);
704  lumicalc.ScaleL1TrigRate(scalel1trigrate);
705  lumicalc.UseLiveTrigger(uselivetrigger, livetrigger);
706  lumicalc.UseLArNoiseDB(uselar, lartag);
707  lumicalc.UseBeamspot(usebeamspot, beamspottag);
708  lumicalc.IntegrateLumi(iovc, (*it));
709  logger << Root::kINFO << "--------------------------------------------" << Root::GEndl;
710 
711  // Write out some summary information for 'quiet' mode
712  if (quiet) {
713  lumicalc.printSummary(std::cout);
714  }
715  }
716  }
717  }
718 
719  //==========================================================================
720  // write out complete xml file for all lb collections together
721  grlcollection.SetVersion(version);
722  if(!grlcollection.empty()){
723  TString xmlfile = "ilumicalc_merged_";
724  if (xmloutfile.empty()) {
725  if (grlcollection.size()==1) { xmlfile += grlcollection[0].GetSuggestedName() + ".xml"; }
726  else { xmlfile += "grls.xml"; }
727  } else { xmlfile = xmloutfile; }
728  converter.CreateXMLFile(grlcollection,xmlfile);
729  }
730  }
731 
732  //==========================================================================
733  // Print timing info
734  timer.Stop();
735  logger << Root::kINFO << "Real time: " << std::setw(5) << timer.RealTime() << " s" << Root::GEndl;
736  logger << Root::kINFO << "CPU time: " << std::setw(5) << timer.CpuTime() << " s" << Root::GEndl;
737 
738  return 0;
739 
740 }

◆ 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.

xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
gengetopt_args_info::lartag_arg
char * lartag_arg
LAr noise burst database tag (default='LARBadChannelsOflEventVeto-UPD4-01').
Definition: cmdline.h:106
Root::TGoodRunsListReader
Definition: TGoodRunsListReader.h:34
python.utils.AtlRunQueryDQUtils.runnum
runnum
Definition: AtlRunQueryDQUtils.py:213
gengetopt_args_info::tag_arg
char ** tag_arg
Input TAG file name.
Definition: cmdline.h:69
gengetopt_args_info::tag_given
unsigned int tag_given
Whether tag was given.
Definition: cmdline.h:136
Root::kWARNING
@ kWARNING
Definition: TMsgLogger.h:51
xAOD::LumiBlockRange_v1::setStopLumiBlockNumber
void setStopLumiBlockNumber(uint32_t value)
Set the luminosity block of the stop time of the range.
gengetopt_args_info::online_flag
int online_flag
Use online luminosity estimates instead of offline database (default=off).
Definition: cmdline.h:88
LumiCalculator::UseLumiChannel
void UseLumiChannel(int chan)
Definition: LumiCalculator.cxx:287
pool::CollectionService::handle
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,...
LumiCalculator::printSummary
void printSummary(std::ostream &os)
Definition: LumiCalculator.cxx:1403
gengetopt_args_info::lbend_arg
int * lbend_arg
LumiBlock number end.
Definition: cmdline.h:56
LumiBlockRangeContainerConverter::GetLumiBlockRangeContainer
xAOD::LumiBlockRangeContainer * GetLumiBlockRangeContainer(const Root::TGoodRunsList &grl, std::map< TString, TString > &metadata, TString &version)
Definition: LumiBlockRangeContainerConverter.cxx:34
cmdline_parser
int cmdline_parser(int argc, char **argv, struct gengetopt_args_info *args_info)
The command line parser.
Definition: cmdline.cxx:659
beamspotman.beamspottag
string beamspottag
Definition: beamspotman.py:54
LumiCalculator::ScaleL1TrigRate
void ScaleL1TrigRate(const float &rate)
Definition: LumiCalculator.h:49
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
gengetopt_args_info::verbose_flag
int verbose_flag
Verbose output level (default=off).
Definition: cmdline.h:124
quiet
bool quiet
Definition: TrigGlobEffCorrValidation.cxx:190
gengetopt_args_info::quiet_flag
int quiet_flag
Quiet output level (default=off).
Definition: cmdline.h:126
gengetopt_args_info::trigger_given
unsigned int trigger_given
Whether trigger was given.
Definition: cmdline.h:144
gengetopt_args_info::tree_given
unsigned int tree_given
Whether tree was given.
Definition: cmdline.h:138
gengetopt_args_info::d3pd_dir_arg
char * d3pd_dir_arg
Name of TDirectory in input ROOT file where Lumi string is stored.
Definition: cmdline.h:82
gengetopt_args_info::xml_collisionlist_flag
int xml_collisionlist_flag
Output XML file of lists of collision candidates (default=off).
Definition: cmdline.h:120
xAOD::LumiBlockRange_v1::setStopRunNumber
void setStopRunNumber(uint32_t value)
Set the run number of the stop time of the range.
cmdline_parser_free
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
tree
TChain * tree
Definition: tile_monitor.h:30
xAOD::LumiBlockRangeAuxContainer_v1
Auxiliary container for xAOD::LumiBlockRangeContainer_v1.
Definition: LumiBlockRangeAuxContainer_v1.h:34
skel.it
it
Definition: skel.GENtoEVGEN.py:407
python.SystemOfUnits.second
float second
Definition: SystemOfUnits.py:135
xAOD::LumiBlockRange_v1::setStartRunNumber
void setStartRunNumber(uint32_t value)
Set the run number of the start time of the range.
Root::kERROR
@ kERROR
Definition: TMsgLogger.h:52
gengetopt_args_info::lumichannel_arg
int lumichannel_arg
Luminosity estimate method by value (default='0').
Definition: cmdline.h:90
gengetopt_args_info::lbstart_arg
int * lbstart_arg
LumiBlock number begin.
Definition: cmdline.h:51
gengetopt_args_info::lumimethod_arg
char * lumimethod_arg
Luminosity estimate method by string (default='ATLAS_PREFERRED').
Definition: cmdline.h:93
LArCalib_HVScale2NtupleConfig.rootfile
string rootfile
Definition: LArCalib_HVScale2NtupleConfig.py:84
LumiBlockRangeContainerConverter
Definition: LumiBlockRangeContainerConverter.h:34
WriteLumiToCool.val1
val1
Definition: WriteLumiToCool.py:184
python.XMLReader.xmlfile
xmlfile
Definition: XMLReader.py:72
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
LumiCalculator::UseLumiMethod
void UseLumiMethod(const std::string &method)
Definition: LumiCalculator.cxx:283
gengetopt_args_info::trigger_arg
char ** trigger_arg
Trigger chain name used for prescale calculation.
Definition: cmdline.h:96
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:85
GEndl
#define GEndl
Definition: TMsgLogger.h:152
xAOD::LumiBlockRangeContainer
LumiBlockRangeContainer_v1 LumiBlockRangeContainer
Declare the latest version of the container.
Definition: LumiBlockRangeContainer.h:17
gengetopt_args_info::xml_arg
char ** xml_arg
Input XML file name.
Definition: cmdline.h:61
gengetopt_args_info::root_given
unsigned int root_given
Whether root was given.
Definition: cmdline.h:137
Root::kDEBUG
@ kDEBUG
Definition: TMsgLogger.h:49
Root::TGRLCollection::SetVersion
void SetVersion(const TString &version)
Definition: TGRLCollection.cxx:58
python.checkMetadata.metadata
metadata
Definition: checkMetadata.py:175
xAOD::LumiBlockRange
LumiBlockRange_v1 LumiBlockRange
Declare the latest version of the class.
Definition: LumiBlockRange.h:16
TileSynchronizeBch.online
online
Definition: TileSynchronizeBch.py:88
gengetopt_args_info::scale_lumi_arg
double scale_lumi_arg
Scale luminosity with a constant value (default='1.0').
Definition: cmdline.h:114
gengetopt_args_info::runnumber_given
unsigned int runnumber_given
Whether runnumber was given.
Definition: cmdline.h:131
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
gengetopt_args_info::beamspot_flag
int beamspot_flag
Require online beamspot valid in trigger livefraction (default=off).
Definition: cmdline.h:109
lumiFormat.i
int i
Definition: lumiFormat.py:85
FileExists
bool FileExists(const std::string &strFilename)
Definition: iLumiCalc.h:163
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
beamspotman.n
n
Definition: beamspotman.py:727
Root::kINFO
@ kINFO
Definition: TMsgLogger.h:50
WriteLumiToCool.val2
val2
Definition: WriteLumiToCool.py:185
xAOD::LumiBlockRangeAuxContainer
LumiBlockRangeAuxContainer_v1 LumiBlockRangeAuxContainer
Declare the latest version of the auxiliary container.
Definition: LumiBlockRangeAuxContainer.h:16
LumiBlockRangeContainerConverter::GetGRLObject
Root::TGoodRunsList * GetGRLObject(const xAOD::LumiBlockRangeContainer &lbc, const grlmetadatamap &metadata=grlmetadatamap(), const char *version="") const
Definition: LumiBlockRangeContainerConverter.cxx:174
gengetopt_args_info::lar_flag
int lar_flag
Calculate LAr defect fraction (default=off).
Definition: cmdline.h:104
file
TFile * file
Definition: tile_monitor.h:29
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
gengetopt_args_info::lbstart_given
unsigned int lbstart_given
Whether lbstart was given.
Definition: cmdline.h:132
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:19
gengetopt_args_info::lumimethod_given
unsigned int lumimethod_given
Whether lumimethod was given.
Definition: cmdline.h:143
LumiCalculator
Definition: LumiCalculator.h:26
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
calibdata.exit
exit
Definition: calibdata.py:235
Root::TGRLCollection
Definition: TGRLCollection.h:29
gengetopt_args_info::lumitag_arg
char * lumitag_arg
Offline luminosity database tag (default='OflLumi-8TeV-002').
Definition: cmdline.h:85
DeMoScan.runnumber
runnumber
Definition: DeMoScan.py:264
beamspotman.dir
string dir
Definition: beamspotman.py:619
LumiCalculator::UseLArNoiseDB
void UseLArNoiseDB(bool lar, const std::string &lardb)
Definition: LumiCalculator.cxx:298
gengetopt_args_info::xml_out_given
unsigned int xml_out_given
Whether xml_out was given.
Definition: cmdline.h:151
gengetopt_args_info::xml_out_arg
char * xml_out_arg
Output XML file name.
Definition: cmdline.h:117
gengetopt_args_info::livetrigger_given
unsigned int livetrigger_given
Whether livetrigger was given.
Definition: cmdline.h:145
PURW_create_actual_mu_profile.lumitag
lumitag
Definition: PURW_create_actual_mu_profile.py:85
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
checkTriggerxAOD.found
found
Definition: checkTriggerxAOD.py:328
LumiCalculator::Verbose
void Verbose(bool verbose=true)
Definition: LumiCalculator.cxx:261
find_data.full
full
Definition: find_data.py:26
LumiCalculator::UseOnlineLumi
void UseOnlineLumi(bool online)
Definition: LumiCalculator.cxx:273
parseLogTest.uselar
uselar
Definition: parseLogTest.py:8
LumiCalculator::UseMC
void UseMC(bool mc=true)
Definition: LumiCalculator.cxx:265
get_generator_info.version
version
Definition: get_generator_info.py:33
print_usage
void print_usage()
Definition: iLumiCalc.cxx:28
gengetopt_args_info::d3pd_dir_given
unsigned int d3pd_dir_given
Whether d3pd_dir was given.
Definition: cmdline.h:139
gengetopt_args_info::lbend_given
unsigned int lbend_given
Whether lbend was given.
Definition: cmdline.h:133
xAOD::LumiBlockRange_v1
Class describing a luminosity block range.
Definition: LumiBlockRange_v1.h:33
gengetopt_args_info::beamspottag_arg
char * beamspottag_arg
Online beamspot database tag (default='IndetBeamposOnl-HLT-UPD1-001-00').
Definition: cmdline.h:111
LumiCalculator::MakeCollList
void MakeCollList(bool collList)
Definition: LumiCalculator.h:48
LumiBlockRangeContainerConverter::CreateXMLFile
void CreateXMLFile(const Root::TGoodRunsList &grl, const TString &xmlfilename="", const TString &prefix="")
Definition: LumiBlockRangeContainerConverter.cxx:107
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:296
DeMoScan.first
bool first
Definition: DeMoScan.py:534
gengetopt_args_info
Where the command line options are stored.
Definition: cmdline.h:43
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:23
gengetopt_args_info::xml_given
unsigned int xml_given
Whether xml was given.
Definition: cmdline.h:134
gengetopt_args_info::runnumber_arg
char ** runnumber_arg
Run number, range, or comma separated list, e.g.
Definition: cmdline.h:46
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
gengetopt_args_info::livetrigger_arg
char * livetrigger_arg
L1 Trigger used for livetime calculation (default='L1_EM30').
Definition: cmdline.h:101
gengetopt_args_info::lumichannel_given
unsigned int lumichannel_given
Whether lumichannel was given.
Definition: cmdline.h:142
pool::CollectionService
Definition: CollectionService.h:26
collisions.reader
reader
read the goodrunslist xml file(s)
Definition: collisions.py:22
LumiCalculator::UseLiveTrigger
void UseLiveTrigger(bool live, std::string &livetrigger)
Definition: LumiCalculator.cxx:293
LumiCalculator::MakePlots
void MakePlots(bool plots)
Definition: LumiCalculator.h:47
gengetopt_args_info::tree_arg
char * tree_arg
Name of TTree in input ROOT file to which Lumi string is attached.
Definition: cmdline.h:79
LumiCalculator::UseBeamspot
void UseBeamspot(bool bs, const std::string &bstag)
Definition: LumiCalculator.cxx:303
python.diffTAGTree.treename
treename
Definition: diffTAGTree.py:140
gengetopt_args_info::root_arg
char ** root_arg
Input ROOT file name.
Definition: cmdline.h:74
gengetopt_args_info::plots_flag
int plots_flag
Create some plots on demand (default=off).
Definition: cmdline.h:122
pool::ICollection
Definition: ICollection.h:23
xAOD::LumiBlockRange_v1::setStartLumiBlockNumber
void setStartLumiBlockNumber(uint32_t value)
Set the luminosity block of the start time of the range.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14
fitman.k
k
Definition: fitman.py:528
Root::TMsgLogger::SetMinLevel
static void SetMinLevel(TMsgLevel minLevel)
Definition: TMsgLogger.h:97
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65
LumiCalculator::UseLumiTag
void UseLumiTag(const std::string &tag)
Definition: LumiCalculator.cxx:279
LumiCalculator::setTree
void setTree(TTree *tree=0)
Definition: LumiCalculator.cxx:210