45int main(
int argc,
char * argv[]){
85 if (scalel1trigrate != 1.) {
98 logger <<
Root::kWARNING <<
"Lumitag: " << lumitag <<
" ignored due to --online " << Root::GEndl;
107 logger <<
Root::kINFO <<
"LAr noise burst inefficiency will be calculated from " << lartag << Root::GEndl;
114 logger <<
Root::kINFO <<
"Livetime will include online beamspot validity requirement from " << beamspottag << Root::GEndl;
120 std::string lumimethod;
121 int lumichannel = -1;
125 logger <<
Root::kERROR <<
"Sorry, the online database doesn't have luminosity method names, use --lumichannel instead!" << Root::GEndl;
137 logger <<
Root::kINFO <<
"Both lumimethod and lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
141 logger <<
Root::kINFO <<
"No lumimethod or lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
144 logger <<
Root::kINFO <<
"No lumimethod or lumichannel is given, defaulting to Lumimethod: " << lumimethod << Root::GEndl;
152 logger <<
Root::kINFO <<
"No trigger specified, proceeding with --trigger=None" << Root::GEndl;
170 bool uselivetrigger =
false;
175 uselivetrigger =
true;
179 logger <<
Root::kINFO <<
"Prescale trigger chains will be used for livetime " << Root::GEndl;
187 std::list<std::pair<unsigned int, unsigned int> > runList;
196 size_t found = full.find(
'-');
198 unsigned int val1, val2;
199 if (found != std::string::npos) {
200 val1 = atoi(full.substr(0, found).c_str());
201 val2 = atoi(full.substr(found+1, std::string::npos).c_str());
203 val1 = atoi(full.c_str());
210 runList.push_back( std::pair<unsigned int, unsigned int>(val1, val2) );
221 unsigned int runtype = 0;
227 std::cout << args_info.
tag_given <<
" TAG file(s) is given..." << std::endl;
228 for(
unsigned int i = 0; i < args_info.
tag_given; ++i){
232 for(std::vector<std::string>::iterator it =
tagfile.begin(); it !=
tagfile.end(); ++it){
234 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
245 for(
unsigned int i = 0; i < args_info.
xml_given; ++i){
249 for(std::vector<std::string>::iterator it =
xmlfile.begin(); it !=
xmlfile.end(); ++it){
251 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
261 logger <<
Root::kERROR <<
"Please provide BOTH --root=\"myfile.root\" AND --tree=\"mytreename\" OR --d3pd_dir=\"mydirname\" options " << Root::GEndl;
266 for(
unsigned int i = 0; i < args_info.
root_given; ++i){
272 logger <<
Root::kERROR <<
"In Root file mode Tree name (--d3p_dir=\"mytreename\") must also be provided" << Root::GEndl;
274 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
276 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
285 logger <<
Root::kERROR <<
"Please provide BOTH --root=\"myfile.root\" AND --d3pd_dir=\"myd3pddirname\" options" << Root::GEndl;
290 for(
unsigned int i = 0; i < args_info.
root_given; ++i){
296 logger <<
Root::kWARNING <<
"In D3PD Root file mode Directory name (--d3pd_dir=\"mylumidir\") must also be provided" << Root::GEndl;
301 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
303 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
318 std::list<std::pair<unsigned int, unsigned int> >
::iterator itr = runList.begin();
321 for (; itr != runList.end(); ++itr) {
324 logger <<
Root::kERROR <<
"Can't use open-ended run ranges to specify sample!" << Root::GEndl;
328 for (
unsigned int runnum = itr->first; runnum <= itr->second; runnum++)
335 for (
unsigned int i=0; i<
runnumber.size(); i++) {
345 for (
unsigned int i=0; i<
runnumber.size(); i++) {
349 for (
unsigned int i=0; i<args_info.
lbend_given; i++) {
364 std::vector< xAOD::LumiBlockRangeContainer* > iovcVec;
365 std::vector< std::vector<std::string> > triggerchainVec;
368 TString version(
"30");
376 logger <<
Root::kERROR <<
"number of lbstart and lbend values must match!" << Root::GEndl;
381 logger <<
Root::kERROR <<
"number of lbstart and lbend values must match number of runs with multiple runs specified!" << Root::GEndl;
392 uint32_t lbstart_val;
397 iovc->setStore( iovcAux );
399 std::vector<uint32_t>::iterator itstart;
400 std::vector<uint32_t>::iterator itend;
401 std::vector<uint32_t>::iterator itrun;
407 itstart !=
lbstart.end() && itend !=
lbend.end(); ++itstart,++itend) {
408 lbstart_val = (*itstart);
409 lbend_val = (*itend);
410 logger <<
Root::kINFO <<
"lbstart-lbend [" << lbstart_val <<
"-" << lbend_val <<
"]" << Root::GEndl;
411 if (lbstart_val > lbend_val) {
412 logger <<
Root::kERROR <<
"lbstart > lbend! Should be: lbstart < = lbend" << Root::GEndl;
428 ++itrun, ++itstart, ++itend) {
430 logger <<
Root::kINFO <<
"lbstart-lbend [" << *itstart <<
"-" << *itend <<
"]" << Root::GEndl;
440 iovcVec.push_back(iovc);
442 std::map<TString,TString> metadata;
444 metadata[Form(
"TriggerName%d",j)] = TString(
triggerchain[j]);
445 grlcollection.push_back( *converter.
GetGRLObject(*iovc,metadata,version) );
456 for(std::vector<std::string>::iterator it =
tagfile.begin(); it !=
tagfile.end(); ++it){
458 int n = (*it).find(
".root");
459 std::string tagfilename = (*it).substr(0,n);
463 if(collection == NULL) {
470 grlcollection = reader.GetMergedGRLCollection();
472 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
475 if ( grlcollection[j].HasTriggerInfo() ) {
476 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
479 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
483 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
495 for(std::vector<std::string>::iterator it =
xmlfile.begin(); it !=
xmlfile.end(); ++it){
497 reader.AddXMLFile(*it);
500 grlcollection = reader.GetMergedGRLCollection();
502 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
505 if ( grlcollection[j].HasTriggerInfo() ) {
506 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
509 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
513 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
527 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
528 logger <<
Root::kINFO <<
"Processing root file: <" << (*it) <<
">" << Root::GEndl;
529 std::string filename = (*it);
530 TFile*
file = TFile::Open(filename.c_str());
538 list =
tree->GetUserInfo() ;
541 for(
int j=0; j<list->GetEntries();++j) {
542 TObjString* objstr =
dynamic_cast<TObjString*
>(list->At(j));
543 if (objstr==0)
continue;
544 if ( objstr->GetString().BeginsWith(
"<?xml version=\"1.0\"?") &&
545 objstr->GetString().Contains(
"DOCTYPE LumiRangeCollection") )
546 reader.AddXMLString(objstr->GetString());
554 grlcollection = reader.GetMergedGRLCollection();
556 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
559 if ( grlcollection[j].HasTriggerInfo() ) {
560 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
563 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
567 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
576 logger <<
Root::kINFO <<
"Being in ROOT D3PD ntuple file mode..." << Root::GEndl;
580 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
581 logger <<
Root::kINFO <<
"Processing root file: <" << (*it) <<
">" << Root::GEndl;
582 std::string filename = (*it);
584 TFile*
file = TFile::Open(filename.c_str());
585 TDirectoryFile * dir = NULL;
587 dir =
dynamic_cast<TDirectoryFile*
>(
file->GetDirectory(
d3pddirname.c_str()));
593 TObjString* objstr = 0;
594 std::map<TString,int> keymap;
595 list = dir->GetListOfKeys();
597 for(
int j=0; j<list->GetEntries();j++) {
598 if ( keymap.find(list->At(j)->GetName())==keymap.end() ) { keymap[list->At(j)->GetName()] = 1; }
599 else { keymap[list->At(j)->GetName()] = keymap[list->At(j)->GetName()]+1; }
600 if(
verbose)
logger <<
Root::kINFO <<
"Found obj key: \"" << Form(
"%s;%d",list->At(j)->GetName(),keymap[list->At(j)->GetName()]) <<
"\"" << Root::GEndl;
601 objstr =
dynamic_cast<TObjString*
>(dir->Get( Form(
"%s;%d",list->At(j)->GetName(),keymap[list->At(j)->GetName()]) ));
604 if ( objstr->GetString().BeginsWith(
"<?xml version=\"1.0\"?") &&
605 objstr->GetString().Contains(
"DOCTYPE LumiRangeCollection") ){
606 reader.AddXMLString(objstr->GetString());
608 logger <<
Root::kERROR <<
"XML string is not in expected format: " << objstr->GetString() <<
". Skipped." << Root::GEndl;
612 logger <<
Root::kERROR <<
"No obj found with key \"" << list->At(j)->GetName() <<
"\"" << Root::GEndl;
622 grlcollection = reader.GetMergedGRLCollection();
623 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
626 if ( grlcollection[j].HasTriggerInfo() ) {
627 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
630 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
634 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
646 if (runtype != 0 && runList.size() > 0) {
647 std::vector<xAOD::LumiBlockRangeContainer*>::iterator iovIt = iovcVec.begin();
648 for (;iovIt != iovcVec.end(); ++iovIt) {
651 while (it != (*iovIt)->end()) {
653 unsigned int runnum = (*it)->startRunNumber() ;
656 std::list<std::pair<unsigned int, unsigned int> >
::iterator runIt = runList.begin();
657 for (; runIt != runList.end(); ++runIt) {
658 if (runnum < runIt->first)
continue;
659 if (runnum > runIt->second)
continue;
665 logger <<
Root::kDEBUG <<
"Skipping run " << (*it)->startRunNumber() <<
" LB [" << (*it)->startLumiBlockNumber() <<
"-" << (*it)->stopLumiBlockNumber() <<
"] due to command-line run range" << Root::GEndl;
668 it = (*iovIt)->begin();
682 for (
unsigned int j=0; j<iovcVec.size(); ++j) {
688 logger <<
Root::kINFO <<
"--------------------------------------------" << Root::GEndl;
689 TTree
tree(
"LumiMetaData",
"LumiMetaData");
694 lumicalc.
UseMC(
false);
703 lumicalc.IntegrateLumi(iovc, (*it));
704 logger <<
Root::kINFO <<
"--------------------------------------------" << Root::GEndl;
717 if(!grlcollection.empty()){
718 TString
xmlfile =
"ilumicalc_merged_";
720 if (grlcollection.size()==1) {
xmlfile += grlcollection[0].GetSuggestedName() +
".xml"; }
721 else {
xmlfile +=
"grls.xml"; }
730 logger <<
Root::kINFO <<
"Real time: " << std::setw(5) << timer.RealTime() <<
" s" << Root::GEndl;
731 logger <<
Root::kINFO <<
"CPU time: " << std::setw(5) << timer.CpuTime() <<
" s" << Root::GEndl;