ATLAS Offline Software
ALFA_Decoder_charge.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <algorithm>
8 
9 static const InterfaceID IID_IALFA_Decoder_charge ("ALFA_Decoder_charge", 1, 0);
11 {
12  return IID_IALFA_Decoder_charge;
13 }
14 
16 // constructor
18 
19 ALFA_Decoder_charge::ALFA_Decoder_charge ( const std::string& type, const std::string& name,const IInterface* parent)
21 m_robDataProvider ("ROBDataProviderSvc",name)
22 //, m_ALFA_RawDataContainerReadOut(0), m_ALFA_RawDataCollectionReadOut(0), m_ALFA_RawDataReadOut_charge(0)
23 {
24 declareInterface<ALFA_Decoder_charge>(this);
25 
26 }
27 
28 
29 
31 // destructor
34 
35 
36 
37 
39 // initialize() -
42 
43 
44  StatusCode sc;
46  msg(MSG::DEBUG) << " ALFA_RoDDecoder_charge::initialize" << endmsg;
47  if (sc.isFailure()) return sc;
48 
49  // Get ROBDataProviderSvc
50  if (m_robDataProvider.retrieve().isFailure()) {
51  msg(MSG::FATAL) << "Failed to retrieve service " << m_robDataProvider << endmsg;
52  return StatusCode::FAILURE;
53  } else {
54  msg(MSG::DEBUG) << "Retrieved service " << m_robDataProvider << endmsg;
55  }
56 
57 
59 
60 
61  // Initialize decoding classes
65 
66 
67  return StatusCode::SUCCESS;
68 }
69 
70 
71 
72 
73 
74 
76 // finalize() -
79 
80 msg(MSG::DEBUG) << " ALFA_RoDDecoder_charge::FINALIZE" << endmsg;
81 
82 msg(MSG::DEBUG) << " Bytestream summary:" << m_fragment_number << " fragments found" << endmsg;
83 
84 
88 
89  return StatusCode::SUCCESS;
90 }
91 
92 
93 
95 // fillCollection() -
98  msg(MSG::DEBUG) << " ALFA_RoDDecoder_charge::fillCollection" << endmsg;
99 
100 ALFA_RawDataCollection_charge* collection = nullptr;
101 
102  uint32_t wordPos = 0;
103 
104  std::vector<uint32_t> VData;
105 
106  VData.clear();
107 
108 
109 uint32_t Event_num=0;
110 uint32_t Event_num_max=0;
111 uint16_t charge_hit;
112 
113 uint16_t tmpCharge=10;
114 uint16_t MBIdNum=0;
115 
116 uint32_t EcrId=1;
117 uint32_t LvL1 =0;
118 
119 uint32_t Count_evt=0;
120 
121 
122 uint16_t CountPMF0=0;
123 
124  int n=0;
125 
126  // Check the ROB and ROD fragment for lenght and version consistency
127 /*
128  try
129  {
130  robFrag->check();
131  }
132 
133  catch (eformat::Issue &ex)
134  {
135  msg(MSG::DEBUG) <<ex.what ()<< endmsg;
136  return StatusCode::FAILURE; // error in fragment - we search for no collection
137  }
138 
139  // Check the ROB status word for truncation or corruption.
140 
141  uint32_t nstat = robFrag->nstatus();
142 
143  if (nstat)
144  {
145  const uint32_t *it;
146  robFrag->status (it);
147 
148 
149  if (*it)
150  {
151  msg(MSG::DEBUG) << " Error in ROB status word: 0x" << endmsg;
152  return StatusCode::FAILURE;
153  }
154  }
155  */
156 
157  // set the data pointer type
158 
160 
161  robFrag->rod_data(vint);
162 
163  // get number of data words in the fragment
164  uint32_t size = robFrag->rod_ndata();
165 
166  // get source ID
167  uint32_t ROD_source_ID = robFrag->rod_source_id();
168 
169 
170  uint32_t ROD_LVL1_ID = robFrag->rod_lvl1_id();
171 
172 msg(MSG::DEBUG) << "============================" << std::endl;
173 msg(MSG::DEBUG) <<"Frag Size : " << robFrag->rod_fragment_size_word() << endmsg;
174 msg(MSG::DEBUG) <<"Header Size: " << robFrag->rod_header_size_word() << endmsg;
175 msg(MSG::DEBUG) <<"Source ID : " << ROD_source_ID << endmsg;
176 msg(MSG::DEBUG) <<"Run num : " << robFrag->rod_run_no() << endmsg;
177 msg(MSG::DEBUG) <<"Version : " << robFrag->rod_version() << endmsg;
178 msg(MSG::DEBUG) << " ROD_LVL1_ID " <<ROD_LVL1_ID<< endmsg;
179 msg(MSG::DEBUG) << "============================" << std::endl;
180 
181 
182 uint32_t evt_Id = ((robFrag->rod_lvl1_id()) & 0xFF000000) >> 24;
183 uint32_t lvl1_Id = ((robFrag->rod_lvl1_id()) & 0x00FFFFFF) ;
184 
185 
186 msg(MSG::DEBUG) <<" evt_Id : " << evt_Id << " lvl1_Id : " << lvl1_Id <<endmsg;
187 
188  /*msg(MSG::DEBUG) << " **********Decoder dumping the words******** "<< endmsg;
189 
190 if (size > 0) {
191 msg(MSG::DEBUG) << " The size of this ROD-read is "<< endmsg;
192  for (unsigned int i=0; i < size; i++)
193  msg(MSG::DEBUG) << " word " << i << " = " << MSG::hex << vint[i] << MSG::dec<< endmsg;
194  } else {
195 msg(MSG::DEBUG) << " Buffer size 0 ! "<< endmsg;
196  return StatusCode::FAILURE;
197  }*/
198 
199 
203 
204  int l=0;
205 
206  if(EcrId!=evt_Id) {
207  n++;
208  l=1;
209  }
210 
211  if (n==0) Event_num = LvL1;
212  else Event_num = ((robFrag->rod_lvl1_id()) & 0x00FFFFFF) + Event_num;
213 
214  LvL1 = ((robFrag->rod_lvl1_id()) & 0x00FFFFFF)+1 ;
215  EcrId = ((robFrag->rod_lvl1_id()) & 0xFF000000) >> 24;
216 
217  if(l==1) Event_num_max=Event_num;
218 
219  Event_num = ((robFrag->rod_lvl1_id()) & 0x00FFFFFF)+1 + Event_num_max;
220 
221  Count_evt++;
222  //if (Count_evt == maxEvt) break;
223 
224  msg(MSG::INFO) << " Event_num " << Event_num << " Count_evt " << Count_evt << endmsg;
225 
226 
227 
228 
230  {
231  msg(MSG::DEBUG) << " Found the beginning of buffer "<< endmsg;
232  // Check that Lvl1d matches the one from the ROD header. this is the number of event.it corresponds to m_ALFA_RawDataReadOut_charge->ecnt_BOT() and m_ALFA_RawDataReadOut_charge->ecnt_EOT()
233  msg(MSG::DEBUG) << " Level 1 Id : " << m_ALFA_RawDataCollectionReadOut->lvl1Id()<< endmsg;
234  } else {
235  msg(MSG::DEBUG) << " Beginning of block not found BOB "<< endmsg;
236  } // BOB
237 
238 
240 
241  //Check for corrupted data
242 
244  {
245  wordPos += 1;
246  if (wordPos >= size)
247  {
248  msg(MSG::ERROR)<<" Error: data corrupted" << endmsg;
249  return StatusCode::FAILURE;
250  }
252  }
253 
254 
256  {
257  msg(MSG::DEBUG) << " Found the beginning of Link BOL"<< endmsg;
258  msg(MSG::DEBUG) << " MrodNum BOL : " << m_ALFA_RawDataCollectionReadOut->MrodNum()<< " RODinput BOL : " <<m_ALFA_RawDataCollectionReadOut->RODinput()<< endmsg;
259 
260  } // is_BOL()
261 
263  {
264  msg(MSG::DEBUG)<<" Error: collection not found " << endmsg;
265  return StatusCode::FAILURE;
266  } // is_EOB()
267 
268 
269  wordPos += 1;
270  if (wordPos >= size) {
271  msg(MSG::ERROR)<<" Error: data corrupted"<< endmsg;
272  return StatusCode::FAILURE;
273  }
274 
275 
278 
280 
282 
283  msg(MSG::DEBUG)<<" Decoding data from Slot Id number : " << slotIdNum << endmsg;
284 
285 
286  // Loop on the TDC data words and create the corresponding RDO's
287 
289  {
290  wordPos += 1;
291  if (wordPos >= size)
292  {
293  msg(MSG::DEBUG)<<" Error: data corrupted" << endmsg;
294  return StatusCode::FAILURE;
295  }
296 
298 
299  uint16_t PMFIdNum;
300  uint16_t ChannelIdNum;
301  uint16_t ChargeNum;
302 
303 
305 
306  // if(m_ALFA_RawDataReadOut_charge->ChannelNumId() ==1) msg(MSG::DEBUG)<<" DECODER : PMFId " << m_ALFA_RawDataReadOut_charge->PMFId() << " ChannelNumId " << m_ALFA_RawDataReadOut_charge->ChannelNumId() << " ChargeChanId "<< m_ALFA_RawDataReadOut_charge->ChargeChanId() <<endmsg;
307 
308 
309 
311  // && m_ALFA_RawDataReadOut_charge->bit27_24()==1
312  // msg(MSG::DEBUG) << " Creation of the new collection"<< endmsg;
313 
314 
315  CountPMF0++;
316 
318 
319  for (unsigned int i=0;i<8;i++){
320 
321  charge_hit = (char) tmpCharge & 0x00000001;
322  tmpCharge>>=1;
323 
324  if(charge_hit==1){
325  MBIdNum=i+1;
326 
327  if(CountPMF0==1) collection = getCollection(MBIdNum,rdoCont );
328  if(collection) collection->SetMBId_POT(MBIdNum);
329 
330  if(CountPMF0==1) msg(MSG::DEBUG)<<" DECODER : MBIdNum " << MBIdNum << endmsg;
331 
332 
333  }
334 
335 
336  } // loop over MBs
337 
338  } // PMFId() ==0
339 
340 
341 
342 
344  // && m_ALFA_RawDataReadOut_charge->bit27_24()==0
345 
346 
348  ChannelIdNum = m_ALFA_RawDataReadOut_charge->ChannelNumId();
349  PMFIdNum = m_ALFA_RawDataReadOut_charge->PMFId();
350 
351  auto rawData_charge = std::make_unique< ALFA_RawData_charge >(PMFIdNum);
352 
353  rawData_charge->SetChannelNum_PMF(ChannelIdNum);
354  rawData_charge->SetPMFId_PMF(PMFIdNum);
355  rawData_charge->SetMBId_PMF(MBIdNum);
356  rawData_charge->SetChargeChan_PMF(ChargeNum);
357 
358 
359  msg(MSG::DEBUG)<<" PMFIdNum = " << PMFIdNum <<" ChannelIdNum = " << ChannelIdNum <<" chargeNum = " << ChargeNum << endmsg;
360 
361  std::vector<uint16_t> ChargeHitId;
362  ChargeHitId.push_back(ChargeNum);
363  rawData_charge->SetChargeChanVect_PMF(ChargeHitId);
364 
365  rawData_charge->addData(vint[wordPos]);
366  rawData_charge->PushBack_PMF(ChargeNum);
367 
368  if(collection) collection->push_back(rawData_charge.release());
369 
370 
371  } // PMFIdNum >0 && <24
372 
373 
374 
375 
376 
377  //if(m_ALFA_RawDataReadOut_charge->PMFId()==24) // PMF 24 contains charge infos
378  //{
379  //} //TSM PMF24
380 
381 
382  } // TSM_charge
383 
384 
385  } // End of loop on AMTs (EOT)
386 
387 
389  msg(MSG::DEBUG) << " Event Counter EOT : " << m_ALFA_RawDataReadOut_charge->ecnt_EOT()<< endmsg;
390  }
391 
392  wordPos += 1;
393  if (wordPos >= size) {
394  msg(MSG::DEBUG)<<" Error: data corrupted" << endmsg;
395  return StatusCode::FAILURE;
396  }
397 
398 
400  m_ALFA_RawDataReadOut_charge->decodeWord(vint[wordPos]);
401 
402  } // End of loop on TDCs (TWC)
403 
404  wordPos += 1;
405  if (wordPos >= size)
406  {
407  msg(MSG::DEBUG)<<" Error: data corrupted" << endmsg;
408  return StatusCode::FAILURE;
409  }
410 
412 
413 
414 
415  // take full event
416 const eformat::FullEventFragment<const uint32_t*> * event = m_robDataProvider->getEvent(Gaudi::Hive::currentContext());
417 
418 msg(MSG::DEBUG) << "========FULL Event=============" << std::endl;
419 msg(MSG::DEBUG) << "Event time (sec): " << (uint32_t)event->bc_time_seconds() << std::endl;
420 msg(MSG::DEBUG) << "Event time (ns): " << (uint32_t)event->bc_time_nanoseconds() << std::endl;
421 msg(MSG::DEBUG) << "Global ID: " << (uint32_t)event->global_id() << std::endl;
422 msg(MSG::DEBUG) << "Run Type: " << (uint32_t)event->run_type() << std::endl;
423 msg(MSG::DEBUG) << "Run Number: " << (uint32_t)event->run_no() << std::endl;
424 msg(MSG::DEBUG) << "Lumi Block: " << (uint32_t)event->lumi_block() << std::endl;
425 msg(MSG::DEBUG) << "Level1 ID: " << (uint32_t)event->lvl1_id() << std::endl;
426 msg(MSG::DEBUG) << "BCID: " << (uint32_t)event->bc_id() << std::endl;
427 msg(MSG::DEBUG) << "Level1 trig type: " << (uint32_t)event->lvl1_trigger_type() << std::endl;
428 msg(MSG::DEBUG) << "Level1 Nwords: " << (uint32_t)event->nlvl1_trigger_info() << std::endl;
429 msg(MSG::DEBUG) << "============================" << std::endl;
430 
431 uint32_t Time_StampID = event->bc_time_seconds();
432 uint32_t BC_ID = event->bc_id();
433 
434 if(collection) collection->SetTimeStamp_POT(Time_StampID);
435 if(collection) collection->SetBCId_POT(BC_ID);
436 
437 
438 
439 
440 
441 
442  } //EOB
443 
444 
446  {
447  msg(MSG::DEBUG) << " Found the end of block EOB ---------------------- "<< endmsg;
448  }
449 
450  wordPos += 1;
452 
453 
454  return StatusCode::SUCCESS;
455 }
456 
457 
459 // getCollection() - return collection corresponding to a particular channel
460 // if it exists in container, or create it if it doesn't
462 
464 
465 msg(MSG::DEBUG) << " ALFA_RoDDecoder_charge::getCollection" << endmsg;
466 
468 
470  bool collExists = false;
473 
474 
475  for (; it!=itE; ++it) {
476  if ((*it)->GetMBId_POT() == MBIdNum) {
477  collExists = true;
478  cont_it = it;
479  }
480  }
481  if (collExists) {
482  msg(MSG::DEBUG) << " Collection exists " << endmsg;
483  return nullptr;
484 
485  } else { // if collection does not exist create it
486  coll = new ALFA_RawDataCollection_charge(MBIdNum);
487  msg(MSG::DEBUG) << " create collection; MBId " << MBIdNum <<endmsg;
488  cont->push_back(coll); // add collection to container
489  }
490 
491 
492  return coll;
493 }
494 
495 
496 
ALFA_RawDataReadOut_charge::is_EOT
bool is_EOT() const
Definition: ALFA_RawDataReadOut_charge.h:96
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ALFA_RawDataReadOut_charge::ChargeChanId
uint16_t ChargeChanId() const
Definition: ALFA_RawDataReadOut_charge.h:113
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
ALFA_RawDataCollection_charge
RDOs : Chamber Service Module, collection of RawData.
Definition: ALFA_RawDataCollection_charge.h:19
ALFA_RawDataContainerReadOut::decodeWord
void decodeWord(uint32_t dataWord)
Definition: ALFA_RawDataContainerReadOut.cxx:26
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
ALFA_Decoder_charge::m_fragment_number
unsigned int m_fragment_number
Definition: ALFA_Decoder_charge.h:71
initialize
void initialize()
Definition: run_EoverP.cxx:894
xAOD::char
char
Definition: TrigDecision_v1.cxx:38
ALFA_RawDataCollectionReadOut::is_TWC
bool is_TWC() const
Definition: ALFA_RawDataCollectionReadOut.h:91
ALFA_RawDataReadOut_charge
Definition: ALFA_RawDataReadOut_charge.h:28
skel.it
it
Definition: skel.GENtoEVGEN.py:396
ALFA_RawDataReadOut_charge::is_TDCch
bool is_TDCch() const
Definition: ALFA_RawDataReadOut_charge.h:98
ALFA_Decoder_charge::m_robDataProvider
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Service for reading bytestream.
Definition: ALFA_Decoder_charge.h:74
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
ALFA_RawDataReadOut_charge::ChannelNumId
uint16_t ChannelNumId() const
Definition: ALFA_RawDataReadOut_charge.h:112
ALFA_RawDataReadOut_charge::SlotId
uint16_t SlotId() const
Definition: ALFA_RawDataReadOut_charge.h:103
ALFA_RawDataCollectionReadOut::is_BOL
bool is_BOL() const
Definition: ALFA_RawDataCollectionReadOut.h:89
TruthTest.itE
itE
Definition: TruthTest.py:25
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
ALFA_Decoder_charge::getCollection
ALFA_RawDataCollection_charge * getCollection(unsigned int MotherBoardId, ALFA_RawDataContainer_charge *cont)
Definition: ALFA_Decoder_charge.cxx:463
ALFA_Decoder_charge::interfaceID
static const InterfaceID & interfaceID()
Definition: ALFA_Decoder_charge.cxx:10
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
OFFLINE_FRAGMENTS_NAMESPACE::PointerType
const DataType * PointerType
Definition: RawEvent.h:25
ALFA_Decoder_charge::initialize
virtual StatusCode initialize()
Definition: ALFA_Decoder_charge.cxx:41
ALFA_RawDataCollection_charge::SetTimeStamp_POT
void SetTimeStamp_POT(uint32_t TimeStamp)
Definition: ALFA_RawDataCollection_charge.cxx:60
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
eformat::ROBFragment
Definition: L1CaloBsDecoderUtil.h:12
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
ALFA_RawDataReadOut_charge::PMFId
uint16_t PMFId() const
Definition: ALFA_RawDataReadOut_charge.h:111
ALFA_RawDataCollectionReadOut::decodeWord
void decodeWord(uint32_t dataWord)
Definition: ALFA_RawDataCollectionReadOut.cxx:27
ALFA_Decoder_charge.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ALFA_Decoder_charge::~ALFA_Decoder_charge
virtual ~ALFA_Decoder_charge()
Definition: ALFA_Decoder_charge.cxx:33
ALFA_RawDataCollectionReadOut::lvl1Id
uint32_t lvl1Id() const
Definition: ALFA_RawDataCollectionReadOut.h:95
ALFA_RawDataCollection_charge::SetBCId_POT
void SetBCId_POT(uint32_t BCId)
Definition: ALFA_RawDataCollection_charge.cxx:65
ALFA_RawDataReadOut_charge::ecnt_EOT
uint16_t ecnt_EOT() const
Definition: ALFA_RawDataReadOut_charge.h:106
ALFA_RawDataCollectionReadOut
Definition: ALFA_RawDataCollectionReadOut.h:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
ALFA_RawDataContainer_charge
This container provides acces to the PMF RDOs.
Definition: ALFA_RawDataContainer_charge.h:21
ALFA_RawDataCollection_charge::SetMBId_POT
void SetMBId_POT(uint16_t MB_number)
Definition: ALFA_RawDataCollection_charge.cxx:43
ALFA_RawDataCollectionReadOut::RODinput
uint16_t RODinput() const
Definition: ALFA_RawDataCollectionReadOut.h:105
ALFA_RawDataCollectionReadOut::MrodNum
uint16_t MrodNum() const
Definition: ALFA_RawDataCollectionReadOut.h:104
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
ALFA_RawDataCollectionReadOut::is_EOB
bool is_EOB() const
Definition: ALFA_RawDataCollectionReadOut.h:92
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
ALFA_Decoder_charge::fillCollection
StatusCode fillCollection(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment *robFrag, ALFA_RawDataContainer_charge *rdoCont, std::vector< unsigned int > *vecHash=NULL)
Definition: ALFA_Decoder_charge.cxx:97
ALFA_RawDataReadOut_charge::decodeWord
void decodeWord(uint32_t dataWord)
Definition: ALFA_RawDataReadOut_charge.cxx:30
AthAlgTool
Definition: AthAlgTool.h:26
ALFA_Decoder_charge::m_ALFA_RawDataContainerReadOut
ALFA_RawDataContainerReadOut * m_ALFA_RawDataContainerReadOut
Definition: ALFA_Decoder_charge.h:79
ALFA_Decoder_charge::m_ALFA_RawDataReadOut_charge
ALFA_RawDataReadOut_charge * m_ALFA_RawDataReadOut_charge
Definition: ALFA_Decoder_charge.h:77
ALFA_Decoder_charge::m_ALFA_RawDataCollectionReadOut
ALFA_RawDataCollectionReadOut * m_ALFA_RawDataCollectionReadOut
Definition: ALFA_Decoder_charge.h:78
ALFA_RawDataReadOut_charge::bit24_27
uint16_t bit24_27() const
Definition: ALFA_RawDataReadOut_charge.h:118
ALFA_RawDataCollectionReadOut::is_BOB
bool is_BOB() const
Definition: ALFA_RawDataCollectionReadOut.h:87
ALFA_RawDataContainerReadOut
Definition: ALFA_RawDataContainerReadOut.h:31
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
ALFA_Decoder_charge::ALFA_Decoder_charge
ALFA_Decoder_charge(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ALFA_Decoder_charge.cxx:19
ALFA_Decoder_charge::finalize
virtual StatusCode finalize()
Definition: ALFA_Decoder_charge.cxx:78