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