Removing compilation warnings and failures
[u/mrichter/AliRoot.git] / TPC / macros / CalibFileMerger.C
1 /*
2   // Macro for merging of the calibration classes:
3 //   marain.ivanov@cern.ch
4 //   //
5 //   //
6 //   Example usage:
7 //   1. Make a list of the calibration files
8 //   2. Load libraries
9 //   3. Merge - the output is stored in the current directory
10 //   //
11 //   
12    gSystem->AddIncludePath("-I$ALICE_ROOT/TPC")
13    gSystem->Load("libANALYSIS");
14    gSystem->Load("libTPCcalib");
15    .L $ALICE_ROOT/TPC/macros/CalibFileMerger.C+g 
16 //   CalibFileMerger();
17 */
18
19 #include <fstream>
20 #include "TSystem.h"
21 #include "TFile.h"
22 #include "TObjArray.h"
23 #include "AliSysInfo.h"
24 #include "AliTPCcalibBase.h"
25
26 void CalibFileMerger(const char *oname, Int_t nmax=1000,const char* filename = "mergelist.txt") {
27
28   gSystem->Load("libANALYSIS");
29   gSystem->Load("libTPCcalib");
30   TObjArray * mergeArray= 0;
31   //
32   // Open the input stream
33   ifstream in;
34   in.open(filename);
35   
36   // Read the input list of files 
37   TString objfile;
38   Int_t counter=0;
39   while(in.good()) {
40     in >> objfile;
41     if (!objfile.Contains("root")) continue; // protection    
42     TFile currentFile(objfile.Data());
43     printf("Open file:Counter\t%d\tMerging file %s\n",counter,objfile.Data());
44     TObjArray * carray =  (TObjArray*)currentFile.Get("TPCCalib");
45     if (!carray) {
46       carray = new TObjArray;
47       TList *farr = currentFile.GetListOfKeys();
48       if (!farr) continue;
49       for (Int_t ical=0; ical<farr->GetEntries(); ical++){
50         if (!farr->At(ical)) continue;
51         TObject *obj = currentFile.Get(farr->At(ical)->GetName());
52         if (obj) carray->AddLast(obj);
53         AliSysInfo::AddStamp(farr->At(ical)->GetName(),1,ical,counter);
54         // reading entries
55       }
56       if (carray->GetEntries()==0) continue;
57     }
58    
59     if (!mergeArray) { mergeArray = carray; continue;}
60     printf("Counter\t%d\tMerging file %s\n",counter,objfile.Data());
61     for (Int_t icalib=0; icalib<mergeArray->GetEntries(); icalib++){
62       AliTPCcalibBase *calib = ( AliTPCcalibBase *)mergeArray->At(icalib);
63       //disable calib align
64       if (!calib->InheritsFrom("AliTPCcalibBase")) continue;
65       if (calib->InheritsFrom("AliTPCcalibTrigger")) continue;  // too big
66       //
67     //   if (counter>50&&counter%2>0){
68 //      if (calib->InheritsFrom("AliTPCcalibCosmic")) continue;  // too big
69 //       }
70 //       if (counter>100&&counter%4>0){
71 //      if (calib->InheritsFrom("AliTPCcalibCosmic")) continue;  // too big
72 //       }
73 //       if (counter>200&&counter%8>0){
74 //      if (calib->InheritsFrom("AliTPCcalibCosmic")) continue;  // too big
75 //       }
76       if (!calib) continue;
77       printf("Merging\t%s\n",calib->GetName());
78       TObjArray toMerge(1);
79       TObject *objectMerge = carray->FindObject(calib->GetName());
80       if (!objectMerge) {
81         printf("Object not found\n");
82         continue;
83       }
84       toMerge.AddAt(objectMerge,0);
85       toMerge.SetOwner(kFALSE);
86       calib->Merge(&toMerge);
87       AliSysInfo::AddStamp(calib->GetName(),2,icalib,counter);
88     }
89     AliSysInfo::AddStamp(objfile.Data(),counter,counter,counter);
90     if (carray){
91       carray->SetOwner(kTRUE);
92       carray->Delete();
93       // for (Int_t i=0; i<carray->GetEntriesFast(); i++){
94 //      TObject *o = carray->At(i);
95 //      if (!o) continue;
96 //      printf("Delete %s\n",o->GetName());
97 //      AliSysInfo::AddStamp(o->GetName(),3,i,counter);
98 //      delete o;
99 //       }
100       delete carray;
101     }
102     counter++;
103     currentFile.Close();
104     if (counter>nmax) break;
105   }
106
107   in.close();
108   if (mergeArray){
109     for (Int_t icalib=0; icalib<mergeArray->GetEntries(); icalib++){
110       TFile * output = new TFile(oname, "UPDATE");
111       TObject * obj = mergeArray->At(icalib); 
112       if (!obj) continue;
113       obj->Write();
114       delete obj;
115       output->Close();
116     }
117   }
118   //
119   // problem to stop root
120   // Make suicide
121   //
122   printf("Kill ourself\n");
123   printf("Kill ourself\n");
124   printf("Kill ourself\n");
125   printf("Kill ourself\n");
126   gSystem->Exec(Form("kill -9 %d",gSystem->GetPid()));
127 }
128
129