Skip to content
Snippets Groups Projects
Commit 9f8c5196 authored by Theodore Efremov's avatar Theodore Efremov :hibiscus:
Browse files

Changed my snakefile and added a macro to merge root file

parent bcfee946
No related branches found
No related tags found
1 merge request!27Draft: [Epic] Preparation of the environement for the new GaseousDetectorScorers...
Pipeline #359185 passed
...@@ -26,7 +26,7 @@ rule all: ...@@ -26,7 +26,7 @@ rule all:
input: input:
expand("{file}",file=analysedfile) 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: rule npanalysis:
input: input:
f"{input_directory}/{{name}}.root" f"{input_directory}/{{name}}.root"
......
void Merger(int N, const char* outputDir, const char* outputFileName, const char* inputBaseName) { void Merger(int N, const char* outputDir, const char* outputFileName, const char* inputBaseName) {
TString outputPath = Form("%s/%s", outputDir, outputFileName); TString outputPath = Form("%s/%s.root", outputDir, outputFileName);
TFile *outputFile = new TFile(outputPath, "RECREATE"); TFileMerger merger;
TList *fileList = new TList(); merger.OutputFile(outputPath, "RECREATE"); // Correct usage: specify the output file path directly
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
TString fileName = Form("%s%d.root", inputBaseName, i); // Base name + index + .root 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 ...@@ -10,18 +10,16 @@ void Merger(int N, const char* outputDir, const char* outputFileName, const char
std::cerr << "Error opening file: " << fileName << std::endl; std::cerr << "Error opening file: " << fileName << std::endl;
continue; continue;
} }
fileList->Add(inputFile); merger.AddFile(fileName); // Add file to the merger
// Display progress // Display progress
int progress = ((i + 1) * 100) / N; int progress = ((i + 1) * 100) / N;
std::cout << "\rMerging files: " << progress << "% complete." << std::flush; std::cout << "\rMerging files: " << progress << "% complete." << std::flush;
} }
TFileMerger merger; // Perform the merge operation
merger.OutputFile(outputFile, "RECREATE"); merger.Merge();
merger.Merge(fileList);
std::cout << std::endl << "Merging completed! Output saved at: " << outputPath << std::endl; std::cout << std::endl << "Merging completed! Output saved at: " << outputPath << std::endl;
outputFile->Close();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment