Adding default option to read lookup tables for reconstruction directly from the...
[u/mrichter/AliRoot.git] / HLT / MUON / macros / RunChain.C
CommitLineData
cc76079a 1/**************************************************************************
1b3806c8 2 * This file is property of and copyright by the ALICE HLT Project *
cc76079a 3 * All rights reserved. *
4 * *
5 * Primary Authors: *
6 * Artur Szostak <artursz@iafrica.com> *
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
1b3806c8 17/* $Id$ */
18
19/**
20 * \ingroup macros
21 * \file RunChain.C
22 * \brief Macro for running the dHLT chain in a standalone mode.
23 *
24 * This macro is used to run the dHLT component chain within the AliHLTSystem
cc76079a 25 * framework, which is a simulation of the dHLT online system's output.
26 * To run this macro you must be in the same directory as the galice.root
27 * files or in the directory containing the rawXX/ directories produced from
28 * AliRoot simulations.
1b3806c8 29 * Also make sure you specify CDB as for the lutDir (lookup table directory)
30 * or that the appropriate LUTs are in the same directory as your working
31 * directory, or you can specify the directory with the lutDir parameter option.
32 *
33 * The simplest way to run this macro with defaults is to copy "rootlogon.C" from
34 * $ALICE_ROOT/HLT/MUON/macros into your current working directory, then from
35 * the shell command prompt run the following command:
36 * \code
37 * > aliroot -b -q -l $ALICE_ROOT/HLT/MUON/macros/RunChain.C+
38 * \endcode
39 *
40 * \author Artur Szostak <artursz@iafrica.com>
cc76079a 41 */
42
43#if !defined(__CINT__) || defined(__MAKECINT__)
44#include "HLT/BASE/AliHLTSystem.h"
45#include "HLT/BASE/AliHLTConfiguration.h"
46#include "AliLog.h"
47#include "TString.h"
48#include <iostream>
49using std::cerr;
50using std::endl;
51#endif
52
1b3806c8 53/**
54 * Used to run the dimuon HLT (dHLT) chain in various configuration in a standalone
55 * configuration. This is normally used for debugging, testing and can also be used
56 * as an example of how to build chains for dHLT by hand.
57 *
58 * @param chainType Specifies the type of chain to run. This can be one of the
cc76079a 59 * following:
60 * "full" - Run the full dHLT chain. (default)
61 * "ddlreco" - Run only the reconstruction of the DDL raw data up to hits
62 * and trigger records.
63 * "tracker" - Run the tracker only using hits and trigger records from
64 * AliRoot simulation or offline reconstruction.
65 * @param firstEvent The event number of the first event to process. (default = 0)
66 * @param lastEvent The event number of the last event to process. If this is
67 * less than firstEvent then it is set to firstEvent automatically. (default = -1)
1f50d9b1 68 * @param output Specifies the kind of output to generate. The options can be one
69 * of the following:
70 * "bin" - Generates all possible output and dumps it to binary files
71 * using the FileWriter component.
72 * "root" - Generates all possible output and writes it to a ROOT file
73 * using the ROOTFileWriter component.
74 * "tracks_bin" - Generates only track data and dumps it to binary files
75 * using the FileWriter component. This option is equivalent to
76 * 'bin' if the chain type is 'ddlreco'.
77 * "tracks_root" - Generates only track data and writes it to a ROOT file
78 * using the ROOTFileWriter component. This option is equivalent
79 * to 'bin' if the chain type is 'ddlreco'.
cc76079a 80 * @param dataSource This is the data source from which to use hits and trigger
81 * records when we are running the tracker only chain. Note this parameter
82 * only makes sense if chainType = "tracker". The possible options are:
83 * "sim" - Take data from GEANT hits. (default)
84 * "rec" - Take data from offline reconstructed hits and local trigger
85 * objects.
86 * @param logLevel Specifies the amount of logging messages produced by the HLT
87 * system. The possible options are:
88 * "normal" - Shows warnings, errors and information.
89 * "max" - Shows everything including debug messages if they were compiled in.
90 * "min" - Shows only error messages.
1f50d9b1 91 * @param lutDir This is the directory in which the LUTs can be found.
1b3806c8 92 * If it is set to "CDB" (case sensitive) then the LUTs will be loaded from
93 * CDB instead. The default behaviour is to read from the local CDB store.
cc76079a 94 */
95void RunChain(
96 const char* chainType = "full",
97 Int_t firstEvent = 0,
98 Int_t lastEvent = -1,
1f50d9b1 99 const char* output = "bin",
cc76079a 100 const char* dataSource = "sim",
1f50d9b1 101 const char* logLevel = "normal",
1b3806c8 102 const char* lutDir = "CDB"
cc76079a 103 )
104{
105 // Make sure that the lastEvent is greater than firstEvent.
106 if (lastEvent < firstEvent)
107 lastEvent = firstEvent;
108 int eventCount = lastEvent - firstEvent + 1;
109
110 bool buildDDLFilePubs = false;
111 bool buildDDLRecoComps = false;
112 bool buildSimDataPubs = false;
113 bool buildRecDataPubs = false;
cc76079a 114 bool buildTrackerComp = false;
1b3806c8 115 bool defaultLogging = true;
cc76079a 116 bool maxLogging = false;
117 bool minLogging = false;
1f50d9b1 118 bool useRootWriter = false;
119 bool makeTracksOnly = false;
120
121 // Parse the chainType, output, dataSource and logLevel option strings:
122 TString outOpt = output;
123 if (outOpt.CompareTo("bin", TString::kIgnoreCase) == 0)
124 {
125 useRootWriter = false;
126 }
127 else if (outOpt.CompareTo("root", TString::kIgnoreCase) == 0)
128 {
129 useRootWriter = true;
130 }
131 else if (outOpt.CompareTo("tracks_bin", TString::kIgnoreCase) == 0)
132 {
133 useRootWriter = false;
134 makeTracksOnly = true;
135 }
136 else if (outOpt.CompareTo("tracks_root", TString::kIgnoreCase) == 0)
137 {
138 useRootWriter = true;
139 makeTracksOnly = true;
140 }
141 else
142 {
143 cerr << "ERROR: Unknown option for output: " << output << endl;
144 return;
145 }
cc76079a 146
cc76079a 147 TString chainOpt = chainType;
148 if (chainOpt.CompareTo("full", TString::kIgnoreCase) == 0)
149 {
150 buildDDLFilePubs = true;
151 buildDDLRecoComps = true;
152 buildTrackerComp = true;
cc76079a 153 }
1f50d9b1 154 else if (chainOpt.CompareTo("ddlreco", TString::kIgnoreCase) == 0)
cc76079a 155 {
156 buildDDLFilePubs = true;
157 buildDDLRecoComps = true;
cc76079a 158 }
159 else if (chainOpt.CompareTo("tracker", TString::kIgnoreCase) == 0)
160 {
cc76079a 161 buildTrackerComp = true;
1f50d9b1 162
cc76079a 163 TString dataOpt = dataSource;
164 if (dataOpt.CompareTo("sim", TString::kIgnoreCase) == 0)
165 {
166 buildSimDataPubs = true;
167 }
168 else if (dataOpt.CompareTo("rec", TString::kIgnoreCase) == 0)
169 {
170 buildRecDataPubs = true;
171 }
172 else
173 {
174 cerr << "ERROR: Unknown option for dataSource: " << dataSource << endl;
175 return;
176 }
177 }
1f50d9b1 178 else
179 {
180 cerr << "ERROR: Unknown option for chainType: " << chainType << endl;
181 return;
182 }
cc76079a 183
184 TString logOpt = logLevel;
a563b588 185 if (logOpt.CompareTo("normal", TString::kIgnoreCase) == 0)
cc76079a 186 {
187 // nothing to do.
188 }
a563b588 189 else if (logOpt.CompareTo("max", TString::kIgnoreCase) == 0)
cc76079a 190 {
191 maxLogging = true;
192 }
a563b588 193 else if (logOpt.CompareTo("min", TString::kIgnoreCase) == 0)
cc76079a 194 {
195 minLogging = true;
196 }
197 else
198 {
199 cerr << "ERROR: Unknown option for logLevel: " << logLevel << endl;
200 return;
201 }
202
1f50d9b1 203 // If we are supposed to make tracks only but are in a ddlreco chain
204 // then we clearly can only generate the DDL reconstructed data, so do that.
205 if (makeTracksOnly && ! buildTrackerComp)
206 {
207 makeTracksOnly = false;
208 }
209
cc76079a 210 // Now we can initialise the AliHLTSystem...
211 AliHLTSystem sys;
cc76079a 212
213 // Start by setting up the logging.
214 if (maxLogging)
215 {
216 AliLog::SetGlobalLogLevel(AliLog::kMaxType);
217 sys.SetGlobalLoggingLevel(kHLTLogAll);
218 }
219 if (minLogging)
220 {
1b3806c8 221 sys.SetGlobalLoggingLevel(AliHLTComponentLogSeverity(
222 kHLTLogFatal | kHLTLogError
223 ));
cc76079a 224 }
a563b588 225
1927abc3 226 sys.LoadComponentLibraries("libAliHLTUtil.so");
a563b588 227 sys.LoadComponentLibraries("libAliHLTMUON.so");
cc76079a 228
229 // The DDL file publishers are only needed if we create the ddlreco or
230 // full chains. The filename lists are built assuming the aliroot rawXX/
231 // directory structure.
232 if (buildDDLFilePubs)
233 {
668eee9f 234 string cmd13 = "-datatype 'DDL_RAW ' 'MUON' -dataspec 0x001000";
235 string cmd14 = "-datatype 'DDL_RAW ' 'MUON' -dataspec 0x002000";
236 string cmd15 = "-datatype 'DDL_RAW ' 'MUON' -dataspec 0x004000";
237 string cmd16 = "-datatype 'DDL_RAW ' 'MUON' -dataspec 0x008000";
238 string cmd17 = "-datatype 'DDL_RAW ' 'MUON' -dataspec 0x010000";
239 string cmd18 = "-datatype 'DDL_RAW ' 'MUON' -dataspec 0x020000";
240 string cmd19 = "-datatype 'DDL_RAW ' 'MUON' -dataspec 0x040000";
241 string cmd20 = "-datatype 'DDL_RAW ' 'MUON' -dataspec 0x080000";
242 string cmd21 = "-datatype 'DDL_RAW ' 'MUON' -dataspec 0x100000";
243 string cmd22 = "-datatype 'DDL_RAW ' 'MUON' -dataspec 0x200000";
cc76079a 244 for (int i = firstEvent; i < lastEvent+1; i++)
245 {
246 if (i != 0)
247 {
248 cmd13 += " -nextevent";
249 cmd14 += " -nextevent";
250 cmd15 += " -nextevent";
251 cmd16 += " -nextevent";
252 cmd17 += " -nextevent";
253 cmd18 += " -nextevent";
254 cmd19 += " -nextevent";
255 cmd20 += " -nextevent";
256 cmd21 += " -nextevent";
257 cmd22 += " -nextevent";
258 }
259 char buf[16];
260 sprintf(buf, "%d", i);
261 cmd13 += " -datafile raw"; cmd13 += buf; cmd13 += "/MUONTRK_2572.ddl";
262 cmd14 += " -datafile raw"; cmd14 += buf; cmd14 += "/MUONTRK_2573.ddl";
263 cmd15 += " -datafile raw"; cmd15 += buf; cmd15 += "/MUONTRK_2574.ddl";
264 cmd16 += " -datafile raw"; cmd16 += buf; cmd16 += "/MUONTRK_2575.ddl";
265 cmd17 += " -datafile raw"; cmd17 += buf; cmd17 += "/MUONTRK_2576.ddl";
266 cmd18 += " -datafile raw"; cmd18 += buf; cmd18 += "/MUONTRK_2577.ddl";
267 cmd19 += " -datafile raw"; cmd19 += buf; cmd19 += "/MUONTRK_2578.ddl";
268 cmd20 += " -datafile raw"; cmd20 += buf; cmd20 += "/MUONTRK_2579.ddl";
269 cmd21 += " -datafile raw"; cmd21 += buf; cmd21 += "/MUONTRG_2816.ddl";
270 cmd22 += " -datafile raw"; cmd22 += buf; cmd22 += "/MUONTRG_2817.ddl";
271 }
272
273 AliHLTConfiguration pubDDL13("pubDDL13", "FilePublisher", NULL, cmd13.c_str());
274 AliHLTConfiguration pubDDL14("pubDDL14", "FilePublisher", NULL, cmd14.c_str());
275 AliHLTConfiguration pubDDL15("pubDDL15", "FilePublisher", NULL, cmd15.c_str());
276 AliHLTConfiguration pubDDL16("pubDDL16", "FilePublisher", NULL, cmd16.c_str());
277 AliHLTConfiguration pubDDL17("pubDDL17", "FilePublisher", NULL, cmd17.c_str());
278 AliHLTConfiguration pubDDL18("pubDDL18", "FilePublisher", NULL, cmd18.c_str());
279 AliHLTConfiguration pubDDL19("pubDDL19", "FilePublisher", NULL, cmd19.c_str());
280 AliHLTConfiguration pubDDL20("pubDDL20", "FilePublisher", NULL, cmd20.c_str());
281 AliHLTConfiguration pubDDL21("pubDDL21", "FilePublisher", NULL, cmd21.c_str());
282 AliHLTConfiguration pubDDL22("pubDDL22", "FilePublisher", NULL, cmd22.c_str());
283 }
284
285 // Build the DDL reconstructor components for all the DDLs 13 to 22, that
286 // is for chambers 7 to 10 and trigger stations. We only need to build
287 // these components if we are are building the ddlreco or full chains.
288 if (buildDDLRecoComps)
289 {
1b3806c8 290 if (TString(lutDir) == "CDB")
291 {
292 AliHLTConfiguration recDDL13("recDDL13", "MUONHitReconstructor", "pubDDL13", TString("-ddl 13 -cdbpath local://$ALICE_ROOT -run 0"));
293 AliHLTConfiguration recDDL14("recDDL14", "MUONHitReconstructor", "pubDDL14", TString("-ddl 14 -cdbpath local://$ALICE_ROOT -run 0"));
294 AliHLTConfiguration recDDL15("recDDL15", "MUONHitReconstructor", "pubDDL15", TString("-ddl 15 -cdbpath local://$ALICE_ROOT -run 0"));
295 AliHLTConfiguration recDDL16("recDDL16", "MUONHitReconstructor", "pubDDL16", TString("-ddl 16 -cdbpath local://$ALICE_ROOT -run 0"));
296 AliHLTConfiguration recDDL17("recDDL17", "MUONHitReconstructor", "pubDDL17", TString("-ddl 17 -cdbpath local://$ALICE_ROOT -run 0"));
297 AliHLTConfiguration recDDL18("recDDL18", "MUONHitReconstructor", "pubDDL18", TString("-ddl 18 -cdbpath local://$ALICE_ROOT -run 0"));
298 AliHLTConfiguration recDDL19("recDDL19", "MUONHitReconstructor", "pubDDL19", TString("-ddl 19 -cdbpath local://$ALICE_ROOT -run 0"));
299 AliHLTConfiguration recDDL20("recDDL20", "MUONHitReconstructor", "pubDDL20", TString("-ddl 20 -cdbpath local://$ALICE_ROOT -run 0"));
300 AliHLTConfiguration recDDL21("recDDL21", "MUONTriggerReconstructor", "pubDDL21", TString("-ddl 21 -cdbpath local://$ALICE_ROOT -run 0 -suppress_partial_triggers"));
301 AliHLTConfiguration recDDL22("recDDL22", "MUONTriggerReconstructor", "pubDDL22", TString("-ddl 22 -cdbpath local://$ALICE_ROOT -run 0 -suppress_partial_triggers"));
302 }
303 else
304 {
305 AliHLTConfiguration recDDL13("recDDL13", "MUONHitReconstructor", "pubDDL13", TString("-ddl 13 -lut ") + lutDir + TString("/Lut13.dat"));
306 AliHLTConfiguration recDDL14("recDDL14", "MUONHitReconstructor", "pubDDL14", TString("-ddl 14 -lut ") + lutDir + TString("/Lut14.dat"));
307 AliHLTConfiguration recDDL15("recDDL15", "MUONHitReconstructor", "pubDDL15", TString("-ddl 15 -lut ") + lutDir + TString("/Lut15.dat"));
308 AliHLTConfiguration recDDL16("recDDL16", "MUONHitReconstructor", "pubDDL16", TString("-ddl 16 -lut ") + lutDir + TString("/Lut16.dat"));
309 AliHLTConfiguration recDDL17("recDDL17", "MUONHitReconstructor", "pubDDL17", TString("-ddl 17 -lut ") + lutDir + TString("/Lut17.dat"));
310 AliHLTConfiguration recDDL18("recDDL18", "MUONHitReconstructor", "pubDDL18", TString("-ddl 18 -lut ") + lutDir + TString("/Lut18.dat"));
311 AliHLTConfiguration recDDL19("recDDL19", "MUONHitReconstructor", "pubDDL19", TString("-ddl 19 -lut ") + lutDir + TString("/Lut19.dat"));
312 AliHLTConfiguration recDDL20("recDDL20", "MUONHitReconstructor", "pubDDL20", TString("-ddl 20 -lut ") + lutDir + TString("/Lut20.dat"));
313 AliHLTConfiguration recDDL21("recDDL21", "MUONTriggerReconstructor", "pubDDL21", TString("-ddl 21 -lut ") + lutDir + TString("/Lut21.dat -suppress_partial_triggers"));
314 AliHLTConfiguration recDDL22("recDDL22", "MUONTriggerReconstructor", "pubDDL22", TString("-ddl 22 -lut ") + lutDir + TString("/Lut22.dat -suppress_partial_triggers"));
315 }
1f50d9b1 316 }
317
318 TString startEventStr = "-firstevent ";
319 startEventStr += firstEvent;
ee3678d3 320
1f50d9b1 321 // Build the data source components to take data from simulated hits if
322 // we are building the tracker only chain with the 'sim' data source.
cc76079a 323 if (buildSimDataPubs)
324 {
1f50d9b1 325 AliHLTConfiguration recDDL13("recDDL13", "MUONRecHitsSource", NULL, startEventStr + " -simdata -plane left -chamber 7");
326 AliHLTConfiguration recDDL14("recDDL14", "MUONRecHitsSource", NULL, startEventStr + " -simdata -plane right -chamber 7");
327 AliHLTConfiguration recDDL15("recDDL15", "MUONRecHitsSource", NULL, startEventStr + " -simdata -plane left -chamber 8");
328 AliHLTConfiguration recDDL16("recDDL16", "MUONRecHitsSource", NULL, startEventStr + " -simdata -plane right -chamber 8");
329 AliHLTConfiguration recDDL17("recDDL17", "MUONRecHitsSource", NULL, startEventStr + " -simdata -plane left -chamber 9");
330 AliHLTConfiguration recDDL18("recDDL18", "MUONRecHitsSource", NULL, startEventStr + " -simdata -plane right -chamber 9");
331 AliHLTConfiguration recDDL19("recDDL19", "MUONRecHitsSource", NULL, startEventStr + " -simdata -plane left -chamber 10");
332 AliHLTConfiguration recDDL20("recDDL20", "MUONRecHitsSource", NULL, startEventStr + " -simdata -plane right -chamber 10");
333 AliHLTConfiguration recDDL21("recDDL21", "MUONTriggerRecordsSource", NULL, startEventStr + " -hitdata -plane left");
334 AliHLTConfiguration recDDL22("recDDL22", "MUONTriggerRecordsSource", NULL, startEventStr + " -hitdata -plane right");
cc76079a 335 }
336
337 // Build the data source components to take data from offline reconstructed
338 // objects if we are building the tracker only chain with the 'rec' data source.
339 if (buildRecDataPubs)
340 {
1f50d9b1 341 AliHLTConfiguration recDDL13("recDDL13", "MUONRecHitsSource", NULL, startEventStr + " -recdata -plane left -chamber 7");
342 AliHLTConfiguration recDDL14("recDDL14", "MUONRecHitsSource", NULL, startEventStr + " -recdata -plane right -chamber 7");
343 AliHLTConfiguration recDDL15("recDDL15", "MUONRecHitsSource", NULL, startEventStr + " -recdata -plane left -chamber 8");
344 AliHLTConfiguration recDDL16("recDDL16", "MUONRecHitsSource", NULL, startEventStr + " -recdata -plane right -chamber 8");
345 AliHLTConfiguration recDDL17("recDDL17", "MUONRecHitsSource", NULL, startEventStr + " -recdata -plane left -chamber 9");
346 AliHLTConfiguration recDDL18("recDDL18", "MUONRecHitsSource", NULL, startEventStr + " -recdata -plane right -chamber 9");
347 AliHLTConfiguration recDDL19("recDDL19", "MUONRecHitsSource", NULL, startEventStr + " -recdata -plane left -chamber 10");
348 AliHLTConfiguration recDDL20("recDDL20", "MUONRecHitsSource", NULL, startEventStr + " -recdata -plane right -chamber 10");
349 AliHLTConfiguration recDDL21("recDDL21", "MUONTriggerRecordsSource", NULL, startEventStr + " -recdata -plane left");
350 AliHLTConfiguration recDDL22("recDDL22", "MUONTriggerRecordsSource", NULL, startEventStr + " -recdata -plane right");
cc76079a 351 }
352
353 // Build the tracker component if we are building the tracker only or
354 // full chains.
355 if (buildTrackerComp)
356 {
357 AliHLTConfiguration tracker("tracker", "MUONMansoTrackerFSM", "recDDL13 recDDL14 recDDL15 recDDL16 recDDL17 recDDL18 recDDL19 recDDL20 recDDL21 recDDL22", "");
358 }
359
1f50d9b1 360 // Build the data sink to subscribe only to what has been created and
361 // to the data source we actaully want.
362 TString sources = "";
363 if (makeTracksOnly)
cc76079a 364 {
1f50d9b1 365 sources += "tracker ";
cc76079a 366 }
1f50d9b1 367 else
368 {
369 if (buildTrackerComp)
370 sources += "tracker ";
371 sources += "recDDL13 recDDL14 recDDL15 recDDL16 recDDL17 recDDL18 recDDL19 recDDL20 recDDL21 recDDL22";
372 }
373 if (useRootWriter)
374 {
375 AliHLTConfiguration convert("convert", "MUONRootifier", sources, "");
376 AliHLTConfiguration sink("sink", "ROOTFileWriter", "convert", "-datafile output.root -specfmt");
377 }
378 else
cc76079a 379 {
1f50d9b1 380 AliHLTConfiguration sink("sink", "FileWriter", sources, "-datafile output.dat -specfmt");
cc76079a 381 }
382
1f50d9b1 383 // Build and run the chain's tasks.
384 sys.BuildTaskList("sink");
cc76079a 385 sys.Run(eventCount);
386}