AliRoot Core  edcc906 (edcc906)
CalibFileMerger.C
Go to the documentation of this file.
1 
18 #include <fstream>
19 #include "TSystem.h"
20 #include "TFile.h"
21 #include "TObjArray.h"
22 #include "AliSysInfo.h"
23 #include "AliTPCcalibBase.h"
24 
25 void CalibFileMerger(const char *oname, Int_t nmax=1000,const char* filename = "mergelist.txt") {
26 
27  gSystem->Load("libANALYSIS");
28  gSystem->Load("libTPCcalib");
29  TObjArray * mergeArray= 0;
30  //
31  // Open the input stream
32  ifstream in;
33  in.open(filename);
34 
35  // Read the input list of files
36  TString objfile;
37  Int_t counter=0;
38  while(in.good()) {
39  in >> objfile;
40  if (!objfile.Contains("root")) continue; // protection
41  TFile currentFile(objfile.Data());
42  printf("Open file:Counter\t%d\tMerging file %s\n",counter,objfile.Data());
43  TObjArray * carray = (TObjArray*)currentFile.Get("TPCCalib");
44  if (!carray) {
45  carray = new TObjArray;
46  TList *farr = currentFile.GetListOfKeys();
47  if (!farr) continue;
48  for (Int_t ical=0; ical<farr->GetEntries(); ical++){
49  if (!farr->At(ical)) continue;
50  TObject *obj = currentFile.Get(farr->At(ical)->GetName());
51  if (obj) carray->AddLast(obj);
52  AliSysInfo::AddStamp(farr->At(ical)->GetName(),1,ical,counter);
53  // reading entries
54  }
55  if (carray->GetEntries()==0) continue;
56  }
57 
58  if (!mergeArray) { mergeArray = carray; continue;}
59  printf("Counter\t%d\tMerging file %s\n",counter,objfile.Data());
60  for (Int_t icalib=0; icalib<mergeArray->GetEntries(); icalib++){
61  AliTPCcalibBase *calib = ( AliTPCcalibBase *)mergeArray->At(icalib);
62  //disable calib align
63  if (!calib->InheritsFrom("AliTPCcalibBase")) continue;
64  if (calib->InheritsFrom("AliTPCcalibTrigger")) continue; // too big
65  //
66  // if (counter>50&&counter%2>0){
67 // if (calib->InheritsFrom("AliTPCcalibCosmic")) continue; // too big
68 // }
69 // if (counter>100&&counter%4>0){
70 // if (calib->InheritsFrom("AliTPCcalibCosmic")) continue; // too big
71 // }
72 // if (counter>200&&counter%8>0){
73 // if (calib->InheritsFrom("AliTPCcalibCosmic")) continue; // too big
74 // }
75  if (!calib) continue;
76  printf("Merging\t%s\n",calib->GetName());
77  TObjArray toMerge(1);
78  TObject *objectMerge = carray->FindObject(calib->GetName());
79  if (!objectMerge) {
80  printf("Object not found\n");
81  continue;
82  }
83  toMerge.AddAt(objectMerge,0);
84  toMerge.SetOwner(kFALSE);
85  calib->Merge(&toMerge);
86  AliSysInfo::AddStamp(calib->GetName(),2,icalib,counter);
87  }
88  AliSysInfo::AddStamp(objfile.Data(),counter,counter,counter);
89  if (carray){
90  carray->SetOwner(kTRUE);
91  carray->Delete();
92  // for (Int_t i=0; i<carray->GetEntriesFast(); i++){
93 // TObject *o = carray->At(i);
94 // if (!o) continue;
95 // printf("Delete %s\n",o->GetName());
96 // AliSysInfo::AddStamp(o->GetName(),3,i,counter);
97 // delete o;
98 // }
99  delete carray;
100  }
101  counter++;
102  currentFile.Close();
103  if (counter>nmax) break;
104  }
105 
106  in.close();
107  if (mergeArray){
108  for (Int_t icalib=0; icalib<mergeArray->GetEntries(); icalib++){
109  TFile * output = new TFile(oname, "UPDATE");
110  TObject * obj = mergeArray->At(icalib);
111  if (!obj) continue;
112  obj->Write();
113  delete obj;
114  output->Close();
115  }
116  }
117  //
118  // problem to stop root
119  // Make suicide
120  //
121  printf("Kill ourself\n");
122  printf("Kill ourself\n");
123  printf("Kill ourself\n");
124  printf("Kill ourself\n");
125  gSystem->Exec(Form("kill -9 %d",gSystem->GetPid()));
126 }
127 
128 
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
#define TObjArray
void CalibFileMerger(const char *oname, Int_t nmax=1000, const char *filename="mergelist.txt")
char * oname
static void AddStamp(const char *sname, Int_t id0=-1, Int_t id1=-1, Int_t id2=-1, Int_t id3=-1)
Definition: AliSysInfo.cxx:179