emcMixedDataObject.C

Go to the documentation of this file.
00001 // Implementation of class : emcMixedDataObject
00002 //
00003 // Author: Yves Schutz (yves.schutz@subatech.in2p3.fr)
00004 
00005 #include "emcMixedDataObject.h"
00006 #include "emcRawDataAccessor.h"
00007 #include <iomanip>
00008 #include <iostream>
00009 #include <cassert>
00010 #include <map>
00011 #include "TString.h"
00012 
00013 ClassImp(emcMixedDataObject)
00014 
00015   using namespace std;
00016 
00017 //_____________________________________________________________________________
00018 emcMixedDataObject::emcMixedDataObject() : emcDataObject()
00019 {
00020   fADC = fTDC = fHG = fLG = 0 ;
00021   fOwnAllocation  = false ;
00022   fPedestal       = false ;
00023   fHLRatio        = false ;
00024   UseHGLG(false) ;
00025 }
00026 
00027 
00028 
00029 //_____________________________________________________________________________
00030 emcMixedDataObject::~emcMixedDataObject()
00031 {
00032   delete[] fADC ;
00033   delete[] fTDC ;
00034   delete[] fHG ;
00035   delete[] fLG ;
00036 }
00037 
00038 //_____________________________________________________________________________
00039 void emcMixedDataObject::Get(Int_t index, Float_t& adc, Float_t& tdc) const
00040 {
00041   /* Get adc,tdc using tower indexing. 
00042      If towerindex is not valid, returned values of adc and tdc are -1
00043   */
00044 
00045   if (index>=0) {
00046     adc        = fADC[index] ;
00047     tdc        = fTDC[index] ;
00048   }
00049   else {
00050     adc = tdc = 0. ;
00051   }
00052 }
00053 
00054 //_____________________________________________________________________________
00055 void emcMixedDataObject::Get(Int_t index, Float_t& adc, Float_t& tdc,
00056                              Float_t& hg, Float_t& lg) const
00057 {
00058   /* Get adc,tdc,hg,lg using tower indexing.
00059      If towerindex is not valid, returned values of adc=tdc=hg=lg=-1
00060   */
00061 
00062   if (index>=0) {
00063     adc        = fADC[index] ;
00064     tdc        = fTDC[index] ;
00065     if (IsUsingHGLG()) {
00066       hg = fHG[index] ;
00067       lg = fLG[index] ;
00068     }
00069     else {
00070       cerr << "<E> emcMixedDataObject::Get : You are requesting HG, LG "
00071            << " but this MDO was not created for that. See UseHGLG(bool) "
00072            << " method."
00073            << endl ;
00074     }
00075   }
00076   else {
00077     adc=tdc=hg=lg= 0. ;
00078   }
00079 }
00080 
00081 //_____________________________________________________________________________
00082 Float_t emcMixedDataObject::GetADC(Int_t index) const 
00083 {
00084   // Returns ADC value or -1 is towerindex is not valid.
00085 
00086   if (index>=0) {
00087     return fADC[index] ; 
00088   }
00089   else {
00090     return 0. ; 
00091   }
00092 } 
00093 
00094 //_____________________________________________________________________________
00095 Float_t emcMixedDataObject::GetHG(Int_t index) const 
00096 {
00097   // Returns HG value or -1 is towerindex is not valid.
00098 
00099   if (!IsUsingHGLG()) {
00100     cerr << "<E> emcMixedDataObject::GetHG : I am not using HGLG" << endl ;
00101     return -1 ;
00102   }
00103 
00104   if (index>=0) {
00105     return fHG[index] ; 
00106   }
00107   else {
00108     return 0. ; 
00109   }
00110 }
00111 
00112 //_____________________________________________________________________________
00113 Float_t emcMixedDataObject::GetLG(Int_t index) const 
00114 {
00115   // Returns Low Gain value or -1 if towerindex is not valid.
00116 
00117   if (!IsUsingHGLG()) {
00118     cerr << "<E> emcMixedDataObject::GetLG : I am not using HGLG" << endl ;
00119     return 0. ;
00120   }
00121 
00122   if (index>=0) {
00123     return fLG[index] ; 
00124   }
00125   else {
00126     return 0. ; 
00127   }
00128 } 
00129 
00130 //_____________________________________________________________________________
00131 void emcMixedDataObject::GetPointers(float*& ADC, float*& TDC,int*& KEY) 
00132 {
00133   // WARNING. USE THIS METHOD IS STRONGLY DISCOURAGED. USE AT YOUR OWN RISK !
00134   ADC = fADC ;
00135   TDC = fTDC ;
00136   KEY = fDataMap ;
00137 }
00138 
00139 //_____________________________________________________________________________
00140 void emcMixedDataObject::GetPointers(float*& ADC, float*& TDC, 
00141                    float*& HG, float*& LG, int*& KEY) 
00142 {
00143   // WARNING. USE THIS METHOD IS STRONGLY DISCOURAGED. USE AT YOUR OWN RISK !
00144   ADC = fADC ;
00145   TDC = fTDC ;
00146   if (IsUsingHGLG()) {
00147     LG = fLG ;
00148     HG = fHG ;
00149   }
00150   else {
00151     cerr << "<E> emcMixedDataObject::GetPointers : You are requesting HG, LG "
00152          << " but this MDO was not created for that. See UseHGLG(bool) "
00153          << " method."
00154          << endl ;
00155   }
00156   KEY = fDataMap ;
00157 }
00158 
00159 //_____________________________________________________________________________
00160 Float_t emcMixedDataObject::GetTDC(Int_t index) const 
00161 {
00162   // Returns TDC value or -1 if towerindex is not valid.
00163 
00164   if (index>=0) {
00165     return fTDC[index] ; 
00166   }
00167   else {
00168     return 0. ; 
00169   }
00170 } 
00171 
00172 //_____________________________________________________________________________
00173 TString emcMixedDataObject::Status() 
00174 {
00175   TString status ; 
00176   TString blank = "     " ; 
00177   status = "emcMixedDataObject status : \n" ;
00178   status += blank ; 
00179   if ( IsPedestalSubtracted() ) 
00180     status += "Pedestals have been subtracted\n" ; 
00181   else
00182     status += "Pedestals have NOT been subtracted\n" ;
00183 
00184   status += blank ; 
00185   if ( IsHLRatioReal() ) 
00186     status += "Real H/L ratios have been applied\n" ; 
00187   else
00188     status += "H/L ratios = 16 have been applied\n" ; 
00189 
00190   return status ; 
00191 }
00192 
00193 //_____________________________________________________________________________
00194 void emcMixedDataObject::Set(int index,  float adc, float tdc)
00195 {
00196   /* Set the data for a given tower, referenced by its index.
00197      Caller must insure that index < GetMaxSize()
00198    */
00199   assert (ValidIndex(index)) ;
00200 
00201   if ( index+1 > fSize) 
00202     fSize = index+1 ;
00203 
00204   fADC[index]        = adc ;
00205   fTDC[index]        = tdc ; 
00206 
00207 }
00208 
00209 //_____________________________________________________________________________
00210 void emcMixedDataObject::Set(int index,  float adc, float tdc,
00211                              float hg, float lg)
00212 {
00213   /* Set the data for a given tower, referenced by its index.
00214      Caller must insure that index < GetMaxSize()
00215    */
00216   assert (ValidIndex(index)) ;
00217 
00218   if ( index+1 > fSize) 
00219     fSize = index+1 ;
00220 
00221   fADC[index]        = adc ;
00222   fTDC[index]        = tdc ; 
00223   fHG[index] = hg ;
00224   fLG[index] = lg ;
00225 }
00226 
00227 //_____________________________________________________________________________
00228 void emcMixedDataObject::SetToZero(int index)
00229 {
00230   if (IsUsingHGLG()) {
00231     Set(index,0.0,0.0,0.0,0.0) ;
00232   }
00233   else {
00234     Set(index,0.0,0.0) ;
00235   }
00236 }
00237 
00238 //_____________________________________________________________________________
00239 bool emcMixedDataObject::IsZero(Int_t index) const 
00240 {
00241   /* Tells if a channel is zero (zero suppressed by DCM's). Will return true also if   index is not valid. */
00242 
00243   if (!ValidIndex(index)) return true ;
00244  
00245   if ( fADC[index] == 0.0 ) return true ;
00246   return false ;
00247 }
00248 
00249 //_____________________________________________________________________________
00250 void emcMixedDataObject::SetMaxSize(Int_t thesize)
00251 {
00257   if ( fMaxSize != thesize) {
00258     // Happens when there is a new configuration file
00259     delete[] fADC ;
00260     delete[] fTDC ;
00261     delete[] fHG ;
00262     delete[] fLG ;
00263 
00264     fMaxSize   = thesize ;
00265     fSize = 0 ;
00266     if(thesize){
00267       fADC        = new Float_t[fMaxSize] ;
00268       fTDC        = new Float_t[fMaxSize] ;
00269       if (IsUsingHGLG()) {
00270         fHG        = new Float_t[fMaxSize] ;
00271         fLG        = new Float_t[fMaxSize] ;
00272       }
00273     } else {
00274       fADC = fTDC = fHG = fLG = 0;
00275     }
00276     fPedestal = fHLRatio = false ; 
00277   }
00278 }
00279 
00280 //_____________________________________________________________________________
00281 void emcMixedDataObject::Streamer(TBuffer&)
00282 {
00283    // Stream an object of class emcMixedDataObject.
00284 
00285   cout << "<W> emcMixedDataObject::Streamer disabled for the moment. Contact aphecetc@in2p3.fr." << endl ;
00286   exit(1);
00287   //  if (R__b.IsReading()) { // reading part
00288     // Version_t R__v = R__b.ReadVersion(); if (R__v) { }
00289 //     emcDataObject::Streamer(R__b); // stream the mother class
00290 //     R__b >> fPedestal ; 
00291 //     R__b >> fHLRatio ; 
00292 
00293 //     delete[] fADC ;
00294 //     delete[] fTDC ;
00295 
00296 //     // we allocate enough space for consistency...
00297 //     fADC        = new Float_t[fMaxSize] ;
00298 //     fTDC        = new Float_t[fMaxSize] ;
00299     
00300 //     // ... but we read only what is on disk = non-zero towers
00301 //     R__b.ReadFastArray(fADC,fSize);
00302 //     R__b.ReadFastArray(fTDC,fSize);
00303 
00304 //     // It was decided that HG and LG values are not kept,
00305 //     // so we tell here that we do not use HG LG values
00306 //     UseHGLG(false) ;
00307     
00308 //   } else { // writing part
00309 //     R__b.WriteVersion(emcMixedDataObject::IsA());
00310 //     emcDataObject::Streamer(R__b); // stream the mother class
00311 //     R__b << fPedestal ; 
00312 //     R__b << fHLRatio ; 
00313 
00314 //     // we write only non-zero towers
00315 //     R__b.WriteFastArray(fADC, fSize);
00316 //     R__b.WriteFastArray(fTDC, fSize);
00317 //   }
00318 }
00319 
00320 //_____________________________________________________________________________
00321 void emcMixedDataObject::UseHGLG(bool use)
00322 {
00323   // Decide if this object must take care of raw High and Low Gain values
00324   // (the LG and HG array will only be usable after a proper call to
00325   // the Set method).
00326 
00327   delete[] fLG ;
00328   delete[] fHG ;
00329 
00330   if ( use == true && fMaxSize) {
00331     fLG = new Float_t[fMaxSize] ;
00332     fHG = new Float_t[fMaxSize] ;    
00333   } else {
00334     fHG = fLG = 0;
00335   }
00336   
00337   fUseHGLG = use ;
00338 }
00339 
00340 //_____________________________________________________________________________
00341 ostream& operator << (ostream& out, const emcMixedDataObject& mdo) 
00342 {
00343   string head = " Tower :      arm    sector yrow   zrow   ADC    TDC    " ;
00344   if (mdo.IsUsingHGLG()) head += " HG     LG" ;
00345   head += "  ERR" ;
00346   head += " DeadNeighbours" ;
00347 
00348   int i ;
00349   int counter = 0 ; 
00350   out << head << endl ;
00351   out << dec ;
00352   Int_t arm, sector, yrow, zrow ; 
00353   TString ans ; 
00354 
00355   for (i = 0; i < mdo.GetSize(); i++) {
00356     out << dec ;
00357     counter++ ; 
00358     if ( counter == 30 ) {
00359       counter = 0 ; 
00360       cout << "S(top) or C(ontinue) ?  " ;
00361       cin >> ans ; 
00362       cout << endl ; 
00363       if ( ans == "s" || ans == "S" ) 
00364         break ; 
00365       out << head << endl ;
00366     }
00367     mdo.DecodeKey( mdo.GetSoftwareKey(mdo.fDataMap[i]), arm,sector, yrow, zrow ) ; 
00368     out << "#" << mdo.GetItemId(i) << " : "
00369         << arm <<" "
00370         << sector <<" "
00371         << yrow <<" "
00372         << zrow <<" * "
00373         << mdo.fADC[i] <<" "
00374         << mdo.fTDC[i] <<" ";
00375     if (mdo.IsUsingHGLG()) {
00376       out << mdo.fHG[i] 
00377           << mdo.fLG[i] ;
00378     }
00379     out << ") " 
00380         << hex << mdo.GetDataError(i) << dec << " D" 
00381         << hex << mdo.GetDead(i)
00382         << endl ;
00383   }
00384   
00385   return out ;
00386 
00387 }