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