]>
Commit | Line | Data |
---|---|---|
1cad2cfb | 1 | #if !defined(__CINT__) || defined(__MAKECINT__) |
2 | #include "AliCDBManager.h" | |
3 | #include "AliCDBStorage.h" | |
4 | #include "AliCDBEntry.h" | |
5 | #include "AliAlignObjParams.h" | |
6 | #include <TString.h> | |
7 | #include <TClonesArray.h> | |
8 | #include <TFile.h> | |
9 | #include <TError.h> | |
10 | #endif | |
11 | ||
12 | ||
13 | void MergeSetsOfAlignObjs(const char* filename1, const char* filename2, const char* det="ITS") | |
14 | { | |
15 | // example macro: building an array by merging the non-SSD entries | |
16 | // from one file (or OCDB entry) with the remaining SSD entries taken | |
17 | // from another file (or OCDB entry); the first two arguments can be local filenames | |
18 | // or URLs of the OCDB folders | |
19 | // | |
20 | const char* macroname = "MergeSetsOfAlignObjs"; | |
21 | ||
22 | TClonesArray* array1 = 0; | |
23 | TClonesArray* array2 = 0; | |
24 | ||
25 | TString arName(det); | |
26 | arName+="AlignObjs"; | |
27 | TString path(det); | |
28 | path+="/Align/Data"; | |
29 | ||
30 | TString f1(filename1); | |
31 | TString f2(filename2); | |
32 | ||
33 | AliCDBStorage* stor1 = 0; | |
34 | AliCDBStorage* stor2 = 0; | |
35 | ||
36 | Bool_t fromOcdb1=kFALSE; | |
37 | Bool_t fromOcdb2=kFALSE; | |
38 | ||
39 | if(f1.Contains("alien://folder=") || f1.Contains("local://")) fromOcdb1=kTRUE; | |
40 | if(f2.Contains("alien://folder=") || f2.Contains("local://")) fromOcdb2=kTRUE; | |
41 | ||
42 | ||
43 | AliCDBManager* cdb = AliCDBManager::Instance(); | |
44 | cdb->SetDefaultStorage("local://$ALICE_ROOT"); | |
45 | cdb->SetRun(0); | |
46 | ||
47 | if(fromOcdb1){ | |
48 | stor1 = cdb->GetStorage(f1.Data()); | |
49 | AliCDBEntry* entry = stor1->Get(path.Data(),0); | |
50 | array1 = (TClonesArray*) entry->GetObject(); | |
51 | }else{ | |
52 | TFile* filein1 = TFile::Open(f1.Data(),"READ"); | |
53 | if(!filein1) | |
54 | { | |
55 | Info(macroname,Form("Unable to open file %s! Exiting ...", f1.Data())); | |
56 | return; | |
57 | } | |
58 | array1 = (TClonesArray*) filein1->Get(arName.Data()); | |
59 | } | |
60 | if(array1){ | |
61 | Info(macroname,Form("First array has %d entries", array1->GetEntriesFast())); | |
62 | }else{ | |
63 | Info(macroname,"Unable to get first array! Exiting ..."); | |
64 | return; | |
65 | } | |
66 | ||
67 | if(fromOcdb2){ | |
68 | stor2 = cdb->GetStorage(f2.Data()); | |
69 | AliCDBEntry* entry = stor2->Get(path.Data(),0); | |
70 | array2 = (TClonesArray*) entry->GetObject(); | |
71 | }else{ | |
72 | TFile* filein2 = TFile::Open(f2.Data(),"READ"); | |
73 | if(!filein2) | |
74 | { | |
75 | Info(macroname,Form("Unable to open file %s! Exiting ...", f2.Data())); | |
76 | return; | |
77 | } | |
78 | array2 = (TClonesArray*) filein2->Get(arName.Data()); | |
79 | } | |
80 | if(array2){ | |
81 | Info(macroname,Form("Second array has %d entries", array2->GetEntriesFast())); | |
82 | }else{ | |
83 | Info(macroname,"Unable to get second array! Exiting ..."); | |
84 | return; | |
85 | } | |
86 | ||
87 | ||
88 | TClonesArray *mergedArr = new TClonesArray("AliAlignObjParams",3000); | |
89 | ||
90 | Info(macroname,"Merging objects for SPD and SDD from the first array ..."); | |
91 | // SSD starts from 500 | |
92 | for(Int_t i=0; i<500; i++) | |
93 | { | |
94 | (*mergedArr)[i] = (AliAlignObjParams*) array1->UncheckedAt(i); | |
95 | } | |
96 | ||
97 | Info(macroname,"Merging objects for SSD from the second array ..."); | |
98 | for(Int_t i=500; i<array2->GetEntriesFast(); i++) | |
99 | { | |
100 | (*mergedArr)[i] = (AliAlignObjParams*) array2->UncheckedAt(i); | |
101 | } | |
102 | ||
103 | TString foutName("merged"); | |
104 | foutName+=det; | |
105 | foutName+="Alignment.root"; | |
106 | Info(macroname,Form("... in a single array into the file %s", foutName.Data())); | |
107 | TFile* fileout = TFile::Open(foutName.Data(),"RECREATE"); | |
108 | fileout->cd(); | |
109 | fileout->WriteObject(mergedArr,arName.Data(),"kSingleKey"); | |
110 | fileout->Close(); | |
111 | ||
112 | mergedArr->Delete(); | |
113 | ||
114 | } |