RawNanoSliceV0.cpp
Go to the documentation of this file.
1 #include "DAQDataFormats/RawNanoSliceV0.h"
2 #include <boost/format.hpp>
3 
4 /// It is requred to
5 /// 1. include DAQDataFormats/DataFormatFirst.inc
6 /// 2. define CURRENT_CLASS
7 /// 3. define CURRENT_CLASS_VERSION for version of the class
8 /// OR define LAST_CLASS_VERSION for the main structure of the class
9 /// 4. (optional) define CURRENT_FIELDS_SUB_NAMESPACE
10 /// 5. include DAQDataFormats/DataFormatLast.inc
11 /// before the declaration of the DataFormat version class in the header.
12 #include "DAQDataFormats/DataFormatFirst.inc"
13 #define CURRENT_CLASS RawNanoSlice
14 #define CURRENT_CLASS_VERSION 0
15 #define CURRENT_FIELDS_SUB_NAMESPACE rawnano
16 #include "DAQDataFormats/DataFormatLast.inc"
17 
18 namespace daqdataformats{
19 
21 
22 namespace VERSION_NAMESPACE{
23  //------------------------Constructors------------------------------------------
25  RawDAQData(version, true)
26  ,ZEROOUT_GET_AND_SET(PulseHeight)
27  ,ZEROOUT_GET_AND_SET(TimeStamp)
28  ,ZEROOUT_GET_AND_SET(Reserved)
29  ,ZEROOUT_FUNCTION(initWithData)
30  ,ZEROOUT_FUNCTION(setParameters)
31  ,ZEROOUT_FUNCTION(checkReservedForCafe)
32  ,ZEROOUT_FUNCTION(initWithDataInternal)
33  ,_Header(NULL)
34 {}
35 //------------------------------------------------------------------------------
37  RawDAQData(nano.Header.Version, true)
38  ,ZEROOUT_GET_AND_SET(PulseHeight)
39  ,ZEROOUT_GET_AND_SET(TimeStamp)
40  ,ZEROOUT_GET_AND_SET(Reserved)
44  ,ZEROOUT_FUNCTION(initWithDataInternal)
45  ,_Header(NULL)
46 {}
47 
48 //------------------------------------------------------------------------------
50  RawDAQData(copyin)
51  ,DEEPCOPY_GET_AND_SET(PulseHeight)
52  ,DEEPCOPY_GET_AND_SET(TimeStamp)
53  ,DEEPCOPY_GET_AND_SET(Reserved)
57  ,DEEPCOPY_FUNCTION(initWithDataInternal)
58  ,_Header(NULL)
59 {
60 }
61 //------------------------Destructor--------------------------------------------
63  if(_Header)
64  delete _Header;
65 }
66 
67 //------------------------------------------------------------------------------
68 // Default Initialization of Data members
70 
71  /// After using resetBufferSource header is already constructed
72  /// Now we need to initialize it
73  _Header->init();
74 
75  /// Initialize the Reserved word to 0xCAFE (for version 0)
77 }
78 
79 //------------------------------------------------------------------------------
80 void RawNanoSlice::initWithData(const NanoSlice& nanoslice_parameters){
81 
82  /// After using resetBufferSource header is already constructed
83  /// Now we need to initialize it
84  _Header->initWithData(nanoslice_parameters.Header);
85 
86  /// Initialize the Reserved word to 0xCAFE (for version 0)
88 
89  /// Additionally, set TimeStamp and PulseHeight from nanoslice_parameters
90  EXECUTE_FUNCTION(setTimeStamp) (nanoslice_parameters.TimeStamp);
91  EXECUTE_FUNCTION(setPulseHeight)(nanoslice_parameters.PulseHeight);
92 }
93 
94 //------------------------------------------------------------------------------
96 
97 //------------------------------------------------------------------------------
98 // Set all parameters
99 bool RawNanoSlice::setParameters(const NanoSlice& nanoslice_parameters){
100  EXECUTE_FUNCTION(setTimeStamp) (nanoslice_parameters.TimeStamp);
101  EXECUTE_FUNCTION(setPulseHeight)(nanoslice_parameters.PulseHeight);
102 
103  /// At this point header must be already defined
104  _Header->setParameters(nanoslice_parameters.Header);
105 
106  return true;
107 }
108 
109 //------------------------------------------------------------------------------
110 bool RawNanoSlice::setBufferSource(const void* pointer){
111 
112  _Buffer = (void*)pointer;
113 
114  /// If Header is already defined, then set its buffer source
115  /// Otherwise, need to construct it
116  if(_Header)return _Header->setBufferSource(pointer);
117 
118  _Header = new daqdataformats::RawNanoSliceHeader(pointer, _version); ///< version of the NanoSliceHeader equals the version of the NanoSlice
119 
120  return true;
121 }
122 
123 //------------------------------------------------------------------------------
124 // Printing the NanoSlice
125 void RawNanoSlice::print(std::ostream& os) const {
126 
127  _Header->print(os);
128 
129  os<<boost::format(" NanoSlice Body: TimeStamp=%u PulseHeight=%u Reserved=%u ")
130  %EXECUTE_FUNCTION(getTimeStamp)()
133 
134  const uint32_t size_of_data = EXECUTE_FUNCTION(sizeofdata)();
135 
136  os<<"Data size = "<<size_of_data<<"\n";
137 
138 
139  os<<"\nRAW(hex):";
140  for(uint32_t i = 0; i < size_of_data; ++i){
141  printWord(i,false, os);
142  os<<" ";
143  }
144 
145  os<<"\nRAW(binary):";
146  for(uint32_t i = 0; i < size_of_data; ++i){
147  if(i > 0)os<<" ";
148  printWord(i,true, os);
149  os<<std::endl;
150  }
151 }
152 
153 
154 //------------------------------------------------------------------------------
156 {
157  if(!fNanoSliceVersionConvention)fNanoSliceVersionConvention = new NanoSliceVersionConvention();
158  return fNanoSliceVersionConvention->getNSamples(_version);
159 }
160 //------------------------------------------------------------------------------
162 {
163  if(!fNanoSliceVersionConvention)fNanoSliceVersionConvention = new NanoSliceVersionConvention();
164  return fNanoSliceVersionConvention->getNPretriggeredSamples(_version);
165 }
166 //------------------------------------------------------------------------------
168 {
169  if(!fNanoSliceVersionConvention)fNanoSliceVersionConvention = new NanoSliceVersionConvention();
170  return fNanoSliceVersionConvention->getEncodeType(_version);
171 }
172 
173 
174 }}// end of namespaces
175 
#define ZEROOUT_FUNCTION(FUNC)
Definition: FunctionBind.h:52
Encode_Type
All encoding types.
#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 VERSION_NAMESPACE
uint32_t getPulseHeight() const
Get Pulse Height for version > 0 == Get Value1.
daqdataformats::RawNanoSliceHeader * _Header
The Nanoslice header pointer.
Data structure for holding all the nanoslice data of interest.
#define ZEROOUT_GET_AND_SET(FUNC)
Definition: FunctionBind.h:56
std::string Header(std::string label)
uint32_t getNSamples(const version_t ver) const
Get the number of samples.
uint32_t getNPretriggeredSamples(const version_t ver) const
Get number of pretriggered samples.
bool setPulseHeight(const uint32_t ph)
Set Pulse Height for version > 0 == Set Value1.
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
const XML_Char * version
Definition: expat.h:187
Encode_Type getEncodeType() const
get the type of encoding for the samples in the nanoslice
bool setReserved(const uint32_t)
Set for Reserved word is not allowed for version 1, because there is no Reserved field.
Class to hold the data from the FEBs in correct formats.
Encode_Type getEncodeType(const version_t ver) const
Get the encoding type.
int32_t version_t
Definition: RawDAQData.h:72
static NanoSliceVersionConvention * fNanoSliceVersionConvention
void print(std::ostream &os=std::cout) const
uint32_t getReserved() const
Get Reserved is not allowed for version 1, because there is no Reserved field.
Class to hold the data from the FEBs in correct formats.
uint32_t getNPretriggeredSamples() const
Get number of pretriggered samples.
bool setParameters(const NanoSlice &)
Set method for all parameters of the NanoSlice.
bool checkReservedForCafe() const
Check if the reserved word is 0xcafe is not allowed for version 1, because there is no Reserved field...
uint32_t getNSamples() const
Get total number of samples in the nanoslice.