Luiza  v03-01
Processor.h
1 // -*- mode: c++; mode: auto-fill; mode: flyspell-prog; -*-
2 
3 #ifndef Processor_h
4 #define Processor_h 1
5 
6 #include "gloria/GloriaDataContainer.h"
7 
8 #include "StringParameters.h"
9 #include "ProcessorParameter.h"
10 
11 #include "streamlog/streamlog.h"
12 
13 #include <map>
14 
15 using namespace gloria ;
16 
17 
18 namespace luiza{
19 
20  class ProcessorMgr ;
21  // class ProcessorParameter ;
22  class XMLFixCollTypes ;
23 
24  typedef std::map<std::string, ProcessorParameter* > ProcParamMap ;
25  typedef std::map<std::string, GloriaCollectionType > GloriaTypeMap ;
26 
28 
55  class Processor {
56 
57  friend class ProcessorMgr ;
58  friend class CMProcessor ;
59  friend class XMLFixCollTypes ;
60 
61  public:
62 
63 // /** Possible verbosity levels */
64 // enum{ VERBOSE = 0, DEBUG = 0, MESSAGE = 1, WARNING = 2, ERROR = 3, SILENT = 4 };
65 
66 // /** Global variable used to set the verbosity level */
67 // static int Verbosity;
68 
70 
73  Processor(const std::string& typeName) ;
74 
76  virtual ~Processor() ;
77 
78 
80 
82  virtual Processor* newProcessor() = 0 ;
83 
84 
86 
88  virtual void init() { }
89 
91 
96  virtual void startAnalysis( GloriaDataContainer* ) { }
97 
99 
102  virtual void processData( GloriaDataContainer* ) { }
103 
105 
108  virtual void check( GloriaDataContainer* ) { }
109 
110 
112 
117  virtual void concludeAnalysis( GloriaDataContainer* ) { }
118 
120 
125  virtual void end(){ }
126 
127 
129  virtual const std::string & type() const { return _typeName ; }
130 
132  virtual const std::string & name() const { return _processorName ; }
133 
135  virtual const std::string & logLevelName() const { return _logLevelName ; }
136 
137 
139  virtual StringParameters* parameters() { return _parameters ; }
140 
141 
143  virtual void printDescription() ;
144 
146  virtual void printDescriptionXML(std::ostream& stream=std::cout) ;
147 
148 
150  template <class T>
152 
153 
154  if( streamlog::out.template write<T>() ) {
155 
156 
157  typedef ProcParamMap::iterator PMI ;
158 
159  streamlog::out() << std::endl
160  << "---- " << name() <<" - parameters: " << std::endl ;
161 
162 
163  for( PMI i = _map.begin() ; i != _map.end() ; i ++ ) {
164 
165  if( ! i->second->isOptional() || i->second->valueSet() ){
166  streamlog::out.template write<T>() ;
167  streamlog::out() << "\t" << i->second->name()
168  << ": " << i->second->value()
169  << std::endl ;
170  }
171  }
172 
173  streamlog::out.template write<T>() ;
174  streamlog::out() << "-------------------------------------------------"
175  << std::endl ;
176 
177  }
178  }
179 
180 
182  void printParameters() ;
183 
184 
185 
187  const std::string& description() { return _description ; }
188 
189 
191  bool isFirstEvent() { return _isFirstEvent ; } ;
192 
194 
195  GloriaCollectionType getGloriaInType( const std::string& colName ) ;
196 
198 
200  GloriaCollectionType getGloriaOutType( const std::string& colName ) ;
201 
203 
206  bool isInputCollectionName( const std::string& parameterName ) ;
207 
208 
210  bool isOutputCollectionName( const std::string& parameterName ) ;
211 
212 
213 // //! Helper function returns the ProcessorParameter for the given name
214 // */
215 // ProcessorParameter* getProcessorParameter( const std::string name) ;
216 
217  protected:
218 
220 
223  void setReturnValue( bool val) ;
224 
226 
229  void setReturnValue( const std::string& name, bool val ) ;
230 
231 
233 
241  template<class T>
242  void registerProcessorParameter(const std::string& name,
243  const std::string& description,
244  T& parameter,
245  const T& defaultVal,
246  int setSize=0 ) {
247 
248  _map[ name ] = new ProcessorParameter_t<T>( name , description,
249  parameter, defaultVal,
250  false , setSize) ;
251  }
252 
254 
258  const std::string& name,
259  const std::string& description,
260  std::string& parameter,
261  const std::string& defaultVal,
262  int setSize=0 ) {
263 
264  setGloriaInType( name , type ) ;
265  registerProcessorParameter( name, description, parameter, defaultVal, setSize ) ;
266  }
267 
269 
273  const std::string& name,
274  const std::string& description,
275  std::string& parameter,
276  const std::string& defaultVal,
277  int setSize=0 ) {
278 
279  setGloriaOutType( name , type ) ;
280  registerProcessorParameter( name, description, parameter, defaultVal, setSize ) ;
281  }
282 
284 
288  const std::string& name,
289  const std::string& description,
290  StringVec& parameter,
291  const StringVec& defaultVal,
292  int setSize=0 ) {
293 
294  setGloriaInType( name , type ) ;
295  registerProcessorParameter( name, description, parameter, defaultVal, setSize ) ;
296  }
297 
299 
304  template<class T>
305  void registerOptionalParameter(const std::string& name,
306  const std::string& description,
307  T& parameter,
308  const T& defaultVal,
309  int setSize=0 ) {
310 
311  _map[ name ] = new ProcessorParameter_t<T>( name , description,
312  parameter, defaultVal,
313  true , setSize) ;
314  }
315 
317  bool parameterSet( const std::string& name ) ;
318 
319 
320 
322 
338  template <class T>
339  void message( const std::string& message ) const {
340 
341 
342  if( streamlog::out.template write<T>() )
343  streamlog::out() << message << std::endl ;
344 
345  }
346 
347 
349 
364  template <class T>
365  inline void message( const std::basic_ostream<char, std::char_traits<char> >& m) const {
366 
367  if( T::active ){ // allow the compiler to optimize this away ...
368 
369  try{
370  const std::stringstream& mess = dynamic_cast<const std::stringstream&>( m ) ;
371 
372  this->template message<T>( mess.str() ) ;
373 
374  }
375  catch( std::bad_cast ) {}
376  }
377  }
378 
380  /* @deprecated
381  */
382  std::stringstream& log() const ;
383 
384 
385  protected: // need to be accessible from derived classes as well
386 
388  virtual void setProcessorParameters( StringParameters* parameters) {
389  setParameters( parameters ) ;
390  }
391 
393  virtual void updateParameters();
394 
396 
402  virtual void updateTelescopeParameters(std::string name );
403 
404 
406 
412  virtual void updateTelescopeParameters(GloriaFitsHeader* header);
413 
414 
415  private: // called by ProcessorMgr
416 
418  virtual void setName( const std::string & name) { _processorName = name ; }
419 
421  virtual void setParameters( StringParameters* parameters) ;
422 
424  virtual void baseInit() ;
425 
427  void setFirstEvent( bool isFirstEvent ) { _isFirstEvent = isFirstEvent ; }
428 
429  // called internally
430 
433  void setGloriaInType(const std::string& colName, const GloriaCollectionType& gloriaInType) ;
434 
435 
436 
439  void setGloriaOutType(const std::string& collectionName, const GloriaCollectionType& gloriaOutType) ;
440 
441 
443  const ProcParamMap& procMap() { return _map ; }
444 
445 
446 
447  protected:
448 
450  std::string _description ;
451  std::string _typeName ;
452  std::string _processorName ;
453  StringParameters* _parameters ;
454 
455  ProcParamMap _map ;
456  bool _isFirstEvent ;
457  GloriaTypeMap _inTypeMap ;
458  GloriaTypeMap _outTypeMap ;
459 
460  std::string _logLevelName ;
461 
462  private:
463  mutable std::stringstream* _str ;
464 
465  Processor() ;
466 
467  };
468 
469 } // end namespace marlin
470 
471 #endif
void message(const std::string &message) const
Print message according to verbosity level.
Definition: Processor.h:339
virtual const std::string & name() const
Return name of this processor.
Definition: Processor.h:132
Definition: CMProcessor.h:21
namespace for data storing and exchange formats
Definition: GloriaAstrometry.h:15
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:242
virtual const std::string & logLevelName() const
Return name of the local verbosity level of this processor - "" if not set.
Definition: Processor.h:135
void message(const std::basic_ostream< char, std::char_traits< char > > &m) const
Similar to message(const std::string& message)
Definition: Processor.h:365
const std::string & description()
Description of processor.
Definition: Processor.h:187
logstream out
Definition: logstream.cc:94
Class for storing all data processed in Luiza.
Definition: GloriaDataContainer.h:82
virtual void end()
Called after data processing is finished.
Definition: Processor.h:125
Base class for Luiza processors.
Definition: Processor.h:55
virtual StringParameters * parameters()
Return parameters defined for this Processor.
Definition: Processor.h:139
void registerInputCollections(const GloriaCollectionType &type, const std::string &name, const std::string &description, StringVec &parameter, const StringVec &defaultVal, int setSize=0)
Register parameter describing input collections.
Definition: Processor.h:287
std::string _description
Describes what the processor does. Set in constructor.
Definition: Processor.h:450
void registerInputCollection(const GloriaCollectionType &type, const std::string &name, const std::string &description, std::string &parameter, const std::string &defaultVal, int setSize=0)
Register parameter describing input collection.
Definition: Processor.h:257
Definition: ProcessorMgr.h:40
virtual const std::string & type() const
Return type name for the processor (as set in constructor).
Definition: Processor.h:129
virtual void setProcessorParameters(StringParameters *parameters)
Allow friend class CCProcessor to change/reset processor parameters.
Definition: Processor.h:388
virtual void startAnalysis(GloriaDataContainer *)
Called before first data processing loop.
Definition: Processor.h:96
Definition: ProcessorParameter.h:104
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:305
Namespace for Luiza framework.
Definition: CCCollection.h:6
virtual void concludeAnalysis(GloriaDataContainer *)
Called after all data processing loops.
Definition: Processor.h:117
void printParameters()
Print the parameters and their values depending on the given verbosity level.
Definition: Processor.h:151
Class for handling fits file headers.
Definition: GloriaFitsHeader.h:33
virtual void init()
Called at the begin of the job before anything is read.
Definition: Processor.h:88
GloriaCollectionType
Enumerator for allowed collection types.
Definition: GloriaDataContainer.h:45
virtual void check(GloriaDataContainer *)
Called for every loop - right after processData() call.
Definition: Processor.h:108
void registerOutputCollection(const GloriaCollectionType &type, const std::string &name, const std::string &description, std::string &parameter, const std::string &defaultVal, int setSize=0)
Register parameter describing output collection.
Definition: Processor.h:272
bool isFirstEvent()
True if first event in processEvent(evt) - use this e.g. to initialize histograms etc...
Definition: Processor.h:191
virtual void processData(GloriaDataContainer *)
Called for every data processing loop.
Definition: Processor.h:102