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