11 #include <framework/io/RootFileInfo.h>
12 #include <framework/io/RootIOUtilities.h>
13 #include <framework/dataobjects/FileMetaData.h>
14 #include <framework/datastore/DataStore.h>
23 TDirectory::TContext directoryGuard;
26 if (!
m_file || !
m_file->IsOpen())
throw std::invalid_argument(
"Could not open file");
28 auto getTree = [&file = this->
m_file](
const std::string & label,
const std::string & name, std::unique_ptr<TTree>& destination) {
30 file->GetObject(name.c_str(), tmp);
31 if (!tmp)
throw std::runtime_error(
"No " + label +
" tree found");
32 destination.reset(tmp);
38 if (
auto npersistent =
m_persistent->GetEntries(); npersistent != 1) {
39 throw std::runtime_error(
"Expected exactly one entry in persistent tree, found " + std::to_string(npersistent));
47 FileMetaData* metadata{
nullptr};
48 auto branchStatus =
m_persistent->SetBranchAddress(
"FileMetaData", &metadata);
49 if (branchStatus < 0)
throw std::runtime_error(
"Error retrieving FileMetaData branch: " + std::to_string(branchStatus));
50 if (
m_persistent->GetEntry(0) <= 0 || !metadata)
throw std::runtime_error(
"Cannot read FileMetaData");
64 std::set<std::string> result;
65 for (
const TObject* obj : * (tree.GetListOfBranches())) {
66 const auto* branch =
dynamic_cast<const TBranch*
>(obj);
67 if (!branch)
throw std::runtime_error(
"Entry in list of branches is no branch");
68 result.emplace(branch->GetName());
71 cache.emplace(std::move(result));
82 std::vector<std::string> missing;
83 std::set_difference(required.begin(), required.end(), existing.begin(), existing.end(),
84 std::inserter(missing, missing.begin()));
86 if (!missing.empty()) {
87 std::stringstream message;
88 message <<
"Branches missing from event tree: ";
89 for (
const auto& name : missing) {
90 message << name <<
", ";
92 throw std::runtime_error(message.str());