ATLAS Offline Software
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>
18 #include <RootCoreUtils/Assert.h>
19 #include <RootCoreUtils/PrintMsg.h>
20 #include <filesystem>
21 
22 //
23 // method implementations
24 //
25 
26 namespace 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 }
TFileMerger.h
hadd.h
RCU
This module defines a variety of assert style macros.
Definition: Assert.cxx:26
Assert.h
sg-dump.input_files
list input_files
Definition: sg-dump.py:124
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
RCU::hadd
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
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
mergePhysValFiles.output_file
output_file
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:27
RCU_PRINT_MSG
#define RCU_PRINT_MSG(message)
Definition: PrintMsg.h:49
merge.status
status
Definition: merge.py:17
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
PrintMsg.h