ATLAS Offline Software
ttree2hdf5.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "copyRootTree.h"
6 #include "getTree.h"
7 #include "treeCopyOpts.h"
8 
9 #include "H5Cpp.h"
10 
11 #include "TFile.h"
12 #include "TChain.h"
13 
14 #include <iostream>
15 #include <memory>
16 
17 int run(int argc, char* argv[]);
18 
19 int main(int argc, char* argv[]) {
20  try {
21  return run(argc, argv);
22  } catch (std::logic_error& e) {
23  std::cerr << "ERROR: " << e.what() << ", quitting." << std::endl;
24  return 1;
25  }
26 }
27 
28 int run(int argc, char* argv[]) {
29  using namespace H5Utils;
31 
32  if (opts.exit_code != 0) return opts.exit_code;
33 
34  // Read in the root tree. We pick whatever tree is on the top level
35  // of the file. If there are two we throw an error.
36  std::string tree_name = opts.file.tree;
37  if (tree_name.size() == 0) tree_name = getTree(opts.file.in.at(0));
38  if (opts.tree.verbose) std::cout << "tree: " << tree_name << std::endl;
39  std::unique_ptr<TChain> chain(new TChain(tree_name.c_str()));
40  for (const auto& file_name: opts.file.in) {
41  if (opts.tree.verbose) std::cout << "adding " << file_name << std::endl;
42  int ret_code = chain->Add(file_name.c_str(), -1);
43  if (ret_code != 1) {
44  std::cerr << "Tree '" << tree_name << "' is missing from "
45  << file_name << std::endl;
46  return 1;
47  }
48  }
49 
50  // make the output file
51  H5::H5File out_file(opts.file.out, H5F_ACC_TRUNC);
52 
53  // All the magic appens here
54  copyRootTree(*chain, out_file, opts.tree);
55 
56  return 0;
57 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
H5Utils::getTreeCopyOpts
AppOpts getTreeCopyOpts(int argc, char *argv[])
Definition: treeCopyOpts.cxx:12
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
H5Utils::AppOpts
Definition: treeCopyOpts.h:36
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
copyRootTree.h
H5Utils::getTree
std::string getTree(const std::string &file_name)
Definition: getTree.cxx:36
physics_parameters.file_name
string file_name
Definition: physics_parameters.py:32
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
H5Utils::copyRootTree
void copyRootTree(TTree &tt, H5::Group &fg, const TreeCopyOpts &opts)
Definition: copyRootTree.cxx:125
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
H5Utils
HDF5 Tuple Writer.
Definition: common.h:20
treeCopyOpts.h
main
int main(int argc, char *argv[])
Definition: ttree2hdf5.cxx:19
getTree.h
athena.opts
opts
Definition: athena.py:88