]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFFEEReader.cxx
Coverity fixes.
[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 <TSystem.h>
29 #include "AliTOFFEEReader.h"
30 #include "AliTOFFEEConfig.h"
31 #include "AliTOFFEElightConfig.h"
32 #include "AliTOFRawStream.h"
33 #include "AliTOFGeometry.h"
34 #include "AliTOFcalibHisto.h"
35 #include "AliLog.h"
36 #include <fstream>
37
38 ClassImp(AliTOFFEEReader)
39
40 //_______________________________________________________________
41
42 AliTOFFEEReader::AliTOFFEEReader() :
43   TObject(),
44   fFEEConfig(new AliTOFFEEConfig()),
45   fFEElightConfig(new AliTOFFEElightConfig()),
46   fChannelEnabled(),
47   fMatchingWindow(),
48   fLatencyWindow()
49 {
50   /* 
51    * 
52    * default constructor 
53    *
54    */
55
56   Reset();
57 }
58
59 //_______________________________________________________________
60
61 AliTOFFEEReader::AliTOFFEEReader(const AliTOFFEEReader &source) :
62   TObject(source),
63   fFEEConfig(new AliTOFFEEConfig()),
64   fFEElightConfig(new AliTOFFEElightConfig())
65 {
66   /* 
67    * 
68    * copy constructor 
69    *
70    */
71
72   memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
73   memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
74 }
75
76 //_______________________________________________________________
77
78 AliTOFFEEReader &
79 AliTOFFEEReader::operator=(const AliTOFFEEReader &source)
80 {
81   /* 
82    * 
83    * operator = 
84    * 
85    */
86
87   TObject::operator=(source);
88   memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
89   memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
90   return *this;
91 }
92
93 //_______________________________________________________________
94
95 AliTOFFEEReader::~AliTOFFEEReader()
96 {
97   /* 
98    *
99    * default destructor 
100    *
101    */
102
103   delete fFEEConfig;
104   delete fFEElightConfig;
105 }
106
107 //_______________________________________________________________
108
109 void
110 AliTOFFEEReader::ResetChannelEnabledArray()
111 {
112   /*
113    *
114    * reset channel enabled array
115    *
116    */
117
118   for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++)
119     fChannelEnabled[iIndex] = kFALSE;
120 }
121
122 //_______________________________________________________________
123
124 void
125 AliTOFFEEReader::ResetTriggerMaskArray()
126 {
127   /*
128    *
129    * reset trigger mask array
130    *
131    */
132
133   for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++)
134     fTriggerMask[iddl] = 0x0;
135 }
136
137 //_______________________________________________________________
138
139 void
140 AliTOFFEEReader::Reset()
141 {
142   /*
143    *
144    * reset 
145    *
146    */
147
148   for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++) {
149     fChannelEnabled[iIndex] = kFALSE;
150     fMatchingWindow[iIndex] = 0;
151     fLatencyWindow[iIndex] = 0;
152   }
153
154   for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++)
155     fTriggerMask[iddl] = 0x0;
156 }
157
158 //_______________________________________________________________
159
160 void
161 AliTOFFEEReader::LoadFEEConfig(const Char_t *FileName) const
162 {
163   /*
164    *
165    * load FEE config
166    *
167    */
168
169   Char_t *expandedFileName = gSystem->ExpandPathName(FileName);
170   std::ifstream is;
171   is.open(expandedFileName, std::ios::binary);
172   is.read((Char_t *)fFEEConfig, sizeof(AliTOFFEEConfig));
173   is.close();
174 }
175
176 //_______________________________________________________________
177
178 void
179 AliTOFFEEReader::LoadFEElightConfig(const Char_t *FileName) const
180 {
181   /*
182    *
183    * load FEElight config
184    *
185    */
186
187   Char_t *expandedFileName = gSystem->ExpandPathName(FileName);
188   std::ifstream is;
189   is.open(expandedFileName, std::ios::binary);
190   is.read((Char_t *)fFEElightConfig, sizeof(AliTOFFEElightConfig));
191   is.close();
192 }
193
194 //_______________________________________________________________
195
196 Int_t
197 AliTOFFEEReader::ParseFEEConfig()
198 {
199   /* 
200    *
201    * parse FEE config
202    *
203    * loops over all FEE channels, checks whether they are enabled
204    * and sets channel enabled 
205    *
206    */
207
208   AliInfo("parsing TOF FEE config");
209
210   AliTOFRawStream rawStream;
211   Int_t nEnabled = 0;
212   Int_t volume[5], index;
213   Int_t temp;
214
215   Reset();
216
217   /* loop over all FEE channels */
218   for (Int_t iDDL = 0; iDDL < GetNumberOfDDLs(); iDDL++)
219     for (Int_t iTRM = 0; iTRM < GetNumberOfTRMs(); iTRM++)
220       for (Int_t iChain = 0; iChain < GetNumberOfChains(); iChain++)
221         for (Int_t iTDC = 0; iTDC < GetNumberOfTDCs(); iTDC++)
222           for (Int_t iChannel = 0; iChannel < GetNumberOfChannels(); iChannel++)
223             /* check whether FEE channel is enabled */
224             if (IsChannelEnabled(iDDL, iTRM + 3, iChain, iTDC, iChannel)) {
225               /* convert FEE channel indexes into detector indexes */
226               rawStream.EquipmentId2VolumeId(iDDL, iTRM + 3, iChain, iTDC, iChannel, volume);
227               /* swap padx and padz to fit AliTOFGeometry::GetIndex behaviour */
228               temp = volume[4]; volume[4] = volume[3]; volume[3] = temp; 
229               /* check if index is ok */
230               if (volume[0] < 0 || volume[0] > 17 ||
231                   volume[1] < 0 || volume[1] > 4 ||
232                   volume[2] < 0 || volume[2] > 18 ||
233                   volume[3] < 0 || volume[3] > 1 ||
234                   volume[4] < 0 || volume[4] > 47)
235                 continue;
236               /* convert detector indexes into calibration index */
237               index = AliTOFGeometry::GetIndex(volume);
238               /* check calibration index */
239               if (index != -1 && index < GetNumberOfIndexes()) {
240                 /* set calibration channel enabled */
241                 fChannelEnabled[index] = kTRUE;
242                 fMatchingWindow[index] = GetMatchingWindow(iDDL, iTRM + 3, iChain, iTDC, iChannel);
243                 nEnabled++;
244               }
245             }
246   return nEnabled;
247 }
248
249 //_______________________________________________________________
250
251 Int_t
252 AliTOFFEEReader::ParseFEElightConfig()
253 {
254   /* 
255    *
256    * parse FEElight config
257    *
258    * loops over all FEE channels, checks whether they are enabled
259    * and sets channel enabled 
260    *
261    */
262
263   AliInfo("parsing TOF FEElight config");
264
265   Reset();
266
267   AliTOFcalibHisto calibHisto;
268   calibHisto.LoadCalibHisto();
269
270   Int_t nEnabled = 0, index;
271   AliTOFFEEchannelConfig *channelConfig = NULL;
272   for (Int_t i = 0; i < GetNumberOfIndexesEO(); i++) {
273     channelConfig = fFEElightConfig->GetChannelConfig(i);
274     if (!channelConfig->IsEnabled()) continue;
275     /* get index DO from index EO */
276     index = (Int_t)calibHisto.GetCalibMap(AliTOFcalibHisto::kIndex, i);
277     if (index == -1) continue;
278     nEnabled++;
279     fChannelEnabled[index] = channelConfig->IsEnabled();
280     fMatchingWindow[index] = channelConfig->GetMatchingWindow();
281     fLatencyWindow[index] = channelConfig->GetLatencyWindow();
282   }
283
284   AliTOFFEEtriggerConfig *triggerConfig = NULL;
285   for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++) {
286     triggerConfig = fFEElightConfig->GetTriggerConfig(iddl);
287     fTriggerMask[iddl] = triggerConfig->GetStatusMap();
288   }
289  
290   return nEnabled;
291 }
292
293 //_______________________________________________________________
294
295 Bool_t 
296 AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
297 {
298   /*
299    *
300    * is channel enabled
301    *
302    * checks whether a FEE channel is enabled using the
303    * TOF FEE config object.
304    *
305    */
306
307   AliTOFFEEConfig *feeConfig;
308   AliTOFCrateConfig *crateConfig;
309   AliTOFTRMConfig *trmConfig;
310   Int_t maskPB, maskTDC, activeChip;
311   
312   /* get and check fee config */
313   if (!(feeConfig = GetFEEConfig()))
314     return kFALSE;
315   
316   /* get and check crate config */
317   if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
318     return kFALSE;
319   
320   /* get and check TRM config */
321   if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
322     return kFALSE;
323
324   /* check DRM enabled */
325   if (!crateConfig->IsDRMEnabled())
326     return kFALSE;
327
328   /* check TRM enabled */
329   if (!crateConfig->IsTRMEnabled(iTRM - 3))
330     return kFALSE;
331
332   /* switch chain */
333   switch (iChain) {
334     /* chain A */
335   case 0:
336     /* check chain enabled */
337     if (trmConfig->GetChainAFlag() != 1)
338       return kFALSE;
339     /* get active chip mask */
340     activeChip = trmConfig->GetActiveChipA();
341     /* switch TDC */
342     switch (iTDC) {
343     case 0: case 1: case 2:
344       maskPB = trmConfig->GetMaskPB0();
345       break;
346     case 3: case 4: case 5:
347       maskPB = trmConfig->GetMaskPB1();
348       break;
349     case 6: case 7: case 8:
350       maskPB = trmConfig->GetMaskPB2();
351       break;
352     case 9: case 10: case 11:
353       maskPB = trmConfig->GetMaskPB3();
354       break;
355     case 12: case 13: case 14:
356       maskPB = trmConfig->GetMaskPB4();
357       break;
358     default:
359       return kFALSE;
360       break;  
361     } /* switch TDC */
362     break; /* chain A */
363     /* chain B */
364   case 1:
365     /* check chain enabled */
366     if (trmConfig->GetChainBFlag() != 1)
367       return kFALSE;
368     /* get active chip mask */
369     activeChip = trmConfig->GetActiveChipB();
370     /* switch TDC */
371     switch (iTDC) {
372     case 0: case 1: case 2:
373       maskPB = trmConfig->GetMaskPB5();
374       break;
375     case 3: case 4: case 5:
376       maskPB = trmConfig->GetMaskPB6();
377       break;
378     case 6: case 7: case 8:
379       maskPB = trmConfig->GetMaskPB7();
380       break;
381     case 9: case 10: case 11:
382       maskPB = trmConfig->GetMaskPB8();
383       break;
384     case 12: case 13: case 14:
385       maskPB = trmConfig->GetMaskPB9();
386       break;
387     default:
388       return kFALSE;
389       break;  
390     } /* switch TDC */
391     break; /* chain B */
392   default:
393     return kFALSE;
394     break;
395   } /* switch chain */
396
397   /* check chip enabled */
398   if (!(activeChip & (0x1 << iTDC)))
399     return kFALSE;
400
401   /* check channel enabled */
402   maskTDC = (maskPB & (0xFF << ((iTDC % 3) * 8))) >> ((iTDC % 3) * 8);
403   if (maskTDC & (0x1 << iChannel))
404     return kTRUE;
405   else
406     return kFALSE;
407   
408 }
409
410 //_______________________________________________________________
411
412 Int_t 
413 AliTOFFEEReader::GetMatchingWindow(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
414 {
415   /*
416    *
417    * get matching window
418    *
419    * checks whether a FEE channel is enabled using the
420    * TOF FEE config object and return the associated
421    * matching window
422    *
423    */
424   
425   AliTOFFEEConfig *feeConfig;
426   AliTOFCrateConfig *crateConfig;
427   AliTOFTRMConfig *trmConfig;
428
429   iChain = 0; iTDC = 0; iChannel = 0; /* dummy for the time being */
430   
431   /* get and check fee config */
432   if (!(feeConfig = GetFEEConfig()))
433     return 0;
434   
435   /* get and check crate config */
436   if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
437     return 0;
438   
439   /* get and check TRM config */
440   if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
441     return 0;
442
443   /* check DRM enabled */
444   if (!crateConfig->IsDRMEnabled())
445     return 0;
446
447   /* check TRM enabled */
448   if (!crateConfig->IsTRMEnabled(iTRM - 3))
449     return 0;
450
451   return trmConfig->GetMatchingWindow();
452 }
453
454
455 void
456 AliTOFFEEReader::DumpFEEConfig()
457 {
458   /*
459    * 
460    * dump FEE config
461    *
462    */
463
464   AliTOFFEEConfig *feeConfig = GetFEEConfig();
465   AliTOFCrateConfig *crateConfig;
466   AliTOFDRMConfig *drmConfig;
467   AliTOFLTMConfig *ltmConfig;
468   AliTOFTRMConfig *trmConfig;
469
470   AliInfo("-------------------------------------");
471   AliInfo("dumping TOF FEE config");
472   AliInfo("-------------------------------------");
473   AliInfo(Form("version: %d", feeConfig->GetVersion()));
474   AliInfo(Form("dump time: %d", (Int_t)feeConfig->GetDumpTime()));
475   AliInfo(Form("run number: %d", feeConfig->GetRunNumber()));
476   AliInfo(Form("run type: %d", feeConfig->GetRunType()));
477   AliInfo("-------------------------------------");
478   
479   /* loop over crates */
480   for (Int_t iCrate = 0; iCrate < AliTOFFEEConfig::GetNumberOfCrates(); iCrate++) {
481     crateConfig = feeConfig->GetCrateConfig(iCrate);
482     
483     /* check crate config */
484     if (!crateConfig)
485       continue;
486     
487     /* check DRM enabled */
488     if (!crateConfig->IsDRMEnabled())
489     continue;
490
491     AliInfo(Form("crate id: %02d", iCrate));
492
493     /* dump DRM config */
494     drmConfig = crateConfig->GetDRMConfig();
495     AliInfo(Form("DRM is enabled: drmId=%d, slotMask=%03x", drmConfig->GetDRMId(), drmConfig->GetSlotMask()));
496
497     /* dump LTM config if enabled */
498     if (crateConfig->IsLTMEnabled()) {
499       ltmConfig = crateConfig->GetLTMConfig();
500       AliInfo(Form("LTM is enabled: threshold=%d", ltmConfig->GetThreshold()));
501     }
502     
503     /* dump CPDM config if enabled */
504     if (crateConfig->IsCPDMEnabled()) {
505       AliInfo(Form("CPDM is enabled"));
506     }
507     
508     /* loop over TRMs */
509     for (Int_t iTRM = 0; iTRM < AliTOFCrateConfig::GetNumberOfTRMs(); iTRM++) {
510
511       trmConfig = crateConfig->GetTRMConfig(iTRM);
512
513       /* check TRM config */
514       if (!trmConfig)
515         continue;
516       
517       /* check TRM enabled */
518       if (!crateConfig->IsTRMEnabled(iTRM))
519         continue;
520
521       /* dump TRM config */
522       AliInfo(Form("TRM%02d is enabled: matchWin=%d, latWin=%d, packFlag=%d", iTRM + 3, trmConfig->GetMatchingWindow(), trmConfig->GetLatencyWindow(), trmConfig->GetPackingFlag()));
523       
524       /* check TRM chain A flag */
525       if (trmConfig->GetChainAFlag() == 1) {
526         AliInfo(Form("TRM%02d chainA is enabled: activeChip=%04X, PB0=%06X, PB1=%06X, PB2=%06X, PB3=%06X, PB4=%06X", iTRM + 3, trmConfig->GetActiveChipA(), trmConfig->GetMaskPB0(), trmConfig->GetMaskPB1(), trmConfig->GetMaskPB2(), trmConfig->GetMaskPB3(), trmConfig->GetMaskPB4()));
527       }
528
529       /* check TRM chain B flag */
530       if (trmConfig->GetChainBFlag() == 1) {
531         AliInfo(Form("TRM%02d chainB is enabled: activeChip=%04X, PB5=%06X, PB6=%06X, PB7=%06X, PB8=%06X, PB9=%06X", iTRM + 3, trmConfig->GetActiveChipB(), trmConfig->GetMaskPB5(), trmConfig->GetMaskPB6(), trmConfig->GetMaskPB7(), trmConfig->GetMaskPB8(), trmConfig->GetMaskPB9()));
532       }
533       
534
535       
536     } /* loop over TRMs */
537     AliInfo("-------------------------------------");
538   } /* loop over crates */
539 }
540
541 //_______________________________________________________________
542
543 void
544 AliTOFFEEReader::CreateFEElightConfig(const Char_t *filename)
545 {
546   /*
547    *
548    * create FEElight config 
549    *
550    */
551
552   AliTOFFEElightConfig lightConfig;
553
554   for (Int_t i = 0; i < GetNumberOfIndexes(); i++) {
555     if (fChannelEnabled[i]) {
556       lightConfig.GetChannelConfig(i)->SetStatus(AliTOFFEEchannelConfig::kStatusEnabled);
557       lightConfig.GetChannelConfig(i)->SetMatchingWindow(fMatchingWindow[i]);
558       lightConfig.GetChannelConfig(i)->SetLatencyWindow(fLatencyWindow[i]);
559     }
560     else {
561       lightConfig.GetChannelConfig(i)->SetStatus(0x0);
562       lightConfig.GetChannelConfig(i)->SetMatchingWindow(0);
563       lightConfig.GetChannelConfig(i)->SetLatencyWindow(0);
564     }
565   }
566
567   Char_t *expandedFileName = gSystem->ExpandPathName(filename);
568   std::ofstream os;
569   os.open(expandedFileName, std::ios::binary);
570   os.write((Char_t *)&lightConfig, sizeof(AliTOFFEElightConfig));
571   os.close();
572   
573 }