3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Artur Szostak <artursz@iafrica.com> *
8 * for The ALICE HLT Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /// @file testAliHLTReadoutList.C
20 /// @author Artur Szostak <artursz@iafrica.com>
22 /// @brief Test program for the AliHLTReadoutList class.
25 #if defined(__CINT__) && (! defined(__MAKECINT__))
26 #error This macro must be compiled. Try running as testAliHLTReadoutList.C++.
29 #if !defined(__CINT__) || defined(__MAKECINT__)
30 #include "AliHLTDataTypes.h"
31 #include "AliHLTReadoutList.h"
32 #include "AliHLTDAQ.h"
35 #include "Riostream.h"
40 // The detector codes as used by AliHLTReadoutList.
41 const int kgNumberOfCodes = 21;
42 const int kgDetCodes[kgNumberOfCodes] = {
43 AliHLTReadoutList::kITSSPD,
44 AliHLTReadoutList::kITSSDD,
45 AliHLTReadoutList::kITSSSD,
46 AliHLTReadoutList::kTPC,
47 AliHLTReadoutList::kTRD,
48 AliHLTReadoutList::kTOF,
49 AliHLTReadoutList::kHMPID,
50 AliHLTReadoutList::kPHOS,
51 AliHLTReadoutList::kCPV,
52 AliHLTReadoutList::kPMD,
53 AliHLTReadoutList::kMUONTRK,
54 AliHLTReadoutList::kMUONTRG,
55 AliHLTReadoutList::kFMD,
56 AliHLTReadoutList::kT0,
57 AliHLTReadoutList::kV0,
58 AliHLTReadoutList::kZDC,
59 AliHLTReadoutList::kACORDE,
60 AliHLTReadoutList::kTRG,
61 AliHLTReadoutList::kEMCAL,
62 AliHLTReadoutList::kDAQTEST,
63 AliHLTReadoutList::kHLT
65 const char* kgDetCodeName[kgNumberOfCodes] = {
66 "AliHLTReadoutList::kITSSPD",
67 "AliHLTReadoutList::kITSSDD",
68 "AliHLTReadoutList::kITSSSD",
69 "AliHLTReadoutList::kTPC",
70 "AliHLTReadoutList::kTRD",
71 "AliHLTReadoutList::kTOF",
72 "AliHLTReadoutList::kHMPID",
73 "AliHLTReadoutList::kPHOS",
74 "AliHLTReadoutList::kCPV",
75 "AliHLTReadoutList::kPMD",
76 "AliHLTReadoutList::kMUONTRK",
77 "AliHLTReadoutList::kMUONTRG",
78 "AliHLTReadoutList::kFMD",
79 "AliHLTReadoutList::kT0",
80 "AliHLTReadoutList::kV0",
81 "AliHLTReadoutList::kZDC",
82 "AliHLTReadoutList::kACORDE",
83 "AliHLTReadoutList::kTRG",
84 "AliHLTReadoutList::kEMCAL",
85 "AliHLTReadoutList::kDAQTEST",
86 "AliHLTReadoutList::kHLT"
90 * Converts a code to string.
91 * \param code The ID code of the detector. One of AliHLTReadoutList::EDetectorId
92 * \returns the code name as a string given a the detector code.
94 const char* CodeToString(int code)
96 for (int i = 0; i < kgNumberOfCodes; ++i)
98 if (kgDetCodes[i] == code) return kgDetCodeName[i];
104 * Checks if the basic empty and clear methods work.
106 bool CheckEmptyAndClear()
108 AliHLTReadoutList rl;
109 if (rl.Empty() != true)
111 cerr << "ERROR: AliHLTReadoutList::Empty returns false for an empty readout list." << endl;
115 // Enable all the detectors and check this operation.
116 rl.Enable(AliHLTReadoutList::kALLDET);
117 for (int i = 0; i < kgNumberOfCodes; ++i)
119 if (i == 19) continue; // This is the test DDL. off by default.
120 if (not rl.DetectorEnabled(kgDetCodes[i]))
122 cerr << "ERROR: AliHLTReadoutList::Enable(AliHLTReadoutList::kALLDET) did not enable for "
123 << CodeToString(kgDetCodes[i]) << "." << endl;
127 if (rl.DetectorEnabled(AliHLTReadoutList::kDAQTEST))
129 cerr << "ERROR: AliHLTReadoutList::Enable(AliHLTReadoutList::kALLDET) enabled bits"
130 " for AliHLTReadoutList::kDAQTEST but should not have." << endl;
135 // Fetch the raw bits for the readout list structure and check that they
136 // are all zero, since we should have disabled everything in the loop above.
137 AliHLTEventDDL bits = rl;
138 if (bits.fCount != (unsigned int)gkAliHLTDDLListSize)
140 cerr << "ERROR: Typecast operator AliHLTEventDDL () is not"
141 " setting the fCount of the structure correctly." << endl;
144 for (int j = 0; j < gkAliHLTDDLListSize; ++j)
146 if (bits.fList[j] != 0x0)
148 cerr << "ERROR: Word " << j << " in internal AliHLTReadoutList"
149 " bitfield structure is not zero as expected after a"
150 " call to AliHLTReadoutList::Clear." << endl;
159 * Tests enabling and disabling of different detectors.
161 bool CheckEnablingDisabling()
163 for (int i = 0; i < 10000; ++i)
165 // Get 3 random detector codes.
167 gRandom->Integer(kgNumberOfCodes),
168 gRandom->Integer(kgNumberOfCodes),
169 gRandom->Integer(kgNumberOfCodes)
172 kgDetCodes[detNum[0]],
173 kgDetCodes[detNum[1]],
174 kgDetCodes[detNum[2]]
176 // make sure the codes are not duplicated.
177 while (code[1] == code[0])
179 detNum[1] = gRandom->Integer(kgNumberOfCodes);
180 code[1] = kgDetCodes[detNum[1]];
182 while (code[2] == code[1] or code[2] == code[0])
184 detNum[2] = gRandom->Integer(kgNumberOfCodes);
185 code[2] = kgDetCodes[detNum[2]];
188 // Choose the number of codes to use, from 1 to max 3.
189 int codeCount = gRandom->Integer(3) + 1;
191 // Build up the detector code list for the AliHLTReadoutList constructor.
193 for (int j = 0; j < codeCount; ++j) totalCode |= code[j];
195 AliHLTReadoutList rl(totalCode);
196 if (rl.Empty() == true)
198 cerr << "ERROR: AliHLTReadoutList::Empty returns true for a non empty readout list." << endl;
202 // Check that the correct detectors have been enabled and
203 // that we can disable a detector correctly.
204 for (int j = 0; j < codeCount; ++j)
206 if (rl.DetectorEnabled(code[j]) == false)
208 cerr << "ERROR: Detector was not enabled for "
209 << CodeToString(code[j]) << " by constructor." << endl;
213 // Also check each bit individualy according to AliHLTDAQ values.
215 int maxddls = AliHLTDAQ::NumberOfDdls(det);
216 for (int ddlindex = 0; ddlindex < maxddls; ++ddlindex)
218 int ddlid = AliHLTDAQ::DdlIDOffset(det) | (ddlindex & 0xFF);
219 if (rl.IsDDLDisabled(ddlid))
221 cerr << "ERROR: Bit not set for DDL " << ddlid
222 << ", even though detector "
223 << AliHLTDAQ::OnlineName(det)
224 << " was enabled." << endl;
230 if (rl.DetectorEnabled(code[j]) == true)
232 cerr << "ERROR: AliHLTReadoutList::Disable(x) is not working for x = "
233 << CodeToString(code[j]) << "." << endl;
238 // Fetch the raw bits for the readout list structure and check that they
239 // are all zero, since we should have disabled everything in the loop above.
240 AliHLTEventDDL bits = rl;
241 for (int j = 0; j < gkAliHLTDDLListSize; ++j)
243 if (bits.fList[j] != 0x0)
245 cerr << "ERROR: Word " << j << " in internal AliHLTReadoutList"
246 " bitfield structure is not zero as expected." << endl;
255 * Tests enabling and disabling of different DDLs.
257 bool CheckEnablingDisablingDDLs()
259 for (int i = 0; i < 10000; ++i)
261 // Get random DDL IDs that are each unique.
262 std::vector<int> ddls;
263 int ddlCount = gRandom->Integer(100) + 1;
264 for (int j = 0; j < ddlCount; ++j)
269 int det = gRandom->Integer(AliHLTDAQ::NumberOfDetectors());
270 int maxddls = AliHLTDAQ::NumberOfDdls(det);
271 // The following is a special check since AliDAQ could be the newer version.
272 // det = 18 is for EMCAL and gkAliHLTDDLListSize = 30 indicates old version
273 // of AliHLTEventDDL before EMCAL expantion with DCAL.
274 if (det == 18 and gkAliHLTDDLListSize == 30 and maxddls > 24) maxddls = 24;
275 int ddlindex = gRandom->Integer(maxddls);
276 ddlid = AliHLTDAQ::DdlID(det, ddlindex);
277 if (std::find(ddls.begin(), ddls.end(), ddlid) != ddls.end()) ddlid = -1;
280 ddls.push_back(ddlid);
283 // Build up the enable list for the AliHLTReadoutList constructor.
285 for (size_t j = 0; j < ddls.size(); ++j)
288 sprintf(num, "%d", ddls[j]);
293 AliHLTReadoutList rl(enableList.Data());
294 if (rl.Empty() == true)
296 cerr << "ERROR: AliHLTReadoutList::Empty returns true for a non empty readout list." << endl;
300 // Check that the correct DDLs have been enabled and
301 // that we can disable a DDL correctly.
302 for (size_t j = 0; j < ddls.size(); ++j)
304 if (rl.IsDDLEnabled(ddls[j]) == false)
306 cerr << "ERROR: DDL " << ddls[j] << " was not enabled by constructor." << endl;
309 rl.DisableDDLBit(ddls[j]);
310 if (rl.IsDDLDisabled(ddls[j]) == false)
312 cerr << "ERROR: AliHLTReadoutList::DisableDDLBit(x) is not working for x = "
313 << ddls[j] << "." << endl;
318 // Fetch the raw bits for the readout list structure and check that they
319 // are all zero, since we should have disabled everything in the loop above.
320 AliHLTEventDDL bits = rl;
321 for (int j = 0; j < gkAliHLTDDLListSize; ++j)
323 if (bits.fList[j] != 0x0)
325 cerr << "ERROR: Word " << j << " in internal AliHLTReadoutList"
326 " bitfield structure is not zero as expected." << endl;
335 * Tests if using incorrect DDL IDs returns zero or is ignored as expected.
337 bool CheckIncorrectIDs()
339 for (int i = 0; i < 1000000; ++i)
341 // Get random DDL ID outside the valid range.
343 int det = gRandom->Integer(AliHLTDAQ::NumberOfDetectors()+1);
344 if (det != AliHLTDAQ::NumberOfDetectors())
346 int maxddls = AliHLTDAQ::NumberOfDdls(det);
347 int ddlindex = gRandom->Integer(0xFF - maxddls) + maxddls;
348 ddlid = AliHLTDAQ::DdlIDOffset(det) | (ddlindex & 0xFF);
352 det = gRandom->Integer(11) + 20;
353 if (det == 30) det = 31;
354 int ddlindex = gRandom->Integer(0xFF);
355 ddlid = (det << 8) | (ddlindex & 0xFF);
358 AliHLTReadoutList rl;
359 if (rl.GetDDLBit(ddlid) != kFALSE)
361 cerr << "ERROR: Received a non zero result for invalid DDL " << ddlid << "." << endl;
364 AliHLTEventDDL before = rl;
365 rl.EnableDDLBit(ddlid);
366 AliHLTEventDDL after = rl;
367 if (memcmp(&before, &after, sizeof(AliHLTEventDDL)) != 0)
369 cerr << "ERROR: Modified AliHLTReadoutList structure using an invalid DDL "
370 << ddlid << "." << endl;
371 cerr << "========== Dump of bits before modification ==========" << endl;
372 for (unsigned int j = 0; j < before.fCount; ++j)
374 cerr << "[word " << dec << j << "] = " << hex << before.fList[j] << dec << endl;
376 cerr << "========== Dump of bits after modification ==========" << endl;
377 for (unsigned int j = 0; j < after.fCount; ++j)
379 cerr << "[word " << dec << j << "] = " << hex << after.fList[j] << dec << endl;
388 * Runs the unit test for the AliHLTReadoutList class.
389 * \returns true if the class passed the test and false otherwise.
391 bool testAliHLTReadoutList()
393 gRandom->SetSeed(123);
395 if (AliHLTDAQ::NumberOfDetectors() != kgNumberOfCodes)
397 cerr << "ERROR: The testAliHLTReadoutList.C macro needs to be updated"
398 " or something went really wrong."
399 " The number of detectors reported by AliHLTDAQ is not "
400 << kgNumberOfCodes << ", as expected, but "
401 << AliHLTDAQ::NumberOfDetectors() << "." << endl;
405 if (not CheckEmptyAndClear()) return false;
406 if (not CheckEnablingDisabling()) return false;
407 if (not CheckEnablingDisablingDDLs()) return false;
408 if (not CheckIncorrectIDs()) return false;
415 int main(int /*argc*/, const char** /*argv*/)
417 bool resultOk = testAliHLTReadoutList();
418 if (not resultOk) return 1;
422 #endif // __MAKECINT__