RawConfigurationNameV0.cpp
Go to the documentation of this file.
1 #include "DAQDataFormats/RawConfigurationNameV0.h"
2 #include "DAQDataFormats/BitFields.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 RawConfigurationName
15 #define CURRENT_CLASS_VERSION 0
16 #define CURRENT_FIELDS_SUB_NAMESPACE rawconfname
17 #include "DAQDataFormats/DataFormatLast.inc"
18 
19 namespace daqdataformats{
20 namespace VERSION_NAMESPACE{
21 
22 //------------------------------------------------------------------------------
23 // Default constructor
25  RawDAQData(version, true, (sizeofdata_t) &RawConfigurationName::getPredefinedSize)
26  ,ZEROOUT_GET_AND_SET(Version)
27  ,ZEROOUT_GET_AND_SET(Size)
28  ,ZEROOUT_GET(HeaderSize)
29  ,ZEROOUT_GET_AND_SET(Name)
30  ,ZEROOUT_GET_AND_SET(Char1)
31  ,ZEROOUT_GET_AND_SET(Char2)
32  ,ZEROOUT_GET_AND_SET(Char3)
33  ,ZEROOUT_GET_AND_SET(Char4)
34 { }
35 
36 //------------------------------------------------------------------------------
38  RawDAQData(copyin)
39  ,DEEPCOPY_GET_AND_SET(Version)
41  ,DEEPCOPY_GET(HeaderSize)
43  ,DEEPCOPY_GET_AND_SET(Char1)
44  ,DEEPCOPY_GET_AND_SET(Char2)
45  ,DEEPCOPY_GET_AND_SET(Char3)
46  ,DEEPCOPY_GET_AND_SET(Char4)
47 { }
48 
50 
51 //------------------------------------------------------------------------------
52 // Initialization of data members
54  EXECUTE_FUNCTION(setVersion)(_version);
55  EXECUTE_FUNCTION(setSize)(EXECUTE_FUNCTION(getHeaderSize)());
56 }
57 
58 //------------------------------------------------------------------------------
59 uint32_t RawConfigurationName::getHeaderSize() const {return rawconfname::WORD_Char;}
60 
61 //------------------------------------------------------------------------------
62 // Setters
63 uint32_t RawConfigurationName::setName(const std::string& name){
64 
65  /// If empty name, set the Data size to the size of header and return
66  if(name.size() == 0){
67  RETURN_FUNCTION(setSize)(EXECUTE_FUNCTION(getHeaderSize)());
68  }
69 
70  /// There are 4 bytes in word
71  /// size of the name block in words
72  const uint32_t size = (name.size() - 1) / 4 + 1;
73 
74  const uint32_t total_block_size = size + EXECUTE_FUNCTION(getHeaderSize)();
75 
76  PRINT_ON_DEBUG("Setting to: "<<name<<" size="<<total_block_size);
77 
78  /// Go ahead and set the name size
79  EXECUTE_FUNCTION(setSize)(total_block_size);
80 
81  PRINT_ON_DEBUG("Size now ="<<EXECUTE_FUNCTION(sizeofdata)());
82 
83  /// If buffer is internal, resize it
84  if(_shouldBufferBeInternal){
85  resizeInternalBuffer(total_block_size);
86  checkBufferInternalness();
87  }
88 
89  /// counter for the char
90  uint32_t ichar = 0;
91 
92  /// Fill the Namespace fields
93  for(uint32_t iword = 0; iword < size ; ++iword){
94  for(uint32_t ichar_in_word = 0; ichar_in_word < 4; ++ichar_in_word){
95  /// If current char is still one of the characters of the string
96  /// that we are setting it to, read it
97  /// Otherwise, make it zero.
98  uint32_t letter = 0;
99  if(ichar < name.size())
100  letter = name[ichar];
101 
102  /// set the char
103  switch(ichar_in_word){
104  case 0: EXECUTE_FUNCTION(setChar1)(letter, iword); break;
105  case 1: EXECUTE_FUNCTION(setChar2)(letter, iword); break;
106  case 2: EXECUTE_FUNCTION(setChar3)(letter, iword); break;
107  case 3: EXECUTE_FUNCTION(setChar4)(letter, iword); break;
108  }// end of cases
109 
110  ++ichar;
111  }}/// end of loops
112 
113  return size;
114 }
115 //------------------------------------------------------------------------------
116 // Setters for Chars
117 bool RawConfigurationName::setChar1(const uint32_t letter, const uint32_t word_number){
118  uint32_t* pointer = &(RAWBUFF32[word_number + rawconfname::WORD_Char]);
119  BITFIELDSET(*pointer, letter, rawconfname::MASK_Char1, rawconfname::SHIFT_Char1);
120  return true;
121 }
122 bool RawConfigurationName::setChar2(const uint32_t letter, const uint32_t word_number){
123  uint32_t* pointer = &(RAWBUFF32[word_number + rawconfname::WORD_Char]);
124  BITFIELDSET(*pointer, letter, rawconfname::MASK_Char2, rawconfname::SHIFT_Char2);
125  return true;
126 }
127 bool RawConfigurationName::setChar3(const uint32_t letter, const uint32_t word_number){
128  uint32_t* pointer = &(RAWBUFF32[word_number + rawconfname::WORD_Char]);
129  BITFIELDSET(*pointer, letter, rawconfname::MASK_Char3, rawconfname::SHIFT_Char3);
130  return true;
131 }
132 bool RawConfigurationName::setChar4(const uint32_t letter, const uint32_t word_number){
133  uint32_t* pointer = &(RAWBUFF32[word_number + rawconfname::WORD_Char]);
134  BITFIELDSET(*pointer, letter, rawconfname::MASK_Char4, rawconfname::SHIFT_Char4);
135  return true;
136 }
137 
138 //------------------------------------------------------------------------------
139 // Getters
140 uint32_t RawConfigurationName::getName(std::string& name) const{
141  name.clear();
142 
143  /// size of data minus header
144  const uint32_t size_of_data = EXECUTE_FUNCTION(sizeofdata)() - EXECUTE_FUNCTION(getHeaderSize)();
145 
146  /// Fill the Namespace fields
147  for(uint32_t iword = 0 ; iword < size_of_data ; ++iword){
148  for(uint32_t ichar_in_word = 0 ; ichar_in_word < 4 ; ++ichar_in_word){
149 
150  uint32_t current_char = 0;
151 
152  if (ichar_in_word == 0 )
153  current_char = EXECUTE_FUNCTION(getChar1)(iword);
154  else if (ichar_in_word == 1 )
155  current_char = EXECUTE_FUNCTION(getChar2)(iword);
156  else if (ichar_in_word == 2 )
157  current_char = EXECUTE_FUNCTION(getChar3)(iword);
158  else if (ichar_in_word == 3 )
159  current_char = EXECUTE_FUNCTION(getChar4)(iword);
160 
161  if(current_char > 0)
162  name += (char)current_char;
163 
164  }}// end of loops over word and char
165 
166  return name.size();
167 }
168 
169 //------------------------------------------------------------------------------
170 // Getters for Chars
171 uint32_t RawConfigurationName::getChar1(const uint32_t word_number) const {
172  const uint32_t* pointer = &(RAWBUFF32[word_number + rawconfname::WORD_Char]);
173  return BITFIELDGET(*pointer, rawconfname::MASK_Char1, rawconfname::SHIFT_Char1);
174 
175 }
176 uint32_t RawConfigurationName::getChar2(const uint32_t word_number) const {
177  const uint32_t* pointer = &(RAWBUFF32[word_number + rawconfname::WORD_Char]);
178  return BITFIELDGET(*pointer, rawconfname::MASK_Char2, rawconfname::SHIFT_Char2);
179 
180 }
181 uint32_t RawConfigurationName::getChar3(const uint32_t word_number) const {
182  const uint32_t* pointer = &(RAWBUFF32[word_number + rawconfname::WORD_Char]);
183  return BITFIELDGET(*pointer, rawconfname::MASK_Char3, rawconfname::SHIFT_Char3);
184 
185 }
186 uint32_t RawConfigurationName::getChar4(const uint32_t word_number) const {
187  const uint32_t* pointer = &(RAWBUFF32[word_number + rawconfname::WORD_Char]);
188  return BITFIELDGET(*pointer, rawconfname::MASK_Char4, rawconfname::SHIFT_Char4);
189 }
190 
191 
192 //------------------------------------------------------------------------------
193 // Print the DataBlock structure
194 void RawConfigurationName::print(std::ostream& os) const {
195 
196  os<<boost::format("\n---RawConfigurationName----------------------------------------------------size=%u\n") % sizeofdata();
197 
198  printBuffer(os,true,true,false,false,false,"\n",1);
199 
201  EXECUTE_FUNCTION(getName)(name);
202  os<<"Name = \""<<name<<"\"\n";
203 
204 }
205 
206 //------------------------------------------------------------------------------
207 // Size of the _Buffer in words
208 uint32_t RawConfigurationName::sizeofdata()const { return getSize();}
209 
210 
211 //------------------------------------------------------------------------------
212 bool RawConfigurationName::setBufferSource(const void* pointer){
213 
214  _Buffer = (void*)pointer;
215  _shouldBufferBeInternal = isInternalBuffer();
216 
217  _function_sizeofdata = (sizeofdata_t) &RawConfigurationName::sizeofdata;
218  return true;
219 }
220 
221 
222 //------------------------------------------------------------------------------
223 // This is a general method to read the microslice from millislice_buffer to _Buffer
225  const uint32_t header_size = EXECUTE_FUNCTION(getHeaderSize)();
226 
227  PRINT_ON_DEBUG(__PRETTY_FUNCTION__<<" 0");
228  /// Read the header and unpack it to find out the size of the RawConfigurationName
229  void* buffer_new = readDataGeneral(buffer, header_size, 0);
230 
231  /// No need to check for internalness here, because we always have at least a header
232 
233  PRINT_ON_DEBUG(__PRETTY_FUNCTION__<<" 1");
234  /// Now, read the rest of the millislice
235  buffer_new = readDataGeneral(buffer_new, sizeofdata() - header_size, header_size);
236 
237  checkBufferInternalness();
238 
239  return buffer_new;
240 
241  }// end of readData(void*)
242 
243 }}// end of namespaces
const XML_Char * name
Definition: expat.h:151
#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
#define ZEROOUT_GET(FUNC)
Definition: FunctionBind.h:53
#define DEEPCOPY_GET(FUNC)
Definition: FunctionBind.h:41
::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
#define BITFIELDGET(block, mask, shift)
Definition: BitFields.h:23
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
const XML_Char * version
Definition: expat.h:187
#define BITFIELDSET(block, data, mask, shift)
Definition: BitFields.h:24
#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.
enum BeamMode string