Belle II Software  release-06-00-14
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 
13 class TTree;
14 class TFile;
15 
16 namespace Belle2 {
21  class FileMetaData;
22  namespace RootIOUtilities {
26  class RootFileInfo {
27  public:
34  explicit RootFileInfo(const std::string& filename);
37 
39  TTree& getPersistentTree() { return *m_persistent; }
41  TTree& getEventTree() { return *m_events; }
47  const std::set<std::string>& getBranchNames(bool persistent = false);
51  void checkMissingBranches(const std::set<std::string>& required, bool persistent = false);
52  private:
54  std::unique_ptr<TFile> m_file;
56  std::unique_ptr<TTree> m_persistent;
58  std::unique_ptr<TTree> m_events;
60  std::unique_ptr<FileMetaData> m_metadata;
62  std::optional<std::set<std::string>> m_persistentBranches;
64  std::optional<std::set<std::string>> m_eventBranches;
65  };
66  }
68 }
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:26
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:58
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:60
std::optional< std::set< std::string > > m_persistentBranches
Cached set of persistent branch names.
Definition: RootFileInfo.h:62
std::unique_ptr< TFile > m_file
Pointer to the file object.
Definition: RootFileInfo.h:54
TTree & getPersistentTree()
Return a reference to the persistent tree.
Definition: RootFileInfo.h:39
std::optional< std::set< std::string > > m_eventBranches
Cached set of event branch names.
Definition: RootFileInfo.h:64
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:41
~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:56
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.