]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/CDB/AliOCDBtoolkit.cxx
Update User Task
[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"
37065a94 104#include <TGrid.h>
c4490ddb 105//
106#include "AliCDBManager.h"
107#include "AliCDBEntry.h"
108#include "AliOCDBtoolkit.h"
a480146e 109#include "AliCDBStorage.h"
c612d6cd 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();
beec2f07 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
beec2f07 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
beec2f07 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;
beec2f07 157 const TMap *cdbMap=0;
158 const TList *cdbList=0;
c4490ddb 159 //
160 //
beec2f07 161 AliCDBManager * man = AliCDBManager::Instance();
c612d6cd 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());
beec2f07 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
b840c18f 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());
05f1b86c 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");
beec2f07 189 if (!cdbMap){
190 printf("cdbMap does not exist in input file\t%s. Exiting\n",fInput.Data());
191 return;
192 }
c612d6cd 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){
b840c18f 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);
c3711112 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
b840c18f 363void AliOCDBtoolkit::SetStorage(const TMap *cdbMap){
364 //
c612d6cd 365 // Set storages as specified in the map - TO CHECK..
366 // Should go to the AliCDBmanager if not alreadyhhere +++MI
b840c18f 367 //
c612d6cd 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
b840c18f 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();
c612d6cd 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);
b840c18f 390 else
c612d6cd 391 man->SetSpecificStorage(aPair->GetName(), url);
b840c18f 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
b840c18f 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
b840c18f 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
c3711112 424 AliOCDBtoolkit::SetStorage(cdbMapESD);
b840c18f 425 AliOCDBtoolkit::LoadOCDBFromMap(cdbMapESD, cdbListESD0);
426}
c4490ddb 427
428
c3711112 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:
b840c18f 436 // To be decided.
c4490ddb 437 //
c3711112 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();
c3711112 481 AliOCDBtoolkit::SetStorage(cdbMap0);
c4490ddb 482 TList * cdbList = (TList*) cdbList0; // sorted array
483 cdbList->Sort();
484
485 TIter next(cdbList);
beec2f07 486 AliCDBId *CDBId=0;
487 TString cdbName="";
488 TString cdbPath="";
c4490ddb 489 TObjString *ostr;
beec2f07 490 AliCDBEntry *cdbEntry=0;
c4490ddb 491 UInt_t hash;
492 TMessage * file;
493 Int_t size;
eaef9ce4 494 FILE *ofs = fopen(outfile.Data(),"w");
c4490ddb 495
496 while ((CDBId =(AliCDBId*) next())){
497 cdbName = CDBId->GetPath();
498 ostr = (TObjString*)cdbMap0->GetValue(cdbName.Data());
499 if(!ostr) ostr = (TObjString*)cdbMap0->GetValue("default");
500 cdbPath = ostr->GetString();
501 if(cdbPath.Contains("local://"))cdbPath=cdbPath(8,cdbPath.Length()).Data();
05f1b86c 502 try {
503 cdbEntry = (AliCDBEntry*) man->Get(*CDBId,kTRUE);
504 }catch(const exception &e){
505 cerr << "OCDB retrieval failed!" << endl;
506 cerr << "Detailes: " << e.what() << endl;
00559ed1 507 hash=0;
508 size=-1;
05f1b86c 509 }
beec2f07 510 if (!cdbEntry) {
511 printf("Object not avaliable\n");
512 CDBId->Print();
513 continue;
514 }
c4490ddb 515 TObject *obj = cdbEntry->GetObject();
516 file = new TMessage(TBuffer::kWrite);
517 file->WriteObject(obj);
518 size = file->Length();
519 if(!obj){
eaef9ce4 520 fprintf(ofs,"object %s empty!\n",cdbName.Data());
c4490ddb 521 continue;
522 }
523 hash = TString::Hash(file->Buffer(),size);
eaef9ce4 524 fprintf(ofs,"%s\t%s\t%s/Run%d_%d_v%d_s%d.root\t%d\t%u\n",
c4490ddb 525 cdbName.Data(),
526 cdbPath.Data(),
527 cdbName.Data(),
528 CDBId->GetFirstRun(),
529 CDBId->GetLastRun(),
530 CDBId->GetVersion(),
531 CDBId->GetSubVersion(),
532 size,
533 hash
534 );
535 //if(!(CDBId->GetPathLevel(0)).Contains("TPC")) continue;
536 //cout << CDBId.ToString() << endl;
537 delete file;
538 }
eaef9ce4 539 fclose(ofs);
c4490ddb 540}
9618bdc7 541
542
543//====================================================================================================
544// Dump object part
545//====================================================================================================
546
547
548
549
550
551void AliOCDBtoolkit::DumpOCDBFile(const char *finput , const char *foutput, Bool_t dumpMetaData, Bool_t xml){
552 //
553 //
554 // DumpOCDBFile("$ALICE_ROOT/OCDB/ITS/Align/Data/Run0_999999999_v0_s0.root", "ITS_Align_Data_Run0_999999999_v0_s0.dump")
555 //
556 if (finput==0) return ;
557 TFile *falignITS = TFile::Open(finput);
558 AliCDBEntry *entry = (AliCDBEntry*)falignITS->Get("AliCDBEntry");
559 if (!entry) return;
560 TObject *obj = ((AliCDBEntry*)falignITS->Get("AliCDBEntry"))->GetObject();
561
562 //
563 if (!xml){
564 if (dumpMetaData) gROOT->ProcessLine(TString::Format("((TObject*)%p)->Dump(); >%s",entry, foutput).Data());
565 if (!obj) return;
eaef9ce4 566 gROOT->ProcessLine(TString::Format("AliOCDBtoolkit::DumpObjectRecursive((TObject*)%p); >>%s",obj, foutput).Data());
9618bdc7 567 }
568 if (xml){
569 TFile * f = TFile::Open(TString::Format("%s.xml",foutput).Data(),"recreate");
570 if (dumpMetaData) entry->Write("AliCDBEntry");
571 else obj->Write("AliCDBEntry");
572 f->Close();
573 }
574}
575
576
577
578void AliOCDBtoolkit::DumpObjectRecursive(TObject *obj){
579 //
580 //
581 //
582 Int_t counterRec=0;
583 printf("==> Dumping object at: %p, name=%s, class=%s)\n", obj, obj->GetName(), (obj->IsA()->GetName()));
584 DumpObjectRecursive(obj, TString(obj->IsA()->GetName())+".",counterRec);
585}
586
587//
588//
589//
590void AliOCDBtoolkit::DumpObjectRecursive(TObject *obj, TString prefix, Int_t &counterRec){
591 //
592 // Recursive dump of the TObject
593 // Dump all basic types and follow pointers to the objects
594 // current limitation:
595 // a.) clases and structures not derived from TObject not followed (to fix)
596 // b.) dynamic arrays not followed
597 // c.) std maps,array .... not followed
598 //
599 //
600 if (!obj) return;
601 //
602 // Special case of Collection classes
603 //
604 if (obj->IsA()->InheritsFrom(TCollection::Class())) {
605 TIter myiter((TCollection*)obj);
606 TObject *arObject=0;
607 Int_t counter=0;
608 while ((arObject = (TObject*)myiter.Next())) {
609 TString prefixArr = TString::Format("%s[%d]",prefix.Data(),counter);
610 DumpObjectRecursive(arObject,prefixArr,counterRec);
611 counter++;
612 }
613 counterRec++;
614 return;
615 }
616
617 TClass * cl = obj->IsA();
618 if (!(cl->GetListOfRealData())) cl->BuildRealData();
619 TRealData* rd = 0;
620 TIter next(cl->GetListOfRealData());
621 while ((rd = (TRealData*) next())) {
622 counterRec++;
623 TDataMember* dm = rd->GetDataMember();
624 TDataType* dtype = dm->GetDataType();
625 Int_t offset = rd->GetThisOffset();
626 char* pointer = ((char*) obj) + offset;
627
628 if (dm->IsaPointer()) {
629 // We have a pointer to an object or a pointer to an array of basic types.
630 TClass* clobj = 0;
631 if (!dm->IsBasic()) {
632 clobj = TClass::GetClass(dm->GetTypeName());
633 }
634 if (clobj) {
635 // We have a pointer to an object.
636 //
637 if (!clobj->InheritsFrom(TObject::Class())) {
638 // It must be a TObject object.
639 continue;
640 }
641 char** apointer = (char**) pointer;
642 TObject* robj = (TObject*) *apointer;
643 //
644 if(!robj)
645 printf("M:%s%s\n",prefix.Data(),dm->GetName()); // Missing - 0 pointer
646 else{
647 printf("T:%s\t%s%s\n", clobj->GetName(),prefix.Data(), dm->GetName());
648 TString prefixNew=prefix;
649 prefixNew+=dm->GetName();
650 prefixNew+=".";
651 if (robj!=obj) DumpObjectRecursive(robj,prefixNew,counterRec); // trivial check
652 if (robj==obj){
653 printf("R:%s\t%s%s\n",clobj->GetName(),prefix.Data(), dm->GetName());
654 }
655 }
656 }
657 } else if (dm->IsBasic()) {
658 //
659 // Basic data type
660 //
661 const char* index = dm->GetArrayIndex();
662 if (dm->GetArrayDim()==0){
663 printf("B:\t%s%s\t%s\n", prefix.Data(),rd->GetName(), dtype->AsString(pointer));
664 }
665 //
666 // Basic array - fixed length
667 //
668 // if (dm->GetArrayDim()>0 && strlen(index) != 0){
669 if (dm->GetArrayDim()>0 ){
670 printf("A:\t%s%s\t",prefix.Data(),rd->GetName());
671 Int_t counter=0;
672 for (Int_t idim=0; idim<dm->GetArrayDim(); idim++){
673 //printf("A:%d\t%d\n", dm->GetArrayDim(),dm->GetMaxIndex(idim));
674 for (Int_t j=0; j<dm->GetMaxIndex(idim); j++){
675 printf("%s\t",dtype->AsString(pointer+dm->GetUnitSize()*counter));
676 counter++;
677 if (counter%5==0) printf("\nA:\t%s%s\t",prefix.Data(),rd->GetName());
678 }
679 }
680 printf("\n");
681 }
682 //
683 // Basic array - dynamic length
684 //
685 if (dm->GetArrayDim()>0 && strlen(index) != 0){
686 //
687 // Dump first only for the moment
688 //
689 printf("B:\t%s%s\t%s\n",prefix.Data(),rd->GetName(), dtype->AsString(pointer));
690 }
691 } else {
692 }
693 }
694}
695
696//
697// Small checks to test the TRealData and TDataType
698//
699
700
701
702void DumpDataSimple(){
703 //
704 // Dump example for elenatr data types
705 //
706 TObject *obj = new TVectorD(20);
707 TClass * cl = obj->IsA();
708 if (!cl->GetListOfRealData()) cl->BuildRealData();
709 //
710 TRealData* rd = 0;
711 rd = (TRealData*)(cl->GetListOfRealData()->FindObject("fNrows"));
712 TDataMember* dm = rd->GetDataMember();
713 TDataType* dtype = dm->GetDataType();
714 //
715 Int_t offset = rd->GetThisOffset();
716 char* pointer = ((char*) obj) + offset;
717 printf("%s\n",dtype->AsString(pointer));
718}
719
720void DumpDataArray(){
721 //
722 // print array example
723 //
724 TObject *obj = new TVectorD(20);
725 TClass * cl = obj->IsA();
726 if (!cl->GetListOfRealData()) cl->BuildRealData();
727 TRealData* rd = 0;
728 rd = (TRealData*)(cl->GetListOfRealData()->FindObject("*fElements"));
729 TDataMember* dm = rd->GetDataMember();
730 TDataType* dtype = dm->GetDataType();
731 dtype->Print();
732 //
733 Int_t offset = rd->GetThisOffset();
734 char* pointer = ((char*) obj) + offset;
735 printf("%s\n",dtype->AsString(pointer));
736}
737
738void DumpTObjectArray(){
739 //
740 //
741 //
742 TObjArray *array = new TObjArray(10);
743 for (Int_t i=0; i<10; i++) array->AddLast(new TNamed(Form("n%d",i), Form("n%d",i)));
744 AliOCDBtoolkit::DumpObjectRecursive(array);
745 //
746 //
747 TObject *obj = array;
748 TClass * cl = obj->IsA();
749 if (!cl->GetListOfRealData()) cl->BuildRealData();
750 TRealData* rd = 0;
751 rd = (TRealData*)(cl->GetListOfRealData()->FindObject("*fCont"));
752 TDataMember* dm = rd->GetDataMember();
753 TDataType* dtype = dm->GetDataType();
754 //
755 Int_t offset = rd->GetThisOffset();
756 char* pointer = ((char*) obj) + offset;
757 char** apointer = (char**) pointer;
758 //we have pointer to pointer here
759 TObject** ppobj = (TObject**) *apointer;
760 (*ppobj)->Print();
761 //
762 TIter myiter(array);
763 TObject *arObject;
764 dtype->Print();
765 while ((arObject = (TObject*)myiter.Next())) {
766 AliOCDBtoolkit::DumpObjectRecursive(arObject);
767 }
768}
a480146e 769
770
771Bool_t AliOCDBtoolkit::AddoptOCDBEntry( const char *finput, const char *output, Int_t ustartRun, Int_t uendRun){
772 //
773 // Addopt OCDB entry - keeping all of the CDBentry quantities
484fd642 774 // // Example usage:
775 // 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 776 TFile * fin = TFile::Open(finput);
777 if (!fin) return kFALSE;
778 AliCDBEntry * entry = (AliCDBEntry*) fin->Get("AliCDBEntry");
779 if (!entry) return kFALSE;
780
781 AliCDBStorage* pocdbStorage = 0;
782 if (output!=0) AliCDBManager::Instance()->GetStorage(output);
783 else{
784 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
785 pocdbStorage = AliCDBManager::Instance()->GetStorage(localStorage.Data());
786 }
787 //
788 AliCDBId idIn = entry->GetId();
789 AliCDBMetaData *metaDataIn = entry->GetMetaData();
790
791 AliCDBMetaData *metaData= new AliCDBMetaData();
792 metaData->SetObjectClassName(metaDataIn->GetObjectClassName());
793 metaData->SetResponsible(TString::Format("%s: copy",metaDataIn->GetResponsible()).Data());
794 metaData->SetBeamPeriod(metaDataIn->GetBeamPeriod());
795 //
796 metaData->SetAliRootVersion(metaDataIn->GetAliRootVersion()); //root version
797 metaData->SetComment((TString::Format("%s: copy",metaDataIn->GetComment()).Data()));
798 AliCDBId* id1=NULL;
799 id1=new AliCDBId(idIn.GetPath(), ustartRun, uendRun);
800 pocdbStorage->Put(entry->GetObject(), (*id1), metaData);
801 return kTRUE;
802}
b840c18f 803
804
805void AliOCDBtoolkit::MakeSnapshotFromTxt(const TString fInput, const TString outfile, Bool_t singleKeys){
806 //
807 // Make snasphot form the txt file
808 //
809 AliCDBManager * man = AliCDBManager::Instance();
810 LoadOCDBFromList(fInput.Data());
811 man->DumpToSnapshotFile(outfile.Data(), singleKeys);
812
813}
c612d6cd 814