]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/test/testAliHLTEventDDLBackwardCompatibility.C
#97492 Request to: patch AliSimulation; port to Release; make tag on release; for...
[u/mrichter/AliRoot.git] / HLT / BASE / test / testAliHLTEventDDLBackwardCompatibility.C
1 // $Id: $
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        *
5  * ALICE Experiment at CERN, All rights reserved.                         *
6  *                                                                        *
7  * Primary Authors: Artur Szostak <artursz@iafrica.com>                   *
8  *                  for The ALICE HLT Project.                            *
9  *                                                                        *
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  **************************************************************************/
18
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.
23 ///
24
25 #if defined(__CINT__) && (! defined(__MAKECINT__))
26 #error This macro must be compiled. Try running as testAliHLTEventDDLBackwardCompatibility.C++.
27 #endif
28
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"
35 #include "TRandom3.h"
36 #include "TString.h"
37 #include "TFile.h"
38 #include "TTree.h"
39 #include "Riostream.h"
40 #include <vector>
41 #include <algorithm>
42 #endif
43
44 /**
45  * Tests to see if the AliHLTReadoutList class handles both AliHLTEventDDLV0
46  * and AliHLTEventDDLV1 correctly.
47  */
48 bool CheckReadoutListConvertedCorrectly()
49 {
50         // Initialise the different versions of the structures so that every detector
51         // has only its first DDL set.
52         union
53         {
54                 AliHLTEventDDL eventddlV0;
55                 AliHLTEventDDLV0 bitsV0;
56         };
57         bitsV0.fCount = gkAliHLTDDLListSizeV0;
58         if (gkAliHLTDDLListSizeV0 != 30)
59         {
60                 cerr << "ERROR: gkAliHLTDDLListSizeV0 has a value of " << gkAliHLTDDLListSizeV0
61                         << " but expected a value of 30." << endl;
62                 return false;
63         }
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
94         
95         union
96         {
97                 AliHLTEventDDL eventddlV1;
98                 AliHLTEventDDLV1 bitsV1;
99         };
100         bitsV1.fCount = gkAliHLTDDLListSizeV1;
101         if (gkAliHLTDDLListSizeV1 != 31)
102         {
103                 cerr << "ERROR: gkAliHLTDDLListSizeV1 has a value of " << gkAliHLTDDLListSizeV1
104                         << " but expected a value of 31." << endl;
105                 return false;
106         }
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
138         
139         AliHLTReadoutList rlV0(eventddlV0);
140         AliHLTReadoutList rlV1(eventddlV1);
141         
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)
146         {
147                 Int_t ddlid = AliHLTDAQ::DdlIDOffset(i) | (j & 0xFF);
148                 if (j == 0)
149                 {
150                         if (rlV0.IsDDLDisabled(ddlid))
151                         {
152                                 cerr << "ERROR: The first DDL for detector " << AliHLTDAQ::DetectorName(i)
153                                         << " was not enabled for readout list initialised from AliHLTEventDDLV0."
154                                         << endl;
155                                 return false;
156                         }
157                         if (rlV1.IsDDLDisabled(ddlid))
158                         {
159                                 cerr << "ERROR: The first DDL for detector " << AliHLTDAQ::DetectorName(i)
160                                         << " was not enabled for readout list initialised from AliHLTEventDDLV1."
161                                         << endl;
162                                 return false;
163                         }
164                 }
165                 else
166                 {
167                         if (rlV0.IsDDLEnabled(ddlid))
168                         {
169                                 cerr << "ERROR: DDL " << ddlid << " for detector " << AliHLTDAQ::DetectorName(i)
170                                         << " was marked enabled for readout list initialised from AliHLTEventDDLV0."
171                                         << endl;
172                                 return false;
173                         }
174                         if (rlV1.IsDDLEnabled(ddlid))
175                         {
176                                 cerr << "ERROR: DDL " << ddlid << " for detector " << AliHLTDAQ::DetectorName(i)
177                                         << " was marked enabled for readout list initialised from AliHLTEventDDLV1."
178                                         << endl;
179                                 return false;
180                         }
181                 }
182         }
183         
184         // Check that the internal buffers are identical.
185         if (rlV0.BufferSize() != rlV1.BufferSize())
186         {
187                 cerr << "ERROR: Buffer sizes for readout lists are different: rlV0.BufferSize() = "
188                         << rlV0.BufferSize() << ", rlV1.BufferSize() = " << rlV1.BufferSize() << endl;
189                 return false;
190         }
191         if (memcmp(rlV0.Buffer(), rlV1.Buffer(), rlV0.BufferSize()) != 0)
192         {
193                 cerr << "ERROR: Buffers for the two readout list versions are different." << endl;
194                 return false;
195         }
196         
197         return true;
198 }
199
200 /**
201  * Tests to see if AliHLTComponent::ExtractTriggerData recognises the old format
202  * of AliHLTEventTriggerData and handles it correctly.
203  */
204 bool CheckHandlingOfOldAliHLTEventTriggerData()
205 {
206         // Prepare old structure format.
207         struct AliHLTEventTriggerDataV0
208         {
209                 AliHLTUInt8_t  fAttributes[gkAliHLTBlockDAttributeCount];
210                 AliHLTUInt64_t fHLTStatus;
211                 AliHLTUInt32_t fCommonHeaderWordCnt;
212                 AliHLTUInt32_t fCommonHeader[gkAliHLTCommonHeaderCount];
213                 AliHLTEventDDLV0 fReadoutListV0;
214         };
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
250         
251         AliHLTComponentTriggerData trigData = {
252                 sizeof(AliHLTComponentTriggerData),
253                 sizeof(AliHLTEventTriggerDataV0),
254                 &eventTrigData
255         };
256         
257         AliHLTReadoutList readoutlistExpected;
258         for (Int_t i = 0; i < AliHLTDAQ::NumberOfDetectors(); ++i)
259         {
260                 Int_t ddlid = AliHLTDAQ::DdlIDOffset(i);
261                 readoutlistExpected.EnableDDLBit(ddlid);
262         }
263         
264         const AliHLTUInt8_t (*attribs)[gkAliHLTBlockDAttributeCount];
265         AliHLTUInt64_t status = 0x0;
266         const AliRawDataHeader* cdh = NULL;
267         AliHLTReadoutList readoutlist;
268         
269         int result = AliHLTComponent::ExtractTriggerData(trigData, &attribs, &status, &cdh, &readoutlist, true);
270         if (result != 0)
271         {
272                 cerr << "ERROR: The method AliHLTComponent::ExtractTriggerData"
273                         " fails for the old structure format." << endl;
274                 return false;
275         }
276         if (attribs != &eventTrigData.fAttributes)
277         {
278                 cerr << "ERROR: The method AliHLTComponent::ExtractTriggerData"
279                         " fails to locate the attributes structure correctly." << endl;
280                 return false;
281         }
282         if (status != 0x123)
283         {
284                 cerr << "ERROR: The method AliHLTComponent::ExtractTriggerData"
285                         " fails to locate the HLT status word correctly." << endl;
286                 return false;
287         }
288         if ((const void*)cdh != (void*)&eventTrigData.fCommonHeader)
289         {
290                 cerr << "ERROR: The method AliHLTComponent::ExtractTriggerData"
291                         " fails to locate the Common Data Header (CDH) structure correctly." << endl;
292                 return false;
293         }
294         if (memcmp(readoutlist.Buffer(), readoutlistExpected.Buffer(), readoutlist.BufferSize()) != 0)
295         {
296                 cerr << "ERROR: The method AliHLTComponent::ExtractTriggerData"
297                         " fails to extract the readout list correctly." << endl;
298                 return false;
299         }
300         
301         return true;
302 }
303
304 /**
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.
308  */
309 bool CheckReadingOldFormat(const char* filename = "oldAliHLTReadoutListFormat.root")
310 {
311         TFile file(filename, "READ");
312         
313         // Load the readout list objects.
314         AliHLTReadoutList* rl[5] = {NULL, NULL, NULL, NULL, NULL};
315         for (int i = 0; i < 5; ++i)
316         {
317                 char name[1024];
318                 sprintf(name, "readoutlist%d", i+1);
319                 rl[i] = dynamic_cast<AliHLTReadoutList*>(file.Get(name));
320                 if (rl[i] == NULL)
321                 {
322                         cerr << "ERROR: Could not get object '" << name
323                                 << "' from file '" << filename << "'." << endl;
324                         return false;
325                 }
326         }
327         
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));
332         if (tree == NULL)
333         {
334                 cerr << "ERROR: Could not get TTree '" << treename
335                         << "' from file '" << filename << "'." << endl;
336                 return false;
337         }
338         AliHLTReadoutList* r = new AliHLTReadoutList;
339         tree->SetBranchAddress("readoutlist", &r);
340         for (int i = 0; i < 5; ++i)
341         {
342                 tree->GetEvent(i);
343                 if (r->BufferSize() != rl[i]->BufferSize())
344                 {
345                         cerr << "ERROR: readoutlist" << i+1
346                                 << " and the one from the TTree have different sizes."
347                                 << endl;
348                         return false;
349                 }
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.
352 #endif
353                 if (memcmp(r->Buffer(), rl[i]->Buffer(), r->BufferSize()) != 0)
354                 {
355                         cerr << "ERROR: readoutlist" << i+1
356                                 << " and the one from the TTree are different."
357                                 << endl;
358                         return false;
359                 }
360         }
361         
362         // Now check each readout list individually.
363         typedef AliHLTReadoutList RL;
364         Int_t alwaysoff = RL::kITSSPD
365                 | RL::kITSSDD
366                 | RL::kITSSSD
367                 | RL::kTPC
368                 | RL::kTRD
369                 | RL::kTOF
370                 | RL::kHMPID
371                 | RL::kPHOS
372                 | RL::kCPV
373                 | RL::kPMD
374                 | RL::kMUONTRK
375                 | RL::kMUONTRG
376                 | RL::kFMD
377                 | RL::kT0
378                 | RL::kV0
379                 | RL::kZDC
380                 | RL::kACORDE;
381         
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)
386         {
387                 for (int j = 1; j <= 3; ++j)
388                 {
389                         Int_t ddlid = AliHLTDAQ::DdlIDOffset("EMCAL") | (i & 0xFF);
390                         rl[j]->EnableDDLBit(ddlid);
391                 }
392         }
393         
394         int rlnum = 0;
395         if (not (rl[rlnum]->DetectorEnabled(RL::kTRG) and
396                  rl[rlnum]->DetectorDisabled(alwaysoff | RL::kEMCAL | RL::kDAQTEST | RL::kHLT)
397            ))
398         {
399                 rl[0]->Print();
400                 cerr << "ERROR: readoutlist" << rlnum+1 << " does not have the correct bits set." << endl;
401                 rl[rlnum]->Print();
402                 return false;
403         }
404         rlnum = 1;
405         if (not (rl[rlnum]->DetectorEnabled(RL::kTRG | RL::kEMCAL) and
406                  rl[rlnum]->DetectorDisabled(alwaysoff | RL::kDAQTEST | RL::kHLT)
407            ))
408         {
409                 cerr << "ERROR: readoutlist" << rlnum+1 << " does not have the correct bits set." << endl;
410                 rl[rlnum]->Print();
411                 return false;
412         }
413         rlnum = 2;
414         if (not (rl[rlnum]->DetectorEnabled(RL::kTRG | RL::kEMCAL | RL::kDAQTEST) and
415                  rl[rlnum]->DetectorDisabled(alwaysoff | RL::kHLT)
416            ))
417         {
418                 cerr << "ERROR: readoutlist" << rlnum+1 << " does not have the correct bits set." << endl;
419                 rl[rlnum]->Print();
420                 return false;
421         }
422         rlnum = 3;
423         if (not (rl[rlnum]->DetectorEnabled(RL::kTRG | RL::kEMCAL | RL::kDAQTEST | RL::kHLT) and
424                  rl[rlnum]->DetectorDisabled(alwaysoff)
425            ))
426         {
427                 cerr << "ERROR: readoutlist" << rlnum+1 << " does not have the correct bits set." << endl;
428                 rl[rlnum]->Print();
429                 return false;
430         }
431         rlnum = 4;
432         if (not (rl[rlnum]->DetectorEnabled(RL::kTRG | RL::kDAQTEST | RL::kHLT) and
433                  rl[rlnum]->DetectorDisabled(alwaysoff | RL::kEMCAL)
434            ))
435         {
436                 cerr << "ERROR: readoutlist" << rlnum+1 << " does not have the correct bits set." << endl;
437                 rl[rlnum]->Print();
438                 return false;
439         }
440         
441         return true;
442 }
443
444 /**
445  * Runs the unit tests for backward compatibility of AliHLTEventDDL succeeded.
446  * \returns true if the tests were passed and false otherwise.
447  */
448 bool testAliHLTEventDDLBackwardCompatibility()
449 {
450         if (not CheckReadoutListConvertedCorrectly()) return false;
451         if (not CheckHandlingOfOldAliHLTEventTriggerData()) return false;
452         if (not CheckReadingOldFormat()) return false;
453         return true;
454 }
455
456 #ifndef __MAKECINT__
457
458 int main(int /*argc*/, const char** /*argv*/)
459 {
460         bool resultOk = testAliHLTEventDDLBackwardCompatibility();
461         if (not resultOk) return 1;
462         return 0;
463 }
464
465 #endif // __MAKECINT__