1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * ALICE Experiment at CERN, All rights reserved. *
5 * Primary Authors: Artur Szostak <artursz@iafrica.com> *
6 * for The ALICE HLT Project. *
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 **************************************************************************/
18 * @file testTriggerCounterComponent.C
19 * @author Artur Szostak <artursz@iafrica.com>
22 * This macro is used to test the AliHLTTriggerCounterComponent class.
23 * Tests are run with component within the AliHLTSystem framework to check that
24 * the trigger counters are generated correctly by the component.
27 #if !defined(__CINT__) || defined(__MAKECINT__)
31 #include "AliHLTTriggerCounters.h"
32 #include "AliHLTTriggerDecision.h"
33 #include "AliHLTGlobalTriggerDecision.h"
34 #include "AliHLTSystem.h"
35 #include "AliHLTConfiguration.h"
36 #include "AliHLTCTPData.h"
37 #include "Riostream.h"
41 * Generates some sample input data and writes it into 9 files named
42 * testInputFileTriggerCounter1.root ... testInputFileTriggerCounter9.root
44 void GenerateInputData()
46 AliHLTTriggerDecision td1(true, "TRIGGER-A", AliHLTTriggerDomain("TRACKS:TPC"));
47 AliHLTTriggerDecision td1f(false, "TRIGGER-A", AliHLTTriggerDomain());
48 AliHLTTriggerDecision td2(true, "TRIGGER-B", AliHLTTriggerDomain("CLUSTERS:TPC"));
49 AliHLTTriggerDecision td2f(false, "TRIGGER-B", AliHLTTriggerDomain());
50 AliHLTTriggerDecision td3(true, "TRIGGER-C", AliHLTTriggerDomain("*******:***"));
51 AliHLTTriggerDecision td3f(false, "TRIGGER-C", AliHLTTriggerDomain());
52 AliHLTGlobalTriggerDecision gd1(true, AliHLTTriggerDomain("TRACKS:TPC"), "TRIGGER-A");
53 AliHLTGlobalTriggerDecision gd2(true, AliHLTTriggerDomain("CLUSTERS:TPC"), "TRIGGER-B");
54 AliHLTGlobalTriggerDecision gd3(true, AliHLTTriggerDomain("*******:***"), "TRIGGER-B,TRIGGER-C");
56 AliHLTCTPData ctp("CTP_TRIGGER_CLASS=00:CINTA:17,01:CINTB:00-01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17,02:CMUB:00-10-11-17");
57 gd1.AddInputObjectRef(&ctp);
58 gd2.AddInputObjectRef(&ctp);
59 gd3.AddInputObjectRef(&ctp);
61 TFile* file = new TFile("testInputFileTriggerCounter1.root", "RECREATE");
62 ctp.Increment(int(0));
63 gd1.Write("HLTGlobalTrigger");
67 file = new TFile("testInputFileTriggerCounter2.root", "RECREATE");
68 ctp.Increment(int(1));
69 gd2.Write("HLTGlobalTrigger");
70 td1f.Write("Trigger");
72 td3f.Write("Trigger");
75 file = new TFile("testInputFileTriggerCounter3.root", "RECREATE");
76 ctp.Increment(int(2));
77 gd3.Write("HLTGlobalTrigger");
78 td1f.Write("Trigger");
83 gd1.AddTriggerInput(td1);
84 gd2.AddTriggerInput(td1f);
85 gd2.AddTriggerInput(td2);
86 gd2.AddTriggerInput(td3f);
87 gd3.AddTriggerInput(td1f);
88 gd3.AddTriggerInput(td2);
89 gd3.AddTriggerInput(td3);
91 file = new TFile("testInputFileTriggerCounter4.root", "RECREATE");
92 ctp.Increment(int(0));
93 gd1.Write("HLTGlobalTrigger");
97 file = new TFile("testInputFileTriggerCounter5.root", "RECREATE");
98 ctp.Increment(int(1));
99 gd2.Write("HLTGlobalTrigger");
100 td1f.Write("Trigger");
101 td2.Write("Trigger");
104 file = new TFile("testInputFileTriggerCounter6.root", "RECREATE");
105 ctp.Increment(int(2));
106 gd3.Write("HLTGlobalTrigger");
107 td1f.Write("Trigger");
108 td2.Write("Trigger");
109 td3.Write("Trigger");
112 file = new TFile("testInputFileTriggerCounter7.root", "RECREATE");
113 ctp.Increment(int(0));
114 gd1.Write("HLTGlobalTrigger");
117 file = new TFile("testInputFileTriggerCounter8.root", "RECREATE");
118 ctp.Increment(int(1));
119 gd2.Write("HLTGlobalTrigger");
122 file = new TFile("testInputFileTriggerCounter9.root", "RECREATE");
123 ctp.Increment(int(2));
124 gd3.Write("HLTGlobalTrigger");
129 * Runs a small chain with the HLTTriggerCounter component to generate output that
131 * \param debug If true then full debug logging is enabled.
132 * \param numOfEvents The number of events to run the chain for.
134 void RunTriggerCounter(bool debug = false, int numOfEvents = 9)
137 sys.ScanOptions("ECS=CTP_TRIGGER_CLASS=00:CINTA:17,01:CINTB:00-01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17,02:CMUB:00-10-11-17");
138 sys.LoadComponentLibraries("libAliHLTUtil.so");
139 sys.LoadComponentLibraries("libAliHLTTRD.so");
140 sys.LoadComponentLibraries("libAliHLTMUON.so");
141 sys.LoadComponentLibraries("libAliHLTTrigger.so");
144 AliLog::SetGlobalLogLevel(AliLog::kMaxType);
145 sys.SetGlobalLoggingLevel(kHLTLogAll);
148 TString cmdline = "-datatype GLOBTRIG 'HLT ' -objectname HLTGlobalTrigger ";
149 for (int i = 1; i <= 9; i++)
151 if (i > 1) cmdline += " -nextevent";
152 cmdline += Form(" -datafile testInputFileTriggerCounter%d.root", i);
154 AliHLTConfiguration pub1("pub1", "ROOTFilePublisher", NULL, cmdline.Data());
155 cmdline = "-datatype TRIG_DEC 'HLT ' -objectname Trigger ";
156 for (int i = 1; i <= 9; i++)
158 if (i > 1) cmdline += " -nextevent";
159 cmdline += Form(" -datafile testInputFileTriggerCounter%d.root", i);
161 AliHLTConfiguration pub2("pub2", "ROOTFilePublisher", NULL, cmdline.Data());
162 AliHLTConfiguration proc("proc", "HLTTriggerCounter", "pub1 pub2", "-skipcdb -config InitialCounterConfig.C");
163 AliHLTConfiguration sink("sink", "ROOTFileWriter", "proc", "-datafile testOutputFileTriggerCounter.root -concatenate-events");
164 sys.BuildTaskList("sink");
165 AliHLTUInt64_t trigMask[9] = {0x1, 0x2, 0x4, 0x1, 0x2, 0x4, 0x1, 0x2, 0x4};
166 for (int i = 0; i < 9 && i < numOfEvents; i++)
169 1, // number of events
170 (i == 8 ? 1 : 0), // Stop chain at end of run.
171 trigMask[i], // Active CTP trigger mask.
179 * Checks that the input and output counters have the expected values or not.
180 * If they do not an appropriate error message is printed.
181 * \param eventNum The number of the event being checked.
182 * \param inputCounters The input counters to check.
183 * \param outputCounters The output counters to check.
184 * \param expectedInputCounters The expected input counter values to check against.
185 * \param expectedOutputCounters The expected output counter values to check against.
186 * \param expectedDescription The expected resulting trigger description.
187 * \returns true if the counters are correct and false otherwise.
191 AliHLTTriggerCounters* inputCounters,
192 AliHLTTriggerCounters* outputCounters,
193 AliHLTTriggerCounters& expectedInputCounters,
194 AliHLTTriggerCounters& expectedOutputCounters
197 if (inputCounters == NULL)
199 cerr << "ERROR: No trigger input counters were found for event "
200 << eventNum << "." << endl;
203 if (outputCounters == NULL)
205 cerr << "ERROR: No trigger output counters were found for event "
206 << eventNum << "." << endl;
209 // Copy over the Rates because these might not be identical since they are a
210 // run time parameter. The counter value and name must be identical however.
211 for (UInt_t i = 0; i < inputCounters->NumberOfCounters() && i < expectedInputCounters.NumberOfCounters(); ++i)
213 expectedInputCounters.GetCounterN(i).Rate( inputCounters->GetCounterN(i).Rate() );
215 for (UInt_t i = 0; i < outputCounters->NumberOfCounters() && i < expectedOutputCounters.NumberOfCounters(); ++i)
217 expectedOutputCounters.GetCounterN(i).Rate( outputCounters->GetCounterN(i).Rate() );
219 bool inputCountersAsExpected = (inputCounters->NumberOfCounters() == expectedInputCounters.NumberOfCounters());
220 bool outputCountersAsExpected = (outputCounters->NumberOfCounters() == expectedOutputCounters.NumberOfCounters());
221 for (UInt_t i = 0; i < inputCounters->NumberOfCounters() && i < expectedInputCounters.NumberOfCounters(); ++i)
223 if (strcmp(expectedInputCounters.GetCounterN(i).Name(), inputCounters->GetCounterN(i).Name()) != 0)
225 inputCountersAsExpected = false;
228 if (expectedInputCounters.GetCounterN(i).Counter() != inputCounters->GetCounterN(i).Counter())
230 inputCountersAsExpected = false;
234 for (UInt_t i = 0; i < outputCounters->NumberOfCounters() && i < expectedOutputCounters.NumberOfCounters(); ++i)
236 if (strcmp(expectedOutputCounters.GetCounterN(i).Name(), outputCounters->GetCounterN(i).Name()) != 0)
238 outputCountersAsExpected = false;
241 if (expectedOutputCounters.GetCounterN(i).Counter() != outputCounters->GetCounterN(i).Counter())
243 outputCountersAsExpected = false;
247 if (! inputCountersAsExpected)
249 cerr << "ERROR: The trigger input counters do not match the expected set of counters for event "
250 << eventNum << "." << endl;
251 cout << "Found the following input counters: " << endl; // using cout since Print() goes there.
252 inputCounters->Print();
253 cout << "But expected the following input counters: " << endl;
254 expectedInputCounters.Print();
257 if (! outputCountersAsExpected)
259 cerr << "ERROR: The trigger output counters do not match the expected set of counters for event "
260 << eventNum << "." << endl;
261 cout << "Found the following output counters: " << endl; // using cout since Print() goes there.
262 outputCounters->Print();
263 cout << "But expected the following output counters: " << endl;
264 expectedOutputCounters.Print();
271 /// Routine for checking the results file generated by the RunTriggerCounter routine.
272 bool CheckTriggerCounterOutput()
274 AliHLTTriggerCounters expectedInputCounters[11];
275 AliHLTTriggerCounters expectedOutputCounters[11];
277 // Start-of-run event (should contain no values)
278 expectedInputCounters[0].Add("CINTA", "", 0, 0);
279 expectedInputCounters[0].Add("CINTB", "", 0, 0);
280 expectedInputCounters[0].Add("CMUB", "", 0, 0);
281 expectedOutputCounters[0].Add("TRIGGER-A", "", 0, 0);
284 expectedInputCounters[1].Add("CINTA", "", 0, 1);
285 expectedInputCounters[1].Add("CINTB", "", 0, 0);
286 expectedInputCounters[1].Add("CMUB", "", 0, 0);
287 expectedInputCounters[1].Add("TRIGGER-A", "", 0, 1);
288 expectedOutputCounters[1].Add("TRIGGER-A", "", 0, 1);
290 expectedInputCounters[2].Add("CINTA", "", 0, 1);
291 expectedInputCounters[2].Add("CINTB", "", 0, 1);
292 expectedInputCounters[2].Add("CMUB", "", 0, 0);
293 expectedInputCounters[2].Add("TRIGGER-A", "", 0, 1);
294 expectedInputCounters[2].Add("TRIGGER-B", "", 0, 1);
295 expectedOutputCounters[2].Add("TRIGGER-A", "", 0, 1);
296 expectedOutputCounters[2].Add("TRIGGER-B", "", 0, 1);
298 expectedInputCounters[3].Add("CINTA", "", 0, 1);
299 expectedInputCounters[3].Add("CINTB", "", 0, 1);
300 expectedInputCounters[3].Add("CMUB", "", 0, 1);
301 expectedInputCounters[3].Add("TRIGGER-A", "", 0, 1);
302 expectedInputCounters[3].Add("TRIGGER-B", "", 0, 2);
303 expectedInputCounters[3].Add("TRIGGER-C", "", 0, 1);
304 expectedOutputCounters[3].Add("TRIGGER-A", "", 0, 1);
305 expectedOutputCounters[3].Add("TRIGGER-B", "", 0, 2);
306 expectedOutputCounters[3].Add("TRIGGER-C", "", 0, 1);
308 expectedInputCounters[4].Add("CINTA", "", 0, 2);
309 expectedInputCounters[4].Add("CINTB", "", 0, 1);
310 expectedInputCounters[4].Add("CMUB", "", 0, 1);
311 expectedInputCounters[4].Add("TRIGGER-A", "", 0, 2);
312 expectedInputCounters[4].Add("TRIGGER-B", "", 0, 2);
313 expectedInputCounters[4].Add("TRIGGER-C", "", 0, 1);
314 expectedOutputCounters[4].Add("TRIGGER-A", "", 0, 2);
315 expectedOutputCounters[4].Add("TRIGGER-B", "", 0, 2);
316 expectedOutputCounters[4].Add("TRIGGER-C", "", 0, 1);
318 expectedInputCounters[5].Add("CINTA", "", 0, 2);
319 expectedInputCounters[5].Add("CINTB", "", 0, 2);
320 expectedInputCounters[5].Add("CMUB", "", 0, 1);
321 expectedInputCounters[5].Add("TRIGGER-A", "", 0, 2);
322 expectedInputCounters[5].Add("TRIGGER-B", "", 0, 3);
323 expectedInputCounters[5].Add("TRIGGER-C", "", 0, 1);
324 expectedOutputCounters[5].Add("TRIGGER-A", "", 0, 2);
325 expectedOutputCounters[5].Add("TRIGGER-B", "", 0, 3);
326 expectedOutputCounters[5].Add("TRIGGER-C", "", 0, 1);
328 expectedInputCounters[6].Add("CINTA", "", 0, 2);
329 expectedInputCounters[6].Add("CINTB", "", 0, 2);
330 expectedInputCounters[6].Add("CMUB", "", 0, 2);
331 expectedInputCounters[6].Add("TRIGGER-A", "", 0, 2);
332 expectedInputCounters[6].Add("TRIGGER-B", "", 0, 4);
333 expectedInputCounters[6].Add("TRIGGER-C", "", 0, 2);
334 expectedOutputCounters[6].Add("TRIGGER-A", "", 0, 2);
335 expectedOutputCounters[6].Add("TRIGGER-B", "", 0, 4);
336 expectedOutputCounters[6].Add("TRIGGER-C", "", 0, 2);
338 expectedInputCounters[7].Add("CINTA", "", 0, 3);
339 expectedInputCounters[7].Add("CINTB", "", 0, 2);
340 expectedInputCounters[7].Add("CMUB", "", 0, 2);
341 expectedInputCounters[7].Add("TRIGGER-A", "", 0, 3);
342 expectedInputCounters[7].Add("TRIGGER-B", "", 0, 4);
343 expectedInputCounters[7].Add("TRIGGER-C", "", 0, 2);
344 expectedOutputCounters[7].Add("TRIGGER-A", "", 0, 3);
345 expectedOutputCounters[7].Add("TRIGGER-B", "", 0, 4);
346 expectedOutputCounters[7].Add("TRIGGER-C", "", 0, 2);
348 expectedInputCounters[8].Add("CINTA", "", 0, 3);
349 expectedInputCounters[8].Add("CINTB", "", 0, 3);
350 expectedInputCounters[8].Add("CMUB", "", 0, 2);
351 expectedInputCounters[8].Add("TRIGGER-A", "", 0, 3);
352 expectedInputCounters[8].Add("TRIGGER-B", "", 0, 5);
353 expectedInputCounters[8].Add("TRIGGER-C", "", 0, 2);
354 expectedOutputCounters[8].Add("TRIGGER-A", "", 0, 3);
355 expectedOutputCounters[8].Add("TRIGGER-B", "", 0, 5);
356 expectedOutputCounters[8].Add("TRIGGER-C", "", 0, 2);
358 expectedInputCounters[9].Add("CINTA", "", 0, 3);
359 expectedInputCounters[9].Add("CINTB", "", 0, 3);
360 expectedInputCounters[9].Add("CMUB", "", 0, 3);
361 expectedInputCounters[9].Add("TRIGGER-A", "", 0, 3);
362 expectedInputCounters[9].Add("TRIGGER-B", "", 0, 6);
363 expectedInputCounters[9].Add("TRIGGER-C", "", 0, 3);
364 expectedOutputCounters[9].Add("TRIGGER-A", "", 0, 3);
365 expectedOutputCounters[9].Add("TRIGGER-B", "", 0, 6);
366 expectedOutputCounters[9].Add("TRIGGER-C", "", 0, 3);
369 expectedInputCounters[10].Add("CINTA", "", 0, 3);
370 expectedInputCounters[10].Add("CINTB", "", 0, 3);
371 expectedInputCounters[10].Add("CMUB", "", 0, 3);
372 expectedInputCounters[10].Add("TRIGGER-A", "", 0, 3);
373 expectedInputCounters[10].Add("TRIGGER-B", "", 0, 6);
374 expectedInputCounters[10].Add("TRIGGER-C", "", 0, 3);
375 expectedOutputCounters[10].Add("TRIGGER-A", "", 0, 3);
376 expectedOutputCounters[10].Add("TRIGGER-B", "", 0, 6);
377 expectedOutputCounters[10].Add("TRIGGER-C", "", 0, 3);
379 TFile* file = new TFile("testOutputFileTriggerCounter.root", "READ");
380 for (int i = 0; i < 11; ++i)
382 AliHLTTriggerCounters* inputCounters = dynamic_cast<AliHLTTriggerCounters*>( file->Get(Form("AliHLTTriggerCounters;%d", i*2+1)) );
383 AliHLTTriggerCounters* outputCounters = dynamic_cast<AliHLTTriggerCounters*>( file->Get(Form("AliHLTTriggerCounters;%d", i*2+2)) );
384 if (! CheckCounters(i-1, inputCounters, outputCounters, expectedInputCounters[i], expectedOutputCounters[i]))
395 * Runs several tests for the AliHLTTriggerCounterComponent class.
396 * We specifically test if the generated counters are correctly generated.
397 * \param debug If true then full debug logging is enabled.
398 * \param numOfEvents The number of events to run the chain over.
399 * \returns true if all the tests succeeded and false otherwise.
401 bool testTriggerCounterComponent(bool debug = false, int numOfEvents = 9)
404 RunTriggerCounter(debug, numOfEvents);
405 if (! CheckTriggerCounterOutput()) return false;
406 // Cleanup all temporary files generated.
407 gSystem->Exec("rm -f testOutputFileTriggerCounter.root testInputFileTriggerCounter*.root");
414 int main(int /*argc*/, const char** /*argv*/)
416 bool resultOk = testTriggerCounterComponent();
417 if (not resultOk) return 1;
421 #endif // __MAKECINT__