RawSummaryDCMDataV0.cpp
Go to the documentation of this file.
1 #include "DAQDataFormats/RawSummaryDCMDataV0.h"
2 #include "DAQDataFormats/RawSummaryDCMDataPoint.h"
3 #include "DAQDataFormats/RawMilliSliceHeader.h"
4 #include <boost/format.hpp>
5 #include <iomanip>
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 RawSummaryDCMData
17 #define CURRENT_CLASS_VERSION 0
18 #define CURRENT_FIELDS_SUB_NAMESPACE summarydcmdata
19 #include "DAQDataFormats/DataFormatLast.inc"
20 
21 //#define PRINT_ON_DEBUG(x) std::cout<<x<<"\n";
22 
23 namespace daqdataformats{
24 namespace VERSION_NAMESPACE{
25 
26 //------------------------------------------------------------------------------
27 // Default constructor
29  RawDAQData(version, true, (sizeofdata_t) &RawSummaryDCMData::getPredefinedSize)
30  ,_Header (NULL)
31 { }
32 
33 //------------------------------------------------------------------------------
35  RawDAQData(copyin)
36  ,_Header (NULL)
37 { }
38 
39 //------------------------------------------------------------------------------
40 // Destructor
42  if(_Header) delete _Header;
43 }
44 
45  bool RawSummaryDCMData::addDataPoints(const std::list<std::pair<uint64_t, uint16_t> >& list, const uint8_t type)
46  {
47  const uint32_t new_sizeofdata = EXECUTE_FUNCTION(sizeofdata)() + list.size() * summarydcmdatapoint::RAWSUMMARYDCMDATAPOINT_SIZE;
48  PRINT_ON_DEBUG(__PRETTY_FUNCTION__ << ": list.size()=" << list.size() << ", new_sizeofdata=" << new_sizeofdata << " 000000000000");
49  /// If buffer is internal, we need to adjust its size
50  if(_shouldBufferBeInternal) {
51  /// Dcmdata size is the size of the header and the microslice
52 
53  /// Add the dcmdata size
54  resizeInternalBuffer(new_sizeofdata);
55 
56  /// Check pointers after each read or resize buffer
57  checkBufferInternalness();
58  }// end of adjusting the internal buffer size
59 
60  PRINT_ON_DEBUG(__PRETTY_FUNCTION__ << ": list.size()=" << list.size() << ", new_sizeofdata=" << new_sizeofdata << " 1111111111111");
61  std::list<std::pair<uint64_t, uint16_t> >::const_iterator ii = list.begin(), ee=list.end();
62  for(; ii != ee; ++ii) {
63  //std::cout << "RawSummaryDCMDataV0::addDataPoints: first:0x" << std::hex << (unsigned long long)(*ii).first <<", second:" << (unsigned)(*ii).second << ", type: " << (unsigned)type << std::endl;
65  newPoint.setTimeStamp((*ii).first);
66  newPoint.setDCMID((*ii).second);
67  newPoint.setDataType(type);
68  readDataGeneral(newPoint.getBuffer(), newPoint.sizeofdata(), EXECUTE_FUNCTION(sizeofdata)());
69  checkBufferInternalness();
70  _Header->advanceNumEntries();
71  PRINT_ON_DEBUG(__PRETTY_FUNCTION__ << ": list.size()=" << list.size() << ", new_sizeofdata=" << new_sizeofdata << " 2222222222222");
72  }
73  return true;
74 
75  }
76 // //------------------------------------------------------------------------------
77  bool RawSummaryDCMData::setBufferSource(const void* pointer){
78 
79  PRINT_ON_DEBUG(__PRETTY_FUNCTION__<<" initial size of internal buffer"<<_InternalBuffer.size());
80 
81  _Buffer = (void*)pointer;
82 
83  _shouldBufferBeInternal = isInternalBuffer();
84 
85  /// If Header is already defined, then set its buffer source
86  /// Otherwise, need to construct it
87  if(_Header) {
88  return _Header->setBufferSource(pointer);
89  }
90  PRINT_ON_DEBUG(__PRETTY_FUNCTION__<<" step0 size of internal buffer "<<_InternalBuffer.size()<<" 000000000000000000000000000000000000000000000000000\n");
91 
92  /// Construct header
93  _Header = new daqdataformats::RawSummaryDCMDataHeader(_Buffer, _version); ///< version of the MicroBlockHeader equals the version of the MicroBlock
94 
95  /// If buffer is internal, resize it to header size plus one,
96  /// so that we can assige the start of the MicroSlice buffer
97  if(_shouldBufferBeInternal){
98  resizeInternalBuffer(_Header->sizeofdata() + 0);
99  /// Check pointers after each read or resize buffer
100  checkBufferInternalness();
101  }
102 
103  PRINT_ON_DEBUG(__PRETTY_FUNCTION__<<" step1 size of internal buffer "<<_InternalBuffer.size()<<" 1111111111111111111111111111111111111111111111111111\n");
104 
106  if(_function_sizeofdata)std::cout<<"sizeofdata before binding "<<sizeofdata()<<"\n";
107  else std::cout<<"sizeofdata is not bound\n"
108  );
109 
110  _function_sizeofdata = (sizeofdata_t) &version0::RawSummaryDCMData::sizeofdata;
111 
112  PRINT_ON_DEBUG("sizeofdata after binding "<<sizeofdata());
113  return true;
114  }
115 
117 
118  /// This is needed for the formats with variable size
119  /// If buffer is internal, need to resize it
120  if(_shouldBufferBeInternal){
121  resizeInternalBuffer(_Header->sizeofdata());
122  /// Check pointers after each read or resize buffer
123  checkBufferInternalness();
124  }
125 
126  _Header->init();
127  }
128 
129  uint32_t RawSummaryDCMData::getVersion() const { return _Header->getVersion();}
130 
131 //------------------------------------------------------------------------------
132 // Printing the MicroBlock structure
133 void RawSummaryDCMData::print(std::ostream& os) const {
134 
135  const uint32_t size_of_data = EXECUTE_FUNCTION(sizeofdata)();
136 
137  os<<boost::format("\n---SummaryDCMData---------------------------------------------(size=%u, version=%u)\n")
138  % size_of_data % _version;
139 
140  printBuffer(os);
141 
142  for(uint32_t i = 0; i < size_of_data; ++i){
143  os<<" ";
144  printWord(i, false, os);
145  os<<"\n";
146  }
147 
148  _Header->print(os);
149  printBinary(_Buffer, _Header->sizeofdata(), os);
150 }
151 
152 //------------------------------------------------------------------------------
153 // Size of the MicroBlock _Buffer in words
155  if(!_Header) return 0;
156  return _Header->sizeofdata() + _Header->getNumEntries() * summarydcmdatapoint::RAWSUMMARYDCMDATAPOINT_SIZE;
157 }
158 
160  {
161  if(_Header->getNumEntries() - 1 < idx) return NULL;
162  void* pointer = (void*)&RAWBUFF32[_Header->sizeofdata() + 3*idx];
163  return new daqdataformats::RawSummaryDCMDataPoint(pointer, 0);
164  }
165 
166 }}// end of namespaces
#define EXECUTE_FUNCTION(FULLFUNCTIONNAME)
Execute and return the delegate.
Definition: Macros.h:54
#define sizeofdata_t
Definition: FunctionBind.h:30
#define VERSION_NAMESPACE
#define EXECUTE_ON_DEBUG(x)
Debugging macros.
Definition: RawDAQData.h:34
bool addDataPoints(const std::list< std::pair< uint64_t, uint16_t > > &dcmlist, const uint8_t type)
::xsd::cxx::tree::type type
Definition: Database.h:110
daqdataformats::RawSummaryDCMDataHeader * _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
#define RAWBUFF32
Definition: RawDAQData.h:16
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.
daqdataformats::RawSummaryDCMDataPoint * getDataPoint(const uint32_t idx) const
MicroBlock Header reference.