3 * @file sample-component1.C
4 * @brief Sample macro for the component initialization and configuration.
8 * aliroot -b -q sample-component1.C | tee sample-component1.log
11 * This macro illustrates the creation of an HLT component and it's
12 * initialization and configuration, including update of values from
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.
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.
26 * The component can also decide if it wants to configure already during
27 * initialization (DoInit) from configuration objects.
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.
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.
45 * @author Matthias.Richter@ift.uib.no
46 * @ingroup alihlt_tutorial
49 /////////////////////////////////////////////////////////////////////////
50 /////////////////////////////////////////////////////////////////////////
51 /////////////////////////////////////////////////////////////////////////
52 // some parameters for this test macro
54 // the path of a temporary file needed to send the reconfigure event
55 const char* tmpFile1="/tmp/samplecomponent1-comconf.dat";
56 const char* tmpFile2="/tmp/samplecomponent1-updtdcs.dat";
58 // path of the cdb entry
59 const char* cdbEntryPath="HLT/ConfigSample/SampleComponent1";
61 // path of detectors with 'active' preprocessors
62 const char* prepDetectors="TPC PHOS";
64 // path of the CDB to be created
65 const char* cdbLocation="/tmp/OCDB";
66 TString cdbUri; cdbUri.Form("local://%s", cdbLocation);
68 // initialization arguments for the component
69 const char* componentInit="-mandatory1 testarg -mandatory2";
71 // configuration arguments for the component
72 const char* componentConfig="-config1 config-param -config2";
75 /////////////////////////////////////////////////////////////////////////
76 /////////////////////////////////////////////////////////////////////////
77 /////////////////////////////////////////////////////////////////////////
78 // global initialization of the HLT
80 // this is just a tool to switch the logging systems
82 //log.SwitchAliLog(0);
85 gHLT.SetGlobalLoggingLevel(0x7c);
87 // load the component library
88 gHLT.LoadComponentLibraries("libAliHLTUtil.so");
89 gHLT.LoadComponentLibraries("libAliHLTSample.so");
91 /////////////////////////////////////////////////////////////////////////
92 /////////////////////////////////////////////////////////////////////////
93 /////////////////////////////////////////////////////////////////////////
96 // this is a tool to send the reconfiguration event and the
97 // path of the cdb entry
98 FILE* fp = fopen(tmpFile1, "w");
100 fprintf(fp, cdbEntryPath);
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");
108 fprintf(fp, prepDetectors);
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())
117 man->SetDefaultStorage(cdbUri);
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);
128 /////////////////////////////////////////////////////////////////////////
129 /////////////////////////////////////////////////////////////////////////
130 /////////////////////////////////////////////////////////////////////////
131 // now we build up a small chain
133 // publisher for the reconfigure event
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());
139 AliHLTConfiguration sc1("sc1", "Sample-component1", "steeringevents" , componentInit);
142 gHLT.BuildTaskList("sc1");
144 // run two events, in the 1st event the component reconfiguration is emulated
145 // in the 2nd one the update of Preprocessor values
148 /////////////////////////////////////////////////////////////////////////
149 /////////////////////////////////////////////////////////////////////////
150 /////////////////////////////////////////////////////////////////////////
153 // delete temporary file
155 cmd.Form("rm -r %s %s %s", tmpFile1, tmpFile2, cdbLocation);
156 gSystem->Exec(cmd.Data());