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