RawTriggerTimeV0.cpp
Go to the documentation of this file.
1 #include "DAQDataFormats/RawTriggerTimeV0.h"
2 #include "DAQDataFormats/BitFields.h"
3 #include <boost/format.hpp>
4 
5 /// It is requred to
6 /// 1. include DAQDataFormats/DataFormatFirst.inc
7 /// 2. define CURRENT_CLASS
8 /// 3. define CURRENT_CLASS_VERSION for version of the class
9 /// OR define LAST_CLASS_VERSION for the main structure of the class
10 /// 4. (optional) define CURRENT_FIELDS_SUB_NAMESPACE
11 /// 5. include DAQDataFormats/DataFormatLast.inc
12 /// before the declaration of the DataFormat version class in the header.
13 #include "DAQDataFormats/DataFormatFirst.inc"
14 #define CURRENT_CLASS RawTriggerTime
15 #define CURRENT_CLASS_VERSION 0
16 #define CURRENT_FIELDS_SUB_NAMESPACE triggertime
17 #include "DAQDataFormats/DataFormatLast.inc"
18 
19 namespace daqdataformats{
20 namespace VERSION_NAMESPACE{
21 
22 //------------------------Constructors------------------------------------------
24  PREVIOUS_VERSION_CLASS_NAME(version)
25  ,ZEROOUT_GET_AND_SET(Version )
26  ,ZEROOUT_GET_AND_SET(TriggerTimeStampLow )
27  ,ZEROOUT_GET_AND_SET(TriggerTimeStampHigh )
28  ,ZEROOUT_GET_AND_SET(TriggerTimeStamp_sec )
29  ,ZEROOUT_GET_AND_SET(TriggerTimeStamp_usec)
30  ,ZEROOUT_GET_AND_SET(ClockSource )
31  ,ZEROOUT_GET_AND_SET(TriggerOrigLength )
32  ,ZEROOUT_GET_AND_SET(TriggerTimeStamp )
33  ,ZEROOUT_GET_AND_SET(TriggerTimeStampTvUsec)
34  ,ZEROOUT_GET_AND_SET(TriggerTimeStampTvSec )
35  ,ZEROOUT_GET_AND_SET(TriggerTimeStampTv )
36 {}
37 
38 //------------------------------------------------------------------------------
40  PREVIOUS_VERSION_CLASS_NAME(copyin)
41  ,DEEPCOPY_GET_AND_SET(Version )
42  ,DEEPCOPY_GET_AND_SET(TriggerTimeStampLow )
43  ,DEEPCOPY_GET_AND_SET(TriggerTimeStampHigh )
44  ,DEEPCOPY_GET_AND_SET(TriggerTimeStamp_sec )
45  ,DEEPCOPY_GET_AND_SET(TriggerTimeStamp_usec)
46  ,DEEPCOPY_GET_AND_SET(ClockSource )
47  ,DEEPCOPY_GET_AND_SET(TriggerOrigLength )
48  ,DEEPCOPY_GET_AND_SET(TriggerTimeStamp )
49  ,DEEPCOPY_GET_AND_SET(TriggerTimeStampTvUsec)
50  ,DEEPCOPY_GET_AND_SET(TriggerTimeStampTvSec )
51  ,DEEPCOPY_GET_AND_SET(TriggerTimeStampTv )
52 {}
53 
54 //------------------------------------------------------------------------------
56 
57 //------------------------------------------------------------------------------
58 // General Initialization
60  EXECUTE_FUNCTION(setVersion)(_version);
61 }
62 
63 //------------------------------------------------------------------------------
64 // get Method for 64 bit time stamp
65 uint64_t RawTriggerTime::getTriggerTimeStamp() const {
66  return getUint64_t(EXECUTE_FUNCTION(getTriggerTimeStampLow)(), EXECUTE_FUNCTION(getTriggerTimeStampHigh)());
67 }
68 
69 //------------------------------------------------------------------------------
70 // set Method for 64bit time stamp
71 bool RawTriggerTime::setTriggerTimeStamp(const uint64_t timestamp) {
72  uint32_t low, high;
73  getLoAndHi(timestamp, low, high);
74 
75  EXECUTE_FUNCTION(setTriggerTimeStampHigh)(high);
76  RETURN_FUNCTION(setTriggerTimeStampLow)(low);
77 }
78 
79 //------------------------------------------------------------------------------
80 // get Method for the the seconds of the timeval
81 time_t RawTriggerTime::getTriggerTimeStampTvSec() const { return (time_t) EXECUTE_FUNCTION(getTriggerTimeStamp_sec)();}
82 //------------------------------------------------------------------------------
83 // Get Method for the the microseconds of the timeval
84 suseconds_t RawTriggerTime::getTriggerTimeStampTvUsec() const { return (suseconds_t) EXECUTE_FUNCTION(getTriggerTimeStamp_usec)();}
85 //------------------------------------------------------------------------------
86 bool RawTriggerTime::setTriggerTimeStampTvSec (const time_t a) { RETURN_FUNCTION(setTriggerTimeStamp_sec)((const uint32_t)a);}
87 bool RawTriggerTime::setTriggerTimeStampTvUsec(const suseconds_t a) { RETURN_FUNCTION(setTriggerTimeStamp_usec)((const uint32_t)a);}
88 
89 //------------------------------------------------------------------------------
90 // get Method for 64 bit time stamp, in timeval format
91 timeval RawTriggerTime::getTriggerTimeStampTv() const {
92  timeval timestamp;
93  timestamp.tv_usec = EXECUTE_FUNCTION(getTriggerTimeStampTvUsec)();
94  timestamp.tv_sec = EXECUTE_FUNCTION(getTriggerTimeStampTvSec)();
95 
96  return timestamp;
97 }
98 
99 //------------------------------------------------------------------------------
100 // set Method for 64bit time stamp, as a timeval
101 bool RawTriggerTime::setTriggerTimeStampTv(timeval timestamp){
102 
103  EXECUTE_FUNCTION(setTriggerTimeStampTvUsec)(timestamp.tv_usec);
104  RETURN_FUNCTION(setTriggerTimeStampTvSec)(timestamp.tv_sec);
105 }
106 
107 //------------------------------------------------------------------------------
108 void RawTriggerTime::print(std::ostream& os) const{
109  os<<"++++ Trigger Time ++++\n";
110  os<<boost::format("Trigger Time Version:\t%u\n")%EXECUTE_FUNCTION(getVersion)();
111  os<<boost::format("Gen Timestamp Low:\t%u\n")%EXECUTE_FUNCTION(getTriggerTimeStampLow)();
112  os<<boost::format("Gen Timestamp High:\t%u\n")%EXECUTE_FUNCTION(getTriggerTimeStampHigh)();
113  os<<boost::format("Gen Timestamp:\t\t%Lu\n")%(long long unsigned int)EXECUTE_FUNCTION(getTriggerTimeStamp)();
114  time_t TrigSec = EXECUTE_FUNCTION(getTriggerTimeStampTvSec)();
115  char ctimestr[27]; ctime_r(&TrigSec,ctimestr);
116  os<<boost::format("Gen Time:\t\t%s")%ctimestr;
117  os<<boost::format("Gen usec:\t\t%d\n")%(uint32_t) EXECUTE_FUNCTION(getTriggerTimeStampTvUsec)();
118  os<<boost::format("Clock Source:\t\t0x%02x\n")%EXECUTE_FUNCTION(getClockSource)();
119  os<<boost::format("Original Trig Length:\t%u\n")%EXECUTE_FUNCTION(getTriggerOrigLength)();
120  PRINT_ON_DEBUG("Buffer is set to "<<_Buffer);
121 
122 }
123 
124 }}// end of namespaces
#define EXECUTE_FUNCTION(FULLFUNCTIONNAME)
Execute and return the delegate.
Definition: Macros.h:54
#define DEEPCOPY_GET_AND_SET(FUNC)
Definition: FunctionBind.h:44
#define VERSION_NAMESPACE
#define ZEROOUT_GET_AND_SET(FUNC)
Definition: FunctionBind.h:56
#define RETURN_FUNCTION(FULLFUNCTIONNAME)
Definition: Macros.h:57
void print(std::ostream &os=std::cout) const
const double a
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
const XML_Char * version
Definition: expat.h:187
int32_t version_t
Definition: RawDAQData.h:72
#define PRINT_ON_DEBUG(x)
Definition: RawDAQData.h:35
Class to hold the data from the FEBs in correct formats.
Class to hold the data corresponding to the generated time of the trigger.
RawTriggerTime(const version_t)
The default constructor.