RawEvent.cc

00001 #include "RawEvent.hh"
00002 #include "Message.hh"
00003 #include <time.h>
00004 
00005 //initialize all the statics
00006 long RawEvent::_total_buffer_size = 0;
00007 uint32_t RawEvent::_event_count = 0;
00008 
00009 RawEvent::RawEvent(bool increment_id_counter) 
00010 {
00011   _event_id = _event_count++;
00012   _timestamp = (uint32_t)(time(0));
00013   _run_id = -1;
00014   _buffer_size = 0;
00015 }
00016 
00017 RawEvent::RawEvent(uint32_t event_id, uint32_t timestamp, uint32_t run_id) : 
00018   _event_id(event_id), _timestamp(timestamp), _run_id(run_id)
00019 {
00020   _buffer_size = 0;
00021 }
00022   
00023 RawEvent::~RawEvent()
00024 {
00025   _total_buffer_size -= _buffer_size;
00026 }
00027 
00028 int RawEvent::AddDataBlock(uint32_t blocktype, uint32_t datasize)
00029 {
00030   _datablocks.push_back(datablock(blocktype, datasize));
00031   _buffer_size += datasize;
00032   _total_buffer_size += datasize;
00033   return _datablocks.size() - 1;  
00034 }
00035 
00036 int RawEvent::RemoveDataBlock(size_t block_n)
00037 {
00038   if(block_n >= _datablocks.size())
00039     return -1;
00040   uint32_t blocksize = _datablocks[block_n].data.size();
00041   _datablocks.erase(_datablocks.begin()+block_n);
00042   _buffer_size -= blocksize;
00043   _total_buffer_size -= blocksize;
00044   return 0;
00045 }
00046 
00047 const RawEvent::datablock* RawEvent::GetDataBlock(size_t block_n) const
00048 {
00049   return &(_datablocks.at(block_n));
00050 }
00051 
00052 unsigned char* RawEvent::GetRawDataBlock(size_t block_n) 
00053 {
00054   return &(_datablocks.at(block_n).data[0]);
00055 }
00056 
00057 uint32_t RawEvent::GetDataBlockSize(size_t block_n) const
00058 {
00059   return _datablocks.at(block_n).datasize;
00060 }
00061 
00062 int RawEvent::SetDataBlockSize(size_t block_n, uint32_t newsize)
00063 {
00064   if(block_n >= _datablocks.size()) 
00065     return -1;
00066   datablock& block = _datablocks[block_n];
00067   uint32_t bufsize = block.data.size();
00068   // expand the buffer if we need to, but don't bother shrinking
00069   if(newsize > bufsize){
00070     block.data.resize(newsize);
00071     _buffer_size += newsize-bufsize;
00072     _total_buffer_size += newsize-bufsize;
00073   }
00074   block.datasize = newsize;
00075   return 0;
00076 }
00077   
00078 uint32_t RawEvent::GetDataBlockType(size_t block_n) const
00079 {
00080   return _datablocks.at(block_n).type;
00081 }
00082 
00083 int RawEvent::SetDataBlockType(size_t block_n, uint32_t newtype)
00084 {
00085   if(block_n >= _datablocks.size())
00086     return -1;
00087   _datablocks[block_n].type = newtype;
00088   return 0;
00089 }
00090   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 20 Jun 2014 for daqman by  doxygen 1.6.1