]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDrawData.cxx
Fixed memory leak
[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 <Riostream.h>
25 #include <TMath.h>
26 #include "TClass.h"
27
28 #include "AliDAQ.h"
29 #include "AliRawDataHeader.h"
30 #include "AliRawReader.h"
31 #include "AliLog.h"
32
33 #include "AliTRDrawData.h"
34 #include "AliTRDdigitsManager.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDdataArrayI.h"
37 #include "AliTRDRawStream.h"
38 #include "AliTRDRawStreamV2.h"
39
40 #include "AliTRDcalibDB.h"
41 #include "AliFstream.h"
42
43 #include "AliTRDSignalIndex.h"
44
45 #include "AliTRDfeeParam.h"
46 #include "AliTRDmcmSim.h"
47
48 ClassImp(AliTRDrawData)
49
50 //_____________________________________________________________________________
51 AliTRDrawData::AliTRDrawData()
52   :TObject()
53   ,fGeo(NULL)
54   ,fFee(NULL)
55   ,fNumberOfDDLs(0)
56 {
57   //
58   // Default constructor
59   //
60   fFee = AliTRDfeeParam::Instance();
61   fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
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   fFee = AliTRDfeeParam::Instance();
75   fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
76 }
77
78 //_____________________________________________________________________________
79 AliTRDrawData::~AliTRDrawData()
80 {
81   //
82   // Destructor
83   //
84 }
85
86 //_____________________________________________________________________________
87 Bool_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
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;
106     AliError("Tracklet input is not supported yet.");
107     return kFALSE;
108   }
109
110   fGeo = new AliTRDgeometry();
111
112   if (!AliTRDcalibDB::Instance()) {
113     AliError("Could not get calibration object");
114     delete fGeo;
115     delete digitsManager;
116     return kFALSE;
117   }
118
119   Int_t retval = kTRUE;
120   Int_t rv     = fFee->GetRAWversion();
121
122   // Call appropriate Raw Simulator
123   if ( rv > 0 && rv <= 3 ) retval = Digits2Raw(digitsManager); 
124   else {
125     retval = kFALSE;
126     AliWarning(Form("Unsupported raw version (%d).", rv));
127   }
128
129   // Cleanup
130   delete fGeo;
131   delete digitsManager;
132
133   return retval;
134
135 }
136
137 //_____________________________________________________________________________
138 Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager)
139 {
140   //
141   // Raw data simulator for all versions > 0. This is prepared for real data.
142   // This version simulate only raw data with ADC data and not with tracklet.
143   //
144
145   const Int_t kMaxHcWords = (fGeo->TBmax()/3)*fGeo->ADCmax()*fGeo->MCMmax()*fGeo->ROBmaxC1()/2 + 100 + 20;
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
156     AliFstream* of = new AliFstream(name);
157
158     // Write a dummy data header
159     AliRawDataHeader  header;  // the event header
160     UInt_t hpos = of->Tellp();
161     of->WriteBuffer((char *) (& header), sizeof(header));
162
163     // Reset payload byte size (payload does not include header).
164     Int_t npayloadbyte = 0;
165
166     // GTU common data header (5x4 bytes per super module, shows link mask)
167     for( Int_t cham = 0; cham < fGeo->Ncham(); cham++ ) {
168       UInt_t GtuCdh = (UInt_t)(0xe << 28);
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.
173         if ( AliTRDcalibDB::Instance()->GetChamberStatus(iDet) )
174           GtuCdh = GtuCdh | (3 << (2*plan));
175       }
176       of->WriteBuffer((char *) (& GtuCdh), sizeof(GtuCdh));
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
190         Int_t hcwords = 0;
191         Int_t rv = fFee->GetRAWversion();
192
193         // Process A side of the chamber
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
197         of->WriteBuffer((char *) hc_buffer, hcwords*4);
198         npayloadbyte += hcwords*4;
199
200         // Process B side of the chamber
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
204         of->WriteBuffer((char *) hc_buffer, hcwords*4);
205         npayloadbyte += hcwords*4;
206       }
207     }
208
209     // Complete header
210     header.fSize = UInt_t(of->Tellp()) - hpos;
211     header.SetAttribute(0);  // Valid data
212     of->Seekp(hpos);         // Rewind to header position
213     of->WriteBuffer((char *) (& header), sizeof(header));
214     delete of;
215   }
216
217   delete [] hc_buffer;
218   return kTRUE;
219
220 }
221
222 //_____________________________________________________________________________
223 Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDdataArrayI *digits, Int_t side
224                                         , Int_t det, UInt_t *buf, Int_t maxSize)
225 {
226   //
227   // This function simulates: 1) SM-I commissiong data Oct. 06 (Raw Version == 1).
228   //                          2) Full Raw Production Version   (Raw Version == 2)
229   //
230   // Produce half chamber data (= an ORI data) for the given chamber (det) and side (side)
231   // where
232   //
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)
250   Int_t        nRow = fGeo->GetRowMax( plan, cham, sect );
251   Int_t        nCol = fGeo->GetColMax( plan );
252   const Int_t nTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
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
256   Int_t          rv = fFee->GetRAWversion();
257
258   // Check the nCol and nRow.
259   if ((nCol == 144) && 
260       (nRow == 16 || nRow == 12)) {
261     kCtype = (nRow-12) / 4;
262   } 
263   else {
264     AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
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) {
276     buf[nw++] = kEndoftrackletmarker;
277   } 
278   else {
279     of++;
280   }
281
282   // Half Chamber header
283   if      ( rv == 1 ) {
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   } 
294   else if ( rv == 2 ) {
295     // h[0] (there are 3 HC header)
296     Int_t minorv = 0;      // The minor version number
297     Int_t add    = 2;      // The number of additional header words to follow
298     x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (plan<<6) | (cham<<3) | (side<<2) | 1;
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     }
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     }
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;
337     for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) {
338       Int_t padrow = iRobRow * 4 + iMcm / 4;
339
340       // MCM header
341       x = ((iRob * fGeo->MCMmax() + iMcm) << 24) | ((iEv % 0x100000) << 4) | 0xC;
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++ ) {
351         Int_t padcol = fFee->GetPadColFromADC(iRob, iMcm, iAdc);
352         UInt_t aa = !(iAdc & 1) + 2;
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) { 
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?)
363           }
364           x = (a[iT+2] << 22) | (a[iT+1] << 12) | (a[iT] << 2) | aa;
365           if (nw < maxSize) {
366             buf[nw++] = x; 
367           }
368           else {
369             of++;
370           }
371         }
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) {
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));
386         }
387         delete [] a;
388       }
389     }
390   }
391
392   // Write end of raw data marker
393   if (nw < maxSize) {
394     buf[nw++] = kEndofrawdatamarker; 
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;
404
405 }
406
407
408 //_____________________________________________________________________________
409 Int_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)
425   Int_t         iEv = 0xA;                     // Event ID. Now fixed to 10, how do I get event id?
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
456   Int_t add    = 2;    // The number of additional header words to follow
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
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
498       AliTRDmcmSim *mcm = new AliTRDmcmSim();
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
516       //mcm->DumpData( "trdmcmdata.txt", "RFZS" ); // debugging purpose
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       }
527
528       delete mcm;
529
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) {
541     AliError("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
542   }
543
544   return nw;
545
546 }
547
548 //_____________________________________________________________________________
549 AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
550 {
551   //
552   // Vx of the raw data reading
553   //
554
555   AliTRDdataArrayI *digits = 0;
556   AliTRDdataArrayI *track0 = 0;
557   AliTRDdataArrayI *track1 = 0;
558   AliTRDdataArrayI *track2 = 0; 
559
560   AliTRDSignalIndex *indexes = 0;
561   // Create the digits manager
562   AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
563   digitsManager->CreateArrays();
564
565   //AliTRDRawStream input(rawReader);
566   AliTRDRawStreamV2 input(rawReader);
567   input.SetRawVersion( fFee->GetRAWversion() );
568   input.Init();
569
570   AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
571
572   // Loop through the digits
573   Int_t lastdet = -1;
574   Int_t det    = 0;
575   Int_t it = 0;
576   while (input.Next()) {
577
578       det    = input.GetDet();
579
580       if (det != lastdet) { // If new detector found
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             }
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());
611         }
612     
613       // 3 timebin data are stored per word
614       for (it = 0; it < 3; it++)
615         {
616           if ( input.GetTimeBin() + it < input.GetNumberOfTimeBins() )
617             {
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                 }
632             }
633         }
634   }
635
636   if (digits) digits->Compress(1,0);
637   if (track0) track0->Compress(1,0);
638   if (track1) track1->Compress(1,0);
639   if (track2) track2->Compress(1,0);
640
641   return digitsManager;
642
643 }