47int main(
int argc,
char * argv[]){
87 if (scalel1trigrate != 1.) {
100 logger <<
Root::kWARNING <<
"Lumitag: " << lumitag <<
" ignored due to --online " << Root::GEndl;
109 logger <<
Root::kINFO <<
"LAr noise burst inefficiency will be calculated from " << lartag << Root::GEndl;
116 logger <<
Root::kINFO <<
"Livetime will include online beamspot validity requirement from " << beamspottag << Root::GEndl;
122 std::string lumimethod;
123 int lumichannel = -1;
127 logger <<
Root::kERROR <<
"Sorry, the online database doesn't have luminosity method names, use --lumichannel instead!" << Root::GEndl;
139 logger <<
Root::kINFO <<
"Both lumimethod and lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
143 logger <<
Root::kINFO <<
"No lumimethod or lumichannel is given, defaulting to Lumichannel: " << lumichannel << Root::GEndl;
146 logger <<
Root::kINFO <<
"No lumimethod or lumichannel is given, defaulting to Lumimethod: " << lumimethod << Root::GEndl;
154 logger <<
Root::kINFO <<
"No trigger specified, proceeding with --trigger=None" << Root::GEndl;
172 bool uselivetrigger =
false;
177 uselivetrigger =
true;
181 logger <<
Root::kINFO <<
"Prescale trigger chains will be used for livetime " << Root::GEndl;
189 std::list<std::pair<unsigned int, unsigned int> > runList;
198 size_t found = full.find(
'-');
200 unsigned int val1, val2;
201 if (found != std::string::npos) {
202 val1 = atoi(full.substr(0, found).c_str());
203 val2 = atoi(full.substr(found+1, std::string::npos).c_str());
205 val1 = atoi(full.c_str());
212 runList.push_back( std::pair<unsigned int, unsigned int>(val1, val2) );
223 unsigned int runtype = 0;
229 std::cout << args_info.
tag_given <<
" TAG file(s) is given..." << std::endl;
230 for(
unsigned int i = 0; i < args_info.
tag_given; ++i){
234 for(std::vector<std::string>::iterator it =
tagfile.begin(); it !=
tagfile.end(); ++it){
236 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
247 for(
unsigned int i = 0; i < args_info.
xml_given; ++i){
251 for(std::vector<std::string>::iterator it =
xmlfile.begin(); it !=
xmlfile.end(); ++it){
253 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
263 logger <<
Root::kERROR <<
"Please provide BOTH --root=\"myfile.root\" AND --tree=\"mytreename\" OR --d3pd_dir=\"mydirname\" options " << Root::GEndl;
268 for(
unsigned int i = 0; i < args_info.
root_given; ++i){
274 logger <<
Root::kERROR <<
"In Root file mode Tree name (--d3p_dir=\"mytreename\") must also be provided" << Root::GEndl;
276 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
278 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
287 logger <<
Root::kERROR <<
"Please provide BOTH --root=\"myfile.root\" AND --d3pd_dir=\"myd3pddirname\" options" << Root::GEndl;
292 for(
unsigned int i = 0; i < args_info.
root_given; ++i){
298 logger <<
Root::kWARNING <<
"In D3PD Root file mode Directory name (--d3pd_dir=\"mylumidir\") must also be provided" << Root::GEndl;
303 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
305 logger <<
Root::kWARNING <<
"Problem: file ["<< (*it) <<
"] may not exist. Will try anyways..." << Root::GEndl;
320 std::list<std::pair<unsigned int, unsigned int> >
::iterator itr = runList.begin();
323 for (; itr != runList.end(); ++itr) {
326 logger <<
Root::kERROR <<
"Can't use open-ended run ranges to specify sample!" << Root::GEndl;
330 for (
unsigned int runnum = itr->first; runnum <= itr->second; runnum++)
337 for (
unsigned int i=0; i<
runnumber.size(); i++) {
347 for (
unsigned int i=0; i<
runnumber.size(); i++) {
351 for (
unsigned int i=0; i<args_info.
lbend_given; i++) {
366 std::vector< xAOD::LumiBlockRangeContainer* > iovcVec;
367 std::vector< std::vector<std::string> > triggerchainVec;
370 TString version(
"30");
378 logger <<
Root::kERROR <<
"number of lbstart and lbend values must match!" << Root::GEndl;
383 logger <<
Root::kERROR <<
"number of lbstart and lbend values must match number of runs with multiple runs specified!" << Root::GEndl;
394 uint32_t lbstart_val;
399 iovc->setStore( iovcAux );
401 std::vector<uint32_t>::iterator itstart;
402 std::vector<uint32_t>::iterator itend;
403 std::vector<uint32_t>::iterator itrun;
409 itstart !=
lbstart.end() && itend !=
lbend.end(); ++itstart,++itend) {
410 lbstart_val = (*itstart);
411 lbend_val = (*itend);
412 logger <<
Root::kINFO <<
"lbstart-lbend [" << lbstart_val <<
"-" << lbend_val <<
"]" << Root::GEndl;
413 if (lbstart_val > lbend_val) {
414 logger <<
Root::kERROR <<
"lbstart > lbend! Should be: lbstart < = lbend" << Root::GEndl;
430 ++itrun, ++itstart, ++itend) {
432 logger <<
Root::kINFO <<
"lbstart-lbend [" << *itstart <<
"-" << *itend <<
"]" << Root::GEndl;
442 iovcVec.push_back(iovc);
444 std::map<TString,TString> metadata;
446 metadata[Form(
"TriggerName%d",j)] = TString(
triggerchain[j]);
447 grlcollection.push_back( *converter.
GetGRLObject(*iovc,metadata,version) );
458 std::string connection =
"";
459 std::string
type =
"RootCollection";
461 for(std::vector<std::string>::iterator it =
tagfile.begin(); it !=
tagfile.end(); ++it){
463 int n = (*it).find(
".root");
464 std::string tagfilename = (*it).substr(0,n);
469 if(collection == NULL) {
476 grlcollection = reader.GetMergedGRLCollection();
478 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
481 if ( grlcollection[j].HasTriggerInfo() ) {
482 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
485 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
489 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
501 for(std::vector<std::string>::iterator it =
xmlfile.begin(); it !=
xmlfile.end(); ++it){
503 reader.AddXMLFile(*it);
506 grlcollection = reader.GetMergedGRLCollection();
508 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
511 if ( grlcollection[j].HasTriggerInfo() ) {
512 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
515 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
519 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
533 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
534 logger <<
Root::kINFO <<
"Processing root file: <" << (*it) <<
">" << Root::GEndl;
535 std::string filename = (*it);
536 TFile*
file = TFile::Open(filename.c_str());
544 list =
tree->GetUserInfo() ;
547 for(
int j=0; j<list->GetEntries();++j) {
548 TObjString* objstr =
dynamic_cast<TObjString*
>(list->At(j));
549 if (objstr==0)
continue;
550 if ( objstr->GetString().BeginsWith(
"<?xml version=\"1.0\"?") &&
551 objstr->GetString().Contains(
"DOCTYPE LumiRangeCollection") )
552 reader.AddXMLString(objstr->GetString());
560 grlcollection = reader.GetMergedGRLCollection();
562 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
565 if ( grlcollection[j].HasTriggerInfo() ) {
566 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
569 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
573 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
582 logger <<
Root::kINFO <<
"Being in ROOT D3PD ntuple file mode..." << Root::GEndl;
586 for(std::vector<std::string>::iterator it =
rootfile.begin(); it !=
rootfile.end(); ++it){
587 logger <<
Root::kINFO <<
"Processing root file: <" << (*it) <<
">" << Root::GEndl;
588 std::string filename = (*it);
590 TFile*
file = TFile::Open(filename.c_str());
591 TDirectoryFile * dir = NULL;
593 dir =
dynamic_cast<TDirectoryFile*
>(
file->GetDirectory(
d3pddirname.c_str()));
599 TObjString* objstr = 0;
600 std::map<TString,int> keymap;
601 list = dir->GetListOfKeys();
603 for(
int j=0; j<list->GetEntries();j++) {
604 if ( keymap.find(list->At(j)->GetName())==keymap.end() ) { keymap[list->At(j)->GetName()] = 1; }
605 else { keymap[list->At(j)->GetName()] = keymap[list->At(j)->GetName()]+1; }
606 if(
verbose)
logger <<
Root::kINFO <<
"Found obj key: \"" << Form(
"%s;%d",list->At(j)->GetName(),keymap[list->At(j)->GetName()]) <<
"\"" << Root::GEndl;
607 objstr =
dynamic_cast<TObjString*
>(dir->Get( Form(
"%s;%d",list->At(j)->GetName(),keymap[list->At(j)->GetName()]) ));
610 if ( objstr->GetString().BeginsWith(
"<?xml version=\"1.0\"?") &&
611 objstr->GetString().Contains(
"DOCTYPE LumiRangeCollection") ){
612 reader.AddXMLString(objstr->GetString());
614 logger <<
Root::kERROR <<
"XML string is not in expected format: " << objstr->GetString() <<
". Skipped." << Root::GEndl;
618 logger <<
Root::kERROR <<
"No obj found with key \"" << list->At(j)->GetName() <<
"\"" << Root::GEndl;
628 grlcollection = reader.GetMergedGRLCollection();
629 for (
unsigned int j=0; j<grlcollection.size(); ++j) {
632 if ( grlcollection[j].HasTriggerInfo() ) {
633 triggerchainVec.push_back(grlcollection[j].GetTriggerList());
636 <<
"> already contain trigger names. Cmd-line triggers are ignored!" << Root::GEndl;
640 grlcollection[j].AddMetaData( Form(
"TriggerName%d",k),TString(
triggerchain[k]) );
652 if (runtype != 0 && runList.size() > 0) {
653 std::vector<xAOD::LumiBlockRangeContainer*>::iterator iovIt = iovcVec.begin();
654 for (;iovIt != iovcVec.end(); ++iovIt) {
657 while (it != (*iovIt)->end()) {
659 unsigned int runnum = (*it)->startRunNumber() ;
662 std::list<std::pair<unsigned int, unsigned int> >
::iterator runIt = runList.begin();
663 for (; runIt != runList.end(); ++runIt) {
664 if (runnum < runIt->first)
continue;
665 if (runnum > runIt->second)
continue;
671 logger <<
Root::kDEBUG <<
"Skipping run " << (*it)->startRunNumber() <<
" LB [" << (*it)->startLumiBlockNumber() <<
"-" << (*it)->stopLumiBlockNumber() <<
"] due to command-line run range" << Root::GEndl;
674 it = (*iovIt)->begin();
688 for (
unsigned int j=0; j<iovcVec.size(); ++j) {
694 logger <<
Root::kINFO <<
"--------------------------------------------" << Root::GEndl;
695 TTree
tree(
"LumiMetaData",
"LumiMetaData");
700 lumicalc.
UseMC(
false);
709 lumicalc.IntegrateLumi(iovc, (*it));
710 logger <<
Root::kINFO <<
"--------------------------------------------" << Root::GEndl;
723 if(!grlcollection.empty()){
724 TString
xmlfile =
"ilumicalc_merged_";
726 if (grlcollection.size()==1) {
xmlfile += grlcollection[0].GetSuggestedName() +
".xml"; }
727 else {
xmlfile +=
"grls.xml"; }
736 logger <<
Root::kINFO <<
"Real time: " << std::setw(5) << timer.RealTime() <<
" s" << Root::GEndl;
737 logger <<
Root::kINFO <<
"CPU time: " << std::setw(5) << timer.CpuTime() <<
" s" << Root::GEndl;