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