add un-use functionality to clusters
[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"
31#include "AliTOFRawStream.h"
39dff6a4 32#include "AliTOFGeometry.h"
1605abc6 33#include "AliLog.h"
34#include <fstream>
35
36ClassImp(AliTOFFEEReader)
37
38//_______________________________________________________________
39
40AliTOFFEEReader::AliTOFFEEReader() :
41 TObject(),
42 fFEEConfig(new AliTOFFEEConfig()),
b059882a 43 fChannelEnabled(),
44 fMatchingWindow()
1605abc6 45{
46 /*
47 *
48 * default constructor
49 *
50 */
51
b059882a 52 Reset();
1605abc6 53}
54
55//_______________________________________________________________
56
57AliTOFFEEReader::AliTOFFEEReader(const AliTOFFEEReader &source) :
58 TObject(source),
59 fFEEConfig(new AliTOFFEEConfig())
60{
61 /*
62 *
63 * copy constructor
64 *
65 */
66
67 memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
68}
69
70//_______________________________________________________________
71
72AliTOFFEEReader &
73AliTOFFEEReader::operator=(const AliTOFFEEReader &source)
74{
75 /*
76 *
77 * operator =
78 *
79 */
80
81 TObject::operator=(source);
82 memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
83 return *this;
84}
85
86//_______________________________________________________________
87
88AliTOFFEEReader::~AliTOFFEEReader()
89{
90 /*
91 *
92 * default destructor
93 *
94 */
95
96 delete fFEEConfig;
97}
98
99//_______________________________________________________________
100
101void
102AliTOFFEEReader::ResetChannelEnabledArray()
103{
104 /*
105 *
106 * reset channel enabled array
107 *
108 */
109
110 for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++)
111 fChannelEnabled[iIndex] = kFALSE;
112}
113
114//_______________________________________________________________
115
116void
b059882a 117AliTOFFEEReader::Reset()
118{
119 /*
120 *
121 * reset
122 *
123 */
124
125 for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++) {
126 fChannelEnabled[iIndex] = kFALSE;
127 fMatchingWindow[iIndex] = 0;
128 }
129}
130
131//_______________________________________________________________
132
133void
39dff6a4 134AliTOFFEEReader::LoadFEEConfig(const Char_t *FileName) const
1605abc6 135{
136 /*
137 *
138 * load FEE config
139 *
140 */
141
5b086af5 142 Char_t *expandedFileName = gSystem->ExpandPathName(FileName);
1605abc6 143 std::ifstream is;
5b086af5 144 is.open(expandedFileName, std::ios::binary);
1605abc6 145 is.read((Char_t *)fFEEConfig, sizeof(AliTOFFEEConfig));
146 is.close();
147}
148
149//_______________________________________________________________
150
151Int_t
152AliTOFFEEReader::ParseFEEConfig()
153{
154 /*
155 *
156 * parse FEE config
157 *
158 * loops over all FEE channels, checks whether they are enabled
159 * and sets channel enabled
160 *
161 */
162
163 AliInfo("parsing TOF FEE config")
164
165 AliTOFRawStream rawStream;
166 Int_t nEnabled = 0;
167 Int_t volume[5], index;
168 Int_t temp;
169
b059882a 170 Reset();
1605abc6 171
172 /* loop over all FEE channels */
173 for (Int_t iDDL = 0; iDDL < GetNumberOfDDLs(); iDDL++)
174 for (Int_t iTRM = 0; iTRM < GetNumberOfTRMs(); iTRM++)
175 for (Int_t iChain = 0; iChain < GetNumberOfChains(); iChain++)
176 for (Int_t iTDC = 0; iTDC < GetNumberOfTDCs(); iTDC++)
177 for (Int_t iChannel = 0; iChannel < GetNumberOfChannels(); iChannel++)
178 /* check whether FEE channel is enabled */
179 if (IsChannelEnabled(iDDL, iTRM + 3, iChain, iTDC, iChannel)) {
180 /* convert FEE channel indexes into detector indexes */
181 rawStream.EquipmentId2VolumeId(iDDL, iTRM + 3, iChain, iTDC, iChannel, volume);
182 /* swap padx and padz to fit AliTOFGeometry::GetIndex behaviour */
183 temp = volume[4]; volume[4] = volume[3]; volume[3] = temp;
b059882a 184 /* check if index is ok */
185 if (volume[0] < 0 || volume[0] > 17 ||
186 volume[1] < 0 || volume[1] > 4 ||
187 volume[2] < 0 || volume[2] > 18 ||
188 volume[3] < 0 || volume[3] > 1 ||
189 volume[4] < 0 || volume[4] > 47)
190 continue;
1605abc6 191 /* convert detector indexes into calibration index */
192 index = AliTOFGeometry::GetIndex(volume);
193 /* check calibration index */
194 if (index != -1 && index < GetNumberOfIndexes()) {
195 /* set calibration channel enabled */
196 fChannelEnabled[index] = kTRUE;
b059882a 197 fMatchingWindow[index] = GetMatchingWindow(iDDL, iTRM + 3, iChain, iTDC, iChannel);
1605abc6 198 nEnabled++;
199 }
200 }
201 return nEnabled;
202}
203
204//_______________________________________________________________
205
206Bool_t
39dff6a4 207AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
1605abc6 208{
209 /*
210 *
211 * is channel enabled
212 *
213 * checks whether a FEE channel is enabled using the
214 * TOF FEE config object.
215 *
216 */
217
218 AliTOFFEEConfig *feeConfig;
219 AliTOFCrateConfig *crateConfig;
220 AliTOFTRMConfig *trmConfig;
221 Int_t maskPB, maskTDC;
222
223 /* get and check fee config */
224 if (!(feeConfig = GetFEEConfig()))
225 return kFALSE;
226
227 /* get and check crate config */
228 if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
229 return kFALSE;
230
231 /* get and check TRM config */
232 if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
233 return kFALSE;
234
235 /* check DRM enabled */
236 if (!crateConfig->IsDRMEnabled())
237 return kFALSE;
238
239 /* check TRM enabled */
240 if (!crateConfig->IsTRMEnabled(iTRM - 3))
241 return kFALSE;
242
243 /* switch chain */
244 switch (iChain) {
245 /* chain A */
246 case 0:
247 /* check chain enabled */
248 if (trmConfig->GetChainAFlag() != 1)
249 return kFALSE;
250 /* switch TDC */
251 switch (iTDC) {
252 case 0: case 1: case 2:
253 maskPB = trmConfig->GetMaskPB0();
254 break;
255 case 3: case 4: case 5:
256 maskPB = trmConfig->GetMaskPB1();
257 break;
258 case 6: case 7: case 8:
259 maskPB = trmConfig->GetMaskPB2();
260 break;
261 case 9: case 10: case 11:
262 maskPB = trmConfig->GetMaskPB3();
263 break;
264 case 12: case 13: case 14:
265 maskPB = trmConfig->GetMaskPB4();
266 break;
267 default:
268 return kFALSE;
269 break;
270 } /* switch TDC */
271 break; /* chain A */
272 /* chain B */
273 case 1:
274 /* check chain enabled */
275 if (trmConfig->GetChainBFlag() != 1)
276 return kFALSE;
277 /* switch TDC */
278 switch (iTDC) {
279 case 0: case 1: case 2:
280 maskPB = trmConfig->GetMaskPB5();
281 break;
282 case 3: case 4: case 5:
283 maskPB = trmConfig->GetMaskPB6();
284 break;
285 case 6: case 7: case 8:
286 maskPB = trmConfig->GetMaskPB7();
287 break;
288 case 9: case 10: case 11:
289 maskPB = trmConfig->GetMaskPB8();
290 break;
291 case 12: case 13: case 14:
292 maskPB = trmConfig->GetMaskPB9();
293 break;
294 default:
295 return kFALSE;
296 break;
297 } /* switch TDC */
298 break; /* chain B */
299 default:
300 return kFALSE;
301 break;
302 } /* switch chain */
303
304 /* check channel enabled */
305 maskTDC = (maskPB & (0xFF << ((iTDC % 3) * 8))) >> ((iTDC % 3) * 8);
306 if (maskTDC & (0x1 << iChannel))
307 return kTRUE;
308 else
309 return kFALSE;
310
311}
312
b059882a 313//_______________________________________________________________
314
315Int_t
316AliTOFFEEReader::GetMatchingWindow(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
317{
318 /*
319 *
320 * get matching window
321 *
322 * checks whether a FEE channel is enabled using the
323 * TOF FEE config object and return the associated
324 * matching window
325 *
326 */
bf1a5fa6 327
b059882a 328 AliTOFFEEConfig *feeConfig;
329 AliTOFCrateConfig *crateConfig;
330 AliTOFTRMConfig *trmConfig;
bf1a5fa6 331
332 iChain = 0; iTDC = 0; iChannel = 0; /* dummy for the time being */
b059882a 333
334 /* get and check fee config */
335 if (!(feeConfig = GetFEEConfig()))
336 return 0;
337
338 /* get and check crate config */
339 if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
340 return 0;
341
342 /* get and check TRM config */
343 if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
344 return 0;
345
346 /* check DRM enabled */
347 if (!crateConfig->IsDRMEnabled())
348 return 0;
349
350 /* check TRM enabled */
351 if (!crateConfig->IsTRMEnabled(iTRM - 3))
352 return 0;
353
354 return trmConfig->GetMatchingWindow();
355}
356
1605abc6 357
358void
359AliTOFFEEReader::DumpFEEConfig()
360{
361 /*
362 *
363 * dump FEE config
364 *
365 */
366
367 AliTOFFEEConfig *feeConfig = GetFEEConfig();
368 AliTOFCrateConfig *crateConfig;
369 AliTOFDRMConfig *drmConfig;
370 AliTOFLTMConfig *ltmConfig;
371 AliTOFTRMConfig *trmConfig;
372
373 AliInfo("-------------------------------------");
374 AliInfo("dumping TOF FEE config");
375 AliInfo("-------------------------------------");
376 AliInfo(Form("version: %d", feeConfig->GetVersion()));
377 AliInfo(Form("dump time: %d", feeConfig->GetDumpTime()));
378 AliInfo(Form("run number: %d", feeConfig->GetRunNumber()));
379 AliInfo(Form("run type: %d", feeConfig->GetRunType()));
380 AliInfo("-------------------------------------");
381
382 /* loop over crates */
383 for (Int_t iCrate = 0; iCrate < AliTOFFEEConfig::GetNumberOfCrates(); iCrate++) {
384 crateConfig = feeConfig->GetCrateConfig(iCrate);
385
386 /* check crate config */
387 if (!crateConfig)
388 continue;
389
390 /* check DRM enabled */
391 if (!crateConfig->IsDRMEnabled())
392 continue;
393
394 AliInfo(Form("crate id: %02d", iCrate));
395
396 /* dump DRM config */
397 drmConfig = crateConfig->GetDRMConfig();
398 AliInfo(Form("DRM is enabled: drmId=%d, slotMask=%03x", drmConfig->GetDRMId(), drmConfig->GetSlotMask()));
399
400 /* dump LTM config if enabled */
401 if (crateConfig->IsLTMEnabled()) {
402 ltmConfig = crateConfig->GetLTMConfig();
403 AliInfo(Form("LTM is enabled: threshold=%d", ltmConfig->GetThreshold()));
404 }
405
406 /* dump CPDM config if enabled */
407 if (crateConfig->IsCPDMEnabled()) {
408 AliInfo(Form("CPDM is enabled"));
409 }
410
411 /* loop over TRMs */
412 for (Int_t iTRM = 0; iTRM < AliTOFCrateConfig::GetNumberOfTRMs(); iTRM++) {
413
414 trmConfig = crateConfig->GetTRMConfig(iTRM);
415
416 /* check TRM config */
417 if (!trmConfig)
418 continue;
419
420 /* check TRM enabled */
421 if (!crateConfig->IsTRMEnabled(iTRM))
422 continue;
423
424 /* dump TRM config */
425 AliInfo(Form("TRM%02d is enabled: matchWin=%d, latWin=%d, packFlag=%d", iTRM + 3, trmConfig->GetMatchingWindow(), trmConfig->GetLatencyWindow(), trmConfig->GetPackingFlag()));
426
427 /* check TRM chain A flag */
428 if (trmConfig->GetChainAFlag() == 1) {
429 AliInfo(Form("TRM%02d chainA is enabled: PB0=%06X, PB1=%06X, PB2=%06X, PB3=%06X, PB4=%06X", iTRM + 3, trmConfig->GetMaskPB0(), trmConfig->GetMaskPB1(), trmConfig->GetMaskPB2(), trmConfig->GetMaskPB3(), trmConfig->GetMaskPB4()));
430 }
431
432 /* check TRM chain B flag */
433 if (trmConfig->GetChainBFlag() == 1) {
434 AliInfo(Form("TRM%02d chainB is enabled: PB5=%06X, PB6=%06X, PB7=%06X, PB8=%06X, PB9=%06X", iTRM + 3, trmConfig->GetMaskPB5(), trmConfig->GetMaskPB6(), trmConfig->GetMaskPB7(), trmConfig->GetMaskPB8(), trmConfig->GetMaskPB9()));
435 }
436
437
438
439 } /* loop over TRMs */
440 AliInfo("-------------------------------------");
441 } /* loop over crates */
442}
443