Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
marlin::Processor Class Referenceabstract

Base class for Marlin processors. More...

#include <Processor.h>

+ Inheritance diagram for marlin::Processor:

Public Member Functions

 Processor (const std::string &typeName)
 Possible verbosity levels. More...
 
virtual ~Processor ()
 Destructor. More...
 
virtual ProcessornewProcessor ()=0
 Return a new instance of the processor. More...
 
virtual void init ()
 Called at the begin of the job before anything is read. More...
 
virtual void processRunHeader (LCRunHeader *)
 Called for every run, e.g. More...
 
virtual void processEvent (LCEvent *)
 Called for every event - the working horse. More...
 
virtual void check (LCEvent *)
 Called for every event - right after processEvent() has been called for this processor. More...
 
virtual void end ()
 Called after data processing for clean up in the inverse order of the init() method so that resources allocated in the first processor also will be available for all following processors. More...
 
virtual const std::stringtype () const
 Return type name for the processor (as set in constructor). More...
 
virtual const std::stringname () const
 Return name of this processor. More...
 
virtual const std::stringlogLevelName () const
 Return name of the local verbosity level of this processor - "" if not set. More...
 
virtual std::shared_ptr
< StringParameters
parameters ()
 Return parameters defined for this Processor. More...
 
virtual void printDescription ()
 Print information about this processor in ASCII steering file format. More...
 
virtual void printDescriptionXML (std::ostream &stream=std::cout)
 Print information about this processor in XML steering file format. More...
 
template<class T >
void printParameters ()
 Print the parameters and their values depending on the given verbosity level. More...
 
void printParameters ()
 Print the parameters and their values with verbosity level MESSAGE. More...
 
const std::stringdescription ()
 Description of processor. More...
 
bool isFirstEvent ()
 True if first event in processEvent(evt) - use this e.g. More...
 
std::string getLCIOInType (const std::string &colName)
 Return the LCIO input type for the collection colName - empty string if colName is not a registered collection name. More...
 
std::string getLCIOOutType (const std::string &colName)
 Return the LCIO output type for the collection colName - empty string if colName is not a registered collection name. More...
 
bool isInputCollectionName (const std::string &parameterName)
 True if the given parameter defines an LCIO input collection, i.e. More...
 
bool isOutputCollectionName (const std::string &parameterName)
 True if the given parameter defines an LCIO output collection. More...
 
virtual void setParameters (std::shared_ptr< StringParameters > parameters)
 Helper function returns the ProcessorParameter for the given name. More...
 
virtual void setName (const std::string &processorName)
 Set processor name. More...
 

Protected Member Functions

void setReturnValue (bool val)
 Set the return value for this processor - typically at end of processEvent(). More...
 
void setReturnValue (const std::string &name, bool val)
 Set a named return value for this processor - typically at end of processEvent() The value can be used in a condition in the steering file referred to by ProcessorName.name of the processor. More...
 
template<class T >
void registerProcessorParameter (const std::string &parameterName, const std::string &parameterDescription, T &parameter, const T &defaultVal, int setSize=0)
 Register a steering variable for this processor - call in constructor of processor. More...
 
void registerInputCollection (const std::string &collectionType, const std::string &parameterName, const std::string &parameterDescription, std::string &parameter, const std::string &defaultVal, int setSize=0)
 Specialization of registerProcessorParameter() for a parameter that defines an input collection - can be used fo checking the consistency of the steering file. More...
 
void registerOutputCollection (const std::string &collectionType, const std::string &parameterName, const std::string &parameterDescription, std::string &parameter, const std::string &defaultVal, int setSize=0)
 Specialization of registerProcessorParameter() for a parameter that defines an output collection - can be used fo checking the consistency of the steering file. More...
 
void registerInputCollections (const std::string &collectionType, const std::string &parameterName, const std::string &parameterDescription, StringVec &parameter, const StringVec &defaultVal, int setSize=0)
 Specialization of registerProcessorParameter() for a parameter that defines one or several input collections - can be used fo checking the consistency of the steering file. More...
 
