00001 #ifndef Processor_h
00002 #define Processor_h 1
00003
00004 #include "lcio.h"
00005
00006 #include "IO/LCRunListener.h"
00007 #include "IO/LCEventListener.h"
00008 #include "IO/LCReader.h"
00009
00010 #include "EVENT/LCEvent.h"
00011 #include "EVENT/LCRunHeader.h"
00012
00013 #include "StringParameters.h"
00014 #include "ProcessorParameter.h"
00015
00016 #include "marlin/VerbosityLevels.h"
00017 #include "streamlog/streamlog.h"
00018
00019 #include <map>
00020
00021
00022
00023 #define m_out( VERBOSITY ) streamlog_out( VERBOSITY )
00024 #define m_endl std::endl
00025
00026
00027
00028
00029 #define MARLIN_MAJOR_VERSION 0
00030 #define MARLIN_MINOR_VERSION 9
00031 #define MARLIN_PATCH_LEVEL 8
00032
00033 #define MARLIN_VERSION_GE( MAJV , MINV , PLEV) ( ( MARLIN_MAJOR_VERSION > MAJV ) || ( (MARLIN_MAJOR_VERSION==MAJV) && ( MARLIN_MINOR_VERSION > MINV ) ) || ( (MARLIN_MAJOR_VERSION==MAJV) && ( MARLIN_MINOR_VERSION == MINV ) && ( MARLIN_PATCH_LEVEL >= PLEV ) ) )
00034
00035
00037
00038
00047
00048
00049
00050
00051
00052
00053
00054
00055 using namespace lcio ;
00056
00057
00058 namespace marlin{
00059
00060 class ProcessorMgr ;
00061
00062 class XMLFixCollTypes ;
00063
00064 typedef std::map<std::string, ProcessorParameter* > ProcParamMap ;
00065 typedef std::map<std::string, std::string > LCIOTypeMap ;
00066
00086 class Processor {
00087
00088 friend class ProcessorMgr ;
00089 friend class CMProcessor ;
00090 friend class XMLFixCollTypes ;
00091
00092 public:
00093
00094
00095
00096
00097
00098
00099
00103 Processor(const std::string& typeName) ;
00104
00106 virtual ~Processor() ;
00107
00108
00112 virtual Processor* newProcessor() = 0 ;
00113
00114
00118 virtual void init() { }
00119
00123 virtual void processRunHeader( LCRunHeader* ) { }
00124
00127 virtual void processEvent( LCEvent * ) { }
00128
00133 virtual void check( LCEvent* ) { }
00134
00135
00140 virtual void end(){ }
00141
00142
00145 virtual const std::string & type() const { return _typeName ; }
00146
00149 virtual const std::string & name() const { return _processorName ; }
00150
00153 virtual StringParameters* parameters() { return _parameters ; }
00154
00155
00158 virtual void printDescription() ;
00159
00162 virtual void printDescriptionXML(std::ostream& stream=std::cout) ;
00163
00164
00167 template <class T>
00168 void printParameters() {
00169
00170
00171 if( streamlog::out.template write<T>() ) {
00172
00173
00174 typedef ProcParamMap::iterator PMI ;
00175
00176 streamlog::out() << std::endl
00177 << "---- " << name() <<" - parameters: " << std::endl ;
00178
00179
00180 for( PMI i = _map.begin() ; i != _map.end() ; i ++ ) {
00181
00182 if( ! i->second->isOptional() || i->second->valueSet() ){
00183 streamlog::out.template write<T>() ;
00184 streamlog::out() << "\t" << i->second->name()
00185 << ": " << i->second->value()
00186 << std::endl ;
00187 }
00188 }
00189
00190 streamlog::out.template write<T>() ;
00191 streamlog::out() << "-------------------------------------------------"
00192 << std::endl ;
00193
00194 }
00195 }
00196
00199 void printParameters() ;
00200
00201
00202
00205 const std::string& description() { return _description ; }
00206
00207
00210 bool isFirstEvent() { return _isFirstEvent ; } ;
00211
00214 std::string getLCIOInType( const std::string& colName ) ;
00215
00218 std::string getLCIOOutType( const std::string& colName ) ;
00219
00224 bool isInputCollectionName( const std::string& parameterName ) ;
00225
00226
00228 bool isOutputCollectionName( const std::string& parameterName ) ;
00229
00230
00231
00232
00233
00234
00235 protected:
00236
00241 void setReturnValue( bool val) ;
00242
00247 void setReturnValue( const std::string& name, bool val ) ;
00248
00249
00259 template<class T>
00260 void registerProcessorParameter(const std::string& name,
00261 const std::string& description,
00262 T& parameter,
00263 const T& defaultVal,
00264 int setSize=0 ) {
00265
00266 _map[ name ] = new ProcessorParameter_t<T>( name , description,
00267 parameter, defaultVal,
00268 false , setSize) ;
00269 }
00270
00274 void registerInputCollection(const std::string& type,
00275 const std::string& name,
00276 const std::string& description,
00277 std::string& parameter,
00278 const std::string& defaultVal,
00279 int setSize=0 ) {
00280
00281 setLCIOInType( name , type ) ;
00282 registerProcessorParameter( name, description, parameter, defaultVal, setSize ) ;
00283 }
00284
00288 void registerOutputCollection(const std::string& type,
00289 const std::string& name,
00290 const std::string& description,
00291 std::string& parameter,
00292 const std::string& defaultVal,
00293 int setSize=0 ) {
00294
00295 setLCIOOutType( name , type ) ;
00296 registerProcessorParameter( name, description, parameter, defaultVal, setSize ) ;
00297 }
00298
00302 void registerInputCollections(const std::string& type,
00303 const std::string& name,
00304 const std::string& description,
00305 StringVec& parameter,
00306 const StringVec& defaultVal,
00307 int setSize=0 ) {
00308
00309 setLCIOInType( name , type ) ;
00310 registerProcessorParameter( name, description, parameter, defaultVal, setSize ) ;
00311 }
00312
00319 template<class T>
00320 void registerOptionalParameter(const std::string& name,
00321 const std::string& description,
00322 T& parameter,
00323 const T& defaultVal,
00324 int setSize=0 ) {
00325
00326 _map[ name ] = new ProcessorParameter_t<T>( name , description,
00327 parameter, defaultVal,
00328 true , setSize) ;
00329 }
00330
00333 bool parameterSet( const std::string& name ) ;
00334
00335
00336
00353 template <class T>
00354 void message( const std::string& message ) const {
00355
00356
00357 if( streamlog::out.template write<T>() )
00358 streamlog::out() << message << std::endl ;
00359
00360 }
00361
00362
00378 template <class T>
00379 inline void message( const std::basic_ostream<char, std::char_traits<char> >& m) const {
00380
00381 if( T::active ){
00382
00383 try{
00384 const std::stringstream& mess = dynamic_cast<const std::stringstream&>( m ) ;
00385
00386 this->template message<T>( mess.str() ) ;
00387
00388 }
00389 catch( std::bad_cast ) {}
00390 }
00391 }
00392
00396 std::stringstream& log() const ;
00397
00398
00399 private:
00400
00402 virtual void setProcessorParameters( StringParameters* parameters) {
00403 setParameters( parameters ) ;
00404 }
00405
00407 virtual void updateParameters();
00408
00410 virtual void setName( const std::string & name) { _processorName = name ; }
00411
00413 virtual void setParameters( StringParameters* parameters) ;
00414
00417 virtual void baseInit() ;
00418
00420 void setFirstEvent( bool isFirstEvent ) { _isFirstEvent = isFirstEvent ; }
00421
00422
00423
00429 void setLCIOInType(const std::string& colName, const std::string& lcioInType) ;
00430
00431
00432
00436 void setLCIOOutType(const std::string& collectionName, const std::string& lcioOutType) ;
00437
00438
00440 const ProcParamMap& procMap() { return _map ; }
00441
00442
00443
00444 protected:
00445
00448 std::string _description ;
00449 std::string _typeName ;
00450 std::string _processorName ;
00451 StringParameters* _parameters ;
00452
00453 ProcParamMap _map ;
00454 bool _isFirstEvent ;
00455 LCIOTypeMap _inTypeMap ;
00456 LCIOTypeMap _outTypeMap ;
00457
00458
00459
00460 private:
00461 mutable std::stringstream* _str ;
00462
00463 Processor() ;
00464
00465 };
00466
00467 }
00468
00469 #endif