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 testAliHLTEventDDLBackwardCompatibility.C
20 /// @author Artur Szostak <artursz@iafrica.com>
21 /// @date 25 June 2010
22 /// @brief Test program for backward compatibility of the AliHLTEventDDL structure.
25 #if defined(__CINT__) && (! defined(__MAKECINT__))
26 #error This macro must be compiled. Try running as testAliHLTEventDDLBackwardCompatibility.C++.
29 #if !defined(__CINT__) || defined(__MAKECINT__)
30 #include "AliHLTDataTypes.h"
31 #include "AliHLTReadoutList.h"
32 #include "AliHLTDAQ.h"
33 #include "AliHLTComponent.h"
34 #include "AliRawDataHeader.h"
39 #include "Riostream.h"
45 * Tests to see if the AliHLTReadoutList class handles both AliHLTEventDDLV0
46 * and AliHLTEventDDLV1 correctly.
48 bool CheckReadoutListConvertedCorrectly()
50 // Initialise the different versions of the structures so that every detector
51 // has only its first DDL set.
54 AliHLTEventDDL eventddlV0;
55 AliHLTEventDDLV0 bitsV0;
57 bitsV0.fCount = gkAliHLTDDLListSizeV0;
58 if (gkAliHLTDDLListSizeV0 != 30)
60 cerr << "ERROR: gkAliHLTDDLListSizeV0 has a value of " << gkAliHLTDDLListSizeV0
61 << " but expected a value of 30." << endl;
64 bitsV0.fList[0] = 0x00000001; // kITSSPD
65 bitsV0.fList[1] = 0x00000001; // kITSSDD
66 bitsV0.fList[2] = 0x00000001; // kITSSSD
67 bitsV0.fList[3] = 0x00000001; // kTPC
68 bitsV0.fList[4] = 0x00000000; // kTPC
69 bitsV0.fList[5] = 0x00000000; // kTPC
70 bitsV0.fList[6] = 0x00000000; // kTPC
71 bitsV0.fList[7] = 0x00000000; // kTPC
72 bitsV0.fList[8] = 0x00000000; // kTPC
73 bitsV0.fList[9] = 0x00000000; // kTPC
74 bitsV0.fList[10] = 0x00000000; // kTPC
75 bitsV0.fList[11] = 0x00000001; // kTRD
76 bitsV0.fList[12] = 0x00000001; // kTOF
77 bitsV0.fList[13] = 0x00000000; // kTOF
78 bitsV0.fList[14] = 0x00000000; // kTOF
79 bitsV0.fList[15] = 0x00000001; // kHMPID
80 bitsV0.fList[16] = 0x00000001; // kPHOS
81 bitsV0.fList[17] = 0x00000001; // kCPV
82 bitsV0.fList[18] = 0x00000001; // kPMD
83 bitsV0.fList[19] = 0x00000001; // kMUONTRK
84 bitsV0.fList[20] = 0x00000001; // kMUONTRG
85 bitsV0.fList[21] = 0x00000001; // kFMD
86 bitsV0.fList[22] = 0x00000001; // kT0
87 bitsV0.fList[23] = 0x00000001; // kV0
88 bitsV0.fList[24] = 0x00000001; // kZDC
89 bitsV0.fList[25] = 0x00000001; // kACORDE
90 bitsV0.fList[26] = 0x00000001; // kTRG
91 bitsV0.fList[27] = 0x00000001; // kEMCAL
92 bitsV0.fList[28] = 0x00000001; // kDAQTEST
93 bitsV0.fList[29] = 0x00000001; // kHLT
97 AliHLTEventDDL eventddlV1;
98 AliHLTEventDDLV1 bitsV1;
100 bitsV1.fCount = gkAliHLTDDLListSizeV1;
101 if (gkAliHLTDDLListSizeV1 != 31)
103 cerr << "ERROR: gkAliHLTDDLListSizeV1 has a value of " << gkAliHLTDDLListSizeV1
104 << " but expected a value of 31." << endl;
107 bitsV1.fList[0] = 0x00000001; // kITSSPD
108 bitsV1.fList[1] = 0x00000001; // kITSSDD
109 bitsV1.fList[2] = 0x00000001; // kITSSSD
110 bitsV1.fList[3] = 0x00000001; // kTPC
111 bitsV1.fList[4] = 0x00000000; // kTPC
112 bitsV1.fList[5] = 0x00000000; // kTPC
113 bitsV1.fList[6] = 0x00000000; // kTPC
114 bitsV1.fList[7] = 0x00000000; // kTPC
115 bitsV1.fList[8] = 0x00000000; // kTPC
116 bitsV1.fList[9] = 0x00000000; // kTPC
117 bitsV1.fList[10] = 0x00000000; // kTPC
118 bitsV1.fList[11] = 0x00000001; // kTRD
119 bitsV1.fList[12] = 0x00000001; // kTOF
120 bitsV1.fList[13] = 0x00000000; // kTOF
121 bitsV1.fList[14] = 0x00000000; // kTOF
122 bitsV1.fList[15] = 0x00000001; // kHMPID
123 bitsV1.fList[16] = 0x00000001; // kPHOS
124 bitsV1.fList[17] = 0x00000001; // kCPV
125 bitsV1.fList[18] = 0x00000001; // kPMD
126 bitsV1.fList[19] = 0x00000001; // kMUONTRK
127 bitsV1.fList[20] = 0x00000001; // kMUONTRG
128 bitsV1.fList[21] = 0x00000001; // kFMD
129 bitsV1.fList[22] = 0x00000001; // kT0
130 bitsV1.fList[23] = 0x00000001; // kV0
131 bitsV1.fList[24] = 0x00000001; // kZDC
132 bitsV1.fList[25] = 0x00000001; // kACORDE
133 bitsV1.fList[26] = 0x00000001; // kTRG
134 bitsV1.fList[27] = 0x00000001; // kEMCAL
135 bitsV1.fList[28] = 0x00000000; // kEMCAL
136 bitsV1.fList[29] = 0x00000001; // kDAQTEST
137 bitsV1.fList[30] = 0x00000001; // kHLT
139 AliHLTReadoutList rlV0(eventddlV0);
140 AliHLTReadoutList rlV1(eventddlV1);
142 // Check that for both readout list versions only the first DDLs are
143 // enabled as expected.
144 for (Int_t i = 0; i < AliHLTDAQ::NumberOfDetectors(); ++i)
145 for (Int_t j = 0; j < AliHLTDAQ::NumberOfDdls(i); ++j)
147 Int_t ddlid = AliHLTDAQ::DdlIDOffset(i) | (j & 0xFF);
150 if (rlV0.IsDDLDisabled(ddlid))
152 cerr << "ERROR: The first DDL for detector " << AliHLTDAQ::DetectorName(i)
153 << " was not enabled for readout list initialised from AliHLTEventDDLV0."
157 if (rlV1.IsDDLDisabled(ddlid))
159 cerr << "ERROR: The first DDL for detector " << AliHLTDAQ::DetectorName(i)
160 << " was not enabled for readout list initialised from AliHLTEventDDLV1."
167 if (rlV0.IsDDLEnabled(ddlid))
169 cerr << "ERROR: DDL " << ddlid << " for detector " << AliHLTDAQ::DetectorName(i)
170 << " was marked enabled for readout list initialised from AliHLTEventDDLV0."
174 if (rlV1.IsDDLEnabled(ddlid))
176 cerr << "ERROR: DDL " << ddlid << " for detector " << AliHLTDAQ::DetectorName(i)
177 << " was marked enabled for readout list initialised from AliHLTEventDDLV1."
184 // Check that the internal buffers are identical.
185 if (rlV0.BufferSize() != rlV1.BufferSize())
187 cerr << "ERROR: Buffer sizes for readout lists are different: rlV0.BufferSize() = "
188 << rlV0.BufferSize() << ", rlV1.BufferSize() = " << rlV1.BufferSize() << endl;
191 if (memcmp(rlV0.Buffer(), rlV1.Buffer(), rlV0.BufferSize()) != 0)
193 cerr << "ERROR: Buffers for the two readout list versions are different." << endl;
201 * Tests to see if AliHLTComponent::ExtractTriggerData recognises the old format
202 * of AliHLTEventTriggerData and handles it correctly.
204 bool CheckHandlingOfOldAliHLTEventTriggerData()
206 // Prepare old structure format.
207 struct AliHLTEventTriggerDataV0
209 AliHLTUInt8_t fAttributes[gkAliHLTBlockDAttributeCount];
210 AliHLTUInt64_t fHLTStatus;
211 AliHLTUInt32_t fCommonHeaderWordCnt;
212 AliHLTUInt32_t fCommonHeader[gkAliHLTCommonHeaderCount];
213 AliHLTEventDDLV0 fReadoutListV0;
215 AliHLTEventTriggerDataV0 eventTrigData;
216 memset(&eventTrigData, 0x0, sizeof(eventTrigData));
217 eventTrigData.fCommonHeaderWordCnt = 8;
218 eventTrigData.fHLTStatus = 0x123;
219 eventTrigData.fReadoutListV0.fCount = gkAliHLTDDLListSizeV0;
220 eventTrigData.fReadoutListV0.fList[0] = 0x00000001; // kITSSPD
221 eventTrigData.fReadoutListV0.fList[1] = 0x00000001; // kITSSDD
222 eventTrigData.fReadoutListV0.fList[2] = 0x00000001; // kITSSSD
223 eventTrigData.fReadoutListV0.fList[3] = 0x00000001; // kTPC
224 eventTrigData.fReadoutListV0.fList[4] = 0x00000000; // kTPC
225 eventTrigData.fReadoutListV0.fList[5] = 0x00000000; // kTPC
226 eventTrigData.fReadoutListV0.fList[6] = 0x00000000; // kTPC
227 eventTrigData.fReadoutListV0.fList[7] = 0x00000000; // kTPC
228 eventTrigData.fReadoutListV0.fList[8] = 0x00000000; // kTPC
229 eventTrigData.fReadoutListV0.fList[9] = 0x00000000; // kTPC
230 eventTrigData.fReadoutListV0.fList[10] = 0x00000000; // kTPC
231 eventTrigData.fReadoutListV0.fList[11] = 0x00000001; // kTRD
232 eventTrigData.fReadoutListV0.fList[12] = 0x00000001; // kTOF
233 eventTrigData.fReadoutListV0.fList[13] = 0x00000000; // kTOF
234 eventTrigData.fReadoutListV0.fList[14] = 0x00000000; // kTOF
235 eventTrigData.fReadoutListV0.fList[15] = 0x00000001; // kHMPID
236 eventTrigData.fReadoutListV0.fList[16] = 0x00000001; // kPHOS
237 eventTrigData.fReadoutListV0.fList[17] = 0x00000001; // kCPV
238 eventTrigData.fReadoutListV0.fList[18] = 0x00000001; // kPMD
239 eventTrigData.fReadoutListV0.fList[19] = 0x00000001; // kMUONTRK
240 eventTrigData.fReadoutListV0.fList[20] = 0x00000001; // kMUONTRG
241 eventTrigData.fReadoutListV0.fList[21] = 0x00000001; // kFMD
242 eventTrigData.fReadoutListV0.fList[22] = 0x00000001; // kT0
243 eventTrigData.fReadoutListV0.fList[23] = 0x00000001; // kV0
244 eventTrigData.fReadoutListV0.fList[24] = 0x00000001; // kZDC
245 eventTrigData.fReadoutListV0.fList[25] = 0x00000001; // kACORDE
246 eventTrigData.fReadoutListV0.fList[26] = 0x00000001; // kTRG
247 eventTrigData.fReadoutListV0.fList[27] = 0x00000001; // kEMCAL
248 eventTrigData.fReadoutListV0.fList[28] = 0x00000001; // kDAQTEST
249 eventTrigData.fReadoutListV0.fList[29] = 0x00000001; // kHLT
251 AliHLTComponentTriggerData trigData = {
252 sizeof(AliHLTComponentTriggerData),
253 sizeof(AliHLTEventTriggerDataV0),
257 AliHLTReadoutList readoutlistExpected;
258 for (Int_t i = 0; i < AliHLTDAQ::NumberOfDetectors(); ++i)
260 Int_t ddlid = AliHLTDAQ::DdlIDOffset(i);
261 readoutlistExpected.EnableDDLBit(ddlid);
264 const AliHLTUInt8_t (*attribs)[gkAliHLTBlockDAttributeCount];
265 AliHLTUInt64_t status = 0x0;
266 const AliRawDataHeader* cdh = NULL;
267 AliHLTReadoutList readoutlist;
269 int result = AliHLTComponent::ExtractTriggerData(trigData, &attribs, &status, &cdh, &readoutlist, true);
272 cerr << "ERROR: The method AliHLTComponent::ExtractTriggerData"
273 " fails for the old structure format." << endl;
276 if (attribs != &eventTrigData.fAttributes)
278 cerr << "ERROR: The method AliHLTComponent::ExtractTriggerData"
279 " fails to locate the attributes structure correctly." << endl;
284 cerr << "ERROR: The method AliHLTComponent::ExtractTriggerData"
285 " fails to locate the HLT status word correctly." << endl;
288 if ((const void*)cdh != (void*)&eventTrigData.fCommonHeader)
290 cerr << "ERROR: The method AliHLTComponent::ExtractTriggerData"
291 " fails to locate the Common Data Header (CDH) structure correctly." << endl;
294 if (memcmp(readoutlist.Buffer(), readoutlistExpected.Buffer(), readoutlist.BufferSize()) != 0)
296 cerr << "ERROR: The method AliHLTComponent::ExtractTriggerData"
297 " fails to extract the readout list correctly." << endl;
305 * Tests to see if reading old AliHLTReadoutList versions from root files works.
306 * \param filename The name of the file generated by GenerateReadoutListFile.C,
307 * which contains the readout list objects to test.
309 bool CheckReadingOldFormat(const char* filename = "oldAliHLTReadoutListFormat.root")
311 TFile file(filename, "READ");
313 // Load the readout list objects.
314 AliHLTReadoutList* rl[5] = {NULL, NULL, NULL, NULL, NULL};
315 for (int i = 0; i < 5; ++i)
318 sprintf(name, "readoutlist%d", i+1);
319 rl[i] = dynamic_cast<AliHLTReadoutList*>(file.Get(name));
322 cerr << "ERROR: Could not get object '" << name
323 << "' from file '" << filename << "'." << endl;
328 // Now load the tree and see that the objects are the same as the readout
329 // list objects stored directly to the TFile.
330 const char* treename = "rltree";
331 TTree* tree = dynamic_cast<TTree*>(file.Get(treename));
334 cerr << "ERROR: Could not get TTree '" << treename
335 << "' from file '" << filename << "'." << endl;
338 AliHLTReadoutList* r = new AliHLTReadoutList;
339 tree->SetBranchAddress("readoutlist", &r);
340 for (int i = 0; i < 5; ++i)
343 if (r->BufferSize() != rl[i]->BufferSize())
345 cerr << "ERROR: readoutlist" << i+1
346 << " and the one from the TTree have different sizes."
350 #if 1 // ROOT_SVN_REVISION < 9999 //FIXME: after fixed https://savannah.cern.ch/bugs/?69241
351 r->SetDDLBit(9999999, kTRUE); // Triggers a reformating of the internal structure to the new version.
353 if (memcmp(r->Buffer(), rl[i]->Buffer(), r->BufferSize()) != 0)
355 cerr << "ERROR: readoutlist" << i+1
356 << " and the one from the TTree are different."
362 // Now check each readout list individually.
363 typedef AliHLTReadoutList RL;
364 Int_t alwaysoff = RL::kITSSPD
382 // We will need to try and set the missing EMCAL DDL bits.
383 // Otherwise the DetectorEnabled and DetectorDisabled methods will not
384 // give the expected answers.
385 for (int i = 24; i < AliHLTDAQ::NumberOfDdls("EMCAL"); ++i)
387 for (int j = 1; j <= 3; ++j)
389 Int_t ddlid = AliHLTDAQ::DdlIDOffset("EMCAL") | (i & 0xFF);
390 rl[j]->EnableDDLBit(ddlid);
395 if (not (rl[rlnum]->DetectorEnabled(RL::kTRG) and
396 rl[rlnum]->DetectorDisabled(alwaysoff | RL::kEMCAL | RL::kDAQTEST | RL::kHLT)
400 cerr << "ERROR: readoutlist" << rlnum+1 << " does not have the correct bits set." << endl;
405 if (not (rl[rlnum]->DetectorEnabled(RL::kTRG | RL::kEMCAL) and
406 rl[rlnum]->DetectorDisabled(alwaysoff | RL::kDAQTEST | RL::kHLT)
409 cerr << "ERROR: readoutlist" << rlnum+1 << " does not have the correct bits set." << endl;
414 if (not (rl[rlnum]->DetectorEnabled(RL::kTRG | RL::kEMCAL | RL::kDAQTEST) and
415 rl[rlnum]->DetectorDisabled(alwaysoff | RL::kHLT)
418 cerr << "ERROR: readoutlist" << rlnum+1 << " does not have the correct bits set." << endl;
423 if (not (rl[rlnum]->DetectorEnabled(RL::kTRG | RL::kEMCAL | RL::kDAQTEST | RL::kHLT) and
424 rl[rlnum]->DetectorDisabled(alwaysoff)
427 cerr << "ERROR: readoutlist" << rlnum+1 << " does not have the correct bits set." << endl;
432 if (not (rl[rlnum]->DetectorEnabled(RL::kTRG | RL::kDAQTEST | RL::kHLT) and
433 rl[rlnum]->DetectorDisabled(alwaysoff | RL::kEMCAL)
436 cerr << "ERROR: readoutlist" << rlnum+1 << " does not have the correct bits set." << endl;
445 * Runs the unit tests for backward compatibility of AliHLTEventDDL succeeded.
446 * \returns true if the tests were passed and false otherwise.
448 bool testAliHLTEventDDLBackwardCompatibility()
450 if (not CheckReadoutListConvertedCorrectly()) return false;
451 if (not CheckHandlingOfOldAliHLTEventTriggerData()) return false;
452 if (not CheckReadingOldFormat()) return false;
458 int main(int /*argc*/, const char** /*argv*/)
460 bool resultOk = testAliHLTEventDDLBackwardCompatibility();
461 if (not resultOk) return 1;
465 #endif // __MAKECINT__