1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 ***************************************************************************/
17 * author: Roberto Preghenella (R+), Roberto.Preghenella@bo.infn.it
20 //////////////////////////////////////////////////////////////////////
23 // This class provides the TOF FEE reader. //
26 //////////////////////////////////////////////////////////////////////
29 #include "AliTOFFEEReader.h"
30 #include "AliTOFFEEConfig.h"
31 #include "AliTOFFEElightConfig.h"
32 #include "AliTOFRawStream.h"
33 #include "AliTOFGeometry.h"
34 #include "AliTOFcalibHisto.h"
38 ClassImp(AliTOFFEEReader)
40 //_______________________________________________________________
42 AliTOFFEEReader::AliTOFFEEReader() :
44 fFEEConfig(new AliTOFFEEConfig()),
45 fFEElightConfig(new AliTOFFEElightConfig()),
59 //_______________________________________________________________
61 AliTOFFEEReader::AliTOFFEEReader(const AliTOFFEEReader &source) :
63 fFEEConfig(new AliTOFFEEConfig()),
64 fFEElightConfig(new AliTOFFEElightConfig())
72 memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
73 memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
76 //_______________________________________________________________
79 AliTOFFEEReader::operator=(const AliTOFFEEReader &source)
87 TObject::operator=(source);
88 memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
89 memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
93 //_______________________________________________________________
95 AliTOFFEEReader::~AliTOFFEEReader()
104 delete fFEElightConfig;
107 //_______________________________________________________________
110 AliTOFFEEReader::ResetChannelEnabledArray()
114 * reset channel enabled array
118 for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++)
119 fChannelEnabled[iIndex] = kFALSE;
122 //_______________________________________________________________
125 AliTOFFEEReader::Reset()
133 for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++) {
134 fChannelEnabled[iIndex] = kFALSE;
135 fMatchingWindow[iIndex] = 0;
136 fLatencyWindow[iIndex] = 0;
140 //_______________________________________________________________
143 AliTOFFEEReader::LoadFEEConfig(const Char_t *FileName) const
151 Char_t *expandedFileName = gSystem->ExpandPathName(FileName);
153 is.open(expandedFileName, std::ios::binary);
154 is.read((Char_t *)fFEEConfig, sizeof(AliTOFFEEConfig));
158 //_______________________________________________________________
161 AliTOFFEEReader::LoadFEElightConfig(const Char_t *FileName) const
165 * load FEElight config
169 Char_t *expandedFileName = gSystem->ExpandPathName(FileName);
171 is.open(expandedFileName, std::ios::binary);
172 is.read((Char_t *)fFEElightConfig, sizeof(AliTOFFEElightConfig));
176 //_______________________________________________________________
179 AliTOFFEEReader::ParseFEEConfig()
185 * loops over all FEE channels, checks whether they are enabled
186 * and sets channel enabled
190 AliInfo("parsing TOF FEE config");
192 AliTOFRawStream rawStream;
194 Int_t volume[5], index;
199 /* loop over all FEE channels */
200 for (Int_t iDDL = 0; iDDL < GetNumberOfDDLs(); iDDL++)
201 for (Int_t iTRM = 0; iTRM < GetNumberOfTRMs(); iTRM++)
202 for (Int_t iChain = 0; iChain < GetNumberOfChains(); iChain++)
203 for (Int_t iTDC = 0; iTDC < GetNumberOfTDCs(); iTDC++)
204 for (Int_t iChannel = 0; iChannel < GetNumberOfChannels(); iChannel++)
205 /* check whether FEE channel is enabled */
206 if (IsChannelEnabled(iDDL, iTRM + 3, iChain, iTDC, iChannel)) {
207 /* convert FEE channel indexes into detector indexes */
208 rawStream.EquipmentId2VolumeId(iDDL, iTRM + 3, iChain, iTDC, iChannel, volume);
209 /* swap padx and padz to fit AliTOFGeometry::GetIndex behaviour */
210 temp = volume[4]; volume[4] = volume[3]; volume[3] = temp;
211 /* check if index is ok */
212 if (volume[0] < 0 || volume[0] > 17 ||
213 volume[1] < 0 || volume[1] > 4 ||
214 volume[2] < 0 || volume[2] > 18 ||
215 volume[3] < 0 || volume[3] > 1 ||
216 volume[4] < 0 || volume[4] > 47)
218 /* convert detector indexes into calibration index */
219 index = AliTOFGeometry::GetIndex(volume);
220 /* check calibration index */
221 if (index != -1 && index < GetNumberOfIndexes()) {
222 /* set calibration channel enabled */
223 fChannelEnabled[index] = kTRUE;
224 fMatchingWindow[index] = GetMatchingWindow(iDDL, iTRM + 3, iChain, iTDC, iChannel);
231 //_______________________________________________________________
234 AliTOFFEEReader::ParseFEElightConfig()
238 * parse FEElight config
240 * loops over all FEE channels, checks whether they are enabled
241 * and sets channel enabled
245 AliInfo("parsing TOF FEElight config");
247 AliTOFcalibHisto calibHisto;
248 calibHisto.LoadCalibHisto();
250 Int_t nEnabled = 0, index;
251 AliTOFFEEchannelConfig *channelConfig = NULL;
252 for (Int_t i = 0; i < GetNumberOfIndexesEO(); i++) {
253 channelConfig = fFEElightConfig->GetChannelConfig(i);
254 if (!channelConfig->IsEnabled()) continue;
255 /* get index DO from index EO */
256 index = (Int_t)calibHisto.GetCalibMap(AliTOFcalibHisto::kIndex, i);
257 if (index == -1) continue;
259 fChannelEnabled[index] = channelConfig->IsEnabled();
260 fMatchingWindow[index] = channelConfig->GetMatchingWindow();
261 fLatencyWindow[index] = channelConfig->GetLatencyWindow();
267 //_______________________________________________________________
270 AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
276 * checks whether a FEE channel is enabled using the
277 * TOF FEE config object.
281 AliTOFFEEConfig *feeConfig;
282 AliTOFCrateConfig *crateConfig;
283 AliTOFTRMConfig *trmConfig;
284 Int_t maskPB, maskTDC, activeChip;
286 /* get and check fee config */
287 if (!(feeConfig = GetFEEConfig()))
290 /* get and check crate config */
291 if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
294 /* get and check TRM config */
295 if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
298 /* check DRM enabled */
299 if (!crateConfig->IsDRMEnabled())
302 /* check TRM enabled */
303 if (!crateConfig->IsTRMEnabled(iTRM - 3))
310 /* check chain enabled */
311 if (trmConfig->GetChainAFlag() != 1)
313 /* get active chip mask */
314 activeChip = trmConfig->GetActiveChipA();
317 case 0: case 1: case 2:
318 maskPB = trmConfig->GetMaskPB0();
320 case 3: case 4: case 5:
321 maskPB = trmConfig->GetMaskPB1();
323 case 6: case 7: case 8:
324 maskPB = trmConfig->GetMaskPB2();
326 case 9: case 10: case 11:
327 maskPB = trmConfig->GetMaskPB3();
329 case 12: case 13: case 14:
330 maskPB = trmConfig->GetMaskPB4();
339 /* check chain enabled */
340 if (trmConfig->GetChainBFlag() != 1)
342 /* get active chip mask */
343 activeChip = trmConfig->GetActiveChipB();
346 case 0: case 1: case 2:
347 maskPB = trmConfig->GetMaskPB5();
349 case 3: case 4: case 5:
350 maskPB = trmConfig->GetMaskPB6();
352 case 6: case 7: case 8:
353 maskPB = trmConfig->GetMaskPB7();
355 case 9: case 10: case 11:
356 maskPB = trmConfig->GetMaskPB8();
358 case 12: case 13: case 14:
359 maskPB = trmConfig->GetMaskPB9();
371 /* check chip enabled */
372 if (!(activeChip & (0x1 << iTDC)))
375 /* check channel enabled */
376 maskTDC = (maskPB & (0xFF << ((iTDC % 3) * 8))) >> ((iTDC % 3) * 8);
377 if (maskTDC & (0x1 << iChannel))
384 //_______________________________________________________________
387 AliTOFFEEReader::GetMatchingWindow(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
391 * get matching window
393 * checks whether a FEE channel is enabled using the
394 * TOF FEE config object and return the associated
399 AliTOFFEEConfig *feeConfig;
400 AliTOFCrateConfig *crateConfig;
401 AliTOFTRMConfig *trmConfig;
403 iChain = 0; iTDC = 0; iChannel = 0; /* dummy for the time being */
405 /* get and check fee config */
406 if (!(feeConfig = GetFEEConfig()))
409 /* get and check crate config */
410 if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
413 /* get and check TRM config */
414 if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
417 /* check DRM enabled */
418 if (!crateConfig->IsDRMEnabled())
421 /* check TRM enabled */
422 if (!crateConfig->IsTRMEnabled(iTRM - 3))
425 return trmConfig->GetMatchingWindow();
430 AliTOFFEEReader::DumpFEEConfig()
438 AliTOFFEEConfig *feeConfig = GetFEEConfig();
439 AliTOFCrateConfig *crateConfig;
440 AliTOFDRMConfig *drmConfig;
441 AliTOFLTMConfig *ltmConfig;
442 AliTOFTRMConfig *trmConfig;
444 AliInfo("-------------------------------------");
445 AliInfo("dumping TOF FEE config");
446 AliInfo("-------------------------------------");
447 AliInfo(Form("version: %d", feeConfig->GetVersion()));
448 AliInfo(Form("dump time: %d", feeConfig->GetDumpTime()));
449 AliInfo(Form("run number: %d", feeConfig->GetRunNumber()));
450 AliInfo(Form("run type: %d", feeConfig->GetRunType()));
451 AliInfo("-------------------------------------");
453 /* loop over crates */
454 for (Int_t iCrate = 0; iCrate < AliTOFFEEConfig::GetNumberOfCrates(); iCrate++) {
455 crateConfig = feeConfig->GetCrateConfig(iCrate);
457 /* check crate config */
461 /* check DRM enabled */
462 if (!crateConfig->IsDRMEnabled())
465 AliInfo(Form("crate id: %02d", iCrate));
467 /* dump DRM config */
468 drmConfig = crateConfig->GetDRMConfig();
469 AliInfo(Form("DRM is enabled: drmId=%d, slotMask=%03x", drmConfig->GetDRMId(), drmConfig->GetSlotMask()));
471 /* dump LTM config if enabled */
472 if (crateConfig->IsLTMEnabled()) {
473 ltmConfig = crateConfig->GetLTMConfig();
474 AliInfo(Form("LTM is enabled: threshold=%d", ltmConfig->GetThreshold()));
477 /* dump CPDM config if enabled */
478 if (crateConfig->IsCPDMEnabled()) {
479 AliInfo(Form("CPDM is enabled"));
483 for (Int_t iTRM = 0; iTRM < AliTOFCrateConfig::GetNumberOfTRMs(); iTRM++) {
485 trmConfig = crateConfig->GetTRMConfig(iTRM);
487 /* check TRM config */
491 /* check TRM enabled */
492 if (!crateConfig->IsTRMEnabled(iTRM))
495 /* dump TRM config */
496 AliInfo(Form("TRM%02d is enabled: matchWin=%d, latWin=%d, packFlag=%d", iTRM + 3, trmConfig->GetMatchingWindow(), trmConfig->GetLatencyWindow(), trmConfig->GetPackingFlag()));
498 /* check TRM chain A flag */
499 if (trmConfig->GetChainAFlag() == 1) {
500 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()));
503 /* check TRM chain B flag */
504 if (trmConfig->GetChainBFlag() == 1) {
505 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()));
510 } /* loop over TRMs */
511 AliInfo("-------------------------------------");
512 } /* loop over crates */
515 //_______________________________________________________________
518 AliTOFFEEReader::CreateFEElightConfig(const Char_t *filename)
522 * create FEElight config
526 AliTOFFEElightConfig lightConfig;
528 for (Int_t i = 0; i < GetNumberOfIndexes(); i++) {
529 if (fChannelEnabled[i]) {
530 lightConfig.GetChannelConfig(i)->SetStatus(AliTOFFEEchannelConfig::kStatusEnabled);
531 lightConfig.GetChannelConfig(i)->SetMatchingWindow(fMatchingWindow[i]);
532 lightConfig.GetChannelConfig(i)->SetLatencyWindow(fLatencyWindow[i]);
535 lightConfig.GetChannelConfig(i)->SetStatus(0x0);
536 lightConfig.GetChannelConfig(i)->SetMatchingWindow(0);
537 lightConfig.GetChannelConfig(i)->SetLatencyWindow(0);
541 Char_t *expandedFileName = gSystem->ExpandPathName(filename);
543 os.open(expandedFileName, std::ios::binary);
544 os.write((Char_t *)&lightConfig, sizeof(AliTOFFEElightConfig));