Belle II Software  release-08-01-10
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 
14 class TTree;
15 class TFile;
16 
17 namespace Belle2 {
22  class FileMetaData;
23  namespace RootIOUtilities {
27  class RootFileInfo {
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);
52  void checkMissingBranches(const std::set<std::string>& required, bool persistent = false);
53  private:
55  std::unique_ptr<TFile> m_file;
57  std::unique_ptr<TTree> m_persistent;
59  std::unique_ptr<TTree> m_events;
61  std::unique_ptr<FileMetaData> m_metadata;
63  std::optional<std::set<std::string>> m_persistentBranches;
65  std::optional<std::set<std::string>> m_eventBranches;
66  };
67  }
69 }
Metadata information about a file.
Definition: FileMetaData.h:29
Helper class to factorize some necessary tasks when working with Belle2 output files.
Definition: RootFileInfo.h:27
const FileMetaData & getFileMetaData()
Return the event metadata from the file.
Definition: RootFileInfo.cc:41
std::unique_ptr< TTree > m_events
Pointer to the event tree.
Definition: RootFileInfo.h:59
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...
Definition: RootFileInfo.cc:75
std::unique_ptr< FileMetaData > m_metadata
Pointer to the file metadata once it has been read.
Definition: RootFileInfo.h:61
std::optional< std::set< std::string > > m_persistentBranches
Cached set of persistent branch names.
Definition: RootFileInfo.h:63
std::unique_ptr< TFile > m_file
Pointer to the file object.
Definition: RootFileInfo.h:55
TTree & getPersistentTree()
Return a reference to the persistent tree.
Definition: RootFileInfo.h:40
std::optional< std::set< std::string > > m_eventBranches
Cached set of event branch names.
Definition: RootFileInfo.h:65
RootFileInfo(const std::string &filename)
Create an object from a given filename or url.
Definition: RootFileInfo.cc:18
TTree & getEventTree()
Return a reference to the event tree.
Definition: RootFileInfo.h:42
~RootFileInfo()
Close the file and delete all structures associated with it.
std::unique_ptr< TTree > m_persistent
Pointer to the persistent tree.
Definition: RootFileInfo.h:57
const std::set< std::string > & getBranchNames(bool persistent=false)
Return a set of branch names for either the event or the persistent tree.
Definition: RootFileInfo.cc:55
Abstract base class for different kinds of events.