CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWLiteAnalyzerWrapper.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_UtilAlgos_interface_FWLiteAnalyzerWrapper_h
2 #define PhysicsTools_UtilAlgos_interface_FWLiteAnalyzerWrapper_h
3 
4 #include <string>
5 #include <vector>
6 #include <iostream>
7 #include <boost/shared_ptr.hpp>
8 
9 #include <TFile.h>
10 #include <TSystem.h>
11 
19 
101 namespace fwlite {
102 
103  template<class T>
105 
106  public:
110  virtual ~AnalyzerWrapper(){};
112  virtual void beginJob() { analyzer_->beginJob(); }
114  virtual void analyze();
116  virtual void endJob() { analyzer_->endJob(); }
117 
118  protected:
126  unsigned int reportAfter_;
130  boost::shared_ptr<T> analyzer_;
131  };
132 
134  template<class T>
136  inputHandler_( cfg ), outputHandler_( cfg ), maxEvents_(inputHandler_.maxEvents()),
137  reportAfter_(inputHandler_.reportAfter()), fileService_( outputHandler_.file() )
138  {
139  // analysis specific parameters
140  const edm::ParameterSet& ana = cfg.getParameter<edm::ParameterSet>(analyzerName.c_str());
141  if(directory.empty()){
142  // create analysis class of type BasicAnalyzer
143  analyzer_ = boost::shared_ptr<T>( new T( ana, fileService_) );
144  }
145  else{
146  // create a directory in the file if directory string is non empty
147  TFileDirectory dir = fileService_.mkdir(directory.c_str());
148  analyzer_ = boost::shared_ptr<T>( new T( ana, dir ) );
149  }
150  }
151 
153  template<class T>
155  int ievt=0;
156  std::vector<std::string> const & inputFiles = inputHandler_.files();
157  // loop the vector of input files
158  fwlite::ChainEvent event( inputFiles );
159  for(event.toBegin(); !event.atEnd(); ++event, ++ievt){
160  // break loop if maximal number of events is reached
161  if(maxEvents_>0 ? ievt+1>maxEvents_ : false) break;
162  // simple event counter
163  if(reportAfter_!=0 ? (ievt>0 && ievt%reportAfter_==0) : false)
164  std::cout << " processing event: " << ievt << std::endl;
165  // analyze event
166  analyzer_->analyze(event);
167  }
168  }
169 }
170 
171 #endif
T getParameter(std::string const &) const
tuple cfg
Definition: looper.py:259
fwlite::OutputFiles outputHandler_
helper class for output file handling
fwlite::TFileService fileService_
TFileService for histogram management.
dictionary analyzer_
fwlite::InputSource inputHandler_
helper class for input parameter handling
virtual void beginJob()
everything which has to be done before the event loop
virtual void endJob()
everything which has to be done after the event loop
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual bool atEnd() const
Definition: ChainEvent.cc:303
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
virtual void analyze()
everything which has to be done during the event loop. NOTE: the event will be looped inside this fun...
ChainEvent const & toBegin()
Definition: ChainEvent.cc:200
int maxEvents_
maximal number of events to be processed (-1 means to loop over all event)
virtual ~AnalyzerWrapper()
default destructor
AnalyzerWrapper(const edm::ParameterSet &cfg, std::string analyzerName, std::string directory="")
default constructor
tuple inputFiles
Definition: merge.py:5
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35
long double T
unsigned int reportAfter_
number of events after which the progress will be reported (0 means no report)
boost::shared_ptr< T > analyzer_
derived class of type BasicAnalyzer