]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSCompressRawDataSDD.cxx
Move to little endian byte order in SDD compressed raw data format (F.Prino)
[u/mrichter/AliRoot.git] / ITS / AliITSCompressRawDataSDD.cxx
1 /**************************************************************************
2  * Copyright(c) 2007-2009, 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 // Class to decode the SDD Raw Data from the CarlosRX format to  //
21 // a compressed format consisting in a word of 32 bit per cell   //
22 // The 32 bits for a data word are defined as follows:           //
23 //   31 control bit (0=data word, 1= control word)               //
24 //   30 -                                                        //
25 //   29  |                                                       //
26 //   28  |-> 4 bits to identify the Carlos (0-11) inside the DDL //
27 //   27 -                                                        //
28 //   26 detecot side (0= left, =right)                           //
29 //   25 -                                                        //
30 //   24  |                                                       //
31 //   23  |                                                       //
32 //   22  |                                                       //
33 //   21  |-> 8 bits to identify the anode number (0-255)         //
34 //   20  |                                                       //
35 //   19  |                                                       //
36 //   18 -                                                        //
37 //   17 -                                                        //
38 //   16  |                                                       //
39 //   15  |                                                       //
40 //   14  |                                                       //
41 //   13  |-> 8 bits to identify the time bin (0-255)             //
42 //   12  |                                                       //
43 //   11  |                                                       //
44 //   10 -                                                        //
45 //    9 -                                                        //
46 //    8  |                                                       //
47 //    7  |                                                       //
48 //    6  |                                                       //
49 //    5  |                                                       //
50 //    4  |-> 10 bit for the ADC counts                           //
51 //    3  |                                                       //
52 //    2  |                                                       //
53 //    1  |                                                       //
54 //    0 -                                                        //
55 //                                                               //
56 // Plus 1 type of control words:                                 //
57 // - End of module data (needed by the Cluster Finder)           //
58 //       first 4 most significant bits                   = 1111  //
59 //                                                               //
60 // Origin: F.Prino, Torino, prino@to.infn.it                     //
61 //                                                               //
62 ///////////////////////////////////////////////////////////////////
63
64 #include"AliLog.h"
65 #include "AliITSCompressRawDataSDD.h"
66 #include "AliRawReader.h"
67 #include "AliRawReaderDate.h"
68 #include "AliRawReaderRoot.h"
69 #include "AliITSRawStreamSDD.h"
70
71
72 ClassImp(AliITSCompressRawDataSDD)
73
74 AliITSCompressRawDataSDD::AliITSCompressRawDataSDD():
75 TObject(),
76 fRawReader(0),
77 fPointerToData(0),
78 fSizeInMemory(0),
79 fEventRange(kFALSE),
80 fFirstEvent(0),
81 fLastEvent(0)
82 {
83   // default constructor
84   fNameFile="";
85 }
86 //______________________________________________________________________
87 AliITSCompressRawDataSDD::AliITSCompressRawDataSDD(TString filename):
88 TObject(),
89 fRawReader(0),
90 fPointerToData(0),
91 fSizeInMemory(0),
92 fEventRange(kFALSE),
93 fFirstEvent(0),
94 fLastEvent(0)
95 {
96   // Contructor for tests
97   fNameFile=filename;
98 }
99 //______________________________________________________________________
100 AliITSCompressRawDataSDD::~AliITSCompressRawDataSDD(){
101   // raw reader is passed from outdside, don't delete it
102 }
103
104 //______________________________________________________________________
105 void AliITSCompressRawDataSDD::Compress(){
106   // Test method to dump raw data on ascii file
107   Int_t iev=0;
108   if(fEventRange) iev=fFirstEvent;
109
110   AliRawReader* rd;
111   if(fNameFile.Contains(".root")){
112     rd=new AliRawReaderRoot(fNameFile.Data(),iev);
113   }else{
114     rd=new AliRawReaderDate(fNameFile.Data(),iev);
115   }
116   
117   FILE *outtxt=fopen("data.txt","w");
118
119   UInt_t word=0;
120   do{
121     rd->Reset();
122
123     AliITSRawStreamSDD s(rd);
124     s.SetDecompressAmbra(kFALSE);
125     while(s.Next()){
126       if(s.IsCompletedModule()==kFALSE){
127         word=s.GetCarlosId()<<27;
128         word+=s.GetChannel()<<26;
129         word+=s.GetCoord1()<<18;
130         word+=s.GetCoord2()<<10;
131         word+=s.GetEightBitSignal();
132         fprintf(outtxt,"%08X\n",word);
133       }
134       if(s.IsCompletedModule()==kTRUE){
135         word=15<<28;
136         word+=s.GetCarlosId();
137         fprintf(outtxt,"%08X\n",word);
138       }
139     }
140     iev++;
141     if(fEventRange && iev>fLastEvent) break;
142   }while(rd->NextEvent());
143   fclose(outtxt);
144 }
145 //______________________________________________________________________
146 UInt_t AliITSCompressRawDataSDD::CompressEvent(UChar_t* inputPtr){
147   // Method to be used in HLT
148   UInt_t siz=0;
149   memcpy(fPointerToData,inputPtr,32); // event header, 8 words
150   fPointerToData+=32;
151   siz+=32;
152   UInt_t word=0;
153   AliITSRawStreamSDD s(fRawReader);
154   s.SetDecompressAmbra(kFALSE);
155   Int_t mask1=0xFF000000;
156   Int_t mask2=0x00FF0000;
157   Int_t mask3=0x0000FF00;
158   Int_t mask4=0x000000FF;
159   while(s.Next()){
160     if(s.IsCompletedModule()==kFALSE){
161       word=s.GetCarlosId()<<27;
162       word+=s.GetChannel()<<26;
163       word+=s.GetCoord1()<<18;
164       word+=s.GetCoord2()<<10;
165       word+=s.GetEightBitSignal();
166       if(siz+4<fSizeInMemory){
167         *(fPointerToData)=(word&mask4);
168         ++fPointerToData;
169         *(fPointerToData)=(word&mask3)>>8;
170         ++fPointerToData;
171         *(fPointerToData)=(word&mask2)>>16;
172         ++fPointerToData;
173         *(fPointerToData)=(word&mask1)>>24;
174         ++fPointerToData;
175         siz+=4;
176       }
177     }
178     if(s.IsCompletedModule()==kTRUE){
179       word=15<<28;
180       word+=s.GetCarlosId();
181       if(siz+4<fSizeInMemory){
182         *(fPointerToData)=(word&mask4);
183         ++fPointerToData;
184         *(fPointerToData)=(word&mask3)>>8;
185         ++fPointerToData;
186         *(fPointerToData)=(word&mask2)>>16;
187         ++fPointerToData;
188         *(fPointerToData)=(word&mask1)>>24;
189         ++fPointerToData;
190         siz+=4;
191       }
192     }
193   }
194   return siz;
195 }