Stepping called right after source using sodraw.
[u/mrichter/AliRoot.git] / TRD / AliTRDrawData.cxx
CommitLineData
5990c064 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
88cb7938 16/* $Id$ */
5990c064 17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// TRD raw data conversion class //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
a2cb5b3d 24#include <Riostream.h>
090026bf 25#include <TMath.h>
ecf39416 26#include "TClass.h"
5990c064 27
2745a409 28#include "AliDAQ.h"
29#include "AliRawDataHeader.h"
30#include "AliRawReader.h"
31#include "AliLog.h"
32
5990c064 33#include "AliTRDrawData.h"
34#include "AliTRDdigitsManager.h"
bd0f8685 35#include "AliTRDgeometry.h"
5990c064 36#include "AliTRDdataArrayI.h"
b864d801 37#include "AliTRDRawStream.h"
ecf39416 38#include "AliTRDRawStreamV2.h"
50378239 39
3551db50 40#include "AliTRDcalibDB.h"
08f92f14 41#include "AliFstream.h"
5990c064 42
ca21baaa 43#include "AliTRDSignalIndex.h"
dfd03fc3 44
45#include "AliTRDfeeParam.h"
46#include "AliTRDmcmSim.h"
47
5990c064 48ClassImp(AliTRDrawData)
49
50//_____________________________________________________________________________
2cb20be6 51AliTRDrawData::AliTRDrawData()
52 :TObject()
dfd03fc3 53 ,fGeo(NULL)
54 ,fFee(NULL)
8c703901 55 ,fNumberOfDDLs(0)
5990c064 56{
b864d801 57 //
58 // Default constructor
59 //
dfd03fc3 60 fFee = AliTRDfeeParam::Instance();
61 fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
5990c064 62}
63
64//_____________________________________________________________________________
8c703901 65AliTRDrawData::AliTRDrawData(const AliTRDrawData &r)
66 :TObject(r)
dfd03fc3 67 ,fGeo(NULL)
68 ,fFee(NULL)
8c703901 69 ,fNumberOfDDLs(0)
70{
71 //
72 // Copy constructor
73 //
dfd03fc3 74 fFee = AliTRDfeeParam::Instance();
75 fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
8c703901 76}
77
78//_____________________________________________________________________________
5990c064 79AliTRDrawData::~AliTRDrawData()
80{
81 //
82 // Destructor
83 //
8c703901 84}
85
86//_____________________________________________________________________________
87Bool_t AliTRDrawData::Digits2Raw(TTree *digitsTree, TTree *tracks )
88{
89 //
90 // Initialize necessary parameters and call one
91 // of the raw data simulator selected by SetRawVersion.
92 //
93 // Currently tracklet output is not spported yet and it
94 // will be supported in higher version simulator.
95 //
96
8c703901 97 AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
98
99 if (!digitsManager->ReadDigits(digitsTree)) {
100 delete digitsManager;
101 return kFALSE;
102 }
103
104 if (tracks != NULL) {
105 delete digitsManager;
7925de54 106 AliError("Tracklet input is not supported yet.");
8c703901 107 return kFALSE;
108 }
109
110 fGeo = new AliTRDgeometry();
111
f162af62 112 if (!AliTRDcalibDB::Instance()) {
7925de54 113 AliError("Could not get calibration object");
8c703901 114 delete fGeo;
115 delete digitsManager;
116 return kFALSE;
117 }
118
119 Int_t retval = kTRUE;
dfd03fc3 120 Int_t rv = fFee->GetRAWversion();
8c703901 121
122 // Call appropriate Raw Simulator
dfd03fc3 123 if ( rv > 0 && rv <= 3 ) retval = Digits2Raw(digitsManager);
7925de54 124 else {
125 retval = kFALSE;
dfd03fc3 126 AliWarning(Form("Unsupported raw version (%d).", rv));
8c703901 127 }
128
129 // Cleanup
130 delete fGeo;
131 delete digitsManager;
132
133 return retval;
134
135}
136
137//_____________________________________________________________________________
50378239 138Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager)
8c703901 139{
140 //
7925de54 141 // Raw data simulator for all versions > 0. This is prepared for real data.
8c703901 142 // This version simulate only raw data with ADC data and not with tracklet.
8c703901 143 //
144
7925de54 145 const Int_t kMaxHcWords = (fGeo->TBmax()/3)*fGeo->ADCmax()*fGeo->MCMmax()*fGeo->ROBmaxC1()/2 + 100 + 20;
8c703901 146
147 // Buffer to temporary store half chamber data
148 UInt_t *hc_buffer = new UInt_t[kMaxHcWords];
149
150 // sect is same as iDDL, so I use only sect here.
151 for (Int_t sect = 0; sect < fGeo->Nsect(); sect++) {
152
153 char name[1024];
154 sprintf(name,"TRD_%d.ddl",sect + AliTRDRawStream::kDDLOffset);
155
08f92f14 156 AliFstream* of = new AliFstream(name);
8c703901 157
158 // Write a dummy data header
159 AliRawDataHeader header; // the event header
08f92f14 160 UInt_t hpos = of->Tellp();
161 of->WriteBuffer((char *) (& header), sizeof(header));
8c703901 162
163 // Reset payload byte size (payload does not include header).
164 Int_t npayloadbyte = 0;
165
7925de54 166 // GTU common data header (5x4 bytes per super module, shows link mask)
8c703901 167 for( Int_t cham = 0; cham < fGeo->Ncham(); cham++ ) {
777fe13b 168 UInt_t GtuCdh = (UInt_t)(0xe << 28);
7925de54 169 for( Int_t plan = 0; plan < fGeo->Nplan(); plan++) {
170 Int_t iDet = fGeo->GetDetector(plan, cham, sect);
171 // If chamber status is ok, we assume that the optical link is also OK.
172 // This is shown in the GTU link mask.
f162af62 173 if ( AliTRDcalibDB::Instance()->GetChamberStatus(iDet) )
7925de54 174 GtuCdh = GtuCdh | (3 << (2*plan));
175 }
08f92f14 176 of->WriteBuffer((char *) (& GtuCdh), sizeof(GtuCdh));
8c703901 177 npayloadbyte += 4;
178 }
179
180 // Prepare chamber data
181 for( Int_t cham = 0; cham < fGeo->Ncham(); cham++) {
182 for( Int_t plan = 0; plan < fGeo->Nplan(); plan++) {
183
184 Int_t iDet = fGeo->GetDetector(plan,cham,sect);
185
186 // Get the digits array
187 AliTRDdataArrayI *digits = digitsManager->GetDigits(iDet);
188 digits->Expand();
189
7925de54 190 Int_t hcwords = 0;
dfd03fc3 191 Int_t rv = fFee->GetRAWversion();
8c703901 192
193 // Process A side of the chamber
dfd03fc3 194 if ( rv >= 1 && rv <= 2 ) hcwords = ProduceHcDataV1andV2(digits,0,iDet,hc_buffer,kMaxHcWords);
195 if ( rv == 3 ) hcwords = ProduceHcDataV3 (digits,0,iDet,hc_buffer,kMaxHcWords);
196
08f92f14 197 of->WriteBuffer((char *) hc_buffer, hcwords*4);
8c703901 198 npayloadbyte += hcwords*4;
199
200 // Process B side of the chamber
dfd03fc3 201 if ( rv >= 1 && rv <= 2 ) hcwords = ProduceHcDataV1andV2(digits,1,iDet,hc_buffer,kMaxHcWords);
202 if ( rv >= 3 ) hcwords = ProduceHcDataV3 (digits,1,iDet,hc_buffer,kMaxHcWords);
203
08f92f14 204 of->WriteBuffer((char *) hc_buffer, hcwords*4);
8c703901 205 npayloadbyte += hcwords*4;
8c703901 206 }
207 }
208
209 // Complete header
08f92f14 210 header.fSize = UInt_t(of->Tellp()) - hpos;
8c703901 211 header.SetAttribute(0); // Valid data
08f92f14 212 of->Seekp(hpos); // Rewind to header position
213 of->WriteBuffer((char *) (& header), sizeof(header));
8c703901 214 delete of;
8c703901 215 }
216
e21c2d7d 217 delete [] hc_buffer;
8c703901 218 return kTRUE;
219
220}
221
222//_____________________________________________________________________________
7925de54 223Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDdataArrayI *digits, Int_t side
224 , Int_t det, UInt_t *buf, Int_t maxSize)
8c703901 225{
226 //
dfd03fc3 227 // This function simulates: 1) SM-I commissiong data Oct. 06 (Raw Version == 1).
228 // 2) Full Raw Production Version (Raw Version == 2)
7925de54 229 //
8c703901 230 // Produce half chamber data (= an ORI data) for the given chamber (det) and side (side)
231 // where
7925de54 232 //
8c703901 233 // side=0 means A side with ROB positions 0, 2, 4, 6.
234 // side=1 means B side with ROB positions 1, 3, 5, 7.
235 //
236 // Chamber type (C0 orC1) is determined by "det" automatically.
237 // Appropriate size of buffer (*buf) must be prepared prior to calling this function.
238 // Pointer to the buffer and its size must be given to "buf" and "maxSize".
239 // Return value is the number of valid data filled in the buffer in unit of 32 bits
240 // UInt_t words.
241 // If buffer size if too small, the data is truncated with the buffer size however
242 // the function will finish without crash (this behaviour is similar to the MCM).
243 //
244
245 Int_t nw = 0; // Number of written words
246 Int_t of = 0; // Number of overflowed words
247 Int_t plan = fGeo->GetPlane( det ); // Plane
248 Int_t cham = fGeo->GetChamber( det ); // Chamber
249 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
f162af62 250 Int_t nRow = fGeo->GetRowMax( plan, cham, sect );
251 Int_t nCol = fGeo->GetColMax( plan );
252 const Int_t nTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
8c703901 253 Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
254 Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
255 UInt_t x = 0; // General used number
dfd03fc3 256 Int_t rv = fFee->GetRAWversion();
8c703901 257
258 // Check the nCol and nRow.
259 if ((nCol == 144) &&
260 (nRow == 16 || nRow == 12)) {
261 kCtype = (nRow-12) / 4;
262 }
263 else {
7925de54 264 AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
8c703901 265 ,nRow,nCol));
266 return 0;
267 }
268
269 AliDebug(1,Form("Producing raw data for sect=%d plan=%d cham=%d side=%d"
270 ,sect,plan,cham,side));
271
272 // Tracklet should be processed here but not implemented yet
273
274 // Write end of tracklet marker
275 if (nw < maxSize) {
bd63bf88 276 buf[nw++] = kEndoftrackletmarker;
8c703901 277 }
278 else {
279 of++;
280 }
281
282 // Half Chamber header
dfd03fc3 283 if ( rv == 1 ) {
7925de54 284 // Now it is the same version as used in SM-I commissioning.
285 Int_t dcs = det+100; // DCS Serial (in simulation, it is meaningless
286 x = (dcs<<20) | (sect<<15) | (plan<<12) | (cham<<9) | (side<<8) | 1;
287 if (nw < maxSize) {
288 buf[nw++] = x;
289 }
290 else {
291 of++;
292 }
293 }
dfd03fc3 294 else if ( rv == 2 ) {
bd63bf88 295 // h[0] (there are 3 HC header)
7925de54 296 Int_t minorv = 0; // The minor version number
ecf39416 297 Int_t add = 2; // The number of additional header words to follow
dfd03fc3 298 x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (plan<<6) | (cham<<3) | (side<<2) | 1;
7925de54 299 if (nw < maxSize) {
300 buf[nw++] = x;
301 }
302 else {
303 of++;
304 }
305 // h[1]
306 Int_t bc_ctr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
307 Int_t pt_ctr = 15; // pretrigger counter. Here it is set to 15 always for no reason
308 Int_t pt_phase = 11; // pretrigger phase. Here it is set to 11 always for no reason
309 x = (bc_ctr<<16) | (pt_ctr<<12) | (pt_phase<<8) | ((nTBin-1)<<2) | 1;
310 if (nw < maxSize) {
311 buf[nw++] = x;
312 }
313 else {
314 of++;
315 }
bd63bf88 316 // h[2]
317 Int_t ped_setup = 1; // Pedestal filter setup (0:1). Here it is always 1 for no reason
318 Int_t gain_setup = 1; // Gain filter setup (0:1). Here it is always 1 for no reason
319 Int_t tail_setup = 1; // Tail filter setup (0:1). Here it is always 1 for no reason
320 Int_t xt_setup = 0; // Cross talk filter setup (0:1). Here it is always 0 for no reason
321 Int_t nonlin_setup = 0; // Nonlinearity filter setup (0:1). Here it is always 0 for no reason
322 Int_t bypass_setup = 0; // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason
323 Int_t common_additive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason
324 x = (ped_setup<<31) | (gain_setup<<30) | (tail_setup<<29) | (xt_setup<<28) | (nonlin_setup<<27)
325 | (bypass_setup<<26) | (common_additive<<20) | 1;
326 if (nw < maxSize) {
327 buf[nw++] = x;
328 }
329 else {
330 of++;
331 }
8c703901 332 }
333
334 // Scan for ROB and MCM
335 for (Int_t iRobRow = 0; iRobRow < (kCtype + 3); iRobRow++ ) {
336 Int_t iRob = iRobRow * 2 + side;
7925de54 337 for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) {
8c703901 338 Int_t padrow = iRobRow * 4 + iMcm / 4;
339
340 // MCM header
7925de54 341 x = ((iRob * fGeo->MCMmax() + iMcm) << 24) | ((iEv % 0x100000) << 4) | 0xC;
8c703901 342 if (nw < maxSize) {
343 buf[nw++] = x;
344 }
345 else {
346 of++;
347 }
348
349 // ADC data
350 for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
ecf39416 351 Int_t padcol = fFee->GetPadColFromADC(iRob, iMcm, iAdc);
7925de54 352 UInt_t aa = !(iAdc & 1) + 2;
8c703901 353 UInt_t *a = new UInt_t[nTBin+2];
354 // 3 timebins are packed into one 32 bits word
355 for (Int_t iT = 0; iT < nTBin; iT+=3) {
7925de54 356 if ((padcol >= 0) && (padcol < nCol)) {
357 a[iT ] = ((iT ) < nTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT ) : 0;
358 a[iT+1] = ((iT + 1) < nTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT + 1) : 0;
359 a[iT+2] = ((iT + 2) < nTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT + 2) : 0;
360 }
361 else {
362 a[iT] = a[iT+1] = a[iT+2] = 0; // This happenes at the edge of chamber (should be pedestal! How?)
8c703901 363 }
7925de54 364 x = (a[iT+2] << 22) | (a[iT+1] << 12) | (a[iT] << 2) | aa;
365 if (nw < maxSize) {
366 buf[nw++] = x;
8c703901 367 }
7925de54 368 else {
369 of++;
8c703901 370 }
7925de54 371 }
8c703901 372 // Diagnostics
373 Float_t avg = 0;
374 Float_t rms = 0;
375 for (Int_t iT = 0; iT < nTBin; iT++) {
376 avg += (Float_t) (a[iT]);
377 }
378 avg /= (Float_t) nTBin;
379 for (Int_t iT = 0; iT < nTBin; iT++) {
380 rms += ((Float_t) (a[iT]) - avg) * ((Float_t) (a[iT]) - avg);
381 }
382 rms = TMath::Sqrt(rms / (Float_t) nTBin);
383 if (rms > 1.7) {
7925de54 384 AliDebug(2,Form("Large RMS (>1.7) (ROB,MCM,ADC)=(%02d,%02d,%02d), avg=%03.1f, rms=%03.1f"
385 ,iRob,iMcm,iAdc,avg,rms));
8c703901 386 }
e21c2d7d 387 delete [] a;
8c703901 388 }
389 }
390 }
391
392 // Write end of raw data marker
393 if (nw < maxSize) {
bd63bf88 394 buf[nw++] = kEndofrawdatamarker;
8c703901 395 }
396 else {
397 of++;
398 }
399 if (of != 0) {
400 AliWarning("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
401 }
402
403 return nw;
5990c064 404
405}
406
dfd03fc3 407
408//_____________________________________________________________________________
409Int_t AliTRDrawData::ProduceHcDataV3(AliTRDdataArrayI *digits, Int_t side
410 , Int_t det, UInt_t *buf, Int_t maxSize)
411{
412 //
413 // This function simulates: Raw Version == 3 (Zero Suppression Prototype)
414 //
415
416 Int_t nw = 0; // Number of written words
417 Int_t of = 0; // Number of overflowed words
418 Int_t plan = fGeo->GetPlane( det ); // Plane
419 Int_t cham = fGeo->GetChamber( det ); // Chamber
420 Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
421 Int_t nRow = fGeo->GetRowMax( plan, cham, sect );
422 Int_t nCol = fGeo->GetColMax( plan );
423 const Int_t nTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
424 Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
6e5d4cb2 425 //Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
dfd03fc3 426 UInt_t x = 0; // General used number
427 Int_t rv = fFee->GetRAWversion();
428
429 // Check the nCol and nRow.
430 if ((nCol == 144) &&
431 (nRow == 16 || nRow == 12)) {
432 kCtype = (nRow-12) / 4;
433 }
434 else {
435 AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
436 ,nRow,nCol));
437 return 0;
438 }
439
440 AliDebug(1,Form("Producing raw data for sect=%d plan=%d cham=%d side=%d"
441 ,sect,plan,cham,side));
442
443 // Tracklet should be processed here but not implemented yet
444
445 // Write end of tracklet marker
446 if (nw < maxSize) {
447 buf[nw++] = kEndoftrackletmarker;
448 }
449 else {
450 of++;
451 }
452
453 // Half Chamber header
454 // h[0] (there are 3 HC header)
455 Int_t minorv = 0; // The minor version number
ecf39416 456 Int_t add = 2; // The number of additional header words to follow
dfd03fc3 457 x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (plan<<6) | (cham<<3) | (side<<2) | 1;
458 if (nw < maxSize) {
459 buf[nw++] = x;
460 }
461 else {
462 of++;
463 }
464 // h[1]
465 Int_t bc_ctr = 99; // bunch crossing counter. Here it is set to 99 always for no reason
466 Int_t pt_ctr = 15; // pretrigger counter. Here it is set to 15 always for no reason
467 Int_t pt_phase = 11; // pretrigger phase. Here it is set to 11 always for no reason
468 x = (bc_ctr<<16) | (pt_ctr<<12) | (pt_phase<<8) | ((nTBin-1)<<2) | 1;
469 if (nw < maxSize) {
470 buf[nw++] = x;
471 }
472 else {
473 of++;
474 }
475 // h[2]
476 Int_t ped_setup = 1; // Pedestal filter setup (0:1). Here it is always 1 for no reason
477 Int_t gain_setup = 1; // Gain filter setup (0:1). Here it is always 1 for no reason
478 Int_t tail_setup = 1; // Tail filter setup (0:1). Here it is always 1 for no reason
479 Int_t xt_setup = 0; // Cross talk filter setup (0:1). Here it is always 0 for no reason
480 Int_t nonlin_setup = 0; // Nonlinearity filter setup (0:1). Here it is always 0 for no reason
481 Int_t bypass_setup = 0; // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason
482 Int_t common_additive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason
483 x = (ped_setup<<31) | (gain_setup<<30) | (tail_setup<<29) | (xt_setup<<28) | (nonlin_setup<<27)
484 | (bypass_setup<<26) | (common_additive<<20) | 1;
485 if (nw < maxSize) {
486 buf[nw++] = x;
487 }
488 else {
489 of++;
490 }
491
dfd03fc3 492
493 // Scan for ROB and MCM
494 for (Int_t iRobRow = 0; iRobRow < (kCtype + 3); iRobRow++ ) {
495 Int_t iRob = iRobRow * 2 + side;
496 for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) {
497
709187ec 498 AliTRDmcmSim *mcm = new AliTRDmcmSim();
dfd03fc3 499 mcm->Init( det, iRob, iMcm );
500 Int_t padrow = mcm->GetRow();
501
502 // Copy ADC data to MCM simulator
503 for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
504 Int_t padcol = mcm->GetCol( iAdc );
505 if ((padcol >= 0) && (padcol < nCol)) {
506 for (Int_t iT = 0; iT < nTBin; iT++) {
507 mcm->SetData( iAdc, iT, digits->GetDataUnchecked( padrow, padcol, iT) );
508 }
509 } else { // this means it is out of chamber, and masked ADC
510 mcm->SetDataPedestal( iAdc );
511 }
512 }
513 // Simulate process in MCM
514 mcm->Filter(); // Apply filter
515 mcm->ZSMapping(); // Calculate zero suppression mapping
ecf39416 516 //mcm->DumpData( "trdmcmdata.txt", "RFZS" ); // debugging purpose
dfd03fc3 517
518 // Write MCM data to buffer
519 Int_t temp_nw = mcm->ProduceRawStream( &buf[nw], maxSize - nw );
520 if( temp_nw < 0 ) {
521 of += temp_nw;
522 nw += maxSize - nw;
523 AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
524 } else {
525 nw += temp_nw;
526 }
709187ec 527
528 delete mcm;
529
dfd03fc3 530 }
531 }
532
533 // Write end of raw data marker
534 if (nw < maxSize) {
535 buf[nw++] = kEndofrawdatamarker;
536 }
537 else {
538 of++;
539 }
540 if (of != 0) {
ecf39416 541 AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
dfd03fc3 542 }
543
544 return nw;
545
546}
547
5990c064 548//_____________________________________________________________________________
7925de54 549AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
5990c064 550{
b864d801 551 //
50378239 552 // Vx of the raw data reading
b864d801 553 //
5990c064 554
2cb20be6 555 AliTRDdataArrayI *digits = 0;
556 AliTRDdataArrayI *track0 = 0;
557 AliTRDdataArrayI *track1 = 0;
558 AliTRDdataArrayI *track2 = 0;
5990c064 559
ca21baaa 560 AliTRDSignalIndex *indexes = 0;
5990c064 561 // Create the digits manager
b864d801 562 AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
b864d801 563 digitsManager->CreateArrays();
5990c064 564
ecf39416 565 //AliTRDRawStream input(rawReader);
566 AliTRDRawStreamV2 input(rawReader);
dfd03fc3 567 input.SetRawVersion( fFee->GetRAWversion() );
50378239 568 input.Init();
5990c064 569
ecf39416 570 AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
571
b864d801 572 // Loop through the digits
50378239 573 Int_t lastdet = -1;
574 Int_t det = 0;
575 Int_t it = 0;
ecf39416 576 while (input.Next()) {
50378239 577
578 det = input.GetDet();
579
ecf39416 580 if (det != lastdet) { // If new detector found
50378239 581
582 lastdet = det;
583
584 if (digits) digits->Compress(1,0);
585 if (track0) track0->Compress(1,0);
586 if (track1) track1->Compress(1,0);
587 if (track2) track2->Compress(1,0);
588
589 // Add a container for the digits of this detector
590 digits = digitsManager->GetDigits(det);
591 track0 = digitsManager->GetDictionary(det,0);
592 track1 = digitsManager->GetDictionary(det,1);
593 track2 = digitsManager->GetDictionary(det,2);
594
595 // Allocate memory space for the digits buffer
596 if (digits->GetNtime() == 0)
597 {
598 digits->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
599 track0->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
600 track1->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
601 track2->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
602 }
ca21baaa 603
604 indexes = digitsManager->GetIndexes(det);
605 indexes->SetSM(input.GetSM());
606 indexes->SetStack(input.GetStack());
607 indexes->SetLayer(input.GetLayer());
608 indexes->SetDetNumber(det);
609 if (indexes->IsAllocated() == kFALSE)
610 indexes->Allocate(input.GetMaxRow(), input.GetMaxCol(), input.GetNumberOfTimeBins());
50378239 611 }
612
ecf39416 613 // 3 timebin data are stored per word
50378239 614 for (it = 0; it < 3; it++)
615 {
616 if ( input.GetTimeBin() + it < input.GetNumberOfTimeBins() )
617 {
ca21baaa 618 if (input.GetSignals()[it] > 0)
619 {
620 digits->SetDataUnchecked(input.GetRow(), input.GetCol(),
621 input.GetTimeBin() + it, input.GetSignals()[it]);
622
623 indexes->AddIndexTBin(input.GetRow(), input.GetCol(),
624 input.GetTimeBin() + it);
625 track0->SetDataUnchecked(input.GetRow(), input.GetCol(),
626 input.GetTimeBin() + it, 0);
627 track1->SetDataUnchecked(input.GetRow(), input.GetCol(),
628 input.GetTimeBin() + it, 0);
629 track2->SetDataUnchecked(input.GetRow(), input.GetCol(),
630 input.GetTimeBin() + it, 0);
631 }
50378239 632 }
633 }
5990c064 634 }
635
b864d801 636 if (digits) digits->Compress(1,0);
928e9fae 637 if (track0) track0->Compress(1,0);
638 if (track1) track1->Compress(1,0);
639 if (track2) track2->Compress(1,0);
b864d801 640
7925de54 641 return digitsManager;
642
643}