dEmcCalibTowerWrapper.C

Go to the documentation of this file.
00001 //INCLUDECHECKER: Removed this line: #include <cstdlib>
00002 #include <iostream>
00003 #include "dEmcCalibTowerWrapper.h"
00004 #include <iostream>
00005 //INCLUDECHECKER: Removed this line: #include "TDirectory.h"
00006 //INCLUDECHECKER: Removed this line: #include "TDatime.h"
00007 #include "emcDefines.h"
00008 
00009 ClassImp(dEmcCalibTowerWrapper);
00010 
00011 using namespace std;
00012 
00013 dEmcCalibTowerWrapper::dEmcCalibTowerWrapper(const char* name, const size_t& max_rows)
00014   : PHTable(name,max_rows)
00015 {
00016   size_t rowSize = sizeof(DEMCCALIBTOWER_ST);
00017   if (max_rows > 0) { // Avoid allocating a space of zero size!
00018      fTableData = new DEMCCALIBTOWER_ST[max_rows];
00019      SetMaxRowCount(max_rows);
00020   }
00021   else {
00022      fTableData = new DEMCCALIBTOWER_ST[1];
00023      SetMaxRowCount(1);
00024   }
00025 
00026   SetRowSize(rowSize);
00027   SetType("dEmcCalibTower");
00028   fTableHeader->dsl_pointer  = (long)this;
00029   fTableHeader->data_pointer = (long)fTableData;
00030 }
00031 
00032 dEmcCalibTowerWrapper::~dEmcCalibTowerWrapper()
00033 {
00034   delete [] fTableData;
00035 }
00036 
00037 void*
00038 dEmcCalibTowerWrapper::RawTableData()
00039 {
00040   return static_cast<void*>(fTableData);
00041 }
00042 
00043 DEMCCALIBTOWER_ST*
00044 dEmcCalibTowerWrapper::TableData()
00045 {
00046   return fTableData;
00047 }
00048 
00049 DEMCCALIBTOWER_ST&
00050 dEmcCalibTowerWrapper::operator[](const size_t& row)
00051 {
00052   return fTableData[row];
00053 }
00054 
00055 const DEMCCALIBTOWER_ST&
00056 dEmcCalibTowerWrapper::operator[](const size_t& row) const
00057 {
00058   return fTableData[row];
00059 }
00060 
00061 void
00062 dEmcCalibTowerWrapper::SetMaxRowCount(const size_t& max_rows)
00063 {
00064   // Avoid reallocing a space of zero size!
00065   if (max_rows <= 0) {
00066      return;
00067   }
00068 
00069   // Ensure that the current row count is not out of range.
00070   if (fTableHeader->nok > max_rows) {
00071      fTableHeader->nok = max_rows;
00072   }
00073 
00074   // If table needs to grow, allocate a new area for it.
00075   if (max_rows > fTableHeader->maxlen) {
00076      DEMCCALIBTOWER_ST* newData = new DEMCCALIBTOWER_ST[max_rows];
00077      if (fTableData) {
00078         for (long i = 0; i < fTableHeader->nok; i++) {
00079            newData[i] = fTableData[i];
00080         }
00081         delete [] fTableData;
00082      }
00083      fTableData = newData;
00084      fTableHeader->data_pointer = (long)fTableData;
00085   }
00086 
00087   fTableHeader->maxlen = max_rows;
00088 }
00089 void
00090 dEmcCalibTowerWrapper::SetRowCount(const size_t& n)
00091 {
00092   if (n > fTableHeader->maxlen) {
00093      fTableHeader->nok = fTableHeader->maxlen;
00094   }
00095   else if (n >= 0) {
00096      fTableHeader->nok = n;
00097   }
00098 }
00099 
00100 void
00101 dEmcCalibTowerWrapper::SetRowSize(const size_t& row_size)
00102 {
00103   if (row_size > 0) {
00104      fTableHeader->rbytes = row_size;
00105   }
00106 }
00107 
00108 void
00109 dEmcCalibTowerWrapper::Streamer(TBuffer &R__b)
00110 {
00111   // MV 2001/12/11 Function significantly modified
00112 
00113   // Stream an object of class dEmcCalibTowerWrapper.
00114   // What should be done on output if the table is empty?
00115   
00116   if(R__b.IsReading()){
00117     
00118     Version_t R__v=R__b.ReadVersion();
00119     
00120     static bool first=true;
00121     
00122     PHTable::Streamer(R__b);         // Read the table header.
00123     
00124     // MV 2001/12/11 Now I understand that adding data members to the
00125     // DEMCCALIBTOWER_ST structure and not incrementing the class version
00126     // of dEmcCalibTowerWrapper was a big mistake.
00127     // So, we finally decided to increment the version number.
00128     // Distinguish between "subversions" of version 1 is tricky.
00129     // This can be done by looking at rowsize which gives us the number
00130     // of bytes in the DEMCCALIBTOWER_ST structure. It changed like this:
00131     // 32 bytes (version 1)
00132     // 36 bytes (version 1)
00133     // 44 bytes (version 1)
00134     // 48 bytes (version 2)
00135     
00136     size_t rowsize=RowSize();
00137     
00138     // Reallocate the table explicitly here; the size of the data array
00139     // may be inconsistent with the max. row count variable in the header
00140     // (since the ROOT I/O default-constructs the former, and reads
00141     // the header for the latter).
00142     size_t max_rows = MaxRowCount();
00143     if (max_rows <= 0) { // Avoid allocating a space of zero size!
00144       max_rows = 1;
00145     }
00146     
00147     delete [] fTableData;
00148     fTableData = new DEMCCALIBTOWER_ST[max_rows];
00149     fTableHeader->data_pointer = (long)fTableData;
00150     
00151     SetMaxRowCount(max_rows);
00152     SetType("dEmcCalibTowerWrapper");
00153     
00154     for(long i=0; i<RowCount(); i++){
00155       
00156       R__b>>fTableData[i].id;
00157       R__b>>fTableData[i].hwkey;
00158       R__b>>fTableData[i].swkey;
00159       R__b>>fTableData[i].type;
00160       R__b>>fTableData[i].arm;
00161       R__b>>fTableData[i].sector;
00162       R__b.ReadStaticArray(fTableData[i].ind);
00163       R__b>>fTableData[i].ecal;
00164       R__b>>fTableData[i].tof;
00165       
00166       if(R__v>1){
00167         
00168         R__b>>fTableData[i].deadmap;
00169         R__b>>fTableData[i].warnmap;
00170         R__b>>fTableData[i].adc;
00171         R__b>>fTableData[i].tac;
00172         
00173         
00174       } else if(R__v==1 && rowsize==44){
00175         
00176         R__b>>fTableData[i].deadmap;
00177         fTableData[i].warnmap=0;
00178         R__b>>fTableData[i].adc;
00179         R__b>>fTableData[i].tac;
00180         
00181         if(first==true){
00182           
00183           cerr<<EMC_INFO_MSG<<" dEmcCalibTowerWrapper::Streamer() "
00184               <<"backward compatibility mode: warnmap contains 0"<<endl;
00185           first=false;
00186           
00187         }
00188       } else if(R__v==1 && rowsize==36){
00189         
00190         R__b>>fTableData[i].deadmap;
00191         fTableData[i].warnmap=0;
00192         fTableData[i].adc=0.;
00193         fTableData[i].tac=0.;
00194         
00195         if(first==true){
00196           
00197           cerr<<EMC_INFO_MSG<<" dEmcCalibTowerWrapper::Streamer() "
00198               <<"backward compatibility mode: warnmap, adc, tdc contain 0"<<endl;
00199           first=false;
00200           
00201         }
00202       } else if(R__v==1 && rowsize==32){
00203         
00204         fTableData[i].deadmap=0;
00205         fTableData[i].warnmap=0;
00206         fTableData[i].adc=0.;
00207         fTableData[i].tac=0.;
00208 
00209         if(first==true){
00210 
00211         cerr<<EMC_INFO_MSG<<" dEmcCalibTowerWrapper::Streamer() "
00212             <<"backward compatibility mode: deadmap, warnmap, adc, tdc contain 0"<<endl;
00213         first=false;
00214 
00215         }
00216       } else{
00217         
00218         //=====> should never get here!!
00219         
00220         cerr<<EMC_ERROR_MSG<<" dEmcCalibTowerWrapper::Streamer():"
00221             <<" RowSize() does not match dEmcCalibTowerWrapper version."
00222             <<" Table will be empty."
00223             <<endl;
00224         SetRowCount(0) ;
00225         return;
00226         
00227       } // end checking class versions
00228     } // end loop on table rows
00229   } else{
00230     
00231     R__b.WriteVersion(IsA());
00232     PHTable::Streamer(R__b);         // Write the table header.
00233     
00234     for(long i=0; i<RowCount(); i++){
00235       
00236       R__b<<fTableData[i].id;
00237       R__b<<fTableData[i].hwkey;
00238       R__b<<fTableData[i].swkey;
00239       R__b<<fTableData[i].type;
00240       R__b<<fTableData[i].arm;
00241       R__b<<fTableData[i].sector;
00242       R__b.WriteArray(fTableData[i].ind,2);
00243       R__b<<fTableData[i].ecal;
00244       R__b<<fTableData[i].tof;
00245       R__b<<fTableData[i].deadmap;
00246       
00247       // MV 2001/12/04
00248       R__b<<fTableData[i].warnmap;
00249       
00250       // MV 2001/09/26
00251       R__b<<fTableData[i].adc;
00252       R__b<<fTableData[i].tac;
00253       
00254     } // end loop on table rows
00255   }
00256 }