emcRawDataObject.C

Go to the documentation of this file.
00001 // Author: Laurent Aphecetche (aphecetc@in2p3.fr)
00002 // E.Kistenev - 04/25/00 - softkey fixed
00003 // Y.Schutz   - 04/28/00 - derivation from emcDataObject
00004 //-------------------------------------------------------------------------
00005 
00006 #include "emcRawDataObject.h"
00007 #include <iostream>
00008 #include <iomanip>
00009 #include <cassert>
00010 #include "TString.h"
00011 #include "EmcFEM.h"
00012 
00013 ClassImp(emcRawDataObject)
00014 
00015   using namespace std;
00016 
00017 //_____________________________________________________________________________
00018 emcRawDataObject::emcRawDataObject() : emcDataObject()
00019 {
00020   fTAC = fHGPost = fLGPost = fHGPre = fLGPre = 0;
00021   fAMUcells = 0;
00022   fOwnAllocation = false;
00023 }
00024 
00025 //_____________________________________________________________________________
00026 emcRawDataObject::emcRawDataObject(Int_t    thesize,
00027                                    int    * dataMap,
00028                                    Float_t* tac,
00029                                    Float_t* hgpost, Float_t* lgpost,
00030                                    Float_t* hgpre, Float_t* lgpre,
00031                                    const cells* amucells,
00032                                    int        * dataerrors)
00033 {
00034   if (thesize%144==0) {
00035     fNumberOfWordsPerFEM = 144;
00036   }
00037   else if (thesize%192==0) {
00038     fNumberOfWordsPerFEM = 192;
00039   } 
00040   else {
00041     assert (0==1);
00042   }
00043 
00044   fOwnAllocation = false;
00045   fMaxSize    = fSize = thesize;
00046   fTAC        = tac;
00047   fHGPost     = hgpost;
00048   fLGPost     = lgpost;
00049   fHGPre      = hgpre;
00050   fLGPre      = lgpre;
00051   fDataMap    = dataMap;
00052   fDataErrors = dataerrors;
00053   fAMUcells   = const_cast<cells*>(amucells);
00054 
00055   fSoftKey    = new long [fMaxSize];
00056   //  if DataMap is present - convert it into Software Keys and fIndexMap
00057   if(fDataMap){
00058     for (int Item = 0; Item<thesize; Item++) {
00059       fSoftKey[Item] = GenerateSoftwareKey(fDataMap[Item]);
00060       fIndexMap[fDataMap[Item]]=Item;
00061     }
00062   }
00063   else {
00064     cout << "<W> RDO : fDataMap not present. Cannot compute IndexMap" << endl;
00065   }
00066 }
00067 
00068 //_____________________________________________________________________________
00069 emcRawDataObject::emcRawDataObject(const emcRawDataObject&) : emcDataObject()
00070 {
00071   std::cerr << __FILE__ << ":" << __LINE__ << "METHOD IS NOT IMPLEMENTED!!"
00072             << std::endl;
00073   exit(1);
00074 }
00075 
00076 //_____________________________________________________________________________
00077 emcRawDataObject&
00078 emcRawDataObject::operator=(const emcRawDataObject&)
00079 {
00080   std::cerr << __FILE__ << ":" << __LINE__ << "METHOD IS NOT IMPLEMENTED!!"
00081             << std::endl;
00082   return *this;
00083 }
00084 
00085 //_____________________________________________________________________________
00086 emcRawDataObject::~emcRawDataObject()
00087 {
00088   if (fOwnAllocation) {
00089     delete[] fTAC;
00090     delete[] fHGPost;
00091     delete[] fLGPost;
00092     delete[] fHGPre;
00093     delete[] fLGPre;
00094     delete[] fAMUcells;
00095     delete[] fDataMap;
00096   }
00097   // By default - This object owns SoftwareKeys only 
00098   if(fSoftKey) delete [] fSoftKey;
00099 }
00100 //_____________________________________________________________________________
00101 
00102 void emcRawDataObject::SetCells(int iSM, int ctac, int cpre, int cpost){
00103   fAMUcells[iSM].tac  = ctac;
00104   fAMUcells[iSM].pre  = cpre;
00105   fAMUcells[iSM].post = cpost;
00106 }
00107 //_____________________________________________________________________________
00108 void emcRawDataObject::GetCells(Int_t    index,
00109                            int& amupre, int& amupost, int& amutac) const
00110 {
00111     amupre  = fAMUcells[index/fNumberOfWordsPerFEM].pre;
00112     amupost = fAMUcells[index/fNumberOfWordsPerFEM].post;
00113     amutac  = fAMUcells[index/fNumberOfWordsPerFEM].tac;
00114 }
00115 //_____________________________________________________________________________
00116 int emcRawDataObject::GetTACCell(Int_t    index) const
00117 {
00118     return  fAMUcells[index/fNumberOfWordsPerFEM].tac;
00119 }
00120 
00121 //_____________________________________________________________________________
00122 
00123 void emcRawDataObject::Set(const int  index,
00124                            const int  & tac,
00125                            const int  & hgpost, const int& lgpost,
00126                            const int  & hgpre,  const int& lgpre,
00127                            const int  & dataerror){
00128     fTAC[index]        = (float)tac; 
00129     fHGPost[index]     = (float)hgpost;
00130     fHGPre[index]      = (float)hgpre;
00131     fLGPost[index]     = (float)lgpost;
00132     fLGPre[index]      = (float)lgpre;
00133     fDataErrors[index] = dataerror;
00134 }
00135 
00136 //_____________________________________________________________________________
00137 void emcRawDataObject::Get(Int_t    index,
00138                            Float_t& tac,
00139                            Float_t& hgpost, Float_t& lgpost,
00140                            Float_t& hgpre, Float_t& lgpre,
00141                            int& amupre, int& amupost, int& amutac,
00142                            int& dataerror) const
00143 {
00144   //  if (ValidIndex(index)) {
00145     tac     = fTAC[index];
00146     hgpost  = fHGPost[index];
00147     hgpre   = fHGPre[index];
00148     lgpost  = fLGPost[index];
00149     lgpre   = fLGPre[index];
00150     amupre  = fAMUcells[index/fNumberOfWordsPerFEM].pre;
00151     amupost = fAMUcells[index/fNumberOfWordsPerFEM].post;
00152     amutac  = fAMUcells[index/fNumberOfWordsPerFEM].tac;
00153     dataerror = fDataErrors[index];
00154 //    }
00155 //    else {
00156 //      cerr << "<E> emcRawDataObject::Get - index out of bounds" << endl;
00157 //    }
00158 }
00159 
00160 //_____________________________________________________________________________
00161 void emcRawDataObject::Get(Int_t    index,
00162                            Float_t& tac,
00163                            Float_t& hgpost, Float_t& lgpost,
00164                            Float_t& hgpre, Float_t& lgpre,
00165                            int& dataerror) const
00166 {
00167   //  if (ValidIndex(index)) {
00168     tac     = fTAC[index];
00169     hgpost  = fHGPost[index];
00170     hgpre   = fHGPre[index];
00171     lgpost  = fLGPost[index];
00172     lgpre   = fLGPre[index];
00173     dataerror = fDataErrors[index];
00174 //    }
00175 //    else {
00176 //      cerr << "<E> emcRawDataObject::Get - index out of bounds" << endl;
00177 //    }
00178 }
00179 
00180 //_____________________________________________________________________________
00181 int emcRawDataObject::GetIndexByTowerId(int towerid) const
00182 {
00183   map<int,int>::const_iterator p;
00184   p = fIndexMap.find(towerid);
00185   if (p!=fIndexMap.end()) {
00186     return p->second;
00187   }
00188   else {
00189     return -1;
00190   }
00191 }
00192 //_____________________________________________________________________________
00193 void emcRawDataObject::resetAMUAddresses(const int fem) const
00194 {
00195   fAMUcells[fem].pre = 0;
00196   fAMUcells[fem].post= 0;
00197   fAMUcells[fem].tac = 0;
00198   
00199 }
00200 
00201 //_____________________________________________________________________________
00202 bool emcRawDataObject::IsZero(Int_t index) const 
00203 {
00204   /* Tells if a channel is zero (zero suppressed by DCM's). Will return true also if   index is not valid. */
00205 
00206   //  if (!ValidIndex(index)) return true;
00207  
00208   //  float zero = 4095.0;
00209 
00210 //      if ( fTAC[index] != zero ||
00211 //           fLGPost[index] != zero ||
00212 //           fHGPost[index] != zero ||
00213 //           fLGPre[index] != zero ||
00214 //           fHGPre[index] != zero 
00215 //       ) 
00216       return ((fDataErrors[index]&0x2000)? true : false);;
00217       //  return true;
00218 }
00219 
00220 //_____________________________________________________________________________
00221 void emcRawDataObject::Streamer(TBuffer &R__b)
00222 {
00223    // Stream an object of class emcRawDataObject.
00224 
00225    int i;
00226 
00227    if (R__b.IsReading()) {
00228       Version_t R__v = R__b.ReadVersion(); if (R__v) { }
00229 
00230       emcDataObject::Streamer(R__b);
00231 
00232       R__b >> fNumberOfWordsPerFEM;
00233 
00234       if (fOwnAllocation) {
00235         delete[] fTAC;
00236         delete[] fHGPost;
00237         delete[] fLGPost;
00238         delete[] fHGPre;
00239         delete[] fLGPre;
00240         delete[] fAMUcells;
00241       }
00242 
00243       fOwnAllocation = true;
00244 
00245       fTAC    = new Float_t[fSize];
00246       fHGPost = new Float_t[fSize];
00247       fLGPost = new Float_t[fSize];
00248       fHGPre  = new Float_t[fSize];
00249       fLGPre  = new Float_t[fSize];
00250 
00251       Byte_t* fAMUPre  = new Byte_t[fSize/fNumberOfWordsPerFEM];
00252       Byte_t* fAMUPost = new Byte_t[fSize/fNumberOfWordsPerFEM];
00253       Byte_t* fAMUTAC  = new Byte_t[fSize/fNumberOfWordsPerFEM];
00254 
00255       R__b.ReadFastArray(fTAC,fSize);
00256       R__b.ReadFastArray(fHGPost,fSize);
00257       R__b.ReadFastArray(fLGPost,fSize);
00258       R__b.ReadFastArray(fHGPre,fSize);
00259       R__b.ReadFastArray(fLGPre,fSize);
00260       
00261       R__b.ReadFastArray(fAMUPre,fSize/fNumberOfWordsPerFEM);
00262       R__b.ReadFastArray(fAMUPost,fSize/fNumberOfWordsPerFEM);
00263       R__b.ReadFastArray(fAMUTAC,fSize/fNumberOfWordsPerFEM);
00264 
00265       fAMUcells = new cells[fSize/fNumberOfWordsPerFEM];
00266 
00267       /* We fill the fAMUcells structures. You may ask why
00268          we do this strange yo-yo between "struct cells" and
00269          plain Byte_t arrays... The answer is : to allow
00270          the RawDataObject to point directly to arrays that are
00271          created by other object (EMCalFEE in this case), i.e.
00272          it is the responsability of the RDO to adapt to EMCalFEE,
00273          and not the other way around...
00274        */
00275       for ( i = 0; i < fSize/fNumberOfWordsPerFEM; i++ ) {
00276         fAMUcells[i].pre  = fAMUPre[i];
00277         fAMUcells[i].post = fAMUPost[i];
00278         fAMUcells[i].tac  = fAMUTAC[i];
00279       }
00280 
00281       delete[] fAMUPre;
00282       delete[] fAMUPost;
00283       delete[] fAMUTAC;
00284 
00285       /* FIXME: this is weird, and should be changed in some way...
00286          We hereby try to reconstruct the fDataMap, assuming that
00287          the emcRawDataAccessor has already been properly set up (i.e.
00288          with the same configuration file that was used to store this
00289          object...) : this is probably a dangerous assumption, but I
00290          don't know how to do it otherwise. 
00291        */
00292       
00293    } else {
00294      
00295       R__b.WriteVersion(emcRawDataObject::IsA());
00296 
00297       emcDataObject::Streamer(R__b);
00298 
00299       R__b << fNumberOfWordsPerFEM;
00300 
00301       R__b.WriteFastArray(fTAC, fSize);
00302       R__b.WriteFastArray(fHGPost, fSize);
00303       R__b.WriteFastArray(fLGPost, fSize);
00304       R__b.WriteFastArray(fHGPre, fSize);
00305       R__b.WriteFastArray(fLGPre, fSize);
00306 
00307       Byte_t* fAMUPre = new Byte_t[fSize/fNumberOfWordsPerFEM];
00308       Byte_t* fAMUPost = new Byte_t[fSize/fNumberOfWordsPerFEM];
00309       Byte_t* fAMUTAC = new Byte_t[fSize/fNumberOfWordsPerFEM];
00310 
00311       for ( i = 0; i < fSize/fNumberOfWordsPerFEM; i++ ) {
00312         fAMUPre[i] = fAMUcells[i].pre;
00313         fAMUPost[i] = fAMUcells[i].post;
00314         fAMUTAC[i] = fAMUcells[i].tac;
00315       }
00316 
00317       R__b.WriteFastArray(fAMUPre, fSize/fNumberOfWordsPerFEM);
00318       R__b.WriteFastArray(fAMUPost, fSize/fNumberOfWordsPerFEM);
00319       R__b.WriteFastArray(fAMUTAC, fSize/fNumberOfWordsPerFEM);
00320 
00321       delete[] fAMUPre;
00322       delete[] fAMUPost;
00323       delete[] fAMUTAC;
00324    }
00325 }
00326 
00327 //_____________________________________________________________________________
00328 ostream& operator << (ostream& out, const emcRawDataObject& rdo) 
00329 {
00330   if ( rdo.fDataMap ) {
00331     int i;
00332     int counter = 0; 
00333     const char* head = " Tower :      TAC HGPost LGPost  HGPre  LGPre (amupre/post/tac) ERR";
00334     out << head << endl;
00335     out << dec;
00336     TString ans; 
00337     for (i = 0; i < rdo.GetSize(); i++) {
00338     counter++; 
00339     if ( counter == 30 ) {
00340       counter = 0; 
00341       cout << "S(top) or C(ontinue) ?  ";
00342       cin >> ans; 
00343       cout << endl; 
00344       if ( ans == "s" || ans == "S" ) 
00345         break; 
00346       out << head << endl;
00347    }
00348       out << "#" << rdo.fDataMap[i] << " : " 
00349           << rdo.fTAC[i]<<" "
00350           << rdo.fHGPost[i]<<" "
00351           << rdo.fLGPost[i]<<" "
00352           << rdo.fHGPre[i]<<" "
00353           << rdo.fLGPre[i]<<" "
00354           << " (" << rdo.GetAMUPre(i)
00355           << "/"  << rdo.GetAMUPost(i)
00356           << "/"  << rdo.GetAMUTAC(i)
00357           << ") " 
00358           << "       |"  << hex << rdo.GetDataError(i) << dec 
00359           << endl;
00360     }
00361   }
00362   return out;
00363 }
00364 
00365 
00366