Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:50

0001 #include "ospEvent.h"
0002 #include "EventTypes.h"
0003 
0004 #include <time.h>
0005 #include <string.h>
0006 
0007 // the constructor first ----------------
0008 ospEvent::ospEvent (PHDWORD * where, const int length
0009         , const int irun, const int etype, const int evtseq)
0010 {
0011   evthdr = ( oncsevtdata_ptr ) where;
0012   evthdr->evt_type = etype;
0013   max_length = length;
0014   prepare_next (evtseq, irun);
0015 }
0016 
0017 void ospEvent::set_event_type(const int etype)
0018 {
0019    evthdr->evt_type = etype;
0020 }
0021 
0022 int ospEvent::prepare_next()
0023 {
0024   // re-initialize the event header length
0025   evthdr->evt_length =  EVTHEADERLENGTH;
0026 
0027   // if < 0, just increment the current seq. number
0028   evthdr->evt_sequence++;
0029 
0030   // reset the current data index, and the leftover counter
0031   current = 0;
0032   left=max_length - EVTHEADERLENGTH ;
0033   evthdr->date = time(0);
0034   evthdr->time = 0;
0035 
0036   return 0;
0037 
0038 }
0039 
0040 int ospEvent::prepare_next( const int evtseq 
0041               , const int irun )
0042 {
0043   // re-initialize the event header length
0044   evthdr->evt_length =  EVTHEADERLENGTH;
0045 
0046   // if < 0, just increment the current seq. number
0047 
0048   evthdr->evt_sequence = evtseq;
0049 
0050   // if > 0, adjust the run number, else just keep it.
0051   evthdr->run_number=irun;
0052   
0053   // reset the current data index, and the leftover counter
0054   current = 0;
0055   left=max_length - EVTHEADERLENGTH ;
0056   evthdr->date = time(0);
0057   evthdr->time = 0;
0058 
0059   return 0;
0060 }
0061 
0062 int  ospEvent::addPacket( const Packet *p)
0063 {
0064 
0065   int* packetstart;
0066   int packetlength  = p->getLength(); 
0067 
0068   
0069   packetstart = &(evthdr->data[current]);
0070 
0071   p->copyMe( (int *)packetstart, packetlength );
0072 
0073   if (packetlength >0)  
0074     { 
0075       evthdr->evt_length += packetlength;
0076       current +=  packetlength;
0077       left -= packetlength;
0078       return packetlength;
0079     }
0080   else return  -1;
0081 }
0082 
0083 
0084 
0085 int  ospEvent::addUnstructPacketData(PHDWORD * data, 
0086             const int length,
0087             const int id,
0088             const int wordsize,
0089             const int hitformat)
0090 {
0091 
0092 //  int* packetstart;
0093   
0094   subevtdata_ptr sevt =  (subevtdata_ptr) &(evthdr->data[current]);
0095   sevt->sub_length =  SEVTHEADERLENGTH;
0096   sevt->sub_id = id;
0097   sevt->sub_type=wordsize;
0098   sevt->sub_decoding = hitformat;
0099   sevt->reserved[0] = 0;
0100   sevt->reserved[1] = 0;
0101   
0102   memcpy(&sevt->data , data, length * sizeof (int) );
0103   sevt->sub_length += length;
0104   
0105   evthdr->evt_length +=  sevt->sub_length;
0106   current +=  sevt->sub_length;
0107   left -=  sevt->sub_length;
0108   return  sevt->sub_length;
0109 
0110 }
0111