Marlin  1.10.0
 All Classes Namespaces Functions Variables Enumerations Friends Pages
Processor.h
1 #ifndef Processor_h
2 #define Processor_h 1
3 
4 #include "lcio.h"
5 
6 #include "IO/LCRunListener.h"
7 #include "IO/LCEventListener.h"
8 #include "IO/LCReader.h"
9 
10 #include "EVENT/LCEvent.h"
11 #include "EVENT/LCRunHeader.h"
12 
13 #include "StringParameters.h"
14 #include "ProcessorParameter.h"
15 //#include "LogStream.h"
16 #include "marlin/VerbosityLevels.h"
17 
18 //----- Marlin version macros are now defined in MarlinConfig.h generated by cmake -----
19 #include "marlin/MarlinConfig.h"
20 
21 #include "streamlog/streamlog.h"
22 
23 #include <map>
24 
25 // ----- define some useful macros-----------
26 // for backward compatibility - use streamlog_out( MESSAGE ) instead
27 // - this conflicts with a boost header und should not be used by now anywhere ...
28 //#define m_out( VERBOSITY ) streamlog_out( VERBOSITY )
29 //#define m_endl std::endl
30 //----------------------------------------
31 
32 using namespace lcio ;
33 
34 
35 namespace marlin{
36 
37  class ProcessorMgr ;
38  // class ProcessorParameter ;
39  class XMLFixCollTypes ;
40 
41  typedef std::map<std::string, ProcessorParameter* > ProcParamMap ;
42  typedef std::map<std::string, std::string > LCIOTypeMap ;
43 
63  class Processor {
64 
65  friend class ProcessorMgr ;
66  friend class CMProcessor ;
67  friend class XMLFixCollTypes ;
68 
69  private:
70  //prevent users from making (default) copies of processors
71  Processor(const Processor& /*typeName*/) {}
72  void operator=(const Processor& /*typeName*/) { }
73 
74  public:
75 
76 // /** Possible verbosity levels */
77 // enum{ VERBOSE = 0, DEBUG = 0, MESSAGE = 1, WARNING = 2, ERROR = 3, SILENT = 4 };
78 
79 // /** Global variable used to set the verbosity level */
80 // static int Verbosity;
81 
85  Processor(const std::string& typeName) ;
86 
88  virtual ~Processor() ;
89 
90 
94  virtual Processor* newProcessor() = 0 ;
95 
96 
100  virtual void init() { }
101 
105  virtual void processRunHeader( LCRunHeader* ) { }
106 
109  virtual void processEvent( LCEvent * ) { }
110 
115  virtual void check( LCEvent* ) { }
116 
117 
122  virtual void end(){ }
123 
124 
127  virtual const std::string & type() const { return _typeName ; }
128 
131  virtual const std::string & name() const { return _processorName ; }
132 
135  virtual const std::string & logLevelName() const { return _logLevelName ; }
136 
137 
140  virtual StringParameters* parameters() { return _parameters ; }
141 
142 
145  virtual void printDescription() ;
146 
149  virtual void printDescriptionXML(std::ostream& stream=std::cout) ;
150 
151 
154  template <class T>
156 
157 
158  if( streamlog::out.template write<T>() ) {
159 
160 
161  typedef ProcParamMap::iterator PMI ;
162 
163  streamlog::out() << std::endl
164  << "---- " << name() <<" - parameters: " << std::endl ;
165 
166 
167  for( PMI i = _map.begin() ; i != _map.end() ; i ++ ) {
168 
169  if( ! i->second->isOptional() || i->second->valueSet() ){
170  streamlog::out.template write<T>() ;
171  streamlog::out() << "\t" << i->second->name()
172  << ": " << i->second->value()
173  << std::endl ;
174  }
175  }
176 
177  streamlog::out.template write<T>() ;
178  streamlog::out() << "-------------------------------------------------"
179  << std::endl ;
180 
181  }
182  }
183 
186  void printParameters() ;
187 
188 
189 
192  const std::string& description() { return _description ; }
193 
194 
197  bool isFirstEvent() { return _isFirstEvent ; } ;
198 
201  std::string getLCIOInType( const std::string& colName ) ;
202 
205  std::string getLCIOOutType( const std::string& colName ) ;
206 
211  bool isInputCollectionName( const std::string& parameterName ) ;
212 
213 
215  bool isOutputCollectionName( const std::string& parameterName ) ;
216 
217 
218 // /** Helper function returns the ProcessorParameter for the given name
219 // */
220 // ProcessorParameter* getProcessorParameter( const std::string name) ;
221 
222  protected:
223 
228  void setReturnValue( bool val) ;
229 
234  void setReturnValue( const std::string& name, bool val ) ;
235 
236 
246  template<class T>
247  void registerProcessorParameter(const std::string& name,
248  const std::string& description,
249  T& parameter,
250  const T& defaultVal,
251  int setSize=0 ) {
252 
253  _map[ name ] = new ProcessorParameter_t<T>( name , description,
254  parameter, defaultVal,
255  false , setSize) ;
256  }
257 
261  void registerInputCollection(const std::string& type,
262  const std::string& name,
263  const std::string& description,
264  std::string& parameter,
265  const std::string& defaultVal,
266  int setSize=0 ) {
267 
268  setLCIOInType( name , type ) ;
269  registerProcessorParameter( name, description, parameter, defaultVal, setSize ) ;
270  }
271 
275  void registerOutputCollection(const std::string& type,
276  const std::string& name,
277  const std::string& description,
278  std::string& parameter,
279  const std::string& defaultVal,
280  int setSize=0 ) {
281 
282  setLCIOOutType( name , type ) ;
283  registerProcessorParameter( name, description, parameter, defaultVal, setSize ) ;
284  }
285 
289  void registerInputCollections(const std::string& type,
290  const std::string& name,
291  const std::string& description,
292  StringVec& parameter,
293  const StringVec& defaultVal,
294  int setSize=0 ) {
295 
296  setLCIOInType( name , type ) ;
297  registerProcessorParameter( name, description, parameter, defaultVal, setSize ) ;
298  }
299 
306  template<class T>
307  void registerOptionalParameter(const std::string& name,
308  const std::string& description,
309  T& parameter,
310  const T& defaultVal,
311  int setSize=0 ) {
312 
313  _map[ name ] = new ProcessorParameter_t<T>( name , description,
314  parameter, defaultVal,
315  true , setSize) ;
316  }
317 
320  bool parameterSet( const std::string& name ) ;
321 
322 
323 
340  template <class T>
341  void message( const std::string& message ) const {
342 
343 
344  if( streamlog::out.template write<T>() )
345  streamlog::out() << message << std::endl ;
346 
347  }
348 
349 
365  template <class T>
366  inline void message( const std::basic_ostream<char, std::char_traits<char> >& m) const {
367 
368  if( T::active ){ // allow the compiler to optimize this away ...
369 
370  try{
371  const std::stringstream& mess = dynamic_cast<const std::stringstream&>( m ) ;
372 
373  this->template message<T>( mess.str() ) ;
374 
375  }
376  catch( std::bad_cast ) {}
377  }
378  }
379 
383  std::stringstream& log() const ;
384 
385 
386  private: // called by ProcessorMgr
387 
389  virtual void setProcessorParameters( StringParameters* parameters) {
390  setParameters( parameters ) ;
391  }
392 
394  virtual void updateParameters();
395 
397  virtual void setName( const std::string & name) { _processorName = name ; }
398 
400  virtual void setParameters( StringParameters* parameters) ;
401 
404  virtual void baseInit() ;
405 
407  void setFirstEvent( bool isFirstEvent ) { _isFirstEvent = isFirstEvent ; }
408 
409  // called internally
410 
416  void setLCIOInType(const std::string& colName, const std::string& lcioInType) ;
417 
418 
419 
423  void setLCIOOutType(const std::string& collectionName, const std::string& lcioOutType) ;
424 
425 
427  const ProcParamMap& procMap() { return _map ; }
428 
429 
430 
431  protected:
432 
435  std::string _description ;
436  std::string _typeName ;
437  std::string _processorName ;
438  StringParameters* _parameters ;
439 
440  ProcParamMap _map ;
441  bool _isFirstEvent ;
442  LCIOTypeMap _inTypeMap ;
443  LCIOTypeMap _outTypeMap ;
444 
445  std::string _logLevelName ;
446 
447  private:
448  mutable std::stringstream* _str ;
449 
450  Processor() ;
451 
452  };
453 
454 } // end namespace marlin
455 
456 #endif
virtual void check(LCEvent *)
Called for every event - right after processEvent() has been called for this processor.
Definition: Processor.h:115
void message(const std::basic_ostream< char, std::char_traits< char > > &m) const
Same as message(const std::string& message) except that it allows the output of more complex messages...
Definition: Processor.h:366
virtual void processRunHeader(LCRunHeader *)
Called for every run, e.g.
Definition: Processor.h:105
virtual StringParameters * parameters()
Return parameters defined for this Processor.
Definition: Processor.h:140
This singleton class contains an instance of every available marlin processor type.
Definition: CMProcessor.h:21
void registerOptionalParameter(const std::string &name, const std::string &description, T &parameter, const T &defaultVal, int setSize=0)
Same as registerProcessorParameter except that the parameter is optional.
Definition: Processor.h:307
virtual const std::string & name() const
Return name of this processor.
Definition: Processor.h:131
virtual const std::string & type() const
Return type name for the processor (as set in constructor).
Definition: Processor.h:127
Templated implementation of ProcessorParameter - automatically created by Processor::registerProcesso...
Definition: ProcessorParameter.h:104
void registerProcessorParameter(const std::string &name, const std::string &description, T &parameter, const T &defaultVal, int setSize=0)
Register a steering variable for this processor - call in constructor of processor.
Definition: Processor.h:247
virtual void init()
Called at the begin of the job before anything is read.
Definition: Processor.h:100
void printParameters()
Print the parameters and their values depending on the given verbosity level.
Definition: Processor.h:155
void message(const std::string &message) const
Print message according to verbosity level of the templated parameter (one of DEBUG, MESSAGE, WARNING, ERROR ) and the global parameter "Verbosity".
Definition: Processor.h:341
const std::string & description()
Description of processor.
Definition: Processor.h:192
void registerInputCollection(const std::string &type, const std::string &name, const std::string &description, std::string &parameter, const std::string &defaultVal, int setSize=0)
Specialization of registerProcessorParameter() for a parameter that defines an input collection - can...
Definition: Processor.h:261
virtual const std::string & logLevelName() const
Return name of the local verbosity level of this processor - "" if not set.
Definition: Processor.h:135
bool isFirstEvent()
True if first event in processEvent(evt) - use this e.g.
Definition: Processor.h:197
Processor manager singleton class.
Definition: ProcessorMgr.h:36
virtual void processEvent(LCEvent *)
Called for every event - the working horse.
Definition: Processor.h:109
Base class for Marlin processors.
Definition: Processor.h:63
void registerOutputCollection(const std::string &type, const std::string &name, const std::string &description, std::string &parameter, const std::string &defaultVal, int setSize=0)
Specialization of registerProcessorParameter() for a parameter that defines an output collection - ca...
Definition: Processor.h:275
void registerInputCollections(const std::string &type, const std::string &name, const std::string &description, StringVec &parameter, const StringVec &defaultVal, int setSize=0)
Specialization of registerProcessorParameter() for a parameter that defines one or several input coll...
Definition: Processor.h:289
std::string _description
Describes what the processor does.
Definition: Processor.h:435
Simple parameters class for Marlin.
Definition: StringParameters.h:34
Internal helper class that creates a new xml steering file with the parameter attributes lcioInType a...
Definition: XMLFixCollTypes.h:25
virtual void end()
Called after data processing for clean up in the inverse order of the init() method so that resources...
Definition: Processor.h:122