//**********MAIN************************************************************************** int main(int argc, char* argv[]) { if(argc < 2) { cout << argv[0] << " cfg file " << "[run]" << endl; return -1; } //---memory consumption tracking--- float cpu[2]{0}, mem[2]={0}, vsz[2]={0}, rss[2]={0}; //---load options--- CfgManager opts; opts.ParseConfigFile(argv[1]); //-----input setup----- if(argc > 2) { vector<string> run(1, argv[2]); opts.SetOpt("h4reco.run", run); } string outSuffix = opts.GetOpt<string>("h4reco.outNameSuffix"); string run = opts.GetOpt<string>("h4reco.run"); TChain* inTree = new TChain("H4tree"); ReadInputFiles(opts, inTree); H4Tree h4Tree(inTree); //-----output setup----- uint64 index=stoul(run)*1e9; TFile* outROOT = new TFile("ntuples/"+outSuffix+TString(run)+".root", "RECREATE"); outROOT->cd(); RecoTree mainTree(&index); //---Get plugin sequence--- PluginLoader<PluginBase>* loader; vector<PluginLoader<PluginBase>* > pluginLoaders; map<string, PluginBase*> pluginMap; vector<PluginBase*> pluginSequence; vector<string> pluginList = opts.GetOpt<vector<string> >("h4reco.pluginList"); //---plugin creation pluginLoaders.reserve(pluginList.size()); for(auto& plugin : pluginList) { cout << ">>> Loading plugin <" << plugin << ">" << endl; //---create loader loader = new PluginLoader<PluginBase>(opts.GetOpt<string>(plugin+".pluginType")); pluginLoaders.push_back(loader); pluginLoaders.back()->Create(); //---get instance and put it in the plugin sequence PluginBase* newPlugin = pluginLoaders.back()->CreateInstance(); if(newPlugin) { pluginSequence.push_back(newPlugin); pluginSequence.back()->SetInstanceName(plugin); pluginMap[plugin] = pluginSequence.back(); } else { cout << ">>> ERROR: plugin type " << opts.GetOpt<string>(plugin+".pluginType") << " is not defined." << endl; return 0; } } //---begin for(auto& plugin : pluginSequence) { plugin->Begin(opts, &index); for(auto& shared : plugin->GetSharedData("", "TTree", true)) { TTree* tree = (TTree*)shared.obj; tree->SetMaxVirtualSize(10000); tree->SetDirectory(outROOT); } } //---events loop int maxEvents=opts.GetOpt<int>("h4reco.maxEvents"); cout << ">>> Processing H4DAQ run #" << run << " <<<" << endl; while(h4Tree.NextEntry() && (index-stoul(run)*1e9<maxEvents || maxEvents==-1)) { if(index % 1000 == 0) { cout << ">>>Processed events: " << index-stoul(run)*1e9 << "/" << (maxEvents<0 ? h4Tree.GetEntries() : min((int)h4Tree.GetEntries(), maxEvents)) << endl; TrackProcess(cpu, mem, vsz, rss); } //---call ProcessEvent for each plugin for(auto& plugin : pluginSequence) plugin->ProcessEvent(h4Tree, pluginMap, opts); //---fill the main tree with info variables and increase event counter mainTree.time_stamp = h4Tree.evtTimeStart; mainTree.run = h4Tree.runNumber; mainTree.spill = h4Tree.spillNumber; mainTree.event = h4Tree.evtNumber; mainTree.Fill(); ++index; } //---end for(auto& plugin : pluginSequence) { //---call endjob for each plugin plugin->End(opts); //---get permanent data from each plugin and store them in the out file for(auto& shared : plugin->GetSharedData()) { if(shared.obj->IsA()->GetName() == string("TTree")) { TTree* currentTree = (TTree*)shared.obj; outROOT->cd(); currentTree->BuildIndex("index"); currentTree->Write(currentTree->GetName(), TObject::kOverwrite); mainTree.AddFriend(currentTree->GetName()); } else { outROOT->cd(); shared.obj->Write(shared.tag.c_str(), TObject::kOverwrite); } } } //---close mainTree.Write(); opts.Write("cfg"); outROOT->Close(); for(auto& loader : pluginLoaders) loader->Destroy(); //---info TrackProcess(cpu, mem, vsz, rss); exit(0); }