Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Processor.cc
Go to the documentation of this file.
1 #include "marlin/Processor.h"
2 #include "marlin/ProcessorMgr.h"
3 #include "marlin/Global.h"
5 
6 using namespace lcio ;
7 
8 
9 namespace marlin{
10 
11  // set default verbosity level to MESSAGE
12  //int Processor::Verbosity=Processor::MESSAGE;
13 
14  Processor::Processor(const std::string& typeName) :
15  _description(" description not set by author ") ,
16  _typeName( typeName ) ,
17  _parameters(0) ,
18  _isFirstEvent( true ),
19  _logLevelName(""),
20  _str(0) {
21 
22  //register processor in map
24 
25 
26  registerOptionalParameter( "Verbosity" ,
27  "verbosity level of this processor (\"DEBUG0-4,MESSAGE0-4,WARNING0-4,ERROR0-4,SILENT\")" ,
28  _logLevelName ,
29  std::string("DEBUG") ) ;
30 
31  }
32 
33 
34  Processor::Processor() : _parameters(NULL), _isFirstEvent(false), _str(NULL) {}
35 
37 
38  if( _str !=0 )
39  delete _str ;
40 
41  typedef ProcParamMap::iterator PMI ;
42 
43  for( PMI i = _map.begin() ; i != _map.end() ; i ++ ) {
44 
45  // streamlog_out(DEBUG) << " deleting processor parameter " << i->second->name()
46  // << " of processor [" << name() << "]"
47  // << std::endl ;
48 
49  delete i->second ;
50  }
51  }
52 
53 
55 
56  _parameters = processorParameters ;
57 
59 
60  // need to reset the log level name in case it has not been set by the user
61  if( !parameterSet("Verbosity") ){
62  _logLevelName = "" ;
63  }
64 
65  // streamlog_out( MESSAGE) << " setParameters : Verbosity : " << _parameters->getStringVal("Verbosity")
66  // << " parameterSet : " << parameterSet("Verbosity")
67  // << " log level name : " << _logLevelName << std::endl ;
68 
69  }
70 
72 
73  if( _str !=0 )
74  delete _str ;
75 
76  _str = new std::stringstream ;
77 
78  return *_str ;
79  }
80 
81 
82 
83  void Processor::printParameters() { printParameters<MESSAGE>() ; }
84 
86 
87  std::cout << ".begin My" << type() << std::endl
88  << "ProcessorType " << type() << std::endl ;
89 
90  std::cout << "#---" << description() << std::endl ;
91 
92  typedef ProcParamMap::iterator PMI ;
93 
94  // std::cout << std::endl
95  // << "# processor parameters:" << std::endl ;
96 
97  for( PMI i = _map.begin() ; i != _map.end() ; i ++ ) {
98 
99  ProcessorParameter* p = i->second ;
100 
101  std::cout << std::endl
102  << "#\t" << p->description() << std::endl
103  << "#\t type: " << " [" << p->type() << "]"
104  << std::endl ;
105 
106  if( p->isOptional() ) {
107 
108  std::cout << "#\t example: " << std::endl ;
109 
110  std::cout << "#\t" << p->name()
111  << " " << p->defaultValue()
112  << std::endl
113  << std::endl ;
114 
115  }else{
116 
117  std::cout << "#\t default: " << p->defaultValue()
118  << std::endl ;
119 
120  std::cout << "\t" << p->name()
121  << " " << p->defaultValue()
122  << std::endl
123  << std::endl ;
124  }
125 
126  }
127 
128  std::cout << ".end -------------------------------------------------"
129  << std::endl
130  << std::endl ;
131 
132 
133  }
134 
136 
137  if(&stream == &std::cout){
138  stream << " <processor name=\"My" << type() << "\""
139  << " type=\"" << type() << "\">"
140  << std::endl ;
141  }
142  else{
143  stream << " <processor name=\"" << name() << "\""
144  << " type=\"" << type() << "\">"
145  << std::endl ;
146 
147  }
148 
149  stream << " <!--" << description() << "-->" << std::endl ;
150 
151  typedef ProcParamMap::iterator PMI ;
152 
153  for( PMI i = _map.begin() ; i != _map.end() ; i ++ ) {
154 
155  ProcessorParameter* p = i->second ;
156 
157  stream << " <!--" << p->description() << "-->" << std::endl ;
158 
159  if( p->isOptional() ) {
160  stream << " <!--parameter name=\"" << p->name() << "\" "
161  << "type=\"" << p->type() ;
162 
163  if ( isInputCollectionName( p->name() ) )
164  stream << "\" lcioInType=\"" << _inTypeMap[ p->name() ] ;
165 
166  if ( isOutputCollectionName( p->name() ) )
167  stream << "\" lcioOutType=\"" << _outTypeMap[ p->name() ] ;
168 
169  stream << "\">"
170  << p->defaultValue()
171  << " </parameter-->"
172  << std::endl ;
173  } else {
174  stream << " <parameter name=\"" << p->name() << "\" "
175  << "type=\"" << p->type() ;
176 
177  if ( isInputCollectionName( p->name() ) )
178  stream << "\" lcioInType=\"" << _inTypeMap[ p->name() ] ;
179 
180  if ( isOutputCollectionName( p->name() ) )
181  stream << "\" lcioOutType=\"" << _outTypeMap[ p->name() ] ;
182 
183  stream << "\">"
184  << p->defaultValue()
185  << " </parameter>"
186  << std::endl ;
187  }
188  }
189 
190  stream << "</processor>"
191  << std::endl
192  << std::endl ;
193 
194  }
195 
196  // ProcessorParameter* Processor::getProcessorParameter( const std::string name) {
197  // ProcParamMap::iterator it = _map.find(name) ;
198  // if( it != _map.end() )
199  // return it->second ;
200  // else
201  // return 0 ;
202  // }
203 
204  bool Processor::parameterSet( const std::string& parameterName ) {
205 
206  ProcParamMap::iterator it = _map.find(parameterName) ;
207 
208  if( it != _map.end() )
209  return it->second->valueSet() ;
210  else
211  return false ;
212  }
213 
215 
216  //fg: now in setParameters
217  // updateParameters();
218 
219  init() ;
220  }
221 
223 
224  typedef ProcParamMap::iterator PMI ;
225 
226  for( PMI i = _map.begin() ; i != _map.end() ; i ++ ) {
227 
228  i->second->setValue( _parameters.get() ) ;
229  }
230  }
231 
232  void Processor::setReturnValue( bool val) {
233 
235  }
236 
237  void Processor::setLCIOInType(const std::string& collectionName, const std::string& lcioInType) {
238  _inTypeMap[ collectionName ] = lcioInType ;
239  }
240 
242 
243  if( isInputCollectionName( colName ) )
244  return _inTypeMap[ colName ] ;
245  else
246  return "" ;
247  }
248 
249 
251 
252  if( isOutputCollectionName( colName ) )
253  return _outTypeMap[ colName ] ;
254  else
255  return "" ;
256  }
257 
258 
260  return _inTypeMap.find( pName ) != _inTypeMap.end() ;
261  }
262 
263  void Processor::setLCIOOutType(const std::string& collectionName, const std::string& lcioOutType) {
264  _outTypeMap[ collectionName ] = lcioOutType ;
265  }
266 
268  return _outTypeMap.find( pName ) != _outTypeMap.end() ;
269  }
270 
271  void Processor::setReturnValue( const std::string& keyName, bool val ){
272 
273  ProcessorMgr::instance()->setProcessorReturnValue( this , val , keyName ) ;
274  }
275 
276 
277 } // namespace marlin
278 
virtual const std::string type()=0
std::string getLCIOOutType(const std::string &colName)
Return the LCIO output type for the collection colName - empty string if colName is not a registered ...
Definition: Processor.cc:250
std::stringstream * _str
Definition: Processor.h:465
static ProcessorMgr * instance()
Return the instance of this manager.
Definition: ProcessorMgr.cc:60
bool parameterSet(const std::string &name)
Tests whether the parameter has been set in the steering file.
Definition: Processor.cc:204
virtual void setProcessorReturnValue(Processor *proc, bool val)
Set the return value for the given processor.
std::string getLCIOInType(const std::string &colName)
Return the LCIO input type for the collection colName - empty string if colName is not a registered c...
Definition: Processor.cc:241
virtual const std::string & name() const
Return name of this processor.
Definition: Processor.h:132
virtual const std::string & type() const
Return type name for the processor (as set in constructor).
Definition: Processor.h:128
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.
Definition: Processor.cc:263
T endl(T...args)
virtual ~Processor()
Destructor.
Definition: Processor.cc:36
T end(T...args)
LCIOTypeMap _outTypeMap
Definition: Processor.h:460
virtual void init()
Called at the begin of the job before anything is read.
Definition: Processor.h:101
ProcParamMap _map
Definition: Processor.h:457
std::string _logLevelName
Definition: Processor.h:462
virtual const std::string & name()
STL class.
bool isInputCollectionName(const std::string &parameterName)
True if the given parameter defines an LCIO input collection, i.e.
Definition: Processor.cc:259
void printParameters()
Print the parameters and their values depending on the given verbosity level.
Definition: Processor.h:156
void registerProcessor(Processor *processor)
Register a processor with the given name.
Definition: ProcessorMgr.cc:73
virtual void setParameters(std::shared_ptr< StringParameters > parameters)
Helper function returns the ProcessorParameter for the given name.
Definition: Processor.cc:54
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.
Definition: Processor.cc:237
std::shared_ptr< StringParameters > _parameters
Definition: Processor.h:455
std::stringstream & log() const
Returns an empty stringstream that is used by the message method.
Definition: Processor.cc:71
void setReturnValue(bool val)
Set the return value for this processor - typically at end of processEvent().
Definition: Processor.cc:232
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.
Definition: Processor.h:314
const std::string & description()
Description of processor.
Definition: Processor.h:193
virtual void updateParameters()
Allow friend class CCProcessor to update processor parameters.
Definition: Processor.cc:222
bool isOutputCollectionName(const std::string &parameterName)
True if the given parameter defines an LCIO output collection.
Definition: Processor.cc:267
virtual const std::string & description()
LCIOTypeMap _inTypeMap
Definition: Processor.h:459
T get(T...args)
virtual void printDescriptionXML(std::ostream &stream=std::cout)
Print information about this processor in XML steering file format.
Definition: Processor.cc:135
Class that holds a steering variable for a marlin processor - automatically created by Processor::reg...
T find(T...args)
virtual const std::string defaultValue()=0
T begin(T...args)
virtual void printDescription()
Print information about this processor in ASCII steering file format.
Definition: Processor.cc:85
virtual void baseInit()
Sets the registered steering parameters before calling init()
Definition: Processor.cc:214
STL class.