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 46 of file iLumiCalc.cxx.

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

◆ 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:214
gengetopt_args_info::tag_arg
char ** tag_arg
Input TAG file name.
Definition: cmdline.h:69
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
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:260
LumiCalculator::printSummary
void printSummary(std::ostream &os)
Definition: LumiCalculator.cxx:1362
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:656
beamspotman.beamspottag
string beamspottag
Definition: beamspotman.py:55
LumiCalculator::ScaleL1TrigRate
void ScaleL1TrigRate(const float &rate)
Definition: LumiCalculator.h:42
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:500
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:396
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:74
LumiBlockRangeContainerConverter
Definition: LumiBlockRangeContainerConverter.h:34
python.XMLReader.xmlfile
xmlfile
Definition: XMLReader.py:72
LumiCalculator::UseLumiMethod
void UseLumiMethod(const std::string &method)
Definition: LumiCalculator.cxx:256
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:86
GEndl
#define GEndl
Definition: TMsgLogger.h:151
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
pool::CollectionService::handle
virtual ICollection * handle(const std::string &name, const std::string &type, 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,...
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:731
Root::kINFO
@ kINFO
Definition: TMsgLogger.h:50
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:20
gengetopt_args_info::lumimethod_given
unsigned int lumimethod_given
Whether lumimethod was given.
Definition: cmdline.h:143
LumiCalculator
Definition: LumiCalculator.h:19
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
calibdata.exit
exit
Definition: calibdata.py:236
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:266
beamspotman.dir
string dir
Definition: beamspotman.py:623
LumiCalculator::UseLArNoiseDB
void UseLArNoiseDB(bool lar, const std::string &lardb)
Definition: LumiCalculator.cxx:271
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.
LumiCalculator::Verbose
void Verbose(bool verbose=true)
Definition: LumiCalculator.cxx:234
find_data.full
full
Definition: find_data.py:27
LumiCalculator::UseOnlineLumi
void UseOnlineLumi(bool online)
Definition: LumiCalculator.cxx:246
parseLogTest.uselar
uselar
Definition: parseLogTest.py:8
LumiCalculator::UseMC
void UseMC(bool mc=true)
Definition: LumiCalculator.cxx:238
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
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
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:41
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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:297
DeMoScan.first
bool first
Definition: DeMoScan.py:536
gengetopt_args_info
Where the command line options are stored.
Definition: cmdline.h:43
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
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:266
LumiCalculator::MakePlots
void MakePlots(bool plots)
Definition: LumiCalculator.h:40
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:276
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
readCCLHist.float
float
Definition: readCCLHist.py:83
pool::ICollection
Definition: ICollection.h:24
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:96
LumiCalculator::UseLumiTag
void UseLumiTag(const std::string &tag)
Definition: LumiCalculator.cxx:252
LumiCalculator::setTree
void setTree(TTree *tree=0)
Definition: LumiCalculator.cxx:183