]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - STEER/makeCDBSnapshotFromUserInfo.C
Example macro to create a CDB snapshot from the userinfo from the ESD-tree of a given...
[u/mrichter/AliRoot.git] / STEER / makeCDBSnapshotFromUserInfo.C
... / ...
CommitLineData
1#include "ARVersion.h"
2#if !defined(__CINT__) || defined(__MAKECINT__)
3#include "AliCDBManager.h"
4#include "AliCDBStorage.h"
5#include "AliCDBId.h"
6#include "AliCDBMetaData.h"
7#include <TTree.h>
8#include <TList.h>
9#include <TObjString.h>
10#include <TString.h>
11#endif
12
13void makeCDBSnapshotFromUserInfo(const char* defaultStorage, const char* esdFile, const char* snapshotFile)
14{
15 // read UserInfo from an esd tree and build the corresponding single-key snapshot from it
16 // ATTENTION: it works if we are happy that all objects will be taken from the default CDB
17 // Example input esd file: "alien:///alice/data/2011/LHC11h_2/000168984/ESDs/pass2/11000168984001.12/AliESDs.root"
18 //
19
20 AliCDBManager *cdb = AliCDBManager::Instance();
21 cdb->SetDefaultStorage(defaultStorage);
22
23 TFile *f = TFile::Open(esdFile);
24 if(!f){
25 Printf("Unable to open file \"%s\". Exiting.",esdFile);
26 return;
27 }
28 TTree *tree = (TTree*) f->Get("esdTree");
29 if(!tree){
30 Printf("Could not get tree from file. Exiting.");
31 return;
32 }
33 TList *ui = (TList*) tree->GetUserInfo();
34 if(!ui){
35 Printf("Could not get user info from tree. Exiting.");
36 return;
37 }
38 TList *ids = (TList*) ui->At(2);
39 if(!ids){
40 Printf("Could not get CDB objects' ids from user info. Exiting.");
41 return;
42 }
43
44 TListIter lIter(ids);
45 TObjString *oStr = 0;
46 while ((oStr = dynamic_cast<TObjString*> (lIter.Next()))) {
47 TString printedId = oStr->GetString();
48 // add here lines like the following if you don't want a given object in the snapshot
49 // this should not be needed because the specific storages overwrite the snapshot-mode
50 //if(printedId.Contains("ITS/Align/Data")||printedId.Contains("MUON/Align/Data"))
51 // continue;
52 printedId.Remove(0,printedId.First('"')+1);
53 TString path = printedId(0,printedId.First('"'));
54 printedId.Remove(0,printedId.First('[')+1);
55 TString fRun = printedId(0,printedId.First(','));
56 printedId.Remove(0,printedId.First(',')+1);
57 Int_t firstRun = fRun.Atoi();
58 TString lRun = printedId(0,printedId.First(']'));
59 Int_t lastRun = lRun.Atoi();
60 printedId.Remove(0,printedId.First(':')+1);
61 printedId.Remove(0,2);
62 printedId.Remove(printedId.First('_'),printedId.Length());
63 Int_t version = printedId.Atoi();
64 AliCDBId id(path.Data(),firstRun,lastRun,version);
65 id.Print();
66 AliCDBEntry *e = cdb->Get(id);
67 }
68
69 cdb->DumpToSnapshotFile(snapshotFile,kFALSE);
70}