dEmcEventWrapper.C

Go to the documentation of this file.
00001 //INCLUDECHECKER: Removed this line: #include <cstdlib>
00002 #include "dEmcEventWrapper.h"
00003 
00004 ClassImp(dEmcEventWrapper)
00005 
00006 dEmcEventWrapper::dEmcEventWrapper(const char* name, const size_t& max_rows)
00007   : PHTable(name,max_rows)
00008 {
00009   size_t rowSize = sizeof(DEMCEVENT_ST);
00010   if (max_rows > 0) { // Avoid allocating a space of zero size!
00011      fTableData = new DEMCEVENT_ST[max_rows];
00012      SetMaxRowCount(max_rows);
00013   }
00014   else {
00015      fTableData = new DEMCEVENT_ST[1];
00016      SetMaxRowCount(1);
00017   }
00018 
00019   SetRowSize(rowSize);
00020   SetType("dEmcEvent");
00021   fTableHeader->dsl_pointer  = (long)this;
00022   fTableHeader->data_pointer = (long)fTableData;
00023 }
00024 
00025 dEmcEventWrapper::~dEmcEventWrapper()
00026 {
00027   delete [] fTableData;
00028 }
00029 
00030 void*
00031 dEmcEventWrapper::RawTableData()
00032 {
00033   return static_cast<void*>(fTableData);
00034 }
00035 
00036 DEMCEVENT_ST*
00037 dEmcEventWrapper::TableData()
00038 {
00039   return fTableData;
00040 }
00041 
00042 DEMCEVENT_ST&
00043 dEmcEventWrapper::operator[](const size_t& row)
00044 {
00045   return fTableData[row];
00046 }
00047 
00048 const DEMCEVENT_ST&
00049 dEmcEventWrapper::operator[](const size_t& row) const
00050 {
00051   return fTableData[row];
00052 }
00053 
00054 void
00055 dEmcEventWrapper::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      DEMCEVENT_ST* newData = new DEMCEVENT_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 dEmcEventWrapper::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 dEmcEventWrapper::SetRowSize(const size_t& row_size)
00095 {
00096   if (row_size > 0) {
00097      fTableHeader->rbytes = row_size;
00098   }
00099 }
00100 
00101 void
00102 dEmcEventWrapper::Streamer(TBuffer& b)
00103 {
00104    // Stream an object of class dEmcEventWrapper.
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(DEMCEVENT_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 DEMCEVENT_ST[max_rows];
00126            fTableHeader->data_pointer = (long)fTableData;
00127 
00128      SetMaxRowCount(max_rows);
00129      SetType("dEmcEventWrapper");
00130 
00131      for (long i=0; i<RowCount(); i++) {
00132         b >> fTableData[i].id;
00133         b >> fTableData[i].evtyp;
00134         b >> fTableData[i].evno;
00135         b >> fTableData[i].runno;
00136         b >> fTableData[i].serialno;
00137         b >> fTableData[i].impact;
00138         b.ReadStaticArray(fTableData[i].xyz);
00139         b >> fTableData[i].twrmultlo;
00140         b >> fTableData[i].twrmulthi;
00141         b >> fTableData[i].tote;
00142         b >> fTableData[i].totet;
00143         b.ReadStaticArray(fTableData[i].trigsum);
00144         b.ReadStaticArray(fTableData[i].sece);
00145         b.ReadStaticArray(fTableData[i].secet);
00146      }
00147    }
00148    else {
00149      b.WriteVersion(IsA());
00150      PHTable::Streamer(b);         // Write the table header.
00151      for (long i=0; i<RowCount(); i++) {
00152         b << fTableData[i].id;
00153         b << fTableData[i].evtyp;
00154         b << fTableData[i].evno;
00155         b << fTableData[i].runno;
00156         b << fTableData[i].serialno;
00157         b << fTableData[i].impact;
00158         b.WriteArray(fTableData[i].xyz,3);
00159         b << fTableData[i].twrmultlo;
00160         b << fTableData[i].twrmulthi;
00161         b << fTableData[i].tote;
00162         b << fTableData[i].totet;
00163         b.WriteArray(fTableData[i].trigsum,3);
00164         b.WriteArray(fTableData[i].sece,8);
00165         b.WriteArray(fTableData[i].secet,8);
00166      }
00167    }
00168 
00169 }
00170 /* Automatically generated.  Do not edit. */