dEmcClusterLocalExtWrapper.C

Go to the documentation of this file.
00001 //INCLUDECHECKER: Removed this line: #include <cstdlib>
00002 #include <iostream> // MV 2001/12/12
00003 #include "emcDefines.h" // MV 2001/12/12
00004 #include "dEmcClusterLocalExtWrapper.h"
00005 
00006 ClassImp(dEmcClusterLocalExtWrapper);
00007 
00008 using namespace std;
00009 
00010 dEmcClusterLocalExtWrapper::dEmcClusterLocalExtWrapper(const char* name, const size_t& max_rows)
00011   : PHTable(name,max_rows)
00012 {
00013   size_t rowSize = sizeof(DEMCCLUSTERLOCALEXT_ST);
00014   if (max_rows > 0) { // Avoid allocating a space of zero size!
00015      fTableData = new DEMCCLUSTERLOCALEXT_ST[max_rows];
00016      SetMaxRowCount(max_rows);
00017   }
00018   else {
00019      fTableData = new DEMCCLUSTERLOCALEXT_ST[1];
00020      SetMaxRowCount(1);
00021   }
00022 
00023   SetRowSize(rowSize);
00024   SetType("dEmcClusterLocalExt");
00025   fTableHeader->dsl_pointer  = (long)this;
00026   fTableHeader->data_pointer = (long)fTableData;
00027 }
00028 
00029 dEmcClusterLocalExtWrapper::~dEmcClusterLocalExtWrapper()
00030 {
00031   delete [] fTableData;
00032 }
00033 
00034 void*
00035 dEmcClusterLocalExtWrapper::RawTableData()
00036 {
00037   return static_cast<void*>(fTableData);
00038 }
00039 
00040 DEMCCLUSTERLOCALEXT_ST*
00041 dEmcClusterLocalExtWrapper::TableData()
00042 {
00043   return fTableData;
00044 }
00045 
00046 DEMCCLUSTERLOCALEXT_ST&
00047 dEmcClusterLocalExtWrapper::operator[](const size_t& row)
00048 {
00049   return fTableData[row];
00050 }
00051 
00052 const DEMCCLUSTERLOCALEXT_ST&
00053 dEmcClusterLocalExtWrapper::operator[](const size_t& row) const
00054 {
00055   return fTableData[row];
00056 }
00057 
00058 void
00059 dEmcClusterLocalExtWrapper::SetMaxRowCount(const size_t& max_rows)
00060 {
00061   // Avoid reallocing a space of zero size!
00062   if (max_rows <= 0) {
00063      return;
00064   }
00065 
00066   // Ensure that the current row count is not out of range.
00067   if (fTableHeader->nok > max_rows) {
00068      fTableHeader->nok = max_rows;
00069   }
00070 
00071   // If table needs to grow, allocate a new area for it.
00072   if (max_rows > fTableHeader->maxlen) {
00073      DEMCCLUSTERLOCALEXT_ST* newData = new DEMCCLUSTERLOCALEXT_ST[max_rows];
00074      if (fTableData) {
00075         for (long i = 0; i < fTableHeader->nok; i++) {
00076            newData[i] = fTableData[i];
00077         }
00078         delete [] fTableData;
00079      }
00080      fTableData = newData;
00081      fTableHeader->data_pointer = (long)fTableData;
00082   }
00083 
00084   fTableHeader->maxlen = max_rows;
00085 }
00086 void
00087 dEmcClusterLocalExtWrapper::SetRowCount(const size_t& n)
00088 {
00089   if (n > fTableHeader->maxlen) {
00090      fTableHeader->nok = fTableHeader->maxlen;
00091   }
00092   else if (n >= 0) {
00093      fTableHeader->nok = n;
00094   }
00095 }
00096 
00097 void
00098 dEmcClusterLocalExtWrapper::SetRowSize(const size_t& row_size)
00099 {
00100   if (row_size > 0) {
00101      fTableHeader->rbytes = row_size;
00102   }
00103 }
00104 
00105 void
00106 dEmcClusterLocalExtWrapper::Streamer(TBuffer &R__b)
00107 {
00108   // MV 2001/12/12 Incremented dEmcClusterLocalExtWrapper version number
00109   // 1 -> 2
00110 
00111   // Stream an object of class dEmcClusterLocalExtWrapper.
00112   // What should be done on output if the table is empty?
00113   
00114   if(R__b.IsReading()){
00115 
00116     static bool first=true;
00117 
00118     Version_t R__v=R__b.ReadVersion();
00119     PHTable::Streamer(R__b);         // Read the table header.
00120 
00121     // MV 2001/12/12 we don't need this check
00122     //    if (RowSize() != sizeof(DEMCCLUSTERLOCALEXT_ST)) {
00123     // Sanity check failed.  Need some error message here.
00124     //      return;
00125     //    }
00126     
00127     // Reallocate the table explicitly here; the size of the data array
00128     // may be inconsistent with the max. row count variable in the header
00129     // (since the ROOT I/O default-constructs the former, and reads
00130     // the header for the latter).
00131     size_t max_rows = MaxRowCount();
00132     if (max_rows <= 0) { // Avoid allocating a space of zero size!
00133       max_rows = 1;
00134     }
00135     
00136     delete [] fTableData;
00137     fTableData = new DEMCCLUSTERLOCALEXT_ST[max_rows];
00138     fTableHeader->data_pointer = (long)fTableData;
00139     
00140     SetMaxRowCount(max_rows);
00141     SetType("dEmcClusterLocalExtWrapper");
00142     
00143     for(long i=0; i<RowCount(); i++){
00144 
00145       R__b>>fTableData[i].id;
00146       R__b>>fTableData[i].runno;
00147       R__b>>fTableData[i].evno;
00148       R__b>>fTableData[i].clusno;
00149       R__b>>fTableData[i].method;
00150       R__b>>fTableData[i].type;
00151       R__b>>fTableData[i].arm;
00152       R__b>>fTableData[i].sector;
00153       R__b.ReadStaticArray(fTableData[i].xyz);
00154       R__b.ReadStaticArray(fTableData[i].dxyz);
00155       R__b>>fTableData[i].e;
00156       R__b>>fTableData[i].ecore;
00157       R__b>>fTableData[i].ecorr;
00158       R__b>>fTableData[i].de;
00159       R__b>>fTableData[i].tof;
00160       R__b>>fTableData[i].ecent;
00161       R__b>>fTableData[i].tofcorr;
00162       R__b>>fTableData[i].dtof;
00163       R__b>>fTableData[i].qual;
00164       
00165       // MV 2001/12/12
00166       if(R__v>1){
00167 
00168         R__b>>fTableData[i].deadmap;
00169         R__b>>fTableData[i].warnmap;
00170 
00171       } else{
00172         
00173         fTableData[i].deadmap=0;
00174         fTableData[i].warnmap=0;
00175 
00176         if(first){
00177 
00178         cerr<<EMC_INFO_MSG<<" dEmcClusterLocalExtWrapper::Streamer() "
00179             <<"backward compatibility mode: deadmap, warnmap contain 0"<<endl;
00180         first=false;
00181 
00182         }
00183       }
00184       
00185       R__b>>fTableData[i].pid;
00186       R__b>>fTableData[i].prob_photon;
00187       R__b>>fTableData[i].prob_neuhad;
00188       R__b>>fTableData[i].chi2;
00189       R__b>>fTableData[i].nsh;
00190       R__b>>fTableData[i].chi2_sh;
00191       R__b>>fTableData[i].prob_photon_sh;
00192       R__b.ReadStaticArray(fTableData[i].e_sh);
00193       R__b.ReadStaticArray(fTableData[i].ecorr_sh);
00194       R__b.ReadStaticArray(fTableData[i].de_sh);
00195       R__b.ReadStaticArray((float *)fTableData[i].xyz_sh);
00196       R__b.ReadStaticArray((float *)fTableData[i].dxyz_sh);
00197       R__b>>fTableData[i].theta;
00198       R__b>>fTableData[i].phi;
00199       R__b.ReadStaticArray(fTableData[i].unitv);
00200       R__b.ReadStaticArray(fTableData[i].ind);
00201       R__b>>fTableData[i].twrhit;
00202       R__b>>fTableData[i].tofmin;
00203       R__b>>fTableData[i].etofmin;
00204       R__b>>fTableData[i].tofmincorr;
00205       R__b>>fTableData[i].tofmax;
00206       R__b>>fTableData[i].etofmax;
00207       R__b>>fTableData[i].tofmaxcorr;
00208       R__b>>fTableData[i].tofmean;
00209       R__b.ReadStaticArray(fTableData[i].disp);
00210       R__b.ReadStaticArray(fTableData[i].padisp);
00211       R__b.ReadStaticArray(fTableData[i].partesum);
00212       R__b.ReadStaticArray(fTableData[i].twrlist);
00213       R__b>>fTableData[i].e9;
00214       R__b>>fTableData[i].re9;
00215       R__b.ReadStaticArray(fTableData[i].yz_cg);
00216 
00217     }
00218   } else{
00219 
00220     R__b.WriteVersion(IsA());
00221     PHTable::Streamer(R__b);         // Write the table header.
00222 
00223     for(long i=0; i<RowCount(); i++){
00224 
00225       R__b<<fTableData[i].id;
00226       R__b<<fTableData[i].runno;
00227       R__b<<fTableData[i].evno;
00228       R__b<<fTableData[i].clusno;
00229       R__b<<fTableData[i].method;
00230       R__b<<fTableData[i].type;
00231       R__b<<fTableData[i].arm;
00232       R__b<<fTableData[i].sector;
00233       R__b.WriteArray(fTableData[i].xyz,3);
00234       R__b.WriteArray(fTableData[i].dxyz,3);
00235       R__b<<fTableData[i].e;
00236       R__b<<fTableData[i].ecore;
00237       R__b<<fTableData[i].ecorr;
00238       R__b<<fTableData[i].de;
00239       R__b<<fTableData[i].tof;
00240       R__b<<fTableData[i].ecent;
00241       R__b<<fTableData[i].tofcorr;
00242       R__b<<fTableData[i].dtof;
00243       R__b<<fTableData[i].qual;
00244       
00245       // MV 2001/12/06
00246       R__b<<fTableData[i].deadmap;
00247       R__b<<fTableData[i].warnmap;
00248       
00249       R__b<<fTableData[i].pid;
00250       R__b<<fTableData[i].prob_photon;
00251       R__b<<fTableData[i].prob_neuhad;
00252       R__b<<fTableData[i].chi2;
00253       R__b<<fTableData[i].nsh;
00254       R__b<<fTableData[i].chi2_sh;
00255       R__b<<fTableData[i].prob_photon_sh;
00256       R__b.WriteArray(fTableData[i].e_sh,2);
00257       R__b.WriteArray(fTableData[i].ecorr_sh,2);
00258       R__b.WriteArray(fTableData[i].de_sh,2);
00259       R__b.WriteArray((float *)fTableData[i].xyz_sh,6);
00260       R__b.WriteArray((float *)fTableData[i].dxyz_sh,6);
00261       R__b<<fTableData[i].theta;
00262       R__b<<fTableData[i].phi;
00263       R__b.WriteArray(fTableData[i].unitv,3);
00264       R__b.WriteArray(fTableData[i].ind,2);
00265       R__b<<fTableData[i].twrhit;
00266       R__b<<fTableData[i].tofmin;
00267       R__b<<fTableData[i].etofmin;
00268       R__b<<fTableData[i].tofmincorr;
00269       R__b<<fTableData[i].tofmax;
00270       R__b<<fTableData[i].etofmax;
00271       R__b<<fTableData[i].tofmaxcorr;
00272       R__b<<fTableData[i].tofmean;
00273       R__b.WriteArray(fTableData[i].disp,2);
00274       R__b.WriteArray(fTableData[i].padisp,2);
00275       R__b.WriteArray(fTableData[i].partesum,16);
00276       R__b.WriteArray(fTableData[i].twrlist,16);
00277       R__b<<fTableData[i].e9;
00278       R__b<<fTableData[i].re9;
00279       R__b.WriteArray(fTableData[i].yz_cg,2);
00280 
00281     }
00282   }
00283 }