]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFD.cxx
Re-correct Makefile for RuleChecker
[u/mrichter/AliRoot.git] / TOF / AliTOFD.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 /*
17 $Log$
18 Revision 1.1  2000/05/10 16:52:18  vicinanz
19 New TOF version with holes for PHOS/RICH
20
21 */
22
23 #include "AliTOF.h"
24 #include "AliTOFD.h"
25 #include "TObject.h"
26
27 //******************************************************************************
28
29 ClassImp(AliTOFRawDigit)
30
31 //______________________________________________________________________________
32 AliTOFRawDigit::AliTOFRawDigit()
33 //
34 // Constructor of AliTOFRawDigit class
35 //
36 {
37   fTreeD     = 0;
38   fRawDigits = 0;
39 }
40
41 //******************************************************************************
42
43 ClassImp(AliTOFRoc)
44
45 //______________________________________________________________________________
46 AliTOFRoc::AliTOFRoc()
47 //
48 // Constructor of AliTOFRoc class
49 // The class represents a ROC in the TARODA system
50 //
51 {
52   Items = 0;
53   Size  = 0;
54 }
55
56 //______________________________________________________________________________
57 AliTOFRoc::~AliTOFRoc(){}
58
59 //______________________________________________________________________________
60 Int_t AliTOFRoc::AddItem(Int_t Fec, Int_t Tdc, Int_t Error,
61                          Float_t Charge, Float_t Time)
62 //
63 // Adds an item (i.e. the charge, the TOF and the 
64 // cohordinates of a hit pad) to the ROC class.
65 //
66 {
67    Items++;
68    SetCharge(Items,Fec,Tdc,Charge);
69    SetTime  (Items,Error,Time);
70    return Items;   
71 }
72
73 //______________________________________________________________________________
74 void AliTOFRoc::SetHeader()
75 //
76 // Calculate the header line of the ROC in the raw data file
77 //
78 {
79    Header  = NRoc<<28;
80    Header += Size;
81 }
82
83
84 //______________________________________________________________________________
85 void AliTOFRoc::SetTime(UInt_t Item, UInt_t Error, Float_t RealTime)
86 //
87 // Calculate the raw data line relative to the TDC
88 // output of a pad in the current ROC.
89 //
90 {
91    UInt_t Itime;
92    Itime = (UInt_t)(RealTime/50.);
93    if (Itime >= TMath::Power(2,24)) Itime = 2^24-1;
94    Error <<= 24;
95    TimeRow[Item]= Error+Itime;
96 }
97
98 //______________________________________________________________________________
99 void AliTOFRoc::SetCharge(UInt_t Item, UInt_t Fec, UInt_t Tdc, Float_t RealCharge)
100 //
101 // Calculate the raw data line relative to the ADC 
102 // output of a pad in the current ROC.
103 //
104 {
105    UInt_t ICharge;
106    if (NRoc>=TMath::Power(2,4)) NRoc = 0;
107    NRoc <<= 28;
108    if (Fec >=TMath::Power(2,6))  Fec = 0;
109    Fec  <<= 22;
110    if (Tdc >=TMath::Power(2,6))  Tdc = 0;
111    Tdc  <<= 16;
112    ICharge = (UInt_t)(RealCharge/50.);
113    if(ICharge>=TMath::Power(2,16)) ICharge = (UInt_t)TMath::Power(2,16)-1;
114    ChrgRow[Item] = ICharge+NRoc+Fec+Tdc;
115 }
116
117 //______________________________________________________________________________
118 void AliTOFRoc::SetTime(UInt_t Item, UInt_t tir)
119 //
120 // Writes the raw data line relative to the TDC
121 //
122 {
123    ChrgRow[Item]=tir;
124 }
125
126 //______________________________________________________________________________
127 void AliTOFRoc::SetCharge(UInt_t Item, UInt_t chr)
128 //
129 // Writes the raw data line relative to the ADC
130 //
131 {
132    ChrgRow[Item]=chr;
133 }
134
135 //______________________________________________________________________________
136 Float_t AliTOFRoc::GetCharge(Int_t Item)
137 //
138 // Reads the effective value of the charge starting
139 // from the line of the raw data
140 //
141 {
142    UInt_t  Charge  = ChrgRow[Item]&0x0000ffff;
143    Float_t ACharge = (Float_t)Charge*50.;
144    return ACharge;
145 }
146
147 //______________________________________________________________________________
148 Float_t AliTOFRoc::GetTime(Int_t Item, UInt_t& Error)
149 //
150 // Reads the effective value of the time of flight starting
151 // from the line of the raw data
152 //
153 {
154    UInt_t  Time  = TimeRow[Item]&0x00ffffff;
155    Float_t ATime = (Float_t)Time*50.;
156    Error = TimeRow[Item]>>24;
157    return ATime; 
158 }
159
160 //______________________________________________________________________________
161 Int_t AliTOFRoc::GetTotPad(Int_t Item)
162 //
163 // Reads the cohordinates of the pad starting
164 // from the line of the raw data
165 //
166 {
167    UInt_t NRoc = (ChrgRow[Item]&0xf0000000)>>28;
168    UInt_t NFec = (ChrgRow[Item]&0x0fc00000)>>22;
169    UInt_t NTdc = (ChrgRow[Item]&0x003f0000)>>16;
170    UInt_t Pad = NRoc*32*32+NFec*32+NTdc;
171    return Pad; 
172 }
173
174 //______________________________________________________________________________
175 UInt_t AliTOFRoc::GetCheckSum()
176 //
177 // Calculate the checksum word of the current ROC
178 // 
179 {
180    UInt_t CheckSum=0;
181    for(Int_t i=0; i<Items; i++){
182       CheckSum += BitCount(GetChrgRow(i));
183       CheckSum += BitCount(GetTimeRow(i));
184    }
185    return CheckSum;
186 }
187
188 //______________________________________________________________________________
189 UInt_t AliTOFRoc::BitCount(UInt_t x)
190 //
191 // Count the "1" bit in the current word
192 //
193 {
194    UInt_t count=0;
195    for (count=0; x!=0; x>>=1){
196       if(x&0x00000001) count++;
197    }
198    return count;
199 }
200
201 //______________________________________________________________________________
202 UInt_t AliTOFRoc::SetSize()
203 //
204 // Reads the size of data from current ROC starting
205 // from the header line of the raw data
206 //
207 {
208    Size = Header&0x0000ffff;
209    Items = (Size-4)/4;
210    return Size;
211 }
212
213
214 //******************************************************************************
215
216 ClassImp(AliTOFRawSector)
217
218 //______________________________________________________________________________
219 AliTOFRawSector::AliTOFRawSector()
220 //
221 // Constructor of AliTOFRawSector class
222 // Each sector is in effect a 
223 // TClonesArray of 14 AliTOFRoc Objects
224 //
225 {
226    fRocData = new TClonesArray("AliTOFRoc",14);   
227 }
228
229 //______________________________________________________________________________
230 AliTOFRawSector::~AliTOFRawSector()
231 {
232    delete fRocData;
233 }
234
235 //______________________________________________________________________________
236 void AliTOFRawSector::WriteSector()
237 //
238 // Starting from the raw data objects writes a binary file
239 // similar to real raw data.
240 //
241 {
242     FILE *rawfile;
243     rawfile = fopen("rawdata.dat","w");
244     
245 //    fprintf(rawfile,Header);
246     
247     Int_t nRoc;
248     
249     for(nRoc=1; nRoc<=14; nRoc++){
250        AliTOFRoc* currentRoc = (AliTOFRoc*)fRocData->UncheckedAt(nRoc);
251        currentRoc->SetHeader();
252        UInt_t RocHeader = currentRoc->Header;
253 //      fprintf(rawfile,RocHeader);
254     }
255     
256     for(nRoc=1; nRoc<=14; nRoc++){
257        AliTOFRoc* currentRoc = (AliTOFRoc*)fRocData->UncheckedAt(nRoc);
258        Int_t rocItems = currentRoc->Items;
259
260        for(Int_t nItem=1; nItem<=rocItems;nItem++){
261           UInt_t TimeRow = currentRoc->GetTimeRow(nItem);
262 //          fprintf(rawfile,TimeRow);
263           UInt_t ChrgRow = currentRoc->GetTimeRow(nItem);
264 //          fprintf(rawfile,ChrgRow);
265        }
266     }
267     
268     UInt_t EndOfSector = GlobalCheckSum;
269 //    fprintf(rawfile,EndOfSector);
270 }
271
272 //______________________________________________________________________________
273 void AliTOFRawSector::ReadSector()
274 //
275 // Starting from raw data initialize and write the 
276 // Raw Data objects 
277 //(i.e. a TClonesArray of 18 AliTOFRawSector)
278 //
279 {
280     FILE *rawfile;
281     rawfile = fopen("rawdata.dat","r");
282     
283 //    fscanf(rawfile,Header);
284     Int_t nRoc;
285     
286     for(nRoc=1; nRoc<=14; nRoc++){
287        AliTOFRoc* currentRoc = (AliTOFRoc*)fRocData->UncheckedAt(nRoc);
288        UInt_t RocHeader;
289  //      fscanf(rawfile,RocHeader);
290        currentRoc->SetHeader(RocHeader);
291     }
292     
293     UInt_t SCMWord;
294 //    fscanf(rawfile,SCMWord);
295     
296     for(nRoc=1; nRoc<=14; nRoc++){
297        AliTOFRoc* currentRoc = (AliTOFRoc*)fRocData->UncheckedAt(nRoc);
298        Int_t Size = currentRoc->SetSize();
299        Int_t nItems = currentRoc->Items;
300        for(Int_t nrow=0; nrow<=nItems; nrow++){
301           UInt_t charRow,timeRow;
302 //        fscanf(rawfile, charRow);
303           currentRoc->SetTime(nrow, charRow);
304 //         fscanf(rawfile, timeRow);
305           currentRoc->SetTime(nrow, timeRow);
306        }
307        Int_t FinalWord;
308 //       fscanf(rawfile,FinalWord);              
309     }
310 //    fscanf(rawfile,GlobalCheckSum);
311 }
312