]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFFEEReader.cxx
0825d6b9a77c0e93b59ad2f0beb6d4ee007eb4ea
[u/mrichter/AliRoot.git] / TOF / AliTOFFEEReader.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  * author: Roberto Preghenella (R+), Roberto.Preghenella@bo.infn.it
18  */
19
20 //////////////////////////////////////////////////////////////////////
21 //                                                                  //
22 //                                                                  //
23 //   This class provides the TOF FEE reader.                        //
24 //                                                                  //
25 //                                                                  //
26 //////////////////////////////////////////////////////////////////////
27
28 #include "AliTOFFEEReader.h"
29 #include "AliTOFFEEConfig.h"
30 #include "AliTOFRawStream.h"
31 #include "AliTOFGeometry.h"
32 #include "AliLog.h"
33 #include <fstream>
34
35 ClassImp(AliTOFFEEReader)
36
37 //_______________________________________________________________
38
39 AliTOFFEEReader::AliTOFFEEReader() :
40   TObject(),
41   fFEEConfig(new AliTOFFEEConfig()),
42   fChannelEnabled()
43 {
44   /* 
45    * 
46    * default constructor 
47    *
48    */
49
50 }
51
52 //_______________________________________________________________
53
54 AliTOFFEEReader::AliTOFFEEReader(const AliTOFFEEReader &source) :
55   TObject(source),
56   fFEEConfig(new AliTOFFEEConfig())
57 {
58   /* 
59    * 
60    * copy constructor 
61    *
62    */
63
64   memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
65 }
66
67 //_______________________________________________________________
68
69 AliTOFFEEReader &
70 AliTOFFEEReader::operator=(const AliTOFFEEReader &source)
71 {
72   /* 
73    * 
74    * operator = 
75    * 
76    */
77
78   TObject::operator=(source);
79   memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
80   return *this;
81 }
82
83 //_______________________________________________________________
84
85 AliTOFFEEReader::~AliTOFFEEReader()
86 {
87   /* 
88    *
89    * default destructor 
90    *
91    */
92
93   delete fFEEConfig;
94 }
95
96 //_______________________________________________________________
97
98 void
99 AliTOFFEEReader::ResetChannelEnabledArray()
100 {
101   /*
102    *
103    * reset channel enabled array
104    *
105    */
106
107   for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++)
108     fChannelEnabled[iIndex] = kFALSE;
109 }
110
111 //_______________________________________________________________
112
113 void
114 AliTOFFEEReader::LoadFEEConfig(const Char_t *FileName) const
115 {
116   /*
117    *
118    * load FEE config
119    *
120    */
121
122   std::ifstream is;
123   is.open(FileName, std::ios::binary);
124   is.read((Char_t *)fFEEConfig, sizeof(AliTOFFEEConfig));
125   is.close();
126 }
127
128 //_______________________________________________________________
129
130 Int_t
131 AliTOFFEEReader::ParseFEEConfig()
132 {
133   /* 
134    *
135    * parse FEE config
136    *
137    * loops over all FEE channels, checks whether they are enabled
138    * and sets channel enabled 
139    *
140    */
141
142   AliInfo("parsing TOF FEE config")
143
144   AliTOFRawStream rawStream;
145   Int_t nEnabled = 0;
146   Int_t volume[5], index;
147   Int_t temp;
148
149   ResetChannelEnabledArray();
150
151   /* loop over all FEE channels */
152   for (Int_t iDDL = 0; iDDL < GetNumberOfDDLs(); iDDL++)
153     for (Int_t iTRM = 0; iTRM < GetNumberOfTRMs(); iTRM++)
154       for (Int_t iChain = 0; iChain < GetNumberOfChains(); iChain++)
155         for (Int_t iTDC = 0; iTDC < GetNumberOfTDCs(); iTDC++)
156           for (Int_t iChannel = 0; iChannel < GetNumberOfChannels(); iChannel++)
157             /* check whether FEE channel is enabled */
158             if (IsChannelEnabled(iDDL, iTRM + 3, iChain, iTDC, iChannel)) {
159               /* convert FEE channel indexes into detector indexes */
160               rawStream.EquipmentId2VolumeId(iDDL, iTRM + 3, iChain, iTDC, iChannel, volume);
161               /* swap padx and padz to fit AliTOFGeometry::GetIndex behaviour */
162               temp = volume[4]; volume[4] = volume[3]; volume[3] = temp; 
163               /* convert detector indexes into calibration index */
164               index = AliTOFGeometry::GetIndex(volume);
165               /* check calibration index */
166               if (index != -1 && index < GetNumberOfIndexes()) {
167                 /* set calibration channel enabled */
168                 fChannelEnabled[index] = kTRUE;
169                 nEnabled++;
170               }
171             }
172   return nEnabled;
173 }
174
175 //_______________________________________________________________
176
177 Bool_t 
178 AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
179 {
180   /*
181    *
182    * is channel enabled
183    *
184    * checks whether a FEE channel is enabled using the
185    * TOF FEE config object.
186    *
187    */
188
189   AliTOFFEEConfig *feeConfig;
190   AliTOFCrateConfig *crateConfig;
191   AliTOFTRMConfig *trmConfig;
192   Int_t maskPB, maskTDC;
193   
194   /* get and check fee config */
195   if (!(feeConfig = GetFEEConfig()))
196     return kFALSE;
197   
198   /* get and check crate config */
199   if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
200     return kFALSE;
201   
202   /* get and check TRM config */
203   if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
204     return kFALSE;
205
206   /* check DRM enabled */
207   if (!crateConfig->IsDRMEnabled())
208     return kFALSE;
209
210   /* check TRM enabled */
211   if (!crateConfig->IsTRMEnabled(iTRM - 3))
212     return kFALSE;
213
214   /* switch chain */
215   switch (iChain) {
216     /* chain A */
217   case 0:
218     /* check chain enabled */
219     if (trmConfig->GetChainAFlag() != 1)
220       return kFALSE;
221     /* switch TDC */
222     switch (iTDC) {
223     case 0: case 1: case 2:
224       maskPB = trmConfig->GetMaskPB0();
225       break;
226     case 3: case 4: case 5:
227       maskPB = trmConfig->GetMaskPB1();
228       break;
229     case 6: case 7: case 8:
230       maskPB = trmConfig->GetMaskPB2();
231       break;
232     case 9: case 10: case 11:
233       maskPB = trmConfig->GetMaskPB3();
234       break;
235     case 12: case 13: case 14:
236       maskPB = trmConfig->GetMaskPB4();
237       break;
238     default:
239       return kFALSE;
240       break;  
241     } /* switch TDC */
242     break; /* chain A */
243     /* chain B */
244   case 1:
245     /* check chain enabled */
246     if (trmConfig->GetChainBFlag() != 1)
247       return kFALSE;
248     /* switch TDC */
249     switch (iTDC) {
250     case 0: case 1: case 2:
251       maskPB = trmConfig->GetMaskPB5();
252       break;
253     case 3: case 4: case 5:
254       maskPB = trmConfig->GetMaskPB6();
255       break;
256     case 6: case 7: case 8:
257       maskPB = trmConfig->GetMaskPB7();
258       break;
259     case 9: case 10: case 11:
260       maskPB = trmConfig->GetMaskPB8();
261       break;
262     case 12: case 13: case 14:
263       maskPB = trmConfig->GetMaskPB9();
264       break;
265     default:
266       return kFALSE;
267       break;  
268     } /* switch TDC */
269     break; /* chain B */
270   default:
271     return kFALSE;
272     break;
273   } /* switch chain */
274
275   /* check channel enabled */
276   maskTDC = (maskPB & (0xFF << ((iTDC % 3) * 8))) >> ((iTDC % 3) * 8);
277   if (maskTDC & (0x1 << iChannel))
278     return kTRUE;
279   else
280     return kFALSE;
281   
282 }
283
284
285 void
286 AliTOFFEEReader::DumpFEEConfig()
287 {
288   /*
289    * 
290    * dump FEE config
291    *
292    */
293
294   AliTOFFEEConfig *feeConfig = GetFEEConfig();
295   AliTOFCrateConfig *crateConfig;
296   AliTOFDRMConfig *drmConfig;
297   AliTOFLTMConfig *ltmConfig;
298   AliTOFTRMConfig *trmConfig;
299
300   AliInfo("-------------------------------------");
301   AliInfo("dumping TOF FEE config");
302   AliInfo("-------------------------------------");
303   AliInfo(Form("version: %d", feeConfig->GetVersion()));
304   AliInfo(Form("dump time: %d", feeConfig->GetDumpTime()));
305   AliInfo(Form("run number: %d", feeConfig->GetRunNumber()));
306   AliInfo(Form("run type: %d", feeConfig->GetRunType()));
307   AliInfo("-------------------------------------");
308   
309   /* loop over crates */
310   for (Int_t iCrate = 0; iCrate < AliTOFFEEConfig::GetNumberOfCrates(); iCrate++) {
311     crateConfig = feeConfig->GetCrateConfig(iCrate);
312     
313     /* check crate config */
314     if (!crateConfig)
315       continue;
316     
317     /* check DRM enabled */
318     if (!crateConfig->IsDRMEnabled())
319     continue;
320
321     AliInfo(Form("crate id: %02d", iCrate));
322
323     /* dump DRM config */
324     drmConfig = crateConfig->GetDRMConfig();
325     AliInfo(Form("DRM is enabled: drmId=%d, slotMask=%03x", drmConfig->GetDRMId(), drmConfig->GetSlotMask()));
326
327     /* dump LTM config if enabled */
328     if (crateConfig->IsLTMEnabled()) {
329       ltmConfig = crateConfig->GetLTMConfig();
330       AliInfo(Form("LTM is enabled: threshold=%d", ltmConfig->GetThreshold()));
331     }
332     
333     /* dump CPDM config if enabled */
334     if (crateConfig->IsCPDMEnabled()) {
335       AliInfo(Form("CPDM is enabled"));
336     }
337     
338     /* loop over TRMs */
339     for (Int_t iTRM = 0; iTRM < AliTOFCrateConfig::GetNumberOfTRMs(); iTRM++) {
340
341       trmConfig = crateConfig->GetTRMConfig(iTRM);
342
343       /* check TRM config */
344       if (!trmConfig)
345         continue;
346       
347       /* check TRM enabled */
348       if (!crateConfig->IsTRMEnabled(iTRM))
349         continue;
350
351       /* dump TRM config */
352       AliInfo(Form("TRM%02d is enabled: matchWin=%d, latWin=%d, packFlag=%d", iTRM + 3, trmConfig->GetMatchingWindow(), trmConfig->GetLatencyWindow(), trmConfig->GetPackingFlag()));
353       
354       /* check TRM chain A flag */
355       if (trmConfig->GetChainAFlag() == 1) {
356         AliInfo(Form("TRM%02d chainA is enabled: PB0=%06X, PB1=%06X, PB2=%06X, PB3=%06X, PB4=%06X", iTRM + 3, trmConfig->GetMaskPB0(), trmConfig->GetMaskPB1(), trmConfig->GetMaskPB2(), trmConfig->GetMaskPB3(), trmConfig->GetMaskPB4()));
357       }
358
359       /* check TRM chain B flag */
360       if (trmConfig->GetChainBFlag() == 1) {
361         AliInfo(Form("TRM%02d chainB is enabled: PB5=%06X, PB6=%06X, PB7=%06X, PB8=%06X, PB9=%06X", iTRM + 3, trmConfig->GetMaskPB5(), trmConfig->GetMaskPB6(), trmConfig->GetMaskPB7(), trmConfig->GetMaskPB8(), trmConfig->GetMaskPB9()));
362       }
363       
364
365       
366     } /* loop over TRMs */
367     AliInfo("-------------------------------------");
368   } /* loop over crates */
369 }
370