RawConfigurationBlockV0.cpp
Go to the documentation of this file.
1 #include "DAQDataFormats/RawConfigurationBlockV0.h"
2 #include "DAQDataFormats/RawConfigurationBlock.h"
3 #include "DAQDataFormats/RawConfigurationTail.h"
4 #include "DAQDataFormats/RawConfigurationSystemID.h"
5 #include <boost/format.hpp>
6 
7 /// It is requred to
8 /// 1. include DAQDataFormats/DataFormatFirst.inc
9 /// 2. define CURRENT_CLASS
10 /// 3. define CURRENT_CLASS_VERSION for version of the class
11 /// OR define LAST_CLASS_VERSION for the main structure of the class
12 /// 4. (optional) define CURRENT_FIELDS_SUB_NAMESPACE
13 /// 5. include DAQDataFormats/DataFormatLast.inc
14 /// before the declaration of the DataFormat version class in the header.
15 #include "DAQDataFormats/DataFormatFirst.inc"
16 #define CURRENT_CLASS RawConfigurationBlock
17 #define CURRENT_CLASS_VERSION 0
18 #define CURRENT_FIELDS_SUB_NAMESPACE configurationblock
19 #include "DAQDataFormats/DataFormatLast.inc"
20 
21 namespace daqdataformats{
22 namespace VERSION_NAMESPACE{
23 
24 
25 //------------------------------------------------------------------------------
26 // Default constructor
28  RawDAQData(version, true, (sizeofdata_t) &RawConfigurationBlock::getPredefinedSize)
30  ,ZEROOUT_FUNCTION(getHeader)
31  ,ZEROOUT_FUNCTION(getTail)
32  ,ZEROOUT_FUNCTION(getTailConst)
33  ,ZEROOUT_FUNCTION(getSystemID)
34  ,ZEROOUT_FUNCTION(getSystemIDConst)
35  ,ZEROOUT_FUNCTION(getSystemIDWithInput)
36  ,ZEROOUT_FUNCTION(getSystemIDConstWithInput)
37  ,ZEROOUT_FUNCTION(setFloatingSystemIDToBufferSource)
38  ,ZEROOUT_FUNCTION(setFloatingSystemID)
39  ,ZEROOUT_FUNCTION(addSystemID)
40  ,ZEROOUT_FUNCTION(getMarkerHi1)
41  ,ZEROOUT_FUNCTION(getMarkerHi2)
42  ,ZEROOUT_FUNCTION(getMarkerLo1)
43  ,ZEROOUT_FUNCTION(getMarkerLo2)
44  ,ZEROOUT_FUNCTION(getConfigurationVersion)
45  ,ZEROOUT_FUNCTION(getConfigurationBlockSize)
46  ,ZEROOUT_FUNCTION(getSystemNumber)
47  ,ZEROOUT_GET_AND_SET(DetectorID)
48  ,ZEROOUT_GET_AND_SET(ResourceManagerID)
49  ,ZEROOUT_GET_AND_SET(RunNumber)
51  ,ZEROOUT_GET_AND_SET(Partition)
52  ,ZEROOUT_GET_AND_SET(Subrun)
53  ,ZEROOUT_GET_AND_SET(SystemVersionIDX)
54  ,_tail (NULL)
55  ,_header (NULL)
56  ,_floatingSystemID (NULL)
57  ,_floatingSystemIDNumber (-1)
58  ,_version_ConfigurationSystemID (rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION)
59  ,_version_ConfigurationTail (rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION)
60 { }
61 
62 //------------------------------------------------------------------------------
64  RawDAQData(copyin)
66  ,DEEPCOPY_FUNCTION(getHeader)
67  ,DEEPCOPY_FUNCTION(getTail)
68  ,DEEPCOPY_FUNCTION(getTailConst)
69  ,DEEPCOPY_FUNCTION(getSystemID)
70  ,DEEPCOPY_FUNCTION(getSystemIDConst)
71  ,DEEPCOPY_FUNCTION(getSystemIDWithInput)
72  ,DEEPCOPY_FUNCTION(getSystemIDConstWithInput)
73  ,DEEPCOPY_FUNCTION(setFloatingSystemIDToBufferSource)
74  ,DEEPCOPY_FUNCTION(setFloatingSystemID)
75  ,DEEPCOPY_FUNCTION(addSystemID)
76  ,DEEPCOPY_FUNCTION(getMarkerHi1)
77  ,DEEPCOPY_FUNCTION(getMarkerHi2)
78  ,DEEPCOPY_FUNCTION(getMarkerLo1)
79  ,DEEPCOPY_FUNCTION(getMarkerLo2)
80  ,DEEPCOPY_FUNCTION(getConfigurationVersion)
81  ,DEEPCOPY_FUNCTION(getConfigurationBlockSize)
82  ,DEEPCOPY_FUNCTION(getSystemNumber)
83  ,DEEPCOPY_GET_AND_SET(DetectorID)
84  ,DEEPCOPY_GET_AND_SET(ResourceManagerID)
85  ,DEEPCOPY_GET_AND_SET(RunNumber)
87  ,DEEPCOPY_GET_AND_SET(Partition)
88  ,DEEPCOPY_GET_AND_SET(Subrun)
89  ,DEEPCOPY_GET_AND_SET(SystemVersionIDX)
90  ,_tail (NULL)
91  ,_header (NULL)
92  ,_floatingSystemID (NULL)
96 {}
97 
98 
99 //------------------------------------------------------------------------------
100 // Destructor
102  if(_header) delete _header;
103  if(_tail) delete _tail;
105 }
106 
107 //------------------------------------------------------------------------------
108 // General initialization
110 
111  /// This is needed for the formats with variable size
112  /// If buffer is internal, need to resize it
113  if(isInternalBuffer()){
114  _InternalBuffer.resize(_header->sizeofdata() + 1);
115  checkBufferInternalness();
116  }
117 
118  _header->init();
119 
120  /// header + crc
121  _header->setConfigurationBlockSize(_header->sizeofdata() + 1);
122 
123 
124  //PRINT_ON_DEBUG("Adresses "<<getBuffer()<<" header"<<_header->getBuffer())
125  /// Initialize _floatingSystemIDNumber
127 }
128 
129 //------------------------------------------------------------------------------
130 daqdataformats::RawConfigurationHeader* RawConfigurationBlock::getHeader() {return _header;}
131 
132 daqdataformats::RawConfigurationTail* RawConfigurationBlock::getTailConst() const {
133  _tail->setBufferSource(&RAWBUFF32[EXECUTE_FUNCTION(sizeofdata)() - _tail->sizeofdata()]);
134  return _tail;
135 }
136 daqdataformats::RawConfigurationTail* RawConfigurationBlock::getTail() {
137  _tail->setBufferSource(&RAWBUFF32[EXECUTE_FUNCTION(sizeofdata)() - _tail->sizeofdata()]);
138  return _tail;
139 }
140 
141 //------------------------------------------------------------------------------
144 
145 //------------------------------------------------------------------------------
146 daqdataformats::RawConfigurationSystemID* RawConfigurationBlock::getSystemIDWithInput(const uint32_t isystem) {
147  EXECUTE_FUNCTION(setFloatingSystemID)(isystem);
148  return _floatingSystemID;
149 }
150 //------------------------------------------------------------------------------
151 daqdataformats::RawConfigurationSystemID* RawConfigurationBlock::getSystemIDConstWithInput(const uint32_t isystem) const {
152  EXECUTE_FUNCTION(setFloatingSystemID)(isystem);
153  return _floatingSystemID;
154 }
155 
156 uint32_t RawConfigurationBlock::getMarkerHi1() const { return _header->getMarkerHi1();}
157 uint32_t RawConfigurationBlock::getMarkerHi2() const { return _header->getMarkerHi2();}
158 uint32_t RawConfigurationBlock::getMarkerLo1() const { RETURN_FUNCTION(getTailConst)()->getMarkerLo1();}
159 uint32_t RawConfigurationBlock::getMarkerLo2() const { RETURN_FUNCTION(getTailConst)()->getMarkerLo2();}
160 uint32_t RawConfigurationBlock::getConfigurationVersion() const { return _header->getConfigurationHeaderVersion();}
161 uint32_t RawConfigurationBlock::getDetectorID() const { return _header->getDetectorID();}
162 uint32_t RawConfigurationBlock::getConfigurationBlockSize() const { return _header->getConfigurationBlockSize();}
163 uint32_t RawConfigurationBlock::getResourceManagerID() const { return _header->getResourceManagerID();}
164 uint32_t RawConfigurationBlock::getRunNumber() const { return _header->getRunNumber();}
165 uint32_t RawConfigurationBlock::getRunType() const { return _header->getRunType();}
166 uint32_t RawConfigurationBlock::getPartition() const { return _header->getPartition();}
167 uint32_t RawConfigurationBlock::getSubrun() const { return _header->getSubrun();}
168 uint32_t RawConfigurationBlock::getSystemNumber() const { return _header->getSystemNumber();}
169 uint32_t RawConfigurationBlock::getSystemVersionIDX() const { return _header->getSystemVersionIDX();}
170 
171 
172 bool RawConfigurationBlock::setDetectorID (const uint32_t a){return _header->setDetectorID(a);}
173 bool RawConfigurationBlock::setResourceManagerID(const uint32_t a){return _header->setResourceManagerID(a);}
174 bool RawConfigurationBlock::setRunNumber (const uint32_t a){return _header->setRunNumber(a);}
175 bool RawConfigurationBlock::setRunType (const uint32_t a){return _header->setRunType(a);}
176 bool RawConfigurationBlock::setPartition (const uint32_t a){return _header->setPartition(a);}
177 bool RawConfigurationBlock::setSubrun (const uint32_t a){return _header->setSubrun(a);}
178 bool RawConfigurationBlock::setSystemVersionIDX (const uint32_t a){return _header->setSystemVersionIDX(a);}
179 
180 //------------------------------------------------------------------------------
181 bool RawConfigurationBlock::addSystemID(const void* system_pointer){
182 
183 
184  const daqdataformats::RawConfigurationSystemID input_system(system_pointer);
185  const uint32_t sysid_size = input_system.sizeofdata();
186 
187  /// If internal buffer, need to adjust the size
188  if(_shouldBufferBeInternal){
189  resizeInternalBuffer(_header->getConfigurationBlockSize() + sysid_size);
190  checkBufferInternalness();
191  }
192 
193  const uint32_t system_number = EXECUTE_FUNCTION(getSystemNumber)();
194 
195  EXECUTE_FUNCTION(setFloatingSystemID)(system_number);
196 
197  /// initialize it. Version and such
198  _floatingSystemID->readData(system_pointer);
199 
200  /// advancing system number
201  _header->setSystemNumber(system_number + 1);
202  return _header->setConfigurationBlockSize(_header->getConfigurationBlockSize() + sysid_size);
203 }
204 
205 //------------------------------------------------------------------------------
206 bool RawConfigurationBlock::setFloatingSystemIDToBufferSource(const void* buffer_pointer) const {
207  /// If it exists, just set its buffer
209  return _floatingSystemID->setBufferSource(buffer_pointer);
210 
211  /// Otherwise, create new Floating MicroSlice pointing to the buffer
213 
214  return true;
215 }
216 
217 //------------------------------------------------------------------------------
218 bool RawConfigurationBlock::setFloatingSystemID(const uint32_t isysid) const {
219 
220  /// If it's already the same, nothing needs to be done
221  if((int)isysid == _floatingSystemIDNumber)
222  return true;
223 
224  /// Pointer that we are going to use
225  uint32_t* pointer;
226 
227  /// If microslice number is greater than current floating Microslice number, then no need
228  /// to loop over all MicroSlices, just start from the current floating MicroSlice
229  if((int)isysid > _floatingSystemIDNumber && _floatingSystemIDNumber > -1){
230  pointer = (uint32_t*)_floatingSystemID->getBuffer();
231  }
232  else{
233  /// Otherwise, start from scratch
234  /// First point to the first MicroSlice
235  pointer = (uint32_t*)&RAWBUFF32[_header->sizeofdata()];
236 
237  /// Set floating MicroSlice to pointer
238  /// If it doesn't exist, create it
239  EXECUTE_FUNCTION(setFloatingSystemIDToBufferSource)(pointer);
241  }// end of setting the first floating MicroSlice
242 
243 
244  /// Pointer to the end of the buffer for checks
245  const uint32_t* end_of_buffer_pointer = &RAWBUFF32[EXECUTE_FUNCTION(sizeofdata)()];
246 
247  /// Start loop over microslices
249  pointer += _floatingSystemID->sizeofdata();
250 
251  /// Check if the pointer is not valid
252  if (pointer >= end_of_buffer_pointer)
253  return false;
254 
255  _floatingSystemID->setBufferSource(pointer);
256  }// end of loop over microslices
257 
258  return true;
259 }
260 
261 //------------------------------------------------------------------------------
262 bool RawConfigurationBlock::close(const bool produce_crc){
263 
264  /// If internal buffer, need to adjust the size
265  if(_shouldBufferBeInternal){
266  resizeInternalBuffer(_header->getConfigurationBlockSize() + _tail->sizeofdata());
267  checkBufferInternalness();
268  }
269 
270  /// Adjust the size
271  _header->setConfigurationBlockSize(_header->getConfigurationBlockSize() + _tail->sizeofdata());
272 
273  /// Set Tail's address and initialize it
274  EXECUTE_FUNCTION(getTail)()->init();
275 
276  /// Add CRC at the very end of _Buffer
277  if(produce_crc){
278  _tail->setCRC(calculateCheckSum(1));
279  }
280 
281  return true;
282 }
283 
284 //------------------------------------------------------------------------------
285 bool RawConfigurationBlock::setBufferSource(const void* pointer){
286 
287  const uint32_t* old_buffer = (uint32_t*)_Buffer;
288  _Buffer = (void*)pointer;
289  _shouldBufferBeInternal = isInternalBuffer();
290 
291  /// If Header is already defined, then set its buffer source
292  /// Otherwise, need to construct it
293  if(_header){
294  _header->setBufferSource(_Buffer);
295 
296  /// It's possible that Floating Microblock was already constructed.
297  /// If so, need to reassign its pointer
298  if(_floatingSystemIDNumber > -1){
299 
300  /// See how many Microblocks in the new buffer.
301  /// If it's greater, then make the floating MicroBlock non-valid.
302  if(_floatingSystemIDNumber > (int)_header->getSystemNumber()){
304  return true;
305  }// end of checking number of microblocks
306 
307  /// New Floating MicroBlock pointer
308  const uint32_t* floating_sysid_pointer =((uint32_t*)_Buffer) + ((uint32_t*)_floatingSystemID->getBuffer() - old_buffer);
309  RETURN_FUNCTION(setFloatingSystemIDToBufferSource)(floating_sysid_pointer);
310  }// end of setting new floating MicroBlock pointer
311 
312  return true;
313 
314  }
315 
316  _header = new daqdataformats::RawConfigurationHeader(_Buffer, _version); ///< version of the DataBlockSliceHeader equals the version of the DataBlockSlice
317 
318  PRINT_ON_DEBUG("Constructed _header with version"<<_version);
319 
320  _function_sizeofdata = (sizeofdata_t) &RawConfigurationBlock::sizeofdata;
321  return true;
322 }
323 
324 //------------------------------------------------------------------------------
325 // This is a general method to read the microslice from millislice_buffer to _Buffer
327 {
328  const uint32_t header_size = _header->sizeofdata();
329 
330  /// If internal buffer, need to adjust the size
331  if(_shouldBufferBeInternal){
332  resizeInternalBuffer(header_size);
333  checkBufferInternalness();
334  }
335 
336  /// Read the header
337  void* buffer_new = _header->readData(buffer);
338 
339  /// If internal buffer, need to adjust the size
340  if(_shouldBufferBeInternal){
341  resizeInternalBuffer(EXECUTE_FUNCTION(sizeofdata)());
342  checkBufferInternalness();
343  }
344 
345  /// Now, read the rest of the configuration block
346  buffer_new = readDataGeneral(buffer_new, EXECUTE_FUNCTION(sizeofdata)() - header_size, header_size);
347 
348  checkBufferInternalness();
349 
350  return buffer_new;
351  }// end of readData(void*)
352 
353 //------------------------------------------------------------------------------
354 // Print the DataBlock structure
355 void RawConfigurationBlock::print(std::ostream& os) const {
356 
357  os<<"----------ConfigurationBlock----------------------------------------size="<<EXECUTE_FUNCTION(sizeofdata)();
358  _header->print(os);
359 
360  const uint32_t nsystems = EXECUTE_FUNCTION(getSystemNumber)();
361 
362  os<<"\nNumber of systems = "<<nsystems<<"\n";
363 
364 
365  daqdataformats::RawConfigurationBlock confblock_copy(_Buffer, _version);
366 
367  if(nsystems){
368  for(uint32_t isystem = 0; isystem < nsystems; ++isystem){
369  confblock_copy.getSystemID(isystem)->print(os);
370  }
371  }
372 
373  daqdataformats::RawConfigurationTail* tail = confblock_copy.getTail();
374 
375  /// see if the tail is valid
376  if(tail->getMarkerLo1() == daqdataformats::rawconftail::Marker_value[0] && tail->getMarkerLo2() == daqdataformats::rawconftail::Marker_value[1]){
377  tail->print(os);
378  }
379  else
380  os<<"Configuration Block is not closed\n";
381 
382 
383 }
384 
385 }}// end of namespaces
#define ZEROOUT_FUNCTION(FUNC)
Definition: FunctionBind.h:52
#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
RawConfigurationSystemID * getSystemIDConst(const uint32_t isystem) const
#define sizeofdata_t
Definition: FunctionBind.h:30
RawConfigurationSystemID * getSystemID(const uint32_t isystem)
RawConfigurationBlock(const version_t)
The default constructor.
#define VERSION_NAMESPACE
::xsd::cxx::tree::buffer< char > buffer
Definition: Database.h:179
#define ZEROOUT_GET_AND_SET(FUNC)
Definition: FunctionBind.h:56
#define RETURN_FUNCTION(FULLFUNCTIONNAME)
Definition: Macros.h:57
const double a
const XML_Char * version
Definition: expat.h:187
IMPLEMENT_MAIN_STANDARD IMPLEMENT_MAIN_setBufferSource bool close(const bool produce_crc=false)
#define RAWBUFF32
Definition: RawDAQData.h:16
int32_t version_t
Definition: RawDAQData.h:72
def tail(path, window=20)
Definition: log_trawl.py:24
#define PRINT_ON_DEBUG(x)
Definition: RawDAQData.h:35
static const version_t DAQDATAFORMAT_UNKNOWN_VERSION
Definition: RawDAQData.h:81
Class to hold the data from the FEBs in correct formats.
daqdataformats::RawConfigurationSystemID * _floatingSystemID
procfile close()