49int main(
int argc,
char * argv[]){
89 if (scalel1trigrate != 1.) {
102 logger <<
Root::kWARNING <<
"Lumitag: " << lumitag <<
" ignored due to --online " << Root::GEndl;
111 logger <<
Root::kINFO <<
"LAr noise burst inefficiency will be calculated from " << lartag << Root::GEndl;
118 logger <<
Root::kINFO <<
"Livetime will include online beamspot validity requirement from " << beamspottag << Root::GEndl;
124 std::string lumimethod;
125 int lumichannel = -1;
129 logger <<
Root::kERROR <<
"Sorry, the online database doesn't have luminosity method names, use --lumichannel instead!" << Root::GEndl;
141 logger <<
Root::kINFO <<
"Both lumimethod and lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
145 logger <<
Root::kINFO <<
"No lumimethod or lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
148 logger <<
Root::kINFO <<
"No lumimethod or lumichannel is given, defaulting to Lumimethod: " << lumimethod << Root::GEndl;
156 logger <<
Root::kINFO <<
"No trigger specified, proceeding with --trigger=None" << Root::GEndl;
174 bool uselivetrigger =
false;
179 uselivetrigger =
true;
183 logger <<
Root::kINFO <<
"Prescale trigger chains will be used for livetime " << Root::GEndl;
191 std::list<std::pair<unsigned int, unsigned int> > runList;
200 size_t found = full.find(
'-');
202 unsigned int val1, val2;
203 if (found != std::string::npos) {
204 val1 = atoi(full.substr(0, found).c_str());
205 val2 = atoi(full.substr(found+1, std::string::npos).c_str());
207 val1 = atoi(full.c_str());
214 runList.push_back( std::pair<unsigned int, unsigned int>(val1, val2) );
225 unsigned int runtype = 0;
231 std::cout << args_info.
tag_given <<
" TAG file(s) is given..." << std::endl;
232 for(
unsigned int i = 0; i < args_info.
tag_given; ++i){
236 for(std::vector<std::string>::iterator it =
tagfile.begin(); it !=
tagfile.end(); ++it){
238 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
249 for(
unsigned int i = 0; i < args_info.
xml_given; ++i){
253 for(std::vector<std::string>::iterator it =
xmlfile.begin(); it !=
xmlfile.end(); ++it){
255 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
265 logger <<
Root::kERROR <<
"Please provide BOTH --root=\"myfile.root\" AND --tree=\"mytreename\" OR --d3pd_dir=\"mydirname\" options " << Root::GEndl;
270 for(
unsigned int i = 0; i < args_info.
root_given; ++i){
276 logger <<
Root::kERROR <<
"In Root file mode Tree name (--d3p_dir=\"mytreename\") must also be provided" << Root::GEndl;
278 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
280 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
289 logger <<
Root::kERROR <<
"Please provide BOTH --root=\"myfile.root\" AND --d3pd_dir=\"myd3pddirname\" options" << Root::GEndl;
294 for(
unsigned int i = 0; i < args_info.
root_given; ++i){
300 logger <<
Root::kWARNING <<
"In D3PD Root file mode Directory name (--d3pd_dir=\"mylumidir\") must also be provided" << Root::GEndl;
305 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
307 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
322 std::list<std::pair<unsigned int, unsigned int> >
::iterator itr = runList.begin();
325 for (; itr != runList.end(); ++itr) {
328 logger <<
Root::kERROR <<
"Can't use open-ended run ranges to specify sample!" << Root::GEndl;
332 for (
unsigned int runnum = itr->first; runnum <= itr->second; runnum++)
339 for (
unsigned int i=0; i<
runnumber.size(); i++) {
349 for (
unsigned int i=0; i<
runnumber.size(); i++) {
353 for (
unsigned int i=0; i<args_info.
lbend_given; i++) {
368 std::vector< xAOD::LumiBlockRangeContainer* > iovcVec;
369 std::vector< std::vector<std::string> > triggerchainVec;
372 TString version(
"30");
380 logger <<
Root::kERROR <<
"number of lbstart and lbend values must match!" << Root::GEndl;
385 logger <<
Root::kERROR <<
"number of lbstart and lbend values must match number of runs with multiple runs specified!" << Root::GEndl;
396 uint32_t lbstart_val;
401 iovc->setStore( iovcAux );
403 std::vector<uint32_t>::iterator itstart;
404 std::vector<uint32_t>::iterator itend;
405 std::vector<uint32_t>::iterator itrun;
411 itstart !=
lbstart.end() && itend !=
lbend.end(); ++itstart,++itend) {
412 lbstart_val = (*itstart);
413 lbend_val = (*itend);
414 logger <<
Root::kINFO <<
"lbstart-lbend [" << lbstart_val <<
"-" << lbend_val <<
"]" << Root::GEndl;
415 if (lbstart_val > lbend_val) {
416 logger <<
Root::kERROR <<
"lbstart > lbend! Should be: lbstart < = lbend" << Root::GEndl;
432 ++itrun, ++itstart, ++itend) {
434 logger <<
Root::kINFO <<
"lbstart-lbend [" << *itstart <<
"-" << *itend <<
"]" << Root::GEndl;
444 iovcVec.push_back(iovc);
446 std::map<TString,TString> metadata;
448 metadata[Form(
"TriggerName%d",j)] = TString(
triggerchain[j]);
449 grlcollection.push_back( *converter.
GetGRLObject(*iovc,metadata,version) );
460 for(std::vector<std::string>::iterator it =
tagfile.begin(); it !=
tagfile.end(); ++it){
462 int n = (*it).find(
".root");
463 std::string tagfilename = (*it).substr(0,n);
468 if(collection == NULL) {
475 grlcollection = reader.GetMergedGRLCollection();
477 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
480 if ( grlcollection[j].HasTriggerInfo() ) {
481 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
484 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
488 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
500 for(std::vector<std::string>::iterator it =
xmlfile.begin(); it !=
xmlfile.end(); ++it){
502 reader.AddXMLFile(*it);
505 grlcollection = reader.GetMergedGRLCollection();
507 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
510 if ( grlcollection[j].HasTriggerInfo() ) {
511 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
514 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
518 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
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());
543 list =
tree->GetUserInfo() ;
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") )
551 reader.AddXMLString(objstr->GetString());
559 grlcollection = reader.GetMergedGRLCollection();
561 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
564 if ( grlcollection[j].HasTriggerInfo() ) {
565 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
568 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
572 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
581 logger <<
Root::kINFO <<
"Being in ROOT D3PD ntuple file mode..." << Root::GEndl;
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);
589 TFile*
file = TFile::Open(filename.c_str());
590 TDirectoryFile * dir = NULL;
592 dir =
dynamic_cast<TDirectoryFile*
>(
file->GetDirectory(
d3pddirname.c_str()));
598 TObjString* objstr = 0;
599 std::map<TString,int> keymap;
600 list = dir->GetListOfKeys();
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()]) ));
609 if ( objstr->GetString().BeginsWith(
"<?xml version=\"1.0\"?") &&
610 objstr->GetString().Contains(
"DOCTYPE LumiRangeCollection") ){
611 reader.AddXMLString(objstr->GetString());
613 logger <<
Root::kERROR <<
"XML string is not in expected format: " << objstr->GetString() <<
". Skipped." << Root::GEndl;
617 logger <<
Root::kERROR <<
"No obj found with key \"" << list->At(j)->GetName() <<
"\"" << Root::GEndl;
627 grlcollection = reader.GetMergedGRLCollection();
628 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
631 if ( grlcollection[j].HasTriggerInfo() ) {
632 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
635 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
639 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
651 if (runtype != 0 && runList.size() > 0) {
652 std::vector<xAOD::LumiBlockRangeContainer*>::iterator iovIt = iovcVec.begin();
653 for (;iovIt != iovcVec.end(); ++iovIt) {
656 while (it != (*iovIt)->end()) {
658 unsigned int runnum = (*it)->startRunNumber() ;
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;
670 logger <<
Root::kDEBUG <<
"Skipping run " << (*it)->startRunNumber() <<
" LB [" << (*it)->startLumiBlockNumber() <<
"-" << (*it)->stopLumiBlockNumber() <<
"] due to command-line run range" << Root::GEndl;
673 it = (*iovIt)->begin();
687 for (
unsigned int j=0; j<iovcVec.size(); ++j) {
693 logger <<
Root::kINFO <<
"--------------------------------------------" << Root::GEndl;
694 TTree
tree(
"LumiMetaData",
"LumiMetaData");
699 lumicalc.
UseMC(
false);
708 lumicalc.IntegrateLumi(iovc, (*it));
709 logger <<
Root::kINFO <<
"--------------------------------------------" << Root::GEndl;
722 if(!grlcollection.empty()){
723 TString
xmlfile =
"ilumicalc_merged_";
725 if (grlcollection.size()==1) {
xmlfile += grlcollection[0].GetSuggestedName() +
".xml"; }
726 else {
xmlfile +=
"grls.xml"; }
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;