ATLAS Offline Software
Loading...
Searching...
No Matches
LArABBADecoder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6//#include "eformat/index.h"
8
9static const InterfaceID IID_ILArABBADecoder("LArABBADecoder", 1, 0);
10
11
12using namespace OFFLINE_FRAGMENTS_NAMESPACE;
13
14LArABBADecoder::LArABBADecoder(const std::string& type, const std::string& name,
15 const IInterface* parent )
16 : AthAlgTool(type,name,parent)
17{
18 declareInterface< LArABBADecoder >( this );
19
20}
21
22const InterfaceID& LArABBADecoder::interfaceID( )
23{ return IID_ILArABBADecoder; }
24
25
26
28
29
31 return StatusCode::SUCCESS;
32}
33
35 return StatusCode::SUCCESS;
36}
37
39{
40
41 bool ret=false;
42 // Check fragment validity:
43 try {
44 ret=re->check();
45 }
46 catch (eformat::Issue& ex) {
47 ATH_MSG_WARNING( "Exception while checking eformat fragment validity: " << ex.what() );
48 ret=false;
49 }
50 if (!ret) {
51 ATH_MSG_ERROR( "Got invalid RawEvent fragment" );
52 return StatusCode::FAILURE;
53 }
54
55 //Build TOC
56 std::map<eformat::SubDetectorGroup, std::vector<const uint32_t*> > robIndex;
57 eformat::helper::build_toc(*re, robIndex );
58 std::map<eformat::SubDetectorGroup, std::vector<const uint32_t*> >::const_iterator robIt = robIndex.find(eformat::LAR);
59 if (robIt!=robIndex.end()) {
60 const std::vector<const uint32_t*>& robs = robIt->second;
61 for (const uint32_t* pRob :robs) {
62 try {
63 ROBFragment robFrag(pRob);
64 //fillCollection(&pRob,coll);
65 fillCollection(&robFrag,coll);
66 }
67 catch (eformat::Issue& ex) {
68 ATH_MSG_WARNING ( " exception thrown by ROBFragment, badly corrupted event. Abort decoding " );
69 coll->clear();
70 break;
71 }
72 }//end loop over robs
73 }//end if got LAr-RODs
74 return StatusCode::SUCCESS;
75}
76
77
79{
81 LArDigit * scDigit=0 ;
82
83 //FIXME: Check validity
84 uint32_t nData = robFrag->rod_ndata();
85 const uint32_t* p=robFrag->rod_data();
86 if (nData < 3) {
87 ATH_MSG_WARNING ( "Error reading bytestream event: "
88 << "Empty ROD block (less than 3 words) for source ID " << robFrag->rod_source_id() );
89 return;
90 }
91 else
92 //int rob_source_id;
93 robFrag->rod_source_id();
94 //std::cout << "rob_source_id: " << robFrag->rob_source_id() << std::endl;
95 //std::cout << "rod_source_id: " << robFrag->rod_source_id() << std::endl;
96 unsigned int n = robFrag->payload_size_word();
97 //std::cout << "payload size: " << n << std::endl;
98
99 std::vector<std::string> string;
100 int x=0x0;
101 int nsamples = p[0];
102 //std::cout << "nsamples :" << std::hex << nsamples << std::endl;
103 for(unsigned int s=1;s<n-13;s+=6) {
104 //std::cout << "Fragmentsize :" << n << std::endl;
105 std::string ss;
106 for (unsigned int k=0;k<6;++k){
107 x = p[s+k];
108 //std::cout << "x :" << x << std::endl;
109 std::ostringstream oss;
110 oss << std::hex << x;
111 if (oss.str().size() == 7){
112 //std::cout << "oss: " << oss.str() << std::endl;
113 //std::cout << "here: " << ss << std::endl;
114 ss.append("0");
115 //std::cout << "adding 0: " << ss << std::endl;
116 }
117 ss += oss.str();
118 //std::cout << "oss: " << oss.str() << ", oss_size: " << oss.str().size() << std::endl;
119 }
120 //std::cout << "ss: " << ss << "ss_size:" << ss.size() <<std::endl;
121 string.push_back(std::move(ss));
122 }
123//std::cout << "string size: "<<string.size() << std::endl;
124
125
126
127constexpr int nFibers = 20;
128constexpr int nchannels = 8;
129constexpr int Nabbachannels = nFibers * nchannels;
130
131constexpr int fiberSeq[16] = {0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1};
132constexpr int adcSeq[16] = {1,0,1,0,3,2,3,2,5,4,5,4,7,6,7,6};
133
134std::vector< std::vector< std::vector<int> > > abbasamples;
135abbasamples.resize(nFibers);
136
137std::vector<std::vector<short>> abba_channel_samples;
138abba_channel_samples.resize(Nabbachannels);
139
140for (int fib=0;fib < nFibers; ++fib){
141 abbasamples[fib].resize(nchannels);
142 for (int ch = 0; ch < nchannels; ++ch){
143 abbasamples[fib][ch].resize(nsamples);
144 int Nchannel = fib*8 + ch;
145 abba_channel_samples[Nchannel].resize(nsamples);
146 }
147 }
148
149//std::cout << "x: " << abbasamples.size() << ", y: " << abbasamples[0].size() << ", z: " << abbasamples[0][0].size() << std::endl;
150
151 for (int fib=0;fib < nFibers; fib+=2){
152 for (int sam=0; sam < nsamples; sam++){
153 int zx = sam + (fib/2)*nsamples;
154 const std::string &wx = string[zx];
155 int k = 0;
156 for (int m = 0; m < 16; ++m){ //16 size of fiberSeq array
157 int fiber_number = fiberSeq[m];
158 int adc_number = adcSeq[m];
159 int idx = k*3;
160 std::stringstream ss;
161 char mysample[3];
162 //std::cout << "idx: " << idx << std::endl;
163 for (int j = idx; j < idx+3; ++j){
164 int i = j%3;
165 //std::cout << "j: " << j << "i: " << i << " wx_size: " << wx.size() << std::endl;
166 mysample[i] = wx[j];
167 }
168 ss << mysample;
169 //std::cout << "ss: " << ss << std::endl;
170 short mysample_int;
171 ss >> std::hex >> mysample_int;
172 int fb = fiber_number+fib;
173 int ch = adc_number;
174 int abbachannel = fb*8+ch;
175 k++;
176 //std::cout << "fiber: " << fb << std::endl;
177 //std::cout << "channel: " << ch << std::endl;
178 //std::cout << "samples: " << sam << std::endl;
179 //std::cout << "mysample int: " << mysample_int << std::endl;
180 //std::cout << "k: " << k << std::endl;
181 abbasamples[fb][ch][sam] = mysample_int;
182 abba_channel_samples[abbachannel][sam] = mysample_int;
183 //std::cout << "abbasamples: " << abbasamples[fb][ch][sam] << std::endl;
184 //std::cout << "abba_channel_samples, abbachannel, sam: " << abba_channel_samples[abbachannel][sam] <<", " << abbachannel << ", " << sam <<std::endl;
185 }
186 }
187 }
188//std::cout << "size: " << abba_channel_samples.size() << std::endl;
189
190std::map<int, HWIdentifier> abba_mapping;
191
192
193int iphi = 0;
194switch (robFrag->rod_source_id())
195{
196case 0x410511:
197 iphi=19;
198 break;
200//case 0x410522:
201case 0x410512:
202 iphi=18;
203 break;
204case 0x410521:
205 iphi=20;
206 break;
208case 0x410522:
209 iphi=21;
210 break;
211
212default:
213msg(MSG::ERROR) << "ROD_source_id not found" << endmsg;
214}
215
216// Dumping of full event data
217/*for (int fib = 0; fib < nFibers; ++fib) {
218 std::cout << std::dec << "fibre: " << fib << std::endl;
219 for (int ch = 0; ch < nchannels; ++ch) {
220 std::cout << "channel: " << ch << " -- ";
221 for (unsigned int sampl = 0; sampl < abbasamples[fib][ch].size(); ++sampl) {
222 std::cout << abbasamples[fib][ch][sampl] << " ";
223 }
224 std::cout << std::endl;
225 }
226}*/
227
228// k-code detection and removal
229/*std::vector<bool> k_code_detected;
230std::vector<bool> k_code_expected;
231
232k_code_detected.resize(nchannels);
233k_code_expected.resize(nchannels);
234
235k_code_expected.at(0) = false;
236k_code_expected.at(1) = false;
237k_code_expected.at(2) = true;
238k_code_expected.at(3) = true;
239k_code_expected.at(4) = true;
240k_code_expected.at(5) = true;
241k_code_expected.at(6) = false;
242k_code_expected.at(7) = true;
243
244for (int fib = 0; fib < nFibers; ++fib) {
245 for (unsigned int sampl = 1; sampl < abbasamples[fib][0].size()-1; ++sampl) {
246 for (int ch = 0; ch < nchannels; ++ch) {
247 if (2 * abbasamples[fib][ch][sampl] - (abbasamples[fib][ch][sampl-1] + abbasamples[fib][ch][sampl+1]) > 3000) k_code_detected.at(ch) = true;
248 else k_code_detected.at(ch) = false;
249 }
250
251 // General output in case of all channels match k-code requirement
252 bool kcode_match = true;
253
254 for (int ch = 0; ch < nchannels; ++ch) {
255 if (!(k_code_expected.at(ch) == k_code_detected.at(ch))) kcode_match = false;
256 }
257
258 // General output in case of one channel matching k-code requirement
259 //bool kcode_match = false;
260 //
261 //for (int ch = 0; ch < nchannels; ++ch) {
262 // if (k_code_detected.at(ch)) kcode_match = true;
263 //}
264
265 if (kcode_match) {
266 std::cerr << "Detected k-code in fibre " << fib << " (iphi = " << iphi << ") at sampl " << sampl << " with the following properties:" << std::endl;
267
268 for (int ch_print = 0; ch_print < nchannels; ++ch_print) {
269 std::cerr << "channel: " << ch_print << " -- ";
270 for (unsigned int sampl_print = sampl-1; sampl_print < sampl+2; ++sampl_print) {
271 std::cerr << abbasamples[fib][ch_print][sampl_print] << " ";
272 }
273 std::cerr << std::endl;
274 }
275 }
276 }
277}*/
278
279
280ABBAMapping::fill(&abba_mapping, iphi);
281
282
283for (std::size_t index_abba_channel_samples = 0; index_abba_channel_samples < abba_channel_samples.size(); ++index_abba_channel_samples) {
284 auto abba_mapping_search = abba_mapping.find(index_abba_channel_samples);
285 if (abba_mapping_search == abba_mapping.end()) {
286 msg(MSG::WARNING) << "No mapping for index_abba_channel_samples: "<<std::dec<<index_abba_channel_samples << endmsg;
287 continue;
288 }
289
290 HWIdentifier channelID = (*abba_mapping_search).second;
291 //std::cout << index_abba_channel_samples << ", channelID: " << channelID << std::endl;
292 std::vector<short> adcValues = abba_channel_samples[index_abba_channel_samples];
293 //std::cout << "size adcValues: " << adcValues.size() << std::endl;
294 scDigit=new LArDigit(channelID,dummyGain,std::move(adcValues));
295
296 //std::cout << "channelID: "<< channelID << std::endl;
297 //std::cout << "adcValues size: "<< adcValues.size() << std::endl;
298
299/*
300if ((adcValues.at(0) < 800) ||(adcValues.at(1) < 800) ||(adcValues.at(2) < 800)||(adcValues.at(3) < 800) ||(adcValues.at(4) < 800) ||(adcValues.at(5) < 800)||(adcValues.at(6) < 800)){
301//std::cout << "abba_channel_samples[0], [1], [2], ...[6]: " << adcValues.at(0) << ", " << adcValues.at(1) << ", " << adcValues.at(2) << ", " <<adcValues.at(3) << ", " <<adcValues.at(4) << ", " << adcValues.at(5)<< ", " <<adcValues.at(6) <<std::endl;
302}
303if ((adcValues.at(7) < 800) ||(adcValues.at(8) < 800) ||(adcValues.at(9) < 800)||(adcValues.at(10) < 800) ||(adcValues.at(11) < 800) ||(adcValues.at(12) <800)){
304//std::cout << "abba_channel_samples[7]...[12]" << adcValues.at(7) << ", " <<adcValues.at(8) << ", " << adcValues.at(9) << ", " << adcValues.at(10) << ", " << adcValues.at(11) << ", " <<adcValues.at(12)<<std::endl;
305}
306if ((adcValues.at(13) < 800) ||(adcValues.at(14) < 800) ||(adcValues.at(15) < 800)||(adcValues.at(16) < 800) ||(adcValues.at(17) < 800) ||(adcValues.at(18) < 800)){
307//std::cout << "abba_channel_samples[13]...[18]" << adcValues.at(13) << ", " <<adcValues.at(14) << ", " << adcValues.at(15) << ", " << adcValues.at(16) << ", " << adcValues.at(17) << ", " <<adcValues.at(18)<<std::endl;
308}
309if ((adcValues.at(19) < 800) ||(adcValues.at(20) < 800) ||(adcValues.at(21) < 800)||(adcValues.at(22) < 800) ||(adcValues.at(23) < 800) ||(adcValues.at(24) < 800)){
310//std::cout << "abba_channel_samples[19]...[24]" << adcValues.at(19) << ", " <<adcValues.at(20) << ", " << adcValues.at(21) << ", " << adcValues.at(22) << ", " << adcValues.at(23) << ", " <<adcValues.at(24)<<std::endl;
311}
312if ((adcValues.at(25) < 800) ||(adcValues.at(26) < 800) ||(adcValues.at(27) < 800)||(adcValues.at(28) < 800) ||(adcValues.at(29) < 800) ||(adcValues.at(30) < 800)){
313//std::cout << "abba_channel_samples[25]...[30]" << adcValues.at(25) << ", " <<adcValues.at(26) << ", " << adcValues.at(27) << ", " << adcValues.at(28) << ", " << adcValues.at(29) << ", " <<adcValues.at(30)<<std::endl;
314}
315if ((adcValues.at(31) < 800) ||(adcValues.at(32) < 800) ||(adcValues.at(33) < 800)||(adcValues.at(34) < 800) ||(adcValues.at(35) < 800) ||(adcValues.at(36) < 800)){
316//std::cout << "abba_channel_samples[31]...[36]" << adcValues.at(31) << ", " <<adcValues.at(32) << ", " << adcValues.at(33) << ", " << adcValues.at(34) << ", " << adcValues.at(35) << ", " <<adcValues.at(36)<<std::endl;
317}
318if ((adcValues.at(37) < 800) ||(adcValues.at(38) < 800) ||(adcValues.at(39) < 800)||(adcValues.at(40) < 800) ||(adcValues.at(41) < 800) ||(adcValues.at(42) < 800)){
319//std::cout << "abba_channel_samples[37]...[42]" << adcValues.at(37) << ", " <<adcValues.at(38) << ", " << adcValues.at(39) << ", " << adcValues.at(40) << ", " << adcValues.at(41) << ", " <<adcValues.at(42)<<std::endl;
320}
321if ((adcValues.at(43) < 800) ||(adcValues.at(44) < 800) ||(adcValues.at(45) < 800)||(adcValues.at(46) < 800) ||(adcValues.at(47) < 800) ||(adcValues.at(48) < 800)){
322//std::cout << "abba_channel_samples[43]...[48]" << adcValues.at(43) << ", " <<adcValues.at(44) << ", " << adcValues.at(45) << ", " << adcValues.at(46) << ", " << adcValues.at(47) << ", " <<adcValues.at(48)<<std::endl;
323}
324if ((adcValues.at(49) < 800) ||(adcValues.at(50) < 800) ||(adcValues.at(51) < 800)||(adcValues.at(52) < 800) ||(adcValues.at(53) < 800) ||(adcValues.at(54) < 800)){
325//std::cout << "abba_channel_samples[49]...[54]" << adcValues.at(49) << ", " <<adcValues.at(50) << ", " << adcValues.at(51) << ", " << adcValues.at(52) << ", " << adcValues.at(53) << ", " <<adcValues.at(54)<<std::endl;
326}
327if ((adcValues.at(55) < 800) ||(adcValues.at(56) < 800) ||(adcValues.at(57) < 800)||(adcValues.at(58) < 800) ||(adcValues.at(59) < 800) ||(adcValues.at(59) < 800)){
328//std::cout << "abba_channel_samples[55]...[60]" << adcValues.at(55) << ", " <<adcValues.at(56) << ", " << adcValues.at(57) << ", " << adcValues.at(58) << ", " << adcValues.at(59) << ", " <<adcValues.at(59)<<std::endl;
329}
330*/
331
332
333
334 coll->push_back(scDigit);
335 //std::cout << "pushback scDigit to coll" << std::endl;
336 }
337
338abbasamples.clear();
339
340 return;
341
342
343}
const boost::regex re(r_e)
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
static const InterfaceID IID_ILArABBADecoder("LArABBADecoder", 1, 0)
static Double_t ss
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Definition RawEvent.h:37
#define x
static void fill(std::map< int, HWIdentifier > *toFill, int iphi)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
MsgStream & msg() const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
void clear()
Erase all the elements in the collection.
static const InterfaceID & interfaceID()
virtual StatusCode initialize() override
LArABBADecoder(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode finalize() override
virtual ~LArABBADecoder()
Destructor.
StatusCode convert(const RawEvent *re, LArDigitContainer *coll) const
void fillCollection(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment *pROB, LArDigitContainer *coll) const
Container class for LArDigit.
Liquid Argon digit base class.
Definition LArDigit.h:25
STL class.
@ LARHIGHGAIN
Definition CaloGain.h:18
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27