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