Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

ProcessorParameter.h

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 // typedef std::map< std::string ,  std::vector< std::string > >  ParametersMap ;
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 //   template< class T>
00067 //   std::ostream& operator<< (  std::ostream& s, const std::vector<T>& v ) {
00068     
00069 //     typename std::vector<T>::const_iterator it ;
00070     
00071 //     for( it = v.begin() ; it != v.end() ; it++) {
00072 //       s <<  (*it) << " " ;
00073 //     }
00074 //     return s ;
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)  )   // start a new line after N parameters
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     //    virtual const std::string  name() { return _name ; } 
00143 
00144     virtual const std::string  type() {  
00145 
00146       // return typeid( _parameter ).name() ; } 
00147 
00148       // make this human readable
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      //def << _defaultValue  ;
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      //     def << _parameter  ;
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 } // end namespace marlin 
00195 #endif
00196 
00197 
00198 //#include "ProcessorParameter.icc"

Generated on Mon Jan 12 09:48:51 2009 for Marlin by doxygen 1.3.5