emcDataObject.C

Go to the documentation of this file.
00001 // Implementation of class : DataObject
00002 //
00003 // Author: Yves Schutz (schutz@in2p3.fr)
00004 
00005 #include "emcDataObject.h"
00006 #include "emcRawDataAccessor.h"
00007 #include <iomanip>
00008 #include <cassert>
00009 #include "TString.h"
00010 #include "EmcIndexer.h"
00011 
00012 ClassImp(emcDataObject)
00013 
00014 //_____________________________________________________________________________
00015 emcDataObject::emcDataObject() 
00016 { 
00017   fMaxSize = 0;
00018   fSize    = 0; 
00019   fDataErrors = 0;
00020   fDataMap    = 0;
00021   fSoftKey    = 0;
00022   fDeadMap = 0;
00023   fOwnDeadMap = false;
00024   fReadOnly = false;
00025 
00026   // MV 2001/12/08
00027   fWarnMap=0;
00028   fOwnWarnMap=false;
00029 
00030 }
00031 
00032 //_____________________________________________________________________________
00033 emcDataObject::~emcDataObject()
00034 {
00035   if(false){
00036     //  FIXME: neither of these areas belonge to this object......
00037     delete[] fDataErrors; 
00038     delete[] fDataMap; 
00039     delete[] fSoftKey; 
00040   }
00041   if (fOwnDeadMap) delete[] fDeadMap;
00042 
00043   // MV 2001/12/08
00044   if (fOwnWarnMap) delete[] fWarnMap;
00045 }
00046 
00047 //_____________________________________________________________________________
00048 void emcDataObject::Reset()
00049 {
00050   fMaxSize = 0;
00051   fSize    = 0; 
00052   if(false){
00053     delete[] fDataErrors; 
00054     delete[] fDataMap; 
00055     delete[] fSoftKey; 
00056   }
00057   fDataErrors = 0; 
00058   fDataMap    = 0; 
00059   fSoftKey    = 0;
00060   fDeadMap = 0;
00061   fOwnDeadMap = false;
00062   fReadOnly = false;
00063 
00064   // MV 2001/12/08
00065   fWarnMap=0;
00066   fOwnWarnMap=false;
00067 }
00068 
00069 //_____________________________________________________________________________
00070 void emcDataObject::SetDataDescriptionPointers(Int_t * dataMap,
00071                                                long  * softwareKey,
00072                                                Int_t * dataerrors)
00073 {
00074   fDataMap    = dataMap;
00075   fSoftKey    = softwareKey;
00076   fDataErrors = dataerrors;
00077 }
00078 
00079 //_____________________________________________________________________________
00080 void emcDataObject::GetDataDescriptionPointers(Int_t * & dataMap,
00081                                                long  * & softwareKey,
00082                                                Int_t * & dataerrors) const
00083 {
00084   dataMap     = fDataMap;
00085   softwareKey = fSoftKey;
00086   dataerrors  = fDataErrors;
00087 }
00088 
00089 //_____________________________________________________________________________
00090 void emcDataObject::SetDataDescriptionPointers(Int_t * dataMap,
00091                                                long  * softwareKey,
00092                                                Int_t * dataerrors,
00093                                                Int_t * deadmap)
00094 {
00095   fDataMap    = dataMap;
00096   fSoftKey    = softwareKey;
00097   fDataErrors = dataerrors;
00098   fDeadMap = deadmap;
00099 }
00100 
00101 //_____________________________________________________________________________
00102 void emcDataObject::GetDataDescriptionPointers(Int_t * & dataMap,
00103                                                long  * & softwareKey,
00104                                                Int_t * & dataerrors,
00105                                                Int_t * & deadmap) const
00106 {
00107   dataMap     = fDataMap;
00108   softwareKey = fSoftKey;
00109   dataerrors  = fDataErrors;
00110   deadmap     = fDeadMap;
00111 }
00112 
00113 //_____________________________________________________________________________
00114 void emcDataObject::SetDataDescriptionPointers(Int_t * dataMap,
00115                                                long  * softwareKey,
00116                                                Int_t * dataerrors,
00117                                                Int_t * deadmap,
00118                                                Int_t * warnmap)
00119 {
00120   // MV 2001/12/08
00121   fDataMap    = dataMap;
00122   fSoftKey    = softwareKey;
00123   fDataErrors = dataerrors;
00124   fDeadMap = deadmap;
00125   fWarnMap=warnmap;
00126 }
00127 
00128 //_____________________________________________________________________________
00129 void emcDataObject::GetDataDescriptionPointers(Int_t * & dataMap,
00130                                                long  * & softwareKey,
00131                                                Int_t * & dataerrors,
00132                                                Int_t * & deadmap,
00133                                                Int_t * & warnmap) const
00134 {
00135   // MV 2001/12/08
00136   dataMap     = fDataMap;
00137   softwareKey = fSoftKey;
00138   dataerrors  = fDataErrors;
00139   deadmap     = fDeadMap;
00140   warnmap=fWarnMap;
00141 }
00142 
00143 
00144 //_____________________________________________________________________________
00145 void emcDataObject::DecodeKey(long key, Int_t& arm, Int_t& sector, Int_t& yrow, Int_t& zrow) const
00146 {
00147   arm    = key / 100000; 
00148   sector = ( key - arm * 100000 ) / 10000; 
00149   yrow   = ( key - arm * 100000 - sector * 10000 ) / 100; 
00150   zrow   = key - arm * 100000 - sector * 10000 - yrow * 100; 
00151 }
00152 
00153 //_____________________________________________________________________________
00154 long emcDataObject::GenerateSoftwareKey(Int_t ItemId) const
00155 {
00156 
00157   int iS;   // sector number (0-7)
00158   int iSMT; // tower_index number within Sector
00159   int iarm; // arm:0=West, 1=East;
00160   int iy;   // row number of the tower_index within a sector (bottom=>row=0)
00161   int iz;   /* column number of the tower_index within a sector. column=0 for
00162                 lower bottom left tower_index, when sector is viewed from back 
00163                 (i.e. you are looking at the electronics).
00164               */
00165   int swkey; /* software key = 
00166                  100000 * iarm +
00167                   10000 * iS +
00168                     100 * iy +
00169                           iz
00170                */
00171 
00172   EmcIndexer::iPXiSiST(ItemId,iS,iSMT); 
00173   // defined in the Static package of online monitoring
00174 
00175   iarm = ((iS<4)?0:1);
00176   if (iS<6) {
00177     iy = iSMT/72;
00178     iz = iSMT%72;
00179   }
00180   else {
00181     iy = iSMT/96;
00182     iz = iSMT%96; 
00183   }
00184   
00185   if(iS>=4){
00186     // change sector numbers to comply with PHENIX geography
00187     iS = ((iS -=6)<0)? iS+4 : iS;
00188   }
00189   swkey = 100000*iarm + 10000*iS + 100*iy + iz;
00190        
00191   return swkey;
00192 }
00193 
00194 //_____________________________________________________________________________
00195 Int_t emcDataObject::GetDead(Int_t index) const
00196 {
00197   if (fDeadMap && index>=0 && index<fMaxSize) {
00198     return fDeadMap[index];
00199   }
00200   else {
00201     return 0;
00202   }
00203 }
00204 
00205 //_____________________________________________________________________________
00206 Int_t emcDataObject::GetWarn(Int_t index) const
00207 {
00208   // MV 2001/12/08
00209 
00210   if (fWarnMap && index>=0 && index<fMaxSize) {
00211     return fWarnMap[index];
00212   }
00213   else {
00214     return 0;
00215   }
00216 }
00217 
00218 //_____________________________________________________________________________
00219 bool emcDataObject::HasErrors(void) const
00220 {
00221   bool rv = false;
00222   if (fDataErrors) {
00223     int i;
00224     for (i=0;i<fSize && rv==false;i++) {
00225       if (fDataErrors[i]) rv = true;
00226     }
00227   }
00228   return rv;
00229 }
00230 
00231 
00232 //______________________________________________________________________________
00233 void emcDataObject::Streamer(TBuffer &R__b)
00234 {
00235   // Stream an object of class emcDataObject.
00236   
00237   // MV 2001/12/12 Incremented class version 1 -> 2
00238 
00239   if (R__b.IsReading()) {
00240     
00241     Version_t R__v = R__b.ReadVersion(); if (R__v) { }
00242     TObject::Streamer(R__b);
00243     
00244     int thesize;
00245     R__b >> thesize;
00246     R__b >> fSize;
00247     
00248     if (thesize!=fMaxSize) {
00249       delete[] fDataErrors;
00250       fDataErrors = 0;
00251       if (fOwnDeadMap) {
00252         delete[] fDeadMap;
00253         fDeadMap = 0;
00254       }
00255       // MV 2001/12/08
00256       if (fOwnWarnMap) {
00257         delete[] fWarnMap;
00258         fWarnMap = 0;
00259       }         
00260     }
00261     
00262     fMaxSize = thesize;
00263     
00264     if (!fDataErrors) fDataErrors = new Int_t[fMaxSize];
00265     if (!fDeadMap) {
00266       fDeadMap = new Int_t[fMaxSize];      
00267       fOwnDeadMap = true;
00268     }
00269     
00270     R__b.ReadFastArray(fDataErrors,fSize);
00271     R__b.ReadFastArray(fDeadMap,fSize);      
00272     fReadOnly = true;
00273     
00274     // MV 2001/12/08
00275     if (!fWarnMap) {
00276       fWarnMap = new Int_t[fMaxSize];      
00277       fOwnWarnMap = true;
00278     }
00279     
00280     if(R__v>1){
00281       
00282       R__b.ReadFastArray(fWarnMap, fSize);
00283       
00284     } else{
00285       
00286       memset((void*)fWarnMap, 0, fSize*sizeof(Int_t));
00287       
00288     }
00289    } else {
00290 
00291       R__b.WriteVersion(emcDataObject::IsA());
00292       TObject::Streamer(R__b);
00293       R__b << fMaxSize;
00294       R__b << fSize;
00295 
00296       Int_t* tmp = 0;
00297 
00298       // MV 2001/12/08 added fWarnMap
00299       if (!fDataErrors || !fDeadMap || !fWarnMap) {
00300         // Prepare an empty array
00301         tmp = new Int_t[fSize];
00302         int i;
00303         for (i=0;i<fSize;i++) tmp[i]=0;
00304       }
00305 
00306       if (fDataErrors) {
00307         R__b.WriteFastArray(fDataErrors,fSize);
00308       }
00309       else {
00310         R__b.WriteFastArray(tmp,fSize);
00311       }
00312 
00313       if (fDeadMap) {
00314         R__b.WriteFastArray(fDeadMap,fSize);
00315       }
00316       else {
00317         R__b.WriteFastArray(tmp,fSize);
00318       }
00319 
00320       // MV 2001/12/08
00321       if (fWarnMap) {
00322         R__b.WriteFastArray(fWarnMap,fSize);
00323       }
00324       else {
00325         R__b.WriteFastArray(tmp,fSize);
00326       }
00327 
00328       delete[] tmp;       
00329    }
00330 }
00331 
00332 
00333 
00334