CMS 3D CMS Logo

FWLiteAnalyzerWrapper.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_FWLite_interface_FWLiteAnalyzerWrapper_h
2 #define PhysicsTools_FWLite_interface_FWLiteAnalyzerWrapper_h
3 
4 #include <string>
5 #include <vector>
6 #include <iostream>
7 
8 #include <TFile.h>
9 #include <TSystem.h>
10 
17 
98 namespace fwlite {
99 
100  template <class T>
102  public:
106  virtual ~AnalyzerWrapper(){};
108  virtual void beginJob() { analyzer_->beginJob(); }
110  virtual void analyze();
112  virtual void endJob() { analyzer_->endJob(); }
113 
114  protected:
122  unsigned int reportAfter_;
126  std::shared_ptr<T> analyzer_;
127  };
128 
130  template <class T>
132  : inputHandler_(cfg),
133  outputHandler_(cfg),
134  maxEvents_(inputHandler_.maxEvents()),
135  reportAfter_(inputHandler_.reportAfter()),
136  fileService_(outputHandler_.file()) {
137  // analysis specific parameters
138  const edm::ParameterSet& ana = cfg.getParameter<edm::ParameterSet>(analyzerName.c_str());
139  if (directory.empty()) {
140  // create analysis class of type BasicAnalyzer
141  analyzer_ = std::shared_ptr<T>(new T(ana, fileService_));
142  } else {
143  // create a directory in the file if directory string is non empty
145  analyzer_ = std::shared_ptr<T>(new T(ana, dir));
146  }
147  }
148 
150  template <class T>
152  int ievt = 0;
153  std::vector<std::string> const& inputFiles = inputHandler_.files();
154  // loop the vector of input files
156  for (event.toBegin(); !event.atEnd(); ++event, ++ievt) {
157  // break loop if maximal number of events is reached
158  if (maxEvents_ > 0 ? ievt + 1 > maxEvents_ : false)
159  break;
160  // simple event counter
161  if (reportAfter_ != 0 ? (ievt > 0 && ievt % reportAfter_ == 0) : false)
162  std::cout << " processing event: " << ievt << std::endl;
163  // analyze event
164  analyzer_->analyze(event);
165  }
166  }
167 } // namespace fwlite
168 
169 #endif
fwlite::AnalyzerWrapper::maxEvents_
int maxEvents_
maximal number of events to be processed (-1 means to loop over all event)
Definition: FWLiteAnalyzerWrapper.h:120
TFileService.h
TFileDirectory::mkdir
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileDirectory.cc:112
fwlite::AnalyzerWrapper::fileService_
fwlite::TFileService fileService_
TFileService for histogram management.
Definition: FWLiteAnalyzerWrapper.h:124
fwlite
Definition: TFileDirectory.h:16
fwlite::AnalyzerWrapper::~AnalyzerWrapper
virtual ~AnalyzerWrapper()
default destructor
Definition: FWLiteAnalyzerWrapper.h:106
gather_cfg.cout
cout
Definition: gather_cfg.py:144
fwlite::AnalyzerWrapper::inputHandler_
fwlite::InputSource inputHandler_
helper class for input parameter handling
Definition: FWLiteAnalyzerWrapper.h:116
fwlite::AnalyzerWrapper::analyzer_
std::shared_ptr< T > analyzer_
derived class of type BasicAnalyzer
Definition: FWLiteAnalyzerWrapper.h:126
TFileDirectory
Definition: TFileDirectory.h:24
fwlite::InputSource
Definition: InputSource.h:19
fwlite::AnalyzerWrapper::beginJob
virtual void beginJob()
everything which has to be done before the event loop
Definition: FWLiteAnalyzerWrapper.h:108
InputSource.h
ChainEvent.h
ProcessDesc.h
fwlite::AnalyzerWrapper
Definition: FWLiteAnalyzerWrapper.h:101
fwlite::OutputFiles
Definition: OutputFiles.h:19
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
OutputFiles.h
edm::ParameterSet
Definition: ParameterSet.h:47
edmPickEvents.event
event
Definition: edmPickEvents.py:273
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
fwlite::AnalyzerWrapper::outputHandler_
fwlite::OutputFiles outputHandler_
helper class for output file handling
Definition: FWLiteAnalyzerWrapper.h:118
fwlite::AnalyzerWrapper::AnalyzerWrapper
AnalyzerWrapper(const edm::ParameterSet &cfg, std::string analyzerName, std::string directory="")
default constructor
Definition: FWLiteAnalyzerWrapper.h:131
looper.cfg
cfg
Definition: looper.py:297
T
long double T
Definition: Basic3DVectorLD.h:48
createBeamHaloJobs.directory
string directory
Definition: createBeamHaloJobs.py:211
Data_TkAlMinBias_Run2018C_PromptReco_v3_cff.maxEvents
maxEvents
Definition: Data_TkAlMinBias_Run2018C_PromptReco_v3_cff.py:3
fwlite::TFileService
Definition: TFileService.h:12
fwlite::AnalyzerWrapper::reportAfter_
unsigned int reportAfter_
number of events after which the progress will be reported (0 means no report)
Definition: FWLiteAnalyzerWrapper.h:122
submitPVValidationJobs.inputFiles
list inputFiles
Definition: submitPVValidationJobs.py:929
cosmicPhotonAnalyzer_cfi.analyzerName
analyzerName
Definition: cosmicPhotonAnalyzer_cfi.py:7
fwlite::ChainEvent
Definition: ChainEvent.h:46
event
Definition: event.py:1
fwlite::AnalyzerWrapper::analyze
virtual void analyze()
everything which has to be done during the event loop. NOTE: the event will be looped inside this fun...
Definition: FWLiteAnalyzerWrapper.h:151
fwlite::AnalyzerWrapper::endJob
virtual void endJob()
everything which has to be done after the event loop
Definition: FWLiteAnalyzerWrapper.h:112
FWLiteEnabler.h
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23