template<class T >
void registerOptionalParameter (const std::string &parameterName, const std::string &parameterDescription, T &parameter, const T &defaultVal, int setSize=0)
 Same as registerProcessorParameter except that the parameter is optional. More...
 
bool parameterSet (const std::string &name)
 Tests whether the parameter has been set in the steering file. More...
 
void checkForExistingParameter (const std::string &parameterName)
 Tests whether the parameter has been registered before. More...
 
template<class T >
void message (const std::string &m) const
 Print message according to verbosity level of the templated parameter (one of DEBUG, MESSAGE, WARNING, ERROR ) and the global parameter "Verbosity". More...
 
template<class T >
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 in the argument using the log() method, e.g. More...
 
std::stringstreamlog () const
 Returns an empty stringstream that is used by the message method. More...
 

Protected Attributes

std::string _description =""
 Describes what the processor does. More...
 
std::string _typeName =""
 
std::string _processorName =""
 
std::shared_ptr< StringParameters_parameters {}
 
ProcParamMap _map {}
 
bool _isFirstEvent = false
 
LCIOTypeMap _inTypeMap {}
 
LCIOTypeMap _outTypeMap {}
 
std::string _logLevelName {}
 

Private Member Functions

 Processor (const Processor &)=delete
 
Processoroperator= (const Processor &)=delete
 
virtual void setProcessorParameters (std::shared_ptr< StringParameters > processorParameters)
 Allow friend class CCProcessor to change/reset processor parameters. More...
 
virtual void updateParameters ()
 Allow friend class CCProcessor to update processor parameters. More...
 
virtual void baseInit ()
 Sets the registered steering parameters before calling init() More...
 
void setFirstEvent (bool firstEvent)
 Called by ProcessorMgr. More...
 
void setLCIOInType (const std::string &colName, const std::string &lcioInType)
 Set the expected LCIO type for a parameter that refers to one or more input collections, e.g. More...
 
void setLCIOOutType (const std::string &collectionName, const std::string &lcioOutType)
 Set the LCIO type for a parameter that refers to an output collections, i.e. More...
 
const ProcParamMapprocMap ()
 Helper function for fixing old steering files. More...
 
 Processor ()
 

Private Attributes

std::stringstream_str =NULL
 

Friends

class ProcessorMgr
 
class CMProcessor
 
class XMLFixCollTypes
 

Detailed Description

Base class for Marlin processors.

Users can optionaly overwrite the following methods:
init, processRun, processEvent and end.
Use registerProcessorParameter to define all parameters that the module uses. Registered parameters are filled automatically before init() is called. With MyAplication -l you can print a list of available processors including the steering parameters they use/need.
With MyAplication -x you can print an example XML steering file for all known processors.

See Also
init
processRun
processEvent
end
Author
F. Gaede, DESY
Version
Id:
Processor.h,v 1.38 2008-06-26 10:25:36 gaede Exp

Definition at line 64 of file Processor.h.

Constructor & Destructor Documentation

marlin::Processor::Processor ( const Processor )
privatedelete
marlin::Processor::Processor ( const std::string typeName)

Possible verbosity levels.

Global variable used to set the verbosity level Default constructor - subclasses need to call this in their default constructor.

Definition at line 14 of file Processor.cc.

References _logLevelName, marlin::ProcessorMgr::instance(), registerOptionalParameter(), and marlin::ProcessorMgr::registerProcessor().

marlin::Processor::~Processor ( )
virtual

Destructor.

Definition at line 36 of file Processor.cc.

References _map, _str, std::map< K, T >::begin(), and std::map< K, T >::end().

marlin::Processor::Processor ( )
private

Definition at line 34 of file Processor.cc.

Member Function Documentation

void marlin::Processor::baseInit ( )
privatevirtual

