Changed class inheritance: from TObject to TTask
[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
72 memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
046dfc5f 73 memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
1605abc6 74}
75
76//_______________________________________________________________
77
78AliTOFFEEReader &
79AliTOFFEEReader::operator=(const AliTOFFEEReader &source)
80{
81 /*
82 *
83 * operator =
84 *
85 */
86
87 TObject::operator=(source);
88 memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
046dfc5f 89 memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
1605abc6 90 return *this;
91}
92
93//_______________________________________________________________
94
95AliTOFFEEReader::~AliTOFFEEReader()
96{
97 /*
98 *
99 * default destructor
100 *
101 */
102
103 delete fFEEConfig;
046dfc5f 104 delete fFEElightConfig;
1605abc6 105}
106
107//_______________________________________________________________
108
109void
110AliTOFFEEReader::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
124void
b059882a 125AliTOFFEEReader::Reset()
126{
127 /*
128 *
129 * reset
130 *
131 */
132
133 for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++) {
134 fChannelEnabled[iIndex] = kFALSE;
135 fMatchingWindow[iIndex] = 0;
046dfc5f 136 fLatencyWindow[iIndex] = 0;
b059882a 137 }
138}
139
140//_______________________________________________________________
141
142void
39dff6a4 143AliTOFFEEReader::LoadFEEConfig(const Char_t *FileName) const
1605abc6 144{
145 /*
146 *
147 * load FEE config
148 *
149 */
150
5b086af5 151 Char_t *expandedFileName = gSystem->ExpandPathName(FileName);
1605abc6 152 std::ifstream is;
5b086af5 153 is.open(expandedFileName, std::ios::binary);
1605abc6 154 is.read((Char_t *)fFEEConfig, sizeof(AliTOFFEEConfig));
155 is.close();
156}
157
158//_______________________________________________________________
159
046dfc5f 160void
161AliTOFFEEReader::LoadFEElightConfig(const Char_t *FileName) const
162{
163 /*
164 *
165 * load FEElight 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 *)fFEElightConfig, sizeof(AliTOFFEElightConfig));
173 is.close();
174}
175
176//_______________________________________________________________
177
1605abc6 178Int_t
179AliTOFFEEReader::ParseFEEConfig()
180{
181 /*
182 *
183 * parse FEE config
184 *
185 * loops over all FEE channels, checks whether they are enabled
186 * and sets channel enabled
187 *
188 */
189
046dfc5f 190 AliInfo("parsing TOF FEE config");
1605abc6 191
192 AliTOFRawStream rawStream;
193 Int_t nEnabled = 0;
194 Int_t volume[5], index;
195 Int_t temp;
196
b059882a 197 Reset();
1605abc6 198
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;
b059882a 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)
217 continue;
1605abc6 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;
b059882a 224 fMatchingWindow[index] = GetMatchingWindow(iDDL, iTRM + 3, iChain, iTDC, iChannel);
1605abc6 225 nEnabled++;
226 }
227 }
228 return nEnabled;
229}
230
231//_______________________________________________________________
232
046dfc5f 233Int_t
234AliTOFFEEReader::ParseFEElightConfig()
235{
236 /*
237 *
238 * parse FEElight config
239 *
240 * loops over all FEE channels, checks whether they are enabled
241 * and sets channel enabled
242 *
243 */
244
245 AliInfo("parsing TOF FEElight config");
246
99096b5f 247 AliTOFcalibHisto calibHisto;
248 calibHisto.LoadCalibHisto();
249
250 Int_t nEnabled = 0, index;
046dfc5f 251 AliTOFFEEchannelConfig *channelConfig = NULL;
99096b5f 252 for (Int_t i = 0; i < GetNumberOfIndexesEO(); i++) {
046dfc5f 253 channelConfig = fFEElightConfig->GetChannelConfig(i);
99096b5f 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;
258 nEnabled++;
259 fChannelEnabled[index] = channelConfig->IsEnabled();
260 fMatchingWindow[index] = channelConfig->GetMatchingWindow();
261 fLatencyWindow[index] = channelConfig->GetLatencyWindow();
046dfc5f 262 }
263
264 return nEnabled;
265}
266
267//_______________________________________________________________
268
1605abc6 269Bool_t
39dff6a4 270AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
1605abc6 271{
272 /*
273 *
274 * is channel enabled
275 *
276 * checks whether a FEE channel is enabled using the
277 * TOF FEE config object.
278 *
279 */
280
281 AliTOFFEEConfig *feeConfig;
282 AliTOFCrateConfig *crateConfig;
283 AliTOFTRMConfig *trmConfig;
71b82bd2 284 Int_t maskPB, maskTDC, activeChip;
1605abc6 285
286 /* get and check fee config */
287 if (!(feeConfig = GetFEEConfig()))
288 return kFALSE;
289
290 /* get and check crate config */
291 if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
292 return kFALSE;
293
294 /* get and check TRM config */
295 if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
296 return kFALSE;
297
298 /* check DRM enabled */
299 if (!crateConfig->IsDRMEnabled())
300 return kFALSE;
301
302 /* check TRM enabled */
303 if (!crateConfig->IsTRMEnabled(iTRM - 3))
304 return kFALSE;
305
306 /* switch chain */
307 switch (iChain) {
308 /* chain A */
309 case 0:
310 /* check chain enabled */
311 if (trmConfig->GetChainAFlag() != 1)
312 return kFALSE;
71b82bd2 313 /* get active chip mask */
314 activeChip = trmConfig->GetActiveChipA();
1605abc6 315 /* switch TDC */
316 switch (iTDC) {
317 case 0: case 1: case 2:
318 maskPB = trmConfig->GetMaskPB0();
319 break;
320 case 3: case 4: case 5:
321 maskPB = trmConfig->GetMaskPB1();
322 break;
323 case 6: case 7: case 8:
324 maskPB = trmConfig->GetMaskPB2();
325 break;
326 case 9: case 10: case 11:
327 maskPB = trmConfig->GetMaskPB3();
328 break;
329 case 12: case 13: case 14:
330 maskPB = trmConfig->GetMaskPB4();
331 break;
332 default:
333 return kFALSE;
334 break;
335 } /* switch TDC */
336 break; /* chain A */
337 /* chain B */
338 case 1:
339 /* check chain enabled */
340 if (trmConfig->GetChainBFlag() != 1)
341 return kFALSE;
71b82bd2 342 /* get active chip mask */
343 activeChip = trmConfig->GetActiveChipB();
1605abc6 344 /* switch TDC */
345 switch (iTDC) {
346 case 0: case 1: case 2:
347 maskPB = trmConfig->GetMaskPB5();
348 break;
349 case 3: case 4: case 5:
350 maskPB = trmConfig->GetMaskPB6();
351 break;
352 case 6: case 7: case 8:
353 maskPB = trmConfig->GetMaskPB7();
354 break;
355 case 9: case 10: case 11:
356 maskPB = trmConfig->GetMaskPB8();
357 break;
358 case 12: case 13: case 14:
359 maskPB = trmConfig->GetMaskPB9();
360 break;
361 default:
362 return kFALSE;
363 break;
364 } /* switch TDC */
365 break; /* chain B */
366 default:
367 return kFALSE;
368 break;
369 } /* switch chain */
370
71b82bd2 371 /* check chip enabled */
372 if (!(activeChip & (0x1 << iTDC)))
373 return kFALSE;
374
1605abc6 375 /* check channel enabled */
376 maskTDC = (maskPB & (0xFF << ((iTDC % 3) * 8))) >> ((iTDC % 3) * 8);
377 if (maskTDC & (0x1 << iChannel))
378 return kTRUE;
379 else
380 return kFALSE;
381
382}
383
b059882a 384//_______________________________________________________________
385
386Int_t
387AliTOFFEEReader::GetMatchingWindow(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
388{
389 /*
390 *
391 * get matching window
392 *
393 * checks whether a FEE channel is enabled using the
394 * TOF FEE config object and return the associated
395 * matching window
396 *
397 */
bf1a5fa6 398
b059882a 399 AliTOFFEEConfig *feeConfig;
400 AliTOFCrateConfig *crateConfig;
401 AliTOFTRMConfig *trmConfig;
bf1a5fa6 402
403 iChain = 0; iTDC = 0; iChannel = 0; /* dummy for the time being */
b059882a 404
405 /* get and check fee config */
406 if (!(feeConfig = GetFEEConfig()))
407 return 0;
408
409 /* get and check crate config */
410 if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
411 return 0;
412
413 /* get and check TRM config */
414 if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
415 return 0;
416
417 /* check DRM enabled */
418 if (!crateConfig->IsDRMEnabled())
419 return 0;
420
421 /* check TRM enabled */
422 if (!crateConfig->IsTRMEnabled(iTRM - 3))
423 return 0;
424
425 return trmConfig->GetMatchingWindow();
426}
427
1605abc6 428
429void
430AliTOFFEEReader::DumpFEEConfig()
431{
432 /*
433 *
434 * dump FEE config
435 *
436 */
437
438 AliTOFFEEConfig *feeConfig = GetFEEConfig();
439 AliTOFCrateConfig *crateConfig;
440 AliTOFDRMConfig *drmConfig;
441 AliTOFLTMConfig *ltmConfig;
442 AliTOFTRMConfig *trmConfig;
443
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("-------------------------------------");
452
453 /* loop over crates */
454 for (Int_t iCrate = 0; iCrate < AliTOFFEEConfig::GetNumberOfCrates(); iCrate++) {
455 crateConfig = feeConfig->GetCrateConfig(iCrate);
456
457 /* check crate config */
458 if (!crateConfig)
459 continue;
460
461 /* check DRM enabled */
462 if (!crateConfig->IsDRMEnabled())
463 continue;
464
465 AliInfo(Form("crate id: %02d", iCrate));
466
467 /* dump DRM config */
468 drmConfig = crateConfig->GetDRMConfig();
469 AliInfo(Form("DRM is enabled: drmId=%d, slotMask=%03x", drmConfig->GetDRMId(), drmConfig->GetSlotMask()));
470
471 /* dump LTM config if enabled */
472 if (crateConfig->IsLTMEnabled()) {
473 ltmConfig = crateConfig->GetLTMConfig();
474 AliInfo(Form("LTM is enabled: threshold=%d", ltmConfig->GetThreshold()));
475 }
476
477 /* dump CPDM config if enabled */
478 if (crateConfig->IsCPDMEnabled()) {
479 AliInfo(Form("CPDM is enabled"));
480 }
481
482 /* loop over TRMs */
483 for (Int_t iTRM = 0; iTRM < AliTOFCrateConfig::GetNumberOfTRMs(); iTRM++) {
484
485 trmConfig = crateConfig->GetTRMConfig(iTRM);
486
487 /* check TRM config */
488 if (!trmConfig)
489 continue;
490
491 /* check TRM enabled */
492 if (!crateConfig->IsTRMEnabled(iTRM))
493 continue;
494
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()));
497
498 /* check TRM chain A flag */
499 if (trmConfig->GetChainAFlag() == 1) {
71b82bd2 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()));
1605abc6 501 }
502
503 /* check TRM chain B flag */
504 if (trmConfig->GetChainBFlag() == 1) {
71b82bd2 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()));
1605abc6 506 }
507
508
509
510 } /* loop over TRMs */
511 AliInfo("-------------------------------------");
512 } /* loop over crates */
513}
514
046dfc5f 515//_______________________________________________________________
516
517void
518AliTOFFEEReader::CreateFEElightConfig(const Char_t *filename)
519{
520 /*
521 *
522 * create FEElight config
523 *
524 */
525
526 AliTOFFEElightConfig lightConfig;
527
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]);
533 }
534 else {
535 lightConfig.GetChannelConfig(i)->SetStatus(0x0);
536 lightConfig.GetChannelConfig(i)->SetMatchingWindow(0);
537 lightConfig.GetChannelConfig(i)->SetLatencyWindow(0);
538 }
539 }
540
541 Char_t *expandedFileName = gSystem->ExpandPathName(filename);
542 std::ofstream os;
543 os.open(expandedFileName, std::ios::binary);
544 os.write((Char_t *)&lightConfig, sizeof(AliTOFFEElightConfig));
545 os.close();
546
547}