ATLAS Offline Software
Loading...
Searching...
No Matches
hadd.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8//
9// includes
10//
11
12#include <RootCoreUtils/hadd.h>
13
14#include <sstream>
15#include <TFileMerger.h>
16#include <TList.h>
17#include <TSystem.h>
20#include <filesystem>
21#include <stdexcept>
22
23//
24// method implementations
25//
26
27namespace RCU
28{
29 void hadd (const std::string& output_file,
30 const std::vector<std::string>& input_files,
31 unsigned max_files)
32 {
33 using namespace msgRootCoreUtils;
34
35 if (input_files.size() == 1)
36 {
37 // if there is only one input file, create a symlink instead of merging
38 std::filesystem::create_symlink (input_files.front(), output_file);
39 return;
40 }
41
42 TFileMerger merger (false, false);
43
44 merger.SetMsgPrefix ("rcu_hadd");
45 merger.SetPrintLevel (98);
46
47 if (max_files > 0)
48 {
49 merger.SetMaxOpenedFiles (max_files);
50 }
51
52 if (!merger.OutputFile (output_file.c_str(), false, 1) )
53 {
54 throw std::runtime_error ("error opening target file: " + output_file);
55 }
56
57 for (const std::string& input : input_files)
58 {
59 if (!merger.AddFile (input.c_str()))
60 {
61 throw std::runtime_error ("error adding input file: " + input);
62 }
63 }
64 merger.SetNotrees (false);
65
66 bool status = merger.Merge();
67
68 if (status)
69 {
70 ANA_MSG_INFO ("merged " << merger.GetMergeList()->GetEntries() << " input files into " << output_file);
71 } else
72 {
73 throw std::runtime_error ("hadd failure during the merge");
74 }
75 }
76}
#define ANA_MSG_INFO(xmsg,...)
Macro printing info messages.
This module defines a variety of assert style macros.
Definition Assert.cxx:23
void hadd(const std::string &output_file, const std::vector< std::string > &input_files, unsigned max_files)
effects: perform the hadd functionality guarantee: basic failures: out of memory III failures: i/o er...
Definition hadd.cxx:29