Sets the registered steering parameters before calling init()

Definition at line 214 of file Processor.cc.

References init().

virtual void marlin::Processor::check ( LCEvent *  )
inlinevirtual

Called for every event - right after processEvent() has been called for this processor.

Use to check processing and/or produce check plots.

Reimplemented in marlin::SimpleFastMCProcessor, marlin::EventSelector, marlin::TestProcessor, MemoryMonitor, and Statusmonitor.

Definition at line 116 of file Processor.h.

void marlin::Processor::checkForExistingParameter ( const std::string parameterName)
inlineprotected

Tests whether the parameter has been registered before.

Parameters
namename of the parameter to check
Exceptions
logic_errorif parameter has been registered before

Definition at line 335 of file Processor.h.

References std::endl(), and std::stringstream::str().

const std::string& marlin::Processor::description ( )
inline

Description of processor.

Definition at line 193 of file Processor.h.

Referenced by marlin::CMProcessor::CMProcessor(), marlin::CCProcessor::getDescription(), printDescription(), and printDescriptionXML().

virtual void marlin::Processor::end ( )
inlinevirtual

Called after data processing for clean up in the inverse order of the init() method so that resources allocated in the first processor also will be available for all following processors.

Reimplemented in marlin::SimpleFastMCProcessor, marlin::LCIOOutputProcessor, marlin::EventSelector, marlin::TestProcessor, MemoryMonitor, Statusmonitor, and marlin::StdHepReader.

Definition at line 123 of file Processor.h.

std::string marlin::Processor::getLCIOInType ( const std::string colName)

Return the LCIO input type for the collection colName - empty string if colName is not a registered collection name.

Definition at line 241 of file Processor.cc.

References _inTypeMap, and isInputCollectionName().

Referenced by marlin::CCProcessor::addColsFromParam(), and marlin::XMLFixCollTypes::parse().

std::string marlin::Processor::getLCIOOutType ( const std::string colName)

Return the LCIO output type for the collection colName - empty string if colName is not a registered collection name.

Definition at line 250 of file Processor.cc.

References _outTypeMap, and isOutputCollectionName().

Referenced by marlin::CCProcessor::addColsFromParam(), and marlin::XMLFixCollTypes::parse().

virtual void marlin::Processor::init ( )
inlinevirtual

Called at the begin of the job before anything is read.

Use to initialize the processor, e.g. book histograms.

Reimplemented in marlin::SimpleFastMCProcessor, marlin::LCIOOutputProcessor, marlin::StdHepReader, marlin::EventSelector, marlin::TestProcessor, MemoryMonitor, and Statusmonitor.

Definition at line 101 of file Processor.h.

Referenced by baseInit().

bool marlin::Processor::isFirstEvent ( )
inline

True if first event in processEvent(evt) - use this e.g.

to initialize histograms etc.

Definition at line 198 of file Processor.h.

Referenced by marlin::SimpleFastMCProcessor::check(), marlin::TestProcessor::processEvent(), and marlin::StdHepReader::readDataSource().

bool marlin::Processor::isInputCollectionName ( const std::string parameterName)

True if the given parameter defines an LCIO input collection, i.e.

the type has been defined with setLCIOInType().

Definition at line 259 of file Processor.cc.

References _inTypeMap, std::map< K, T >::end(), and std::map< K, T >::find().

Referenced by marlin::CCProcessor::addColsFromParam(), getLCIOInType(), marlin::XMLFixCollTypes::parse(), and printDescriptionXML().

bool marlin::Processor::isOutputCollectionName ( const std::string parameterName)

True if the given parameter defines an LCIO output collection.

Definition at line 267 of file Processor.cc.

References _outTypeMap, std::map< K, T >::end(), and std::map< K, T >::find().

Referenced by marlin::CCProcessor::addColsFromParam(), getLCIOOutType(), marlin::XMLFixCollTypes::parse(), and printDescriptionXML().

