emcWalkTofFEM.C

Go to the documentation of this file.
00001 #include "emcWalkTofFEM.h"
00002 #include "emcDataManager.h"
00003 #include "emcDefines.h"
00004 #include "emcCalFEMFactory.h"
00005 #include <string>
00006 #include <cassert>
00007 
00008 using namespace std;
00009 
00010 namespace
00011 {
00012   static string name = "emcWalkTofFEM" ;
00013   static string title = "WalkTof calibration data" ;
00014   static string classname = "emcWalkTofFEM" ;
00015   
00016   emcCalFEM* creator(int absPosition,
00017                      const PHTimeStamp& start,
00018                      const PHTimeStamp& end,
00019                      bool isDefault)
00020   {
00021     if ( isDefault )
00022       {
00023         return emcWalkTofFEM::Default(absPosition,start,end);
00024       }
00025     else
00026       {
00027         return new emcWalkTofFEM(absPosition,start,end);
00028       }
00029   }
00030 
00031   static bool r = emcCalFEMFactory::registerCreator("WalkTofs",
00032                                                     creator);
00033 }
00034 
00035 //_____________________________________________________________________________
00036 emcWalkTofFEM::emcWalkTofFEM(int absPosition)
00037   : emcCalFEM(absPosition)
00038 {
00039   NameIt(name,title,classname) ;
00040 }
00041 
00042 //_____________________________________________________________________________
00043 emcWalkTofFEM::emcWalkTofFEM(int absPosition, 
00044                          const PHTimeStamp& t1, const PHTimeStamp& t2)
00045   : emcCalFEM(absPosition,t1,t2)
00046 {
00047   NameIt(name,title,classname) ;
00048 }
00049 
00050 //_____________________________________________________________________________
00051 emcWalkTofFEM::emcWalkTofFEM(const emcWalkTofFEM& o)
00052   : emcCalFEM(o.AbsolutePosition(),o.GetStartValTime(),
00053               o.GetEndValTime())
00054 {
00055   o.Copy(*this) ;
00056 }
00057 
00058 //_____________________________________________________________________________
00059 emcWalkTofFEM&
00060 emcWalkTofFEM::operator=(const emcWalkTofFEM& o)
00061 {
00062   if ( this == &o ) return *this ;
00063   Reset() ;
00064   o.Copy(*this) ;
00065   return *this ;
00066 }
00067 
00068 //_____________________________________________________________________________
00069 void
00070 emcWalkTofFEM::Copy(emcWalkTofFEM& o) const
00071 {
00072   emcCalFEM::Copy(o) ;
00073   o.fWalkTof.resize(fWalkTof.size()) ;
00074   size_t i ;
00075   for ( i = 0 ; i < fWalkTof.size() ; i++) {
00076     o.fWalkTof[i] = fWalkTof[i] ;
00077   }  
00078 }
00079 
00080 //_____________________________________________________________________________
00081 emcWalkTofFEM::~emcWalkTofFEM()
00082 {
00083   Reset() ;
00084 }
00085 
00086 //_____________________________________________________________________________
00087 void emcWalkTofFEM::AppendOneChannel(const float value1, const float value2)
00088 {
00089   vfloat tmp;
00090 
00091   tmp.push_back(value1);
00092   tmp.push_back(value2);
00093 
00094   if (fWalkTof.size()<144) {
00095     fWalkTof.push_back(tmp);
00096   }
00097   else {
00098     cerr << "<E-EMCAL> emcWalkTofFEM::AppendOneChannel : fem is full" << endl ;
00099     assert(0);
00100   }
00101 }
00102 
00103 //_____________________________________________________________________________
00104 emcWalkTofFEM* 
00105 emcWalkTofFEM::Default(const int& absPosition, 
00106                      const PHTimeStamp& t1, 
00107                      const PHTimeStamp& t2)
00108 {
00109   emcWalkTofFEM* fem = new emcWalkTofFEM(absPosition,t1,t2) ;
00110 
00111   size_t i ;
00112 
00113   for ( i = 0 ; i < 144 ; i++ ) {
00114     // FIXME: what's a sensible default value here ?
00115     fem->AppendOneChannel(0,0) ;
00116   }
00117   return fem ;
00118 }
00119 
00120 //_____________________________________________________________________________
00121 float
00122 emcWalkTofFEM::getValue(int ichannel, int what) const 
00123 {
00124   if (what!=0 && what!=1) {
00125 
00126     cerr << EMC_WARNING_MSG
00127          << " emcWalkTofFEM::getValue(ichannel,what) : what="
00128          << what << " is incorrect. Returning default value of "
00129          << DefaultReturnValue() << " instead" << endl ;
00130 
00131     return DefaultReturnValue() ;
00132 
00133   }
00134 
00135   if (ichannel>=0 && ichannel<static_cast<int>(fWalkTof.size())) {
00136     return getValueFast(ichannel,what) ;
00137   }
00138   else {
00139     return DefaultReturnValue() ;
00140   }
00141 }
00142 
00143 //_____________________________________________________________________________
00144 void
00145 emcWalkTofFEM::setValue(int ichannel, int what, float value) 
00146 {
00147   if((what>=0&&what<=1)&&(ichannel>=0&&ichannel<144)) fWalkTof[ichannel][what] = value; else 
00148     cerr << EMC_WARNING_MSG
00149          << "<emcWalkTofFEM> Attempt to set value outside address field - ignored"<<endl;
00150 }
00151 
00152 //_____________________________________________________________________________
00153 float
00154 emcWalkTofFEM::getValueFast(int ichannel, int what) const
00155 {
00156   return (fWalkTof[ichannel])[what] ;
00157 }
00158 
00159 //_____________________________________________________________________________
00160 bool
00161 emcWalkTofFEM::IsEqual(const emcCalFEM& obj) const
00162 {
00163   if ( !dynamic_cast<const emcCalFEM*>(&obj) ) return false ;
00164 
00165   if ( size() != obj.size() ) return false ;
00166 
00167   for ( size_t i = 0 ; i < size() ; i++) {
00168     for ( int j = 0 ; j < 2 ; j++ ) {
00169       if ( getValue(i,j) != obj.getValue(i,j) ) return false ;
00170     }
00171   }
00172 
00173   return true ;
00174 }
00175 
00176 //_____________________________________________________________________________
00177 void emcWalkTofFEM::Reset(void)
00178 {
00179   fWalkTof.clear();
00180 }
00181 
00182 //_____________________________________________________________________________
00183 ostream&
00184 emcWalkTofFEM::Print(ostream& out, int level) const
00185 {
00186   emcCalFEM::Print(out,level) ;
00187 
00188   if (level) {
00189     
00190     int size = fWalkTof.size() ;
00191      
00192     for ( int i = 0  ; i <  size ; i++)
00193       {
00194         out << "#" << i 
00195             << " " << getValue(i,0) 
00196             << " " << getValue(i,1) 
00197             << endl ;   
00198       }
00199   }
00200   return out ;
00201 }