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