]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFDecoder.cxx
Go from pointer to ifstream to ifstream.
[u/mrichter/AliRoot.git] / TOF / AliTOFDecoder.cxx
CommitLineData
2531be5d 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14***************************************************************************/
15
16/*
17$Log$
6e10339d 18Revision 1.5 2007/11/24 14:58:34 zampolli
19New Method implemented (#DDL <-> TOF channels)
20
974c1ccc 21Revision 1.4 2007/05/18 13:08:57 decaro
22Coding convention: RS1 violation -> suppression
23
7694c542 24Revision 1.3 2007/05/08 11:56:05 arcelli
25improved verbosity in verbose mode (R.Preghenella)
26
27Revision 1.2 2007/05/03 11:34:43 decaro
28Coding convention: RS1 violation -> suppression
29
856d92f7 30Revision 1.1 2007/04/27 11:00:32 arcelli
31TOF Raw Data decoder
32
2531be5d 33 author: Roberto Preghenella (R+), preghenella@bo.infn.it
34*/
35
36
7694c542 37//////////////////////////////////////////////////////////////////////
38// //
39// //
40// Class for raw data decoding //
41// //
42// //
43//////////////////////////////////////////////////////////////////////
2531be5d 44
45
46
47#include "AliLog.h"
48#include "AliTOFHitData.h"
5c7c93fa 49#include "AliTOFHitDataBuffer.h"
2531be5d 50#include "AliTOFDecoder.h"
974c1ccc 51#include "AliTOFGeometry.h"
1858e994 52#include "AliRawDataHeader.h"
26f75fad 53#include "AliRawDataHeaderV3.h"
4748b094 54#include "AliTOFRawDataFormat.h"
2531be5d 55
56ClassImp(AliTOFDecoder)
57
58//_________________________________________________________________
59
60AliTOFDecoder::AliTOFDecoder() :
61 TObject(),
62 fVerbose(0),
63 fV2718Patch(kFALSE),
64 fDataBuffer(0x0),
65 fPackedDataBuffer(0x0),
4748b094 66 //fTRMGlobalHeader(0x0),
67 //fTRMGlobalTrailer(0x0),
68 //fTRMChainHeader(0x0),
69 //fTRMChainTrailer(0x0),
70 //fTDCPackedHit(0x0),
71 //fTDCUnpackedHit(0x0),
72 //fTRMTDCError(0x0),
73 //fTRMDiagnosticErrorWord1(0x0),
74 //fTRMDiagnosticErrorWord2(0x0),
2531be5d 75 fSpiderCurrentSlotID(-1),
76 fSpiderCurrentChain(-1),
77 fSpiderCurrentTDC(-1)
78{
79 //default constructor
6cbeb729 80
81 for (Int_t chan=0;chan<N_CHANNEL;chan++)
82 fSpiderLeadingFlag[chan] = kFALSE;
83
2531be5d 84}
85
86//_________________________________________________________________
87
88AliTOFDecoder::AliTOFDecoder(AliTOFHitDataBuffer *DataBuffer, AliTOFHitDataBuffer *PackedDataBuffer) :
89 TObject(),
90 fVerbose(0),
91 fV2718Patch(kFALSE),
92 fDataBuffer(DataBuffer),
93 fPackedDataBuffer(PackedDataBuffer),
4748b094 94 //fTRMGlobalHeader(0x0),
95 //fTRMGlobalTrailer(0x0),
96 //fTRMChainHeader(0x0),
97 //fTRMChainTrailer(0x0),
98 //fTDCPackedHit(0x0),
99 //fTDCUnpackedHit(0x0),
100 //fTRMTDCError(0x0),
101 //fTRMDiagnosticErrorWord1(0x0),
102 //fTRMDiagnosticErrorWord2(0x0),
2531be5d 103 fSpiderCurrentSlotID(-1),
104 fSpiderCurrentChain(-1),
105 fSpiderCurrentTDC(-1)
106{
107 //another constructor
6cbeb729 108
109 for (Int_t chan=0;chan<N_CHANNEL;chan++)
110 fSpiderLeadingFlag[chan] = kFALSE;
111
2531be5d 112}
113
114//_________________________________________________________________
115
116AliTOFDecoder::AliTOFDecoder(const AliTOFDecoder &source) :
8a190ba2 117 TObject(source),
118 fVerbose(source.fVerbose),
119 fV2718Patch(source.fV2718Patch),
120 fDataBuffer(source.fDataBuffer),
121 fPackedDataBuffer(source.fPackedDataBuffer),
4748b094 122 //fTRMGlobalHeader(source.fTRMGlobalHeader),
123 //fTRMGlobalTrailer(source.fTRMGlobalTrailer),
124 //fTRMChainHeader(source.fTRMChainHeader),
125 //fTRMChainTrailer(source.fTRMChainTrailer),
126 //fTDCPackedHit(source.fTDCPackedHit),
127 //fTDCUnpackedHit(source.fTDCUnpackedHit),
128 //fTRMTDCError(source.fTRMTDCError),
129 //fTRMDiagnosticErrorWord1(source.fTRMDiagnosticErrorWord1),
130 //fTRMDiagnosticErrorWord2(source.fTRMDiagnosticErrorWord2),
8a190ba2 131 fSpiderCurrentSlotID(source.fSpiderCurrentSlotID),
132 fSpiderCurrentChain(source.fSpiderCurrentChain),
133 fSpiderCurrentTDC(source.fSpiderCurrentTDC)
2531be5d 134{
135 //copy constructor
6cbeb729 136
137 for (Int_t chan=0;chan<N_CHANNEL;chan++)
138 fSpiderLeadingFlag[chan] = source.fSpiderLeadingFlag[chan];
2531be5d 139
2531be5d 140}
141
142//_________________________________________________________________
143
144AliTOFDecoder &
145AliTOFDecoder::operator = (const AliTOFDecoder &source)
146{
147 //operator =
148
8a190ba2 149 if (this == &source)
150 return *this;
151
152 TObject::operator=(source);
153 fVerbose = source.fVerbose;
154 fV2718Patch = source.fV2718Patch;
155 fDataBuffer = source.fDataBuffer;
156 fPackedDataBuffer = source.fPackedDataBuffer;
4748b094 157 //fTRMGlobalHeader = source.fTRMGlobalHeader;
158 //fTRMGlobalTrailer = source.fTRMGlobalTrailer;
159 //fTRMChainHeader = source.fTRMChainHeader;
160 //fTRMChainTrailer = source.fTRMChainTrailer;
161 //fTDCPackedHit = source.fTDCPackedHit;
162 //fTDCUnpackedHit = source.fTDCUnpackedHit;
163 //fTRMTDCError = source.fTRMTDCError;
164 //fTRMDiagnosticErrorWord1 = source.fTRMDiagnosticErrorWord1;
165 //fTRMDiagnosticErrorWord2 = source.fTRMDiagnosticErrorWord2;
8a190ba2 166 fSpiderCurrentSlotID = source.fSpiderCurrentSlotID;
167 fSpiderCurrentChain = source.fSpiderCurrentChain;
168 fSpiderCurrentTDC = source.fSpiderCurrentTDC;
6cbeb729 169 for (Int_t chan=0;chan<N_CHANNEL;chan++)
170 fSpiderLeadingFlag[chan] = source.fSpiderLeadingFlag[chan];
171
2531be5d 172 return *this;
173}
174
175AliTOFDecoder::~AliTOFDecoder()
176{}
177
178//_________________________________________________________________
179
180Bool_t
26f75fad 181AliTOFDecoder::Decode(const UInt_t *rawData, Int_t nWords, const AliRawDataHeader *cdh, const AliRawDataHeaderV3 *cdhV3)
2531be5d 182{
183 /* main decoding routine.
184 * it loops over nWords 32-bit words
185 * starting at *rawData and decodes them.
186 * it also fills some buffers in order to
187 * have the decoded data available for other
188 * classes.
189 */
190
2bf4d9d6 191 AliTOFDRMStatusHeader3 *lDRMStatusHeader3;
4748b094 192 AliTOFTRMGlobalHeader *lTRMGlobalHeader; //TRM global header
193 AliTOFTRMGlobalTrailer *lTRMGlobalTrailer; //TRM global trailer
194 AliTOFTRMChainHeader *lTRMChainHeader; //TRM chain header
195 //AliTOFTRMChainTrailer *lTRMChainTrailer; //TRM chain trailer
196 AliTOFTDCPackedHit *lTDCPackedHit; //TDC packed hit
197 AliTOFTDCUnpackedHit *lTDCUnpackedHit; //TDC unpacked hit
198 //AliTOFTRMTDCError *lTRMTDCError; //TRM TDC error
199 //AliTOFTRMDiagnosticErrorWord1 *lTRMDiagnosticErrorWord1; //TRM diagnostic error word 1
200 //AliTOFTRMDiagnosticErrorWord2 *lTRMDiagnosticErrorWord2; //TRM diagnostica error word 2
201
202
2531be5d 203 AliTOFHitData hitData;
204
205 //useful variables
206 Int_t status;
207 Short_t tempPS;
208 Float_t tempTOT; //ns
209 Int_t tempTOTBin; //TOT_BIN_WIDTH
210
211 //decoder variables
212 UShort_t decodeStatus = 0x0;
213 Short_t currentDDL = -1;
214 Short_t currentSlotID = -1;
215 Short_t currentACQ = -1;
216 Short_t currentChain = -1;
217 Short_t currentBunchID = -1;
2bf4d9d6 218 Short_t currentL0BCID = -1;
8fa5c3a3 219 Short_t currentMiniEventID = cdh ? cdh->GetMiniEventID() : (Short_t)(-1);
26f75fad 220 currentMiniEventID = cdhV3 ? cdhV3->GetMiniEventID() : (Short_t)(-1);
8fa5c3a3 221 Short_t currentEventID1 = cdh ? cdh->GetEventID1() : (Short_t)(-1);
26f75fad 222 currentEventID1 = cdhV3 ? cdhV3->GetEventID1() : (Short_t)(-1);
68343832 223 AliDebug(1, Form("EvID1 = %d, EvID2 = %d, currentMiniEventID = %d", currentEventID1, cdh->GetEventID2(), currentMiniEventID));
26f75fad 224 if (!cdh && !cdhV3)
1858e994 225 AliWarning("CDH not valid: deltaBunchID not reliable ");
2531be5d 226
227 /*** V2718 patch ***/
228 if (fV2718Patch){
229 decodeStatus = decodeStatus | DRM_BIT;
230 if (fVerbose)
231 AliInfo("DRM not present: - V2718 patch decoding -");
232 }
233 /*** V2718 patch ***/
234
235 if (fVerbose==2)
236 AliInfo("Initialize SPIDER function");
237 status = InitializeSpider();
238
239 if (fVerbose)
240 AliInfo("Start decoding");
241
242 if (fVerbose)
243 AliInfo("Loop over the data and decode");
244
245 if (fVerbose)
246 AliInfo(" St Hex Word \t Decoded Word");
247
248 //loop over raw data
249 for (Int_t iWord = 0; iWord < nWords; iWord++, rawData++){
250
251 //switch word type
252 switch (*rawData & WORD_TYPE_MASK){
253
254 case GLOBAL_HEADER:
255
256 //switch slot ID
257 switch (*rawData & SLOT_ID_MASK){
258
259 //DRM global header (slotID=1)
260 case 1:
261 //check decode status
262 if ( decodeStatus != DRM_HEADER_STATUS ){
263 AliError(Form(" %02x - 0x%08x [ERROR] Unexpected DRM global header",decodeStatus,*rawData));
264 return kTRUE;
265 }
266 //decode status ok
267 if (fVerbose)
268 AliInfo(Form(" %02x - 0x%08x \t DRM global header",decodeStatus,*rawData));
269 //change decode status
270 decodeStatus = decodeStatus | DRM_BIT;
271
272 //skip DRM data
2bf4d9d6 273 for (Int_t i = 0; i < DRM_DATA_WORDS; i++, iWord++){
274 rawData++;
2531be5d 275 if (fVerbose)
0e83a136 276 AliInfo(Form(" %02x - 0x%08x \t DRM data",decodeStatus,*rawData));
2bf4d9d6 277 switch (i) {
278 case 2:
279 lDRMStatusHeader3 = (AliTOFDRMStatusHeader3*)rawData;
280 currentL0BCID = lDRMStatusHeader3->GetL0BCID();
281 break;
282 default:
283 break;
284 }
2531be5d 285 }
286 break;
287
288 //LTM global header (slotID=2)
289 case 2:
290 //check decode status
291 if ( decodeStatus != LTM_HEADER_STATUS ){
292 AliError(Form(" %02x - 0x%08x [ERROR] Unexpected LTM global header",decodeStatus,*rawData));
293 return kTRUE;
294 }
295 //decode status ok
296 if (fVerbose)
297 AliInfo(Form(" %02x - 0x%08x \t LTM global header",decodeStatus,*rawData));
298 //change decode status
299 decodeStatus = decodeStatus | LTM_BIT;
300
301 //skip LTM data
2bf4d9d6 302 for (Int_t i = 0; i < LTM_DATA_WORDS; i++, iWord++){
303 rawData++;
2531be5d 304 if (fVerbose)
305 AliInfo(Form(" %02x - 0x%08x \t LTM data",decodeStatus,*rawData));
306 }
307 break;
308
309 //TRM global header (slotID=3-12)
310 case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12:
311 //check decode status
312 if ( decodeStatus != TRM_HEADER_STATUS ){
313 AliError(Form(" %02x - 0x%08x [ERROR] Unexpected TRM global header",decodeStatus,*rawData));
314 return kTRUE;
315 }
316 //decode status ok
317 //set TRM global header
4748b094 318 lTRMGlobalHeader = (AliTOFTRMGlobalHeader*)rawData;
2531be5d 319 //set current TRM
4748b094 320 currentSlotID = lTRMGlobalHeader->GetSlotID();
321 currentACQ = lTRMGlobalHeader->GetACQBits();
2531be5d 322 if (fVerbose)
4748b094 323 AliInfo(Form(" %02x - 0x%08x \t TRM global header \t slotID=%02d ACQ=%01d L=%01d",decodeStatus,*rawData,lTRMGlobalHeader->GetSlotID(),lTRMGlobalHeader->GetACQBits(),lTRMGlobalHeader->GetLBit()));
2531be5d 324 //change decode status
325 decodeStatus = decodeStatus | TRM_BIT;
326 break;
327
328 default:
682baa04 329 AliError(Form(" %02x - 0x%08x [ERROR] Not valid slotID in global header",decodeStatus,*rawData));
2531be5d 330 return kTRUE;
331 break;
332
333 }
334 //end switch slotID
335 break;
336
337 case GLOBAL_TRAILER:
338
339 //switch slot ID
340 switch (*rawData & SLOT_ID_MASK){
341
342 //DRM global trailer (slotID=1)
343 case 1:
344 //check decode status
345 if ( decodeStatus != DRM_TRAILER_STATUS ){
346 AliError(Form(" %02x - 0x%08x [ERROR] Unexpected DRM global trailer",decodeStatus,*rawData));
347 return kTRUE;
348 }
349 //decode status ok
350 if (fVerbose)
351 AliInfo(Form(" %02x - 0x%08x \t DRM global trailer",decodeStatus,*rawData));
352 //change decode status
353 decodeStatus = decodeStatus & ~DRM_BIT;
354 break;
355
356 //LTM global trailer (slotID=2)
357 case 2:
358 //check decode status
359 if ( decodeStatus != LTM_TRAILER_STATUS ){
360 AliError(Form(" %02x - 0x%08x [ERROR] Unexpected LTM global trailer",decodeStatus,*rawData));
361 return kTRUE;
362 }
363 //decode status ok
364 if (fVerbose)
365 AliInfo(Form(" %02x - 0x%08x \t LTM global trailer",decodeStatus,*rawData));
366 //change decode status
367 decodeStatus = decodeStatus & ~LTM_BIT;
368 break;
369
370 //TRM global trailer (slotID=15)
371 case 15:
372 //check decode status
373 if ( decodeStatus != TRM_TRAILER_STATUS ){
374 AliError(Form(" %02x - 0x%08x [ERROR] Unexpected TRM global trailer",decodeStatus,*rawData));
375 return kTRUE;
376 }
377 //decode status ok
378 //set TRM global trailer
4748b094 379 lTRMGlobalTrailer = (AliTOFTRMGlobalTrailer *)rawData;
2531be5d 380 if (fVerbose)
4748b094 381 AliInfo(Form(" %02x - 0x%08x \t TRM global trailer \t CRC=%04d eventCounter=%04d",decodeStatus,*rawData,lTRMGlobalTrailer->GetEventCRC(),lTRMGlobalTrailer->GetEventCounter()));
2531be5d 382 //change decode status
383 decodeStatus = decodeStatus & ~TRM_BIT;
384 break;
385
386 default:
682baa04 387 AliError(Form(" %02x - 0x%08x [ERROR] Not valid slotID/pattern in global trailer",decodeStatus,*rawData));
2531be5d 388 return kTRUE;
389 break;
390 }
391 break;
392
393 case CHAIN_A_HEADER:
394 //check decode status
395 if ( (decodeStatus != CHAIN_A_HEADER_STATUS) ){
396 AliError(Form(" %02x - 0x%08x [ERROR] Unexpected TRM chain A header",decodeStatus,*rawData));
397 return kTRUE;
398 }
399 //decode status ok
4748b094 400 lTRMChainHeader = (AliTOFTRMChainHeader *)rawData;
2531be5d 401 currentChain = 0;
4748b094 402 currentBunchID = lTRMChainHeader->GetBunchID();
2531be5d 403 if (fVerbose)
404 AliInfo(Form(" %02x - 0x%08x \t TRM chain A header \t chain=%01d bunchID=%04d",decodeStatus,*rawData,currentChain,currentBunchID));
405 //change decode status
406 decodeStatus = decodeStatus | CHAIN_A_BIT;
407 break;
408
409 case CHAIN_A_TRAILER:
410 //check decode status
411 if ( decodeStatus != CHAIN_A_TRAILER_STATUS ){
412 AliError(Form(" %02x - 0x%08x [ERROR] Unexpected TRM chain A trailer",decodeStatus,*rawData));
413 return kTRUE;
414 }
415 //decode status ok
416 if (fVerbose)
417 AliInfo(Form(" %02x - 0x%08x \t TRM chain A trailer",decodeStatus,*rawData));
418 //change decode status
419 decodeStatus = decodeStatus & ~CHAIN_A_BIT;
420 break;
421
422 case CHAIN_B_HEADER:
423 //check decode status
424 if ( decodeStatus != CHAIN_B_HEADER_STATUS ){
425 AliError(Form(" %02x - 0x%08x [ERROR] Unexpected TRM chain B header",decodeStatus,*rawData));
426 return kTRUE;
427 }
428 //decode status ok
4748b094 429 lTRMChainHeader = (AliTOFTRMChainHeader *)rawData;
2531be5d 430 currentChain = 1;
4748b094 431 currentBunchID = lTRMChainHeader->GetBunchID();
2531be5d 432 if (fVerbose)
433 AliInfo(Form(" %02x - 0x%08x \t TRM chain B header \t chain=%01d bunchID=%04d",decodeStatus,*rawData,currentChain,currentBunchID));
434 //change decode status
435 decodeStatus = decodeStatus | CHAIN_B_BIT;
436 break;
437
438 case CHAIN_B_TRAILER:
439 //check decode status
440 if ( decodeStatus != CHAIN_B_TRAILER_STATUS ){
441 AliError(Form(" %02x - 0x%08x [ERROR] Unexpected TRM chain B trailer",decodeStatus,*rawData));
442 return kTRUE;
443 }
444 //decode status ok
445 if (fVerbose)
446 AliInfo(Form(" %02x - 0x%08x \t TRM chain B trailer",decodeStatus,*rawData));
447 //change decode status
448 decodeStatus = decodeStatus & ~CHAIN_B_BIT;
449 break;
450
451 case ERROR:
452 if (fVerbose)
453 AliInfo(Form(" %02x - 0x%08x \t TDC error",decodeStatus,*rawData));
454 break;
455
456 case FILLER:
457 if (fVerbose)
458 AliInfo(Form(" %02x - 0x%08x \t Filler",decodeStatus,*rawData));
459 break;
460
461 default:
462 //check decode status
463 if ( decodeStatus != CHAIN_A_TDC_HIT_STATUS &&
464 decodeStatus != CHAIN_B_TDC_HIT_STATUS ){
465 AliError(Form(" %02x - 0x%08x [ERROR] Unexpected or unknown word",decodeStatus,*rawData));
466 return kTRUE;
467 }
468 //decode status ok
469
470 //switch TRM ACQ
471 switch (currentACQ){
472
473 case PACKING_ENABLED_ACQ:
474 //decode TDC packed hit
4748b094 475 lTDCPackedHit = (AliTOFTDCPackedHit *)rawData;
476 lTDCUnpackedHit = (AliTOFTDCUnpackedHit *)rawData;
2531be5d 477 //set hit in the equipment data
478 hitData.SetDDLID(currentDDL);
479 hitData.SetSlotID(currentSlotID);
480 hitData.SetACQ(currentACQ);
481 hitData.SetChain(currentChain);
4748b094 482 hitData.SetPS(lTDCPackedHit->GetPSBits());
483 hitData.SetTDC(lTDCPackedHit->GetTDCID());
484 hitData.SetChan(lTDCPackedHit->GetChan());
485 hitData.SetTime((float)lTDCPackedHit->GetHitTime() * TIME_BIN_WIDTH);
486 hitData.SetTimeBin(lTDCPackedHit->GetHitTime());
487 hitData.SetTOT((float)lTDCPackedHit->GetTOTWidth() * TOT_BIN_WIDTH);
488 hitData.SetTOTBin(lTDCPackedHit->GetTOTWidth());
8d5b0d29 489 hitData.SetDeltaBunchID(currentBunchID - currentEventID1);
2bf4d9d6 490 hitData.SetL0L1Latency(currentMiniEventID - currentL0BCID);
2531be5d 491 //orphane leading hit
492 if (hitData.GetPS()==LEADING_HIT_PS){
4748b094 493 hitData.SetTime((float)lTDCUnpackedHit->GetHitTime() * TIME_BIN_WIDTH);
494 hitData.SetTimeBin(lTDCUnpackedHit->GetHitTime());
2531be5d 495 //set TOT to zero
496 hitData.SetTOT(0);
497 hitData.SetTOTBin(0);
498 //push hit data in packed data buffer
499 if (fPackedDataBuffer != 0x0)
500 fPackedDataBuffer->Add(hitData);
501 //set TOT to not measured
502 hitData.SetTOT(-1);
503 hitData.SetTOTBin(-1);
504 //push hit data in packed data buffer
505 if (fDataBuffer != 0x0)
506 fDataBuffer->Add(hitData);
507 }
508 //orphane trailing hit
509 else if (hitData.GetPS()==TRAILING_HIT_PS){
4748b094 510 hitData.SetTime((float)lTDCUnpackedHit->GetHitTime() * TIME_BIN_WIDTH);
511 hitData.SetTimeBin(lTDCUnpackedHit->GetHitTime());
2531be5d 512 //set TOT to not measured
513 hitData.SetTOT(-1);
514 hitData.SetTOTBin(-1);
515 //push hit data in data buffer
516 if (fDataBuffer != 0x0)
517 fDataBuffer->Add(hitData);
518 }
519 //packed hit and OVF
520 else{
521 //push hit data in packed data buffer
522 if (fPackedDataBuffer != 0x0)
523 fPackedDataBuffer->Add(hitData);
524 //save PS temporary
525 tempPS = hitData.GetPS();
526 //save TOT temporary
527 tempTOT = hitData.GetTOT();
528 tempTOTBin = hitData.GetTOTBin();
529 //unpack the hit: leading hit
530 hitData.SetPS(LEADING_HIT_PS);
531 //set TOT to not measured
532 hitData.SetTOT(-1);
533 hitData.SetTOTBin(-1);
534 //push leading hit data in data buffer
535 if (fDataBuffer != 0x0)
536 fDataBuffer->Add(hitData);
537 //unpack the hit: trailing hit
538 hitData.SetPS(TRAILING_HIT_PS);
539 hitData.SetTime(hitData.GetTime() + tempTOT);
540 hitData.SetTimeBin(hitData.GetTimeBin() + (Int_t)(tempTOTBin * TOT_TO_TIME_BIN_WIDTH));
541 //push trailing hit data in data buffer
542 if (fDataBuffer != 0x0)
543 fDataBuffer->Add(hitData);
544 //restore packed hit
545 hitData.SetPS(tempPS);
546 hitData.SetTime(hitData.GetTime() - tempTOT);
547 hitData.SetTimeBin(hitData.GetTimeBin() - (Int_t)(tempTOTBin * TOT_TO_TIME_BIN_WIDTH));
548 hitData.SetTOT(tempTOT);
549 hitData.SetTOTBin(tempTOTBin);
550 }
551
552 if (fVerbose)
553 switch (hitData.GetPS()){
554 case PACKED_HIT_PS:
555 AliInfo(Form(" %02x - 0x%08x \t TDC hit [packed] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
556 break;
557 case LEADING_HIT_PS:
558 AliInfo(Form(" %02x - 0x%08x \t TDC hit [orp.lead] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
559 break;
560 case TRAILING_HIT_PS:
561 AliInfo(Form(" %02x - 0x%08x \t TDC hit [orp.trai] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
562 break;
563 case TOT_OVF_HIT_PS:
564 AliInfo(Form(" %02x - 0x%08x \t TDC hit [TOT ovfl] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
565 break;
566 }
567 break;
568
569 case LEADING_ONLY_ACQ: case TRAILING_ONLY_ACQ:
570 //decode TDC unpacked hit
4748b094 571 lTDCUnpackedHit = (AliTOFTDCUnpackedHit *)rawData;
2531be5d 572 //set hit in the equipment data
573 hitData.SetDDLID(currentDDL);
574 hitData.SetSlotID(currentSlotID);
575 hitData.SetACQ(currentACQ);
576 hitData.SetChain(currentChain);
4748b094 577 hitData.SetPS(lTDCUnpackedHit->GetPSBits());
578 hitData.SetTDC(lTDCUnpackedHit->GetTDCID());
579 hitData.SetChan(lTDCUnpackedHit->GetChan());
580 hitData.SetTime((float)lTDCUnpackedHit->GetHitTime() * TIME_BIN_WIDTH);
581 hitData.SetTimeBin(lTDCUnpackedHit->GetHitTime());
2531be5d 582 hitData.SetTOT(-1.);
583 hitData.SetTOTBin(-1);
8d5b0d29 584 hitData.SetDeltaBunchID(currentBunchID - currentEventID1);
2bf4d9d6 585 hitData.SetL0L1Latency(currentMiniEventID - currentL0BCID);
2531be5d 586 //push hit data in data buffer
587 if (fDataBuffer != 0x0)
588 fDataBuffer->Add(hitData);
589
590 if (fVerbose)
591 switch (hitData.GetPS()){
592 case PACKED_HIT_PS:
593 AliInfo(Form(" %02x - 0x%08x \t TDC hit [packed] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
594 break;
595 case LEADING_HIT_PS:
596 AliInfo(Form(" %02x - 0x%08x \t TDC hit [leading] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
597 break;
598 case TRAILING_HIT_PS:
599 AliInfo(Form(" %02x - 0x%08x \t TDC hit [trailing] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
600 break;
601 case TOT_OVF_HIT_PS:
602 AliInfo(Form(" %02x - 0x%08x \t TDC hit [TOT ovfl] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
603 break;
604 }
605 break;
606
607 case PACKING_DISABLED_ACQ:
608 //decode TDC unpacked hit
4748b094 609 lTDCUnpackedHit = (AliTOFTDCUnpackedHit *)rawData;
2531be5d 610 //set hit in the equipment data
611 hitData.SetDDLID(currentDDL);
612 hitData.SetSlotID(currentSlotID);
613 hitData.SetACQ(currentACQ);
614 hitData.SetChain(currentChain);
4748b094 615 hitData.SetPS(lTDCUnpackedHit->GetPSBits());
616 hitData.SetTDC(lTDCUnpackedHit->GetTDCID());
617 hitData.SetChan(lTDCUnpackedHit->GetChan());
618 hitData.SetTime((float)lTDCUnpackedHit->GetHitTime() * TIME_BIN_WIDTH);
619 hitData.SetTimeBin(lTDCUnpackedHit->GetHitTime());
2531be5d 620 hitData.SetTOT(-1.);
621 hitData.SetTOTBin(-1);
8d5b0d29 622 hitData.SetDeltaBunchID(currentBunchID - currentEventID1);
2bf4d9d6 623 hitData.SetL0L1Latency(currentMiniEventID - currentL0BCID);
2531be5d 624 //push hit data in data buffer
625 if (fDataBuffer != 0x0)
626 fDataBuffer->Add(hitData);
627
628 if (fVerbose)
629 switch (hitData.GetPS()){
630 case PACKED_HIT_PS:
631 AliInfo(Form(" %02x - 0x%08x \t TDC hit [packed] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
632 break;
633 case LEADING_HIT_PS:
634 AliInfo(Form(" %02x - 0x%08x \t TDC hit [leading] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
635 break;
636 case TRAILING_HIT_PS:
637 AliInfo(Form(" %02x - 0x%08x \t TDC hit [trailing] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
638 break;
639 case TOT_OVF_HIT_PS:
640 AliInfo(Form(" %02x - 0x%08x \t TDC hit [TOT ovfl] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
641 break;
642 }
643 //call spider function
644 if (fVerbose==2)
645 AliInfo("Calling SPIDER function");
646 Spider(hitData);
647 break;
648 }
649 //end switch TRM ACQ
650
651
652 }
653 //end switch word type
654
655 }
656 //end equipment data loop
657
658 if (fVerbose)
659 AliInfo("End of data loop");
660
661 if (fVerbose==2)
662 AliInfo("Reset SPIDER function");
663 status = ResetSpider();
664
665 if (fVerbose)
666 AliInfo("Decoder is exiting succesfully.");
667
668 return kFALSE;
669}
670
671//_________________________________________________________________
672
673Bool_t
674AliTOFDecoder::InitializeSpider(){
675
676 /* SPIDER initialization routine.
677 it initializes SPIDER variables in order
678 to have SPIDER ready to pack tof data
679 in packed data objects
680 */
681
682 if (fVerbose==2)
683 AliInfo("Initializing SPIDER");
684
685 fSpiderCurrentSlotID=-1;
686 fSpiderCurrentChain=-1;
687 fSpiderCurrentTDC=-1;
688
689 for (Int_t chan=0;chan<N_CHANNEL;chan++)
690 fSpiderLeadingFlag[chan] = kFALSE;
691
692 return kFALSE;
693}
694
695//_________________________________________________________________
696
697Bool_t
698AliTOFDecoder::ResetSpider(){
699
700 /* SPIDER reset routine.
701 it resets SPIDER buffers and
702 variables in order to empty full
703 buffers a set up SIPDER for new
704 HPTDC data
705 */
706
707 if (fVerbose==2)
708 AliInfo("Resetting SPIDER buffers");
709
710 for (Int_t chan=0;chan<N_CHANNEL;chan++){
711 if (fSpiderLeadingFlag[chan]){
712 if (fVerbose==2)
713 AliInfo("Buffer non empty: put leading hit into buffer as orphane");
714 //set TOT to zero
715 fSpiderLeadingHit[chan].SetACQ(4);
716 fSpiderLeadingHit[chan].SetPS(1);
717 fSpiderLeadingHit[chan].SetTOT(0);
718 fSpiderLeadingHit[chan].SetTOTBin(0);
719 //push hit into packed buffer
720 if (fPackedDataBuffer != 0x0)
721 fPackedDataBuffer->Add(fSpiderLeadingHit[chan]);
722 if (fVerbose==2)
723 AliInfo(Form("Packed hit: slotID=%d chain=%d PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",fSpiderLeadingHit[chan].GetSlotID(),fSpiderLeadingHit[chan].GetChain(),fSpiderLeadingHit[chan].GetPS(),fSpiderLeadingHit[chan].GetTDC(),fSpiderLeadingHit[chan].GetChan(),fSpiderLeadingHit[chan].GetTOT(),fSpiderLeadingHit[chan].GetTOTBin(),fSpiderLeadingHit[chan].GetTime(),fSpiderLeadingHit[chan].GetTimeBin()));
724
725 }
726 fSpiderLeadingFlag[chan]=kFALSE;
727 }
728
729 return kFALSE;
730}
731
732//_________________________________________________________________
733
734Bool_t
1858e994 735AliTOFDecoder::Spider(AliTOFHitData &hitData){
2531be5d 736
737 /* main SPIDER routine.
738 it receives, reads, stores and packs
739 unpacked HPTDC data in packed data
740 object. it also fills buffers.
741 */
742
743 Int_t status;
744
745 if (fVerbose==2)
746 AliInfo("Hit data received");
747
748 //check if TDC is changed (slotID,chain,TDC triplet)
749 if (fSpiderCurrentSlotID!=hitData.GetSlotID() ||
750 fSpiderCurrentChain!=hitData.GetChain() ||
751 fSpiderCurrentTDC!=hitData.GetTDC() ){
752 if (fVerbose==2)
753 AliInfo("Data coming from a new TDC: reset buffers");
754 //reset spider
755 status = ResetSpider();
756 //set current TDC
757 fSpiderCurrentSlotID=hitData.GetSlotID();
758 fSpiderCurrentChain=hitData.GetChain();
759 fSpiderCurrentTDC=hitData.GetTDC();
760 }
761
762 //switch PS bits
763 switch (hitData.GetPS()){
764
765 case LEADING_HIT_PS:
766 if (fVerbose==2)
767 AliInfo(Form("Leading hit: slotID=%d chain=%d PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",hitData.GetSlotID(),hitData.GetChain(),hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
768 //check spider leading flag
769 if (fSpiderLeadingFlag[hitData.GetChan()]){
770 if (fVerbose==2)
771 AliInfo("Leading hit: buffer full, put previous in buffers as orphane and keep current");
772 //set TOT at zero for previous hit
773 fSpiderLeadingHit[hitData.GetChan()].SetACQ(4);
774 fSpiderLeadingHit[hitData.GetChan()].SetPS(1);
775 fSpiderLeadingHit[hitData.GetChan()].SetTOT(0);
776 fSpiderLeadingHit[hitData.GetChan()].SetTOTBin(0);
777 //push previous hit into packed buffer
778 if (fPackedDataBuffer != 0x0)
779 fPackedDataBuffer->Add(fSpiderLeadingHit[hitData.GetChan()]);
780 //set current hit
781 fSpiderLeadingHit[hitData.GetChan()]=hitData;
782 if (fVerbose==2)
783 AliInfo(Form("Packed hit: slotID=%d chain=%d PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",fSpiderLeadingHit[hitData.GetChan()].GetSlotID(),fSpiderLeadingHit[hitData.GetChan()].GetChain(),fSpiderLeadingHit[hitData.GetChan()].GetPS(),fSpiderLeadingHit[hitData.GetChan()].GetTDC(),fSpiderLeadingHit[hitData.GetChan()].GetChan(),fSpiderLeadingHit[hitData.GetChan()].GetTOT(),fSpiderLeadingHit[hitData.GetChan()].GetTOTBin(),fSpiderLeadingHit[hitData.GetChan()].GetTime(),fSpiderLeadingHit[hitData.GetChan()].GetTimeBin()));
784 }
785 else{
786 if (fVerbose==2)
787 AliInfo("Leading hit: buffer empty, keep current hit and set flag");
788 fSpiderLeadingHit[hitData.GetChan()]=hitData;
789 //set spider leading flag
790 fSpiderLeadingFlag[hitData.GetChan()]=kTRUE;
791 }
792 break;
793
794 case TRAILING_HIT_PS:
795 if (fVerbose==2)
796 AliInfo(Form("Trailing hit: slotID=%d chain=%d PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",hitData.GetSlotID(),hitData.GetChain(),hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
797 //check spider leading flag
798 if (fSpiderLeadingFlag[hitData.GetChan()]){
799 if (fVerbose==2)
800 AliInfo("Trailing hit: buffer full, pack leading and trailing");
801 hitData.SetACQ(4);
802 hitData.SetPS(0);
803 hitData.SetTOT(hitData.GetTime()-fSpiderLeadingHit[hitData.GetChan()].GetTime());
804 hitData.SetTOTBin((Int_t)((hitData.GetTimeBin()-fSpiderLeadingHit[hitData.GetChan()].GetTimeBin())*TIME_TO_TOT_BIN_WIDTH));
805 hitData.SetTime(fSpiderLeadingHit[hitData.GetChan()].GetTime());
806 hitData.SetTimeBin(fSpiderLeadingHit[hitData.GetChan()].GetTimeBin());
807 //check TOT and set TOT overflow if TOT < 0
808 if (hitData.GetTOT() < 0){
809 hitData.SetPS(3);
810 hitData.SetTOT(0);
811 hitData.SetTOTBin(0);
812 }
813 if (fPackedDataBuffer != 0x0)
814 fPackedDataBuffer->Add(hitData);
815 if (fVerbose==2)
816 AliInfo(Form("Packed hit: slotID=%d chain=%d PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",hitData.GetSlotID(),hitData.GetChain(),hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
817 //unset spider leading flag
818 fSpiderLeadingFlag[hitData.GetChan()]=kFALSE;
819 }
820 else{
821 if (fVerbose==2)
822 AliInfo("Trailing hit: buffer empty, throw hit away");
823 }
824 break;
825 }
826 //end switch PS bits
827
828 return kFALSE;
829}
974c1ccc 830//_____________________________________________________________________________
831void AliTOFDecoder::GetArrayDDL(Int_t* array, Int_t ddl){
832
833 // method that fills array with the
834 // TOF channels indexes corresponding
835 // to DDL iDDL
836
837 AliTOFGeometry *geom = new AliTOFGeometry();
838 Int_t indexDDL = ddl%4;
839 Int_t iSector = Int_t(ddl/4);
68343832 840 if (fVerbose)
974c1ccc 841 AliInfo(Form(" Sector = %i, DDL within sector = %i",iSector, indexDDL));
68343832 842
6e10339d 843 Int_t volume[5];
844 volume[0]=iSector;
974c1ccc 845 Int_t minPlate=0, maxPlate=0, minStrip2=0, maxStrip2=0, minPadz=0, maxPadz=0, minPadx=0, maxPadx=0;
846
847 if (indexDDL==0){
848 minPlate=kMinPlate0;
849 maxPlate=kMaxPlate0;
850 minStrip2=kMinStrip0;
851 maxStrip2=kMaxStrip0;
852 minPadz=kMinPadz0;
853 maxPadz=kMaxPadz0;
854 minPadx=kMinPadx0;
855 maxPadx=kMaxPadx0;
856 }
857
858 else if (indexDDL==1){
859 minPlate=kMinPlate1;
860 maxPlate=kMaxPlate1;
861 minStrip2=kMinStrip1;
862 maxStrip2=kMaxStrip1;
863 minPadz=kMinPadz1;
864 maxPadz=kMaxPadz1;
865 minPadx=kMinPadx1;
866 maxPadx=kMaxPadx1;
867 }
868
869 else if (indexDDL==2){
870 minPlate=kMinPlate2;
871 maxPlate=kMaxPlate2;
872 minStrip2=kMinStrip2;
873 maxStrip2=kMaxStrip2;
874 minPadz=kMinPadz2;
875 maxPadz=kMaxPadz2;
876 minPadx=kMinPadx2;
877 maxPadx=kMaxPadx2;
878 }
879
880 else if (indexDDL==3){
881 minPlate=kMinPlate3;
882 maxPlate=kMaxPlate3;
883 minStrip2=kMinStrip3;
884 maxStrip2=kMaxStrip3;
885 minPadz=kMinPadz3;
886 maxPadz=kMaxPadz3;
887 minPadx=kMinPadx3;
888 maxPadx=kMaxPadx3;
889 }
890
891 Int_t ichTOF=0;
892
893 Int_t minStrip=0;
894 Int_t maxStrip=18;
895 for (Int_t iPlate=minPlate;iPlate<=maxPlate;iPlate++){
896 if (iPlate==2) {
897 maxStrip = maxStrip2;
898 minStrip = minStrip2;
899 }
900 else {
901 maxStrip = 18;
902 minStrip = 0;
903 }
904 for (Int_t iStrip=minStrip;iStrip<=maxStrip;iStrip++){
905 for (Int_t iPadz=minPadz;iPadz<=maxPadz;iPadz++){
906 for (Int_t iPadx=minPadx;iPadx<=maxPadx;iPadx++){
6e10339d 907 volume[1]=iPlate;
908 volume[2]=iStrip;
909 volume[3]=iPadz;
910 volume[4]=iPadx;
68343832 911 if (fVerbose)
6e10339d 912 AliInfo(Form(" volume[0] = %i, volume[1] = %i, volume[2] = %i, volume[3] = %i, volume[4] = %i",volume[0],volume[1],volume[2],volume[3],volume[4]));
68343832 913
974c1ccc 914 if (indexDDL==0 || indexDDL==2){
6e10339d 915 array[ichTOF]=geom->GetIndex(volume);
68343832 916 if (fVerbose)
974c1ccc 917 AliInfo(Form(" ichTOF = %i, TOFChannel = %i",ichTOF,array[ichTOF]));
68343832 918
974c1ccc 919 }
920 else {
6e10339d 921 array[ichTOF]=geom->GetIndex(volume);
68343832 922 if (fVerbose)
974c1ccc 923 AliInfo(Form(" ichTOF = %i, TOFChannel = %i",ichTOF,array[ichTOF]));
68343832 924
974c1ccc 925 }
926 ichTOF++;
927 }
928 }
929 }
930 }
931 //AliInfo(Form("ichTOF = %i",ichTOF));
68343832 932 if ((indexDDL%2==0 && ichTOF!=2160) ||
933 (indexDDL%2==1 && ichTOF!=2208)) {
974c1ccc 934 AliWarning(Form("Something strange occurred, number of entries in array different from expected! Please, check! ichTOF = %i",ichTOF));
935 }
936 return;
937}
0e83a136 938
939//------------------------------------------------------------
26f75fad 940void AliTOFDecoder::PrintStack(const UInt_t *rawData, Int_t nWords, const AliRawDataHeader *cdh, const AliRawDataHeaderV3 *cdhV3)
0e83a136 941{
942 /* It loops over nWords 32-bit words
943 * starting at *rawData and prints them in 0x format.
944 * It does not decode them!
945 */
946
8fa5c3a3 947 Short_t currentMiniEventID = cdh ? cdh->GetMiniEventID() : (Short_t)(-1);
26f75fad 948 currentMiniEventID = cdhV3 ? cdhV3->GetMiniEventID() : (Short_t)(-1);
8fa5c3a3 949 Short_t currentEventID1 = cdh ? cdh->GetEventID1() : (Short_t)(-1);
26f75fad 950 currentEventID1 = cdhV3 ? cdhV3->GetEventID1() : (Short_t)(-1);
0e83a136 951 AliDebug(1, Form("EvID1 = %d, EvID2 = %d, currentMiniEventID = %d", currentEventID1, cdh->GetEventID2(), currentMiniEventID));
26f75fad 952 if (!cdh && !cdhV3)
6cbeb729 953 AliWarning("CDH not valid: deltaBunchID not reliable ");
954
0e83a136 955 AliInfo("Printing raw data stack for current equipment\n");
956 AliInfo(" wordN - Hex Word ");
957 //loop over raw data
958 for (Int_t iWord = 0; iWord < nWords; iWord++, rawData++){
959 if (iWord<10) AliInfo(Form(" %i - 0x%08x",iWord,*rawData));
960 if (iWord>9 &&iWord<100) AliInfo(Form(" %i - 0x%08x",iWord,*rawData));
961 if (iWord>99) AliInfo(Form(" %i - 0x%08x",iWord,*rawData));
962 }
963 return;
964}