Belle II Software  release-05-02-19
RootFileInfo.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 #include <memory>
12 #include <string>
13 #include <set>
14 
15 class TTree;
16 class TFile;
17 
18 namespace Belle2 {
23  class FileMetaData;
24  namespace RootIOUtilities {
28  class RootFileInfo {
29  public:
36  explicit RootFileInfo(const std::string& filename);
38  ~RootFileInfo();
39 
41  TTree& getPersistentTree() { return *m_persistent; }
43  TTree& getEventTree() { return *m_events; }
49  const std::set<std::string>& getBranchNames(bool persistent = false);
53  void checkMissingBranches(const std::set<std::string>& required, bool persistent = false);
54  private:
56  std::unique_ptr<TFile> m_file;
58  std::unique_ptr<TTree> m_persistent;
60  std::unique_ptr<TTree> m_events;
62  std::unique_ptr<FileMetaData> m_metadata;
64  std::optional<std::set<std::string>> m_persistentBranches;
66  std::optional<std::set<std::string>> m_eventBranches;
67  };
68  }
70 }
Belle2::RootIOUtilities::RootFileInfo::checkMissingBranches
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:85
Belle2::RootIOUtilities::RootFileInfo::m_file
std::unique_ptr< TFile > m_file
Pointer to the file object.
Definition: RootFileInfo.h:56
Belle2::RootIOUtilities::RootFileInfo::m_persistent
std::unique_ptr< TTree > m_persistent
Pointer to the persistent tree.
Definition: RootFileInfo.h:58
Belle2::RootIOUtilities::RootFileInfo::getPersistentTree
TTree & getPersistentTree()
Return a reference to the persistent tree.
Definition: RootFileInfo.h:41
Belle2::RootIOUtilities::RootFileInfo::getEventTree
TTree & getEventTree()
Return a reference to the event tree.
Definition: RootFileInfo.h:43
Belle2::RootIOUtilities::RootFileInfo::m_eventBranches
std::optional< std::set< std::string > > m_eventBranches
Cached set of event branch names.
Definition: RootFileInfo.h:66
Belle2::RootIOUtilities::RootFileInfo::m_persistentBranches
std::optional< std::set< std::string > > m_persistentBranches
Cached set of persistent branch names.
Definition: RootFileInfo.h:64
Belle2::FileMetaData
Metadata information about a file.
Definition: FileMetaData.h:39
Belle2::RootIOUtilities::RootFileInfo::getFileMetaData
const FileMetaData & getFileMetaData()
Return the event metadata from the file.
Definition: RootFileInfo.cc:51
Belle2::RootIOUtilities::RootFileInfo
Helper class to factorize some necessary tasks when working with Belle2 output files.
Definition: RootFileInfo.h:28
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RootIOUtilities::RootFileInfo::getBranchNames
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:65
Belle2::RootIOUtilities::RootFileInfo::RootFileInfo
RootFileInfo(const std::string &filename)
Create an object from a given filename or url.
Definition: RootFileInfo.cc:28
Belle2::RootIOUtilities::RootFileInfo::~RootFileInfo
~RootFileInfo()
Close the file and delete all structures associated with it.
Belle2::RootIOUtilities::RootFileInfo::m_events
std::unique_ptr< TTree > m_events
Pointer to the event tree.
Definition: RootFileInfo.h:60
Belle2::RootIOUtilities::RootFileInfo::m_metadata
std::unique_ptr< FileMetaData > m_metadata
Pointer to the file metadata once it has been read.
Definition: RootFileInfo.h:62