]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFRawStream.cxx
TOF raw data decoding classes split in more files
[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$
dd824655 18Revision 1.19.1 2008/09/19 preghenella
19 Decode method updated:
20 it reads the CDH from the rawReader and sends it to the decoder;
21 LoadRawDataBuffers modified:
22 it corrects tof hit infos per ddlBC and deltaBC offsets
23 (in case of the static member fgApplyBCCorrections
24 has been setted to kTRUE);
25 Added static member fgApplyBCCorrections (kTRUE by default)
26 and the related static method ApplyBCCorrections;
27
96f01799 28Revision 1.19 2007/05/18 13:07:53 decaro
29Error messages stored in the global raw-reader error log (Cvetan, Chiara)
30
019f6101 31Revision 1.18 2007/05/08 11:53:29 arcelli
32Improved class flexibility for further use (R.Preghenella)
33
2fd622fa 34Revision 1.17 2007/05/03 08:53:50 decaro
35Coding convention: RS3 violation -> suppression
36
19eefa2b 37Revision 1.16 2007/05/03 08:22:22 decaro
38Coding convention: RN17 violation -> suppression
39
dfcee998 40Revision 1.15 2007/04/30 15:22:06 arcelli
41Change TOF digit Time, Tot etc to int type
42
bf33f8f0 43Revision 1.14 2007/04/27 11:11:53 arcelli
44updates for the new decoder
45
dfcee998 46Revision 1.13 2007/03/16 11:46:35 decaro
47Coding convention: RN17 rule violation -> suppression
48
8994284f 49Revision 1.12 2007/02/22 09:43:45 decaro
50Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
51
740f0695 52Revision 1.11 2007/02/20 15:57:00 decaro
53Raw data update: to read the TOF raw data defined in UNPACKED mode
54
15ec34b9 55Revision 1.10 2006/12/15 14:01:38 cvetan
56Memory leak fixed
57
f1aa96cc 58Revision 1.9 2006/10/13 11:22:27 arcelli
59remove warnings due to uninitialized AliTOFtdcDigit data members
60
36f66fad 61Revision 1.8 2006/08/22 13:30:17 arcelli
62removal of effective c++ warnings (C.Zampolli)
63
655e379f 64Revision 1.7 2006/08/10 14:46:54 decaro
65TOF raw data format: updated version
66
d0eb8f39 67Revision 1.6.1 2006/06/28 A. De Caro, R. Preghenella:
68 Update TOF raw data format
69 according to the final version
70 (see the ALICE internal note in preparation
71 'ALICE TOF raw data format')
72 Added the methods for the correspoonding numbering
73 between the equipment IDs and the volume IDs:
74 Equip2VolNPlate(...)
75 Equip2VolNStrip(...)
76 Equip2VolNPad(...)
77
571dda3d 78Revision 0.02 2005/07/28 A. De Caro:
79 Update format TOF raw data
80 (temporary solution)
81 Correction of few wrong corrispondences
82 between 'software' and 'hardware' numberings
83
84Revision 0.01 2005/07/22 A. De Caro
85 Implement methods Next()
86 GetSector(),
87 GetPlate(),
88 GetStrip(),
89 GetPadZ(),
90 GetPadX()
91*/
92
0e46b9ae 93////////////////////////////////////////////////////////////////////////
94// //
95// This class provides access to TOF raw data in DDL files. //
96// //
97// It loops over all TOF raw data given by the AliRawReader. //
98// //
99////////////////////////////////////////////////////////////////////////
571dda3d 100
15ec34b9 101
13d6bff9 102#include "Riostream.h"
103
15ec34b9 104#include "TClonesArray.h"
105
106#include "AliDAQ.h"
d0eb8f39 107#include "AliLog.h"
571dda3d 108#include "AliRawReader.h"
109
110#include "AliTOFGeometry.h"
15ec34b9 111#include "AliTOFrawData.h"
112#include "AliTOFRawMap.h"
571dda3d 113#include "AliTOFRawStream.h"
32ead898 114//#include "AliTOFCableLengthMap.h"
571dda3d 115
5c7c93fa 116#include "AliTOFHitData.h"
d0eb8f39 117
32ead898 118#include "AliRawEventHeaderBase.h"
143cfc81 119#include "AliRawDataHeader.h"
32ead898 120
571dda3d 121ClassImp(AliTOFRawStream)
122
32ead898 123const Int_t AliTOFRawStream::fgkddlBCshift[72] =
124{
125 2, 2, -1, -1,
cfceaf15 126 2, 2, 0, 0,
32ead898 127 2, 2, 0, 0,
128 2, 2, 0, 0,
129 2, 2, 0, 0,
130 2, 2, 0, 0,
131 2, 2, 0, 0,
132 2, 2, 0, 0,
133 2, 2, 0, 0,
134 2, 2, 0, 0,
135 2, 2, -1, -1,
136 2, 2, -1, -1,
137 2, 2, -2, -2,
138 2, 2, -2, -2,
139 2, 2, -2, -2,
140 2, 2, -1, -1,
141 2, 2, -1, -1,
142 2, 2, -1, -1
143};
144
dd824655 145Bool_t AliTOFRawStream::fgApplyBCCorrections = kTRUE;
571dda3d 146//_____________________________________________________________________________
655e379f 147AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
15ec34b9 148 fRawReader(rawReader),
7813bb1a 149 fTOFrawData(0x0),
150 fDecoder(new AliTOFDecoder()),
655e379f 151 fDDL(-1),
152 fTRM(-1),
655e379f 153 fTRMchain(-1),
15ec34b9 154 fTDC(-1),
655e379f 155 fTDCchannel(-1),
15ec34b9 156 fTime(-1),
655e379f 157 fToT(-1),
15ec34b9 158 fLeadingEdge(-1),
159 fTrailingEdge(-1),
655e379f 160 fErrorFlag(-1),
655e379f 161 fSector(-1),
162 fPlate(-1),
163 fStrip(-1),
164 fPadX(-1),
165 fPadZ(-1),
15ec34b9 166 fPackedDigits(0),
655e379f 167 fWordType(-1),
168 fSlotID(-1),
169 fACQ(-1),
170 fPSbit(-1),
655e379f 171 fTDCerrorFlag(-1),
172 fInsideDRM(kFALSE),
173 fInsideTRM(kFALSE),
174 fInsideLTM(kFALSE),
175 fInsideTRMchain0(kFALSE),
38f24f3f 176 fInsideTRMchain1(kFALSE),
177 fLocalEventCounterDRM(-1),
178 fLocalEventCounterLTM(-1),
179 fLocalEventCounterTRM(0x0),
32ead898 180 fLocalEventCounterChain(0x0),
ca6d7f17 181 fChainBunchID(0x0),
32ead898 182 fCableLengthMap(0x0),
183 fEventID(0)
571dda3d 184{
185 //
186 // create an object to read TOF raw digits
187 //
188
7813bb1a 189 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
2fd622fa 190 fDataBuffer[i]=new AliTOFHitDataBuffer();
191 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
7813bb1a 192 }
193
194 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
195 fTOFrawData->SetOwner();
196
15ec34b9 197 fRawReader->Reset();
362c9d61 198 fRawReader->Select("TOF");
38f24f3f 199
ca6d7f17 200 fLocalEventCounterTRM = new Int_t[13];
201 fLocalEventCounterChain = new Int_t*[13];
202 fChainBunchID = new Int_t*[13];
203 for (Int_t j=0;j<13;j++){
204 fLocalEventCounterTRM[j] = -1;
205 fLocalEventCounterChain[j] = new Int_t[2];
206 fChainBunchID[j] = new Int_t[2];
207 for (Int_t k=0;k<2;k++){
208 fLocalEventCounterChain[j][k] = -1;
209 fChainBunchID[j][k] = -1;
210 }
211 }
38f24f3f 212
32ead898 213 fCableLengthMap = new AliTOFCableLengthMap();
214
ca6d7f17 215 fEventID = (Int_t)fRawReader->GetBCID(); //bunch crossing
216
571dda3d 217}
218
219//_____________________________________________________________________________
655e379f 220AliTOFRawStream::AliTOFRawStream():
7813bb1a 221 fRawReader(0x0),
7813bb1a 222 fTOFrawData(0x0),
223 fDecoder(new AliTOFDecoder()),
655e379f 224 fDDL(-1),
225 fTRM(-1),
655e379f 226 fTRMchain(-1),
15ec34b9 227 fTDC(-1),
655e379f 228 fTDCchannel(-1),
15ec34b9 229 fTime(-1),
655e379f 230 fToT(-1),
15ec34b9 231 fLeadingEdge(-1),
232 fTrailingEdge(-1),
655e379f 233 fErrorFlag(-1),
655e379f 234 fSector(-1),
235 fPlate(-1),
236 fStrip(-1),
237 fPadX(-1),
238 fPadZ(-1),
15ec34b9 239 fPackedDigits(0),
655e379f 240 fWordType(-1),
241 fSlotID(-1),
242 fACQ(-1),
243 fPSbit(-1),
655e379f 244 fTDCerrorFlag(-1),
245 fInsideDRM(kFALSE),
246 fInsideTRM(kFALSE),
247 fInsideLTM(kFALSE),
248 fInsideTRMchain0(kFALSE),
38f24f3f 249 fInsideTRMchain1(kFALSE),
250 fLocalEventCounterDRM(-1),
251 fLocalEventCounterLTM(-1),
252 fLocalEventCounterTRM(0x0),
32ead898 253 fLocalEventCounterChain(0x0),
ca6d7f17 254 fChainBunchID(0x0),
32ead898 255 fCableLengthMap(0x0),
256 fEventID(0)
571dda3d 257{
258 //
d0eb8f39 259 // default ctr
571dda3d 260 //
7813bb1a 261 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
2fd622fa 262 fDataBuffer[i]=new AliTOFHitDataBuffer();
263 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
7813bb1a 264 }
15ec34b9 265
7813bb1a 266 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
267 fTOFrawData->SetOwner();
38f24f3f 268
ca6d7f17 269 fLocalEventCounterTRM = new Int_t[13];
270 fLocalEventCounterChain = new Int_t*[13];
271 fChainBunchID = new Int_t*[13];
272 for (Int_t j=0;j<13;j++){
273 fLocalEventCounterTRM[j] = -1;
274 fLocalEventCounterChain[j] = new Int_t[2];
275 fChainBunchID[j] = new Int_t[2];
276 for (Int_t k=0;k<2;k++){
277 fLocalEventCounterChain[j][k] = -1;
278 fChainBunchID[j][k] = -1;
279 }
280 }
38f24f3f 281
32ead898 282 fCableLengthMap = new AliTOFCableLengthMap();
283
d0eb8f39 284}
285
286//_____________________________________________________________________________
287AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
655e379f 288 TObject(stream),
289 fRawReader(0x0),
7813bb1a 290 fTOFrawData(0x0),
291 fDecoder(new AliTOFDecoder()),
655e379f 292 fDDL(-1),
293 fTRM(-1),
655e379f 294 fTRMchain(-1),
15ec34b9 295 fTDC(-1),
655e379f 296 fTDCchannel(-1),
15ec34b9 297 fTime(-1),
655e379f 298 fToT(-1),
15ec34b9 299 fLeadingEdge(-1),
300 fTrailingEdge(-1),
655e379f 301 fErrorFlag(-1),
655e379f 302 fSector(-1),
303 fPlate(-1),
304 fStrip(-1),
305 fPadX(-1),
306 fPadZ(-1),
15ec34b9 307 fPackedDigits(0),
655e379f 308 fWordType(-1),
309 fSlotID(-1),
310 fACQ(-1),
311 fPSbit(-1),
655e379f 312 fTDCerrorFlag(-1),
313 fInsideDRM(kFALSE),
314 fInsideTRM(kFALSE),
315 fInsideLTM(kFALSE),
316 fInsideTRMchain0(kFALSE),
38f24f3f 317 fInsideTRMchain1(kFALSE),
318 fLocalEventCounterDRM(-1),
319 fLocalEventCounterLTM(-1),
320 fLocalEventCounterTRM(0x0),
32ead898 321 fLocalEventCounterChain(0x0),
ca6d7f17 322 fChainBunchID(0x0),
32ead898 323 fCableLengthMap(0x0),
324 fEventID(0)
d0eb8f39 325{
326 //
327 // copy constructor
328 //
329
330 fRawReader = stream.fRawReader;
15ec34b9 331
332 fTOFrawData = stream.fTOFrawData;
333
d0eb8f39 334 fDDL = stream.fDDL;
335 fTRM = stream.fTRM;
d0eb8f39 336 fTRMchain = stream.fTRMchain;
15ec34b9 337 fTDC = stream.fTDC;
d0eb8f39 338 fTDCchannel = stream.fTDCchannel;
15ec34b9 339 fTime = stream.fTime;
d0eb8f39 340 fToT = stream.fToT;
15ec34b9 341 fLeadingEdge = stream.fLeadingEdge;
342 fTrailingEdge = stream.fTrailingEdge;
343
d0eb8f39 344 fErrorFlag = stream.fErrorFlag;
345
346 fSector = stream.fSector;
347 fPlate = stream.fPlate;
348 fStrip = stream.fStrip;
349 fPadX = stream.fPadX;
350 fPadZ = stream.fPadZ;
351
15ec34b9 352 fPackedDigits = stream.fPackedDigits;
353
d0eb8f39 354 fWordType = stream.fWordType;
355 fSlotID = stream.fSlotID;
356 fACQ = stream.fACQ;
357 fPSbit = stream.fPSbit;
d0eb8f39 358 fTDCerrorFlag = stream.fTDCerrorFlag;
359 fInsideDRM = stream.fInsideDRM;
360 fInsideTRM = stream.fInsideTRM;
361 fInsideLTM = stream.fInsideLTM;
362 fInsideTRMchain0 = stream.fInsideTRMchain0;
363 fInsideTRMchain1 = stream.fInsideTRMchain1;
d0eb8f39 364
7813bb1a 365 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
366 fDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fDataBuffer[i]);
367 fPackedDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fPackedDataBuffer[i]);
368 }
369
370 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
38f24f3f 371
ca6d7f17 372 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;
373 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;
374 for (Int_t j=0;j<13;j++){
375 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];
376 for (Int_t k=0;k<2;k++){
377 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];
378 fChainBunchID[j][k] = stream.fChainBunchID[j][k];
379 }
380 }
38f24f3f 381
32ead898 382 fCableLengthMap = stream.fCableLengthMap;
383
384 fEventID = stream.fEventID;
385
571dda3d 386}
387
388//_____________________________________________________________________________
389AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
390{
391 //
392 // assignment operator
393 //
394
395 fRawReader = stream.fRawReader;
15ec34b9 396
397 fTOFrawData = stream.fTOFrawData;
398
571dda3d 399 fDDL = stream.fDDL;
400 fTRM = stream.fTRM;
d0eb8f39 401 fTRMchain = stream.fTRMchain;
15ec34b9 402 fTDC = stream.fTDC;
d0eb8f39 403 fTDCchannel = stream.fTDCchannel;
15ec34b9 404 fTime = stream.fTime;
d0eb8f39 405 fToT = stream.fToT;
15ec34b9 406 fLeadingEdge = stream.fLeadingEdge;
407 fTrailingEdge = stream.fTrailingEdge;
571dda3d 408 fErrorFlag = stream.fErrorFlag;
d0eb8f39 409
410 fSector = stream.fSector;
411 fPlate = stream.fPlate;
412 fStrip = stream.fStrip;
413 fPadX = stream.fPadX;
414 fPadZ = stream.fPadZ;
571dda3d 415
15ec34b9 416 fPackedDigits = stream.fPackedDigits;
417
d0eb8f39 418 fWordType = stream.fWordType;
419 fSlotID = stream.fSlotID;
420 fACQ = stream.fACQ;
421 fPSbit = stream.fPSbit;
d0eb8f39 422 fTDCerrorFlag = stream.fTDCerrorFlag;
423 fInsideDRM = stream.fInsideDRM;
424 fInsideTRM = stream.fInsideTRM;
425 fInsideLTM = stream.fInsideLTM;
426 fInsideTRMchain0 = stream.fInsideTRMchain0;
427 fInsideTRMchain1 = stream.fInsideTRMchain1;
7813bb1a 428
429 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
430 fDataBuffer[i] = stream.fDataBuffer[i];
431 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
432 }
433
434 fTOFrawData = stream.fTOFrawData;
38f24f3f 435
ca6d7f17 436 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;
437 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;
438 for (Int_t j=0;j<13;j++){
439 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];
440 for (Int_t k=0;k<2;k++){
441 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];
442 fChainBunchID[j][k] = stream.fChainBunchID[j][k];
443 }
444 }
38f24f3f 445
32ead898 446 fCableLengthMap = stream.fCableLengthMap;
447
448 fEventID = stream.fEventID;
449
571dda3d 450 return *this;
451
452}
453
454//_____________________________________________________________________________
455AliTOFRawStream::~AliTOFRawStream()
456{
457// destructor
458
15ec34b9 459 fPackedDigits = 0;
460
7813bb1a 461 for (Int_t i=0;i<72;i++){
462 delete fDataBuffer[i];
463 delete fPackedDataBuffer[i];
464 }
d3c7bfac 465
7813bb1a 466 delete fDecoder;
15ec34b9 467
7813bb1a 468 fTOFrawData->Clear();
469 delete fTOFrawData;
38f24f3f 470
415c84fa 471 delete [] fLocalEventCounterTRM;
ca6d7f17 472 for (Int_t ii=0; ii<2; ii++) {
32ead898 473 delete [] fLocalEventCounterChain[ii];
ca6d7f17 474 delete [] fChainBunchID[ii];
475 }
32ead898 476 delete fCableLengthMap;
38f24f3f 477
571dda3d 478}
479
480
15ec34b9 481//_____________________________________________________________________________
482
483void AliTOFRawStream::LoadRawData(Int_t indexDDL)
484{
0192b95f 485 //
486 // To load raw data
487 //
15ec34b9 488
74cd22f8 489 fTOFrawData->Clear();
0192b95f 490
74cd22f8 491 TClonesArray &arrayTofRawData = *fTOFrawData;
492
15ec34b9 493 fPackedDigits = 0;
494
495 // create raw data map
496 AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
497 rawMap->Clear();
498
499 Int_t slot[4] = {-1, -1, -1, -1};
500
415c84fa 501 fLocalEventCounterDRM = -1;
502 fLocalEventCounterLTM = -1;
503 for (Int_t ii=0; ii<13; ii++)
504 fLocalEventCounterTRM[ii] = -1;
505 for (Int_t ii=0; ii<13; ii++)
506 for (Int_t jj=0; jj<2; jj++)
507 fLocalEventCounterChain[ii][jj] = -1;
508
15ec34b9 509 fRawReader->Reset();
510 fRawReader->Select("TOF", indexDDL, indexDDL);
511
512 Bool_t signal = kFALSE;
513
74cd22f8 514 AliTOFrawData *rawDigit = NULL;
7813bb1a 515
15ec34b9 516 while(Next()) {
517
518 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
519 if (signal) {
38f24f3f 520 AliDebug(2,Form(" %2i %1i %2i %1i %2i", fSector, fPlate, fStrip, fPadZ, fPadX));
15ec34b9 521
522 slot[0] = fTRM;
523 slot[1] = fTRMchain;
524 slot[2] = fTDC;
525 slot[3] = fTDCchannel;
526
527 if (rawMap->TestHit(slot) != kEmpty) {
528
74cd22f8 529 rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
15ec34b9 530
531 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
532 fLeadingEdge==-1 && fTrailingEdge!=-1) {
533
534 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
535 }
536 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
537 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
538
0192b95f 539 )
15ec34b9 540 {
541
74cd22f8 542 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
15ec34b9 543
74cd22f8 544 rawMap->SetHit(slot);
15ec34b9 545
74cd22f8 546 }
15ec34b9 547
548
549 }
550 else {
551
15ec34b9 552 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
553
554 rawMap->SetHit(slot);
555
556 } // else if (rawMap->TestHit(slot) == kEmpty)
557
558 } // if (signal)
559
560 } // closed -> while (Next())
561
74cd22f8 562 rawMap->Delete();
7813bb1a 563
15ec34b9 564}
565
571dda3d 566//_____________________________________________________________________________
567Bool_t AliTOFRawStream::Next()
568{
d0eb8f39 569 //
570 // Read next 32-bit word in TOF raw data files
571 // returns kFALSE if there is no word left
572 //
571dda3d 573
574 UInt_t data;
575
38f24f3f 576 Int_t dummy = 0;
577
571dda3d 578 if (!fRawReader->ReadNextInt(data)) return kFALSE;
579
d0eb8f39 580 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
581 fSector = -1;
15ec34b9 582 fPlate = -1;
583 fStrip = -1;
584 fPadZ = -1;
585 fPadX = -1;
586 fTime = -1;
587 fToT = -1;
588 fLeadingEdge = -1;
589 fTrailingEdge = -1;
d0eb8f39 590 }
571dda3d 591
571dda3d 592 fDDL = fRawReader->GetDDLID();
593
d0eb8f39 594 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
595
596 switch (fWordType) { // switch word type
597
598 case GLOBAL_HEADER_TYPE: // global header
599 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
600 fTRM = fSlotID;
601
602
603 switch (fSlotID) { // switch global header slot ID
604
605 case DRM_ID_NUMBER: //DRM global header
606 if (fInsideDRM) { // unexpected DRM global headers -> exit
607 break;
608 }
609 fInsideDRM = kTRUE; // DRM global header accepted
610 break;
611
612 case LTM_ID_NUMBER: // LTM global header
613 if (fInsideLTM) { // unexpected LTM global headers -> exit
614 break;
615 }
616 fInsideLTM = kTRUE; // LTM global header accepted
617 break;
618
619 case 3: //TRM header
620 case 4: //TRM header
621 case 5: //TRM header
622 case 6: //TRM header
623 case 7: //TRM header
624 case 8: //TRM header
625 case 9: //TRM header
626 case 10: //TRM header
627 case 11: //TRM header
628 case 12: //TRM header
629 if (fInsideTRM) { // unexpected TRM global headers -> exit
630 break;
631 }
632 fInsideTRM = kTRUE; // TRM global header accepted
633 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
634 break;
635
636 default: // unexpected global header slot ID
637 break;
638
639 } //end switch global header slot id
640
641 break;
642
643
644 case GLOBAL_TRAILER_TYPE: // global trailer
645 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
d0eb8f39 646
647 switch (fSlotID) { // switch global trailer slot ID
648
649 case DRM_ID_NUMBER: // DRM global trailer
650 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
651 break;
652 }
38f24f3f 653 dummy = 0x0000fff0;
654 //AliInfo(Form(" DRM local event counter = %i", GetField(data,dummy,4)));
ca6d7f17 655 fLocalEventCounterDRM = GetField(data,dummy,4);
d0eb8f39 656 fInsideDRM = kFALSE; // DRM global trailer accepted
657 fInsideTRM = kFALSE;
658 fInsideLTM = kFALSE;
659 fInsideTRMchain0 = kFALSE;
660 fInsideTRMchain1 = kFALSE;
d0eb8f39 661 fSector = -1;
15ec34b9 662 fPlate = -1;
663 fStrip = -1;
664 fPadZ = -1;
665 fPadX = -1;
666 fDDL = -1;
667 fTRM = -1;
668 fTDC = -1;
669 fTRMchain = -1;
d0eb8f39 670 fTDCchannel = -1;
15ec34b9 671 fTime = -1;
672 fToT = -1;
673 fLeadingEdge = -1;
674 fTrailingEdge = -1;
d0eb8f39 675 fErrorFlag = -1;
15ec34b9 676 fACQ = -1;
d0eb8f39 677 fPSbit = -1;
d0eb8f39 678 fTDCerrorFlag = -1;
679 break;
680 case LTM_ID_NUMBER: // LTM global trailer
681 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
682 break;
683 }
38f24f3f 684 dummy = 0x0fff0000;
685 //AliInfo(Form(" LTM local event counter = %i", GetField(data,dummy,16)));
ca6d7f17 686 fLocalEventCounterLTM = GetField(data,dummy,16);
d0eb8f39 687 fInsideLTM = kFALSE; // LTM global trailer accepted
688 break;
689 case 15: //TRM global trailer
690 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
691 break;
692 }
38f24f3f 693 dummy = 0x0fff0000;
694 //AliInfo(Form(" TRM local event counter = %i", GetField(data,dummy,16)));
ca6d7f17 695 fLocalEventCounterTRM[fTRM] = GetField(data,dummy,16);
d0eb8f39 696 fInsideTRM = kFALSE; // TRM global trailer accepted
697 break;
698 default: // unexpected global trailer slot ID
699 break;
700 } //end switch global trailer slot id
701
702
703 break;
704
705
706 case ERROR_TYPE: // TDC error
15ec34b9 707 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
d0eb8f39 708 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
709 break;
710
711
712 case FILLER_TYPE: // filler
713 break;
714
715
716 default: // other word types
717
718 if (fInsideTRM) { // inside TRM
719
720 switch (fWordType) { // switch word type inside TRM
721 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
722 if (fInsideTRMchain0) { // unexpected TRM chain0 header
723 break;
724 }
725 fInsideTRMchain0 = kTRUE;
726 fTRMchain = 0;
ca6d7f17 727 dummy = 0x0000fff0;
728 //AliInfo(Form(" chain bunch ID = %i", GetField(data,dummy,4)));
729 fChainBunchID[fTRM][fTRMchain] = GetField(data,dummy,4);
d0eb8f39 730 break;
731 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
732 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
733 break;
734 }
38f24f3f 735 dummy = 0x0fff0000;
736 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
ca6d7f17 737 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);
d0eb8f39 738 fInsideTRMchain0 = kFALSE;
739 fTRMchain = -1;
740 break;
741 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
742 if (fInsideTRMchain1) { // unexpected TRM chain1 header
743 break;
744 }
745 fInsideTRMchain1 = kTRUE;
746 fTRMchain = 1;
ca6d7f17 747 dummy = 0x0000fff0;
748 //AliInfo(Form(" chain bunch ID = %i", GetField(data,dummy,4)));
749 fChainBunchID[fTRM][fTRMchain] = GetField(data,dummy,4);
d0eb8f39 750 break;
751 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
752 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
753 break;
754 }
38f24f3f 755 dummy = 0x0fff0000;
756 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
ca6d7f17 757 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);
d0eb8f39 758 fInsideTRMchain1 = kFALSE;
759 fTRMchain = -1;
760 break;
761 } // end switch word type inside TRM
762
763 } // end if (fInsideTRM)
764
765
766 if (
767 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
768 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
769 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
770 ){ // inside TRM chains
15ec34b9 771
772 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
773 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
d0eb8f39 774 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
15ec34b9 775 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
776
777 SetSector();
778 SetPlate();
779 SetStrip();
780 SetPadZ();
781 SetPadX();
782
d0eb8f39 783
784 switch (fPSbit) { // switch fPSbit bits inside TRM chains
15ec34b9 785
786 case 0: // packing ok, digit time and TOT
787 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
32ead898 788 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
cfceaf15 789 /*-
790 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
32ead898 791 ;
143cfc81 792 if (fgApplyBCCorrections) {
ca6d7f17 793 AliDebug(2,"Apply nominal DDL BC time-shift correction");
794 AliDebug(2,"Apply deltaBC time-shift correction");
795 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
143cfc81 796 fTime +=
ca6d7f17 797 (Int_t)(fgkddlBCshift[fDDL]*25./AliTOFGeometry::TdcBinWidth()*1.E+03)
143cfc81 798 +
ca6d7f17 799 (Int_t)((fChainBunchID[fTRM][fTRMchain]-fEventID)*25./AliTOFGeometry::TdcBinWidth()*1.E+03);
143cfc81 800 }
d0eb8f39 801 break;
802
803 case 1: // leading edge digit, long digit time, no TOT
15ec34b9 804 //fToT = -1;
805 //fTime = -1;
32ead898 806 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
cfceaf15 807 /*-
808 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
32ead898 809 ;
143cfc81 810 if (fgApplyBCCorrections) {
ca6d7f17 811 AliDebug(2,"Apply nominal DDL BC time-shift correction");
812 AliDebug(2,"Apply deltaBC time-shift correction");
813 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
143cfc81 814 fLeadingEdge +=
ca6d7f17 815 (Int_t)(fgkddlBCshift[fDDL]*25./AliTOFGeometry::TdcBinWidth()*1.E+03)
143cfc81 816 +
ca6d7f17 817 (Int_t)((fChainBunchID[fTRM][fTRMchain]-fEventID)*25./AliTOFGeometry::TdcBinWidth()*1.E+03);
143cfc81 818 }
d0eb8f39 819 break;
820
821 case 2: // trailing edge digit, long digit time, no TOT
15ec34b9 822 //fToT = -1;
823 //fTime = -1;
32ead898 824 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
cfceaf15 825 /*-
826 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
32ead898 827 ;
143cfc81 828 if (fgApplyBCCorrections) {
ca6d7f17 829 AliDebug(2,"Apply nominal DDL BC time-shift correction");
830 AliDebug(2,"Apply deltaBC time-shift correction");
831 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
143cfc81 832 fTrailingEdge +=
ca6d7f17 833 (Int_t)(fgkddlBCshift[fDDL]*25./AliTOFGeometry::TdcBinWidth()*1.E+03)
143cfc81 834 +
ca6d7f17 835 (Int_t)((fChainBunchID[fTRM][fTRMchain]-fEventID)*25./AliTOFGeometry::TdcBinWidth()*1.E+03);
143cfc81 836 }
d0eb8f39 837 break;
15ec34b9 838
d0eb8f39 839 case 3: // TOT overflow
15ec34b9 840 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
32ead898 841 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
cfceaf15 842 /*-
843 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
32ead898 844 ;
143cfc81 845 if (fgApplyBCCorrections) {
ca6d7f17 846 AliDebug(2,"Apply nominal DDL BC time-shift correction");
847 AliDebug(2,"Apply deltaBC time-shift correction");
848 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
143cfc81 849 fTime +=
ca6d7f17 850 (Int_t)(fgkddlBCshift[fDDL]*25./AliTOFGeometry::TdcBinWidth()*1.E+03)
143cfc81 851 +
ca6d7f17 852 (Int_t)((fChainBunchID[fTRM][fTRMchain]-fEventID)*25./AliTOFGeometry::TdcBinWidth()*1.E+03);
143cfc81 853 }
d0eb8f39 854 break;
d0eb8f39 855
15ec34b9 856 } // end switch PS bits inside TRM chains
d0eb8f39 857
858 } // end if is inside TRM chains
859
860 } // end switch on fWordType
571dda3d 861
15ec34b9 862
571dda3d 863 return kTRUE;
7813bb1a 864
571dda3d 865}
866//_____________________________________________________________________________
867
d0eb8f39 868void AliTOFRawStream::SetSector()
571dda3d 869{
870 //
d0eb8f39 871 // Evaluate the TOF sector number -> [ 0;17]
872 // corresponding to the TOF equipment IDs:
873 // fDDL -> [ 0;71]
874 // fTRM -> [ 3;12]
15ec34b9 875 // fTRMchain -> [ 0; 1]
d0eb8f39 876 // fTDC -> [ 0;14]
877 // fTDCchannel -> [ 0; 7]
571dda3d 878 //
879
880 Int_t iSector = -1;
571dda3d 881
d0eb8f39 882 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
883
884 fSector = iSector;
571dda3d 885
886}
887//_____________________________________________________________________________
888
d0eb8f39 889
890void AliTOFRawStream::SetPlate()
571dda3d 891{
892 //
d0eb8f39 893 // Evaluate the TOF plate number ->[ 0; 4]
894 // corresponding to the TOF equipment IDs:
895 // fDDL -> [ 0;71]
896 // fTRM -> [ 3;12]
15ec34b9 897 // fTRMchain -> [ 0; 1]
d0eb8f39 898 // fTDC -> [ 0;14]
899 // fTDCchannel -> [ 0; 7]
571dda3d 900 //
901
902 Int_t iPlate = -1;
d0eb8f39 903 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
904 || fSector==-1))
905 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
571dda3d 906
d0eb8f39 907 fPlate = iPlate;
571dda3d 908
909}
910//_____________________________________________________________________________
911
d0eb8f39 912void AliTOFRawStream::SetStrip()
571dda3d 913{
914 //
d0eb8f39 915 // Evaluate the TOF strip number per module -> [ 0; 14/18]
916 // corresponding to the TOF equipment IDs:
917 // fDDL -> [ 0;71]
918 // fTRM -> [ 3;12]
15ec34b9 919 // fTRMchain -> [ 0; 1]
d0eb8f39 920 // fTDC -> [ 0;14]
921 // fTDCchannel -> [ 0; 7]
571dda3d 922 //
923
924 Int_t iStrip = -1;
925
d0eb8f39 926 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
927 || fSector==-1 || fPlate==-1))
928 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
571dda3d 929
d0eb8f39 930 fStrip = iStrip;
571dda3d 931
932}
933//_____________________________________________________________________________
934
d0eb8f39 935void AliTOFRawStream::SetPadZ()
571dda3d 936{
937 //
d0eb8f39 938 // Evaluate the TOF padRow number per strip -> [ 0; 1]
939 // corresponding to the TOF equipment IDs:
940 // fDDL -> [ 0;71]
941 // fTRM -> [ 3;12]
15ec34b9 942 // fTRMchain -> [ 0; 1]
d0eb8f39 943 // fTDC -> [ 0;14]
944 // fTDCchannel -> [ 0; 7]
571dda3d 945 //
946
947 Int_t iPadZ = -1;
948
d0eb8f39 949 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
950 || fSector==-1 || fPlate==-1 || fStrip==-1))
951 {
952 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
953 if (iPadAlongTheStrip!=-1)
954 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
955 }
571dda3d 956
38f24f3f 957 //iPadZ = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)%AliTOFGeometry::NpadZ();
958 //iPadZ = Equip2VolNpadZ(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
959
d0eb8f39 960 fPadZ = iPadZ;
571dda3d 961
d0eb8f39 962}
963//_____________________________________________________________________________
964
965void AliTOFRawStream::SetPadX()
966{
967 //
968 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
969 // corresponding to the TOF equipment IDs:
970 // fDDL -> [ 0;71]
971 // fTRM -> [ 3;12]
15ec34b9 972 // fTRMchain -> [ 0; 1]
d0eb8f39 973 // fTDC -> [ 0;14]
974 // fTDCchannel -> [ 0; 7]
975 //
571dda3d 976
d0eb8f39 977 Int_t iPadX = -1;
571dda3d 978
d0eb8f39 979 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
980 || fSector==-1 || fPlate==-1 || fStrip==-1))
981 {
982 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
983 if (iPadAlongTheStrip!=-1)
984 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
985 }
986
38f24f3f 987 //iPadX = (Int_t)(Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)/(Float_t(AliTOFGeometry::NpadZ())));
988 //iPadX = Equip2VolNpadX(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
989
d0eb8f39 990 fPadX = iPadX;
571dda3d 991
992}
571dda3d 993
d0eb8f39 994//----------------------------------------------------------------------------
995Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
996{
997 //
998 //
999 //
1000
1001 return ((word & fieldMask) >> fieldPosition);
1002}
1003
1004//----------------------------------------------------------------------------
13d6bff9 1005Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC)
571dda3d 1006{
1007 //
d0eb8f39 1008 // Returns the TOF plate number [0;4]
1009 // corresponding to the TOF equipment ID numbers:
1010 // iDDL -> DDL number per sector [0;3]
1011 // nTRM -> TRM number [3;12]
1012 // nTDC -> TDC number [0;14]
571dda3d 1013 //
1014
d0eb8f39 1015 Int_t iPlate = -1;
5f72a2bf 1016
d0eb8f39 1017 if (iDDL==0) {
1018
1019 if (nTRM>=4 && nTRM<7) {
1020 iPlate = 0;
1021 } else if (nTRM==7) {
1022 if (nTDC<12) iPlate = 0;
1023 else iPlate = 1;
1024 } else if (nTRM>=8 && nTRM<11) {
1025 iPlate = 1;
1026 } else if (nTRM==11) {
1027 if (nTDC<9) iPlate = 1;
1028 else iPlate = 2;
1029 }else if (nTRM==12) {
1030 iPlate = 2;
1031 }
1032
1033 } else if (iDDL==1) {
1034
1035 if (nTRM==3) {
1036 if (nTDC<3) iPlate = 0;
1037 } else if (nTRM>=4 && nTRM<7) {
1038 iPlate = 0;
1039 } else if (nTRM==7) {
1040 if (nTDC<6) iPlate = 1;
1041 else iPlate = 0;
1042 } else if (nTRM>=8 && nTRM<11) {
1043 iPlate = 1;
1044 } else if (nTRM==11) {
1045 if (nTDC<9) iPlate = 2;
1046 else iPlate = 1;
1047 } else if (nTRM==12) {
1048 iPlate = 2;
1049 }
1050
1051 } else if (iDDL==2) {
1052
1053 if (nTRM>=4 && nTRM<7) {
1054 iPlate = 4;
1055 } else if (nTRM==7) {
1056 if (nTDC<12) iPlate = 4;
1057 else iPlate = 3;
1058 } else if (nTRM>=8 && nTRM<11) {
1059 iPlate = 3;
1060 } else if (nTRM==11) {
1061 if (nTDC<9) iPlate = 3;
1062 else iPlate = 2;
1063 }else if (nTRM==12) {
1064 iPlate = 2;
1065 }
1066
1067 } else if (iDDL==3) {
1068
1069 if (nTRM==3) {
1070 if (nTDC<3) iPlate = 4;
1071 } else if (nTRM>=4 && nTRM<7) {
1072 iPlate = 4;
1073 } else if (nTRM==7) {
1074 if (nTDC<6) iPlate = 3;
1075 else iPlate = 4;
1076 } else if (nTRM>=8 && nTRM<11) {
1077 iPlate = 3;
1078 } else if (nTRM==11) {
1079 if (nTDC<9) iPlate = 2;
1080 else iPlate = 3;
1081 } else if (nTRM==12) {
1082 iPlate = 2;
1083 }
571dda3d 1084
d0eb8f39 1085 }
571dda3d 1086
d0eb8f39 1087 return iPlate;
571dda3d 1088
d0eb8f39 1089}
571dda3d 1090
d0eb8f39 1091//----------------------------------------------------------------------------
13d6bff9 1092Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC)
d0eb8f39 1093{
1094 //
1095 // Returns the TOF strip number per module:
1096 // [0;14], in the central plates,
1097 // [0;18], in the intermediate and external plates
1098 // corresponding to the TOF equipment ID numbers:
1099 // iDDL -> DDL number per sector [0;3]
1100 // nTRM -> TRM number [3;12]
1101 // nTDC -> TDC number [0;14]
1102 //
571dda3d 1103
d0eb8f39 1104 Int_t iStrip = -1;
571dda3d 1105
d0eb8f39 1106 if (iDDL==0) {
1107
1108 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
1109 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
1110 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
1111 else if (nTRM== 7) {
1112 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
1113 else iStrip = (Int_t)(nTDC/3.) - 4;
1114 }
1115 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
1116 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
1117 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
1118 else if (nTRM==11) {
1119 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
1120 else iStrip = (Int_t)(nTDC/3.) - 3;
1121 }
1122 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
1123
1124 } else if (iDDL==1) {
1125
1126 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
1127 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
1128 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
1129 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
1130 else if (nTRM== 7) {
1131 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
1132 else iStrip = 20 - (Int_t)(nTDC/3.);
1133 }
1134 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
1135 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
1136 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
1137 else if (nTRM==11) {
1138 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
1139 else iStrip = 21 - (Int_t)(nTDC/3.);
1140 }
1141 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
1142
1143 } else if (iDDL==2) {
1144
1145 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
1146 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
1147 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
1148 else if (nTRM== 7) {
1149 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
1150 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
1151 }
1152 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
1153 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
1154 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
1155 else if (nTRM==11) {
1156 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
1157 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
1158 }
1159 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
1160
1161 } else if (iDDL==3) {
1162
1163 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
1164 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
1165 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
1166 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
1167 else if (nTRM== 7) {
1168 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
1169 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
1170 }
1171 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
1172 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
1173 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
1174 else if (nTRM==11) {
1175 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1176 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1177 }
1178 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1179
1180 }
1181
1182 return iStrip;
1183
1184}
1185
1186//----------------------------------------------------------------------------
1187Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
13d6bff9 1188 Int_t iCH)
d0eb8f39 1189{
1190 //
1191 // Returns the TOF pad number per strip [0;95]
1192 // corresponding to the TOF equipment ID numbers:
1193 // iDDL -> DDL number per sector [0;3]
1194 // iChain -> TRM chain number [0;1]
1195 // nTDC -> TDC number [0;14]
1196 // iCH -> TDC channel number [0;7]
1197 //
1198
1199 Int_t iPadAlongTheStrip = -1;
1200
38f24f3f 1201 // wrong
1202 //Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1203 //if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1204 //else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
d0eb8f39 1205
38f24f3f 1206 // right
1207 Int_t iTDClocal = -1;
1208 Int_t iTDClocal03 = nTDC%3 + (1-iChain)*3;
1209 Int_t iTDClocal12 = 2-nTDC%3 + iChain*3;
1210 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal03;
1211 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal12);
d0eb8f39 1212
1213 Int_t iCHlocal = iCH;
1214 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1215
1216 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1217
1218 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
019f6101 1219 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
13d6bff9 1220 std::cerr << "Problems with the padX number!" << endl;
1221 //AliWarning("Problems with the padX number!");
019f6101 1222 }
d0eb8f39 1223 return iPadAlongTheStrip;
1224
1225}
1226
38f24f3f 1227//----------------------------------------------------------------------------
1228Int_t AliTOFRawStream::Equip2VolNpadX(Int_t iDDL, Int_t iChain, Int_t nTDC,
1229 Int_t iCH)
1230{
1231 //
1232 // Returns the TOF padX number [0;47]
1233 // corresponding to the TOF equipment ID numbers:
1234 // iDDL -> DDL number per sector [0;3]
1235 // iChain -> TRM chain number [0;1]
1236 // nTDC -> TDC number [0;14]
1237 // iCH -> TDC channel number [0;7]
1238 //
1239
1240 Int_t iPadX = (Int_t)(AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)/
1241 (Float_t(AliTOFGeometry::NpadZ())));
1242
1243 return iPadX;
1244
1245}
1246
1247//----------------------------------------------------------------------------
1248Int_t AliTOFRawStream::Equip2VolNpadZ(Int_t iDDL, Int_t iChain, Int_t nTDC,
1249 Int_t iCH)
1250{
1251 //
1252 // Returns the TOF padZ number [0;1]
1253 // corresponding to the TOF equipment ID numbers:
1254 // iDDL -> DDL number per sector [0;3]
1255 // iChain -> TRM chain number [0;1]
1256 // nTDC -> TDC number [0;14]
1257 // iCH -> TDC channel number [0;7]
1258 //
1259
1260 Int_t iPadZ = AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1261
1262 return iPadZ;
1263
1264}
1265
d0eb8f39 1266//----------------------------------------------------------------------------
5f72a2bf 1267Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL)
d0eb8f39 1268{
1269 //
1270 // Returns the sector number [0;17]
1271 // corresponing to the assigned DRM/DDL number [0;71]
1272 //
1273
1274 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1275
1276 return iSector;
1277
1278}
1279//----------------------------------------------------------------------------
5f72a2bf 1280Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL)
d0eb8f39 1281{
1282 //
1283 // Return the DRM/DDL number per sector [0;3]
1284 // corresponing to the assigned DRM/DDL number [0;71]
1285 //
1286
1287 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1288
1289 return iDDL;
1290
1291}
1292
7813bb1a 1293//----------------------------------------------------------------------------
1294void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1295{
1296 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1297}
d0eb8f39 1298//----------------------------------------------------------------------------
1299void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1300 Int_t nTDC, Int_t iCH,
1301 Int_t *volume) const
1302{
1303 //
1304 // To convert:
1305 // nDDL (variable in [0;71]) -> number of the DDL file
1306 // nTRM (variable in [3;12]) -> number of the TRM slot
1307 // iChain (variable in [0; 1]) -> number of the TRM chain
1308 // nTDC (variable in [0;14]) -> number of the TDC
1309 // iCH (variable in [0; 7]) -> number of the TDC channel
1310 //
1311 // in:
1312 // sector number, i.e. volume[0] (variable in [0,17])
1313 // plate number, i.e. volume[1] (variable in [0, 5])
1314 // strip number, i.e. volume[2] (variable in [0,14/18])
1315 // padX number, i.e. volume[3] (variable in [0,47])
1316 // padZ number, i.e. volume[4] (variable in [0, 1])
1317 //
1318
1319 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1320
1321 Int_t iSector = GetSectorNumber(nDDL);
1322
1323 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
019f6101 1324 if (iPlate==-1) {
13d6bff9 1325 if (fRawReader)
1326 fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");
019f6101 1327 AliWarning("Problems with the plate number!");
1328 }
d0eb8f39 1329
1330 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
019f6101 1331 if (iStrip==-1) {
13d6bff9 1332 if (fRawReader)
1333 fRawReader->AddMajorErrorLog(kStripError,"strip = -1");
019f6101 1334 AliWarning("Problems with the strip number!");
1335 }
d0eb8f39 1336
1337 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
019f6101 1338 if (iPadAlongTheStrip==-1){
13d6bff9 1339 if (fRawReader)
1340 fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");
019f6101 1341 AliWarning("Problems with the pad number along the strip!");
1342 }
13d6bff9 1343
d0eb8f39 1344 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1345 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
38f24f3f 1346
1347 //Int_t iPadX = (Int_t)(Equip2VolNpad(iDDL, iChain, nTDC, iCH)/(Float_t(AliTOFGeometry::NpadZ())));
1348 //Int_t iPadZ = Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1349
1350 //Int_t iPadX = Equip2VolNpadX(iDDL, iChain, nTDC, iCH);
1351 //Int_t iPadZ = Equip2VolNpadZ(iDDL, iChain, nTDC, iCH);
1352
d0eb8f39 1353 volume[0] = iSector;
1354 volume[1] = iPlate;
1355 volume[2] = iStrip;
1356 volume[3] = iPadX;
1357 volume[4] = iPadZ;
571dda3d 1358
1359}
7813bb1a 1360//-----------------------------------------------------------------------------
019f6101 1361Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose = 0) {
1362 //
1363 // To decode raw data for DDL number in [nDDLmin; nDDLmax]
1364 //
1365
7813bb1a 1366 //check and fix valid DDL range
019f6101 1367 if (nDDLMin < 0){
1368 nDDLMin = 0;
1369 fRawReader->AddMinorErrorLog(kDDLMinError);
1370 AliWarning("Wrong DDL range: setting first DDL ID to 0");
7813bb1a 1371 }
019f6101 1372 if (nDDLMax > 71){
1373 nDDLMax = 71;
1374 fRawReader->AddMinorErrorLog(kDDLMaxError);
1375 AliWarning("Wrong DDL range: setting last DDL ID to 71");
7813bb1a 1376 }
1377
1378 //select required DDLs
019f6101 1379 fRawReader->Select("TOF", nDDLMin, nDDLMax);
7813bb1a 1380
1381 if (verbose)
019f6101 1382 AliInfo(Form("Selected TOF DDL range: %d-%d", nDDLMin, nDDLMax));
7813bb1a 1383
2fd622fa 1384 return(Decode(verbose));
1385}
1386//-----------------------------------------------------------------------------
019f6101 1387Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
1388 //
1389 // New decoder method
1390 //
1391
2fd622fa 1392 Int_t currentEquipment;
1393 Int_t currentDDL;
dd824655 1394 const AliRawDataHeader *currentCDH;
2fd622fa 1395
1396 //pointers
1397 UChar_t *data = 0x0;
1398
7813bb1a 1399 //loop and read DDL headers
1400 while(fRawReader->ReadHeader()){
1401
1402 //memory leak prevention (actually data should be always 0x0 here)
1403 if (data != 0x0)
1404 delete [] data;
1405
1406 //get equipment infos
1407 currentEquipment = fRawReader->GetEquipmentId();
1408 currentDDL = fRawReader->GetDDLID();
dd824655 1409 currentCDH = fRawReader->GetDataHeader();
7813bb1a 1410 const Int_t kDataSize = fRawReader->GetDataSize();
1411 const Int_t kDataWords = kDataSize / 4;
1412 data = new UChar_t[kDataSize];
1413
1414 if (verbose)
1415 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1416
1417 if (verbose)
1418 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1419
1420 //read equipment payload
1421 if (!fRawReader->ReadNext(data, kDataSize))
1422 {
019f6101 1423 fRawReader->AddMajorErrorLog(kDDLdataReading);
7813bb1a 1424 if (verbose)
019f6101 1425 AliWarning("Error while reading DDL data. Go to next equipment");
7813bb1a 1426 delete [] data;
1427 data = 0x0;
1428 continue;
1429 }
1430
1431 if (verbose)
1432 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1433
1434
1435 //set up the decoder
1436 fDecoder->SetVerbose(verbose);
1437 fDecoder->SetDataBuffer(fDataBuffer[currentDDL]);
1438 fDecoder->SetPackedDataBuffer(fPackedDataBuffer[currentDDL]);
1439
1440 //start decoding
dd824655 1441 if (fDecoder->Decode((UInt_t *)data, kDataWords, currentCDH) == kTRUE) {
019f6101 1442 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1443 AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1444 }
7813bb1a 1445
1446 delete [] data;
1447 data = 0x0;
1448 }
1449
1450 //reset reader
1451 fRawReader->Reset();
1452
1453 if (verbose)
1454 AliInfo("All done");
1455
1456 return kFALSE;
1457
1458}
1459//---------------------------------------------------------------------------
1460void
1461AliTOFRawStream::ResetBuffers()
1462{
19eefa2b 1463 //
1464 // To reset the buffers
1465 //
1466
7813bb1a 1467 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1468 ResetDataBuffer(iDDL);
1469 ResetPackedDataBuffer(iDDL);
1470 }
1471}
1472
1473//---------------------------------------------------------------------------
1474Bool_t
1475AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1476{
19eefa2b 1477 //
1478 // To load the buffers
1479 //
1480
7813bb1a 1481 fTOFrawData->Clear();
1482 fPackedDigits = 0;
1483
1484 if (verbose > 0)
1485 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1486
1487 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
019f6101 1488 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",indexDDL));
1489 AliWarning(Form("Error while decoding DDL # %d", indexDDL));
7813bb1a 1490 return kTRUE;
1491 }
1492
1493 if (verbose > 0)
1494 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL]->GetEntries(), fPackedDataBuffer[indexDDL]->GetEntries() > 1 ? "hits have" : "hit has"));
1495
1496 AliTOFHitData *hitData; //hit data pointer
1497
1498 if (verbose > 0)
1499 AliInfo("Filling TClonesArray ...");
1500
dd824655 1501 if (verbose > 0)
1502 if (fgApplyBCCorrections) {
1503 AliInfo("Apply nominal DDL BC time-shift correction");
1504 AliInfo("Apply deltaBC time-shift correction");
1505 }
1506
7813bb1a 1507 //loop over DDL packed hits
1508 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL]->GetEntries(); iHit++){
1509 hitData = fPackedDataBuffer[indexDDL]->GetHit(iHit); //get hit data
1510 Int_t hitACQ = hitData->GetACQ();
1511 Int_t hitPS = hitData->GetPS();
1512 Int_t hitSlotID = hitData->GetSlotID();
1513 Int_t hitChain = hitData->GetChain();
1514 Int_t hitTDC = hitData->GetTDC();
1515 Int_t hitChan = hitData->GetChan();
7813bb1a 1516 Int_t hitTimeBin = hitData->GetTimeBin();
7813bb1a 1517 Int_t hitTOTBin = hitData->GetTOTBin();
dd824655 1518
1519 if (fgApplyBCCorrections) {
1520 /* DDL BC shift time correction */
1521 hitTimeBin += fgkddlBCshift[indexDDL];
1522 /* deltaBC shift time correction */
1523 hitTimeBin += hitData->GetDeltaBunchID();
1524 }
1525
1526 Int_t hitLeading = hitData->GetTimeBin();
bf33f8f0 1527 Int_t hitTrailing = -1;
1528 Int_t hitError = -1;
7813bb1a 1529
1530 TClonesArray &arrayTofRawData = *fTOFrawData;
bf33f8f0 1531 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
7813bb1a 1532 }
1533
1534 if (verbose > 0)
1535 AliInfo("Done.");
1536
1537 if (verbose > 0)
1538 AliInfo("Resetting buffers ...");
1539
1540 fDataBuffer[indexDDL]->Reset();
1541 fPackedDataBuffer[indexDDL]->Reset();
1542
1543 if (verbose > 0)
1544 AliInfo("Done.");
1545
1546 return kFALSE;
1547}
1548
5f72a2bf 1549//---------------------------------------------------------------------------
1550void AliTOFRawStream::Geant2EquipmentId(Int_t vol[], Int_t eqId[])
1551{
1552 //
1553 // To convert:
1554 // nSector number -vol[0]- (variable in [0,17])
1555 // nPlate number -vol[1]- (variable in [0, 5])
1556 // nStrip number -vol[2]- (variable in [0,14/18])
1557 // nPadZ number -vol[3]- (variable in [0, 1])
1558 // nPadX number -vol[4]- (variable in [0,47])
1559 // in:
1560 // nDDL -eqId[0]- (variable in [0;71]) -> number of the DDL file
1561 // nTRM -eqId[1]- (variable in [3;12]) -> number of the TRM file
1562 // nTDC -eqId[2]- (variable in [0;14]) -> number of the TDC file
1563 // nChain -eqId[3]- (variable in [0; 1]) -> number of the chain file
1564 // nChannel -eqId[4]- (variable in [0; 8]) -> number of the channel file
1565 //
1566
1567 eqId[0] = Geant2DDL(vol);
1568 eqId[1] = Geant2TRM(vol);
1569 eqId[2] = Geant2TDC(vol);
1570 eqId[3] = Geant2Chain(vol);
1571 eqId[4] = Geant2Channel(vol);
1572
1573}
1574
1575//---------------------------------------------------------------------------
1576Int_t AliTOFRawStream::Geant2DDL(Int_t vol[])
1577{
1578 //
1579 // To convert:
1580 // nSector number -vol[0]- (variable in [0,17])
1581 // nPlate number -vol[1]- (variable in [0, 5])
1582 // nStrip number -vol[2]- (variable in [0,14/18])
1583 // nPadZ number -vol[3]- (variable in [0, 1])
1584 // nPadX number -vol[4]- (variable in [0,47])
1585 // in:
1586 // nDDL (variable in [0;71]) -> number of the DDL file
1587 //
1588
1589
1590 Int_t iDDL = -1;
1591
1592 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1593 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1594 return iDDL;
1595 }
1596 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1597 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1598 return iDDL;
1599 }
1600 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1601 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1602 return iDDL;
1603 }
1604 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
1605 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1606 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
1607 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1608 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
1609 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1610 return iDDL;
1611 }
1612
1613 Int_t nSector = vol[0];
1614 Int_t nPlate = vol[1];
1615 Int_t nStrip = vol[2];
1616 Int_t nPadX = vol[4];
1617
1618 if ( nPadX<24 && ( nPlate==0 || nPlate==1 || (nPlate==2 && nStrip<7) ) )
1619 iDDL = 0;
1620 else if ( nPadX>=24 && ( nPlate==0 || nPlate==1 || (nPlate==2 && nStrip<8) ) )
1621 iDDL = 1;
1622 else if ( nPadX>=24 && ( nPlate==3 || nPlate==4 || (nPlate==2 && nStrip>7) ) )
1623 iDDL = 2;
1624 else if ( nPadX<24 && ( nPlate==3 || nPlate==4 || (nPlate==2 && nStrip>6) ) )
1625 iDDL = 3;
1626
1627 return 4*nSector+iDDL;
1628
1629}
1630
1631//---------------------------------------------------------------------------
1632Int_t AliTOFRawStream::Geant2TRM(Int_t vol[])
1633{
1634 //
1635 // To convert:
1636 // nSector number -vol[0]- (variable in [0,17])
1637 // nPlate number -vol[1]- (variable in [0, 5])
1638 // nStrip number -vol[2]- (variable in [0,14/18])
1639 // nPadZ number -vol[3]- (variable in [0, 1])
1640 // nPadX number -vol[4]- (variable in [0,47])
1641 // in:
1642 // nTRM (variable in [3;12]) -> number of the TRM slot
1643 //
1644
1645 Int_t nTRM = -1;
1646
1647 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1648 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1649 return nTRM;
1650 }
1651 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1652 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1653 return nTRM;
1654 }
1655 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1656 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1657 return nTRM;
1658 }
1659 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ()) {
1660 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1661 return nTRM;
1662 }
1663 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX()) {
1664 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1665 return nTRM;
1666 }
1667
1668 if ( vol[3]>=AliTOFGeometry::NpadZ() )
1669 {
1670 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1671 return nTRM;
1672 }
1673
1674 Int_t nPlate = vol[1];
1675 Int_t nStrip = vol[2];
1676
1677 Int_t iDDL = Geant2DDL(vol)%4;
1678
1679 switch (iDDL) {
1680
1681 case 0:
1682
1683 if (nPlate==0) {
1684 if (nStrip<= 4) nTRM = 4;
1685 else if (nStrip> 4 && nStrip<= 9) nTRM = 5;
1686 else if (nStrip> 9 && nStrip<=14) nTRM = 6;
1687 else if (nStrip>14) nTRM = 7;
1688 }
1689 else if (nPlate==1) {
1690 if (nStrip== 0) nTRM = 7;
1691 else if (nStrip> 0 && nStrip<= 5) nTRM = 8;
1692 else if (nStrip> 5 && nStrip<=10) nTRM = 9;
1693 else if (nStrip>10 && nStrip<=15) nTRM = 10;
1694 else if (nStrip>15) nTRM = 11;
1695 }
1696 else if (nPlate==2) {
1697 if (nStrip<= 1) nTRM = 11;
1698 else if (nStrip> 1 && nStrip< 7) nTRM = 12;
1699 }
1700
1701 break;
1702 case 1:
1703
1704 if (nPlate==0) {
1705 if (nStrip== 0) nTRM = 3;
1706 else if (nStrip> 0 && nStrip<= 5) nTRM = 4;
1707 else if (nStrip> 5 && nStrip<=10) nTRM = 5;
1708 else if (nStrip>10 && nStrip<=15) nTRM = 6;
1709 else if (nStrip>15) nTRM = 7;
1710 }
1711 else if (nPlate==1) {
1712 if (nStrip<=1) nTRM = 7;
1713 else if (nStrip> 1 && nStrip<= 6) nTRM = 8;
1714 else if (nStrip> 6 && nStrip<=11) nTRM = 9;
1715 else if (nStrip>11 && nStrip<=16) nTRM = 10;
1716 else if (nStrip>16) nTRM = 11;
1717 }
1718 else if (nPlate==2) {
1719 if (nStrip<= 2) nTRM = 11;
1720 else if (nStrip> 2 && nStrip<= 7) nTRM = 12;
1721 }
1722
1723 break;
1724 case 2:
1725
1726 if (nPlate==4) {
1727 if (nStrip>=14) nTRM = 4;
1728 else if (nStrip<14 && nStrip>= 9) nTRM = 5;
1729 else if (nStrip< 9 && nStrip>= 4) nTRM = 6;
1730 else if (nStrip< 4) nTRM = 7;
1731 }
1732 else if (nPlate==3) {
1733 if (nStrip==18) nTRM = 7;
1734 else if (nStrip<18 && nStrip>=13) nTRM = 8;
1735 else if (nStrip<13 && nStrip>= 8) nTRM = 9;
1736 else if (nStrip< 8 && nStrip>= 3) nTRM = 10;
1737 else if (nStrip< 3) nTRM = 11;
1738 }
1739 else if (nPlate==2) {
1740 if (nStrip>=13) nTRM = 11;
1741 else if (nStrip<13 && nStrip>= 8) nTRM = 12;
1742 }
1743
1744 break;
1745 case 3:
1746
1747 if (nPlate==4) {
1748 if (nStrip==18) nTRM = 3;
1749 else if (nStrip<18 && nStrip>=13) nTRM = 4;
1750 else if (nStrip<13 && nStrip>= 8) nTRM = 5;
1751 else if (nStrip< 8 && nStrip>= 3) nTRM = 6;
1752 else if (nStrip< 3) nTRM = 7;
1753 }
1754 else if (nPlate==3) {
1755 if (nStrip>=17) nTRM = 7;
1756 else if (nStrip<17 && nStrip>=12) nTRM = 8;
1757 else if (nStrip<12 && nStrip>= 7) nTRM = 9;
1758 else if (nStrip< 7 && nStrip>= 2) nTRM = 10;
1759 else if (nStrip< 2) nTRM = 11;
1760 }
1761 else if (nPlate==2) {
1762 if (nStrip>=12) nTRM = 11;
1763 else if (nStrip <12 && nStrip>= 7) nTRM = 12;
1764 }
1765
1766 break;
1767
1768 }
1769
1770 return nTRM;
1771
1772}
1773
1774//---------------------------------------------------------------------------
1775Int_t AliTOFRawStream::Geant2TDC(Int_t vol[])
1776{
1777 //
1778 // To convert:
1779 // nSector number -vol[0]- (variable in [0,17])
1780 // nPlate number -vol[1]- (variable in [0, 5])
1781 // nStrip number -vol[2]- (variable in [0,14/18])
1782 // nPadZ number -vol[3]- (variable in [0, 1])
1783 // nPadX number -vol[4]- (variable in [0,47])
1784 // in:
1785 // nTDC (variable in [0;14]) -> number of the TDC
1786 //
1787
1788 Int_t nTDC = -1;
1789
1790 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1791 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1792 return nTDC;
1793 }
1794 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1795 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1796 return nTDC;
1797 }
1798 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1799 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1800 return nTDC;
1801 }
1802 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
1803 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1804 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
1805 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1806 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
1807 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1808 return nTDC;
1809 }
1810
1811 Int_t nPlate = vol[1];
1812 Int_t nStrip = vol[2];
1813 Int_t iPadX = vol[4];
1814
1815 Int_t iDDL = Geant2DDL(vol)%4;
1816
1817 switch (iDDL) {
1818
1819 case 0:
1820
1821 if (nPlate==0) {
1822 if (nStrip<= 4) nTDC = (3*(nStrip)+2-(iPadX/4)%3);
1823 else if (nStrip> 4 && nStrip<= 9) nTDC = (3*(nStrip- 5)+2-(iPadX/4)%3);
1824 else if (nStrip> 9 && nStrip<=14) nTDC = (3*(nStrip-10)+2-(iPadX/4)%3);
1825 else if (nStrip>14) nTDC = (3*(nStrip-15)+2-(iPadX/4)%3);
1826 }
1827 else if (nPlate==1) {
1828 if (nStrip== 0) nTDC = (3*(nStrip+ 4)+2-(iPadX/4)%3);
1829 else if (nStrip> 0 && nStrip<= 5) nTDC = (3*(nStrip- 1)+2-(iPadX/4)%3);
1830 else if (nStrip> 5 && nStrip<=10) nTDC = (3*(nStrip- 6)+2-(iPadX/4)%3);
1831 else if (nStrip>10 && nStrip<=15) nTDC = (3*(nStrip-11)+2-(iPadX/4)%3);
1832 else if (nStrip>15) nTDC = (3*(nStrip-16)+2-(iPadX/4)%3);
1833 }
1834 else if (nPlate==2) {
1835 if (nStrip<= 1) nTDC = (3*(nStrip+ 3)+2-(iPadX/4)%3);
1836 else if (nStrip> 1 && nStrip< 7) nTDC = (3*(nStrip- 2)+2-(iPadX/4)%3);
1837 }
1838
1839 break;
1840 case 1:
1841
1842 if (nPlate==0) {
1843 if (nStrip== 0) nTDC = (3*(nStrip)+(iPadX/4)%3);
1844 else if (nStrip> 0 && nStrip<= 5) nTDC = (3*( 5-nStrip)+(iPadX/4)%3);
1845 else if (nStrip> 5 && nStrip<=10) nTDC = (3*(10-nStrip)+(iPadX/4)%3);
1846 else if (nStrip>10 && nStrip<=15) nTDC = (3*(15-nStrip)+(iPadX/4)%3);
1847 else if (nStrip>15) nTDC = (3*(20-nStrip)+(iPadX/4)%3);
1848 }
1849 else if (nPlate==1) {
1850 if (nStrip<= 1) nTDC = (3*( 1-nStrip)+(iPadX/4)%3);
1851 else if (nStrip> 1 && nStrip<= 6) nTDC = (3*( 6-nStrip)+(iPadX/4)%3);
1852 else if (nStrip> 6 && nStrip<=11) nTDC = (3*(11-nStrip)+(iPadX/4)%3);
1853 else if (nStrip>11 && nStrip<=16) nTDC = (3*(16-nStrip)+(iPadX/4)%3);
1854 else if (nStrip>16) nTDC = (3*(21-nStrip)+(iPadX/4)%3);
1855 }
1856 else if (nPlate==2) {
1857 if (nStrip<= 2) nTDC = (3*( 2-nStrip)+(iPadX/4)%3);
1858 else if (nStrip> 2 && nStrip<= 7) nTDC = (3*( 7-nStrip)+(iPadX/4)%3);
1859 }
1860
1861 break;
1862 case 2:
1863
1864 if (nPlate==4) {
1865 if (nStrip>=14) nTDC = (3*(18-nStrip)+((iPadX/4)%3));
1866 else if (nStrip<14 && nStrip>= 9) nTDC = (3*(13-nStrip)+((iPadX/4)%3));
1867 else if (nStrip< 9 && nStrip>= 4) nTDC = (3*( 8-nStrip)+((iPadX/4)%3));
1868 else if (nStrip< 4) nTDC = (3*( 3-nStrip)+((iPadX/4)%3));
1869 }
1870 else if (nPlate==3) {
1871 if (nStrip==18) nTDC = (3*(22-nStrip)+((iPadX/4)%3));
1872 else if (nStrip<18 && nStrip>=13) nTDC = (3*(17-nStrip)+((iPadX/4)%3));
1873 else if (nStrip<13 && nStrip>= 8) nTDC = (3*(12-nStrip)+((iPadX/4)%3));
1874 else if (nStrip< 8 && nStrip>= 3) nTDC = (3*( 7-nStrip)+((iPadX/4)%3));
1875 else if (nStrip< 3) nTDC = (3*( 2-nStrip)+((iPadX/4)%3));
1876 }
1877 else if (nPlate==2) {
1878 if (nStrip>=13) nTDC = (3*(17-nStrip)+((iPadX/4)%3));
1879 else if (nStrip<13 && nStrip>= 8) nTDC = (3*(12-nStrip)+((iPadX/4)%3));
1880 }
1881
1882 break;
1883 case 3:
1884
1885 if (nPlate==4) {
1886 if (nStrip==18) nTDC = (3*(nStrip-18)+2-(iPadX/4)%3);
1887 else if (nStrip<18 && nStrip>=13) nTDC = (3*(nStrip-13)+2-(iPadX/4)%3);
1888 else if (nStrip<13 && nStrip>= 8) nTDC = (3*(nStrip- 8)+2-(iPadX/4)%3);
1889 else if (nStrip< 8 && nStrip>= 3) nTDC = (3*(nStrip- 3)+2-(iPadX/4)%3);
1890 else if (nStrip< 3) nTDC = (3*(nStrip+ 2)+2-(iPadX/4)%3);
1891 }
1892 else if (nPlate==3) {
1893 if (nStrip>=17) nTDC = (3*(nStrip-17)+2-(iPadX/4)%3);
1894 else if (nStrip<17 && nStrip>=12) nTDC = (3*(nStrip-12)+2-(iPadX/4)%3);
1895 else if (nStrip<12 && nStrip>= 7) nTDC = (3*(nStrip- 7)+2-(iPadX/4)%3);
1896 else if (nStrip< 7 && nStrip>= 2) nTDC = (3*(nStrip- 2)+2-(iPadX/4)%3);
1897 else if (nStrip< 2) nTDC = (3*(nStrip+ 3)+2-(iPadX/4)%3);
1898 }
1899 else if (nPlate==2) {
1900 if (nStrip>=12) nTDC = (3*(nStrip-12)+2-(iPadX/4)%3);
1901 else if (nStrip <12 && nStrip>= 7) nTDC = (3*(nStrip- 7)+2-(iPadX/4)%3);
1902 }
1903
1904 break;
1905
1906 }
1907
1908 return nTDC;
1909
1910}
1911
1912//---------------------------------------------------------------------------
1913Int_t AliTOFRawStream::Geant2Chain(Int_t vol[])
1914{
1915 //
1916 // To convert:
1917 // nSector number -vol[0]- (variable in [0,17])
1918 // nPlate number -vol[1]- (variable in [0, 5])
1919 // nStrip number -vol[2]- (variable in [0,14/18])
1920 // nPadZ number -vol[3]- (variable in [0, 1])
1921 // nPadX number -vol[4]- variable in [0,47])
1922 // in:
1923 // nChain (variable in [0; 1]) -> number of the TRM chain
1924 //
1925
1926 Int_t nChain = -1;
1927
1928 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1929 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1930 return nChain;
1931 }
1932 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1933 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1934 return nChain;
1935 }
1936 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1937 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1938 return nChain;
1939 }
1940 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
1941 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1942 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
1943 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1944 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
1945 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1946 return nChain;
1947 }
1948
1949 Int_t iPadX = vol[4];
1950
1951 if (iPadX<12 || iPadX>=36) nChain = 0;
1952 else nChain = 1;
1953
1954 return nChain;
1955
1956}
1957
1958//---------------------------------------------------------------------------
1959Int_t AliTOFRawStream::Geant2Channel(Int_t vol[])
1960{
1961 //
1962 // To convert:
1963 // nSector number -vol[0]- (variable in [0,17])
1964 // nPlate number -vol[1]- (variable in [0, 5])
1965 // nStrip number -vol[2]- (variable in [0,14/18])
1966 // nPadZ number -vol[3]- (variable in [0, 1])
1967 // nPadX number -vol[4]- (variable in [0,47])
1968 // in:
1969 // nChannel (variable in [0; 7]) -> number of the TDC channel
1970 //
1971
1972 Int_t nChannel = -1;
1973
1974 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1975 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1976 return nChannel;
1977 }
1978 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1979 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1980 return nChannel;
1981 }
1982 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1983 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1984 return nChannel;
1985 }
1986 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
1987 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1988 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
1989 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1990 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
1991 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1992 return nChannel;
1993 }
1994
1995 Int_t iPadZ = vol[3];
1996 Int_t iPadX = vol[4];
1997
1998 Int_t iDDL = Geant2DDL(vol)%4;
1999
2000 switch (iDDL) {
2001
2002 case 0:
2003 nChannel = ((2*(23-iPadX) + (1-iPadZ)))%8;
2004 break;
2005 case 1:
2006 nChannel = ((2*(iPadX-24) + (iPadZ)))%8;
2007 break;
2008 case 2:
2009 nChannel = ((2*(iPadX-24) + (iPadZ)))%8;
2010 break;
2011 case 3:
2012 nChannel = ((2*(23-iPadX) + (1-iPadZ)))%8;
2013 break;
2014 }
2015
2016 return nChannel;
2017
2018}