From 9f8c519636b7c90249300f22700ecca4a94c2b19 Mon Sep 17 00:00:00 2001
From: "theodore.efremov" <theodore.efremov@cea.fr>
Date: Mon, 21 Oct 2024 10:49:28 +0200
Subject: [PATCH] Changed my snakefile and added a macro to merge root file

---
 Projects/AlPhaPha/2024/Snakefile     |  2 +-
 Projects/AlPhaPha/DataMacro/Merger.C | 14 ++++++--------
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/Projects/AlPhaPha/2024/Snakefile b/Projects/AlPhaPha/2024/Snakefile
index 438df75fa..08299b90b 100644
--- a/Projects/AlPhaPha/2024/Snakefile
+++ b/Projects/AlPhaPha/2024/Snakefile
@@ -26,7 +26,7 @@ rule all:
   input:
     expand("{file}",file=analysedfile)
 
-# Règle pour convertir les fichiers .fast dans le dossier .cat en .root
+# Règle pour convertir les fichiers raw en analysé
 rule npanalysis:
     input:
        f"{input_directory}/{{name}}.root"
diff --git a/Projects/AlPhaPha/DataMacro/Merger.C b/Projects/AlPhaPha/DataMacro/Merger.C
index e0acff44c..aea1e9640 100644
--- a/Projects/AlPhaPha/DataMacro/Merger.C
+++ b/Projects/AlPhaPha/DataMacro/Merger.C
@@ -1,7 +1,7 @@
 void Merger(int N, const char* outputDir, const char* outputFileName, const char* inputBaseName) {
-    TString outputPath = Form("%s/%s", outputDir, outputFileName);
-    TFile *outputFile = new TFile(outputPath, "RECREATE");
-    TList *fileList = new TList();
+    TString outputPath = Form("%s/%s.root", outputDir, outputFileName);
+    TFileMerger merger;
+    merger.OutputFile(outputPath, "RECREATE");  // Correct usage: specify the output file path directly
 
     for (int i = 0; i < N; i++) {
         TString fileName = Form("%s%d.root", inputBaseName, i); // Base name + index + .root
@@ -10,18 +10,16 @@ void Merger(int N, const char* outputDir, const char* outputFileName, const char
             std::cerr << "Error opening file: " << fileName << std::endl;
             continue;
         }
-        fileList->Add(inputFile);
+        merger.AddFile(fileName);  // Add file to the merger
 
         // Display progress
         int progress = ((i + 1) * 100) / N;
         std::cout << "\rMerging files: " << progress << "% complete." << std::flush;
     }
 
-    TFileMerger merger;
-    merger.OutputFile(outputFile, "RECREATE");
-    merger.Merge(fileList);
+    // Perform the merge operation
+    merger.Merge();
 
     std::cout << std::endl << "Merging completed! Output saved at: " << outputPath << std::endl;
-    outputFile->Close();
 }
 
-- 
GitLab