RawConfigurationSystemIDV0.cpp
Go to the documentation of this file.
1 #include "DAQDataFormats/RawConfigurationSystemIDV0.h"
2 #include "DAQDataFormats/RawConfigurationName.h"
3 #include "DAQDataFormats/BitFields.h"
4 #include <boost/format.hpp>
5 
6 /// It is requred to
7 /// 1. include DAQDataFormats/DataFormatFirst.inc
8 /// 2. define CURRENT_CLASS
9 /// 3. define CURRENT_CLASS_VERSION for version of the class
10 /// OR define LAST_CLASS_VERSION for the main structure of the class
11 /// 4. (optional) define CURRENT_FIELDS_SUB_NAMESPACE
12 /// 5. include DAQDataFormats/DataFormatLast.inc
13 /// before the declaration of the DataFormat version class in the header.
14 #include "DAQDataFormats/DataFormatFirst.inc"
15 #define CURRENT_CLASS RawConfigurationSystemID
16 #define CURRENT_CLASS_VERSION 0
17 #define CURRENT_FIELDS_SUB_NAMESPACE rawconfsysid
18 #include "DAQDataFormats/DataFormatLast.inc"
19 
20 namespace daqdataformats{
21 namespace VERSION_NAMESPACE{
22 
23 //------------------------------------------------------------------------------
24 // Default constructor
26  RawDAQData(version, true, (sizeofdata_t) &RawConfigurationSystemID::getPredefinedSize)
27  ,ZEROOUT_GET_AND_SET(Version)
28  ,ZEROOUT_GET_AND_SET(DAQSystemID)
29  ,ZEROOUT_GET_AND_SET(DAQSubSystemID)
30  ,ZEROOUT_GET_AND_SET(VersionName)
31  ,ZEROOUT_FUNCTION(getHeaderSize)
32  ,_versionName(NULL)
33  ,_configurationName_version(rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION)
34 {}
35 
37  RawDAQData(copyin)
38  ,DEEPCOPY_GET_AND_SET(Version)
39  ,DEEPCOPY_GET_AND_SET(DAQSystemID)
40  ,DEEPCOPY_GET_AND_SET(DAQSubSystemID)
41  ,DEEPCOPY_GET_AND_SET(VersionName)
42  ,DEEPCOPY_FUNCTION(getHeaderSize)
43  ,_versionName(NULL)
45 
46 { }
47 
48 //------------------------------------------------------------------------------
49 // Destructor
51 
52 //------------------------------------------------------------------------------
53 // Initialization of data members
55  EXECUTE_FUNCTION(setVersion)(_version);
56 }
57 
58 //------------------------------------------------------------------------------
59 // Printing the RawConfigurationSystemID structure
60 void RawConfigurationSystemID::print(std::ostream& os) const{
61 
62  //printBuffer(os,true,true,true,true,true);
63  //if(_versionName)_versionName->print(os);
64 
65 
66  os<<boost::format("\n---RawConfigurationSystemID---------------------------------------------Version =%u, Size is %u words\n")
67  % getVersion()% sizeofdata();
68 
69  printBuffer(os);
70 
71 
72  os<<boost::format("DAQSystemID=%u " ) % EXECUTE_FUNCTION(getDAQSystemID)();
73  os<<boost::format("DAQSubSystemID=%u " ) % EXECUTE_FUNCTION(getDAQSubSystemID)();
74 
75  if(_versionName){
76  std::string version_name;
77  EXECUTE_FUNCTION(getVersionName)(version_name);
78  os<<boost::format("DAQSystemVersion=\"%s\"") % version_name.c_str();
79  }
80 
81  os<<"\n";
82 
83 }
84 
85 //------------------------------------------------------------------------------
86 uint32_t RawConfigurationSystemID::getHeaderSize() const {return rawconfsysid::HEADER_SIZE;}
87 
88 //------------------------------------------------------------------------------
89 uint32_t RawConfigurationSystemID::getVersionName( std::string& str) const {return _versionName->getName(str);}
90 uint32_t RawConfigurationSystemID::setVersionName(const std::string& str) {
91 
92  if(_shouldBufferBeInternal){
93 
94  const uint32_t new_size = EXECUTE_FUNCTION(getHeaderSize)()
95  + _versionName->getHeaderSize()
96  + (str.size()/4 + 1);
97 
98  resizeInternalBuffer(new_size);
99 
100  /// Check pointers after each read or resize buffer
101  checkBufferInternalness();
102  }
103 
104 
105  return _versionName->setName(str);
106 }
107 
108 //------------------------------------------------------------------------------
109 // Size of the RawConfigurationSystemID _Buffer in words
110 uint32_t RawConfigurationSystemID::sizeofdata() const { return EXECUTE_FUNCTION(getHeaderSize)() + _versionName->sizeofdata();}
111 
112 
113 //------------------------------------------------------------------------------
115 
116  _Buffer = (void*)pointer;
117  _shouldBufferBeInternal = isInternalBuffer();
118 
119  const uint32_t* version_name_pointer = (uint32_t*)(_Buffer) + EXECUTE_FUNCTION(getHeaderSize)();
120 
121  /// If _versionName is already defined, then set its buffer source
122  /// Otherwise, need to construct it
123  if(_versionName){
124  return _versionName->setBufferSource(version_name_pointer);
125  }
126 
127  if(_shouldBufferBeInternal){
128 
129  /// Figure out the minimum RawConfigurationName size
131 
132  resizeInternalBuffer(EXECUTE_FUNCTION(getHeaderSize)() + confname_tmp.sizeofdata());
133 
134  /// Check pointers after each read or resize buffer
135  checkBufferInternalness();
136 
138 
139  /// Need to initialize to set the size.
140  /// For internal buffers only and only if it's non-zero
141  if(_versionName->sizeofdata() < _versionName->getHeaderSize())
142  _versionName->init();
143  }
144  else{
146  }
147 
148 
149  _function_sizeofdata = (sizeofdata_t)&RawConfigurationSystemID::sizeofdata;
150 
151  return true;
152 }
153 
154 
155 
156 //------------------------------------------------------------------------------
157 // This is a general method to read the microslice from millislice_buffer to _Buffer
159 {
160  /// Read SystemID header and Configuration Name header
161  const uint32_t header_stuff = EXECUTE_FUNCTION(getHeaderSize)() + _versionName->getHeaderSize();
162 
163  void* buffer_new = readDataGeneral(buffer, header_stuff, 0);
164 
165  /// Now we know sizeofdata
166  buffer_new = readDataGeneral(buffer_new, EXECUTE_FUNCTION(sizeofdata)() - header_stuff, header_stuff);
167  /// Check pointers after each read or resize buffer
168  checkBufferInternalness();
169 
170  return buffer_new;
171 }// end of readData(void*)
172 
173 
174 }}// 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
#define sizeofdata_t
Definition: FunctionBind.h:30
#define VERSION_NAMESPACE
::xsd::cxx::tree::buffer< char > buffer
Definition: Database.h:179
#define ZEROOUT_GET_AND_SET(FUNC)
Definition: FunctionBind.h:56
RawConfigurationName * _versionName
SubSystem&#39;s version name.
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
static const version_t DAQDATAFORMAT_UNKNOWN_VERSION
Definition: RawDAQData.h:81
Class to hold the data from the FEBs in correct formats.
enum BeamMode string