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