RawMicroBlockHeaderV0.cpp
Go to the documentation of this file.
1 #include "DAQDataFormats/RawMicroBlockHeaderV0.h"
2 #include "DAQDataFormats/RawMilliSliceHeader.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 RawMicroBlockHeader
15 #define CURRENT_CLASS_VERSION 0
16 #define CURRENT_FIELDS_SUB_NAMESPACE rawmicroblockhdr
17 #include "DAQDataFormats/DataFormatLast.inc"
18 
19 
20 namespace daqdataformats{
21 namespace VERSION_NAMESPACE{
22 //------------------------------------------------------------
23 // Default constructor
25  PREVIOUS_VERSION_CLASS_NAME(version)
26  ,ZEROOUT_GET_AND_SET(DestBuffID)
27  ,ZEROOUT_GET_AND_SET(Partition)
29  ,ZEROOUT_GET_AND_SET(Version)
30  ,_DCMChan(NULL)
31 {}
32 
33 //------------------------------------------------------------
35  PREVIOUS_VERSION_CLASS_NAME(copyin)
36  ,DEEPCOPY_GET_AND_SET(DestBuffID)
37  ,DEEPCOPY_GET_AND_SET(Partition)
39  ,DEEPCOPY_GET_AND_SET(Version)
40  ,_DCMChan(NULL)
41 {}
42 
43 //------------------------------------------------------------
44 // Destructor
46  if(_DCMChan)
47  delete _DCMChan;
48 }
49 
50 //------------------------------------------------------------
51 // Initialize the data members
54  PRINT_ON_DEBUG("version is set to "<<getVersion());
55 }
56 
57 //------------------------------------------------------------------------------
58 uint32_t RawMicroBlockHeader::getVersion() const { RETURN_FUNCTION(getV0)();}
59 bool RawMicroBlockHeader::setVersion(const uint32_t a) { RETURN_FUNCTION(setV0)(a);}
60 
61 //------------------------------------------------------------------------------
62 bool RawMicroBlockHeader::setAllParameters(const void* millislice_buffer){
63 
64  const RawMilliSliceHeader millislice_header(millislice_buffer);
65 
66  setGlobalDCMID(millislice_header.getGlobalDCMID());
67  EXECUTE_FUNCTION(setDestBuffID)(millislice_header.getDestBuffID());
68  RETURN_FUNCTION(setPartition)(millislice_header.getPartition());
69 }
70 
71 
72 //------------------------------------------------------------------------------
73  bool RawMicroBlockHeader::setBufferSource(const void* pointer){
74  _Buffer = (void*)pointer;
75 
76  /// Check if the internal buffer is too small
77 #pragma GCC diagnostic push
78 #pragma GCC diagnostic ignored "-Wtype-limits"
79  if(isInternalBuffer() && _InternalBuffer.size() < rawmicroblockhdr::WORD_DCMChan){
80  _InternalBuffer.assign(rawmicroblockhdr::WORD_DCMChan + 1, 0);
81  }// end of checking if the internal buffer is too small
82 #pragma GCC diagnostic pop
83  /// Pointer to the word of the DCMChan
84  const uint32_t* pp = (uint32_t*)pointer + rawmicroblockhdr::WORD_DCMChan;
85 
86  /// If it exists, set its buffer source
87  if(_DCMChan) return _DCMChan->setBufferSource(pp);
88 
89  /// Since it does not exist, create a new
90  _DCMChan = new RawDCMChan(pointer); ///< version of the NanoSliceHeader equals the version of the NanoSlice
91 
92  return true;
93 }
94 
95 //------------------------------------------------------------------------------
96 // Print the MicroBlock header information
97 void RawMicroBlockHeader::print(std::ostream& os) const{
98  const uint32_t size_of_data = EXECUTE_FUNCTION(sizeofdata)();
99 
100  os<<boost::format("\nMicroBlock Header(size=%u, version=%u):") % size_of_data % _version ;
101  os<<boost::format(" getDiblockId=%u")% getDiblockId();
102  os<<boost::format(" DCMId=%u" )% getDCMId();
103  os<<boost::format(" DetId=%u" )% getDetId();
104  os<<boost::format(" DestBuff=%u" )% EXECUTE_FUNCTION(getDestBuffID)(); //! Destination buffer node
105  os<<boost::format(" Partition=%u" )% EXECUTE_FUNCTION(getPartition)(); //! Partition
106  os<<boost::format(" V0=%u" )% EXECUTE_FUNCTION(getV0)();
107  os<<boost::format(" Version=%u" )% EXECUTE_FUNCTION(getVersion)();
108  os<<"\n";
109 
110  printBuffer(os);
111 
112  os<<"\nMicroBlockHeader RAW 32bit words (converted, if required, to native endian format):";
113  for(uint32_t i = 0; i < size_of_data; ++i){
114  os<<" ";
115  printWord(i,false, os);
116  }
117 
118  os<<"\nMicroBlockHeader RAW bits (converted, if required, to native endian format):";
119  for(uint32_t i = 0; i < size_of_data; ++i){
120  os<<std::endl;
121  printWord(i,true, os);
122  }
123 }
124 
125 
126 }}// 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
bool setBufferSource(const void *)
We are not going to overload these funtions, so no need to declare them virtual.
Definition: RawDAQData.cpp:880
#define ZEROOUT_GET_AND_SET(FUNC)
Definition: FunctionBind.h:56
#define RETURN_FUNCTION(FULLFUNCTIONNAME)
Definition: Macros.h:57
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.