std::stringstream & marlin::Processor::log ( ) const
protected

Returns an empty stringstream that is used by the message method.

Deprecated:

Definition at line 71 of file Processor.cc.

References _str.

virtual const std::string& marlin::Processor::logLevelName ( ) const
inlinevirtual

Return name of the local verbosity level of this processor - "" if not set.

Definition at line 136 of file Processor.h.

Referenced by marlin::TestProcessor::processEvent().

template<class T >
void marlin::Processor::message ( const std::string m) const
inlineprotected

Print message according to verbosity level of the templated parameter (one of DEBUG, MESSAGE, WARNING, ERROR ) and the global parameter "Verbosity".

If Marlin is compiled w/o debug mode ($MARLINDEBUG not set) then DEBUG messages will be ignored completely at compile time, i.e. no output (and code!) will be generated, regardless of the value of the "Verbosity" parameter. This is useful in order to save CPU time in production mode.
Every line of the output string will be prepended by the verbosity level of the message and the processor name, e.g:

  [ MESSAGE "MyTestProcessor" ]  processing event 42 in run 4711

Use this method for simple strings. In order to use more complex messages, including numbers, use:

See Also
void message( const std::basic_ostream<char, std::char_traits<char> >& m)
Deprecated:

Definition at line 364 of file Processor.h.

References std::endl().

template<class T >
void marlin::Processor::message ( const std::basic_ostream< char, std::char_traits< char > > &  m) const
inlineprotected

Same as message(const std::string& message) except that it allows the output of more complex messages in the argument using the log() method, e.g.

:

message<MESSAGE>( log() 
                  << " processing event " << evt->getEventNumber() 
                  << "  in run "          << evt->getRunNumber() 
                  ) ;
Deprecated:
See Also
void message( const std::string& message )
std::stringstream& log()

Definition at line 389 of file Processor.h.

References std::stringstream::str().

virtual const std::string& marlin::Processor::name ( ) const
inlinevirtual
virtual Processor* marlin::Processor::newProcessor ( )
pure virtual
Processor& marlin::Processor::operator= ( const Processor )
privatedelete
virtual std::shared_ptr<StringParameters> marlin::Processor::parameters ( )
inlinevirtual

Return parameters defined for this Processor.

Definition at line 141 of file Processor.h.

Referenced by marlin::TestProcessor::init().

bool marlin::Processor::parameterSet ( const std::string name)
protected

Tests whether the parameter has been set in the steering file.

Definition at line 204 of file Processor.cc.

References _map, std::map< K, T >::end(), and std::map< K, T >::find().

Referenced by marlin::LCIOOutputProcessor::dropCollections(), marlin::LCIOOutputProcessor::init(), and setParameters().

void marlin::Processor::printDescription ( )
virtual
void marlin::Processor::printDescriptionXML ( std::ostream stream = std::cout)
virtual
template<class T >
void marlin::Processor::printParameters ( )
inline

Print the parameters and their values depending on the given verbosity level.

Definition at line 156 of file Processor.h.

References std::endl().

Referenced by Statusmonitor::init(), MemoryMonitor::init(), marlin::EventSelector::init(), marlin::StdHepReader::init(), marlin::LCIOOutputProcessor::init(), and marlin::SimpleFastMCProcessor::init().

void marlin::Processor::printParameters ( )

Print the parameters and their values with verbosity level MESSAGE.

virtual void marlin::Processor::processEvent ( LCEvent *  )
inlinevirtual

Called for every event - the working horse.

Reimplemented in marlin::SimpleFastMCProcessor, marlin::LCIOOutputProcessor, marlin::EventSelector, marlin::TestProcessor, MemoryMonitor, and Statusmonitor.

Definition at line 110 of file Processor.h.

virtual void marlin::Processor::processRunHeader ( LCRunHeader *  )
inlinevirtual

Called for every run, e.g.

overwrite to initialize run dependent histograms.

