FindFASTJET
[u/mrichter/AliRoot.git] / HLT / exa / sample-component1.C
CommitLineData
9b4f7f90 1// $Id$
5045badf 2/**
10bd167f 3 * @file sample-component1.C
4 * @brief Sample macro for the component initialization and configuration.
5045badf 5 *
6 * Usage:
10bd167f 7 * <pre>
5045badf 8 * aliroot -b -q sample-component1.C | tee sample-component1.log
10bd167f 9 * </pre>
5045badf 10 *
11 * This macro illustrates the creation of an HLT component and it's
b543e186 12 * initialization and configuration, including update of values from
13 * DCS.
5045badf 14 *
15 * A component can be initialized by command line arguments. The scan
16 * and interpretation of those arguments must be implemented in the
17 * DoInit function of the component. The command line arguments are
18 * specified in the chain configuration. In this example, it is an
19 * AliRoot HLT chain. The same applies for PubSub online HLT chains.
20 *
21 * Configuration of components is done from configuration objects in
22 * the CDB. It's the responsibility of the component to retrieve the
23 * CDB entry from the CDB and interprete it. The CDB initialization
24 * is done by the framework.
25 *
26 * The component can also decide if it wants to configure already during
27 * initialization (DoInit) from configuration objects.
28 *
10bd167f 29 * The Sample-component1 (AliHLTSampleComponent1) implements configuration
30 * via a string of arguments like e.g. '-config1 config-param -config2'.
31 * Two different ways of configuration are implemented:
32 * - configuration arguments can be part of the initialization arguments.
33 * All arguments not known to the argument scan in DoInit are treated
34 * as configuration arguments. Scanning of those remaining arguments
35 * is done at the end of the DoInit
36 * - if there are no configuration arguments, the configuration is done
37 * from the default object in the CDB
38 * - The implemented Reconfigure method retrieves either the object
39 * specified in the reconfiguration event or the default object.
40 *
41 * The macro defines the CDB in the /tmp folder and creates an object
42 * in the CDB. Then it defines a very simple chain, which models the
43 * respons of the component to the reconfiguration event.
44 *
5045badf 45 * @author Matthias.Richter@ift.uib.no
10bd167f 46 * @ingroup alihlt_tutorial
5045badf 47 */
48{
49 /////////////////////////////////////////////////////////////////////////
50 /////////////////////////////////////////////////////////////////////////
51 /////////////////////////////////////////////////////////////////////////
52 // some parameters for this test macro
53
54 // the path of a temporary file needed to send the reconfigure event
b543e186 55 const char* tmpFile1="/tmp/samplecomponent1-comconf.dat";
56 const char* tmpFile2="/tmp/samplecomponent1-updtdcs.dat";
5045badf 57
58 // path of the cdb entry
59 const char* cdbEntryPath="HLT/ConfigSample/SampleComponent1";
60
b543e186 61 // path of detectors with 'active' preprocessors
62 const char* prepDetectors="TPC PHOS";
63
5045badf 64 // path of the CDB to be created
b543e186 65 const char* cdbLocation="/tmp/OCDB";
66 TString cdbUri; cdbUri.Form("local://%s", cdbLocation);
5045badf 67
68 // initialization arguments for the component
69 const char* componentInit="-mandatory1 testarg -mandatory2";
70
71 // configuration arguments for the component
72 const char* componentConfig="-config1 config-param -config2";
73
74
75 /////////////////////////////////////////////////////////////////////////
76 /////////////////////////////////////////////////////////////////////////
77 /////////////////////////////////////////////////////////////////////////
78 // global initialization of the HLT
79
80 // this is just a tool to switch the logging systems
81 AliHLTLogging log;
82 //log.SwitchAliLog(0);
83
84 AliHLTSystem gHLT;
5aebebf7 85 gHLT.SetGlobalLoggingLevel(0x7c);
5045badf 86
87 // load the component library
88 gHLT.LoadComponentLibraries("libAliHLTUtil.so");
89 gHLT.LoadComponentLibraries("libAliHLTSample.so");
90
91 /////////////////////////////////////////////////////////////////////////
92 /////////////////////////////////////////////////////////////////////////
93 /////////////////////////////////////////////////////////////////////////
94 // CDB initialization
95
96 // this is a tool to send the reconfiguration event and the
97 // path of the cdb entry
b543e186 98 FILE* fp = fopen(tmpFile1, "w");
5045badf 99 if (fp) {
100 fprintf(fp, cdbEntryPath);
101 fclose(fp);
102 }
103
b543e186 104 // this is a tool to send the update DCS event and the
105 // path of the cdb entry
106 FILE* fp = fopen(tmpFile2, "w");
107 if (fp) {
108 fprintf(fp, prepDetectors);
109 fclose(fp);
110 }
111
5045badf 112 // now we create the actual entry in the CDB
113 // the CDB is created in /tmp
114 AliCDBManager* man = AliCDBManager::Instance();
115 if (!man->IsDefaultStorageSet())
116 {
117 man->SetDefaultStorage(cdbUri);
118 man->SetRun(0);
119
120 // here is the actual content of the configuration object
121 TObjString obj=componentConfig;
122 AliCDBPath cdbPath(cdbEntryPath);
123 AliCDBId cdbId(cdbPath, 0, 0);
124 AliCDBMetaData cdbMetaData;
125 man->Put(&obj, cdbId, &cdbMetaData);
126 }
127
128 /////////////////////////////////////////////////////////////////////////
129 /////////////////////////////////////////////////////////////////////////
130 /////////////////////////////////////////////////////////////////////////
131 // now we build up a small chain
132
133 // publisher for the reconfigure event
134 TString arg;
289c6c1a 135 arg.Form("-datatype COM_CONF PRIV -datafile %s -nextevent "
136 "-datatype UPDT_DCS PRIV -datafile %s", tmpFile1, tmpFile2);
137 AliHLTConfiguration sep("steeringevents", "FilePublisher", NULL , arg.Data());
5045badf 138
289c6c1a 139 AliHLTConfiguration sc1("sc1", "Sample-component1", "steeringevents" , componentInit);
b543e186 140
289c6c1a 141 // build the chain
5045badf 142 gHLT.BuildTaskList("sc1");
289c6c1a 143
144 // run two events, in the 1st event the component reconfiguration is emulated
145 // in the 2nd one the update of Preprocessor values
146 gHLT.Run(2);
5045badf 147
148 /////////////////////////////////////////////////////////////////////////
149 /////////////////////////////////////////////////////////////////////////
150 /////////////////////////////////////////////////////////////////////////
151 // cleanup
152
153 // delete temporary file
154 TString cmd;
b543e186 155 cmd.Form("rm -r %s %s %s", tmpFile1, tmpFile2, cdbLocation);
5045badf 156 gSystem->Exec(cmd.Data());
157}