otsdaq  v1_01_03
 All Classes Namespaces Functions
DataDecoder.cc
1 #include "otsdaq-core/DataDecoders/DataDecoder.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 
5 #include <iostream>
6 #include <cassert>
7 #include <unistd.h>
8 
9 using namespace ots;
10 
11 
12 
13 //========================================================================================================================
14 DataDecoder::DataDecoder(void)
15 {}
16 
17 //========================================================================================================================
18 DataDecoder::~DataDecoder(void)
19 {}
20 
21 //========================================================================================================================
22 void DataDecoder::convertBuffer(const std::string& buffer, std::queue<uint32_t>& convertedBuffer, bool invert)
23 {
24  for(unsigned int i=0; i<buffer.length(); i+=4 )
25  convertedBuffer.push(convertBuffer(buffer, i, invert));
26 }
27 
28 //========================================================================================================================
29 uint32_t DataDecoder::convertBuffer(const std::string& buffer, unsigned int bufferIndex, bool invert)
30 {
31  if(invert)
32  return (unsigned int)(((unsigned char)buffer[bufferIndex ]) << 24)
33  + (unsigned int)(((unsigned char)buffer[bufferIndex+1]) << 16)
34  + (unsigned int)(((unsigned char)buffer[bufferIndex+2]) << 8)
35  + (unsigned int)( (unsigned char)buffer[bufferIndex+3]);
36  else
37  return (unsigned int)((unsigned char)buffer[bufferIndex ])
38  + (unsigned int)(((unsigned char)buffer[bufferIndex+1]) << 8)
39  + (unsigned int)(((unsigned char)buffer[bufferIndex+2]) << 16)
40  + (unsigned int)(((unsigned char)buffer[bufferIndex+3]) << 24);
41 
42 }
43 
44 //========================================================================================================================
45 bool DataDecoder::isBCOHigh(uint32_t data)
46 {
47  return bcoDataDecoder_.isBCOHigh(data);
48 }
49 
50 //========================================================================================================================
51 bool DataDecoder::isBCOLow(uint32_t data)
52 {
53  return bcoDataDecoder_.isBCOLow(data);
54 }
55 
56 //========================================================================================================================
57 bool DataDecoder::isTriggerLow(uint32_t data)
58 {
59  return triggerDataDecoder_.isTriggerLow(data);
60 }
61 
62 //========================================================================================================================
63 bool DataDecoder::isTriggerHigh(uint32_t data)
64 {
65  return triggerDataDecoder_.isTriggerHigh(data);
66 }
67 
68 //========================================================================================================================
69 bool DataDecoder::isFSSRData(uint32_t data)
70 {
71  return FSSRDataDecoder_.isFSSR(data);
72 }
73 
74 //========================================================================================================================
75 bool DataDecoder::isVIPICData(uint32_t data)
76 {
77  return VIPICDataDecoder_.isVIPIC(data);
78 }
79 
80 //========================================================================================================================
81 bool DataDecoder::isPSI46Data(uint32_t data)
82 {
83  return PSI46DataDecoder_.isPSI46(data);
84 }
85 
86 //========================================================================================================================
87 bool DataDecoder::isPSI46DigData(uint32_t data)
88 {
89  return PSI46DigDataDecoder_.isPSI46Dig(data);
90 }
91 
92 //========================================================================================================================
93 uint64_t DataDecoder::mergeBCOHighAndLow(uint32_t dataBCOHigh, uint32_t dataBCOLow)
94 {
95  return bcoDataDecoder_.mergeBCOHighAndLow(bcoDataDecoder_.decodeBCOHigh(dataBCOHigh),bcoDataDecoder_.decodeBCOLow(dataBCOLow));
96 }
97 
98 //========================================================================================================================
99 uint64_t DataDecoder::mergeTriggerHighAndLow(uint32_t dataTriggerHigh, uint32_t dataTriggerLow)
100 {
101  return triggerDataDecoder_.mergeTriggerHighAndLow(triggerDataDecoder_.decodeTriggerHigh(dataTriggerHigh),triggerDataDecoder_.decodeTriggerLow(dataTriggerLow));
102 }
103 
104 //========================================================================================================================
105 void DataDecoder::insertBCOHigh(uint64_t& bco, uint32_t dataBCOHigh)
106 {
107  bcoDataDecoder_.insertBCOHigh(bco,dataBCOHigh);
108 }
109 
110 //========================================================================================================================
111 void DataDecoder::insertBCOLow(uint64_t& bco, uint32_t dataBCOLow)
112 {
113  bcoDataDecoder_.insertBCOLow(bco,dataBCOLow);
114 }
115 
116 //========================================================================================================================
117 void DataDecoder::decodeData(uint32_t data, DetectorDataBase** decodedData)
118 {
119  if(isFSSRData(data))
120  {
121  FSSRDataDecoder_.decode(data);
122  *decodedData = (DetectorDataBase*)(&FSSRDataDecoder_);
123  }
124  else if(isVIPICData(data))
125  {
126  VIPICDataDecoder_.decode(data);
127  *decodedData = (DetectorDataBase*)(&VIPICDataDecoder_);
128  }
129  else if(isPSI46DigData(data))
130  {
131  PSI46DigDataDecoder_.decode(data);
132  *decodedData = (DetectorDataBase*)(&PSI46DigDataDecoder_);
133  }
134  else
135  *decodedData = 0;
136 }