dEmcRespParWrapper.C

Go to the documentation of this file.
00001 //INCLUDECHECKER: Removed this line: #include <cstdlib>
00002 #include "dEmcRespParWrapper.h"
00003 
00004 ClassImp(dEmcRespParWrapper)
00005 
00006 dEmcRespParWrapper::dEmcRespParWrapper(const char* name, const size_t& max_rows)
00007   : PHTable(name,max_rows)
00008 {
00009   size_t rowSize = sizeof(DEMCRESPPAR_ST);
00010   if (max_rows > 0) { // Avoid allocating a space of zero size!
00011      fTableData = new DEMCRESPPAR_ST[max_rows];
00012      SetMaxRowCount(max_rows);
00013   }
00014   else {
00015      fTableData = new DEMCRESPPAR_ST[1];
00016      SetMaxRowCount(1);
00017   }
00018 
00019   SetRowSize(rowSize);
00020   SetType("dEmcRespPar");
00021   fTableHeader->dsl_pointer  = (long)this;
00022   fTableHeader->data_pointer = (long)fTableData;
00023 }
00024 
00025 dEmcRespParWrapper::~dEmcRespParWrapper()
00026 {
00027   delete [] fTableData;
00028 }
00029 
00030 void*
00031 dEmcRespParWrapper::RawTableData()
00032 {
00033   return static_cast<void*>(fTableData);
00034 }
00035 
00036 DEMCRESPPAR_ST*
00037 dEmcRespParWrapper::TableData()
00038 {
00039   return fTableData;
00040 }
00041 
00042 DEMCRESPPAR_ST&
00043 dEmcRespParWrapper::operator[](const size_t& row)
00044 {
00045   return fTableData[row];
00046 }
00047 
00048 const DEMCRESPPAR_ST&
00049 dEmcRespParWrapper::operator[](const size_t& row) const
00050 {
00051   return fTableData[row];
00052 }
00053 
00054 void
00055 dEmcRespParWrapper::SetMaxRowCount(const size_t& max_rows)
00056 {
00057   // Avoid reallocing a space of zero size!
00058   if (max_rows <= 0) {
00059      return;
00060   }
00061 
00062   // Ensure that the current row count is not out of range.
00063   if (fTableHeader->nok > max_rows) {
00064      fTableHeader->nok = max_rows;
00065   }
00066 
00067   // If table needs to grow, allocate a new area for it.
00068   if (max_rows > fTableHeader->maxlen) {
00069      DEMCRESPPAR_ST* newData = new DEMCRESPPAR_ST[max_rows];
00070      if (fTableData) {
00071         for (long i = 0; i < fTableHeader->nok; i++) {
00072            newData[i] = fTableData[i];
00073         }
00074         delete [] fTableData;
00075      }
00076      fTableData = newData;
00077      fTableHeader->data_pointer = (long)fTableData;
00078   }
00079 
00080   fTableHeader->maxlen = max_rows;
00081 }
00082 void
00083 dEmcRespParWrapper::SetRowCount(const size_t& n)
00084 {
00085   if (n > fTableHeader->maxlen) {
00086      fTableHeader->nok = fTableHeader->maxlen;
00087   }
00088   else if (n >= 0) {
00089      fTableHeader->nok = n;
00090   }
00091 }
00092 
00093 void
00094 dEmcRespParWrapper::SetRowSize(const size_t& row_size)
00095 {
00096   if (row_size > 0) {
00097      fTableHeader->rbytes = row_size;
00098   }
00099 }
00100 
00101 void
00102 dEmcRespParWrapper::Streamer(TBuffer& b)
00103 {
00104    // Stream an object of class dEmcRespParWrapper.
00105    // What should be done on output if the table is empty?
00106 
00107    if (b.IsReading()) {
00108      Version_t v = b.ReadVersion();
00109      PHTable::Streamer(b);         // Read the table header.
00110      if (RowSize() != sizeof(DEMCRESPPAR_ST)) {
00111        // Sanity check failed.  Need some error message here.
00112        return;
00113      }
00114 
00115            // Reallocate the table explicitly here; the size of the data array
00116            // may be inconsistent with the max. row count variable in the header
00117            // (since the ROOT I/O default-constructs the former, and reads
00118            // the header for the latter).
00119            size_t max_rows = MaxRowCount();
00120            if (max_rows <= 0) { // Avoid allocating a space of zero size!
00121               max_rows = 1;
00122            }
00123 
00124            delete [] fTableData;
00125            fTableData = new DEMCRESPPAR_ST[max_rows];
00126            fTableHeader->data_pointer = (long)fTableData;
00127 
00128      SetMaxRowCount(max_rows);
00129      SetType("dEmcRespParWrapper");
00130 
00131      for (long i=0; i<RowCount(); i++) {
00132         b >> fTableData[i].anyset;
00133         b >> fTableData[i].sim_timing;
00134         b >> fTableData[i].pbgl_response;
00135      }
00136    }
00137    else {
00138      b.WriteVersion(IsA());
00139      PHTable::Streamer(b);         // Write the table header.
00140      for (long i=0; i<RowCount(); i++) {
00141         b << fTableData[i].anyset;
00142         b << fTableData[i].sim_timing;
00143         b << fTableData[i].pbgl_response;
00144      }
00145    }
00146 
00147 }
00148 /* Automatically generated.  Do not edit. */