Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
daq_device_rtclock.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file daq_device_rtclock.cc
1 
2 
3 #include <iostream>
4 #include <string.h>
5 
6 #include <daq_device_rtclock.h>
7 
8 using namespace std;
9 
11  , const int subeventid
12  , const int n_what)
13 {
14 
15  m_eventType = eventtype;
16  m_subeventid = subeventid;
17 }
18 
20 {
21 }
22 
23 
24 
25 // the put_data function
26 
27 int daq_device_rtclock::put_data(const int etype, int * adr, const int length )
28 {
29 
30  if (etype != m_eventType ) // not our id
31  {
32  return 0;
33  }
34 
35 
36  struct timespec clk;
37 
38 
39  if ( daq_getEventFormat() ) // we are writing PRDF
40  {
41 
42  formatPacketHdr(adr);
43  packetdata_ptr sevt = (packetdata_ptr) adr;
44  // update id's etc
45  sevt->sub_id = m_subeventid;
46  sevt->sub_type = 4;
47  sevt->sub_decoding = 30000+9;
48 
49  int *d = (int *) &sevt->data;
50  int s = clock_gettime(CLOCK_MONOTONIC_RAW, &clk);
51 
52  if (s) // error, set everything to 0
53  {
54  for ( int i = 0; i < 6; i++) *d++ = 0;
55  }
56  else
57  {
58  *d++ = clk.tv_sec;
59  memcpy(d, &clk.tv_nsec, sizeof(clk.tv_nsec));
60  d+=2;
61  *d++ = previous_clk.tv_sec;
62  memcpy(d, &previous_clk.tv_nsec, sizeof(previous_clk.tv_nsec));
63  d+=2;
64  }
65  previous_clk = clk;
66 
67  sevt->sub_length += 6;
68  return sevt->sub_length;
69  }
70 
71  else
72  {
73  sevt = (subevtdata_ptr) adr;
74  // set the initial subevent length
75  sevt->sub_length = SEVTHEADERLENGTH;
76 
77  // update id's etc
78  sevt->sub_id = m_subeventid;
79  sevt->sub_type=4;
80  sevt->sub_decoding = IDRTCLK;
81  sevt->reserved[0] = 0;
82  sevt->reserved[1] = 0;
83 
84 
85  int *d = (int *) &sevt->data;
86  int s = clock_gettime(CLOCK_MONOTONIC_RAW, &clk);
87 
88  if (s) // error, set everything to 0
89  {
90  for ( int i = 0; i < 6; i++) *d++ = 0;
91  }
92  else
93  {
94  *d++ = clk.tv_sec;
95  memcpy(d, &clk.tv_nsec, sizeof(clk.tv_nsec));
96  d+=2;
97  *d++ = previous_clk.tv_sec;
98  memcpy(d, &previous_clk.tv_nsec, sizeof(previous_clk.tv_nsec));
99  d+=2;
100  }
101  previous_clk = clk;
102 
103  sevt->sub_padding = 0;
104  sevt->sub_length += 6;
105  return sevt->sub_length;
106  }
107 }
108 
109 
110 void daq_device_rtclock::identify(std::ostream& os) const
111 {
112 
113  os << "Real-time clock Device Event Type: " << m_eventType << " Subevent id: " << m_subeventid << endl;
114 
115 }
116 
117 int daq_device_rtclock::max_length(const int etype) const
118 {
119  if (etype != m_eventType) return 0;
120  return (6 + SEVTHEADERLENGTH);
121 }
122 
124 {
125  clock_gettime(CLOCK_MONOTONIC_RAW, &previous_clk);
126 
127  return 0;
128 }
129 
130 
131