EventAnalysis  1.3.0
RootDataProvider.h
Go to the documentation of this file.
1 /*
2  * RootDataProvider.h
3  *
4  * Created on: 24 May 2017
5  * Author: Nicola Mori
6  */
7 
10 #ifndef ROOTDATAPROVIDER_H_
11 #define ROOTDATAPROVIDER_H_
12 
13 // EventAnalysis headers
14 #include "data/DataProvider.h"
15 
16 // Root headers
17 #include "TChain.h"
18 #include "TDataType.h"
19 
20 class TFile;
21 class TObject;
22 class TBranch;
23 class TClass;
24 
25 namespace EA {
26 
34 public:
43  RootDataProvider(const std::string &name, const std::string &dataSource);
44 
53  bool Connect() override;
54 
59  bool Disconnect() override;
60  RetrievalResult GetObject(const std::string &name, ObjectCategory category, ObjectWrapper &wrapper,
61  std::string &actualName) override;
62  bool SetCurrentEvent(unsigned int event, std::vector<std::string> &notValidGlobalObjects) override;
63 
71  bool IsEventAvailable(unsigned int event);
72 
82  virtual std::vector<std::string> FreeObjects(const std::vector<std::string> &objs, Memory::Status memStatus) override;
83 
84 protected:
92 
100 
101 private:
102  struct EvObjInfo {
103  void *object; // Input buffer; it is nullptr when the branch address is not set
104  TClass *objClass;
105  EDataType objDataType;
106  TBranch *objectBranch; // Branch for event objects
107 
108  // The following will be used only for real names (i.e. not for aliases)
109  bool flag; // True if the object is present for current event
110  TBranch *flagBranch; // Branch for flags
111 
112  // The following will be non-empty only for aliases
113  std::map<std::string, TBranch *> aliasedBranches;
114 
116  : object(nullptr), objClass(nullptr), objectBranch(nullptr), flag(true), flagBranch(nullptr),
117  objDataType(kOther_t) {}
118  };
119  using EvObjectsBook = std::unordered_map<std::string, EvObjInfo>;
121 
122  // Object info structure for standard global objects and for global object aliases
123  struct GlobObjInfo {
124  // Common fields for standard and for aliases
125  TClass *objClass;
126  void *object; // Input buffer for the global object
127  std::string *actualName; // Name of the object or currently aliased object
128 
129  // The following will be non-empty only for aliases
130  TBranch *aliasedBranch; // Branch of names for aliased global objects corresponding to the alias
131  std::map<std::string, GlobObjInfo *> aliasedObjects; // Global book entries for aliased objects
132 
133  GlobObjInfo() : objClass(nullptr), object(nullptr), actualName(nullptr), aliasedBranch(nullptr) {}
134  };
135  using GlobObjectsBook = std::unordered_map<std::string, GlobObjInfo>;
137 
138  TChain *_eventChain;
139 
140  unsigned int _currentEvent;
141  bool _withoutTree; // true if we are processing a single Root file with no event tree
142  TFile *_fileWoTree; // Pointer to the single input file if it has no event tree (and thus cannot be obtained from
143  // the chain)
144  Long64_t _treeReadEntry; // entry of the current tree which is <= than the chain entry
145  Int_t _treeNumber;
146 };
147 
148 } // namespace EA
149 
150 #endif /* ROOTDATAPROVIDER_H_ */
bool Disconnect() override
Closes the input file(s).
Definition: RootDataProvider.cpp:272
std::unordered_map< std::string, GlobObjInfo > GlobObjectsBook
Definition: RootDataProvider.h:135
observer_ptr< TFile > GetCurrentFile()
Getter method for the current input file.
Definition: RootDataProvider.cpp:284
virtual std::vector< std::string > FreeObjects(const std::vector< std::string > &objs, Memory::Status memStatus) override
Free the memory for given objects.
Definition: RootDataProvider.cpp:630
Definition: RootDataProvider.h:123
bool Connect() override
Connects to the input file(s).
Definition: RootDataProvider.cpp:29
TBranch * flagBranch
Definition: RootDataProvider.h:110
Long64_t _treeReadEntry
Definition: RootDataProvider.h:144
TFile * _fileWoTree
Definition: RootDataProvider.h:142
EvObjInfo()
Definition: RootDataProvider.h:115
A smart pointer not owning the wrapped object.
Definition: ObserverPtr.h:28
EDataType objDataType
Definition: RootDataProvider.h:105
GlobObjectsBook _globalBook
Definition: RootDataProvider.h:136
TBranch * aliasedBranch
Definition: RootDataProvider.h:130
std::unordered_map< std::string, EvObjInfo > EvObjectsBook
Definition: RootDataProvider.h:119
RetrievalResult
Definition: RetrievalResult.h:16
std::string * actualName
Definition: RootDataProvider.h:127
bool flag
Definition: RootDataProvider.h:109
void * object
Definition: RootDataProvider.h:103
TBranch * objectBranch
Definition: RootDataProvider.h:106
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
RootDataProvider(const std::string &name, const std::string &dataSource)
Constructor.
Definition: RootDataProvider.cpp:25
bool _withoutTree
Definition: RootDataProvider.h:141
void * object
Definition: RootDataProvider.h:126
Int_t _treeNumber
Definition: RootDataProvider.h:145
ObjectCategory
Category of objects.
Definition: ObjectCategory.h:17
bool SetCurrentEvent(unsigned int event, std::vector< std::string > &notValidGlobalObjects) override
Set the current event.
Definition: RootDataProvider.cpp:553
Generic wrapper class.
Definition: ObjectWrapper.h:28
EvObjectsBook _eventBook
Definition: RootDataProvider.h:120
TChain * _eventChain
Definition: RootDataProvider.h:138
unsigned int _currentEvent
Definition: RootDataProvider.h:140
std::map< std::string, GlobObjInfo * > aliasedObjects
Definition: RootDataProvider.h:131
observer_ptr< TChain > GetEventChain()
Getter method for the event chain.
Definition: RootDataProvider.h:99
Status
Aliases for memory occupation levels.
Definition: Memory.h:23
GlobObjInfo()
Definition: RootDataProvider.h:133
TClass * objClass
Definition: RootDataProvider.h:104
std::map< std::string, TBranch * > aliasedBranches
Definition: RootDataProvider.h:113
Data provider for Root file written by RootPersistenceService.
Definition: RootDataProvider.h:33
RetrievalResult GetObject(const std::string &name, ObjectCategory category, ObjectWrapper &wrapper, std::string &actualName) override
Get the requested data object for current event.
Definition: RootDataProvider.cpp:301
Definition: RootDataProvider.h:102
bool IsEventAvailable(unsigned int event)
Checks if the data provider can provide the given event.
Definition: RootDataProvider.cpp:628
TClass * objClass
Definition: RootDataProvider.h:125
A base class for data providers.
Definition: DataProvider.h:29