RawMilliSliceIndex.cpp
Go to the documentation of this file.
1 #include "DAQDataFormats/RawMilliSliceIndex.h"
2 #include "DAQDataFormats/DataFormatException.h"
3 
4 namespace daqdataformats{
5 
6 //------------------------------------------------------------
7 // Default constructor
10  ,_Header(NULL)
11 {
12  _function_sizeofdata = (sizeofdata_t) &RawMilliSliceIndex::sizeofdata;
15 }
16 
17 //------------------------------------------------------------------------------
19  RawDAQData(copy_in)
20  ,_Header(NULL)
21 {
22  lastOperationsInDeepCopy(copy_in);
23 }
24 
25 //------------------------------------------------------------------------------
26 RawMilliSliceIndex::RawMilliSliceIndex(const void* millisliceheader_buffer):
28  ,_Header(NULL)
29 {
30  _function_sizeofdata = (sizeofdata_t) &RawMilliSliceIndex::sizeofdata;
31 
32  copy(millisliceheader_buffer);
33 }
34 //------------------------------------------------------------
35 // Destructor
37  if(_Header) delete _Header;
38 }
39 
40 //------------------------------------------------------------
41 // Initialize the data members
43 
44  /// After using resetBufferSource header is already constructed
45  /// Now we need to initialize it
46  _Header->init();
47 }
48 
49 //------------------------------------------------------------------------------
50 // Getters
51 uint32_t RawMilliSliceIndex::getTime (const uint32_t iindex) const {
52  const uint32_t word = iindex * getSizeOfOneIndex() + rawmilliindx::WORD_Time;
53  return BITFIELDGET(RAWBUFF32[word], rawmilliindx::MASK_Time, rawmilliindx::SHIFT_Time);
54 }
55 
56 //------------------------------------------------------------------------------
57 uint32_t RawMilliSliceIndex::getOffset (const uint32_t iindex) const {
58  const uint32_t word = iindex * getSizeOfOneIndex() + rawmilliindx::WORD_Offset;
59  return BITFIELDGET(RAWBUFF32[word], rawmilliindx::MASK_Offset, rawmilliindx::SHIFT_Offset);
60 }
61 //------------------------------------------------------------------------------
62 uint32_t RawMilliSliceIndex::getIndexNumber() const { return _Header->getIndexNumber();}
63 
64 //------------------------------------------------------------------------------
65 bool RawMilliSliceIndex::isClosed() const {return _Header->isClosed();}
66 
67 //------------------------------------------------------------------------------
68 // Add an index
69 bool RawMilliSliceIndex::addIndex (const uint32_t time_length, const uint32_t offset){
70 
73  /// Check pointers after each read or resize buffer
75  }
76 
77  const uint32_t index = getIndexNumber();
78  setTime(index, time_length);
79  setOffset(index, offset);
80  return advanceIndexNumber();
81 }
82 
83 //------------------------------------------------------------------------------
84 // Setters
85 // Set time of the "iindex"-th index
86 bool RawMilliSliceIndex::setTime (const uint32_t iindex, const uint32_t time_length){
87  const uint32_t word = iindex * getSizeOfOneIndex() + rawmilliindx::WORD_Time;
88  BITFIELDSET(RAWBUFF32[word], time_length, rawmilliindx::MASK_Time, rawmilliindx::SHIFT_Time);
89  return true;
90 }
91 
92 //------------------------------------------------------------------------------
93 // Set Offset of the "iindex"-th index
94 bool RawMilliSliceIndex::setOffset (const uint32_t iindex, const uint32_t offset){
95  const uint32_t word = iindex * getSizeOfOneIndex() + rawmilliindx::WORD_Offset;
96  BITFIELDSET(RAWBUFF32[word], offset, rawmilliindx::MASK_Offset, rawmilliindx::SHIFT_Offset);
97  return true;
98 }
99 
100 //------------------------------------------------------------------------------
101 bool RawMilliSliceIndex::setIndexNumber(uint32_t indx){return _Header->setIndexNumber(indx);}
102 
103 //------------------------------------------------------------------------------
105 
106 //------------------------------------------------------------------------------
107 bool RawMilliSliceIndex::setClosed(bool closeness){return _Header->setClosed(closeness);}
108 
109 //------------------------------------------------------------------------------
110 bool RawMilliSliceIndex::setBufferSource(const void* pointer){
111  _Buffer = (void*) pointer;
112 
114 
115  /// If Header is already defined, then set its buffer source
116  /// Otherwise, need to construct it
117  if(_Header)return _Header->setBufferSource(pointer);
118 
119  _Header = new RawMilliSliceIndexHeader(pointer); ///< version of the NanoSliceHeader equals the version of the NanoSlice
120 
121  return true;
122 }
123 
124  //------------------------------------------------------------------------------
125 // Print the MilliSlice header information
126 void RawMilliSliceIndex::print(std::ostream& os) const{
127 
128  _Header->print(os);
129 
130  os<<"\nMilliSliceIndex:";
131 
132  const uint32_t size = sizeofdata();
133 
134  for(uint32_t i = 0; i < size; ++i){
135  os<<" ";
136  printWord(i,false, os);
137  }
138 
139  os<<"\nMilliSliceIndex RAW bits (converted, if required, to native endian format):";
140  for(uint32_t i = 0; i < size; ++i){
141  os<<std::endl;
142  printWord(i,true, os);
143  }
144 }
145 
146 //------------------------------------------------------------------------------
147 // Size of _Buffer in words
149 
150  /// If header is currently not defined, just return 1. Eventually it will be defined
151  if(!_Header) return 1;
152 
153  uint32_t size = _Header->sizeofdata()
155 
156  if(isClosed()) size += _Header->sizeofdata();
157 
158  return size;
159 }
160 
161 //------------------------------------------------------------------------------
162 // Close MilliSlice Index
164 
165  if(isClosed())return false;
166 
167  /// Set Close bit in the header
168  setClosed(true);
169 
170  /// Copy Header into the end of the MilliSlice Index
172 
173  /// Check pointers after each read or resize buffer
175 
176  return true;
177 }
178 
179 
180 //------------------------------------------------------------------------------
181 // This is a general method to read the microslice from millislice_buffer to _Buffer
183 {
184  void* buffer_copy = (void*) buffer;
185 
186  const uint32_t millisliceindex_header_size = _Header->sizeofdata();
187 
188  /// Read the header and find out the size of the millislice
189  buffer_copy = readDataGeneral(buffer_copy, millisliceindex_header_size, 0);
190 
191  /// Check pointers after each read
192  /// To be able to use sizeofdata()
194 
195  /// Now, read the rest of the millislice
196  buffer_copy = readDataGeneral(buffer_copy, sizeofdata() - millisliceindex_header_size, millisliceindex_header_size);
197 
198  /// Check pointers after each read or resize buffer
200 
201  return buffer_copy;
202  }// end of readData(void*)
203 
204 }// end of namespace
void * readDataGeneral(const void *buffer)
General ReadData method when the sizeofdata is known.
Definition: RawDAQData.cpp:186
#define sizeofdata_t
Definition: FunctionBind.h:30
bool setTime(const uint32_t, const uint32_t)
void print(std::ostream &os=std::cout) const
bool setOffset(const uint32_t, const uint32_t)
bool setBufferSource(const void *)
We are not going to overload these funtions, so no need to declare them virtual.
Definition: RawDAQData.cpp:880
void * _Buffer
All data formats need to have _Buffer and a Data structure. _Buffer will be common.
Definition: RawDAQData.h:276
uint32_t getOffset(const uint32_t) const
RawMilliSliceIndex(const uint32_t size=DEFAULT_MILLISLICEINDEX_MAXIMUM_SIZE)
void * getBuffer() const
Definition: RawDAQData.h:131
virtual void copy(const RawDAQData &)
Deep copy from the DAQDataFormat.
Definition: RawDAQData.cpp:830
bool checkBufferInternalness()
If the buffer should be internal, check it&#39;s pointers and reassign them.
Definition: RawDAQData.cpp:612
bool _shouldBufferBeInternal
Auxillary variable that holds whether the buffer should be external or internal.
Definition: RawDAQData.h:286
::xsd::cxx::tree::buffer< char > buffer
Definition: Database.h:179
void lastOperationsInDeepCopy(const RawDAQData &copy_in)
Need to perform these operations in Deep Copy constructor.
Definition: RawDAQData.cpp:151
void print(std::ostream &os=std::cout) const
Method for printing the content of the Buffer.
Definition: RawDAQData.cpp:500
#define BITFIELDGET(block, mask, shift)
Definition: BitFields.h:23
daqdataformats::RawMilliSliceIndexHeader * _Header
RawMilliSliceIndexHeader.
bool isInternalBuffer() const
Definition: RawDAQData.h:141
uint32_t getTime(const uint32_t) const
void * readData(const void *buffer)
#define BITFIELDSET(block, data, mask, shift)
Definition: BitFields.h:24
bool addToInternalBuffer(const uint32_t size_of_data_to_add)
Add Zeros to internal buffer.
Definition: RawDAQData.cpp:284
#define RAWBUFF32
Definition: RawDAQData.h:16
void printWord(const uint32_t iword, const bool is_bynary_printing, std::ostream &os=std::cout) const
Print word from Buffer.
Definition: RawDAQData.cpp:440
bool reserveInternalBuffer(const uint32_t size_of_data)
Reserve space for the internal buffer to some predetermined size.
Definition: RawDAQData.cpp:271
Class to hold the data from the FEBs in correct formats.
bool addIndex(const uint32_t, const uint32_t)
#define init_t
Definition: FunctionBind.h:29