]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/test/testGlobalTriggerComponent.C
transition revision for functions to be removed
[u/mrichter/AliRoot.git] / HLT / trigger / test / testGlobalTriggerComponent.C
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        *
3  * ALICE Experiment at CERN, All rights reserved.                         *
4  *                                                                        *
5  * Primary Authors: Artur Szostak <artursz@iafrica.com>                   *
6  *                  for The ALICE HLT Project.                            *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 /**
18  * @file   testGlobalTriggerComponent.C
19  * @author Artur Szostak <artursz@iafrica.com>
20  * @date   19 Dec 2008
21  *
22  * This macro is used to test the AliHLTGlobalTriggerComponent class.
23  * A number of tests are run with the AliHLTSystem framework to check that
24  * the automatically generated global trigger logic is generated correctly.
25  *
26  * This macro can also be used to debug the configuration that fails.
27  * If a configuration test fails then the global trigger logic implementation
28  * is left in a generated file with a name of the form \<AliHLTGlobalTriggerImpl_*.cxx\>.
29  * For example a file named like: AliHLTGlobalTriggerImpl_08869e64_c54b_11de_9717_0101007fbeef.cxx
30  * One can make manual modifications to this file and then rerun the test with
31  * these manual modifications with the following command in aliroot:
32  *  .x testGlobalTriggerComponent.C+(\<configVersion\>,"\<AliHLTGlobalTriggerImpl_*\>")
33  * where \<configVersion\> is the appropriate config version number as passed to the
34  * TriggerConfig.C file to initialise the configuration we want to test. Also take note
35  * that we only specify the root of the file name without the .cxx file name extention.
36  * For our example file name the command to execute in aliroot would be:
37  *  .x testGlobalTriggerComponent.C+(2,"AliHLTGlobalTriggerImpl_08869e64_c54b_11de_9717_0101007fbeef")
38  * where we are testing the 2nd trigger configuration in TriggerConfig.C.
39  */
40
41 #if defined(__CINT__) && (! defined(__MAKECINT__))
42 #error This macro must be compiled. Try running as testGlobalTriggerComponent.C++, but remember to load the libAliHLTTrigger.so library first.
43 #endif
44
45 #if !defined(__CINT__) || defined(__MAKECINT__)
46 #include "TSystem.h"
47 #include "TClassTable.h"
48 #include "TFile.h"
49 #include "AliLog.h"
50 #include "AliHLTReadoutList.h"
51 #include "AliHLTTriggerDomain.h"
52 #include "AliHLTTriggerDecision.h"
53 #include "AliHLTGlobalTriggerDecision.h"
54 #include "AliHLTEventSummary.h"
55 #include "AliHLTSystem.h"
56 #include "AliHLTConfiguration.h"
57 #include "Riostream.h"
58 #endif
59
60 /**
61  * Generates some sample input data and writes it into 8 files named
62  * testInputFile1.root ... testInputFile8.root
63  */
64 void GenerateInputData()
65 {
66         bool loadedLibs = false;
67         if (gClassTable->GetID("AliHLTGlobalTriggerComponent") < 0)
68         {
69                 gSystem->Load("libAliHLTUtil.so");
70                 gSystem->Load("libAliHLTTRD.so");
71                 gSystem->Load("libAliHLTMUON.so");
72                 gSystem->Load("libAliHLTTrigger.so");
73                 loadedLibs = true;
74         }
75
76         AliHLTReadoutList readoutList1("TPC");
77         AliHLTTriggerDomain triggerDomain1;
78         triggerDomain1.Add("CLUSTERS", "TPC ");
79         triggerDomain1.Add("TRACKS", "TPC ");
80         triggerDomain1.Add(readoutList1);
81         AliHLTTriggerDecision decision1(true, "triggerTPC", triggerDomain1, "TPC has data");
82         
83         AliHLTReadoutList readoutList2a("MUONTRK");
84         AliHLTReadoutList readoutList2b("MUONTRG");
85         AliHLTTriggerDomain triggerDomain2;
86         triggerDomain2.Add("TRACKS", "MUON");
87         triggerDomain2.Add(readoutList2a);
88         triggerDomain2.Add(readoutList2b);
89         AliHLTTriggerDecision decision2(true, "triggerMUON", triggerDomain2, "MUON has data");
90         
91         AliHLTReadoutList readoutList3("ITSSSD");
92         AliHLTTriggerDomain triggerDomain3;
93         triggerDomain3.Add("*******", "SSD ");
94         triggerDomain3.Add(readoutList3);
95         AliHLTTriggerDecision decision3(true, "triggerSSD", triggerDomain3, "SSD has data");
96         
97         AliHLTEventSummary summary1;
98         summary1.SetTriggerClass(0x1);
99         
100         AliHLTEventSummary summary2;
101         summary2.SetTriggerClass(0x2);
102         
103         TFile* file = new TFile("testInputFile1.root", "RECREATE");
104         decision1.Write("triggerTPC");
105         decision2.Write("triggerMUON");
106         decision3.Write("triggerSSD");
107         summary2.Write("summary");
108         delete file;
109         
110         file = new TFile("testInputFile2.root", "RECREATE");
111         decision1.Write("triggerTPC");
112         summary2.Write("summary");
113         delete file;
114         
115         file = new TFile("testInputFile3.root", "RECREATE");
116         decision2.Write("triggerMUON");
117         summary1.Write("summary");
118         delete file;
119         
120         file = new TFile("testInputFile4.root", "RECREATE");
121         decision3.Write("triggerSSD");
122         summary2.Write("summary");
123         delete file;
124         
125         file = new TFile("testInputFile5.root", "RECREATE");
126         decision1.Write("triggerTPC");
127         decision2.Write("triggerMUON");
128         summary1.Write("summary");
129         delete file;
130         
131         file = new TFile("testInputFile6.root", "RECREATE");
132         decision1.Write("triggerTPC");
133         decision3.Write("triggerSSD");
134         summary2.Write("summary");
135         delete file;
136         
137         file = new TFile("testInputFile7.root", "RECREATE");
138         decision2.Write("triggerMUON");
139         decision3.Write("triggerSSD");
140         summary1.Write("summary");
141         delete file;
142         
143         file = new TFile("testInputFile8.root", "RECREATE");
144         delete file;
145         
146         if (loadedLibs)
147         {
148                 gSystem->Unload("libAliHLTTrigger.so");
149                 gSystem->Unload("libAliHLTMUON.so");
150                 gSystem->Unload("libAliHLTTRD.so");
151                 gSystem->Unload("libAliHLTUtil.so");
152         }
153 }
154
155 /**
156  * Runs a small global trigger test chain with the different configuration as specified
157  * in TriggerConfig.C.
158  * \param config  The configuration version to pass to TriggerConfig.C
159  * \param usecint  If true then the global trigger component uses CINT to interpret
160  *     the code rather than compiling it.
161  * \param debug  If true then the global trigger component generates extra debug
162  *     statements in the on the fly AliHLTGlobalTriggerImp_*.cxx file.
163  * \param numOfEvents  The number of events to run the chain for.
164  * \param customClass  Names the custom class that should be loaded from the file
165  *     <i>\<customClass\>.cxx</i>. This is useful for debugging only. i.e. you can
166  *     edit a generated logic file and test it by hand.
167  */
168 void RunTrigger(int config = 0, bool usecint = false, bool debug = false, int numOfEvents = 8, const char* customClass = NULL)
169 {
170         AliHLTSystem sys;
171         sys.ScanOptions("ECS=CTP_TRIGGER_CLASS=00:TRIGGER-ALL:00-01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17");
172         sys.LoadComponentLibraries("libAliHLTUtil.so");
173         sys.LoadComponentLibraries("libAliHLTTRD.so");
174         sys.LoadComponentLibraries("libAliHLTMUON.so");
175         sys.LoadComponentLibraries("libAliHLTTrigger.so");
176         if (debug)
177         {
178                 AliLog::SetGlobalLogLevel(AliLog::kMaxType);
179                 sys.SetGlobalLoggingLevel(kHLTLogAll);
180         }
181         
182         TString cmdline = "-datatype ROOTTOBJ 'HLT ' ";
183         for (int i = 1; i <= 8; i++)
184         {
185                 if (i > 1) cmdline += " -nextevent";
186                 cmdline += Form(" -datafile testInputFile%d.root", i);
187         }
188         AliHLTConfiguration pub("pub", "ROOTFilePublisher", NULL, cmdline.Data());
189         
190         cmdline = Form("-config $ALICE_ROOT/HLT/trigger/test/TriggerConfig.C(%d)"
191                 " -includepath $ALICE_ROOT/include -includepath $ALICE_ROOT/HLT/BASE"
192                 " -includepath $ALICE_ROOT/HLT/trigger -include AliHLTEventSummary.h",
193                 config
194                 );
195         if (customClass != NULL) cmdline += Form(" -usecode %s.cxx %s", customClass, customClass);
196         if (usecint) cmdline += " -cint";
197         if (debug) cmdline += " -debug";
198         AliHLTConfiguration proc("proc", "HLTGlobalTrigger", "pub", cmdline.Data());
199         
200         AliHLTConfiguration sink("sink", "ROOTFileWriter", "proc", "-datafile testOutputFile.root -concatenate-events");
201         
202         sys.BuildTaskList("sink");
203         sys.Run(
204                 numOfEvents,
205                 1,   // Stop chain at end of run.
206                 0x1, // Active CTP trigger mask.
207                 0,   // Time stamp.
208                 0    // Event type.
209         );
210 }
211
212 /**
213  * This method calls the RunTrigger method in an independant aliroot process.
214  * This is necessary since we get memory corruption if we run too many instances of
215  * AliHLTSystem in the same process.
216  */
217 void CallRunTrigger(
218                 int config = 0, bool usecint = false, bool debug = false,
219                 int numOfEvents = 8, const char* customClass = NULL,
220                 bool showOutput = false
221         )
222 {
223         const char* redirection = "> /dev/null";
224         const char* classNameString = "NULL";
225         if (showOutput) redirection = "";
226         if (customClass != NULL) classNameString = Form("\"%s\"", customClass);
227         const char* command = Form(
228                         "aliroot %s <<EOF\n"
229                         "gSystem->Load(\"libAliHLTUtil.so\");\n"
230                         "gSystem->Load(\"libAliHLTTRD.so\");\n"
231                         "gSystem->Load(\"libAliHLTMUON.so\");\n"
232                         "gSystem->Load(\"libAliHLTTrigger.so\");\n"
233                         "gSystem->SetIncludePath(\"-I${ALICE_ROOT}/include"
234                         " -I${ALICE_ROOT}/HLT/BASE -I${ALICE_ROOT}/HLT/trigger\");\n"
235                         ".L $ALICE_ROOT/HLT/trigger/test/testGlobalTriggerComponent.C+\n"
236                         "RunTrigger(%d,%d,%d,%d,%s);\n"
237                         "EOF\n",
238                         redirection,
239                         config,
240                         usecint,
241                         debug,
242                         numOfEvents,
243                         classNameString
244                 );
245         gSystem->Exec(command);
246 }
247
248 /**
249  * Checks that a particular decision is as expected and prints error messages
250  * if it is not.
251  * \param testName  The name of the test being run.
252  * \param eventNum  The number of the event being checked.
253  * \param decision  The global trigger decision being checked.
254  * \param expectedResult  The expected global trigger result.
255  * \param expectedDomain  The expected resulting global trigger domain.
256  * \param expectedDescription  The expected resulting trigger description.
257  * \returns true if the decision is as expected.
258  */
259 bool Check(
260                 const char* testName,
261                 int eventNum,
262                 AliHLTGlobalTriggerDecision* decision,
263                 bool expectedResult,
264                 AliHLTTriggerDomain expectedDomain,
265                 TString expectedDescription
266         )
267 {
268         if (decision == NULL)
269         {
270                 cerr << "ERROR (Test: " << testName
271                      << "): No decision found where expected for event "
272                      << eventNum << "." << endl;
273                 return false;
274         }
275         if (decision->Result() != expectedResult)
276         {
277                 cerr << "ERROR (Test: " << testName
278                      << "): The result does not match the expected value for event "
279                      << eventNum << ". Got " << decision->Result() << " but expected "
280                      << expectedResult << "." << endl;
281                 return false;
282         }
283         if (decision->TriggerDomain() != expectedDomain)
284         {
285                 cerr << "ERROR (Test: " << testName
286                      << "): The domain does not match the expected value for event "
287                      << eventNum << ". Got:" << endl;
288                 decision->TriggerDomain().Print();
289                 cerr << "but expected:" << endl;
290                 expectedDomain.Print();
291                 return false;
292         }
293         if (decision->Description() != expectedDescription)
294         {
295                 cerr << "ERROR (Test: " << testName
296                      << "): The description does not match the expected value for event "
297                      << eventNum << ". Got '" << decision->Description() << "' but expected '"
298                      << expectedDescription << "'." << endl;
299                 return false;
300         }
301         return true;
302 }
303
304
305 /// Routine for checking the result of the PriorityGroupTestConfig() config in TriggerConfig.C
306 bool CheckPriorityGroupTestConfig(const char* testName = "Priority group config")
307 {
308         AliHLTGlobalTriggerDecision* decision = NULL;
309         bool result = false;
310         
311         AliHLTTriggerDomain domainTPC("CLUSTERS:TPC ,TRACKS:TPC ");
312         domainTPC.Add(AliHLTReadoutList("TPC"));
313         AliHLTTriggerDomain domainMUON("TRACKS:MUON");
314         domainMUON.Add(AliHLTReadoutList("MUONTRK"));
315         domainMUON.Add(AliHLTReadoutList("MUONTRG"));
316         AliHLTTriggerDomain domainSSD("*******:SSD ");
317         domainSSD.Add(AliHLTReadoutList("ITSSSD"));
318
319         TFile* file = new TFile("testOutputFile.root", "READ");
320         
321         // Triggers in events (i.e. input triggers):
322         // event 1: TPC MUON SSD
323         // event 2: TPC
324         // event 3: MUON
325         // event 4: SSD
326         // event 5: TPC MUON
327         // event 6: TPC SSD
328         // event 7: MUON SSD
329         // event 8: (empty)
330         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;1"));
331         result = Check(testName, 1, decision, true, domainSSD, "Fast SSD trigger");
332         if (! result) goto cleanup;
333         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;2"));
334         result = Check(testName, 2, decision, true, domainTPC, "TPC trigger");
335         if (! result) goto cleanup;
336         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;3"));
337         result = Check(testName, 3, decision, true, domainMUON, "MUON trigger");
338         if (! result) goto cleanup;
339         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;4"));
340         result = Check(testName, 4, decision, true, domainSSD, "MUON trigger");
341         if (! result) goto cleanup;
342         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;5"));
343         result = Check(testName, 5, decision, true, domainMUON, "MUON trigger");
344         if (! result) goto cleanup;
345         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;6"));
346         result = Check(testName, 6, decision, true, domainSSD, "Fast SSD trigger");
347         if (! result) goto cleanup;
348         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;7"));
349         result = Check(testName, 7, decision, true, domainMUON | domainSSD, "MUON trigger");
350         if (! result) goto cleanup;
351         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;8"));
352         result = Check(testName, 8, decision, false, AliHLTTriggerDomain(), "No trigger");
353         if (! result) goto cleanup;
354         
355         delete file;
356         return true;
357         
358 cleanup:
359         if (decision != NULL)
360         {
361                 cout << "========== Dumping incorrect decision ========== " << endl;
362                 decision->Print();
363         }
364         delete file;
365         return false;
366 }
367
368
369 /// Routine for checking the result of the SingleGroupTestConfig() config in TriggerConfig.C
370 bool CheckSingleGroupTestConfig(const char* testName = "Single group config")
371 {
372         AliHLTGlobalTriggerDecision* decision = NULL;
373         bool result = false;
374         
375         AliHLTTriggerDomain domainTPC("CLUSTERS:TPC ,TRACKS:TPC ");
376         domainTPC.Add(AliHLTReadoutList("TPC"));
377         AliHLTTriggerDomain domainMUON("TRACKS:MUON");
378         domainMUON.Add(AliHLTReadoutList("MUONTRK"));
379         domainMUON.Add(AliHLTReadoutList("MUONTRG"));
380         AliHLTTriggerDomain domainSSD("*******:SSD ");
381         domainSSD.Add(AliHLTReadoutList("ITSSSD"));
382
383         TFile* file = new TFile("testOutputFile.root", "READ");
384         
385         // Triggers in events (i.e. input triggers):
386         // event 1: TPC MUON SSD
387         // event 2: TPC
388         // event 3: MUON
389         // event 4: SSD
390         // event 5: TPC MUON
391         // event 6: TPC SSD
392         // event 7: MUON SSD
393         // event 8: (empty)
394         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;1"));
395         result = Check(testName, 1, decision, true, domainTPC | domainMUON | domainSSD, "TPC trigger,MUON trigger,SSD trigger");
396         if (! result) goto cleanup;
397         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;2"));
398         result = Check(testName, 2, decision, true, domainTPC, "TPC trigger");
399         if (! result) goto cleanup;
400         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;3"));
401         result = Check(testName, 3, decision, true, domainMUON, "MUON trigger");
402         if (! result) goto cleanup;
403         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;4"));
404         result = Check(testName, 4, decision, true, domainSSD, "SSD trigger");
405         if (! result) goto cleanup;
406         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;5"));
407         result = Check(testName, 5, decision, true, domainTPC | domainMUON, "TPC trigger,MUON trigger");
408         if (! result) goto cleanup;
409         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;6"));
410         result = Check(testName, 6, decision, true, domainTPC | domainSSD, "TPC trigger,SSD trigger");
411         if (! result) goto cleanup;
412         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;7"));
413         result = Check(testName, 7, decision, true, domainMUON | domainSSD, "MUON trigger,SSD trigger");
414         if (! result) goto cleanup;
415         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;8"));
416         result = Check(testName, 8, decision, false, AliHLTTriggerDomain(), "");
417         if (! result) goto cleanup;
418         
419         delete file;
420         return true;
421         
422 cleanup:
423         if (decision != NULL)
424         {
425                 cout << "========== Dumping incorrect decision ========== " << endl;
426                 decision->Print();
427         }
428         delete file;
429         return false;
430 }
431
432
433 /// Routine for checking the result of the PrescalarTestConfig() config in TriggerConfig.C
434 bool CheckPrescalarTestConfig(const char* testName = "Prescalar config")
435 {
436         AliHLTGlobalTriggerDecision* decision = NULL;
437         bool result = false;
438         
439         AliHLTTriggerDomain domainTPC("CLUSTERS:TPC ,TRACKS:TPC ");
440         domainTPC.Add(AliHLTReadoutList("TPC"));
441         AliHLTTriggerDomain domainMUON("TRACKS:MUON");
442         domainMUON.Add(AliHLTReadoutList("MUONTRK"));
443         domainMUON.Add(AliHLTReadoutList("MUONTRG"));
444         AliHLTTriggerDomain domainSSD("*******:SSD ");
445         domainSSD.Add(AliHLTReadoutList("ITSSSD"));
446         AliHLTTriggerDomain defaultDomain("*******:HLT ");
447
448         TFile* file = new TFile("testOutputFile.root", "READ");
449         
450         // Triggers in events (i.e. input triggers):
451         // event 1: TPC MUON SSD
452         // event 2: TPC
453         // event 3: MUON
454         // event 4: SSD
455         // event 5: TPC MUON
456         // event 6: TPC SSD
457         // event 7: MUON SSD
458         // event 8: (empty)
459         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;1"));
460         result = Check(testName, 1, decision, true, domainTPC, "TPC trigger");
461         if (! result) goto cleanup;
462         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;2"));
463         result = Check(testName, 2, decision, false, defaultDomain, "No trigger");
464         if (! result) goto cleanup;
465         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;3"));
466         result = Check(testName, 3, decision, true, domainMUON, "MUON trigger");
467         if (! result) goto cleanup;
468         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;4"));
469         result = Check(testName, 4, decision, false, defaultDomain, "No trigger");
470         if (! result) goto cleanup;
471         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;5"));
472         result = Check(testName, 5, decision, true, domainMUON, "MUON trigger");
473         if (! result) goto cleanup;
474         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;6"));
475         result = Check(testName, 6, decision, true, domainTPC, "TPC trigger");
476         if (! result) goto cleanup;
477         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;7"));
478         result = Check(testName, 7, decision, true, domainMUON, "MUON trigger");
479         if (! result) goto cleanup;
480         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;8"));
481         result = Check(testName, 8, decision, false, defaultDomain, "No trigger");
482         if (! result) goto cleanup;
483         
484         delete file;
485         return true;
486         
487 cleanup:
488         if (decision != NULL)
489         {
490                 cout << "========== Dumping incorrect decision ========== " << endl;
491                 decision->Print();
492         }
493         delete file;
494         return false;
495 }
496
497
498 /// Routine for checking the result of the SymbolTestConfig() config in TriggerConfig.C
499 bool CheckSymbolTestConfig(const char* testName = "Symbol config")
500 {
501         AliHLTGlobalTriggerDecision* decision = NULL;
502         bool result = false;
503         
504         AliHLTTriggerDomain domainAll("*******:***,-DAQRDOUT:TST");
505         AliHLTTriggerDomain domainPHOS("CLUSTERS:PHOS,TRACKS:PHOS");
506         AliHLTTriggerDomain domainTPC("CLUSTERS:TPC ,TRACKS:TPC ");
507         domainTPC.Add(AliHLTReadoutList("TPC"));
508         AliHLTTriggerDomain domainMUON("TRACKS:MUON");
509         domainMUON.Add(AliHLTReadoutList("MUONTRK"));
510         domainMUON.Add(AliHLTReadoutList("MUONTRG"));
511         AliHLTTriggerDomain domainSSD("*******:SSD ");
512         domainSSD.Add(AliHLTReadoutList("ITSSSD"));
513
514         TFile* file = new TFile("testOutputFile.root", "READ");
515         
516         // Triggers in events (i.e. input triggers) and trigger classes in AliHLTEventSummary:
517         // event 1: TPC MUON SSD, 0x2
518         // event 2: TPC         , 0x2
519         // event 3: MUON        , 0x1
520         // event 4: SSD         , 0x2
521         // event 5: TPC MUON    , 0x1
522         // event 6: TPC SSD     , 0x2
523         // event 7: MUON SSD    , 0x1
524         // event 8: (empty)     , 0x0
525         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;1"));
526         result = Check(testName, 1, decision, true, domainAll - AliHLTTriggerDomain("DAQRDOUT:EMC"), "Pass through");
527         if (! result) goto cleanup;
528         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;2"));
529         result = Check(testName, 2, decision, true, domainTPC | domainPHOS, "Trigger class 2");
530         if (! result) goto cleanup;
531         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;3"));
532         result = Check(testName, 3, decision, false, AliHLTTriggerDomain(), "");
533         if (! result) goto cleanup;
534         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;4"));
535         result = Check(testName, 4, decision, true, domainPHOS, "Trigger class 2");
536         if (! result) goto cleanup;
537         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;5"));
538         result = Check(testName, 5, decision, true, domainAll - AliHLTTriggerDomain("DAQRDOUT:EMC"), "Pass through");
539         if (! result) goto cleanup;
540         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;6"));
541         result = Check(testName, 6, decision, true, domainTPC | domainPHOS, "Trigger class 2");
542         if (! result) goto cleanup;
543         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;7"));
544         result = Check(testName, 7, decision, false, AliHLTTriggerDomain(), "");
545         if (! result) goto cleanup;
546         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;8"));
547         result = Check(testName, 8, decision, false, AliHLTTriggerDomain(), "");
548         if (! result) goto cleanup;
549         
550         delete file;
551         return true;
552         
553 cleanup:
554         if (decision != NULL)
555         {
556                 cout << "========== Dumping incorrect decision ========== " << endl;
557                 decision->Print();
558         }
559         delete file;
560         return false;
561 }
562
563
564 /// Routine for checking the result of the ComplexTestConfig() config in TriggerConfig.C
565 bool CheckComplexTestConfig(const char* testName = "Complex config")
566 {
567         AliHLTGlobalTriggerDecision* decision = NULL;
568         bool result = false;
569         
570         AliHLTTriggerDomain domainAll("*******:***,-DAQRDOUT:TST,-DAQRDOUT:EMC");
571         AliHLTTriggerDomain domainPHOS("CLUSTERS:PHOS,TRACKS:PHOS");
572         AliHLTTriggerDomain domainTPC("CLUSTERS:TPC ,TRACKS:TPC ");
573         domainTPC.Add(AliHLTReadoutList("TPC"));
574         AliHLTTriggerDomain domainMUON("TRACKS:MUON");
575         domainMUON.Add(AliHLTReadoutList("MUONTRK"));
576         domainMUON.Add(AliHLTReadoutList("MUONTRG"));
577         AliHLTTriggerDomain domainSSD("*******:SSD ");
578         domainSSD.Add(AliHLTReadoutList("ITSSSD"));
579
580         TFile* file = new TFile("testOutputFile.root", "READ");
581         
582         // Triggers in events (i.e. input triggers) and trigger classes in AliHLTEventSummary:
583         // event 1: TPC MUON SSD, 0x2
584         // event 2: TPC         , 0x2
585         // event 3: MUON        , 0x1
586         // event 4: SSD         , 0x2
587         // event 5: TPC MUON    , 0x1
588         // event 6: TPC SSD     , 0x2
589         // event 7: MUON SSD    , 0x1
590         // event 8: (empty)     , 0x0
591         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;1"));
592         result = Check(testName, 1, decision, true, domainAll, "Pass through");
593         if (! result) goto cleanup;
594         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;2"));
595         result = Check(testName, 2, decision, true, domainTPC, "Slow trigger");
596         if (! result) goto cleanup;
597         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;3"));
598         result = Check(testName, 3, decision, true, domainMUON, "MUON trigger 2");
599         if (! result) goto cleanup;
600         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;4"));
601         result = Check(testName, 4, decision, true, domainSSD | domainPHOS, "SSD trigger 2");
602         if (! result) goto cleanup;
603         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;5"));
604         result = Check(testName, 5, decision, true, domainMUON, "MUON trigger 2");
605         if (! result) goto cleanup;
606         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;6"));
607         result = Check(testName, 6, decision, true, domainSSD | domainPHOS, "SSD trigger 2");
608         if (! result) goto cleanup;
609         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;7"));
610         result = Check(testName, 7, decision, true, domainSSD | domainMUON, "SSD trigger 1,MUON trigger 1");
611         if (! result) goto cleanup;
612         decision = dynamic_cast<AliHLTGlobalTriggerDecision*>(file->Get("HLTGlobalTrigger;8"));
613         result = Check(testName, 8, decision, true, domainAll, "Pass through");
614         if (! result) goto cleanup;
615         
616         delete file;
617         return true;
618         
619 cleanup:
620         if (decision != NULL)
621         {
622                 cout << "========== Dumping incorrect decision ========== " << endl;
623                 decision->Print();
624         }
625         delete file;
626         return false;
627 }
628
629
630 typedef bool (*CheckFunctionType)(const char* testName);
631
632 /**
633  * This will check the results of a global trigger run with a particular checking
634  * routine and for different combinations of -cint and -debug flags passed to the
635  * global trigger component.
636  * It is important to check these flag combinations to make sure that everything
637  * is functioning the same under all the different combinations as it should.
638  * \param function  The checking routine to use.
639  * \param version  The trigger menu configuration version to use in <i>RunTrigger</i>.
640  * \param testName  The name of the test being run.
641  * \param numOfEvents  The number of events to run the chain for.
642  * \param customClass  Name of the custom class as passed to <i>RunTrigger</i>.
643  * \param showOutput  If true then the output from the RunTrigger method is not suppressed.
644  * \returns true if the different checks succeeded and false otherwise.
645  */
646 bool CheckDifferentModes(
647                 CheckFunctionType function, int version, const char* testName,
648                 int numOfEvents = 8, const char* customClass = NULL,
649                 bool showOutput = false
650         )
651 {
652         TString name = testName;
653         name += " in debug mode";
654         cout << "#################### Running test: " << name.Data() << " ####################" << endl;
655         CallRunTrigger(version, false, true, numOfEvents, customClass, showOutput);
656         if (! function(testName)) return false;
657         gSystem->Exec("rm -f testOutputFile.root");  // Cleanup output file for next test.
658         
659         name = testName;
660         cout << "#################### Running test: " << name.Data() << " ####################" << endl;
661         CallRunTrigger(version, false, false, numOfEvents, customClass, showOutput);
662         if (! function(testName)) return false;
663         gSystem->Exec("rm -f testOutputFile.root");  // Cleanup output file for next test.
664         
665         name = testName;
666         name += " interpreted with CINT in debug mode";
667         cout << "#################### Running test: " << name.Data() << " ####################" << endl;
668         CallRunTrigger(version, true, true, numOfEvents, customClass, showOutput);
669         if (! function(testName)) return false;
670         gSystem->Exec("rm -f testOutputFile.root");  // Cleanup output file for next test.
671         
672         name = testName;
673         name += " interpreted with CINT";
674         cout << "#################### Running test: " << name.Data() << " ####################" << endl;
675         CallRunTrigger(version, true, false, numOfEvents, customClass, showOutput);
676         if (! function(testName)) return false;
677         gSystem->Exec("rm -f testOutputFile.root");  // Cleanup output file for next test.
678         
679         return true;
680 }
681
682 /**
683  * Runs several tests for the AliHLTGlobalTriggerComponent class.
684  * We specifically test if the global trigger menu configuration is interpreted
685  * correctly and the trigger logic generated correctly on the fly.
686  * \param configVersion  The appropriate version number of the config being tested
687  *     which is passed to TriggerConfig.C.
688  * \param customClass  Name of the custom class as passed to <i>CheckDifferentModes</i>.
689  * \returns true if the different checks succeeded and false otherwise.
690  * \param numOfEvents  The number of events to run the chain for.
691  * \returns true if all the tests succeeded and false otherwise.
692  */
693 bool testGlobalTriggerComponent(int configVersion = -1, const char* customClass = NULL, int numOfEvents = 8)
694 {
695         GenerateInputData();
696         
697         if (configVersion != -1)
698         {
699                 CheckFunctionType function = NULL;
700                 switch (configVersion)
701                 {
702                 case 0: function = CheckPriorityGroupTestConfig; break;
703                 case 1: function = CheckSingleGroupTestConfig; break;
704                 case 2: function = CheckPrescalarTestConfig; break;
705                 case 3: function = CheckSymbolTestConfig; break;
706                 case 4: function = CheckComplexTestConfig; break;
707                 default:
708                         cerr << "ERROR: Invalid value for configVersion specified." << endl;
709                         return false;
710                 }
711                 bool result = CheckDifferentModes(
712                                 function,
713                                 configVersion,
714                                 Form("Config version %d", configVersion),
715                                 numOfEvents,
716                                 customClass,
717                                 true
718                         );
719                 return result;
720         }
721         
722         if (! CheckDifferentModes(CheckPriorityGroupTestConfig, 0, "Priority group config", numOfEvents, customClass)) return false;
723         if (! CheckDifferentModes(CheckSingleGroupTestConfig, 1, "Single group config", numOfEvents, customClass)) return false;
724         if (! CheckDifferentModes(CheckPrescalarTestConfig, 2, "Prescalar config", numOfEvents, customClass)) return false;
725         if (! CheckDifferentModes(CheckSymbolTestConfig, 3, "Symbol config", numOfEvents, customClass)) return false;
726         if (! CheckDifferentModes(CheckComplexTestConfig, 4, "Complex config", numOfEvents, customClass)) return false;
727         
728         // Cleanup all temporary files generated.
729         gSystem->Exec("rm -f testOutputFile.root testInputFile*.root AliHLTGlobalTriggerImpl*");
730         return true;
731 }
732
733
734 #ifndef __MAKECINT__
735
736 int main(int /*argc*/, const char** /*argv*/)
737 {
738         bool resultOk = testGlobalTriggerComponent();
739         if (not resultOk) return 1;
740         return 0;
741 }
742
743 #endif // __MAKECINT__