RawMicroBlockV0.cpp
Go to the documentation of this file.
1 #include "DAQDataFormats/RawMicroBlockV0.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 RawMicroBlock
15 #define CURRENT_CLASS_VERSION 0
16 #define CURRENT_FIELDS_SUB_NAMESPACE rawmicroblock
17 #include "DAQDataFormats/DataFormatLast.inc"
18 
19 namespace daqdataformats{
20 namespace VERSION_NAMESPACE{
21 
22 //------------------------------------------------------------------------------
23 // Default constructor
25  RawDAQData(version, true, (sizeofdata_t) &RawMicroBlock::getPredefinedSize)
26  ,_Header (NULL)
27  ,_MicroSlice (NULL)
28 { }
29 
30 //------------------------------------------------------------------------------
32  RawDAQData(copyin)
33  ,_Header (NULL)
34  ,_MicroSlice (NULL)
35 { }
36 
37 //------------------------------------------------------------------------------
38 // Destructor
40  if(_Header) delete _Header;
41  if(_MicroSlice) delete _MicroSlice;
42 }
43 
44 //------------------------------------------------------------------------------
45 bool RawMicroBlock::setBufferSource(const void* pointer){
46 
47  PRINT_ON_DEBUG(__PRETTY_FUNCTION__<<" initial size of internal buffer"<<_InternalBuffer.size());
48 
49  _Buffer = (void*)pointer;
50 
51  _shouldBufferBeInternal = isInternalBuffer();
52 
53  /// If Header is already defined, then set its buffer source
54  /// Otherwise, need to construct it
55  if(_Header) {
56  _Header->setBufferSource(pointer);
57  const uint32_t* pp = (uint32_t*)pointer + _Header->sizeofdata();
58  return _MicroSlice->setBufferSource(pp);
59  }
60  PRINT_ON_DEBUG(__PRETTY_FUNCTION__<<" step0 size of internal buffer "<<_InternalBuffer.size()<<" 000000000000000000000000000000000000000000000000000\n");
61 
62  /// Construct header
63  _Header = new daqdataformats::RawMicroBlockHeader(_Buffer, _version); ///< version of the MicroBlockHeader equals the version of the MicroBlock
64 
65  /// If buffer is internal, resize it to header size plus one,
66  /// so that we can assige the start of the MicroSlice buffer
67  if(_shouldBufferBeInternal){
68  resizeInternalBuffer(_Header->sizeofdata() + 1);
69  /// Check pointers after each read or resize buffer
70  checkBufferInternalness();
71  }
72 
73  /// Pointer to the MicroSlice buffer
74  const uint32_t* pp = (uint32_t*)pointer + _Header->sizeofdata();
75 
76  /// Construct the MicroSlice
77  _MicroSlice = new RawMicroSlice((void*)pp);
78 
79  PRINT_ON_DEBUG(__PRETTY_FUNCTION__<<" step1 size of internal buffer "<<_InternalBuffer.size()<<" 1111111111111111111111111111111111111111111111111111\n");
80 
82  if(_function_sizeofdata)std::cout<<"sizeofdata before binding "<<sizeofdata()<<"\n";
83  else std::cout<<"sizeofdata is not bound\n"
84  );
85 
86  _function_sizeofdata = (sizeofdata_t) &version0::RawMicroBlock::sizeofdata;
87 
88  PRINT_ON_DEBUG("sizeofdata after binding "<<sizeofdata());
89  return true;
90  }
91 
92 //------------------------------------------------------------------------------
93 // Printing the MicroBlock structure
94 void RawMicroBlock::print(std::ostream& os) const {
95 
96  const uint32_t size_of_data = EXECUTE_FUNCTION(sizeofdata)();
97 
98  os<<boost::format("\n---MicroBlock---------------------------------------------(size=%u, version=%u)\n")
99  % size_of_data % _version;
100 
101  printBuffer(os);
102 
103  for(uint32_t i = 0; i < size_of_data; ++i){
104  os<<" ";
105  printWord(i, false, os);
106  os<<"\n";
107  }
108 
109  _Header->print(os);
110  _MicroSlice->print(os);
111  printBinary(_Buffer, _Header->sizeofdata(), os);
112 }
113 
114 //------------------------------------------------------------------------------
115 // Size of the MicroBlock _Buffer in words
116 uint32_t RawMicroBlock::sizeofdata() const {
117 
118  /// We know that the header and MicroSlice is constructed
119  if(_MicroSlice->getByteCount() == 0)
120  return _Header->sizeofdata();
121 
122  return _Header->sizeofdata() + _MicroSlice->sizeofdata();
123 }
124 
125 //------------------------------------------------------------------------------
126 // This is a general method to read the microslice from millislice_buffer to _Buffer
127 void* RawMicroBlock::readData(const void* microblock_buffer)
128 {
129  /// Read the header and find out the size of the MicroBlock Header and MicroSlice Header
130  void* buffer_new = readDataGeneral(microblock_buffer, MICROBLOCK_HEADER_STUFF, 0);
131 
132  /// Check pointers after each read or resize buffer
133  checkBufferInternalness();
134 
135  /// Now, read the rest of the microblock
136  buffer_new = readDataGeneral(buffer_new, EXECUTE_FUNCTION(sizeofdata)() - MICROBLOCK_HEADER_STUFF, MICROBLOCK_HEADER_STUFF);
137 
138  /// Check pointers after each read or resize buffer
139  checkBufferInternalness();
140 
141  return buffer_new;
142 
143 }// end of readData(void*)
144 
145 //------------------------------------------------------------------------------
146 bool RawMicroBlock::setMicroSlice(const void* microslice_buffer) {
147 
148  const daqdataformats::RawMicroSliceHeader header(microslice_buffer);
149 
150  const uint32_t micro_size = header.getMicroSliceSize();
151 
152  if(_shouldBufferBeInternal){
153 
154  resizeInternalBuffer(micro_size);
155  /// Check pointers after each read or resize buffer
156  checkBufferInternalness();
157  }
158 
159  readDataGeneral(microslice_buffer, micro_size, _Header->sizeofdata());
160 
161  return true;
162 }
163 
164 
165 }}// end of namespaces
#define EXECUTE_FUNCTION(FULLFUNCTIONNAME)
Execute and return the delegate.
Definition: Macros.h:54
#define sizeofdata_t
Definition: FunctionBind.h:30
bool setBufferSource(const void *pointer)
Setting Buffer, Header and Timing marker. Don&#39;t bother Floating NanoSlice.
#define VERSION_NAMESPACE
daqdataformats::RawMicroSlice * _MicroSlice
MicroBlock Header.
#define EXECUTE_ON_DEBUG(x)
Debugging macros.
Definition: RawDAQData.h:34
bool setMicroSlice(const void *microslice_buffer)
daqdataformats::RawMicroBlockHeader * _Header
void print(std::ostream &os=std::cout) const
Method for printing the content of the Buffer.
Definition: RawDAQData.cpp:500
static const uint32_t MICROBLOCK_HEADER_STUFF
MicroBlock header size + MicroSlice Header.
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
OStream cout
Definition: OStream.cxx:6
const XML_Char * version
Definition: expat.h:187
uint32_t getByteCount() const
Get the Data Present bit of the Header.
Class to hold the MicroSlice data.
Definition: RawMicroSlice.h:48
int32_t version_t
Definition: RawDAQData.h:72
void print(std::ostream &os=std::cout) const
#define PRINT_ON_DEBUG(x)
Definition: RawDAQData.h:35
Class to hold the data from the FEBs in correct formats.