RawDataBlockHeaderV0.cpp
Go to the documentation of this file.
1 #include "DAQDataFormats/RawDataBlockHeaderV0.h"
2 #include <boost/format.hpp>
3 
4 /// It is requred to
5 /// 1. include DAQDataFormats/DataFormatFirst.inc
6 /// 2. define CURRENT_CLASS
7 /// 3. define CURRENT_CLASS_VERSION for version of the class
8 /// OR define LAST_CLASS_VERSION for the main structure of the class
9 /// 4. (optional) define CURRENT_FIELDS_SUB_NAMESPACE
10 /// 5. include DAQDataFormats/DataFormatLast.inc
11 /// before the declaration of the DataFormat version class in the header.
12 #include "DAQDataFormats/DataFormatFirst.inc"
13 #define CURRENT_CLASS RawDataBlockHeader
14 #define CURRENT_CLASS_VERSION 0
15 #define CURRENT_FIELDS_SUB_NAMESPACE datablockheader
16 #include "DAQDataFormats/DataFormatLast.inc"
17 
18 namespace daqdataformats{
19 namespace VERSION_NAMESPACE{
20 
21 //------------------------------------------------------------------------------
22 // Default constructor
24  RawDAQData(version)
25 { }
26 
27 //------------------------------------------------------------------------------
29  RawDAQData(copyin)
30  ,DEEPCOPY_GET_AND_SET(Version)
31  ,DEEPCOPY_GET_AND_SET(Marker)
32  ,DEEPCOPY_GET_AND_SET(TrigNumLo)
33  ,DEEPCOPY_GET_AND_SET(TrigNumHi)
34  ,DEEPCOPY_GET_AND_SET(NumMicroBlocks)
35  ,DEEPCOPY_GET_AND_SET(BuffId)
36  ,DEEPCOPY_GET_AND_SET(DataSize)
37  ,DEEPCOPY_GET_AND_SET(MonteCarloFlag)
38  ,DEEPCOPY_IS_AND_SET(CRCCalculationUsed)
39  ,DEEPCOPY_IS_AND_SET(ConnectionInitialization)
40  ,DEEPCOPY_IS_AND_SET(CloseConnection)
41  ,DEEPCOPY_IS_AND_SET(MissingData)
42  ,DEEPCOPY_GET_AND_SET(TrigNum)
43  ,DEEPCOPY_FUNCTION(addDataSize)
44  ,DEEPCOPY_FUNCTION(advanceNumMicroBlocks)
45  ,DEEPCOPY_FUNCTION(checkMarker)
46 { }
47 
48 //------------------------------------------------------------------------------
49 // Destructor
51 
52 //------------------------------------------------------------------------------
53 // Initialization of data members
55 
56  // Set the Marker
57  EXECUTE_FUNCTION(setVersion) (_version);
59 
60  /// In the beginning of the datablock we havn't calculated CRC yet
61  /// So, set it to false
62  EXECUTE_FUNCTION(setCRCCalculationUsed)(false);
63 
64  /// Size of the header + CRC
65  EXECUTE_FUNCTION(setDataSize)(EXECUTE_FUNCTION(sizeofdata)() + 1);
66 }
67 
68 //------------------------------------------------------------------------------
69 // Getters
70 //------------------------------------------------------------------------------
71 uint64_t RawDataBlockHeader::getTrigNum() const {
72  return getUint64_t(EXECUTE_FUNCTION(getTrigNumLo)(), EXECUTE_FUNCTION(getTrigNumHi)());
73 }
74 
75 //------------------------------------------------------------------------------
76 bool RawDataBlockHeader::setTrigNum(const uint64_t trigstamp) {
77  uint32_t low, high;
78  getLoAndHi(trigstamp, low, high);
79 
80  EXECUTE_FUNCTION(setTrigNumLo)(low);
81  RETURN_FUNCTION(setTrigNumHi)(high);
82 }
83 
84 //------------------------------------------------------------------------------
85 bool RawDataBlockHeader::addDataSize (const uint32_t size){ RETURN_FUNCTION(setDataSize)(EXECUTE_FUNCTION(getDataSize)() + size);}
86 bool RawDataBlockHeader::advanceNumMicroBlocks() { RETURN_FUNCTION(setNumMicroBlocks)(EXECUTE_FUNCTION(getNumMicroBlocks)() + 1);}
87 bool RawDataBlockHeader::checkMarker() const { return (EXECUTE_FUNCTION(getMarker)() == daqdataformats::datablockheader::DataBlock_Marker);}
88 
89 //------------------------------------------------------------------------------
90 // Print the Data Block Header
91 void RawDataBlockHeader::print(std::ostream& os) const{
92 
93  const uint32_t size_of_data = EXECUTE_FUNCTION(sizeofdata)();
94 
95  os<<boost::format("\nRawDataBlockHeader Header (size=%u, version=%u): ") % size_of_data % _version<<std::endl;
96  printBuffer(os);
97 
98  os<<boost::format("Version=%u" ) % EXECUTE_FUNCTION(getVersion)();
99  os<<boost::format(" Marker=%u" ) % EXECUTE_FUNCTION(getMarker)();
100  os<<boost::format(" TriggerNumberLo=%u" ) % EXECUTE_FUNCTION(getTrigNumLo)();
101  os<<boost::format(" TriggerNumberHi=%u" ) % EXECUTE_FUNCTION(getTrigNumHi)();
102  os<<boost::format(" NumMicroBlocks=%u" ) % EXECUTE_FUNCTION(getNumMicroBlocks)();
103  os<<boost::format(" BuffId=%u" ) % EXECUTE_FUNCTION(getBuffId)();
104  os<<boost::format(" DataSize=%u" ) % EXECUTE_FUNCTION(getDataSize)();
105  os<<boost::format(" MonteCarloFlag=%u" ) % EXECUTE_FUNCTION(getMonteCarloFlag)();
106  os<<boost::format(" isCRCCalculationUsed=%u" ) % EXECUTE_FUNCTION(isCRCCalculationUsed)();
107  os<<boost::format(" isConnectionInitialization=%u") % EXECUTE_FUNCTION(isConnectionInitialization)();
108  os<<boost::format(" isCloseConnection=%u" ) % EXECUTE_FUNCTION(isCloseConnection)();
109  os<<boost::format(" isMissingData=%u" ) % EXECUTE_FUNCTION(isMissingData)();
110  os<<std::endl;
111 
112  os<<"\nRawDataBlockHeader RAW bits (converted, if required, to native endian format):";
113  for(uint32_t i = 0; i < size_of_data; ++i){
114  os<<boost::format("\n");
115  printWord(i, true, os);
116  }
117 
118 }// end of print
119 
120 
121 }}// end of namespaces
122 
123 
124 
125 
126 
127 
128 
129 
130 
#define DEEPCOPY_FUNCTION(FUNC)
Definition: FunctionBind.h:40
#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 RETURN_FUNCTION(FULLFUNCTIONNAME)
Definition: Macros.h:57
#define DEEPCOPY_IS_AND_SET(FUNC)
Definition: FunctionBind.h:47
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
RawDataBlockHeader(const version_t)
The default constructor.
const XML_Char * version
Definition: expat.h:187
int32_t version_t
Definition: RawDAQData.h:72
Class to hold the data from the FEBs in correct formats.