Reimplemented in marlin::SimpleFastMCProcessor, marlin::LCIOOutputProcessor, marlin::EventSelector, marlin::TestProcessor, MemoryMonitor, and Statusmonitor.

Definition at line 106 of file Processor.h.

const ProcParamMap& marlin::Processor::procMap ( )
inlineprivate

Helper function for fixing old steering files.

Definition at line 444 of file Processor.h.

Referenced by marlin::XMLFixCollTypes::parse().

void marlin::Processor::registerInputCollection ( const std::string collectionType,
const std::string parameterName,
const std::string parameterDescription,
std::string parameter,
const std::string defaultVal,
int  setSize = 0 
)
inlineprotected

Specialization of registerProcessorParameter() for a parameter that defines an input collection - can be used fo checking the consistency of the steering file.

Definition at line 268 of file Processor.h.

Referenced by marlin::SimpleFastMCProcessor::SimpleFastMCProcessor().

void marlin::Processor::registerInputCollections ( const std::string collectionType,
const std::string parameterName,
const std::string parameterDescription,
StringVec parameter,
const StringVec defaultVal,
int  setSize = 0 
)
inlineprotected

Specialization of registerProcessorParameter() for a parameter that defines one or several input collections - can be used fo checking the consistency of the steering file.

Definition at line 296 of file Processor.h.

template<class T >
void marlin::Processor::registerOptionalParameter ( const std::string parameterName,
const std::string parameterDescription,
T &  parameter,
const T &  defaultVal,
int  setSize = 0 
)
inlineprotected

Same as registerProcessorParameter except that the parameter is optional.

The value of the parameter will still be set to the default value, which is used to print an example steering line. Use parameterSet() to check whether it actually has been set in the steering file.

Definition at line 314 of file Processor.h.

Referenced by marlin::LCIOOutputProcessor::myConstruct(), and Processor().

void marlin::Processor::registerOutputCollection ( const std::string collectionType,
const std::string parameterName,
const std::string parameterDescription,
std::string parameter,
const std::string defaultVal,
int  setSize = 0 
)
inlineprotected

Specialization of registerProcessorParameter() for a parameter that defines an output collection - can be used fo checking the consistency of the steering file.

Definition at line 282 of file Processor.h.

Referenced by marlin::SimpleFastMCProcessor::SimpleFastMCProcessor().

template<class T >
void marlin::Processor::registerProcessorParameter ( const std::string parameterName,
const std::string parameterDescription,
T &  parameter,
const T &  defaultVal,
int  setSize = 0 
)
inlineprotected

Register a steering variable for this processor - call in constructor of processor.

The default value has to be of the same type as the parameter, e.g.
float _cut ;
...
registerProcessorParameter( "Cut", "cut...", _cut , float( 3.141592 ) ) ;
as implicit conversions don't work for templates.
The optional parameter setSize is used for formating the printout of parameters. This can be used if the parameter values are expected to come in sets of fixed size.

Definition at line 254 of file Processor.h.

Referenced by marlin::EventSelector::EventSelector(), MemoryMonitor::MemoryMonitor(), marlin::LCIOOutputProcessor::myConstruct(), marlin::SimpleFastMCProcessor::SimpleFastMCProcessor(), Statusmonitor::Statusmonitor(), and marlin::StdHepReader::StdHepReader().

void marlin::Processor::setFirstEvent ( bool  firstEvent)
inlineprivate

Called by ProcessorMgr.

Definition at line 424 of file Processor.h.

void marlin::Processor::setLCIOInType ( const std::string colName,
const std::string lcioInType 
)
private

Set the expected LCIO type for a parameter that refers to one or more input collections, e.g.

:
   setReturnValue( "InputCollecitonName" , LCIO::MCPARTICLE ) ;
Set to LCIO::LCObject if more than one type is allowed, e.g. for a viewer processor.

Definition at line 237 of file Processor.cc.

References _inTypeMap.

