]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFRawStream.cxx
Obsolete printing removed.
[u/mrichter/AliRoot.git] / TOF / AliTOFRawStream.cxx
CommitLineData
571dda3d 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/*
d0eb8f39 17$Log$
96f01799 18Revision 1.19 2007/05/18 13:07:53 decaro
19Error messages stored in the global raw-reader error log (Cvetan, Chiara)
20
019f6101 21Revision 1.18 2007/05/08 11:53:29 arcelli
22Improved class flexibility for further use (R.Preghenella)
23
2fd622fa 24Revision 1.17 2007/05/03 08:53:50 decaro
25Coding convention: RS3 violation -> suppression
26
19eefa2b 27Revision 1.16 2007/05/03 08:22:22 decaro
28Coding convention: RN17 violation -> suppression
29
dfcee998 30Revision 1.15 2007/04/30 15:22:06 arcelli
31Change TOF digit Time, Tot etc to int type
32
bf33f8f0 33Revision 1.14 2007/04/27 11:11:53 arcelli
34updates for the new decoder
35
dfcee998 36Revision 1.13 2007/03/16 11:46:35 decaro
37Coding convention: RN17 rule violation -> suppression
38
8994284f 39Revision 1.12 2007/02/22 09:43:45 decaro
40Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
41
740f0695 42Revision 1.11 2007/02/20 15:57:00 decaro
43Raw data update: to read the TOF raw data defined in UNPACKED mode
44
15ec34b9 45Revision 1.10 2006/12/15 14:01:38 cvetan
46Memory leak fixed
47
f1aa96cc 48Revision 1.9 2006/10/13 11:22:27 arcelli
49remove warnings due to uninitialized AliTOFtdcDigit data members
50
36f66fad 51Revision 1.8 2006/08/22 13:30:17 arcelli
52removal of effective c++ warnings (C.Zampolli)
53
655e379f 54Revision 1.7 2006/08/10 14:46:54 decaro
55TOF raw data format: updated version
56
d0eb8f39 57Revision 1.6.1 2006/06/28 A. De Caro, R. Preghenella:
58 Update TOF raw data format
59 according to the final version
60 (see the ALICE internal note in preparation
61 'ALICE TOF raw data format')
62 Added the methods for the correspoonding numbering
63 between the equipment IDs and the volume IDs:
64 Equip2VolNPlate(...)
65 Equip2VolNStrip(...)
66 Equip2VolNPad(...)
67
571dda3d 68Revision 0.02 2005/07/28 A. De Caro:
69 Update format TOF raw data
70 (temporary solution)
71 Correction of few wrong corrispondences
72 between 'software' and 'hardware' numberings
73
74Revision 0.01 2005/07/22 A. De Caro
75 Implement methods Next()
76 GetSector(),
77 GetPlate(),
78 GetStrip(),
79 GetPadZ(),
80 GetPadX()
81*/
82
0e46b9ae 83////////////////////////////////////////////////////////////////////////
84// //
85// This class provides access to TOF raw data in DDL files. //
86// //
87// It loops over all TOF raw data given by the AliRawReader. //
88// //
89////////////////////////////////////////////////////////////////////////
571dda3d 90
15ec34b9 91
13d6bff9 92#include "Riostream.h"
93
15ec34b9 94#include "TClonesArray.h"
95
96#include "AliDAQ.h"
d0eb8f39 97#include "AliLog.h"
571dda3d 98#include "AliRawReader.h"
99
100#include "AliTOFGeometry.h"
15ec34b9 101#include "AliTOFrawData.h"
102#include "AliTOFRawMap.h"
571dda3d 103#include "AliTOFRawStream.h"
32ead898 104//#include "AliTOFCableLengthMap.h"
571dda3d 105
5c7c93fa 106#include "AliTOFHitData.h"
d0eb8f39 107
32ead898 108#include "AliRawEventHeaderBase.h"
109
571dda3d 110ClassImp(AliTOFRawStream)
111
32ead898 112const Int_t AliTOFRawStream::fgkddlBCshift[72] =
113{
114 2, 2, -1, -1,
115 2, 3, 0, 0,
116 2, 2, 0, 0,
117 2, 2, 0, 0,
118 2, 2, 0, 0,
119 2, 2, 0, 0,
120 2, 2, 0, 0,
121 2, 2, 0, 0,
122 2, 2, 0, 0,
123 2, 2, 0, 0,
124 2, 2, -1, -1,
125 2, 2, -1, -1,
126 2, 2, -2, -2,
127 2, 2, -2, -2,
128 2, 2, -2, -2,
129 2, 2, -1, -1,
130 2, 2, -1, -1,
131 2, 2, -1, -1
132};
133
571dda3d 134
135//_____________________________________________________________________________
655e379f 136AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
15ec34b9 137 fRawReader(rawReader),
7813bb1a 138 fTOFrawData(0x0),
139 fDecoder(new AliTOFDecoder()),
655e379f 140 fDDL(-1),
141 fTRM(-1),
655e379f 142 fTRMchain(-1),
15ec34b9 143 fTDC(-1),
655e379f 144 fTDCchannel(-1),
15ec34b9 145 fTime(-1),
655e379f 146 fToT(-1),
15ec34b9 147 fLeadingEdge(-1),
148 fTrailingEdge(-1),
655e379f 149 fErrorFlag(-1),
655e379f 150 fSector(-1),
151 fPlate(-1),
152 fStrip(-1),
153 fPadX(-1),
154 fPadZ(-1),
15ec34b9 155 fPackedDigits(0),
655e379f 156 fWordType(-1),
157 fSlotID(-1),
158 fACQ(-1),
159 fPSbit(-1),
655e379f 160 fTDCerrorFlag(-1),
161 fInsideDRM(kFALSE),
162 fInsideTRM(kFALSE),
163 fInsideLTM(kFALSE),
164 fInsideTRMchain0(kFALSE),
38f24f3f 165 fInsideTRMchain1(kFALSE),
166 fLocalEventCounterDRM(-1),
167 fLocalEventCounterLTM(-1),
168 fLocalEventCounterTRM(0x0),
32ead898 169 fLocalEventCounterChain(0x0),
170 fCableLengthMap(0x0),
171 fEventID(0)
571dda3d 172{
173 //
174 // create an object to read TOF raw digits
175 //
176
7813bb1a 177 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
2fd622fa 178 fDataBuffer[i]=new AliTOFHitDataBuffer();
179 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
7813bb1a 180 }
181
182 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
183 fTOFrawData->SetOwner();
184
15ec34b9 185 fRawReader->Reset();
362c9d61 186 fRawReader->Select("TOF");
38f24f3f 187
188 fLocalEventCounterTRM = new Int_t[13];//adc
189 fLocalEventCounterChain = new Int_t*[13];//adc
190 for (Int_t j=0;j<13;j++){//adc
191 fLocalEventCounterTRM[j] = -1;//adc
192 fLocalEventCounterChain[j] = new Int_t[2];//adc
193 for (Int_t k=0;k<2;k++){//adc
194 fLocalEventCounterChain[j][k] = -1;//adc
195 }//adc
196 }//adc
197
32ead898 198 fCableLengthMap = new AliTOFCableLengthMap();
199
200 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
201 //UInt_t run = rawReader->GetRunNumber();
202 const UInt_t *id = eventHeader->GetP("Id");
203 fEventID = ((id)[1]&0x00000fff); //bunch crossing
204 //UInt_t orbit=((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff)); //orbit number
205 //UInt_t period=(((id)[0]>>4)&0x0fffffff); //period number
206 //UInt_t type=eventHeader->Get("Type"); //this is 7 in physics events
207
571dda3d 208}
209
210//_____________________________________________________________________________
655e379f 211AliTOFRawStream::AliTOFRawStream():
7813bb1a 212 fRawReader(0x0),
7813bb1a 213 fTOFrawData(0x0),
214 fDecoder(new AliTOFDecoder()),
655e379f 215 fDDL(-1),
216 fTRM(-1),
655e379f 217 fTRMchain(-1),
15ec34b9 218 fTDC(-1),
655e379f 219 fTDCchannel(-1),
15ec34b9 220 fTime(-1),
655e379f 221 fToT(-1),
15ec34b9 222 fLeadingEdge(-1),
223 fTrailingEdge(-1),
655e379f 224 fErrorFlag(-1),
655e379f 225 fSector(-1),
226 fPlate(-1),
227 fStrip(-1),
228 fPadX(-1),
229 fPadZ(-1),
15ec34b9 230 fPackedDigits(0),
655e379f 231 fWordType(-1),
232 fSlotID(-1),
233 fACQ(-1),
234 fPSbit(-1),
655e379f 235 fTDCerrorFlag(-1),
236 fInsideDRM(kFALSE),
237 fInsideTRM(kFALSE),
238 fInsideLTM(kFALSE),
239 fInsideTRMchain0(kFALSE),
38f24f3f 240 fInsideTRMchain1(kFALSE),
241 fLocalEventCounterDRM(-1),
242 fLocalEventCounterLTM(-1),
243 fLocalEventCounterTRM(0x0),
32ead898 244 fLocalEventCounterChain(0x0),
245 fCableLengthMap(0x0),
246 fEventID(0)
571dda3d 247{
248 //
d0eb8f39 249 // default ctr
571dda3d 250 //
7813bb1a 251 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
2fd622fa 252 fDataBuffer[i]=new AliTOFHitDataBuffer();
253 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
7813bb1a 254 }
15ec34b9 255
7813bb1a 256 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
257 fTOFrawData->SetOwner();
38f24f3f 258
259 fLocalEventCounterTRM = new Int_t[13];//adc
260 fLocalEventCounterChain = new Int_t*[13];//adc
261 for (Int_t j=0;j<13;j++){//adc
262 fLocalEventCounterTRM[j] = -1;//adc
263 fLocalEventCounterChain[j] = new Int_t[2];//adc
264 for (Int_t k=0;k<2;k++){//adc
265 fLocalEventCounterChain[j][k] = -1;//adc
266 }//adc
267 }//adc
268
32ead898 269 fCableLengthMap = new AliTOFCableLengthMap();
270
d0eb8f39 271}
272
273//_____________________________________________________________________________
274AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
655e379f 275 TObject(stream),
276 fRawReader(0x0),
7813bb1a 277 fTOFrawData(0x0),
278 fDecoder(new AliTOFDecoder()),
655e379f 279 fDDL(-1),
280 fTRM(-1),
655e379f 281 fTRMchain(-1),
15ec34b9 282 fTDC(-1),
655e379f 283 fTDCchannel(-1),
15ec34b9 284 fTime(-1),
655e379f 285 fToT(-1),
15ec34b9 286 fLeadingEdge(-1),
287 fTrailingEdge(-1),
655e379f 288 fErrorFlag(-1),
655e379f 289 fSector(-1),
290 fPlate(-1),
291 fStrip(-1),
292 fPadX(-1),
293 fPadZ(-1),
15ec34b9 294 fPackedDigits(0),
655e379f 295 fWordType(-1),
296 fSlotID(-1),
297 fACQ(-1),
298 fPSbit(-1),
655e379f 299 fTDCerrorFlag(-1),
300 fInsideDRM(kFALSE),
301 fInsideTRM(kFALSE),
302 fInsideLTM(kFALSE),
303 fInsideTRMchain0(kFALSE),
38f24f3f 304 fInsideTRMchain1(kFALSE),
305 fLocalEventCounterDRM(-1),
306 fLocalEventCounterLTM(-1),
307 fLocalEventCounterTRM(0x0),
32ead898 308 fLocalEventCounterChain(0x0),
309 fCableLengthMap(0x0),
310 fEventID(0)
d0eb8f39 311{
312 //
313 // copy constructor
314 //
315
316 fRawReader = stream.fRawReader;
15ec34b9 317
318 fTOFrawData = stream.fTOFrawData;
319
d0eb8f39 320 fDDL = stream.fDDL;
321 fTRM = stream.fTRM;
d0eb8f39 322 fTRMchain = stream.fTRMchain;
15ec34b9 323 fTDC = stream.fTDC;
d0eb8f39 324 fTDCchannel = stream.fTDCchannel;
15ec34b9 325 fTime = stream.fTime;
d0eb8f39 326 fToT = stream.fToT;
15ec34b9 327 fLeadingEdge = stream.fLeadingEdge;
328 fTrailingEdge = stream.fTrailingEdge;
329
d0eb8f39 330 fErrorFlag = stream.fErrorFlag;
331
332 fSector = stream.fSector;
333 fPlate = stream.fPlate;
334 fStrip = stream.fStrip;
335 fPadX = stream.fPadX;
336 fPadZ = stream.fPadZ;
337
15ec34b9 338 fPackedDigits = stream.fPackedDigits;
339
d0eb8f39 340 fWordType = stream.fWordType;
341 fSlotID = stream.fSlotID;
342 fACQ = stream.fACQ;
343 fPSbit = stream.fPSbit;
d0eb8f39 344 fTDCerrorFlag = stream.fTDCerrorFlag;
345 fInsideDRM = stream.fInsideDRM;
346 fInsideTRM = stream.fInsideTRM;
347 fInsideLTM = stream.fInsideLTM;
348 fInsideTRMchain0 = stream.fInsideTRMchain0;
349 fInsideTRMchain1 = stream.fInsideTRMchain1;
d0eb8f39 350
7813bb1a 351 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
352 fDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fDataBuffer[i]);
353 fPackedDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fPackedDataBuffer[i]);
354 }
355
356 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
38f24f3f 357
358 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;//adc
359 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;//adc
360 for (Int_t j=0;j<13;j++){//adc
361 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];//adc
362 for (Int_t k=0;k<2;k++){//adc
363 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];//adc
364 }//adc
365 }//adc
366
32ead898 367 fCableLengthMap = stream.fCableLengthMap;
368
369 fEventID = stream.fEventID;
370
571dda3d 371}
372
373//_____________________________________________________________________________
374AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
375{
376 //
377 // assignment operator
378 //
379
380 fRawReader = stream.fRawReader;
15ec34b9 381
382 fTOFrawData = stream.fTOFrawData;
383
571dda3d 384 fDDL = stream.fDDL;
385 fTRM = stream.fTRM;
d0eb8f39 386 fTRMchain = stream.fTRMchain;
15ec34b9 387 fTDC = stream.fTDC;
d0eb8f39 388 fTDCchannel = stream.fTDCchannel;
15ec34b9 389 fTime = stream.fTime;
d0eb8f39 390 fToT = stream.fToT;
15ec34b9 391 fLeadingEdge = stream.fLeadingEdge;
392 fTrailingEdge = stream.fTrailingEdge;
571dda3d 393 fErrorFlag = stream.fErrorFlag;
d0eb8f39 394
395 fSector = stream.fSector;
396 fPlate = stream.fPlate;
397 fStrip = stream.fStrip;
398 fPadX = stream.fPadX;
399 fPadZ = stream.fPadZ;
571dda3d 400
15ec34b9 401 fPackedDigits = stream.fPackedDigits;
402
d0eb8f39 403 fWordType = stream.fWordType;
404 fSlotID = stream.fSlotID;
405 fACQ = stream.fACQ;
406 fPSbit = stream.fPSbit;
d0eb8f39 407 fTDCerrorFlag = stream.fTDCerrorFlag;
408 fInsideDRM = stream.fInsideDRM;
409 fInsideTRM = stream.fInsideTRM;
410 fInsideLTM = stream.fInsideLTM;
411 fInsideTRMchain0 = stream.fInsideTRMchain0;
412 fInsideTRMchain1 = stream.fInsideTRMchain1;
7813bb1a 413
414 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
415 fDataBuffer[i] = stream.fDataBuffer[i];
416 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
417 }
418
419 fTOFrawData = stream.fTOFrawData;
38f24f3f 420
421 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;//adc
422 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;//adc
423 for (Int_t j=0;j<13;j++){//adc
424 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];//adc
425 for (Int_t k=0;k<2;k++){//adc
426 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];//adc
427 }//adc
428 }//adc
429
32ead898 430 fCableLengthMap = stream.fCableLengthMap;
431
432 fEventID = stream.fEventID;
433
571dda3d 434 return *this;
435
436}
437
438//_____________________________________________________________________________
439AliTOFRawStream::~AliTOFRawStream()
440{
441// destructor
442
15ec34b9 443 fPackedDigits = 0;
444
7813bb1a 445 for (Int_t i=0;i<72;i++){
446 delete fDataBuffer[i];
447 delete fPackedDataBuffer[i];
448 }
d3c7bfac 449
7813bb1a 450 delete fDecoder;
15ec34b9 451
7813bb1a 452 fTOFrawData->Clear();
453 delete fTOFrawData;
38f24f3f 454
415c84fa 455 delete [] fLocalEventCounterTRM;
32ead898 456 for (Int_t ii=0; ii<2; ii++)
457 delete [] fLocalEventCounterChain[ii];
458
459 delete fCableLengthMap;
38f24f3f 460
571dda3d 461}
462
463
15ec34b9 464//_____________________________________________________________________________
465
466void AliTOFRawStream::LoadRawData(Int_t indexDDL)
467{
0192b95f 468 //
469 // To load raw data
470 //
15ec34b9 471
74cd22f8 472 fTOFrawData->Clear();
0192b95f 473
74cd22f8 474 TClonesArray &arrayTofRawData = *fTOFrawData;
475
15ec34b9 476 fPackedDigits = 0;
477
478 // create raw data map
479 AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
480 rawMap->Clear();
481
482 Int_t slot[4] = {-1, -1, -1, -1};
483
415c84fa 484 fLocalEventCounterDRM = -1;
485 fLocalEventCounterLTM = -1;
486 for (Int_t ii=0; ii<13; ii++)
487 fLocalEventCounterTRM[ii] = -1;
488 for (Int_t ii=0; ii<13; ii++)
489 for (Int_t jj=0; jj<2; jj++)
490 fLocalEventCounterChain[ii][jj] = -1;
491
15ec34b9 492 fRawReader->Reset();
493 fRawReader->Select("TOF", indexDDL, indexDDL);
494
495 Bool_t signal = kFALSE;
496
74cd22f8 497 AliTOFrawData *rawDigit = NULL;
7813bb1a 498
15ec34b9 499 while(Next()) {
500
501 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
502 if (signal) {
38f24f3f 503 AliDebug(2,Form(" %2i %1i %2i %1i %2i", fSector, fPlate, fStrip, fPadZ, fPadX));
15ec34b9 504
505 slot[0] = fTRM;
506 slot[1] = fTRMchain;
507 slot[2] = fTDC;
508 slot[3] = fTDCchannel;
509
510 if (rawMap->TestHit(slot) != kEmpty) {
511
74cd22f8 512 rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
15ec34b9 513
514 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
515 fLeadingEdge==-1 && fTrailingEdge!=-1) {
516
517 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
518 }
519 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
520 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
521
0192b95f 522 )
15ec34b9 523 {
524
74cd22f8 525 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
15ec34b9 526
74cd22f8 527 rawMap->SetHit(slot);
15ec34b9 528
74cd22f8 529 }
15ec34b9 530
531
532 }
533 else {
534
15ec34b9 535 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
536
537 rawMap->SetHit(slot);
538
539 } // else if (rawMap->TestHit(slot) == kEmpty)
540
541 } // if (signal)
542
543 } // closed -> while (Next())
544
74cd22f8 545 rawMap->Delete();
7813bb1a 546
15ec34b9 547}
548
571dda3d 549//_____________________________________________________________________________
550Bool_t AliTOFRawStream::Next()
551{
d0eb8f39 552 //
553 // Read next 32-bit word in TOF raw data files
554 // returns kFALSE if there is no word left
555 //
571dda3d 556
557 UInt_t data;
558
38f24f3f 559 Int_t dummy = 0;
560
571dda3d 561 if (!fRawReader->ReadNextInt(data)) return kFALSE;
562
d0eb8f39 563 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
564 fSector = -1;
15ec34b9 565 fPlate = -1;
566 fStrip = -1;
567 fPadZ = -1;
568 fPadX = -1;
569 fTime = -1;
570 fToT = -1;
571 fLeadingEdge = -1;
572 fTrailingEdge = -1;
d0eb8f39 573 }
571dda3d 574
571dda3d 575 fDDL = fRawReader->GetDDLID();
576
d0eb8f39 577 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
578
579 switch (fWordType) { // switch word type
580
581 case GLOBAL_HEADER_TYPE: // global header
582 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
583 fTRM = fSlotID;
584
585
586 switch (fSlotID) { // switch global header slot ID
587
588 case DRM_ID_NUMBER: //DRM global header
589 if (fInsideDRM) { // unexpected DRM global headers -> exit
590 break;
591 }
592 fInsideDRM = kTRUE; // DRM global header accepted
593 break;
594
595 case LTM_ID_NUMBER: // LTM global header
596 if (fInsideLTM) { // unexpected LTM global headers -> exit
597 break;
598 }
599 fInsideLTM = kTRUE; // LTM global header accepted
600 break;
601
602 case 3: //TRM header
603 case 4: //TRM header
604 case 5: //TRM header
605 case 6: //TRM header
606 case 7: //TRM header
607 case 8: //TRM header
608 case 9: //TRM header
609 case 10: //TRM header
610 case 11: //TRM header
611 case 12: //TRM header
612 if (fInsideTRM) { // unexpected TRM global headers -> exit
613 break;
614 }
615 fInsideTRM = kTRUE; // TRM global header accepted
616 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
617 break;
618
619 default: // unexpected global header slot ID
620 break;
621
622 } //end switch global header slot id
623
624 break;
625
626
627 case GLOBAL_TRAILER_TYPE: // global trailer
628 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
d0eb8f39 629
630 switch (fSlotID) { // switch global trailer slot ID
631
632 case DRM_ID_NUMBER: // DRM global trailer
633 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
634 break;
635 }
38f24f3f 636 dummy = 0x0000fff0;
637 //AliInfo(Form(" DRM local event counter = %i", GetField(data,dummy,4)));
638 fLocalEventCounterDRM = GetField(data,dummy,4);//adc
d0eb8f39 639 fInsideDRM = kFALSE; // DRM global trailer accepted
640 fInsideTRM = kFALSE;
641 fInsideLTM = kFALSE;
642 fInsideTRMchain0 = kFALSE;
643 fInsideTRMchain1 = kFALSE;
d0eb8f39 644 fSector = -1;
15ec34b9 645 fPlate = -1;
646 fStrip = -1;
647 fPadZ = -1;
648 fPadX = -1;
649 fDDL = -1;
650 fTRM = -1;
651 fTDC = -1;
652 fTRMchain = -1;
d0eb8f39 653 fTDCchannel = -1;
15ec34b9 654 fTime = -1;
655 fToT = -1;
656 fLeadingEdge = -1;
657 fTrailingEdge = -1;
d0eb8f39 658 fErrorFlag = -1;
15ec34b9 659 fACQ = -1;
d0eb8f39 660 fPSbit = -1;
d0eb8f39 661 fTDCerrorFlag = -1;
662 break;
663 case LTM_ID_NUMBER: // LTM global trailer
664 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
665 break;
666 }
38f24f3f 667 dummy = 0x0fff0000;
668 //AliInfo(Form(" LTM local event counter = %i", GetField(data,dummy,16)));
669 fLocalEventCounterLTM = GetField(data,dummy,16);//adc
d0eb8f39 670 fInsideLTM = kFALSE; // LTM global trailer accepted
671 break;
672 case 15: //TRM global trailer
673 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
674 break;
675 }
38f24f3f 676 dummy = 0x0fff0000;
677 //AliInfo(Form(" TRM local event counter = %i", GetField(data,dummy,16)));
678 fLocalEventCounterTRM[fTRM] = GetField(data,dummy,16);//adc
d0eb8f39 679 fInsideTRM = kFALSE; // TRM global trailer accepted
680 break;
681 default: // unexpected global trailer slot ID
682 break;
683 } //end switch global trailer slot id
684
685
686 break;
687
688
689 case ERROR_TYPE: // TDC error
15ec34b9 690 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
d0eb8f39 691 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
692 break;
693
694
695 case FILLER_TYPE: // filler
696 break;
697
698
699 default: // other word types
700
701 if (fInsideTRM) { // inside TRM
702
703 switch (fWordType) { // switch word type inside TRM
704 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
705 if (fInsideTRMchain0) { // unexpected TRM chain0 header
706 break;
707 }
708 fInsideTRMchain0 = kTRUE;
709 fTRMchain = 0;
710 break;
711 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
712 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
713 break;
714 }
38f24f3f 715 dummy = 0x0fff0000;
716 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
717 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);//adc
d0eb8f39 718 fInsideTRMchain0 = kFALSE;
719 fTRMchain = -1;
720 break;
721 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
722 if (fInsideTRMchain1) { // unexpected TRM chain1 header
723 break;
724 }
725 fInsideTRMchain1 = kTRUE;
726 fTRMchain = 1;
727 break;
728 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
729 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
730 break;
731 }
38f24f3f 732 dummy = 0x0fff0000;
733 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
734 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);//adc
d0eb8f39 735 fInsideTRMchain1 = kFALSE;
736 fTRMchain = -1;
737 break;
738 } // end switch word type inside TRM
739
740 } // end if (fInsideTRM)
741
742
743 if (
744 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
745 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
746 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
747 ){ // inside TRM chains
15ec34b9 748
749 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
750 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
d0eb8f39 751 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
15ec34b9 752 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
753
754 SetSector();
755 SetPlate();
756 SetStrip();
757 SetPadZ();
758 SetPadX();
759
d0eb8f39 760
761 switch (fPSbit) { // switch fPSbit bits inside TRM chains
15ec34b9 762
763 case 0: // packing ok, digit time and TOT
764 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
32ead898 765 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
766 -
767 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)
768 /*+
769 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
770 +
771 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth())*/
772 ;
d0eb8f39 773 break;
774
775 case 1: // leading edge digit, long digit time, no TOT
15ec34b9 776 //fToT = -1;
777 //fTime = -1;
32ead898 778 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
779 -
780 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)
781 /*+
782 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
783 +
784 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth())*/
785 ;
d0eb8f39 786 break;
787
788 case 2: // trailing edge digit, long digit time, no TOT
15ec34b9 789 //fToT = -1;
790 //fTime = -1;
32ead898 791 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
792 -
793 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)
794 /*+
795 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
796 +
797 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth())*/
798 ;
d0eb8f39 799 break;
15ec34b9 800
d0eb8f39 801 case 3: // TOT overflow
15ec34b9 802 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
32ead898 803 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
804 -
805 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)
806 /*+
807 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
808 +
809 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth())*/
810 ;
d0eb8f39 811 break;
d0eb8f39 812
15ec34b9 813 } // end switch PS bits inside TRM chains
d0eb8f39 814
815 } // end if is inside TRM chains
816
817 } // end switch on fWordType
571dda3d 818
15ec34b9 819
571dda3d 820 return kTRUE;
7813bb1a 821
571dda3d 822}
823//_____________________________________________________________________________
824
d0eb8f39 825void AliTOFRawStream::SetSector()
571dda3d 826{
827 //
d0eb8f39 828 // Evaluate the TOF sector number -> [ 0;17]
829 // corresponding to the TOF equipment IDs:
830 // fDDL -> [ 0;71]
831 // fTRM -> [ 3;12]
15ec34b9 832 // fTRMchain -> [ 0; 1]
d0eb8f39 833 // fTDC -> [ 0;14]
834 // fTDCchannel -> [ 0; 7]
571dda3d 835 //
836
837 Int_t iSector = -1;
571dda3d 838
d0eb8f39 839 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
840
841 fSector = iSector;
571dda3d 842
843}
844//_____________________________________________________________________________
845
d0eb8f39 846
847void AliTOFRawStream::SetPlate()
571dda3d 848{
849 //
d0eb8f39 850 // Evaluate the TOF plate number ->[ 0; 4]
851 // corresponding to the TOF equipment IDs:
852 // fDDL -> [ 0;71]
853 // fTRM -> [ 3;12]
15ec34b9 854 // fTRMchain -> [ 0; 1]
d0eb8f39 855 // fTDC -> [ 0;14]
856 // fTDCchannel -> [ 0; 7]
571dda3d 857 //
858
859 Int_t iPlate = -1;
d0eb8f39 860 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
861 || fSector==-1))
862 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
571dda3d 863
d0eb8f39 864 fPlate = iPlate;
571dda3d 865
866}
867//_____________________________________________________________________________
868
d0eb8f39 869void AliTOFRawStream::SetStrip()
571dda3d 870{
871 //
d0eb8f39 872 // Evaluate the TOF strip number per module -> [ 0; 14/18]
873 // corresponding to the TOF equipment IDs:
874 // fDDL -> [ 0;71]
875 // fTRM -> [ 3;12]
15ec34b9 876 // fTRMchain -> [ 0; 1]
d0eb8f39 877 // fTDC -> [ 0;14]
878 // fTDCchannel -> [ 0; 7]
571dda3d 879 //
880
881 Int_t iStrip = -1;
882
d0eb8f39 883 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
884 || fSector==-1 || fPlate==-1))
885 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
571dda3d 886
d0eb8f39 887 fStrip = iStrip;
571dda3d 888
889}
890//_____________________________________________________________________________
891
d0eb8f39 892void AliTOFRawStream::SetPadZ()
571dda3d 893{
894 //
d0eb8f39 895 // Evaluate the TOF padRow number per strip -> [ 0; 1]
896 // corresponding to the TOF equipment IDs:
897 // fDDL -> [ 0;71]
898 // fTRM -> [ 3;12]
15ec34b9 899 // fTRMchain -> [ 0; 1]
d0eb8f39 900 // fTDC -> [ 0;14]
901 // fTDCchannel -> [ 0; 7]
571dda3d 902 //
903
904 Int_t iPadZ = -1;
905
d0eb8f39 906 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
907 || fSector==-1 || fPlate==-1 || fStrip==-1))
908 {
909 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
910 if (iPadAlongTheStrip!=-1)
911 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
912 }
571dda3d 913
38f24f3f 914 //iPadZ = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)%AliTOFGeometry::NpadZ();
915 //iPadZ = Equip2VolNpadZ(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
916
d0eb8f39 917 fPadZ = iPadZ;
571dda3d 918
d0eb8f39 919}
920//_____________________________________________________________________________
921
922void AliTOFRawStream::SetPadX()
923{
924 //
925 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
926 // corresponding to the TOF equipment IDs:
927 // fDDL -> [ 0;71]
928 // fTRM -> [ 3;12]
15ec34b9 929 // fTRMchain -> [ 0; 1]
d0eb8f39 930 // fTDC -> [ 0;14]
931 // fTDCchannel -> [ 0; 7]
932 //
571dda3d 933
d0eb8f39 934 Int_t iPadX = -1;
571dda3d 935
d0eb8f39 936 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
937 || fSector==-1 || fPlate==-1 || fStrip==-1))
938 {
939 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
940 if (iPadAlongTheStrip!=-1)
941 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
942 }
943
38f24f3f 944 //iPadX = (Int_t)(Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)/(Float_t(AliTOFGeometry::NpadZ())));
945 //iPadX = Equip2VolNpadX(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
946
d0eb8f39 947 fPadX = iPadX;
571dda3d 948
949}
571dda3d 950
d0eb8f39 951//----------------------------------------------------------------------------
952Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
953{
954 //
955 //
956 //
957
958 return ((word & fieldMask) >> fieldPosition);
959}
960
961//----------------------------------------------------------------------------
13d6bff9 962Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC)
571dda3d 963{
964 //
d0eb8f39 965 // Returns the TOF plate number [0;4]
966 // corresponding to the TOF equipment ID numbers:
967 // iDDL -> DDL number per sector [0;3]
968 // nTRM -> TRM number [3;12]
969 // nTDC -> TDC number [0;14]
571dda3d 970 //
971
d0eb8f39 972 Int_t iPlate = -1;
973 if (iDDL==0) {
974
975 if (nTRM>=4 && nTRM<7) {
976 iPlate = 0;
977 } else if (nTRM==7) {
978 if (nTDC<12) iPlate = 0;
979 else iPlate = 1;
980 } else if (nTRM>=8 && nTRM<11) {
981 iPlate = 1;
982 } else if (nTRM==11) {
983 if (nTDC<9) iPlate = 1;
984 else iPlate = 2;
985 }else if (nTRM==12) {
986 iPlate = 2;
987 }
988
989 } else if (iDDL==1) {
990
991 if (nTRM==3) {
992 if (nTDC<3) iPlate = 0;
993 } else if (nTRM>=4 && nTRM<7) {
994 iPlate = 0;
995 } else if (nTRM==7) {
996 if (nTDC<6) iPlate = 1;
997 else iPlate = 0;
998 } else if (nTRM>=8 && nTRM<11) {
999 iPlate = 1;
1000 } else if (nTRM==11) {
1001 if (nTDC<9) iPlate = 2;
1002 else iPlate = 1;
1003 } else if (nTRM==12) {
1004 iPlate = 2;
1005 }
1006
1007 } else if (iDDL==2) {
1008
1009 if (nTRM>=4 && nTRM<7) {
1010 iPlate = 4;
1011 } else if (nTRM==7) {
1012 if (nTDC<12) iPlate = 4;
1013 else iPlate = 3;
1014 } else if (nTRM>=8 && nTRM<11) {
1015 iPlate = 3;
1016 } else if (nTRM==11) {
1017 if (nTDC<9) iPlate = 3;
1018 else iPlate = 2;
1019 }else if (nTRM==12) {
1020 iPlate = 2;
1021 }
1022
1023 } else if (iDDL==3) {
1024
1025 if (nTRM==3) {
1026 if (nTDC<3) iPlate = 4;
1027 } else if (nTRM>=4 && nTRM<7) {
1028 iPlate = 4;
1029 } else if (nTRM==7) {
1030 if (nTDC<6) iPlate = 3;
1031 else iPlate = 4;
1032 } else if (nTRM>=8 && nTRM<11) {
1033 iPlate = 3;
1034 } else if (nTRM==11) {
1035 if (nTDC<9) iPlate = 2;
1036 else iPlate = 3;
1037 } else if (nTRM==12) {
1038 iPlate = 2;
1039 }
571dda3d 1040
d0eb8f39 1041 }
571dda3d 1042
d0eb8f39 1043 return iPlate;
571dda3d 1044
d0eb8f39 1045}
571dda3d 1046
d0eb8f39 1047//----------------------------------------------------------------------------
13d6bff9 1048Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC)
d0eb8f39 1049{
1050 //
1051 // Returns the TOF strip number per module:
1052 // [0;14], in the central plates,
1053 // [0;18], in the intermediate and external plates
1054 // corresponding to the TOF equipment ID numbers:
1055 // iDDL -> DDL number per sector [0;3]
1056 // nTRM -> TRM number [3;12]
1057 // nTDC -> TDC number [0;14]
1058 //
571dda3d 1059
d0eb8f39 1060 Int_t iStrip = -1;
571dda3d 1061
d0eb8f39 1062 if (iDDL==0) {
1063
1064 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
1065 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
1066 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
1067 else if (nTRM== 7) {
1068 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
1069 else iStrip = (Int_t)(nTDC/3.) - 4;
1070 }
1071 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
1072 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
1073 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
1074 else if (nTRM==11) {
1075 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
1076 else iStrip = (Int_t)(nTDC/3.) - 3;
1077 }
1078 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
1079
1080 } else if (iDDL==1) {
1081
1082 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
1083 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
1084 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
1085 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
1086 else if (nTRM== 7) {
1087 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
1088 else iStrip = 20 - (Int_t)(nTDC/3.);
1089 }
1090 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
1091 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
1092 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
1093 else if (nTRM==11) {
1094 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
1095 else iStrip = 21 - (Int_t)(nTDC/3.);
1096 }
1097 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
1098
1099 } else if (iDDL==2) {
1100
1101 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
1102 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
1103 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
1104 else if (nTRM== 7) {
1105 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
1106 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
1107 }
1108 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
1109 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
1110 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
1111 else if (nTRM==11) {
1112 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
1113 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
1114 }
1115 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
1116
1117 } else if (iDDL==3) {
1118
1119 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
1120 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
1121 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
1122 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
1123 else if (nTRM== 7) {
1124 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
1125 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
1126 }
1127 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
1128 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
1129 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
1130 else if (nTRM==11) {
1131 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1132 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1133 }
1134 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1135
1136 }
1137
1138 return iStrip;
1139
1140}
1141
1142//----------------------------------------------------------------------------
1143Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
13d6bff9 1144 Int_t iCH)
d0eb8f39 1145{
1146 //
1147 // Returns the TOF pad number per strip [0;95]
1148 // corresponding to the TOF equipment ID numbers:
1149 // iDDL -> DDL number per sector [0;3]
1150 // iChain -> TRM chain number [0;1]
1151 // nTDC -> TDC number [0;14]
1152 // iCH -> TDC channel number [0;7]
1153 //
1154
1155 Int_t iPadAlongTheStrip = -1;
1156
38f24f3f 1157 // wrong
1158 //Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1159 //if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1160 //else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
d0eb8f39 1161
38f24f3f 1162 // right
1163 Int_t iTDClocal = -1;
1164 Int_t iTDClocal03 = nTDC%3 + (1-iChain)*3;
1165 Int_t iTDClocal12 = 2-nTDC%3 + iChain*3;
1166 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal03;
1167 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal12);
d0eb8f39 1168
1169 Int_t iCHlocal = iCH;
1170 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1171
1172 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1173
1174 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
019f6101 1175 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
13d6bff9 1176 std::cerr << "Problems with the padX number!" << endl;
1177 //AliWarning("Problems with the padX number!");
019f6101 1178 }
d0eb8f39 1179 return iPadAlongTheStrip;
1180
1181}
1182
38f24f3f 1183//----------------------------------------------------------------------------
1184Int_t AliTOFRawStream::Equip2VolNpadX(Int_t iDDL, Int_t iChain, Int_t nTDC,
1185 Int_t iCH)
1186{
1187 //
1188 // Returns the TOF padX number [0;47]
1189 // corresponding to the TOF equipment ID numbers:
1190 // iDDL -> DDL number per sector [0;3]
1191 // iChain -> TRM chain number [0;1]
1192 // nTDC -> TDC number [0;14]
1193 // iCH -> TDC channel number [0;7]
1194 //
1195
1196 Int_t iPadX = (Int_t)(AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)/
1197 (Float_t(AliTOFGeometry::NpadZ())));
1198
1199 return iPadX;
1200
1201}
1202
1203//----------------------------------------------------------------------------
1204Int_t AliTOFRawStream::Equip2VolNpadZ(Int_t iDDL, Int_t iChain, Int_t nTDC,
1205 Int_t iCH)
1206{
1207 //
1208 // Returns the TOF padZ number [0;1]
1209 // corresponding to the TOF equipment ID numbers:
1210 // iDDL -> DDL number per sector [0;3]
1211 // iChain -> TRM chain number [0;1]
1212 // nTDC -> TDC number [0;14]
1213 // iCH -> TDC channel number [0;7]
1214 //
1215
1216 Int_t iPadZ = AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1217
1218 return iPadZ;
1219
1220}
1221
d0eb8f39 1222//----------------------------------------------------------------------------
1223Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL) const
1224{
1225 //
1226 // Returns the sector number [0;17]
1227 // corresponing to the assigned DRM/DDL number [0;71]
1228 //
1229
1230 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1231
1232 return iSector;
1233
1234}
1235//----------------------------------------------------------------------------
1236Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL) const
1237{
1238 //
1239 // Return the DRM/DDL number per sector [0;3]
1240 // corresponing to the assigned DRM/DDL number [0;71]
1241 //
1242
1243 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1244
1245 return iDDL;
1246
1247}
1248
7813bb1a 1249//----------------------------------------------------------------------------
1250void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1251{
1252 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1253}
d0eb8f39 1254//----------------------------------------------------------------------------
1255void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1256 Int_t nTDC, Int_t iCH,
1257 Int_t *volume) const
1258{
1259 //
1260 // To convert:
1261 // nDDL (variable in [0;71]) -> number of the DDL file
1262 // nTRM (variable in [3;12]) -> number of the TRM slot
1263 // iChain (variable in [0; 1]) -> number of the TRM chain
1264 // nTDC (variable in [0;14]) -> number of the TDC
1265 // iCH (variable in [0; 7]) -> number of the TDC channel
1266 //
1267 // in:
1268 // sector number, i.e. volume[0] (variable in [0,17])
1269 // plate number, i.e. volume[1] (variable in [0, 5])
1270 // strip number, i.e. volume[2] (variable in [0,14/18])
1271 // padX number, i.e. volume[3] (variable in [0,47])
1272 // padZ number, i.e. volume[4] (variable in [0, 1])
1273 //
1274
1275 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1276
1277 Int_t iSector = GetSectorNumber(nDDL);
1278
1279 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
019f6101 1280 if (iPlate==-1) {
13d6bff9 1281 if (fRawReader)
1282 fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");
019f6101 1283 AliWarning("Problems with the plate number!");
1284 }
d0eb8f39 1285
1286 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
019f6101 1287 if (iStrip==-1) {
13d6bff9 1288 if (fRawReader)
1289 fRawReader->AddMajorErrorLog(kStripError,"strip = -1");
019f6101 1290 AliWarning("Problems with the strip number!");
1291 }
d0eb8f39 1292
1293 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
019f6101 1294 if (iPadAlongTheStrip==-1){
13d6bff9 1295 if (fRawReader)
1296 fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");
019f6101 1297 AliWarning("Problems with the pad number along the strip!");
1298 }
13d6bff9 1299
d0eb8f39 1300 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1301 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
38f24f3f 1302
1303 //Int_t iPadX = (Int_t)(Equip2VolNpad(iDDL, iChain, nTDC, iCH)/(Float_t(AliTOFGeometry::NpadZ())));
1304 //Int_t iPadZ = Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1305
1306 //Int_t iPadX = Equip2VolNpadX(iDDL, iChain, nTDC, iCH);
1307 //Int_t iPadZ = Equip2VolNpadZ(iDDL, iChain, nTDC, iCH);
1308
d0eb8f39 1309 volume[0] = iSector;
1310 volume[1] = iPlate;
1311 volume[2] = iStrip;
1312 volume[3] = iPadX;
1313 volume[4] = iPadZ;
571dda3d 1314
1315}
7813bb1a 1316//-----------------------------------------------------------------------------
019f6101 1317Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose = 0) {
1318 //
1319 // To decode raw data for DDL number in [nDDLmin; nDDLmax]
1320 //
1321
7813bb1a 1322 //check and fix valid DDL range
019f6101 1323 if (nDDLMin < 0){
1324 nDDLMin = 0;
1325 fRawReader->AddMinorErrorLog(kDDLMinError);
1326 AliWarning("Wrong DDL range: setting first DDL ID to 0");
7813bb1a 1327 }
019f6101 1328 if (nDDLMax > 71){
1329 nDDLMax = 71;
1330 fRawReader->AddMinorErrorLog(kDDLMaxError);
1331 AliWarning("Wrong DDL range: setting last DDL ID to 71");
7813bb1a 1332 }
1333
1334 //select required DDLs
019f6101 1335 fRawReader->Select("TOF", nDDLMin, nDDLMax);
7813bb1a 1336
1337 if (verbose)
019f6101 1338 AliInfo(Form("Selected TOF DDL range: %d-%d", nDDLMin, nDDLMax));
7813bb1a 1339
2fd622fa 1340 return(Decode(verbose));
1341}
1342//-----------------------------------------------------------------------------
019f6101 1343Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
1344 //
1345 // New decoder method
1346 //
1347
2fd622fa 1348 Int_t currentEquipment;
1349 Int_t currentDDL;
1350
1351 //pointers
1352 UChar_t *data = 0x0;
1353
7813bb1a 1354 //loop and read DDL headers
1355 while(fRawReader->ReadHeader()){
1356
1357 //memory leak prevention (actually data should be always 0x0 here)
1358 if (data != 0x0)
1359 delete [] data;
1360
1361 //get equipment infos
1362 currentEquipment = fRawReader->GetEquipmentId();
1363 currentDDL = fRawReader->GetDDLID();
1364 const Int_t kDataSize = fRawReader->GetDataSize();
1365 const Int_t kDataWords = kDataSize / 4;
1366 data = new UChar_t[kDataSize];
1367
1368 if (verbose)
1369 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1370
1371 if (verbose)
1372 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1373
1374 //read equipment payload
1375 if (!fRawReader->ReadNext(data, kDataSize))
1376 {
019f6101 1377 fRawReader->AddMajorErrorLog(kDDLdataReading);
7813bb1a 1378 if (verbose)
019f6101 1379 AliWarning("Error while reading DDL data. Go to next equipment");
7813bb1a 1380 delete [] data;
1381 data = 0x0;
1382 continue;
1383 }
1384
1385 if (verbose)
1386 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1387
1388
1389 //set up the decoder
1390 fDecoder->SetVerbose(verbose);
1391 fDecoder->SetDataBuffer(fDataBuffer[currentDDL]);
1392 fDecoder->SetPackedDataBuffer(fPackedDataBuffer[currentDDL]);
1393
1394 //start decoding
019f6101 1395 if (fDecoder->Decode((UInt_t *)data, kDataWords) == kTRUE) {
1396 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1397 AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1398 }
7813bb1a 1399
1400 delete [] data;
1401 data = 0x0;
1402 }
1403
1404 //reset reader
1405 fRawReader->Reset();
1406
1407 if (verbose)
1408 AliInfo("All done");
1409
1410 return kFALSE;
1411
1412}
1413//---------------------------------------------------------------------------
1414void
1415AliTOFRawStream::ResetBuffers()
1416{
19eefa2b 1417 //
1418 // To reset the buffers
1419 //
1420
7813bb1a 1421 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1422 ResetDataBuffer(iDDL);
1423 ResetPackedDataBuffer(iDDL);
1424 }
1425}
1426
1427//---------------------------------------------------------------------------
1428Bool_t
1429AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1430{
19eefa2b 1431 //
1432 // To load the buffers
1433 //
1434
7813bb1a 1435 fTOFrawData->Clear();
1436 fPackedDigits = 0;
1437
1438 if (verbose > 0)
1439 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1440
1441 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
019f6101 1442 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",indexDDL));
1443 AliWarning(Form("Error while decoding DDL # %d", indexDDL));
7813bb1a 1444 return kTRUE;
1445 }
1446
1447 if (verbose > 0)
1448 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL]->GetEntries(), fPackedDataBuffer[indexDDL]->GetEntries() > 1 ? "hits have" : "hit has"));
1449
1450 AliTOFHitData *hitData; //hit data pointer
1451
1452 if (verbose > 0)
1453 AliInfo("Filling TClonesArray ...");
1454
1455 //loop over DDL packed hits
1456 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL]->GetEntries(); iHit++){
1457 hitData = fPackedDataBuffer[indexDDL]->GetHit(iHit); //get hit data
1458 Int_t hitACQ = hitData->GetACQ();
1459 Int_t hitPS = hitData->GetPS();
1460 Int_t hitSlotID = hitData->GetSlotID();
1461 Int_t hitChain = hitData->GetChain();
1462 Int_t hitTDC = hitData->GetTDC();
1463 Int_t hitChan = hitData->GetChan();
7813bb1a 1464 Int_t hitTimeBin = hitData->GetTimeBin();
7813bb1a 1465 Int_t hitTOTBin = hitData->GetTOTBin();
1466
32ead898 1467 Int_t hitLeading = hitData->GetTimeBin()
1468 -
1469 fCableLengthMap->GetCableTimeShiftBin(indexDDL, hitSlotID, hitChain, hitTDC);//-1; // adc
bf33f8f0 1470 Int_t hitTrailing = -1;
1471 Int_t hitError = -1;
7813bb1a 1472
1473 TClonesArray &arrayTofRawData = *fTOFrawData;
bf33f8f0 1474 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
7813bb1a 1475 }
1476
1477 if (verbose > 0)
1478 AliInfo("Done.");
1479
1480 if (verbose > 0)
1481 AliInfo("Resetting buffers ...");
1482
1483 fDataBuffer[indexDDL]->Reset();
1484 fPackedDataBuffer[indexDDL]->Reset();
1485
1486 if (verbose > 0)
1487 AliInfo("Done.");
1488
1489 return kFALSE;
1490}
1491