Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-02 08:21:01

0001  
0002 
0003 #include <iostream>
0004 
0005 #include <daq_device_deadtime.h>
0006 
0007 using namespace std;
0008 
0009 daq_device_deadtime::daq_device_deadtime(const int eventtype
0010     , const int subeventid
0011     , const int n_ticks
0012     , const int n_words
0013     , const int trigger_enabled)
0014 {
0015 
0016   m_eventType  = eventtype;
0017   m_subeventid = subeventid;
0018   number_of_ticks = n_ticks;
0019   number_of_words = n_words;
0020   if (trigger_enabled) 
0021     {
0022       th = new pulserTriggerHandler(m_eventType);
0023       registerTriggerHandler(th);
0024     }
0025   else
0026     {
0027       th = 0;
0028     }
0029 }
0030 
0031 daq_device_deadtime::~daq_device_deadtime()
0032 {
0033   if ( th) 
0034     {
0035       clearTriggerHandler();
0036       delete th;
0037     }
0038 }
0039 
0040 
0041 
0042 // the put_data function
0043 
0044 int daq_device_deadtime::put_data(const int etype, int * adr, const int length )
0045 {
0046 
0047 
0048   if (etype != m_eventType )  // not our id
0049     {
0050       return 0;
0051     }
0052 
0053   if ( number_of_ticks) usleep ( number_of_ticks);
0054   
0055   if ( number_of_words) 
0056     {
0057 
0058       if ( daq_getEventFormat() ) // we are writing PRDF
0059     {
0060       formatPacketHdr(adr);
0061 
0062       packetdata_ptr sevt =  (packetdata_ptr) adr;
0063       
0064       // update id's etc
0065       sevt->sub_id =  m_subeventid;
0066       sevt->sub_type=4;
0067       sevt->sub_decoding = 30000 + ID4EVT;
0068       
0069       int padding = number_of_words%2;
0070       sevt->structureinfo += padding;
0071       sevt->sub_length += number_of_words + padding;
0072       return  sevt->sub_length;
0073     }
0074       else
0075     {
0076       sevt =  (subevtdata_ptr) adr;
0077       // set the initial subevent length
0078       sevt->sub_length =  SEVTHEADERLENGTH;
0079       
0080       // update id's etc
0081       sevt->sub_id =  m_subeventid;
0082       sevt->sub_type=4;
0083       sevt->sub_decoding = ID4EVT;
0084       sevt->reserved[0] = 0;
0085       sevt->reserved[1] = 0;
0086       
0087       sevt->sub_padding = number_of_words%2;
0088       sevt->sub_length += number_of_words + sevt->sub_padding;
0089       return  sevt->sub_length;
0090     }
0091     }
0092   return  0;
0093 }
0094 
0095 
0096 void daq_device_deadtime::identify(std::ostream& os) const
0097 {
0098   
0099   os  << "Deadtime Device  Event Type: " << m_eventType
0100       << " n_ticks: " << number_of_ticks << " n_words: " << number_of_words;
0101 
0102     if (th) 
0103       {
0104     os << " ** Trigger enabled";
0105       }
0106 
0107   os << endl;
0108 
0109 }
0110 
0111 int daq_device_deadtime::max_length(const int etype) const
0112 {
0113   if (etype != m_eventType) return 0;
0114 
0115   if ( number_of_words)
0116     {
0117       return SEVTHEADERLENGTH + number_of_words +2;
0118     }
0119 
0120   return 0;
0121 }
0122 
0123 int  daq_device_deadtime::init()
0124 {
0125 
0126   return 0;
0127 }
0128 
0129 // the rearm() function
0130 int  daq_device_deadtime::rearm(const int etype)
0131 {
0132   return 0;
0133 }
0134