EventAnalysis  1.2.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 
73  virtual std::vector<std::string> FreeObjects(const std::vector<std::string> &objs, Memory::Status memStatus) override;
74 
75 protected:
83 
91 
92 private:
93  struct EvObjInfo {
94  void *object; // Input buffer; it is nullptr when the branch address is not set
95  TClass *objClass;
96  EDataType objDataType;
97  TBranch *objectBranch; // Branch for event objects
98 
99  // The following will be used only for real names (i.e. not for aliases)
100  bool flag; // True if the object is present for current event
101  TBranch *flagBranch; // Branch for flags
102 
103  // The following will be non-empty only for aliases
104  std::map<std::string, TBranch *> aliasedBranches;
105 
107  : object(nullptr), objClass(nullptr), objectBranch(nullptr), flag(true), flagBranch(nullptr),
108  objDataType(kOther_t) {}
109  };
110  using EvObjectsBook = std::unordered_map<std::string, EvObjInfo>;
112 
113  // Object info structure for standard global objects and for global object aliases
114  struct GlobObjInfo {
115  // Common fields for standard and for aliases
116  TClass *objClass;
117  void *object; // Input buffer for the global object
118  std::string *actualName; // Name of the object or currently aliased object
119 
120  // The following will be non-empty only for aliases
121  TBranch *aliasedBranch; // Branch of names for aliased global objects corresponding to the alias
122  std::map<std::string, GlobObjInfo *> aliasedObjects; // Global book entries for aliased objects
123 
124  GlobObjInfo() : objClass(nullptr), object(nullptr), actualName(nullptr), aliasedBranch(nullptr) {}
125  };
126  using GlobObjectsBook = std::unordered_map<std::string, GlobObjInfo>;
128 
129  TChain *_eventChain;
130 
131  unsigned int _currentEvent;
132  bool _withoutTree; // true if we are processing a single Root file with no event tree
133  TFile *_fileWoTree; // Pointer to the single input file if it has no event tree (and thus cannot be obtained from
134  // the chain)
135  Long64_t _treeReadEntry; // entry of the current tree which is <= than the chain entry
136  Int_t _treeNumber;
137 };
138 
139 } // namespace EA
140 
141 #endif /* ROOTDATAPROVIDER_H_ */
bool Disconnect() override
Closes the input file(s).
Definition: RootDataProvider.cpp:270
std::unordered_map< std::string, GlobObjInfo > GlobObjectsBook
Definition: RootDataProvider.h:126
observer_ptr< TFile > GetCurrentFile()
Getter method for the current input file.
Definition: RootDataProvider.cpp:282
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:610
Definition: RootDataProvider.h:114
bool Connect() override
Connects to the input file(s).
Definition: RootDataProvider.cpp:29
TBranch * flagBranch
Definition: RootDataProvider.h:101
Long64_t _treeReadEntry
Definition: RootDataProvider.h:135
TFile * _fileWoTree
Definition: RootDataProvider.h:133
EvObjInfo()
Definition: RootDataProvider.h:106
A smart pointer not owning the wrapped object.
Definition: ObserverPtr.h:28
EDataType objDataType
Definition: RootDataProvider.h:96
GlobObjectsBook _globalBook
Definition: RootDataProvider.h:127
TBranch * aliasedBranch
Definition: RootDataProvider.h:121
std::unordered_map< std::string, EvObjInfo > EvObjectsBook
Definition: RootDataProvider.h:110
RetrievalResult
Definition: RetrievalResult.h:16
std::string * actualName
Definition: RootDataProvider.h:118
bool flag
Definition: RootDataProvider.h:100
void * object
Definition: RootDataProvider.h:94
TBranch * objectBranch
Definition: RootDataProvider.h:97
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:132
void * object
Definition: RootDataProvider.h:117
Int_t _treeNumber
Definition: RootDataProvider.h:136
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:544
Generic wrapper class.
Definition: ObjectWrapper.h:28
EvObjectsBook _eventBook
Definition: RootDataProvider.h:111
TChain * _eventChain
Definition: RootDataProvider.h:129
unsigned int _currentEvent
Definition: RootDataProvider.h:131
std::map< std::string, GlobObjInfo * > aliasedObjects
Definition: RootDataProvider.h:122
observer_ptr< TChain > GetEventChain()
Getter method for the event chain.
Definition: RootDataProvider.h:90
Status
Aliases for memory occupation levels.
Definition: Memory.h:23
GlobObjInfo()
Definition: RootDataProvider.h:124
TClass * objClass
Definition: RootDataProvider.h:95
std::map< std::string, TBranch * > aliasedBranches
Definition: RootDataProvider.h:104
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
Retrieve the requested data object for current event.
Definition: RootDataProvider.cpp:299
Definition: RootDataProvider.h:93
TClass * objClass
Definition: RootDataProvider.h:116
A base class for data providers.
Definition: DataProvider.h:29