Update master to aliroot
[u/mrichter/AliRoot.git] / HLT / programs / adjustOCDBObject.C
1 // $Id$
2 /**
3  * @file adjustOCDBObject.C
4  * @brief Tool to adjust properties of an OCDB object and write it back to OCDB.
5  *
6  * Usage:
7  * <pre>
8  *   aliroot -b -q adjustOCDBObject("file",
9  *                                  targetCDB="local://$PWD",
10  *                                  firstrun=-1,
11  *                                  lastrun=-1,
12  *                                  version=-1,
13  *                                  subversion=-1,
14  *                                  comment=NULL,
15  *                                  responsible=NULL,
16  *                                  alirootv=NULL) 
17  * </pre>
18  *
19  * The macro opens an OCDB entry directly as a file, changes properties
20  * of the entry and uses the CDBmanager to write it back to some new
21  * location.
22  *
23  * Required parameters:
24  * - filename
25  * - OCDB target
26  * Optional parameters, if the default values are specified the
27  * corresponding key in the entry is not changed
28  * - first run
29  * - last run, if smaller than first run 'AliCDBRunRange::Infinity' is used
30  * - version
31  * - subversion
32  * - comment
33  * - responsible
34  * - aliroot version 
35  *
36  * @author Matthias.Richter@ift.uib.no
37  * @ingroup alihlt_tutorial
38  */
39 void adjustOCDBObject(const char* file,
40                       const char* targetCDB="local://$PWD",
41                       int firstrun=-1,
42                       int lastrun=-1,
43                       int version=-1,
44                       int subversion=-1,
45                       const char* comment=NULL,
46                       const char* responsible=NULL,
47                       const char* alirootv=NULL) 
48 {
49   TFile* origfile=new TFile(file);
50   if (origfile->IsZombie()) {
51     cerr << "error opening file " << file << endl;
52     return;
53   }
54   
55   AliCDBEntry* cdbEntry=NULL;
56   origfile->GetObject("AliCDBEntry", cdbEntry);
57   if (!cdbEntry) {
58     cerr << "can not find CDB entry in file " << file << endl;
59   }
60
61   AliCDBId& cdbId=cdbEntry->GetId();
62   if (version>=0) cdbId.SetVersion(version);
63   if (subversion>=0) cdbId.SetSubVersion(subversion);
64   if (firstrun>=0) cdbId.SetFirstRun(firstrun);
65   if (lastrun>=0) cdbId.SetLastRun(lastrun);
66   if (lastrun<firstrun) cdbId.SetLastRun(AliCDBRunRange::Infinity());
67
68   AliCDBMetaData* meta=cdbEntry->GetMetaData();
69   if (comment) meta->SetComment(comment);
70   if (responsible) meta->SetResponsible(responsible);
71   if (alirootv) meta->SetAliRootVersion(alirootv);
72
73   AliCDBManager* man = AliCDBManager::Instance();
74   man->SetDefaultStorage(targetCDB);
75   man->Put(cdbEntry);
76
77 }
78
79 void adjustOCDBObject() 
80 {
81   cout << "adjustOCDBObject.C   adjust properties of an OCDB entry" << endl;
82   cout << "usage:" << endl;
83   cout << "   aliroot -b -q adjustOCDBObject'(\"file\", " << endl;
84   cout << "                                  targetCDB=\"local://$PWD\", " << endl;
85   cout << "                                  firstrun=-1, " << endl;
86   cout << "                                  lastrun=-1, " << endl;
87   cout << "                                  version=-1, " << endl;
88   cout << "                                  subversion=-1, " << endl;
89   cout << "                                  comment=NULL, " << endl;
90   cout << "                                  responsible=NULL, " << endl;
91   cout << "                                  alirootv=NULL)'  " << endl;
92   cout << " e.g." << endl;
93   cout << "   aliroot -b -q adjustOCDBObject'(\"myfile.root\", \"$ALICE_ROOT/OCDB\", 42, 42)'" << endl;
94 }