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