Go to the documentation of this file.00001 #include "ForIA/EventLoop.hh"
00002
00003 #include "ForIA/DataConverter.hh"
00004
00005 #include <boost/numeric/conversion/cast.hpp>
00006
00007 #include <iostream>
00008
00009 namespace ForIA{
00010
00011 EventLoop::EventLoop(DataConverter *converter, IHistogrammer *histogrammer):
00012 m_converter(converter), m_histogrammer(histogrammer), m_weightSum(0.0){
00013
00014 }
00015
00016 bool EventLoop::addAnalysis(const string &name){
00017
00018 m_analyses.push_back(m_factory.createAnalysis(name, m_histogrammer));
00019
00020 return true;
00021 }
00022
00023 void EventLoop::printAnalyses(std::ostream &out)const{
00024
00025 vector<string> analyses = m_factory.listAnalyses();
00026 out<<std::endl<<"List of available analyses:"<<std::endl;
00027
00028 for(vector<string>::const_iterator name = analyses.begin();
00029 name != analyses.end(); ++name){
00030 out<<*name<<std::endl;
00031 }
00032
00033 return;
00034 }
00035
00036 bool EventLoop::initialise(){
00037
00038 bool success = true;
00039
00040 for(vector<AnalysisPtr>::iterator analysis = m_analyses.begin();
00041 analysis != m_analyses.end(); ++analysis){
00042 success = success && (*analysis)->initialise();
00043 }
00044
00045 return success;
00046 }
00047
00048 bool EventLoop::finalise(){
00049 bool success = true;
00050
00051 for(vector<AnalysisPtr>::iterator analysis = m_analyses.begin();
00052 analysis != m_analyses.end(); ++analysis){
00053 success = success && (*analysis)->finalise();
00054 }
00055
00056 m_histogrammer->bookHistogram1D("/EventLoop", "sumOfEventWeights", "Sum of event weights in loop", 1, 0.5, 1.5);
00057 m_histogrammer->fillHistogram1D("/EventLoop", "sumOfEventWeights", 1.0, m_weightSum);
00058
00059 return success;
00060 }
00061
00062 bool EventLoop::run(long nEvents){
00063
00064 long counter=0;
00065 long counterThresh=10;
00066 long counterThreshMax=10000;
00067 unsigned int smallCounter = 1;
00068 unsigned int incr=1;
00069
00070 unsigned long vetoCounter=0;
00071 unsigned long vetoMax=50;
00072
00073 string th = "th";
00074
00075 bool success = true;
00076
00077 while(m_converter->nextEvent() && counter != nEvents){
00078
00079 Event ev = m_converter->loadEvent();
00080
00081 if(smallCounter==incr){
00082 try{
00083 std::cout<<"Processing "<<counter<<th<<" event. "<<ev<<std::endl;
00084 }catch(boost::numeric::negative_overflow negEr){
00085 std::cout<<"EventLoop::run : Looks like the event didn't contain enough info."<<std::endl;
00086 std::cout<<"EventLoop::run : Check that the event run/lb/number is present and read in for this data format"<<std::endl;
00087 throw;
00088 }
00089
00090 if(counter == 0){
00091 th="st";
00092 }else if(counter == 1){
00093 th="nd";
00094 }else if(counter == 2){
00095 th="rd";
00096 }else if(counter ==3){
00097 th="th";
00098 }
00099 smallCounter=0;
00100 }
00101
00102 if(counter == counterThresh){
00103 incr *= 10;
00104 if(counterThresh != counterThreshMax){
00105 counterThresh *=10;
00106 }
00107 }
00108
00109 ++smallCounter;
00110 ++counter;
00111
00112 if(!ev.goodLumiBlock()){
00113 if(vetoCounter < vetoMax){
00114 std::cout<<"vetoing event on bad lumi block"<<std::endl;
00115 }else if(vetoCounter == vetoMax){
00116 std::cout<<"reached max number of bad lumi block messages"<<std::endl;
00117 }
00118 ++vetoCounter;
00119 continue;
00120 }
00121 m_weightSum += ev.weight();
00122
00123 bool storeEvent = false;
00124 for(vector<AnalysisPtr>::iterator analysis=m_analyses.begin();
00125 analysis != m_analyses.end(); ++analysis){
00126 (*analysis)->executeClear(ev);
00127 if((*analysis)->storesEvent())storeEvent = true;
00128 }
00129
00130 if(storeEvent) m_converter->storeEvent();
00131
00132 }
00133
00134 if(counter == nEvents){
00135 std::cout<<"Event limit reached - finished"<<std::endl;
00136 }
00137
00138 return success;
00139 }
00140
00141 }