ATLAS Offline Software
Loading...
Searching...
No Matches
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
9static const InterfaceID IID_IALFA_Decoder_charge ("ALFA_Decoder_charge", 1, 0);
11{
13}
14
16// constructor
18
19ALFA_Decoder_charge::ALFA_Decoder_charge ( const std::string& type, const std::string& name,const IInterface* parent)
20: AthAlgTool(type,name,parent),
21m_robDataProvider ("ROBDataProviderSvc",name)
22//, m_ALFA_RawDataContainerReadOut(0), m_ALFA_RawDataCollectionReadOut(0), m_ALFA_RawDataReadOut_charge(0)
23{
24declareInterface<ALFA_Decoder_charge>(this);
25
26}
27
28
29
31// destructor
34
35
36
37
39// initialize() -
42
43
44 StatusCode sc;
45 sc = AthAlgTool::initialize();
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
80msg(MSG::DEBUG) << " ALFA_RoDDecoder_charge::FINALIZE" << endmsg;
81
82msg(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
100ALFA_RawDataCollection_charge* collection = nullptr;
101
102 uint32_t wordPos = 0;
103
104 std::vector<uint32_t> VData;
105
106 VData.clear();
107
108
109uint32_t Event_num=0;
110uint32_t Event_num_max=0;
111uint16_t charge_hit;
112
113uint16_t tmpCharge=10;
114uint16_t MBIdNum=0;
115
116uint32_t EcrId=1;
117uint32_t LvL1 =0;
118
119uint32_t Count_evt=0;
120
121
122uint16_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
172msg(MSG::DEBUG) << "============================" << std::endl;
173msg(MSG::DEBUG) <<"Frag Size : " << robFrag->rod_fragment_size_word() << endmsg;
174msg(MSG::DEBUG) <<"Header Size: " << robFrag->rod_header_size_word() << endmsg;
175msg(MSG::DEBUG) <<"Source ID : " << ROD_source_ID << endmsg;
176msg(MSG::DEBUG) <<"Run num : " << robFrag->rod_run_no() << endmsg;
177msg(MSG::DEBUG) <<"Version : " << robFrag->rod_version() << endmsg;
178msg(MSG::DEBUG) << " ROD_LVL1_ID " <<ROD_LVL1_ID<< endmsg;
179msg(MSG::DEBUG) << "============================" << std::endl;
180
181
182uint32_t evt_Id = ((robFrag->rod_lvl1_id()) & 0xFF000000) >> 24;
183uint32_t lvl1_Id = ((robFrag->rod_lvl1_id()) & 0x00FFFFFF) ;
184
185
186msg(MSG::DEBUG) <<" evt_Id : " << evt_Id << " lvl1_Id : " << lvl1_Id <<endmsg;
187
188 /*msg(MSG::DEBUG) << " **********Decoder dumping the words******** "<< endmsg;
189
190if (size > 0) {
191msg(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 {
195msg(MSG::DEBUG) << " Buffer size 0 ! "<< endmsg;
196 return StatusCode::FAILURE;
197 }*/
198
199
200 m_ALFA_RawDataCollectionReadOut->decodeWord(vint[wordPos]);
201 m_ALFA_RawDataReadOut_charge->decodeWord(vint[wordPos]);
202 m_ALFA_RawDataContainerReadOut->decodeWord(vint[wordPos]);
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
229 if (m_ALFA_RawDataCollectionReadOut->is_BOB())
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
239 while (!m_ALFA_RawDataCollectionReadOut->is_EOB()){
240
241 //Check for corrupted data
242
243 while ((!m_ALFA_RawDataCollectionReadOut->is_BOL()) && (!m_ALFA_RawDataCollectionReadOut->is_EOB()))
244 {
245 wordPos += 1;
246 if (wordPos >= size)
247 {
248 msg(MSG::ERROR)<<" Error: data corrupted" << endmsg;
249 return StatusCode::FAILURE;
250 }
251 m_ALFA_RawDataCollectionReadOut->decodeWord(vint[wordPos]);
252 }
253
254
255 if (m_ALFA_RawDataCollectionReadOut->is_BOL())
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
262 else if (m_ALFA_RawDataCollectionReadOut->is_EOB())
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
276 m_ALFA_RawDataCollectionReadOut->decodeWord(vint[wordPos]);
277 m_ALFA_RawDataReadOut_charge->decodeWord(vint[wordPos]);
278
279 while (!m_ALFA_RawDataCollectionReadOut->is_TWC()) {
280
281 uint16_t slotIdNum = m_ALFA_RawDataReadOut_charge->SlotId();
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
288 while (!m_ALFA_RawDataReadOut_charge->is_EOT())
289 {
290 wordPos += 1;
291 if (wordPos >= size)
292 {
293 msg(MSG::DEBUG)<<" Error: data corrupted" << endmsg;
294 return StatusCode::FAILURE;
295 }
296
297 m_ALFA_RawDataReadOut_charge->decodeWord(vint[wordPos]);
298
299 uint16_t PMFIdNum;
300 uint16_t ChannelIdNum;
301 uint16_t ChargeNum;
302
303
304 if (m_ALFA_RawDataReadOut_charge->is_TDCch() ) {
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
310 if(m_ALFA_RawDataReadOut_charge->PMFId() ==0){
311 // && m_ALFA_RawDataReadOut_charge->bit27_24()==1
312 // msg(MSG::DEBUG) << " Creation of the new collection"<< endmsg;
313
314
315 CountPMF0++;
316
317 tmpCharge = m_ALFA_RawDataReadOut_charge->ChargeChanId();
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
343 if(m_ALFA_RawDataReadOut_charge->PMFId() >0 && m_ALFA_RawDataReadOut_charge->PMFId() <24){
344 // && m_ALFA_RawDataReadOut_charge->bit27_24()==0
345
346
347 ChargeNum=m_ALFA_RawDataReadOut_charge->ChargeChanId();
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
388 if (m_ALFA_RawDataReadOut_charge->is_EOT() && m_ALFA_RawDataReadOut_charge->bit24_27()!=0) {
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
399 m_ALFA_RawDataCollectionReadOut->decodeWord(vint[wordPos]);
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
411 m_ALFA_RawDataCollectionReadOut->decodeWord(vint[wordPos]);
412
413
414
415 // take full event
416const eformat::FullEventFragment<const uint32_t*> * event = m_robDataProvider->getEvent(Gaudi::Hive::currentContext());
417
418msg(MSG::DEBUG) << "========FULL Event=============" << std::endl;
419msg(MSG::DEBUG) << "Event time (sec): " << (uint32_t)event->bc_time_seconds() << std::endl;
420msg(MSG::DEBUG) << "Event time (ns): " << (uint32_t)event->bc_time_nanoseconds() << std::endl;
421msg(MSG::DEBUG) << "Global ID: " << (uint32_t)event->global_id() << std::endl;
422msg(MSG::DEBUG) << "Run Type: " << (uint32_t)event->run_type() << std::endl;
423msg(MSG::DEBUG) << "Run Number: " << (uint32_t)event->run_no() << std::endl;
424msg(MSG::DEBUG) << "Lumi Block: " << (uint32_t)event->lumi_block() << std::endl;
425msg(MSG::DEBUG) << "Level1 ID: " << (uint32_t)event->lvl1_id() << std::endl;
426msg(MSG::DEBUG) << "BCID: " << (uint32_t)event->bc_id() << std::endl;
427msg(MSG::DEBUG) << "Level1 trig type: " << (uint32_t)event->lvl1_trigger_type() << std::endl;
428msg(MSG::DEBUG) << "Level1 Nwords: " << (uint32_t)event->nlvl1_trigger_info() << std::endl;
429msg(MSG::DEBUG) << "============================" << std::endl;
430
431uint32_t Time_StampID = event->bc_time_seconds();
432uint32_t BC_ID = event->bc_id();
433
434if(collection) collection->SetTimeStamp_POT(Time_StampID);
435if(collection) collection->SetBCId_POT(BC_ID);
436
437
438
439
440
441
442 } //EOB
443
444
445 if (m_ALFA_RawDataCollectionReadOut->is_EOB())
446 {
447 msg(MSG::DEBUG) << " Found the end of block EOB ---------------------- "<< endmsg;
448 }
449
450 wordPos += 1;
451 m_ALFA_RawDataCollectionReadOut->decodeWord(vint[wordPos]);
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
465msg(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
static const InterfaceID IID_IALFA_Decoder_charge("ALFA_Decoder_charge", 1, 0)
#define endmsg
static Double_t sc
ALFA_RawDataCollection_charge * getCollection(unsigned int MotherBoardId, ALFA_RawDataContainer_charge *cont)
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Service for reading bytestream.
static const InterfaceID & interfaceID()
StatusCode fillCollection(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment *robFrag, ALFA_RawDataContainer_charge *rdoCont, std::vector< unsigned int > *vecHash=NULL)
ALFA_Decoder_charge(const std::string &type, const std::string &name, const IInterface *parent)
ALFA_RawDataCollectionReadOut * m_ALFA_RawDataCollectionReadOut
virtual StatusCode finalize()
virtual StatusCode initialize()
ALFA_RawDataContainerReadOut * m_ALFA_RawDataContainerReadOut
ALFA_RawDataReadOut_charge * m_ALFA_RawDataReadOut_charge
RDOs : Chamber Service Module, collection of RawData.
This container provides acces to the PMF RDOs.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
const DataType * PointerType
Definition RawEvent.h:25
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27