Marlin  1.10.0
 All Classes Namespaces Functions Variables Enumerations Friends Pages
ProcessorParameter.h
1 #ifndef ProcessorParameter_h
2 #define ProcessorParameter_h 1
3 
4 #include "lcio.h"
5 
6 #include <iostream>
7 #include <string>
8 #include <sstream>
9 #include "LCIOSTLTypes.h"
10 #include "StringParameters.h"
11 #include <typeinfo>
12 
13 // typedef std::map< std::string , std::vector< std::string > > ParametersMap ;
14 
15 
16 using namespace lcio ;
17 
18 namespace marlin{
19 
28 
29  friend std::ostream& operator<< ( std::ostream& , ProcessorParameter& ) ;
30 
31  public:
32 
33  ProcessorParameter() : _setSize(0), _optional(false), _valueSet(false) {}
34 
35  virtual ~ProcessorParameter() {}
36 
37  virtual const std::string& name() { return _name ; }
38  virtual const std::string& description() { return _description ; }
39  virtual int setSize() { return _setSize ; } ;
40  virtual bool isOptional() { return _optional ; }
41  virtual bool valueSet() { return _valueSet ; }
42 
43  virtual const std::string type()=0 ;
44  virtual const std::string value()=0 ;
45  virtual const std::string defaultValue()=0 ;
46 
47 
48 
49  virtual void setValue( StringParameters* params )=0 ;
50 
51  protected:
52 
53  std::string _description ;
54  std::string _name ;
55  int _setSize ;
56  bool _optional ;
57  bool _valueSet ;
58  };
59 
60 
61  std::ostream& operator<< ( std::ostream& s, ProcessorParameter& p ) ;
62 
63 
66 // template< class T>
67 // std::ostream& operator<< ( std::ostream& s, const std::vector<T>& v ) {
68 
69 // typename std::vector<T>::const_iterator it ;
70 
71 // for( it = v.begin() ; it != v.end() ; it++) {
72 // s << (*it) << " " ;
73 // }
74 // return s ;
75 // }
76 
77  void toStream( std::ostream& s, int i , int N) ;
78  void toStream( std::ostream& s, float f , int N) ;
79  void toStream( std::ostream& s, double d , int N) ;
80  void toStream( std::ostream& s, const std::string& str , int N) ;
81  void toStream( std::ostream& s, bool b , int N) ;
82 
83  template< class T>
84  std::ostream& toStream( std::ostream& s, const std::vector<T>& v , int N) {
85 
86  typename std::vector<T>::const_iterator it ;
87 
88  unsigned count = 0 ;
89  for( it = v.begin() ; it != v.end() ; it++) {
90 
91  if( count && N && ! (count % N) ) // start a new line after N parameters
92  s << "\n\t\t" ;
93 
94  s << (*it) << " " ;
95  count ++ ;
96 
97 
98  }
99  return s ;
100  }
101 
102 
103  template< class T>
105 
106  template < class T1>
107  void setProcessorParameter( ProcessorParameter_t<T1>* procParam , StringParameters* params );
108 
109 
110 
113  template< class T>
115 
116  friend void setProcessorParameter<>(ProcessorParameter_t<T>* , StringParameters* ) ;
117 
118  public:
119 
120  ProcessorParameter_t( const std::string& name,
121  const std::string& description,
122  T& parameter ,
123  const T& defaultValue,
124  bool optional,
125  int setSize=0) :
126 
127  _parameter( parameter ),
128  _defaultValue( defaultValue )
129  {
130  _name = name ;
131  _parameter = defaultValue ;
132  _description = description ;
133  _optional = optional ;
134  _valueSet = false ;
135  _setSize = setSize ;
136  }
137 
138  virtual ~ProcessorParameter_t() {}
139 
140 
141 
142  // virtual const std::string name() { return _name ; }
143 
144  virtual const std::string type() {
145 
146  // return typeid( _parameter ).name() ; }
147 
148  // make this human readable
149  if ( typeid( _parameter ) == typeid( IntVec )) return "IntVec" ;
150  else if( typeid( _parameter ) == typeid( FloatVec )) return "FloatVec" ;
151  else if( typeid( _parameter ) == typeid( StringVec )) return "StringVec" ;
152  else if( typeid( _parameter ) == typeid( int )) return "int" ;
153  else if( typeid( _parameter ) == typeid( float )) return "float" ;
154  else if( typeid( _parameter ) == typeid( double )) return "double" ;
155  else if( typeid( _parameter ) == typeid(std::string) ) return "string" ;
156  else if( typeid( _parameter ) == typeid( bool ) ) return "bool";
157 
158  else
159  return typeid( _parameter ).name() ;
160  }
161 
162  virtual const std::string defaultValue() {
163 
164  std::stringstream def ;
165 
166  //def << _defaultValue ;
167  toStream( def, _parameter , setSize() ) ;
168 
169  return def.str() ;
170  }
171 
172  virtual const std::string value() {
173 
174  std::stringstream def ;
175 
176  // def << _parameter ;
177  toStream( def, _parameter , setSize() ) ;
178 
179  return def.str() ;
180  }
181 
182  void setValue( StringParameters* params ) {
183 
184  setProcessorParameter< T >( this , params ) ;
185 
186  }
187 
188  protected:
189  T& _parameter ;
190  T _defaultValue ;
191 
192  };
193 
194 } // end namespace marlin
195 #endif
196 
197 
198 //#include "ProcessorParameter.icc"
Templated implementation of ProcessorParameter - automatically created by Processor::registerProcesso...
Definition: ProcessorParameter.h:104
Class that holds a steering variable for a marlin processor - automatically created by Processor::reg...
Definition: ProcessorParameter.h:27
void toStream(std::ostream &s, int i, int N)
Helper function for printing parameter vectors.
Definition: ProcessorParameter.cc:17
Simple parameters class for Marlin.
Definition: StringParameters.h:34