FindFASTJET
[u/mrichter/AliRoot.git] / HLT / exa / makeComponentConfigurationObject.C
CommitLineData
9bdcc572 1// $Id$
2/**
3 * @file makeComponentConfigurationObject.C
4 * @brief Creation of HLT component configuration objects in OCDB
5 *
6 * <pre>
12fe5aa8 7 * Usage:
8 * aliroot -b -q makeComponentConfigurationObject.C'("path", "param", "uri", runmin, runmax)'
9 * aliroot -b -q makeComponentConfigurationObject.C'("path", "key", "param", "uri", runmin, runmax)'
9bdcc572 10 * </pre>
11 *
12 * Create an OCDB entry with a TObjString containing param.
13 * Many HLT components understand configuration strings containing
14 * arguments and parameters just like the command line arguments.
15 * This macro facilitates the creation of an appropriate object
16 * from a parameter string.
12fe5aa8 17 * As another approach the TObjString parameters are stored in a TMap
18 * associated to a key. A TMap object is generated if 'key' is specified.
9bdcc572 19 *
20 * Parameters: <br>
21 * - path path of the entry within the OCDB
22 * - param (opt) string to be stored in the TObjSting, default empty
23 * - uri (opt) the OCDB URI, default $ALICE_ROOT
24 * - runmin (opt) default 0
25 * - runmax (opt) default 999999999
26 *
27 * Note: The configuration procedure of an HLT component is not
28 * restricted to that scheme. The implementation is up to the
29 * developer and more complex objects are possible.
30 *
31 * @author Matthias.Richter@ift.uib.no
32 * @ingroup alihlt_tutorial
33 */
12fe5aa8 34void makeComponentConfigurationObject(const char* path,
35 const char* key,
36 const char* param,
37 const char* cdbUri,
9bdcc572 38 int runmin=0,
fd228666 39 int runmax=AliCDBRunRange::Infinity(),
12fe5aa8 40 int runNo=0)
9bdcc572 41{
42 AliCDBManager* man = AliCDBManager::Instance();
43 if (!man) {
44 cerr << "can not get AliCDBManager" << end;
45 exit;
46 }
47 TString storage;
48 if (!man->IsDefaultStorageSet()) {
49 if (cdbUri) {
50 storage=cdbUri;
84683b66 51 if (storage.Contains("://")==0) {
9bdcc572 52 storage="local://"; storage+=cdbUri;
53 }
54 } else {
55 storage="local://$ALICE_ROOT/OCDB";
56 }
57 man->SetDefaultStorage(storage);
58 } else {
59 storage = man->GetDefaultStorage()->GetURI();
60 }
61
12fe5aa8 62 TMap* pMap=NULL;
63
64 // load existing object and init TMap
65 AliCDBEntry* pExisting=NULL;
66 AliCDBStorage* pStorage=AliCDBManager::Instance()->GetDefaultStorage();
67 if (key && pStorage->GetLatestVersion(path, runNo)>=0) {
68 pExisting=pStorage->Get(path, runNo);
69 if (pExisting->GetObject()->IsA() == TMap::Class()) {
70 pMap=(TMap*)pExisting->GetObject()->Clone();
71 }
72 }
73
74 if (key && !pMap) pMap=new TMap;
75
9bdcc572 76 // here is the actual content of the configuration object
12fe5aa8 77 TObject* obj=new TObjString(param);
78 if (pMap) {
79 if (pMap->FindObject(key)) {
80 pMap->Remove(new TObjString(key));
81 }
82 pMap->Add(new TObjString(key), obj);
83 obj=pMap;
84 }
85
9bdcc572 86 AliCDBPath cdbPath(path);
87 AliCDBId cdbId(cdbPath, runmin, runmax);
cbeb249c 88 AliCDBMetaData* cdbMetaData=NULL;
89 if (pExisting) cdbMetaData=pExisting->GetMetaData();
90 else cdbMetaData=new AliCDBMetaData;
12fe5aa8 91 man->Put(obj, cdbId, cdbMetaData);
92}
93
94void makeComponentConfigurationObject(const char* path, const char* param="",
95 const char* cdbUri=NULL,
96 int runmin=0,
fd228666 97 int runmax=AliCDBRunRange::Infinity())
12fe5aa8 98{
cbeb249c 99 makeComponentConfigurationObject(path, NULL, param, cdbUri, runmin, runmax);
12fe5aa8 100}
101
102void makeComponentConfigurationObject(const char* path,
103 int runNo,
104 const char* key,
105 const char* param)
106{
fd228666 107 makeComponentConfigurationObject(path, key, param, NULL, 0, AliCDBRunRange::Infinity(), runNo);
9bdcc572 108}
109
110void makeComponentConfigurationObject()
111{
112 cout << "===============================================================" << endl;
113 cout << "usage: aliroot -b -q -l makeComponentConfigurationObject.C'(\"path\", \"param\", \"uri\", rangemin, rangemax)'" << endl << endl;
114 cout << " path path of the entry within the OCDB" << endl;
115 cout << " param (opt) string to be stored in the TObjSting, default empty" << endl;
a51a0599 116 cout << " uri (opt) the OCDB URI, default $ALICE_ROOT/OCDB " << endl;
9bdcc572 117 cout << " rangemin (opt) default 0" << endl;
fd228666 118 cout << " rangemax (opt) default AliCDBRunRange::Infinity()" << endl;
9bdcc572 119 cout << "===============================================================" << endl;
12fe5aa8 120 cout << "usage: aliroot -b -q -l makeComponentConfigurationObject.C'(\"path\", \"key\", \"param\", \"uri\", rangemin, rangemax)'" << endl << endl;
121 cout << " path path of the entry within the OCDB" << endl;
122 cout << " param (opt) string to be stored in the TObjSting, default empty" << endl;
123 cout << " uri (opt) the OCDB URI, default $ALICE_ROOT/OCDB " << endl;
124 cout << " rangemin (opt) default 0" << endl;
fd228666 125 cout << " rangemax (opt) default AliCDBRunRange::Infinity()" << endl;
12fe5aa8 126 cout << "===============================================================" << endl;
9bdcc572 127}