]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDRawStream.h
Better error monitoring. Pedestal structure updated. Set the sigma cut from a file...
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDRawStream.h
1 #ifndef ALIHMPIDRAWSTREAM_H
2 #define ALIHMPIDRAWSTREAM_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 ///////////////////////////////////////////////////////////////////////////////
7 ///
8 /// This is a class for reading raw data digits for HMPID.
9 /// The data format is taken from the document provided by Paolo Martinengo.
10 ///
11 /// cvetan.cheshkov@cern.ch 19/07/2007
12 ///
13 ///////////////////////////////////////////////////////////////////////////////
14
15 #include <TObject.h>
16 #include <TRandom.h>
17 #include "AliHMPIDParam.h"
18 #include <AliBitPacking.h>
19 #include <AliFstream.h>
20 #include "AliHMPIDDigit.h"
21 #include "AliDAQ.h"
22 #include "AliRawDataHeaderSim.h"
23 class AliRawReader;
24
25 class AliHMPIDRawStream: public TObject {
26   public :
27     AliHMPIDRawStream(AliRawReader* rawReader);
28     AliHMPIDRawStream();
29     
30     virtual ~AliHMPIDRawStream();
31
32     virtual void     Reset();
33     virtual Bool_t   Next();
34             void     InitVars(Int_t n);
35             void     DelVars();
36     
37             Int_t GetDDLNumber()  const { return fDDLNumber; }                                                                          // Provide current DDL number
38    static  inline Int_t GetPad(Int_t ddl,Int_t row,Int_t dil,Int_t pad);                                                                 //
39    static  inline Int_t GetNDDL()     { return kNDDL;}                                 //return the number of max # of DDLs
40    static  inline Int_t GetNErrors()  { return kSumErr;}                               //return the number of max # of Error Types
41
42             Int_t   GetNPads()       const { return fNPads;}
43             Int_t*  GetPadArray()    const { return fPad;}
44             Int_t*  GetChargeArray() const { return fCharge;}
45             Int_t   Pc          ( Int_t ddl,Int_t row,Int_t dil,Int_t pad                            ) {return AliHMPIDParam::A2P(GetPad(ddl,row,dil,pad));}                                                 //PC position number
46             Int_t   PadPcX      ( Int_t ddl,Int_t row,Int_t dil,Int_t pad                            ) {return AliHMPIDParam::A2X(GetPad(ddl,row,dil,pad));}                                                 //pad pc x # 0..79
47             Int_t   PadPcY      ( Int_t ddl,Int_t row,Int_t dil,Int_t pad                            ) {return AliHMPIDParam::A2Y(GetPad(ddl,row,dil,pad));}                                                 //pad pc y # 0..47
48
49     static inline  Char_t* GetErrName(Int_t eType);      
50     inline  Bool_t SetZeroSup (Bool_t isSup);
51     inline  Bool_t GetZeroSup(); 
52     inline  Int_t  GetErrors(Int_t ddl,Int_t eType);                                                                                   //Get errors and occurance
53     inline  Int_t  GetDDLNumber() { return fDDLNumber;} //return the number of DDL actually being decoded
54     inline  UInt_t  GetLDCNumber() { return fLDCNumber;} //return the number of LDC actually being decoded
55     inline  UInt_t  GetTimeStamp() { return fTimeStamp;} //return the time stamp of the event actually being decoded
56
57   
58         
59     Bool_t ReadHMPIDRawData();                           // Read HMPID Raw data
60     Bool_t ReadSegment(Int_t &cntSegment);               // Read Segment
61     Bool_t ReadRow(Int_t &cntRow);                       // Read Row
62     Bool_t ReadDilogic(Int_t &cntDilogic);               // Read Dilogic
63
64     Bool_t CheckRow(UInt_t row);                         // Check Row
65     Bool_t CheckDilogic(UInt_t dilogic);                 // Check Dilogic
66     Bool_t CheckPad(UInt_t pad);                         // Check pad
67     Bool_t CheckEoE(Int_t &nDil);                        // Check EoE
68     Bool_t CheckRowMarker();                             // Check RowMarker
69     Bool_t CheckSegment();                               // Check Segment
70     void   DumpData(Int_t nw);                           // Dump Data
71     void   StorePosition();                              //Debug purpose
72     
73 //    inline void    Raw            (UInt_t &w32,Int_t &ddl,Int_t &r,Int_t &d,Int_t &a);                                              //digit->(w32,ddl,r,d,a)
74 //    inline void    Raw            (Int_t ddl,Int_t r,Int_t d,Int_t a);                                                              //raw->abs pad number
75 //    inline Bool_t  Raw            (UInt_t  w32,Int_t  ddl,AliRawReader *pRR);                                                       //(w32,ddl)->digit
76     inline void    WriteRaw       (TObjArray *pDigLst                             );                                                      //write as raw stream     
77     inline void   WriteRowMarker  (AliFstream *ddl,UInt_t size);
78     inline void   WriteEoE        (AliFstream *ddl,UInt_t row,UInt_t dil,UInt_t wordCnt);  
79     inline void   WriteSegMarker  (AliFstream *ddl,UInt_t row, Int_t nwInSeg);   
80     
81 //    inline TClonesArray  ReMap(TClonesArray *pDigIn);
82 enum EDirection {kFwd,kBwd};
83
84 enum Ebits {kbit0,kbit1 , kbit2, kbit3, kbit4, kbit5, kbit6, kbit7, kbit8,
85                   kbit9 ,kbit10,kbit11,kbit12,kbit13,kbit14,kbit15,kbit16,
86                   kbit17,kbit18,kbit19,kbit20,kbit21,kbit22,kbit23,kbit24,
87                   kbit25,kbit26,kbit27,kbit28,kbit29,kbit30,kbit31,kbit32};
88     
89   enum EHMPIDRawStreamError { kRawDataSizeErr   = 0,  kRowMarkerErr     = 1,  kWrongRowErr      = 2,  kWrongDilogicErr  = 3,
90                               kWrongPadErr      = 4,  kEoEFlagErr       = 5,  kEoESizeErr       = 6,  kEoEDILOGICErr    = 7,
91                               kEoERowErr        = 8,  kBadSegWordErr    = 9,  kWrongSegErr      = 10, kRowMarkerSizeErr = 11,
92                               kSumErr           = 12  //This is always the last one, to retreive the number of errors
93                             };                        //Always check the updated list of names in the .cxx file for print-out!
94    
95   enum {
96       kNRows       = 24,                                    // Number of rows (starting from 1 !)//was25
97       kNDILOGICAdd = 10,                                    // Number of DILOGIC addresses in a row (starting from 1 !) //was11
98       kNPadAdd     = 48,                                    // Number of pad row
99       kNRowsPerSegment = 8,                                 // Number of rows per segment
100       kNDDL = 14
101     };
102  enum EHMPIDRawError {
103     kInvalidRawDataWord = 1
104   };
105
106     
107   private :
108
109     AliHMPIDRawStream& operator = (const AliHMPIDRawStream& stream);
110     AliHMPIDRawStream(const AliHMPIDRawStream& stream);
111
112     Bool_t           GetWord(Int_t n=1,EDirection dir=kFwd);             // Get n-th word
113     UInt_t           GetNextWord();                                      // Get next word
114     Int_t            fNPads;                                             // counter of pads in one DDL
115     Int_t           *fCharge;                                            // Array for charge values for all channels in one DDL
116     Int_t           *fPad;                                               // Array for abs pad values for all channels in one DDL
117     Int_t            fDDLNumber;                                         // index of current DDL number
118     UInt_t           fLDCNumber;                                         // index of current LDC number
119     UInt_t           fTimeStamp;                                         // TimeStamp
120     AliRawReader    *fRawReader;                                         // object for reading the raw data
121     UChar_t         *fData;                                              // raw data
122     Int_t          **fNumOfErr;                                          // Store the numner of errors for a given error type and a given DDL
123     Int_t            fPosition;                                          // current word
124     UInt_t           fWord;                                              // current position in fData
125     Bool_t           fZeroSup;                                           // set if zero suppression is applied
126     Int_t           *fPos;                                               // for debug purposes
127     Int_t            fiPos;                                               // counter for debug
128   
129     ClassDef(AliHMPIDRawStream, 2)                                       // base class for reading HMPID raw digits
130 };
131 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
132     /*
133 void AliHMPIDRawStream::Raw(UInt_t &w32,Int_t &ddl,Int_t &r,Int_t &d,Int_t &a)
134 {
135 // Convert raw stream word to raw word format
136 // Arguments: w32,ddl,r,d,a where to write the results
137 // Returns: none
138   Int_t y2a[6]={5,3,1,0,2,4};
139   
140   ddl=2*Ch(ddl,r,d,a)+Pc(ddl,r,d,a)%2;                                                          //DDL# 0..13
141   Int_t tmp=1+Pc(ddl,r,d,a)/2*8+PadPcY(ddl,r,d,a)/6;  r=(Pc(ddl,r,d,a)%2)? 25-tmp:tmp;              //row r=1..24
142   d=1+PadPcX(ddl,r,d,a)/8;                                                                  //DILOGIC# 1..10
143   a=y2a[PadPcY(ddl,r,d,a)%6]+6*(PadPcX(ddl,r,d,a)%8);                                           //ADDRESS 0..47        
144   
145   w32=0;    
146   AliBitPacking::PackWord((fCharge[fNPads]>4095)?4095:(UInt_t)fCharge[fNPads],w32, 0,11);       // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq        Qdc               bits (00..11) counts (0..4095)
147   //molnarl: Since in simulation the the charge can be > than 4095 but not in real life we need to protect. If fQ>4095 after packing we will get 0 for the charge! 
148   assert(0<=a&&a<=47);AliBitPacking::PackWord(        a ,w32,12,17);  // 3322 2222 2222 1111 1111 1000 0000 0000        DILOGIC address   bits (12..17) counts (0..47)
149   assert(1<=d&&d<=10);AliBitPacking::PackWord(        d ,w32,18,21);  // 1098 7654 3210 9876 5432 1098 7654 3210        DILOGIC number    bits (18..21) counts (1..10)
150   assert(1<=r&&r<=24);AliBitPacking::PackWord(        r ,w32,22,26);  //                                                Row number        bits (22..26) counts (1..24)  
151 }
152 */
153 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
154     /*
155 Int_t AliHMPIDRawStream::Raw(Int_t ddl,Int_t r,Int_t d,Int_t a)
156 {
157   //Assign absolute pad ID based on ddl,row,dil,pad
158   //Arguments: DDL, row number, dilogic number, dilogic address(pad)
159   //Returns  : nothing
160
161   assert(0<=ddl&&ddl<=13); assert(1<=r&&r<=24); assert(1<=d&&d<=10);   assert(0<=a&&a<=47);  
162   Int_t a2y[6]={3,2,4,1,5,0};//pady for a given address (for single DILOGIC chip)
163                                   Int_t ch=ddl/2;
164   Int_t tmp=(r-1)/8;              Int_t pc=(ddl%2)? 5-2*tmp:2*tmp; 
165                                   Int_t px=(d-1)*8+a/6;
166         tmp=(ddl%2)?(24-r):r-1;   Int_t py=6*(tmp%8)+a2y[a%6];
167   return AliHMPIDParam::Abs(ch,pc,px,py);
168 }
169 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
170 Bool_t AliHMPIDRawStream::Raw(UInt_t w32,Int_t ddl, AliRawReader *pRR)
171 {
172 // Converts a given raw data word to a digit
173 // Arguments: w32 - 32 bits raw data word
174 //            ddl - DDL idx  0 1 2 3 4 ... 13
175 //   Returns: none
176   Int_t r = AliBitPacking::UnpackWord(w32,22,26); assert(1<=r&&r<=24);   //                                         Row number      (1..24)    
177   Int_t d = AliBitPacking::UnpackWord(w32,18,21); assert(1<=d&&d<=10);   // 3322 2222 2222 1111 1111 1000 0000 0000 DILOGIC number  (1..10)
178   Int_t a = AliBitPacking::UnpackWord(w32,12,17); assert(0<=a&&a<=47);   // 1098 7654 3210 9876 5432 1098 7654 3210 DILOGIC address (0..47)  
179   Int_t q = AliBitPacking::UnpackWord(w32, 0,11); assert(0<=q&&q<=4095); // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq Qdc             (0..4095) 
180   if (r<1 || r>24 || d<1 || d>10 || a<0 || a>47 || q<0 || q>4095) {
181     AliWarning(Form("Invalid raw data word %x",w32));
182     pRR->AddMajorErrorLog(kInvalidRawDataWord,Form("w=%x",w32));
183     return kFALSE;
184   }
185   Raw(ddl,r,d,a);
186   fCharge[ddl][r][d][a]=q;
187   return kTRUE;
188 }
189 */
190 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
191 Int_t AliHMPIDRawStream::GetPad(Int_t ddl,Int_t row,Int_t dil,Int_t pad)
192 {
193   // The method returns the absolute pad number or -1 
194   // in case the charge from the channels
195   // has not been read or invalid arguments
196  
197   assert(0<=ddl&&ddl<=13);  
198   assert(1<=row&&row<=24); 
199   assert(1<=dil&&dil<=10);   
200   assert(0<=pad&&pad<=47);  
201   
202   Int_t a2y[6]={3,2,4,1,5,0};     //pady for a given padress (for single DILOGIC chip)
203                                   Int_t ch=ddl/2;
204   Int_t tmp=(row-1)/8;            Int_t pc=(ddl%2)? 5-2*tmp:2*tmp; 
205                                   Int_t px=(dil-1)*8+pad/6;
206         tmp=(ddl%2)?(24-row):row-1;   
207                                   Int_t py=6*(tmp%8)+a2y[pad%6];
208                                   
209   return AliHMPIDParam::Abs(ch,pc,px,py);
210 }//GetPad()
211 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
212 void AliHMPIDRawStream::WriteRowMarker(AliFstream *ddl,UInt_t size)
213 {
214   //Writes the row marker for real data and pedestal into the ddl stream
215   //Arguments: ddl stream and the size of the block of the given row, the siye is at least the 10 EoE words!
216   //Returns:   nothing
217   UInt_t w32=0;
218   UInt_t marker=13992;                                   //for pedestal=12968  ==  32a8 for zero suppressed 36a8
219   AliBitPacking::PackWord(size,  w32, 16,31);            //number of roaw written after row marker (digits and EoE)
220   AliBitPacking::PackWord(marker,w32,0,15);              //the marker word
221   ddl->WriteBuffer((char*)&w32,sizeof(w32));              
222 }
223 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
224 void AliHMPIDRawStream::WriteEoE(AliFstream *ddl,UInt_t row,UInt_t dil,UInt_t wordCnt  )
225 {
226   //Writes the EoE word from real data and pedestals into the ddl stream
227   //Arguments:  ddl stream, row number, dilogic number and the number of words before the EoE
228   //Retursns:   nothing
229   UInt_t e=1;
230   UInt_t w32=0;
231   assert(1<=row&&row<=24);      AliBitPacking::PackWord((UInt_t)row     ,w32,22,26);    // row number (1...24)
232   assert(1<=dil&&dil<=10);      AliBitPacking::PackWord((UInt_t)dil     ,w32,18,21);    // DILOGIC number (1...10)
233                                 AliBitPacking::PackWord(          e     ,w32, 7,17);   // event number -- not used
234                                 AliBitPacking::PackWord((UInt_t)wordCnt ,w32, 0, 6);  // word counter (0...47)                                                                  AliBitPacking::PackWord((UInt_t)1       ,w32,27,27);  // bit 27 is always 1 by definition of EoE
235                                 AliBitPacking::PackWord((UInt_t)1       ,w32,27,27);  // bit 27 is always 1 by definition of EoE    
236   ddl->WriteBuffer((char*)&w32,sizeof(w32));      
237
238 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
239 void AliHMPIDRawStream::WriteSegMarker(AliFstream *ddl,UInt_t row, Int_t nwInSeg)
240 {
241   //Writes the segment marker (after 8 rows) into the ddl stream
242   //Arguments: ddl stream and the segment: row 8 -> 0x5800, row 16 -> 5801, row 24 -> 5802 for pedestal
243   //Retruns:   nothing
244     UInt_t w32=0;
245
246       //Segment marker: 2736 == ab0
247       //AliBitPacking::PackWord((UInt_t)0   ,w32,27,31);          //zero out the rest of the bits, since they are not needed
248       AliBitPacking::PackWord((UInt_t)2736   ,w32,20,31);       //ab0 the segment marker word
249       AliBitPacking::PackWord((UInt_t)nwInSeg,w32, 8,19);       //number of words in the segment
250       AliBitPacking::PackWord((UInt_t)(row/8),w32, 0, 7);       //segment 0,1,2    
251       ddl->WriteBuffer((char*)&w32,sizeof(w32)); 
252       //Printf("Segment word created is: %x",w32);
253 }      
254 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
255 Bool_t AliHMPIDRawStream::SetZeroSup (Bool_t isSup)
256 {
257   //Prevision to turn OFF zero suppression
258   //Arguments: setter
259   //Returns:   switch
260   fZeroSup=isSup;
261   return fZeroSup;
262 }
263 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
264 Bool_t AliHMPIDRawStream::GetZeroSup()
265 {
266   if(fZeroSup==kTRUE) return kTRUE;
267   else                return kFALSE;
268 }
269 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
270 void AliHMPIDRawStream::WriteRaw(TObjArray *pDigAll)
271 {
272 // Write a list of digits for a given chamber in raw data stream
273 // Arguments: pDigAll- list of digits 
274 //   Returns: none      
275   Int_t  ddl,r,d,a;            //32 bits data word 
276   Int_t  cntLpad,cntRpad;
277   Int_t  cntLrow,cntRrow;
278   Int_t  cntL=0,cntR=0;                           //data words counters for DDLs
279   Int_t  cntLeoe,cntReoe;
280   UInt_t posL,posR;
281   UInt_t cntLseg,cntRseg;
282   UInt_t cntwInLseg=0,cntwInRseg=0;
283   Int_t  cntRdig=0,cntLdig=0;
284   
285   UInt_t posLmarker,posRmarker;
286   Int_t digcnt=0;
287
288   Int_t isDigThere[14][25][11][48];
289   
290   for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){//chambers loop
291     cntL=0;cntR=0;   
292     for(Int_t iddl=0;iddl<14;iddl++){
293       for(Int_t irow=1;irow<=24;irow++){
294         for(Int_t idil=1;idil<=10;idil++){
295           for(Int_t ipad=0;ipad<48;ipad++){
296             isDigThere[iddl][irow][idil][ipad]=-1;
297           }
298         }
299       }
300     }
301     
302     AliFstream* ddlL;                                 //output streams, 2 per chamber
303     AliFstream* ddlR;                          
304     
305     AliRawDataHeaderSim header; header.SetAttribute(0);  //empty DDL header
306     
307     ddlL = new AliFstream(AliDAQ::DdlFileName("HMPID",2*iCh+1)); //left and right looking at the IP
308     ddlR = new AliFstream(AliDAQ::DdlFileName("HMPID",2*iCh));   //open both DDL of this chamber in parallel
309     
310     ddlL->WriteBuffer((char*)&header,sizeof(header));            //write dummy header as place holder, actual 
311     ddlR->WriteBuffer((char*)&header,sizeof(header));            //will be rewritten later when total size of DDL is known
312     
313     UInt_t w32=0;                 //32 bits data word 
314     digcnt=0;
315     
316     TClonesArray *pDigCh=(TClonesArray *)pDigAll->At(iCh); //list of digits for current chamber 
317    
318     for(Int_t iDig=0;iDig<pDigCh->GetEntriesFast();iDig++){//digits loop
319       AliHMPIDDigit *pDig1=(AliHMPIDDigit*)pDigCh->At(iDig);
320       pDig1->Raw(w32,ddl,r,d,a);
321       isDigThere[ddl][r][d][a]=iDig;
322     }  
323     
324     for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows; row++){ //AliHMPIDRawStream::kNRows=25!
325       cntRrow=0;cntLrow=0;cntLseg=0;cntRseg=0;// 
326       cntLeoe=0;cntReoe=0;
327       posLmarker=ddlL->Tellp(); WriteRowMarker(ddlL,(UInt_t)1);   cntL++; cntRrow++; cntwInRseg++;
328       posRmarker=ddlR->Tellp(); WriteRowMarker(ddlR,(UInt_t)1);   cntR++; cntLrow++; cntwInLseg++;
329       for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){ //AliHMPIDRawStream::kNDILOGICAdd = 11!
330         cntLpad=0;cntRpad=0;
331         for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){   //AliHMPIDRawStream::kNPadAdd     = 48
332           for ( Int_t iddl=2*iCh; iddl<=2*iCh+1;iddl++){
333             if (isDigThere[iddl][row][dil][pad]!=-1) {
334               AliHMPIDDigit *pDig=(AliHMPIDDigit*)pDigCh->At(isDigThere[iddl][row][dil][pad]);             
335               pDig->Raw(w32,ddl,r,d,a);  
336               if(pDig->Q() < 0 ) continue;                                                 //We can turn of the zero sup for pedestal simulation
337                 if(ddl%2){                                                                               //write raw digit selecting on DDL
338                 ddlL->WriteBuffer((char*)&w32,sizeof(w32));   cntL++; cntLpad++; cntLrow++;  cntLdig++; cntwInLseg++;//Printf(" WL: %x isDig: %d",w32,isDigThere[iddl][row][dil][pad]);
339               }else{
340                 ddlR->WriteBuffer((char*)&w32,sizeof(w32));   cntR++; cntRpad++; cntRrow++;   cntRdig++;cntwInRseg++;//Printf(" WR: %x isDig: %d",w32,isDigThere[iddl][row][dil][pad]);
341               }
342             }//ddl 
343           }//isDig
344         }//pad
345         WriteEoE(ddlL,row,dil,cntLpad); cntL++;  cntLrow++;    cntLeoe++;   cntwInLseg++;                              //molnarl: write EoE markers
346         WriteEoE(ddlR,row,dil,cntRpad); cntR++;  cntRrow++;    cntReoe++;   cntwInRseg++;
347       }//dil
348       if(row%8==0){                                               
349         WriteSegMarker(ddlL,row,cntwInLseg); cntL++;  cntLseg++; cntwInLseg=0;
350         WriteSegMarker(ddlR,row,cntwInRseg); cntR++;  cntRseg++;  cntwInRseg=0; 
351       }
352       posL=ddlL->Tellp();   ddlL->Seekp(posLmarker);    WriteRowMarker(ddlL,(UInt_t)(cntLrow-1)); ddlL->Seekp(posL);      //find the marker position write and  go back to the actual position to continue writing                    
353       posR=ddlR->Tellp();   ddlR->Seekp(posRmarker);    WriteRowMarker(ddlR,(UInt_t)(cntRrow-1)); ddlR->Seekp(posR);                           
354     }//row
355     header.fSize=sizeof(header)+cntL*sizeof(w32); ddlL->Seekp(0); ddlL->WriteBuffer((char*)&header,sizeof(header)); delete ddlL; //rewrite header with size set to
356     header.fSize=sizeof(header)+cntR*sizeof(w32); ddlR->Seekp(0); ddlR->WriteBuffer((char*)&header,sizeof(header)); delete ddlR; //number of bytes and close file
357     
358     //Printf("In Ch %d # digits written to LDD %d RDDL %d",iCh,cntLdig,cntRdig);
359     
360   }//chambers loop
361 }//WriteRaw()
362 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
363 Int_t AliHMPIDRawStream::GetErrors(Int_t ddl,Int_t eType)
364 {
365 // Return the number of errors for a given error tye during raw data reading
366 // Arguments: errorType
367 // Returns: error or -999 if error Type does not exist
368   
369   if(eType < 0 || eType> kSumErr ||  ddl < 0 || ddl > kNDDL-1 ) return -999;
370   else return fNumOfErr[ddl][eType];
371 } //GetErrors()     
372 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
373 Char_t* AliHMPIDRawStream::GetErrName(Int_t eType)
374 {
375   // Return the name of the error for a given error tye during raw data reading
376   // Arguments: errorType
377   // Returns: error or -999 if error Type does not exist
378   Char_t *eName[]={ "kRawDataSizeErr",  "kRowMarkerErr" , "kWrongRowErr" , "kWrongDilogicErr",
379                     "kWrongPadErr"   ,  "kEoEFlagErr"   , "kEoESizeErr"  , "kEoEDILOGICErr",
380                     "kEoERowErr"     ,  "kBadSegWordErr", "kWrongSegErr" , "kRowMarkerSizeErr",
381                     "kSumErr"        };                       
382   Char_t *eNoErr="NotDefinedErrorType";
383   if(eType<0 || eType>kSumErr) return eNoErr;
384   else                         return eName[eType];
385 }//GetErrName()
386 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
387     
388     
389     
390 #endif