3 Primary goal of the proposal was to provide functionality to browse and compare the content of the OCDB
4 specified by different means.
6 a.) galice.root - as currently implemented by Ruben in MC (or any file with cdbMap, and cdbList)
7 b.) AliESDs.root - for the reconstructed data
8 c.) ocdb snapshot - as used for grid productions
9 d.) TMap(s) - as used internally in galice.root and AliESDs,root
10 e.) log file (if possible) - looks logs aways used similar syntax, tested and working
11 f.) C macro - custom macro
13 Content comparison should be done:
14 a.) on the level of symbolic links
15 b.) on the level of content itself
16 - by by byte comparison dif
17 - data member by data member comparison
19 Implementation assumption:
20 All input formats (a .. f) will be converted to the TMap storages and TList if AliCDBIds
24 export mcProd=$ALICE_ROOT/PWGPP/CalibMacros/
25 .L $mcProd/AliOCDBToolkit.cxx+
26 MakeDiffExampleUseCase();
39 #include "TObjArray.h"
44 #include "AliCDBManager.h"
45 #include "AliCDBEntry.h"
52 void MakeDiffExampleUseCase(); // example usage
55 Bool_t ParseInfoFromOcdbString(TString ocdbString, TString &ocdbPath, Int_t &run0, Int_t &run1, Int_t &version, Int_t &subVersion);
56 Bool_t ParseInfoFromOcdbString(TString ocdbString, AliCDBId &cdbId);
57 TList * ConvertListStringToCDBId(const TList *cdbList0);
59 void LoadOCDBFromLog(const char *logName, Int_t verbose);
60 void LoadOCDBFromMap(const TMap *cdbMap, const TList *cdbList);
61 void MakeDiff(const TMap *cdbMap0, const TList *cdbList0, const TMap *cdbMap1, const TList *cdbList1, Int_t verbose);
62 void DumpOCDB(const TMap *cdbMap0, const TList *cdbList0);
66 void MakeDiffExampleUseCase(){
68 // Example usage for the MC
69 // To run example case, assuming presence of following files in working directory:
74 AliCDBManager * man = AliCDBManager::Instance();
75 LoadOCDBFromLog("rec.log",0);
76 const TMap *cdbMapLog= man->GetStorageMap(); // this is map of
77 const TList *cdbListLog=man->GetRetrievedIds(); // this is list of AliCDBId
78 // TList *cdbListLog0=man->GetRetrievedIds(); // this is list of AliCDBId
80 TFile *fmc = TFile::Open("galice.root");
81 TMap *cdbMapMC= (TMap*)fmc->Get("cdbMap"); //
82 TList *cdbListMC0= (TList*)fmc->Get("cdbList"); // this is list of TObjStrings
83 TList *cdbListMC = ConvertListStringToCDBId(cdbListMC0); // convert to the TObjArray of AliCDBids
85 TFile *fesd = TFile::Open("AliESDs.root");
86 TList *listESD = ((TTree*)fesd->Get("esdTree"))->GetUserInfo();
87 TMap *cdbMapESD= (TMap*)listESD->FindObject("cdbMap");
88 TList *cdbListESD0= (TList*)listESD->FindObject("cdbList"); // this is list of TObjStrings
89 TList *cdbListESD = ConvertListStringToCDBId(cdbListESD0); // convert to the TObjArray of AliCDBids
94 printf("Diff log>>>ESD\n\n:");
95 MakeDiff(cdbMapLog, cdbListLog, cdbMapESD, cdbListESD,0);
97 printf("Diff ESD>>>log\n\n:");
98 MakeDiff(cdbMapESD, cdbListESD,cdbMapLog, cdbListLog,0);
101 printf("Diff ESD>>>MC\n\n:");
102 MakeDiff(cdbMapMC, cdbListMC, cdbMapESD, cdbListESD,0);
106 void DumpOCDBAsTxt(const TString fInput,const TString fType){
109 const TList *cdbList;
112 if(fType.EqualTo("MC",TString::kIgnoreCase)){
113 file = TFile::Open(fInput.Data());
114 cdbMap = (TMap*)file->Get("cdbMap"); //
115 TList *cdbListMC0 = (TList*)file->Get("cdbList"); // this is list of TObjStrings
116 cdbList = ConvertListStringToCDBId(cdbListMC0); // convert to the TObjArray of AliCDBids
118 else if(fType.EqualTo("ESD",TString::kIgnoreCase)){
119 file = TFile::Open(fInput.Data());
120 TList *listESD = ((TTree*)file->Get("esdTree"))->GetUserInfo();
121 cdbMap = (TMap*)listESD->FindObject("cdbMap");
122 TList *cdbListESD0= (TList*)listESD->FindObject("cdbList"); // this is list of TObjStrings
123 cdbList = ConvertListStringToCDBId(cdbListESD0); // convert to the TObjArray of AliCDBids
125 else if(fType.EqualTo("log",TString::kIgnoreCase)){
126 AliCDBManager * man = AliCDBManager::Instance();
127 LoadOCDBFromLog(fInput.Data(),0);
128 cdbMap = man->GetStorageMap(); // this is map of
129 cdbList =man->GetRetrievedIds(); // this is list of AliCDBId
132 printf("unsupported option: %s",fType.Data());
135 cout <<"BEGINDUMP:" << endl;
136 DumpOCDB(cdbMap,cdbList);
140 Bool_t ParseInfoFromOcdbString(TString ocdbString, TString &ocdbPath, Int_t &run0, Int_t &run1, Int_t &version, Int_t &subVersion){
142 // Parse OCDB id string and provide basic ocdb information
144 // a.) parse ocdbPath
145 Int_t indexBeginPath= ocdbString.Index("path: ")+7;
146 if (indexBeginPath<0) return kFALSE;
147 Int_t indexEndPath=ocdbString.Index(";",indexBeginPath);
148 if (indexEndPath<0) return kFALSE;
149 ocdbPath=TString(&(ocdbString.Data()[indexBeginPath]), indexEndPath-indexBeginPath-1);
150 // b.) parse runRange
151 Int_t indexRun0= ocdbString.Index(": [",indexEndPath)+3;
152 if (indexRun0<0) return kFALSE;
153 Int_t indexRun1= ocdbString.Index(",",indexRun0)+1;
154 if (indexRun1<0) return kFALSE;
155 run0=atoi(&(ocdbString.Data()[indexRun0]));
156 run1=atoi(&(ocdbString.Data()[indexRun1]));
157 AliCDBRunRange runRange(run0,run1);
158 //c.) parse version, subversion
159 Int_t indexVersion= ocdbString.Index("version: v",indexRun1)+10;
160 if (indexVersion<0) return kFALSE;
161 Int_t indexSubVersion= ocdbString.Index("_s",indexVersion)+2;
162 if (indexSubVersion<0) return kFALSE;
163 version=atoi(&(ocdbString.Data()[indexVersion]));
164 subVersion=atoi(&(ocdbString.Data()[indexSubVersion]));
168 Bool_t ParseInfoFromOcdbString(TString ocdbString, AliCDBId &cdbId){
170 // Parse OCDB id string and provide basic ocdb information and fillcdbID object
173 Int_t run0=0, run1=0;
174 Int_t version=0, subVersion=0;
175 Bool_t parseStatus = ParseInfoFromOcdbString(ocdbString, ocdbPath, run0,run1,version,subVersion);
177 AliCDBRunRange runRange(run0,run1);
178 cdbId=AliCDBId(ocdbPath.Data(),runRange,version,subVersion);
179 AliCDBId* id = AliCDBId::MakeFromString(ocdbString);
187 TList * ConvertListStringToCDBId(const TList *cdbList0){
189 // Convert input list of the TObjString to list to AliCDBid
191 Int_t entriesList0=cdbList0->GetEntries();
192 TList * array0 = new TList();
194 for (Int_t ientry0=0; ientry0<entriesList0; ientry0++){
195 if (cdbList0->At(ientry0)==0) continue;
196 Bool_t isId = cdbList0->At(ientry0)->IsA()->InheritsFrom("AliCDBId");
198 array0->AddLast(cdbList0->At(ientry0));
200 Bool_t isString = cdbList0->At(ientry0)->IsA()->InheritsFrom("TObjString");
202 TObjString* sid0 = dynamic_cast<TObjString*> (cdbList0->At(ientry0));
203 Bool_t status = ParseInfoFromOcdbString(sid0->String(), tmp0);
204 if (!status) continue;
205 array0->AddLast(new AliCDBId(tmp0));
214 void LoadOCDBFromLog(const char *logName, Int_t verbose){
217 // Load OCDB setting as specified in log
218 // Assuming fixed version of the log
219 // AliCDBManager is initilaized - ocdbMap and ID list can be exported
222 // Parsing/loading sequence:
223 // 0.) SetDefault storage *** Default Storage URI:
224 // 1.) SetSpecific storage *** Specific storage
225 // 2.) SetRunNumber Run number:
228 AliCDBManager * man = AliCDBManager::Instance();
230 // 0.) SetDefault storage *** Default Storage URI:
232 TString defaultOCDB = gSystem->GetFromPipe(TString::Format("cat %s| grep \"Storage URI:\"",logName).Data());
233 TObjArray *array = defaultOCDB.Tokenize("\"");
234 man->SetDefaultStorage(array->Last()->GetName());
237 // 1.) SetSpecific storage *** Specific storage
239 TString specificStorage = gSystem->GetFromPipe(TString::Format("cat %s| grep \"Specific storage\"",logName).Data());
240 array = specificStorage.Tokenize("\"");
241 Int_t entries = array->GetEntries();
242 for (Int_t i=1; i<entries-2; i+=4){
243 // add protection here line shuld be in expected format
244 if (verbose&2>0) printf("%s\t%s\n",array->At(i)->GetName(),array->At(i+2)->GetName());
245 man->SetSpecificStorage(array->At(i)->GetName(),array->At(i+2)->GetName());
249 // 2.) SetRunNumber Run number:
251 TString runLine = gSystem->GetFromPipe(TString::Format("cat %s| grep \"I-AliCDBManager::Print: Run number =\"",logName).Data());
252 array = runLine.Tokenize("=");
254 if (array->GetEntries()>1) run=atoi(array->At(1)->GetName());
260 TString ids = gSystem->GetFromPipe(TString::Format("cat %s| grep I-AliCDB | grep path| grep range | grep version", logName).Data());
261 array= ids.Tokenize("\n");
262 entries = array->GetEntries();
264 for (Int_t i=0; i<entries; i++){
266 TString ocdbString = array->At(i)->GetName();
269 Int_t run0=0, run1=0;
270 Int_t version=0, subVersion=0;
271 Bool_t parseStatus = ParseInfoFromOcdbString(ocdbString, ocdbPath, run0,run1,version,subVersion);
272 if (!parseStatus) continue;
273 AliCDBRunRange runRange(run0,run1);
275 if ((verbose&2)!=0) {
276 printf("%s/Run%d_%d_v%d_s%d.root\n",ocdbPath.Data(),run0,run1,version,subVersion);
279 AliCDBEntry*entry= man->Get(ocdbPath.Data(),runRange,version,subVersion);
280 } catch(const exception &e){
281 cerr << "OCDB retrieval failed!" << endl;
282 cerr << "Detailes: " << e.what() << endl;
287 man->GetStorageMap()->Print();
288 man->GetRetrievedIds()->Print();
293 void LoadOCDBFromMap(TMap */*cdbMap*/, TList */*cdbList*/){
296 // Load OCDB setting as specified in maps
297 // Or Do we have already implementation in AliCDBanager?
302 void MakeDiff(const TMap *cdbMap0, const TList *cdbList0, const TMap *cdbMap1, const TList *cdbList1, Int_t verbose){
305 // Print difference between the 2 ocdb maps
307 // maps and list charactireizing OCDB setup
309 // To be decided, currently it is the teinal output
311 Int_t entriesList0=cdbList0->GetEntries();
312 Int_t entriesList1=cdbList1->GetEntries();
314 for (Int_t ientry0=0; ientry0<entriesList0; ientry0++){
315 AliCDBId *id0 = dynamic_cast<AliCDBId*> (cdbList0->At(ientry0));
317 for (Int_t ientry1=0; ientry1<entriesList1; ientry1++){
318 AliCDBId *cid1 = dynamic_cast<AliCDBId*> (cdbList1->At(ientry1));
321 if (cid1->GetPath().Contains(id0->GetPath().Data())==0) continue;
325 printf("Missing entry\t");
330 if (id0->GetFirstRun()!= id1->GetFirstRun() ||id0->GetLastRun()!= id1->GetLastRun()){
331 printf("Differrent run range\n");
335 if (id0->GetVersion()!= id1->GetVersion() ||id0->GetSubVersion()!= id1->GetSubVersion()){
336 printf("Differrent version\n");
343 void DumpOCDB(const TMap *cdbMap0, const TList *cdbList0){
345 // Dump the OCDb configuatation as formated text file
346 // with following collumns
347 // cdb name prefix cdb path
348 // OCDB entries are sorted alphabetically
350 // TPC/Calib/RecoParam /hera/alice/jwagner/software/aliroot/AliRoot_TPCdev/OCDB/ TPC/Calib/RecoParam/Run0_999999999_v0_s0.root $SIZE_AliCDBEntry_Object $HASH_AliCDBEntry_Object
352 AliCDBManager * man = AliCDBManager::Instance();
353 TIter next(cdbList0);
358 AliCDBEntry *cdbEntry;
363 while ((CDBId =(AliCDBId*) next())){
364 cdbName = CDBId->GetPath();
365 ostr = (TObjString*)cdbMap0->GetValue(cdbName.Data());
366 if(!ostr) ostr = (TObjString*)cdbMap0->GetValue("default");
367 cdbPath = ostr->GetString();
368 if(cdbPath.Contains("local://"))cdbPath=cdbPath(8,cdbPath.Length()).Data();
370 cdbEntry = (AliCDBEntry*) man->Get(*CDBId);
371 TObject *obj = cdbEntry->GetObject();
372 file = new TMessage(TBuffer::kWrite);
373 file->WriteObject(obj);
374 size = file->Length();
376 printf("object %s empty!\n",cdbName.Data());
379 hash = TString::Hash(file->Buffer(),size);
380 printf("%s\t%s\t%s/Run%d_%d_v%d_s%d.root\t%d\t%u\n",
384 CDBId->GetFirstRun(),
387 CDBId->GetSubVersion(),
391 //if(!(CDBId->GetPathLevel(0)).Contains("TPC")) continue;
392 //cout << CDBId.ToString() << endl;