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())
73 memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
74 memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
77 //_______________________________________________________________
80 AliTOFFEEReader::operator=(const AliTOFFEEReader &source)
88 TObject::operator=(source);
89 memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
90 memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
94 //_______________________________________________________________
96 AliTOFFEEReader::~AliTOFFEEReader()
105 delete fFEElightConfig;
108 //_______________________________________________________________
111 AliTOFFEEReader::ResetChannelEnabledArray()
115 * reset channel enabled array
119 for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++)
120 fChannelEnabled[iIndex] = kFALSE;
123 //_______________________________________________________________
126 AliTOFFEEReader::ResetTriggerMaskArray()
130 * reset trigger mask array
134 for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++)
135 fTriggerMask[iddl] = 0x0;
138 //_______________________________________________________________
141 AliTOFFEEReader::Reset()
149 for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++) {
150 fChannelEnabled[iIndex] = kFALSE;
151 fMatchingWindow[iIndex] = 0;
152 fLatencyWindow[iIndex] = 0;
155 for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++)
156 fTriggerMask[iddl] = 0x0;
159 //_______________________________________________________________
162 AliTOFFEEReader::LoadFEEConfig(const Char_t *FileName) const
170 Char_t *expandedFileName = gSystem->ExpandPathName(FileName);
172 is.open(expandedFileName, std::ios::binary);
173 is.read((Char_t *)fFEEConfig, sizeof(AliTOFFEEConfig));
177 //_______________________________________________________________
180 AliTOFFEEReader::LoadFEElightConfig(const Char_t *FileName) const
184 * load FEElight config
188 Char_t *expandedFileName = gSystem->ExpandPathName(FileName);
190 is.open(expandedFileName, std::ios::binary);
191 is.read((Char_t *)fFEElightConfig, sizeof(AliTOFFEElightConfig));
195 //_______________________________________________________________
198 AliTOFFEEReader::ParseFEEConfig()
204 * loops over all FEE channels, checks whether they are enabled
205 * and sets channel enabled
209 AliInfo("parsing TOF FEE config");
211 AliTOFRawStream rawStream;
213 Int_t volume[5], index;
218 /* loop over all FEE channels */
219 for (Int_t iDDL = 0; iDDL < GetNumberOfDDLs(); iDDL++)
220 for (Int_t iTRM = 0; iTRM < GetNumberOfTRMs(); iTRM++)
221 for (Int_t iChain = 0; iChain < GetNumberOfChains(); iChain++)
222 for (Int_t iTDC = 0; iTDC < GetNumberOfTDCs(); iTDC++)
223 for (Int_t iChannel = 0; iChannel < GetNumberOfChannels(); iChannel++)
224 /* check whether FEE channel is enabled */
225 if (IsChannelEnabled(iDDL, iTRM + 3, iChain, iTDC, iChannel)) {
226 /* convert FEE channel indexes into detector indexes */
227 rawStream.EquipmentId2VolumeId(iDDL, iTRM + 3, iChain, iTDC, iChannel, volume);
228 /* swap padx and padz to fit AliTOFGeometry::GetIndex behaviour */
229 temp = volume[4]; volume[4] = volume[3]; volume[3] = temp;
230 /* check if index is ok */
231 if (volume[0] < 0 || volume[0] > 17 ||
232 volume[1] < 0 || volume[1] > 4 ||
233 volume[2] < 0 || volume[2] > 18 ||
234 volume[3] < 0 || volume[3] > 1 ||
235 volume[4] < 0 || volume[4] > 47)
237 /* convert detector indexes into calibration index */
238 index = AliTOFGeometry::GetIndex(volume);
239 /* check calibration index */
240 if (index != -1 && index < GetNumberOfIndexes()) {
241 /* set calibration channel enabled */
242 fChannelEnabled[index] = kTRUE;
243 fMatchingWindow[index] = GetMatchingWindow(iDDL, iTRM + 3, iChain, iTDC, iChannel);
250 //_______________________________________________________________
253 AliTOFFEEReader::ParseFEElightConfig()
257 * parse FEElight config
259 * loops over all FEE channels, checks whether they are enabled
260 * and sets channel enabled
264 AliInfo("parsing TOF FEElight config");
268 AliTOFcalibHisto calibHisto;
269 calibHisto.LoadCalibHisto();
271 Int_t nEnabled = 0, index;
272 AliTOFFEEchannelConfig *channelConfig = NULL;
273 for (Int_t i = 0; i < GetNumberOfIndexesEO(); i++) {
274 channelConfig = fFEElightConfig->GetChannelConfig(i);
275 if (!channelConfig->IsEnabled()) continue;
276 /* get index DO from index EO */
277 index = (Int_t)calibHisto.GetCalibMap(AliTOFcalibHisto::kIndex, i);
278 if (index == -1) continue;
280 fChannelEnabled[index] = channelConfig->IsEnabled();
281 fMatchingWindow[index] = channelConfig->GetMatchingWindow();
282 fLatencyWindow[index] = channelConfig->GetLatencyWindow();
285 AliTOFFEEtriggerConfig *triggerConfig = NULL;
286 for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++) {
287 triggerConfig = fFEElightConfig->GetTriggerConfig(iddl);
288 fTriggerMask[iddl] = triggerConfig->GetStatusMap();
294 //_______________________________________________________________
297 AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
303 * checks whether a FEE channel is enabled using the
304 * TOF FEE config object.
308 AliTOFFEEConfig *feeConfig;
309 AliTOFCrateConfig *crateConfig;
310 AliTOFTRMConfig *trmConfig;
311 Int_t maskPB, maskTDC, activeChip;
313 /* get and check fee config */
314 if (!(feeConfig = GetFEEConfig()))
317 /* get and check crate config */
318 if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
321 /* get and check TRM config */
322 if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
325 /* check DRM enabled */
326 if (!crateConfig->IsDRMEnabled())
329 /* check TRM enabled */
330 if (!crateConfig->IsTRMEnabled(iTRM - 3))
337 /* check chain enabled */
338 if (trmConfig->GetChainAFlag() != 1)
340 /* get active chip mask */
341 activeChip = trmConfig->GetActiveChipA();
344 case 0: case 1: case 2:
345 maskPB = trmConfig->GetMaskPB0();
347 case 3: case 4: case 5:
348 maskPB = trmConfig->GetMaskPB1();
350 case 6: case 7: case 8:
351 maskPB = trmConfig->GetMaskPB2();
353 case 9: case 10: case 11:
354 maskPB = trmConfig->GetMaskPB3();
356 case 12: case 13: case 14:
357 maskPB = trmConfig->GetMaskPB4();
366 /* check chain enabled */
367 if (trmConfig->GetChainBFlag() != 1)
369 /* get active chip mask */
370 activeChip = trmConfig->GetActiveChipB();
373 case 0: case 1: case 2:
374 maskPB = trmConfig->GetMaskPB5();
376 case 3: case 4: case 5:
377 maskPB = trmConfig->GetMaskPB6();
379 case 6: case 7: case 8:
380 maskPB = trmConfig->GetMaskPB7();
382 case 9: case 10: case 11:
383 maskPB = trmConfig->GetMaskPB8();
385 case 12: case 13: case 14:
386 maskPB = trmConfig->GetMaskPB9();
398 /* check chip enabled */
399 if (!(activeChip & (0x1 << iTDC)))
402 /* check channel enabled */
403 maskTDC = (maskPB & (0xFF << ((iTDC % 3) * 8))) >> ((iTDC % 3) * 8);
404 if (maskTDC & (0x1 << iChannel))
411 //_______________________________________________________________
414 AliTOFFEEReader::GetMatchingWindow(Int_t iDDL, Int_t iTRM, Int_t, Int_t, Int_t) const
418 * get matching window
420 * checks whether a FEE channel is enabled using the
421 * TOF FEE config object and return the associated
426 AliTOFFEEConfig *feeConfig;
427 AliTOFCrateConfig *crateConfig;
428 AliTOFTRMConfig *trmConfig;
430 /* get and check fee config */
431 if (!(feeConfig = GetFEEConfig()))
434 /* get and check crate config */
435 if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
438 /* get and check TRM config */
439 if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
442 /* check DRM enabled */
443 if (!crateConfig->IsDRMEnabled())
446 /* check TRM enabled */
447 if (!crateConfig->IsTRMEnabled(iTRM - 3))
450 return trmConfig->GetMatchingWindow();
455 AliTOFFEEReader::DumpFEEConfig()
463 AliTOFFEEConfig *feeConfig = GetFEEConfig();
464 AliTOFCrateConfig *crateConfig;
465 AliTOFDRMConfig *drmConfig;
466 AliTOFLTMConfig *ltmConfig;
467 AliTOFTRMConfig *trmConfig;
469 AliInfo("-------------------------------------");
470 AliInfo("dumping TOF FEE config");
471 AliInfo("-------------------------------------");
472 AliInfo(Form("version: %d", feeConfig->GetVersion()));
473 AliInfo(Form("dump time: %d", (Int_t)feeConfig->GetDumpTime()));
474 AliInfo(Form("run number: %d", feeConfig->GetRunNumber()));
475 AliInfo(Form("run type: %d", feeConfig->GetRunType()));
476 AliInfo("-------------------------------------");
478 /* loop over crates */
479 for (Int_t iCrate = 0; iCrate < AliTOFFEEConfig::GetNumberOfCrates(); iCrate++) {
480 crateConfig = feeConfig->GetCrateConfig(iCrate);
482 /* check crate config */
486 /* check DRM enabled */
487 if (!crateConfig->IsDRMEnabled())
490 AliInfo(Form("crate id: %02d", iCrate));
492 /* dump DRM config */
493 drmConfig = crateConfig->GetDRMConfig();
494 AliInfo(Form("DRM is enabled: drmId=%d, slotMask=%03x", drmConfig->GetDRMId(), drmConfig->GetSlotMask()));
496 /* dump LTM config if enabled */
497 if (crateConfig->IsLTMEnabled()) {
498 ltmConfig = crateConfig->GetLTMConfig();
499 AliInfo(Form("LTM is enabled: threshold=%d", ltmConfig->GetThreshold()));
502 /* dump CPDM config if enabled */
503 if (crateConfig->IsCPDMEnabled()) {
504 AliInfo(Form("CPDM is enabled"));
508 for (Int_t iTRM = 0; iTRM < AliTOFCrateConfig::GetNumberOfTRMs(); iTRM++) {
510 trmConfig = crateConfig->GetTRMConfig(iTRM);
512 /* check TRM config */
516 /* check TRM enabled */
517 if (!crateConfig->IsTRMEnabled(iTRM))
520 /* dump TRM config */
521 AliInfo(Form("TRM%02d is enabled: matchWin=%d, latWin=%d, packFlag=%d", iTRM + 3, trmConfig->GetMatchingWindow(), trmConfig->GetLatencyWindow(), trmConfig->GetPackingFlag()));
523 /* check TRM chain A flag */
524 if (trmConfig->GetChainAFlag() == 1) {
525 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()));
528 /* check TRM chain B flag */
529 if (trmConfig->GetChainBFlag() == 1) {
530 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()));
535 } /* loop over TRMs */
536 AliInfo("-------------------------------------");
537 } /* loop over crates */
540 //_______________________________________________________________
543 AliTOFFEEReader::CreateFEElightConfig(const Char_t *filename)
547 * create FEElight config
551 AliTOFFEElightConfig lightConfig;
553 for (Int_t i = 0; i < GetNumberOfIndexes(); i++) {
554 if (fChannelEnabled[i]) {
555 lightConfig.GetChannelConfig(i)->SetStatus(AliTOFFEEchannelConfig::kStatusEnabled);
556 lightConfig.GetChannelConfig(i)->SetMatchingWindow(fMatchingWindow[i]);
557 lightConfig.GetChannelConfig(i)->SetLatencyWindow(fLatencyWindow[i]);
560 lightConfig.GetChannelConfig(i)->SetStatus(0x0);
561 lightConfig.GetChannelConfig(i)->SetMatchingWindow(0);
562 lightConfig.GetChannelConfig(i)->SetLatencyWindow(0);
566 Char_t *expandedFileName = gSystem->ExpandPathName(filename);
568 os.open(expandedFileName, std::ios::binary);
569 os.write((Char_t *)&lightConfig, sizeof(AliTOFFEElightConfig));