Belle II Software development
RootFileInfo.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9#include <memory>
10#include <string>
11#include <set>
12#include <optional>
13
14class TTree;
15class TFile;
16
17namespace Belle2 {
22 class FileMetaData;
23 namespace RootIOUtilities {
28 public:
35 explicit RootFileInfo(const std::string& filename);
38
40 TTree& getPersistentTree() { return *m_persistent; }
42 TTree& getEventTree() { return *m_events; }
48 const std::set<std::string>& getBranchNames(bool persistent = false);
50 const std::set<std::string> getNtupleBranchNames(std::string treeName);
52 const std::set<std::string> getTreeNames();
56 void checkMissingBranches(const std::set<std::string>& required, bool persistent = false);
57 private:
59 std::unique_ptr<TFile> m_file;
61 std::unique_ptr<TTree> m_persistent;
63 std::unique_ptr<TTree> m_events;
65 std::unique_ptr<FileMetaData> m_metadata;
67 std::optional<std::set<std::string>> m_persistentBranches;
69 std::optional<std::set<std::string>> m_eventBranches;
70 };
71 }
72
73}
Metadata information about a file.
const std::set< std::string > getTreeNames()
Return a set of event tree names in the file.
const FileMetaData & getFileMetaData()
Return the event metadata from the file.
std::unique_ptr< TTree > m_events
Pointer to the event tree.
void checkMissingBranches(const std::set< std::string > &required, bool persistent=false)
Check if the event or persistent tree contain at least all the branches in the set of required branch...
std::unique_ptr< FileMetaData > m_metadata
Pointer to the file metadata once it has been read.
TTree & getPersistentTree()
Return a reference to the persistent tree.
std::optional< std::set< std::string > > m_persistentBranches
Cached set of persistent branch names.
std::unique_ptr< TFile > m_file
Pointer to the file object.
std::optional< std::set< std::string > > m_eventBranches
Cached set of event branch names.
RootFileInfo(const std::string &filename)
Create an object from a given filename or url.
~RootFileInfo()
Close the file and delete all structures associated with it.
const std::set< std::string > getNtupleBranchNames(std::string treeName)
Return a set of branch names residing in the passed tree.
std::unique_ptr< TTree > m_persistent
Pointer to the persistent tree.
TTree & getEventTree()
Return a reference to the event tree.
const std::set< std::string > & getBranchNames(bool persistent=false)
Return a set of branch names for either the event or the persistent tree.
Some constants and helpers common to the RootInput and RootOutput modules.
Abstract base class for different kinds of events.