00001 #ifndef ProcessorParameter_h
00002 #define ProcessorParameter_h 1
00003
00004 #include "lcio.h"
00005
00006 #include <iostream>
00007 #include <string>
00008 #include <sstream>
00009 #include "LCIOSTLTypes.h"
00010 #include "StringParameters.h"
00011 #include <typeinfo>
00012
00013
00014
00015
00016 using namespace lcio ;
00017
00018 namespace marlin{
00019
00027 class ProcessorParameter {
00028
00029 friend std::ostream& operator<< ( std::ostream& , ProcessorParameter& ) ;
00030
00031 public:
00032
00033 ProcessorParameter() {}
00034
00035 virtual ~ProcessorParameter() {}
00036
00037 virtual const std::string& name() { return _name ; }
00038 virtual const std::string& description() { return _description ; }
00039 virtual int setSize() { return _setSize ; } ;
00040 virtual bool isOptional() { return _optional ; }
00041 virtual bool valueSet() { return _valueSet ; }
00042
00043 virtual const std::string type()=0 ;
00044 virtual const std::string value()=0 ;
00045 virtual const std::string defaultValue()=0 ;
00046
00047
00048
00049 virtual void setValue( StringParameters* params )=0 ;
00050
00051 protected:
00052
00053 std::string _description ;
00054 std::string _name ;
00055 int _setSize ;
00056 bool _optional ;
00057 bool _valueSet ;
00058 };
00059
00060
00061 std::ostream& operator<< ( std::ostream& s, ProcessorParameter& p ) ;
00062
00063
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 void toStream( std::ostream& s, int i , int N) ;
00078 void toStream( std::ostream& s, float f , int N) ;
00079 void toStream( std::ostream& s, double d , int N) ;
00080 void toStream( std::ostream& s, const std::string& str , int N) ;
00081 void toStream( std::ostream& s, bool b , int N) ;
00082
00083 template< class T>
00084 std::ostream& toStream( std::ostream& s, const std::vector<T>& v , int N) {
00085
00086 typename std::vector<T>::const_iterator it ;
00087
00088 unsigned count = 0 ;
00089 for( it = v.begin() ; it != v.end() ; it++) {
00090
00091 if( count && N && ! (count % N) )
00092 s << "\n\t\t" ;
00093
00094 s << (*it) << " " ;
00095 count ++ ;
00096
00097
00098 }
00099 return s ;
00100 }
00101
00102
00103 template< class T>
00104 class ProcessorParameter_t ;
00105
00106 template < class T1>
00107 void setProcessorParameter( ProcessorParameter_t<T1>* procParam , StringParameters* params );
00108
00109
00110
00113 template< class T>
00114 class ProcessorParameter_t : public ProcessorParameter {
00115
00116 friend void setProcessorParameter<>(ProcessorParameter_t<T>* , StringParameters* ) ;
00117
00118 public:
00119
00120 ProcessorParameter_t( const std::string& name,
00121 const std::string& description,
00122 T& parameter ,
00123 const T& defaultValue,
00124 bool optional,
00125 int setSize=0) :
00126
00127 _parameter( parameter ),
00128 _defaultValue( defaultValue )
00129 {
00130 _name = name ;
00131 _parameter = defaultValue ;
00132 _description = description ;
00133 _optional = optional ;
00134 _valueSet = false ;
00135 _setSize = setSize ;
00136 }
00137
00138 virtual ~ProcessorParameter_t() {}
00139
00140
00141
00142
00143
00144 virtual const std::string type() {
00145
00146
00147
00148
00149 if ( typeid( _parameter ) == typeid( IntVec )) return "IntVec" ;
00150 else if( typeid( _parameter ) == typeid( FloatVec )) return "FloatVec" ;
00151 else if( typeid( _parameter ) == typeid( StringVec )) return "StringVec" ;
00152 else if( typeid( _parameter ) == typeid( int )) return "int" ;
00153 else if( typeid( _parameter ) == typeid( float )) return "float" ;
00154 else if( typeid( _parameter ) == typeid( double )) return "double" ;
00155 else if( typeid( _parameter ) == typeid(std::string) ) return "string" ;
00156 else if( typeid( _parameter ) == typeid( bool ) ) return "bool";
00157
00158 else
00159 return typeid( _parameter ).name() ;
00160 }
00161
00162 virtual const std::string defaultValue() {
00163
00164 std::stringstream def ;
00165
00166
00167 toStream( def, _parameter , setSize() ) ;
00168
00169 return def.str() ;
00170 }
00171
00172 virtual const std::string value() {
00173
00174 std::stringstream def ;
00175
00176
00177 toStream( def, _parameter , setSize() ) ;
00178
00179 return def.str() ;
00180 }
00181
00182 void setValue( StringParameters* params ) {
00183
00184 setProcessorParameter< T >( this , params ) ;
00185
00186 }
00187
00188 protected:
00189 T& _parameter ;
00190 T _defaultValue ;
00191
00192 };
00193
00194 }
00195 #endif
00196
00197
00198