emcLCTofFEM.C

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