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
22//
23// method implementations
24//
25
26namespace RCU
27{
28 void hadd (const std::string& output_file,
29 const std::vector<std::string>& input_files,
30 unsigned max_files)
31 {
32 if (input_files.size() == 1)
33 {
34 // if there is only one input file, create a symlink instead of merging
35 std::filesystem::create_symlink (input_files.front(), output_file);
36 return;
37 }
38
39 TFileMerger merger (false, false);
40
41 merger.SetMsgPrefix ("rcu_hadd");
42 merger.SetPrintLevel (98);
43
44 if (max_files > 0)
45 {
46 merger.SetMaxOpenedFiles (max_files);
47 }
48
49 if (!merger.OutputFile (output_file.c_str(), false, 1) )
50 {
51 RCU_THROW_MSG ("error opening target file: " + output_file);
52 }
53
54 for (std::vector<std::string>::const_iterator input = input_files.begin(),
55 end = input_files.end(); input != end; ++ input)
56 {
57 if (!merger.AddFile (input->c_str()))
58 {
59 RCU_THROW_MSG ("error adding input file: " + *input);
60 }
61 }
62 merger.SetNotrees (false);
63
64 bool status = merger.Merge();
65
66 if (status)
67 {
68 std::ostringstream msg;
69 msg << "merged " << merger.GetMergeList()->GetEntries()
70 << " input files into " << output_file;
71 RCU_PRINT_MSG (msg.str());
72 } else
73 {
74 RCU_THROW_MSG ("hadd failure during the merge");
75 }
76 }
77}
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
#define RCU_PRINT_MSG(message)
Definition PrintMsg.h:49
This module defines a variety of assert style macros.
Definition Assert.cxx:26
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:28
MsgStream & msg
Definition testRead.cxx:32