Removed memory leak (Marian)
authormarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 19 Mar 2009 19:10:31 +0000 (19:10 +0000)
committermarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 19 Mar 2009 19:10:31 +0000 (19:10 +0000)
TPC/macros/CalibFileMerger.C

index 768337c..9bf3366 100644 (file)
@@ -8,17 +8,24 @@
   2. Load libraries
   3. Merge - the output is stored in the current directory
   //
+  .x ~/rootlogon.C
   gSystem->Load("libANALYSIS");
   gSystem->Load("libTPCcalib");
-  .L $ALICE_ROOT/TPC/macros/CalibFileMerger.C
+  .L $ALICE_ROOT/TPC/macros/CalibFileMerger.C+
   CalibFileMerger();
 */
 
-void CalibFileMerger(const char* filename = "mergelist.txt") {
+#include <fstream>
+#include "TFile.h"
+#include "TObjArray.h"
+#include "AliSysInfo.h"
+#include "AliTPCcalibBase.h"
 
+void CalibFileMerger(Int_t nmax=200,const char* filename = "mergelist.txt") {
 
-  TObjArray * mergeArray= 0;
 
+  TObjArray * mergeArray= 0;
+  //
   // Open the input stream
   ifstream in;
   in.open(filename);
@@ -30,6 +37,7 @@ void CalibFileMerger(const char* filename = "mergelist.txt") {
     in >> objfile;
     if (!objfile.Contains("root")) continue; // protection    
     TFile currentFile(objfile.Data());
+    printf("Open file:Counter\t%d\tMerging file %s\n",counter,objfile.Data());
     TObjArray * carray =  (TObjArray*)currentFile.Get("TPCCalib");
     if (!carray) continue;
     if (!mergeArray) { mergeArray = carray; continue;}
@@ -37,16 +45,27 @@ void CalibFileMerger(const char* filename = "mergelist.txt") {
     for (Int_t icalib=0; icalib<mergeArray->GetEntries(); icalib++){
       AliTPCcalibBase *calib = ( AliTPCcalibBase *)mergeArray->At(icalib);
       //disable calib align
-      //if (calib->InheritsFrom("AliTPCcalibAlign")) continue;
-      if (calib) calib->Merge(carray);
+      if (calib->InheritsFrom("AliTPCcalibUnlinearity")) continue;
+      //if (calib->InheritsFrom("AliTPCcalibCosmic")) continue;
+      if (!calib) continue;
+      printf("Merging\t%s\n",calib->GetName());
+      TObjArray toMerge(1);
+      TObject *objectMerge = carray->FindObject(calib->GetName());
+      if (!objectMerge) {
+       printf("Object not found\n");
+       continue;
+      }
+      toMerge.AddAt(objectMerge,0);
+      toMerge.SetOwner(kFALSE);
+      calib->Merge(&toMerge);
     }
-    AliSysInfo::AddStamp(objfile->Data(),counter,counter,counter);
-    //currentFile.Close();
+    AliSysInfo::AddStamp(objfile.Data(),counter,counter,counter);
     carray->SetOwner(kTRUE);
     carray->Delete();
     delete carray;
     counter++;
-    //if (counter>10) break;
+    currentFile.Close();
+    if (counter>nmax) break;
   }
 
   in.close();
@@ -58,35 +77,4 @@ void CalibFileMerger(const char* filename = "mergelist.txt") {
 
 }
 
-/*
-//
-TFile * output = new TFile("CalibObjects0.root", "RECREATE");
-mergeArray->At(0)->Write();
-output->Close();
-
-TFile * output = new TFile("CalibObjects1.root", "RECREATE");
-mergeArray->At(1)->Write();
-output->Close();
-
-TFile * output = new TFile("CalibObjects2.root", "RECREATE");
-mergeArray->At(2)->Write();
-output->Close();
-
-TFile * output = new TFile("CalibObjects3.root", "RECREATE");
-mergeArray->At(3)->Write();
-output->Close();
-
-TFile * output = new TFile("CalibObjects4.root", "RECREATE");
-mergeArray->At(4)->Write();
-output->Close();
-
-TFile * output = new TFile("CalibObjects5.root", "RECREATE");
-mergeArray->At(5)->Write();
-output->Close();
-
-TFile * output = new TFile("CalibObjects6.root", "RECREATE");
-mergeArray->At(6)->Write();
-output->Close();
-*/
-