ATO-69: AliCDBManager.{h,.cxx} - ExtractBaseFolder(TString& url) remove everything...
[u/mrichter/AliRoot.git] / STEER / CDB / AliOCDBtoolkit.cxx
CommitLineData
c4490ddb 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17
18 Primary goal of the proposal was to provide functionality to browse and compare the content of the OCDB
19 specified by different means.
20
21 a.) galice.root - as currently implemented by Ruben in MC (or any file with cdbMap, and cdbList)
22 b.) AliESDs.root - for the reconstructed data
23 c.) ocdb snapshot - as used for grid productions
24 d.) TMap(s) - as used internally in galice.root and AliESDs,root
25 e.) log file (if possible) - looks logs aways used similar syntax, tested and working
26 f.) C macro - custom macro
27
28 Content comparison should be done:
29 a.) on the level of symbolic links
30 b.) on the level of content itself
31 - by by byte comparison dif
32 - data member by data member comparison
33
34 Implementation assumption:
35 All input formats (a .. f) will be converted to the TMap storages and TList if AliCDBIds
36
c4490ddb 37 Example usage:
38 AliOCDBtoolkit::MakeDiffExampleUseCase();
beec2f07 39 or from the AliOCDBtoolkit.sh in propmpt
40 ocdbMakeTable AliESDs.root ESD OCDBrec.list
b840c18f 41 ocdbMakeTable galice.root MC OCDBsim.list
beec2f07 42
43
44
c4490ddb 45
46
9618bdc7 47
48 //=============================================================================
49 // Functionality to dump content of objects in human readable format
50 //=============================================================================
51 Use case examples
52 1.) compare oontent of alignent OCDB files for differnt yers
53 2.) compare ClusterParam for different periods
54
55
56
57 =================================================================================================================
58 // 1.)
59 // Compare alignment example:
60 // Compare TPC alignemnt 2013 and 2010
61 //
eaef9ce4 62 AliOCDBtoolkit::DumpOCDBFile("/cvmfs/alice.gsi.de/alice/data/2013/OCDB/TPC/Align/Data/Run0_999999999_v1_s0.root","TPCalign2013.dump",1,1);
63 AliOCDBtoolkit::DumpOCDBFile("/cvmfs/alice.gsi.de/alice/data/2010/OCDB/TPC/Align/Data/Run0_999999999_v1_s0.root","TPCalign2010.dump",1,1);
9618bdc7 64 diff TPCalign2013.dump TPCalign2010.dump > TPCalign2013_TPCalign2010.diff
65 //
66 //
67 =================================================================================================================
68 // 2.)
69 // Compare CluterParam OCDB etry
70 //
71 AliOCDBtoolkit::DumpOCDBFile("/cvmfs/alice.gsi.de/alice/data/2010/OCDB/TPC/Calib/ClusterParam/Run131541_999999999_v2_s0.root","2010_TPC_Calib_ClusterParam_Run131541_999999999_v2_s0.dump",1);
72 AliOCDBtoolkit:: AliOCDBtoolkit::DumpOCDBFile("/cvmfs/alice.gsi.de/alice/data/2010/OCDB/TPC/Calib/ClusterParam/Run0_999999999_v1_s0.root","2010_TPC_Calib_ClusterParam_Run0_999999999_v1_s0.dump",1);
73 AliOCDBtoolkit::DumpOCDBFile("/cvmfs/alice.gsi.de/alice/data/2013/OCDB/TPC/Calib/ClusterParam/Run0_999999999_v1_s0.root","2013_TPC_Calib_ClusterParam_Run0_999999999_v1_s0.dump",1);
74 diff 2010_TPC_Calib_ClusterParam_Run131541_999999999_v2_s0.dump 2010_TPC_Calib_ClusterParam_Run0_999999999_v1_s0.dump
75
76
c4490ddb 77*/
78
b840c18f 79/*
80 To check:
81 1.) Verify hash value uasge as and MD5 sum -
82
83 */
c4490ddb 84
85using namespace std;
86
87// STD
88#include <iostream>
89#include <algorithm>
90#include <sstream>
91#include <stdexcept>
92#include <functional>
9618bdc7 93#include "TRealData.h"
94#include "TDataMember.h"
95#include "TClass.h"
96#include "TROOT.h"
97#include <TVectorD.h>
c4490ddb 98//
99#include "TSystem.h"
100#include "TObjArray.h"
101#include "TString.h"
102#include "TTree.h"
103#include "TMessage.h"
104//
105#include "AliCDBManager.h"
106#include "AliCDBEntry.h"
107#include "AliOCDBtoolkit.h"
a480146e 108#include "AliCDBStorage.h"
c612d6cd 109#include "TRegexp.h"
c4490ddb 110
111void AliOCDBtoolkit::MakeDiffExampleUseCase(){
112 //
113 // Example usage for the MC
114 // To run example case, assuming presence of following files in working directory:
115 // - rec.log
116 // - galice.root
117 // - AliESDs.root
118 //
119 AliCDBManager * man = AliCDBManager::Instance();
beec2f07 120 AliOCDBtoolkit::LoadOCDBFromLog("rec.log",0);
c4490ddb 121 const TMap *cdbMapLog= man->GetStorageMap(); // this is map of
122 const TList *cdbListLog=man->GetRetrievedIds(); // this is list of AliCDBId
123 // TList *cdbListLog0=man->GetRetrievedIds(); // this is list of AliCDBId
124 //
125 TFile *fmc = TFile::Open("galice.root");
126 TMap *cdbMapMC= (TMap*)fmc->Get("cdbMap"); //
127 TList *cdbListMC0= (TList*)fmc->Get("cdbList"); // this is list of TObjStrings
beec2f07 128 TList *cdbListMC = AliOCDBtoolkit::ConvertListStringToCDBId(cdbListMC0); // convert to the TObjArray of AliCDBids
c4490ddb 129 //
130 TFile *fesd = TFile::Open("AliESDs.root");
131 TList *listESD = ((TTree*)fesd->Get("esdTree"))->GetUserInfo();
132 TMap *cdbMapESD= (TMap*)listESD->FindObject("cdbMap");
133 TList *cdbListESD0= (TList*)listESD->FindObject("cdbList"); // this is list of TObjStrings
beec2f07 134 TList *cdbListESD = AliOCDBtoolkit::ConvertListStringToCDBId(cdbListESD0); // convert to the TObjArray of AliCDBids
c4490ddb 135 //
136 //
137 //
138 printf("\n\n");
139 printf("Diff log>>>ESD\n\n:");
140 MakeDiff(cdbMapLog, cdbListLog, cdbMapESD, cdbListESD,0);
141 printf("\n\n");
142 printf("Diff ESD>>>log\n\n:");
143 MakeDiff(cdbMapESD, cdbListESD,cdbMapLog, cdbListLog,0);
144 //
145 printf("\n\n");
146 printf("Diff ESD>>>MC\n\n:");
147 MakeDiff(cdbMapMC, cdbListMC, cdbMapESD, cdbListESD,0);
148}
149
150
eaef9ce4 151void AliOCDBtoolkit::DumpOCDBAsTxt(const TString fInput, const TString fType, const TString outfile){
c4490ddb 152 //
153 //
154 //
155 TFile *file;
beec2f07 156 const TMap *cdbMap=0;
157 const TList *cdbList=0;
c4490ddb 158 //
159 //
beec2f07 160 AliCDBManager * man = AliCDBManager::Instance();
c612d6cd 161 if (fInput.Contains("alien://") && gGrid==0){
162 TGrid *myGrid = TGrid::Connect("alien://"); //Oddly this will return also a pointer if connection fails
163 if(myGrid->GetPort()==0){ //if connection fails port 0 is saved, using this to check for successful connection
164 cerr << "Cannot connect to grid!" << endl;
165 return;
166 }
167 }
c4490ddb 168 if(fType.EqualTo("MC",TString::kIgnoreCase)){
169 file = TFile::Open(fInput.Data());
beec2f07 170 cdbMap = (TMap*)file->Get("cdbMap");
171 if (!cdbMap){
172 printf("cdbMap does not exist in input file\t%s. Exiting\n",fInput.Data());
173 return;
174 }
175 //
176 man->SetDefaultStorage(((TPair*)cdbMap->FindObject("default"))->Value()->GetName());
c4490ddb 177 TList *cdbListMC0 = (TList*)file->Get("cdbList"); // this is list of TObjStrings
b840c18f 178 cdbList = AliOCDBtoolkit::ConvertListStringToCDBId(cdbListMC0); // convert to the TObjArray of AliCDBids
c4490ddb 179 }
180 else if(fType.EqualTo("ESD",TString::kIgnoreCase)){
181 file = TFile::Open(fInput.Data());
05f1b86c 182 if (!file) {
183 printf("Input file does not exist %s. Exiting\n",fInput.Data());
184 return;
185 }
c4490ddb 186 TList *listESD = ((TTree*)file->Get("esdTree"))->GetUserInfo();
187 cdbMap = (TMap*)listESD->FindObject("cdbMap");
beec2f07 188 if (!cdbMap){
189 printf("cdbMap does not exist in input file\t%s. Exiting\n",fInput.Data());
190 return;
191 }
c612d6cd 192 AliOCDBtoolkit::SetStorage(cdbMap);
c4490ddb 193 TList *cdbListESD0= (TList*)listESD->FindObject("cdbList"); // this is list of TObjStrings
194 cdbList = ConvertListStringToCDBId(cdbListESD0); // convert to the TObjArray of AliCDBids
195 }
196 else if(fType.EqualTo("log",TString::kIgnoreCase)){
c4490ddb 197 LoadOCDBFromLog(fInput.Data(),0);
198 cdbMap = man->GetStorageMap(); // this is map of
199 cdbList =man->GetRetrievedIds(); // this is list of AliCDBId
200 }
201 else{
202 printf("unsupported option: %s",fType.Data());
203 return;
204 }
205 cout <<"BEGINDUMP:" << endl;
eaef9ce4 206 DumpOCDB(cdbMap,cdbList,outfile);
c4490ddb 207}
208
209
210Bool_t AliOCDBtoolkit::ParseInfoFromOcdbString(TString ocdbString, TString &ocdbPath, Int_t &run0, Int_t &run1, Int_t &version, Int_t &subVersion){
b840c18f 211 // Functionalit
c4490ddb 212 // Parse OCDB id string and provide basic ocdb information
213 //
214 // a.) parse ocdbPath
215 Int_t indexBeginPath= ocdbString.Index("path: ")+7;
216 if (indexBeginPath<0) return kFALSE;
217 Int_t indexEndPath=ocdbString.Index(";",indexBeginPath);
218 if (indexEndPath<0) return kFALSE;
219 ocdbPath=TString(&(ocdbString.Data()[indexBeginPath]), indexEndPath-indexBeginPath-1);
220 // b.) parse runRange
221 Int_t indexRun0= ocdbString.Index(": [",indexEndPath)+3;
222 if (indexRun0<0) return kFALSE;
223 Int_t indexRun1= ocdbString.Index(",",indexRun0)+1;
224 if (indexRun1<0) return kFALSE;
225 run0=atoi(&(ocdbString.Data()[indexRun0]));
226 run1=atoi(&(ocdbString.Data()[indexRun1]));
227 AliCDBRunRange runRange(run0,run1);
228 //c.) parse version, subversion
229 Int_t indexVersion= ocdbString.Index("version: v",indexRun1)+10;
230 if (indexVersion<0) return kFALSE;
231 Int_t indexSubVersion= ocdbString.Index("_s",indexVersion)+2;
232 if (indexSubVersion<0) return kFALSE;
233 version=atoi(&(ocdbString.Data()[indexVersion]));
234 subVersion=atoi(&(ocdbString.Data()[indexSubVersion]));
235 return kTRUE;
236}
237
238Bool_t AliOCDBtoolkit::ParseInfoFromOcdbString(TString ocdbString, AliCDBId &cdbId){
239 //
240 // Parse OCDB id string and provide basic ocdb information and fillcdbID object
241 //
242 TString ocdbPath;
243 Int_t run0=0, run1=0;
244 Int_t version=0, subVersion=0;
245 Bool_t parseStatus = ParseInfoFromOcdbString(ocdbString, ocdbPath, run0,run1,version,subVersion);
246 if (parseStatus) {
247 AliCDBRunRange runRange(run0,run1);
248 cdbId=AliCDBId(ocdbPath.Data(),runRange,version,subVersion);
249 AliCDBId* id = AliCDBId::MakeFromString(ocdbString);
250 cdbId=*id;
251 delete id;
252 }
253 //
254 return parseStatus;
255}
256
257TList * AliOCDBtoolkit::ConvertListStringToCDBId(const TList *cdbList0){
258 //
259 // Convert input list of the TObjString to list to AliCDBid
260 //
261 Int_t entriesList0=cdbList0->GetEntries();
262 TList * array0 = new TList();
263 AliCDBId tmp0;
264 for (Int_t ientry0=0; ientry0<entriesList0; ientry0++){
265 if (cdbList0->At(ientry0)==0) continue;
266 Bool_t isId = cdbList0->At(ientry0)->IsA()->InheritsFrom("AliCDBId");
267 if (isId){
268 array0->AddLast(cdbList0->At(ientry0));
269 }else{
270 Bool_t isString = cdbList0->At(ientry0)->IsA()->InheritsFrom("TObjString");
271 if (isString){
272 TObjString* sid0 = dynamic_cast<TObjString*> (cdbList0->At(ientry0));
273 Bool_t status = ParseInfoFromOcdbString(sid0->String(), tmp0);
c3711112 274 if (!status) continue;
c4490ddb 275 array0->AddLast(new AliCDBId(tmp0));
276 }
277 }
278 }
279 return array0;
280}
281
282
283
284void AliOCDBtoolkit::LoadOCDBFromLog(const char *logName, Int_t verbose){
285 //
286 // Initilaize OCDB
287 // Load OCDB setting as specified in log
288 // Assuming fixed version of the log
289 // AliCDBManager is initilaized - ocdbMap and ID list can be exported
290 //
291
292 // Parsing/loading sequence:
293 // 0.) SetDefault storage *** Default Storage URI:
294 // 1.) SetSpecific storage *** Specific storage
295 // 2.) SetRunNumber Run number:
296 // 3.) Set used IDs
297 //
298 AliCDBManager * man = AliCDBManager::Instance();
299 //
300 // 0.) SetDefault storage *** Default Storage URI:
301 //
302 TString defaultOCDB = gSystem->GetFromPipe(TString::Format("cat %s| grep \"Storage URI:\"",logName).Data());
303 TObjArray *array = defaultOCDB.Tokenize("\"");
304 man->SetDefaultStorage(array->Last()->GetName());
305 delete array;
306 //
307 // 1.) SetSpecific storage *** Specific storage
308 //
309 TString specificStorage = gSystem->GetFromPipe(TString::Format("cat %s| grep \"Specific storage\"",logName).Data());
310 array = specificStorage.Tokenize("\"");
311 Int_t entries = array->GetEntries();
312 for (Int_t i=1; i<entries-2; i+=4){
313 // add protection here line shuld be in expected format
a480146e 314 if ((verbose&2)>0) printf("%s\t%s\n",array->At(i)->GetName(),array->At(i+2)->GetName());
c4490ddb 315 man->SetSpecificStorage(array->At(i)->GetName(),array->At(i+2)->GetName());
316 }
317 delete array;
318 //
319 // 2.) SetRunNumber Run number:
320 //
321 TString runLine = gSystem->GetFromPipe(TString::Format("cat %s| grep \"I-AliCDBManager::Print: Run number =\"",logName).Data());
322 array = runLine.Tokenize("=");
323 Int_t run = 0;
324 if (array->GetEntries()>1) run=atoi(array->At(1)->GetName());
325 delete array;
326 man->SetRun(run);
327 //
328 // 3.) Set used IDs
329 //
330 TString ids = gSystem->GetFromPipe(TString::Format("cat %s| grep I-AliCDB | grep path| grep range | grep version", logName).Data());
331 array= ids.Tokenize("\n");
332 entries = array->GetEntries();
333 //
334 for (Int_t i=0; i<entries; i++){
335 //
336 TString ocdbString = array->At(i)->GetName();
337 TString ocdbEntry;
338 TString ocdbPath;
339 Int_t run0=0, run1=0;
340 Int_t version=0, subVersion=0;
341 Bool_t parseStatus = ParseInfoFromOcdbString(ocdbString, ocdbPath, run0,run1,version,subVersion);
342 if (!parseStatus) continue;
343 AliCDBRunRange runRange(run0,run1);
344 //
345 if ((verbose&2)!=0) {
346 printf("%s/Run%d_%d_v%d_s%d.root\n",ocdbPath.Data(),run0,run1,version,subVersion);
347 }
348 try {
a480146e 349 man->Get(ocdbPath.Data(),runRange,version,subVersion);
c4490ddb 350 } catch(const exception &e){
351 cerr << "OCDB retrieval failed!" << endl;
352 cerr << "Detailes: " << e.what() << endl;
a480146e 353 }
c4490ddb 354 }
355 if ((verbose&1)!=0){
356 man->Print();
357 man->GetStorageMap()->Print();
358 man->GetRetrievedIds()->Print();
359 }
360}
361
b840c18f 362void AliOCDBtoolkit::SetStorage(const TMap *cdbMap){
363 //
c612d6cd 364 // Set storages as specified in the map - TO CHECK..
365 // Should go to the AliCDBmanager if not alreadyhhere +++MI
b840c18f 366 //
c612d6cd 367 // In case OCDB_PATH local variable is defined
368 // alien storage is replaced by OCDB_PATH prefix: e.g: local:///cvmfs/alice.gsi.de/
369 //
370 // Regexp extensivelly used - see documentation in ????
371 // http://wwwacs.gantep.edu.tr/guides/programming/root/htmldoc/examples/tstring.C.html
b840c18f 372 AliCDBManager * man = AliCDBManager::Instance();
373 TIter iter(cdbMap->GetTable());
374 TPair* aPair=0;
375 while ((aPair = (TPair*) iter.Next())) {
376 // aPair->Value();
377 //aPair->Print();
c612d6cd 378 TString urlOrig = aPair->Value()->GetName();
379 TString url=urlOrig; // e.g TString url="alien://?User=?DBFolder=/alice/data/2010/OCDB?SE=default?CacheFolder=?OperateDisconnected=1?CacheSize=1073741824?CleanupInterval=0"
380 man->ExtractBaseFolder(url); // url==alien://Folder=/alice/data/2010/OCDB"
381 TString ocdbPrefix(gSystem->Getenv("OCDB_PATHTEST"));
382 if (url.Length()>0){
383 TRegexp alienPrefix("^alien://Folder=");
384 url(alienPrefix)=ocdbPrefix+"";
385 }
386
387 printf("%s\t%s\t%s\n", aPair->GetName(), urlOrig.Data(), url.Data());
388 if (TString(aPair->GetName())=="default") man->SetDefaultStorage(url);
b840c18f 389 else
c612d6cd 390 man->SetSpecificStorage(aPair->GetName(), url);
b840c18f 391 }
392}
393
394void AliOCDBtoolkit::LoadOCDBFromMap(const TMap *cdbMap, const TList *cdbList){
c4490ddb 395 //
396 // Initilaize OCDB
397 // Load OCDB setting as specified in maps
b840c18f 398 // Or Do we have already implementation in AliCDBanager? TO CHECK.. Should go to the AliCDBmanager if not alreadyhhere
399 AliCDBManager * man = AliCDBManager::Instance();
400 AliOCDBtoolkit::SetStorage(cdbMap);
401 TIter iter(cdbList);
402 TObjString *ocdbString=0;
403 while (( ocdbString= (TObjString*) iter.Next())) {
404 AliCDBId* cdbId = AliCDBId::MakeFromString(ocdbString->String());
405 try {
406 // AliCDBEntry * cdbEntry = (AliCDBEntry*) man->Get(*cdbId,kTRUE);
407 man->Get(*cdbId,kTRUE);
408 } catch(const exception &e){
409 cerr << "OCDB retrieval failed!" << endl;
410 cerr << "Detailes: " << e.what() << endl;
411 }
412 }
c4490ddb 413}
414
b840c18f 415void AliOCDBtoolkit::LoadOCDBFromESD(const char *fname){
416 //
417 // Load OCDB setup from the ESD file
418 //
419 TFile * fesd = TFile::Open(fname);
420 TList *listESD = ((TTree*)fesd->Get("esdTree"))->GetUserInfo();
421 TMap *cdbMapESD= (TMap*)listESD->FindObject("cdbMap");
422 TList *cdbListESD0= (TList*)listESD->FindObject("cdbList"); // this is list of TObjStrings
c3711112 423 AliOCDBtoolkit::SetStorage(cdbMapESD);
b840c18f 424 AliOCDBtoolkit::LoadOCDBFromMap(cdbMapESD, cdbListESD0);
425}
c4490ddb 426
427
c3711112 428void AliOCDBtoolkit::MakeDiff(const TMap *cdbMap0, const TList *cdbList0, const TMap */*cdbMap1*/, const TList *cdbList1, Int_t /*verbose*/){
c4490ddb 429 //
430 //
431 // Print difference between the 2 ocdb maps
432 // Input:
433 // maps and list charactireizing OCDB setup
434 // Output:
b840c18f 435 // To be decided.
c4490ddb 436 //
c3711112 437 AliOCDBtoolkit::SetStorage(cdbMap0);
c4490ddb 438 Int_t entriesList0=cdbList0->GetEntries();
439 Int_t entriesList1=cdbList1->GetEntries();
440 //
441 for (Int_t ientry0=0; ientry0<entriesList0; ientry0++){
442 AliCDBId *id0 = dynamic_cast<AliCDBId*> (cdbList0->At(ientry0));
443 AliCDBId *id1=0;
444 for (Int_t ientry1=0; ientry1<entriesList1; ientry1++){
445 AliCDBId *cid1 = dynamic_cast<AliCDBId*> (cdbList1->At(ientry1));
446 //id0.Print();
447 //cid1.Print();
448 if (cid1->GetPath().Contains(id0->GetPath().Data())==0) continue;
449 id1=cid1;
450 }
451 if (!id1) {
452 printf("Missing entry\t");
453 id0->Print();
454 continue;
455 }
a480146e 456 // Bool_t isOK=kTRUE;
c4490ddb 457 if (id0->GetFirstRun()!= id1->GetFirstRun() ||id0->GetLastRun()!= id1->GetLastRun()){
458 printf("Differrent run range\n");
459 id0->Print();
460 id1->Print();
461 }
462 if (id0->GetVersion()!= id1->GetVersion() ||id0->GetSubVersion()!= id1->GetSubVersion()){
463 printf("Differrent version\n");
464 id0->Print();
465 id1->Print();
466 }
467 }
468}
469
eaef9ce4 470void AliOCDBtoolkit::DumpOCDB(const TMap *cdbMap0, const TList *cdbList0, const TString outfile){
c4490ddb 471 //
472 // Dump the OCDB configuatation as formated text file
473 // with following collumns
474 // cdb name prefix cdb path
475 // OCDB entries are sorted alphabetically
476 // e.g:
477 // 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
478
479 AliCDBManager * man = AliCDBManager::Instance();
c3711112 480 AliOCDBtoolkit::SetStorage(cdbMap0);
c4490ddb 481 TList * cdbList = (TList*) cdbList0; // sorted array
482 cdbList->Sort();
483
484 TIter next(cdbList);
beec2f07 485 AliCDBId *CDBId=0;
486 TString cdbName="";
487 TString cdbPath="";
c4490ddb 488 TObjString *ostr;
beec2f07 489 AliCDBEntry *cdbEntry=0;
c4490ddb 490 UInt_t hash;
491 TMessage * file;
492 Int_t size;
eaef9ce4 493 FILE *ofs = fopen(outfile.Data(),"w");
c4490ddb 494
495 while ((CDBId =(AliCDBId*) next())){
496 cdbName = CDBId->GetPath();
497 ostr = (TObjString*)cdbMap0->GetValue(cdbName.Data());
498 if(!ostr) ostr = (TObjString*)cdbMap0->GetValue("default");
499 cdbPath = ostr->GetString();
500 if(cdbPath.Contains("local://"))cdbPath=cdbPath(8,cdbPath.Length()).Data();
05f1b86c 501 try {
502 cdbEntry = (AliCDBEntry*) man->Get(*CDBId,kTRUE);
503 }catch(const exception &e){
504 cerr << "OCDB retrieval failed!" << endl;
505 cerr << "Detailes: " << e.what() << endl;
00559ed1 506 hash=0;
507 size=-1;
05f1b86c 508 }
beec2f07 509 if (!cdbEntry) {
510 printf("Object not avaliable\n");
511 CDBId->Print();
512 continue;
513 }
c4490ddb 514 TObject *obj = cdbEntry->GetObject();
515 file = new TMessage(TBuffer::kWrite);
516 file->WriteObject(obj);
517 size = file->Length();
518 if(!obj){
eaef9ce4 519 fprintf(ofs,"object %s empty!\n",cdbName.Data());
c4490ddb 520 continue;
521 }
522 hash = TString::Hash(file->Buffer(),size);
eaef9ce4 523 fprintf(ofs,"%s\t%s\t%s/Run%d_%d_v%d_s%d.root\t%d\t%u\n",
c4490ddb 524 cdbName.Data(),
525 cdbPath.Data(),
526 cdbName.Data(),
527 CDBId->GetFirstRun(),
528 CDBId->GetLastRun(),
529 CDBId->GetVersion(),
530 CDBId->GetSubVersion(),
531 size,
532 hash
533 );
534 //if(!(CDBId->GetPathLevel(0)).Contains("TPC")) continue;
535 //cout << CDBId.ToString() << endl;
536 delete file;
537 }
eaef9ce4 538 fclose(ofs);
c4490ddb 539}
9618bdc7 540
541
542//====================================================================================================
543// Dump object part
544//====================================================================================================
545
546
547
548
549
550void AliOCDBtoolkit::DumpOCDBFile(const char *finput , const char *foutput, Bool_t dumpMetaData, Bool_t xml){
551 //
552 //
553 // DumpOCDBFile("$ALICE_ROOT/OCDB/ITS/Align/Data/Run0_999999999_v0_s0.root", "ITS_Align_Data_Run0_999999999_v0_s0.dump")
554 //
555 if (finput==0) return ;
556 TFile *falignITS = TFile::Open(finput);
557 AliCDBEntry *entry = (AliCDBEntry*)falignITS->Get("AliCDBEntry");
558 if (!entry) return;
559 TObject *obj = ((AliCDBEntry*)falignITS->Get("AliCDBEntry"))->GetObject();
560
561 //
562 if (!xml){
563 if (dumpMetaData) gROOT->ProcessLine(TString::Format("((TObject*)%p)->Dump(); >%s",entry, foutput).Data());
564 if (!obj) return;
eaef9ce4 565 gROOT->ProcessLine(TString::Format("AliOCDBtoolkit::DumpObjectRecursive((TObject*)%p); >>%s",obj, foutput).Data());
9618bdc7 566 }
567 if (xml){
568 TFile * f = TFile::Open(TString::Format("%s.xml",foutput).Data(),"recreate");
569 if (dumpMetaData) entry->Write("AliCDBEntry");
570 else obj->Write("AliCDBEntry");
571 f->Close();
572 }
573}
574
575
576
577void AliOCDBtoolkit::DumpObjectRecursive(TObject *obj){
578 //
579 //
580 //
581 Int_t counterRec=0;
582 printf("==> Dumping object at: %p, name=%s, class=%s)\n", obj, obj->GetName(), (obj->IsA()->GetName()));
583 DumpObjectRecursive(obj, TString(obj->IsA()->GetName())+".",counterRec);
584}
585
586//
587//
588//
589void AliOCDBtoolkit::DumpObjectRecursive(TObject *obj, TString prefix, Int_t &counterRec){
590 //
591 // Recursive dump of the TObject
592 // Dump all basic types and follow pointers to the objects
593 // current limitation:
594 // a.) clases and structures not derived from TObject not followed (to fix)
595 // b.) dynamic arrays not followed
596 // c.) std maps,array .... not followed
597 //
598 //
599 if (!obj) return;
600 //
601 // Special case of Collection classes
602 //
603 if (obj->IsA()->InheritsFrom(TCollection::Class())) {
604 TIter myiter((TCollection*)obj);
605 TObject *arObject=0;
606 Int_t counter=0;
607 while ((arObject = (TObject*)myiter.Next())) {
608 TString prefixArr = TString::Format("%s[%d]",prefix.Data(),counter);
609 DumpObjectRecursive(arObject,prefixArr,counterRec);
610 counter++;
611 }
612 counterRec++;
613 return;
614 }
615
616 TClass * cl = obj->IsA();
617 if (!(cl->GetListOfRealData())) cl->BuildRealData();
618 TRealData* rd = 0;
619 TIter next(cl->GetListOfRealData());
620 while ((rd = (TRealData*) next())) {
621 counterRec++;
622 TDataMember* dm = rd->GetDataMember();
623 TDataType* dtype = dm->GetDataType();
624 Int_t offset = rd->GetThisOffset();
625 char* pointer = ((char*) obj) + offset;
626
627 if (dm->IsaPointer()) {
628 // We have a pointer to an object or a pointer to an array of basic types.
629 TClass* clobj = 0;
630 if (!dm->IsBasic()) {
631 clobj = TClass::GetClass(dm->GetTypeName());
632 }
633 if (clobj) {
634 // We have a pointer to an object.
635 //
636 if (!clobj->InheritsFrom(TObject::Class())) {
637 // It must be a TObject object.
638 continue;
639 }
640 char** apointer = (char**) pointer;
641 TObject* robj = (TObject*) *apointer;
642 //
643 if(!robj)
644 printf("M:%s%s\n",prefix.Data(),dm->GetName()); // Missing - 0 pointer
645 else{
646 printf("T:%s\t%s%s\n", clobj->GetName(),prefix.Data(), dm->GetName());
647 TString prefixNew=prefix;
648 prefixNew+=dm->GetName();
649 prefixNew+=".";
650 if (robj!=obj) DumpObjectRecursive(robj,prefixNew,counterRec); // trivial check
651 if (robj==obj){
652 printf("R:%s\t%s%s\n",clobj->GetName(),prefix.Data(), dm->GetName());
653 }
654 }
655 }
656 } else if (dm->IsBasic()) {
657 //
658 // Basic data type
659 //
660 const char* index = dm->GetArrayIndex();
661 if (dm->GetArrayDim()==0){
662 printf("B:\t%s%s\t%s\n", prefix.Data(),rd->GetName(), dtype->AsString(pointer));
663 }
664 //
665 // Basic array - fixed length
666 //
667 // if (dm->GetArrayDim()>0 && strlen(index) != 0){
668 if (dm->GetArrayDim()>0 ){
669 printf("A:\t%s%s\t",prefix.Data(),rd->GetName());
670 Int_t counter=0;
671 for (Int_t idim=0; idim<dm->GetArrayDim(); idim++){
672 //printf("A:%d\t%d\n", dm->GetArrayDim(),dm->GetMaxIndex(idim));
673 for (Int_t j=0; j<dm->GetMaxIndex(idim); j++){
674 printf("%s\t",dtype->AsString(pointer+dm->GetUnitSize()*counter));
675 counter++;
676 if (counter%5==0) printf("\nA:\t%s%s\t",prefix.Data(),rd->GetName());
677 }
678 }
679 printf("\n");
680 }
681 //
682 // Basic array - dynamic length
683 //
684 if (dm->GetArrayDim()>0 && strlen(index) != 0){
685 //
686 // Dump first only for the moment
687 //
688 printf("B:\t%s%s\t%s\n",prefix.Data(),rd->GetName(), dtype->AsString(pointer));
689 }
690 } else {
691 }
692 }
693}
694
695//
696// Small checks to test the TRealData and TDataType
697//
698
699
700
701void DumpDataSimple(){
702 //
703 // Dump example for elenatr data types
704 //
705 TObject *obj = new TVectorD(20);
706 TClass * cl = obj->IsA();
707 if (!cl->GetListOfRealData()) cl->BuildRealData();
708 //
709 TRealData* rd = 0;
710 rd = (TRealData*)(cl->GetListOfRealData()->FindObject("fNrows"));
711 TDataMember* dm = rd->GetDataMember();
712 TDataType* dtype = dm->GetDataType();
713 //
714 Int_t offset = rd->GetThisOffset();
715 char* pointer = ((char*) obj) + offset;
716 printf("%s\n",dtype->AsString(pointer));
717}
718
719void DumpDataArray(){
720 //
721 // print array example
722 //
723 TObject *obj = new TVectorD(20);
724 TClass * cl = obj->IsA();
725 if (!cl->GetListOfRealData()) cl->BuildRealData();
726 TRealData* rd = 0;
727 rd = (TRealData*)(cl->GetListOfRealData()->FindObject("*fElements"));
728 TDataMember* dm = rd->GetDataMember();
729 TDataType* dtype = dm->GetDataType();
730 dtype->Print();
731 //
732 Int_t offset = rd->GetThisOffset();
733 char* pointer = ((char*) obj) + offset;
734 printf("%s\n",dtype->AsString(pointer));
735}
736
737void DumpTObjectArray(){
738 //
739 //
740 //
741 TObjArray *array = new TObjArray(10);
742 for (Int_t i=0; i<10; i++) array->AddLast(new TNamed(Form("n%d",i), Form("n%d",i)));
743 AliOCDBtoolkit::DumpObjectRecursive(array);
744 //
745 //
746 TObject *obj = array;
747 TClass * cl = obj->IsA();
748 if (!cl->GetListOfRealData()) cl->BuildRealData();
749 TRealData* rd = 0;
750 rd = (TRealData*)(cl->GetListOfRealData()->FindObject("*fCont"));
751 TDataMember* dm = rd->GetDataMember();
752 TDataType* dtype = dm->GetDataType();
753 //
754 Int_t offset = rd->GetThisOffset();
755 char* pointer = ((char*) obj) + offset;
756 char** apointer = (char**) pointer;
757 //we have pointer to pointer here
758 TObject** ppobj = (TObject**) *apointer;
759 (*ppobj)->Print();
760 //
761 TIter myiter(array);
762 TObject *arObject;
763 dtype->Print();
764 while ((arObject = (TObject*)myiter.Next())) {
765 AliOCDBtoolkit::DumpObjectRecursive(arObject);
766 }
767}
a480146e 768
769
770Bool_t AliOCDBtoolkit::AddoptOCDBEntry( const char *finput, const char *output, Int_t ustartRun, Int_t uendRun){
771 //
772 // Addopt OCDB entry - keeping all of the CDBentry quantities
484fd642 773 // // Example usage:
774 // AliOCDBtoolkit::AddoptOCDBEntry("/cvmfs/alice.gsi.de/alice/simulation/2008/v4-15-Release/Residual/TPC/Calib/ClusterParam/Run127712_130850_v4_s0.root",0,0,AliCDBRunRange::Infinity())
a480146e 775 TFile * fin = TFile::Open(finput);
776 if (!fin) return kFALSE;
777 AliCDBEntry * entry = (AliCDBEntry*) fin->Get("AliCDBEntry");
778 if (!entry) return kFALSE;
779
780 AliCDBStorage* pocdbStorage = 0;
781 if (output!=0) AliCDBManager::Instance()->GetStorage(output);
782 else{
783 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
784 pocdbStorage = AliCDBManager::Instance()->GetStorage(localStorage.Data());
785 }
786 //
787 AliCDBId idIn = entry->GetId();
788 AliCDBMetaData *metaDataIn = entry->GetMetaData();
789
790 AliCDBMetaData *metaData= new AliCDBMetaData();
791 metaData->SetObjectClassName(metaDataIn->GetObjectClassName());
792 metaData->SetResponsible(TString::Format("%s: copy",metaDataIn->GetResponsible()).Data());
793 metaData->SetBeamPeriod(metaDataIn->GetBeamPeriod());
794 //
795 metaData->SetAliRootVersion(metaDataIn->GetAliRootVersion()); //root version
796 metaData->SetComment((TString::Format("%s: copy",metaDataIn->GetComment()).Data()));
797 AliCDBId* id1=NULL;
798 id1=new AliCDBId(idIn.GetPath(), ustartRun, uendRun);
799 pocdbStorage->Put(entry->GetObject(), (*id1), metaData);
800 return kTRUE;
801}
b840c18f 802
803
804void AliOCDBtoolkit::MakeSnapshotFromTxt(const TString fInput, const TString outfile, Bool_t singleKeys){
805 //
806 // Make snasphot form the txt file
807 //
808 AliCDBManager * man = AliCDBManager::Instance();
809 LoadOCDBFromList(fInput.Data());
810 man->DumpToSnapshotFile(outfile.Data(), singleKeys);
811
812}
c612d6cd 813