]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/exa/sample-component1.C
Fixing comments
[u/mrichter/AliRoot.git] / HLT / exa / sample-component1.C
1 // $Id$
2 /**
3  * @file sample-component1.C
4  * @brief Sample macro for the component initialization and configuration.
5  *
6  * Usage:
7  * <pre>
8  *   aliroot -b -q sample-component1.C | tee sample-component1.log
9  * </pre>
10  *
11  * This macro illustrates the creation of an HLT component and it's
12  * initialization and configuration, including update of values from
13  * DCS.
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  *
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  *
45  * @author Matthias.Richter@ift.uib.no
46  * @ingroup alihlt_tutorial
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
55   const char* tmpFile1="/tmp/samplecomponent1-comconf.dat";
56   const char* tmpFile2="/tmp/samplecomponent1-updtdcs.dat";
57
58   // path of the cdb entry
59   const char* cdbEntryPath="HLT/ConfigSample/SampleComponent1";
60
61   // path of detectors with 'active' preprocessors
62   const char* prepDetectors="TPC PHOS";
63
64   // path of the CDB to be created
65   const char* cdbLocation="/tmp/OCDB";
66   TString cdbUri; cdbUri.Form("local://%s", cdbLocation);
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;
85   gHLT.SetGlobalLoggingLevel(0x7c);
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
98   FILE* fp = fopen(tmpFile1, "w");
99   if (fp) {
100     fprintf(fp, cdbEntryPath);
101     fclose(fp);
102   }
103
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
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;
135   arg.Form("-datatype COM_CONF PRIV -datafile %s", tmpFile1);
136   AliHLTConfiguration reconfevent("reconfevent", "FilePublisher", NULL , arg.Data());
137
138   arg.Form("-datatype UPDT_DCS PRIV -datafile %s", tmpFile2);
139   AliHLTConfiguration updtdcsevent("updtdcsevent", "FilePublisher", NULL , arg.Data());
140
141   AliHLTConfiguration sc1("sc1", "Sample-component1", "reconfevent updtdcsevent" , componentInit);
142
143   // run the chain
144   gHLT.BuildTaskList("sc1");
145   gHLT.Run();
146
147   /////////////////////////////////////////////////////////////////////////
148   /////////////////////////////////////////////////////////////////////////
149   /////////////////////////////////////////////////////////////////////////
150   // cleanup
151
152   // delete temporary file
153   TString cmd;
154   cmd.Form("rm -r %s %s %s", tmpFile1, tmpFile2, cdbLocation);
155   gSystem->Exec(cmd.Data());
156 }