otsdaq  v2_01_00
VIPICData.cc
1 #include "otsdaq-core/DataDecoders/VIPICData.h"
2 
3 #include <iostream>
4 
5 using namespace ots;
6 
7 
8 //========================================================================================================================
9 VIPICData::VIPICData(void)
10 {
11 }
12 
13 //========================================================================================================================
14 VIPICData::~VIPICData(void)
15 {
16 }
17 
18 //========================================================================================================================
19 bool VIPICData::isVIPIC(uint32_t data)
20 {
21  int type = data & 0x0f;
22  if (type == 2)
23  return true;
24  else
25  return false;
26 }
27 
28 //========================================================================================================================
29 VIPICData& VIPICData::decode(uint32_t word)
30 {
31  // stibId_ = 0x03 & (word >> 30) ; //FIXME: Missing in Jones' code
32  // channelNumber_ = 0x07 & (word >> 27) ;
33  // chipId_ = 0x07 & (word >> 24) ;
34  // set_ = 0x1f & (word >> 12) ;
35  // stripNumber_ = 0x0f & (word >> 17) ;
36  // bco_ = 0xff & (word >> 4) ;
37  // adc_ = 0x7 & (word >> 1) ;
38 
39  stibId_ = 0x03 & (word >> 30) ; //FIXME: Missing in Jones' code
40  channelNumber_ = 0x07 & (word >> 27) ;
41  chipId_ = 0x07 & (word >> 24) ;
42  set_ = 0x1f & (word >> 12) ;
43  stripNumber_ = 0x0f & (word >> 17) ;
44  bco_ = 0xff & (word >> 8 ) ;
45  pixel_ = 0xfff & (word >> 20) ;
46 
47 
48  return *this;
49 
50  // switch (type)
51  // {
52  // case 8:
53  // {
54  // switch(datatype)
55  // {
56  // case 2:
57  // {
58  // bco_counter &= 0x0000000000ffffffULL;
59  // bco_counter |= ((uint64_t)data)<<24;
60  // std::cout << __COUT_HDR_FL__ << "BCO = " << hex << bco_counter << dec << " (" << bco_counter-last_bco << ")" << std::endl;
61  // if ( bco_counter - last_bco > 256 ) {
62  // nhit = 0;
63  // }
64  // break;
65  // }
66  // case 1:
67  // {
68  // last_bco = bco_counter;
69  // bco_counter &= 0xffffffffff000000ULL;
70  // bco_counter |= (uint64_t)data;
71  // break;
72  // }
73  // case 0x0a: {
74  // int bco = (word>>8)&0xff;
75  // int trignum_low = word>>16;
76  // std::cout << __COUT_HDR_FL__ << "Trigger low = " << trignum_low << ", bco = " << hex << bco << dec << std::endl;
77  // break;
78  // }
79  // case 0x0b: {
80  // int trignum_high = word>>8;
81  // std::cout << __COUT_HDR_FL__ << "Trigger high = " << trignum_high << std::endl;
82  // break;
83  // }
84  // case 0x0c:
85  // case 0x0d:
86  // case 0x0e:
87  // case 0x0f: {
88  // int trig0 = (word>>16)&0xff;
89  // int trig1 = (word>>24)&0xff;
90  // int bco = (word>>8)&0xff;
91  // std::cout << __COUT_HDR_FL__ << "Trigger word " << 15-datatype << " : " << std::endl;
92  // for ( int k=7; k>=0; k-- ) {
93  // if ( (trig1&(1<<k)) ) {
94  // std::cout << __COUT_HDR_FL__ << "#" << std::endl;
95  // }
96  // else {
97  // std::cout << __COUT_HDR_FL__ << "_" << std::endl;
98  // }
99  // }
100  // std::cout << __COUT_HDR_FL__ << " " << std::endl;
101  // for ( int k=7; k>=0; k-- ) {
102  // if ( (trig0&(1<<k)) ) {
103  // std::cout << __COUT_HDR_FL__ << "#" << std::endl;
104  // }
105  // else {
106  // std::cout << __COUT_HDR_FL__ << "_" << std::endl;
107  // }
108  // }
109  // std::cout << __COUT_HDR_FL__ << " " << hex << bco << dec << std::endl;
110  // break;
111  // }
112  // default:
113  // //FIXME: Raises error of invalid data
114  // break;
115  // }
116  // }
117  // }
118 
119 
120 
121  // if ( type == 8 ) {
122  // if ( datatype == 2 ) {
123  // bco_counter &= 0x0000000000ffffffULL;
124  // bco_counter |= ((uint64_t)data)<<24;
125  // std::cout << __COUT_HDR_FL__ << "BCO = " << hex << bco_counter << dec << " (" << bco_counter-last_bco << ")" << std::endl;
126  // if ( bco_counter - last_bco > 256 ) {
127  // nhit = 0;
128  // }
129  // }
130  // if ( datatype == 1 ) {
131  // last_bco = bco_counter;
132  // bco_counter &= 0xffffffffff000000ULL;
133  // bco_counter |= (uint64_t)data;
134  // }
135  // if ( datatype <= 0x0f && datatype >= 0x0c ) {
136  // int trig0 = (word>>16)&0xff;
137  // int trig1 = (word>>24)&0xff;
138  // int bco = (word>>8)&0xff;
139  // std::cout << __COUT_HDR_FL__ << "Trigger word " << 15-datatype << " : " << std::endl;
140  // for ( int k=7; k>=0; k-- ) {
141  // if ( (trig1&(1<<k)) ) {
142  // std::cout << __COUT_HDR_FL__ << "#" << std::endl;
143  // }
144  // else {
145  // std::cout << __COUT_HDR_FL__ << "_" << std::endl;
146  // }
147  // }
148  // std::cout << __COUT_HDR_FL__ << " " << std::endl;
149  // for ( int k=7; k>=0; k-- ) {
150  // if ( (trig0&(1<<k)) ) {
151  // std::cout << __COUT_HDR_FL__ << "#" << std::endl;
152  // }
153  // else {
154  // std::cout << __COUT_HDR_FL__ << "_" << std::endl;
155  // }
156  // }
157  // std::cout << __COUT_HDR_FL__ << " " << hex << bco << dec << std::endl;
158  // }
159  // if ( datatype == 0x0a ) {
160  // int bco = (word>>8)&0xff;
161  // int trignum_low = word>>16;
162  // std::cout << __COUT_HDR_FL__ << "Trigger low = " << trignum_low << ", bco = " << hex << bco << dec << std::endl;
163  // }
164  // if ( datatype == 0x0b ) {
165  // int trignum_high = word>>8;
166  // std::cout << __COUT_HDR_FL__ << "Trigger high = " << trignum_high << std::endl;
167  // }
168  // }
169 // else if (type & 1) {
170 // std::cout << __COUT_HDR_FL__ << "Channel: " << chan_ << " chipid: " << chipid_ << " set: " << set_ << " strip: " << strip_ << " adc: " << adc_ << " bco: " << hex << bco << dec << " istrip: " << istrip_ << std::endl;
171 // if ( chan > 6 || istrip > 639 ) {
172 // std::cout << __COUT_HDR_FL__ << "Bad word " << i << " = " << hex << word << dec << " = " << chan << "," << chipid << "," << set << "," << strip << " = " << istrip << std::endl;
173 // }
174 // nhit += 1;
175 // }
176 // else if ( type == 2 ) {
177 // int pix = (word>>20)&0xfff;
178 // int count = (word>>16)&0x0f;
179 // int bco = (word>>8)&0xff;
180 // std::cout << __COUT_HDR_FL__ << hex << setw(8) << setfill('0') << word << dec << " VIPIC pixel " << pix << " count = " << count << ", bco = " << hex << bco << dec << std::endl;
181 // }
182 // else if ( type == 10 ) {
183 // int chan = (word>>24)&0x0f;
184 // int count = (word>>16)&0xff;
185 // int bco = (word>>8)&0xff;
186 // std::cout << __COUT_HDR_FL__ << hex << setw(8) << setfill('0') << word << dec << " PSI46 channel " << chan << " count = " << count << ", bco = " << hex << bco << dec << std::endl;
187 // }
188 // else if ( type == 6 ) {
189 // int adc = (word>>8)&0xff;
190 // int row = (word>>16)&0x3f;
191 // int col = (word>>22)&0xf;
192 // std::cout << __COUT_HDR_FL__ << hex << setw(8) << setfill('0') << word << dec << " PSI46 hit col " << col << " row " << row << ", adc = " << adc << std::endl;
193 // }
194 
195 
196  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << " Chan: " << chan << " chipId: " << (int)chipId_
197  // << " set: " << (unsigned int)set_ << " strip: " << (int)stripNumber_ << " bco: " << (int)bco_ << std::endl;
198 
199 }
200 
201 //========================================================================================================================
202 unsigned int VIPICData::getStibId(void)
203 {
204  return (unsigned int)stibId_;
205 }
206 
207 //========================================================================================================================
208 unsigned int VIPICData::getChannelNumber(void)
209 {
210  return (unsigned int)channelNumber_;
211 }
212 
213 //========================================================================================================================
214 unsigned int VIPICData::getChipId(void)
215 {
216  return (unsigned int)chipId_;
217 }
218 
219 //========================================================================================================================
220 unsigned int VIPICData::getStripNumber(void)
221 {
222  return (unsigned int)stripNumber_;
223 }
224 
225 //========================================================================================================================
226 unsigned int VIPICData::getBco(void)
227 {
228  return (unsigned int)bco_;
229 }
230 
231 //========================================================================================================================
232 unsigned int VIPICData::getCol(void)
233 {
234  return (unsigned int) pixel_ % 64;
235 }
236 
237 //========================================================================================================================
238 unsigned int VIPICData::getRow(void)
239 {
240  return (unsigned int) pixel_ / 64;
241 }