42int main(
int argc,
char * argv[]){
82 if (scalel1trigrate != 1.) {
95 logger <<
Root::kWARNING <<
"Lumitag: " << lumitag <<
" ignored due to --online " << Root::GEndl;
104 logger <<
Root::kINFO <<
"LAr noise burst inefficiency will be calculated from " << lartag << Root::GEndl;
111 logger <<
Root::kINFO <<
"Livetime will include online beamspot validity requirement from " << beamspottag << Root::GEndl;
117 std::string lumimethod;
118 int lumichannel = -1;
122 logger <<
Root::kERROR <<
"Sorry, the online database doesn't have luminosity method names, use --lumichannel instead!" << Root::GEndl;
134 logger <<
Root::kINFO <<
"Both lumimethod and lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
138 logger <<
Root::kINFO <<
"No lumimethod or lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
141 logger <<
Root::kINFO <<
"No lumimethod or lumichannel is given, defaulting to Lumimethod: " << lumimethod << Root::GEndl;
149 logger <<
Root::kINFO <<
"No trigger specified, proceeding with --trigger=None" << Root::GEndl;
167 bool uselivetrigger =
false;
172 uselivetrigger =
true;
176 logger <<
Root::kINFO <<
"Prescale trigger chains will be used for livetime " << Root::GEndl;
184 std::list<std::pair<unsigned int, unsigned int> > runList;
193 size_t found = full.find(
'-');
195 unsigned int val1, val2;
196 if (found != std::string::npos) {
197 val1 = atoi(full.substr(0, found).c_str());
198 val2 = atoi(full.substr(found+1, std::string::npos).c_str());
200 val1 = atoi(full.c_str());
207 runList.push_back( std::pair<unsigned int, unsigned int>(val1, val2) );
218 unsigned int runtype = 0;
224 std::cout << args_info.
tag_given <<
" TAG file(s) is given..." << std::endl;
225 for(
unsigned int i = 0; i < args_info.
tag_given; ++i){
229 for(std::vector<std::string>::iterator it =
tagfile.begin(); it !=
tagfile.end(); ++it){
231 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
242 for(
unsigned int i = 0; i < args_info.
xml_given; ++i){
246 for(std::vector<std::string>::iterator it =
xmlfile.begin(); it !=
xmlfile.end(); ++it){
248 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
258 logger <<
Root::kERROR <<
"Please provide BOTH --root=\"myfile.root\" AND --tree=\"mytreename\" OR --d3pd_dir=\"mydirname\" options " << Root::GEndl;
263 for(
unsigned int i = 0; i < args_info.
root_given; ++i){
269 logger <<
Root::kERROR <<
"In Root file mode Tree name (--d3p_dir=\"mytreename\") must also be provided" << Root::GEndl;
271 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
273 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
282 logger <<
Root::kERROR <<
"Please provide BOTH --root=\"myfile.root\" AND --d3pd_dir=\"myd3pddirname\" options" << Root::GEndl;
287 for(
unsigned int i = 0; i < args_info.
root_given; ++i){
293 logger <<
Root::kWARNING <<
"In D3PD Root file mode Directory name (--d3pd_dir=\"mylumidir\") must also be provided" << Root::GEndl;
298 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
300 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
315 std::list<std::pair<unsigned int, unsigned int> >
::iterator itr = runList.begin();
318 for (; itr != runList.end(); ++itr) {
321 logger <<
Root::kERROR <<
"Can't use open-ended run ranges to specify sample!" << Root::GEndl;
325 for (
unsigned int runnum = itr->first; runnum <= itr->second; runnum++)
332 for (
unsigned int i=0; i<
runnumber.size(); i++) {
342 for (
unsigned int i=0; i<
runnumber.size(); i++) {
346 for (
unsigned int i=0; i<args_info.
lbend_given; i++) {
361 std::vector< xAOD::LumiBlockRangeContainer* > iovcVec;
362 std::vector< std::vector<std::string> > triggerchainVec;
365 TString version(
"30");
373 logger <<
Root::kERROR <<
"number of lbstart and lbend values must match!" << Root::GEndl;
378 logger <<
Root::kERROR <<
"number of lbstart and lbend values must match number of runs with multiple runs specified!" << Root::GEndl;
389 uint32_t lbstart_val;
394 iovc->setStore( iovcAux );
396 std::vector<uint32_t>::iterator itstart;
397 std::vector<uint32_t>::iterator itend;
398 std::vector<uint32_t>::iterator itrun;
404 itstart !=
lbstart.end() && itend !=
lbend.end(); ++itstart,++itend) {
405 lbstart_val = (*itstart);
406 lbend_val = (*itend);
407 logger <<
Root::kINFO <<
"lbstart-lbend [" << lbstart_val <<
"-" << lbend_val <<
"]" << Root::GEndl;
408 if (lbstart_val > lbend_val) {
409 logger <<
Root::kERROR <<
"lbstart > lbend! Should be: lbstart < = lbend" << Root::GEndl;
425 ++itrun, ++itstart, ++itend) {
427 logger <<
Root::kINFO <<
"lbstart-lbend [" << *itstart <<
"-" << *itend <<
"]" << Root::GEndl;
437 iovcVec.push_back(iovc);
439 std::map<TString,TString> metadata;
441 metadata[Form(
"TriggerName%d",j)] = TString(
triggerchain[j]);
442 grlcollection.push_back( *converter.
GetGRLObject(*iovc,metadata,version) );
455 grlcollection = reader.GetMergedGRLCollection();
457 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
460 if ( grlcollection[j].HasTriggerInfo() ) {
461 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
464 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
468 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
480 for(std::vector<std::string>::iterator it =
xmlfile.begin(); it !=
xmlfile.end(); ++it){
482 reader.AddXMLFile(*it);
485 grlcollection = reader.GetMergedGRLCollection();
487 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
490 if ( grlcollection[j].HasTriggerInfo() ) {
491 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
494 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
498 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
512 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
513 logger <<
Root::kINFO <<
"Processing root file: <" << (*it) <<
">" << Root::GEndl;
514 std::string filename = (*it);
515 TFile*
file = TFile::Open(filename.c_str());
523 list =
tree->GetUserInfo() ;
526 for(
int j=0; j<list->GetEntries();++j) {
527 TObjString* objstr =
dynamic_cast<TObjString*
>(list->At(j));
528 if (objstr==0)
continue;
529 if ( objstr->GetString().BeginsWith(
"<?xml version=\"1.0\"?") &&
530 objstr->GetString().Contains(
"DOCTYPE LumiRangeCollection") )
531 reader.AddXMLString(objstr->GetString());
539 grlcollection = reader.GetMergedGRLCollection();
541 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
544 if ( grlcollection[j].HasTriggerInfo() ) {
545 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
548 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
552 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
561 logger <<
Root::kINFO <<
"Being in ROOT D3PD ntuple file mode..." << Root::GEndl;
565 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
566 logger <<
Root::kINFO <<
"Processing root file: <" << (*it) <<
">" << Root::GEndl;
567 std::string filename = (*it);
569 TFile*
file = TFile::Open(filename.c_str());
570 TDirectoryFile * dir = NULL;
572 dir =
dynamic_cast<TDirectoryFile*
>(
file->GetDirectory(
d3pddirname.c_str()));
578 TObjString* objstr = 0;
579 std::map<TString,int> keymap;
580 list = dir->GetListOfKeys();
582 for(
int j=0; j<list->GetEntries();j++) {
583 if ( keymap.find(list->At(j)->GetName())==keymap.end() ) { keymap[list->At(j)->GetName()] = 1; }
584 else { keymap[list->At(j)->GetName()] = keymap[list->At(j)->GetName()]+1; }
585 if(
verbose)
logger <<
Root::kINFO <<
"Found obj key: \"" << Form(
"%s;%d",list->At(j)->GetName(),keymap[list->At(j)->GetName()]) <<
"\"" << Root::GEndl;
586 objstr =
dynamic_cast<TObjString*
>(dir->Get( Form(
"%s;%d",list->At(j)->GetName(),keymap[list->At(j)->GetName()]) ));
589 if ( objstr->GetString().BeginsWith(
"<?xml version=\"1.0\"?") &&
590 objstr->GetString().Contains(
"DOCTYPE LumiRangeCollection") ){
591 reader.AddXMLString(objstr->GetString());
593 logger <<
Root::kERROR <<
"XML string is not in expected format: " << objstr->GetString() <<
". Skipped." << Root::GEndl;
597 logger <<
Root::kERROR <<
"No obj found with key \"" << list->At(j)->GetName() <<
"\"" << Root::GEndl;
607 grlcollection = reader.GetMergedGRLCollection();
608 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
611 if ( grlcollection[j].HasTriggerInfo() ) {
612 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
615 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
619 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
631 if (runtype != 0 && runList.size() > 0) {
632 std::vector<xAOD::LumiBlockRangeContainer*>::iterator iovIt = iovcVec.begin();
633 for (;iovIt != iovcVec.end(); ++iovIt) {
636 while (it != (*iovIt)->end()) {
638 unsigned int runnum = (*it)->startRunNumber() ;
641 std::list<std::pair<unsigned int, unsigned int> >
::iterator runIt = runList.begin();
642 for (; runIt != runList.end(); ++runIt) {
643 if (runnum < runIt->first)
continue;
644 if (runnum > runIt->second)
continue;
650 logger <<
Root::kDEBUG <<
"Skipping run " << (*it)->startRunNumber() <<
" LB [" << (*it)->startLumiBlockNumber() <<
"-" << (*it)->stopLumiBlockNumber() <<
"] due to command-line run range" << Root::GEndl;
653 it = (*iovIt)->begin();
667 for (
unsigned int j=0; j<iovcVec.size(); ++j) {
673 logger <<
Root::kINFO <<
"--------------------------------------------" << Root::GEndl;
674 TTree
tree(
"LumiMetaData",
"LumiMetaData");
679 lumicalc.
UseMC(
false);
688 lumicalc.IntegrateLumi(iovc, (*it));
689 logger <<
Root::kINFO <<
"--------------------------------------------" << Root::GEndl;
702 if(!grlcollection.empty()){
703 TString
xmlfile =
"ilumicalc_merged_";
705 if (grlcollection.size()==1) {
xmlfile += grlcollection[0].GetSuggestedName() +
".xml"; }
706 else {
xmlfile +=
"grls.xml"; }
715 logger <<
Root::kINFO <<
"Real time: " << std::setw(5) << timer.RealTime() <<
" s" << Root::GEndl;
716 logger <<
Root::kINFO <<
"CPU time: " << std::setw(5) << timer.CpuTime() <<
" s" << Root::GEndl;