V172X_Event.cc

00001 #include "V172X_Event.hh"
00002 #include "Message.hh"
00003 #include <bitset>
00004 
00005 V172X_BoardData::V172X_BoardData(const unsigned char* const raw_data) : 
00006   event_size( *((uint32_t*)raw_data) & 0x0FFFFFFF),//32-bit words
00007   channel_mask( *((uint8_t*)(raw_data+4)) ),
00008   pattern( *((uint16_t*)(raw_data+5)) ),
00009   zle_enabled( *(raw_data+7) & 1),
00010   board_id( (*((uint8_t*)(raw_data+7))) >>3 ),
00011   event_counter( *((uint32_t*)(raw_data+8)) ),
00012   timestamp( *((uint32_t*)(raw_data+12)) & 0x7FFFFFFF ) 
00013 {
00014   /*
00015   std::cerr<<std::hex;
00016   for(uint32_t word=0; word < 100; word++){
00017   std::cerr<<*((uint32_t*)(raw_data) + word)<<std::endl;
00018   }
00019   std::cerr<<std::dec;
00020   */
00021   std::fill_n(channel_start,nchans,(char*)0);
00022   std::fill_n(channel_end,nchans,(char*)0);
00023   
00024   std::bitset<8> enabled_chans(channel_mask);
00025   
00026   int bytes_per_chan = 0;
00027   if(enabled_chans.count()) 
00028     bytes_per_chan = (event_size*4 - 16) / enabled_chans.count();
00029   int offset = 16;
00030   for(int i=0; i<nchans; i++){
00031     if(!enabled_chans[i])
00032       continue;
00033     channel_start[i] = (char*)(raw_data + offset);
00034     
00035     if(!zle_enabled)
00036       offset += bytes_per_chan;
00037     else
00038       offset += 4 * *((uint32_t*)(channel_start[i]));
00039     
00040     channel_end[i] = (char*)(raw_data + offset);
00041     
00042   }
00043 }
00044 V172X_BoardData::~V172X_BoardData()
00045 {}
00046 
00047 
00048 /*V172X_Event::V172X_Event(RawEventPtr base_event, V172X_Params* params) : 
00049   _base(base_event), _params(params)
00050 {
00051   if(_base){
00052     //For now, we'll assume no ZLE
00053     unsigned int offset = 0;
00054     while(offset < _base->GetDataSize() - _base->GetHeaderSize()){
00055       V172X_BoardData board(_base->GetRawBufferAfterHeader()+offset);
00056       offset += board.event_size*4;
00057       _boards.push_back(board);
00058     }   
00059   }
00060 }
00061 */
00062 
00063 V172X_Event::V172X_Event(const unsigned char* raw_buffer, 
00064                          const unsigned int size, V172X_Params* params) :
00065   _buffer(raw_buffer), _size(size), _params(params)
00066 {
00067   if(_buffer){
00068     //for now, assume no ZLE
00069     unsigned int offset = 0;
00070     while(offset < size){
00071       V172X_BoardData board(_buffer+offset);
00072       offset +=board.event_size*4;
00073       _boards.push_back(board);
00074     }
00075   }
00076 }
00077 
00078 V172X_Event::~V172X_Event() 
00079 {}
00080 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 20 Jun 2014 for daqman by  doxygen 1.6.1