48int main(
int argc,
char * argv[]){
88 if (scalel1trigrate != 1.) {
101 logger <<
Root::kWARNING <<
"Lumitag: " << lumitag <<
" ignored due to --online " << Root::GEndl;
110 logger <<
Root::kINFO <<
"LAr noise burst inefficiency will be calculated from " << lartag << Root::GEndl;
117 logger <<
Root::kINFO <<
"Livetime will include online beamspot validity requirement from " << beamspottag << Root::GEndl;
123 std::string lumimethod;
124 int lumichannel = -1;
128 logger <<
Root::kERROR <<
"Sorry, the online database doesn't have luminosity method names, use --lumichannel instead!" << Root::GEndl;
140 logger <<
Root::kINFO <<
"Both lumimethod and lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
144 logger <<
Root::kINFO <<
"No lumimethod or lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
147 logger <<
Root::kINFO <<
"No lumimethod or lumichannel is given, defaulting to Lumimethod: " << lumimethod << Root::GEndl;
155 logger <<
Root::kINFO <<
"No trigger specified, proceeding with --trigger=None" << Root::GEndl;
173 bool uselivetrigger =
false;
178 uselivetrigger =
true;
182 logger <<
Root::kINFO <<
"Prescale trigger chains will be used for livetime " << Root::GEndl;
190 std::list<std::pair<unsigned int, unsigned int> > runList;
199 size_t found = full.find(
'-');
201 unsigned int val1, val2;
202 if (found != std::string::npos) {
203 val1 = atoi(full.substr(0, found).c_str());
204 val2 = atoi(full.substr(found+1, std::string::npos).c_str());
206 val1 = atoi(full.c_str());
213 runList.push_back( std::pair<unsigned int, unsigned int>(val1, val2) );
224 unsigned int runtype = 0;
230 std::cout << args_info.
tag_given <<
" TAG file(s) is given..." << std::endl;
231 for(
unsigned int i = 0; i < args_info.
tag_given; ++i){
235 for(std::vector<std::string>::iterator it =
tagfile.begin(); it !=
tagfile.end(); ++it){
237 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
248 for(
unsigned int i = 0; i < args_info.
xml_given; ++i){
252 for(std::vector<std::string>::iterator it =
xmlfile.begin(); it !=
xmlfile.end(); ++it){
254 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
264 logger <<
Root::kERROR <<
"Please provide BOTH --root=\"myfile.root\" AND --tree=\"mytreename\" OR --d3pd_dir=\"mydirname\" options " << Root::GEndl;
269 for(
unsigned int i = 0; i < args_info.
root_given; ++i){
275 logger <<
Root::kERROR <<
"In Root file mode Tree name (--d3p_dir=\"mytreename\") must also be provided" << Root::GEndl;
277 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
279 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
288 logger <<
Root::kERROR <<
"Please provide BOTH --root=\"myfile.root\" AND --d3pd_dir=\"myd3pddirname\" options" << Root::GEndl;
293 for(
unsigned int i = 0; i < args_info.
root_given; ++i){
299 logger <<
Root::kWARNING <<
"In D3PD Root file mode Directory name (--d3pd_dir=\"mylumidir\") must also be provided" << Root::GEndl;
304 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
306 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
321 std::list<std::pair<unsigned int, unsigned int> >
::iterator itr = runList.begin();
324 for (; itr != runList.end(); ++itr) {
327 logger <<
Root::kERROR <<
"Can't use open-ended run ranges to specify sample!" << Root::GEndl;
331 for (
unsigned int runnum = itr->first; runnum <= itr->second; runnum++)
338 for (
unsigned int i=0; i<
runnumber.size(); i++) {
348 for (
unsigned int i=0; i<
runnumber.size(); i++) {
352 for (
unsigned int i=0; i<args_info.
lbend_given; i++) {
367 std::vector< xAOD::LumiBlockRangeContainer* > iovcVec;
368 std::vector< std::vector<std::string> > triggerchainVec;
371 TString version(
"30");
379 logger <<
Root::kERROR <<
"number of lbstart and lbend values must match!" << Root::GEndl;
384 logger <<
Root::kERROR <<
"number of lbstart and lbend values must match number of runs with multiple runs specified!" << Root::GEndl;
395 uint32_t lbstart_val;
400 iovc->setStore( iovcAux );
402 std::vector<uint32_t>::iterator itstart;
403 std::vector<uint32_t>::iterator itend;
404 std::vector<uint32_t>::iterator itrun;
410 itstart !=
lbstart.end() && itend !=
lbend.end(); ++itstart,++itend) {
411 lbstart_val = (*itstart);
412 lbend_val = (*itend);
413 logger <<
Root::kINFO <<
"lbstart-lbend [" << lbstart_val <<
"-" << lbend_val <<
"]" << Root::GEndl;
414 if (lbstart_val > lbend_val) {
415 logger <<
Root::kERROR <<
"lbstart > lbend! Should be: lbstart < = lbend" << Root::GEndl;
431 ++itrun, ++itstart, ++itend) {
433 logger <<
Root::kINFO <<
"lbstart-lbend [" << *itstart <<
"-" << *itend <<
"]" << Root::GEndl;
443 iovcVec.push_back(iovc);
445 std::map<TString,TString> metadata;
447 metadata[Form(
"TriggerName%d",j)] = TString(
triggerchain[j]);
448 grlcollection.push_back( *converter.
GetGRLObject(*iovc,metadata,version) );
459 for(std::vector<std::string>::iterator it =
tagfile.begin(); it !=
tagfile.end(); ++it){
461 int n = (*it).find(
".root");
462 std::string tagfilename = (*it).substr(0,n);
467 if(collection == NULL) {
474 grlcollection = reader.GetMergedGRLCollection();
476 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
479 if ( grlcollection[j].HasTriggerInfo() ) {
480 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
483 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
487 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
499 for(std::vector<std::string>::iterator it =
xmlfile.begin(); it !=
xmlfile.end(); ++it){
501 reader.AddXMLFile(*it);
504 grlcollection = reader.GetMergedGRLCollection();
506 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
509 if ( grlcollection[j].HasTriggerInfo() ) {
510 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
513 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
517 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
531 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
532 logger <<
Root::kINFO <<
"Processing root file: <" << (*it) <<
">" << Root::GEndl;
533 std::string filename = (*it);
534 TFile*
file = TFile::Open(filename.c_str());
542 list =
tree->GetUserInfo() ;
545 for(
int j=0; j<list->GetEntries();++j) {
546 TObjString* objstr =
dynamic_cast<TObjString*
>(list->At(j));
547 if (objstr==0)
continue;
548 if ( objstr->GetString().BeginsWith(
"<?xml version=\"1.0\"?") &&
549 objstr->GetString().Contains(
"DOCTYPE LumiRangeCollection") )
550 reader.AddXMLString(objstr->GetString());
558 grlcollection = reader.GetMergedGRLCollection();
560 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
563 if ( grlcollection[j].HasTriggerInfo() ) {
564 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
567 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
571 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
580 logger <<
Root::kINFO <<
"Being in ROOT D3PD ntuple file mode..." << Root::GEndl;
584 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
585 logger <<
Root::kINFO <<
"Processing root file: <" << (*it) <<
">" << Root::GEndl;
586 std::string filename = (*it);
588 TFile*
file = TFile::Open(filename.c_str());
589 TDirectoryFile * dir = NULL;
591 dir =
dynamic_cast<TDirectoryFile*
>(
file->GetDirectory(
d3pddirname.c_str()));
597 TObjString* objstr = 0;
598 std::map<TString,int> keymap;
599 list = dir->GetListOfKeys();
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()]) ));
608 if ( objstr->GetString().BeginsWith(
"<?xml version=\"1.0\"?") &&
609 objstr->GetString().Contains(
"DOCTYPE LumiRangeCollection") ){
610 reader.AddXMLString(objstr->GetString());
612 logger <<
Root::kERROR <<
"XML string is not in expected format: " << objstr->GetString() <<
". Skipped." << Root::GEndl;
616 logger <<
Root::kERROR <<
"No obj found with key \"" << list->At(j)->GetName() <<
"\"" << Root::GEndl;
626 grlcollection = reader.GetMergedGRLCollection();
627 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
630 if ( grlcollection[j].HasTriggerInfo() ) {
631 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
634 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
638 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
650 if (runtype != 0 && runList.size() > 0) {
651 std::vector<xAOD::LumiBlockRangeContainer*>::iterator iovIt = iovcVec.begin();
652 for (;iovIt != iovcVec.end(); ++iovIt) {
655 while (it != (*iovIt)->end()) {
657 unsigned int runnum = (*it)->startRunNumber() ;
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;
669 logger <<
Root::kDEBUG <<
"Skipping run " << (*it)->startRunNumber() <<
" LB [" << (*it)->startLumiBlockNumber() <<
"-" << (*it)->stopLumiBlockNumber() <<
"] due to command-line run range" << Root::GEndl;
672 it = (*iovIt)->begin();
686 for (
unsigned int j=0; j<iovcVec.size(); ++j) {
692 logger <<
Root::kINFO <<
"--------------------------------------------" << Root::GEndl;
693 TTree
tree(
"LumiMetaData",
"LumiMetaData");
698 lumicalc.
UseMC(
false);
707 lumicalc.IntegrateLumi(iovc, (*it));
708 logger <<
Root::kINFO <<
"--------------------------------------------" << Root::GEndl;
721 if(!grlcollection.empty()){
722 TString
xmlfile =
"ilumicalc_merged_";
724 if (grlcollection.size()==1) {
xmlfile += grlcollection[0].GetSuggestedName() +
".xml"; }
725 else {
xmlfile +=
"grls.xml"; }
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;