void marlin::Processor::setLCIOOutType ( const std::string collectionName,
const std::string lcioOutType 
)
private

Set the LCIO type for a parameter that refers to an output collections, i.e.

the type has been defined with setLCIOOutType().

Definition at line 263 of file Processor.cc.

References _outTypeMap.

virtual void marlin::Processor::setName ( const std::string processorName)
inlinevirtual

Set processor name.

Definition at line 227 of file Processor.h.

Referenced by marlin::ProcessorMgr::addActiveProcessor().

void marlin::Processor::setParameters ( std::shared_ptr< StringParameters parameters)
virtual

Helper function returns the ProcessorParameter for the given name.

Initialize the parameters

Definition at line 54 of file Processor.cc.

References _logLevelName, _parameters, parameterSet(), and updateParameters().

Referenced by marlin::ProcessorMgr::addActiveProcessor().

virtual void marlin::Processor::setProcessorParameters ( std::shared_ptr< StringParameters processorParameters)
inlineprivatevirtual

Allow friend class CCProcessor to change/reset processor parameters.

Definition at line 412 of file Processor.h.

void marlin::Processor::setReturnValue ( bool  val)
protected

Set the return value for this processor - typically at end of processEvent().

The value can be used in a condition in the steering file referred to by the name of the processor.

Definition at line 232 of file Processor.cc.

References marlin::ProcessorMgr::instance(), and marlin::ProcessorMgr::setProcessorReturnValue().

Referenced by marlin::TestProcessor::processEvent(), and marlin::EventSelector::processEvent().

void marlin::Processor::setReturnValue ( const std::string name,
bool  val 
)
protected

Set a named return value for this processor - typically at end of processEvent() The value can be used in a condition in the steering file referred to by ProcessorName.name of the processor.

Definition at line 271 of file Processor.cc.

References marlin::ProcessorMgr::instance(), and marlin::ProcessorMgr::setProcessorReturnValue().

virtual const std::string& marlin::Processor::type ( ) const
inlinevirtual

Return type name for the processor (as set in constructor).

Definition at line 128 of file Processor.h.

Referenced by printDescription(), printDescriptionXML(), and marlin::ProcessorMgr::registerProcessor().

void marlin::Processor::updateParameters ( )
privatevirtual

Allow friend class CCProcessor to update processor parameters.

Definition at line 222 of file Processor.cc.

References _map, _parameters, std::map< K, T >::begin(), std::map< K, T >::end(), and std::shared_ptr::get().

Referenced by setParameters().

Friends And Related Function Documentation

friend class CMProcessor
friend

Definition at line 67 of file Processor.h.

friend class ProcessorMgr
friend

Definition at line 66 of file Processor.h.

friend class XMLFixCollTypes
friend

Definition at line 68 of file Processor.h.

Member Data Documentation

std::string marlin::Processor::_description =""
protected
LCIOTypeMap marlin::Processor::_inTypeMap {}
protected
bool marlin::Processor::_isFirstEvent = false
protected

Definition at line 458 of file Processor.h.

Referenced by marlin::StdHepReader::readDataSource().

std::string marlin::Processor::_logLevelName {}
protected

Definition at line 462 of file Processor.h.

Referenced by Processor(), and setParameters().

ProcParamMap marlin::Processor::_map {}
protected
LCIOTypeMap marlin::Processor::_outTypeMap {}
protected
std::shared_ptr<StringParameters> marlin::Processor::_parameters {}
protected

Definition at line 455 of file Processor.h.

Referenced by setParameters(), and updateParameters().

std::string marlin::Processor::_processorName =""
protected

Definition at line 454 of file Processor.h.

std::stringstream* marlin::Processor::_str =NULL
mutableprivate

Definition at line 465 of file Processor.h.

Referenced by log(), and ~Processor().

std::string marlin::Processor::_typeName =""
protected

Definition at line 453 of file Processor.h.


The documentation for this class was generated from the following files: