EventAnalysis  1.1.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 #include "TChain.h"
14 #include "TDataType.h"
15 #include "data/DataProvider.h"
16 
17 class TFile;
18 class TObject;
19 class TBranch;
20 class TClass;
21 
22 namespace EA {
23 
31 public:
40  RootDataProvider(const std::string &name, const std::string &dataSource);
41 
50  bool Connect() override;
51 
56  bool Disconnect() override;
57  RetrievalResult GetObject(const std::string &name, ObjectCategory category, ObjectWrapper &wrapper,
58  std::string &actualName) override;
59  bool SetCurrentEvent(unsigned int event, std::vector<std::string> &notValidGlobalObjects) override;
60 
70  virtual std::vector<std::string> FreeObjects(const std::vector<std::string> &objs, Memory::Status memStatus) override;
71 
72 protected:
80 
88 
89 private:
90  struct EvObjInfo {
91  void *object; // Input buffer
92  TClass *objClass;
93  EDataType objDataType;
94  TBranch *objectBranch; // Branch for event objects
95  bool flag; // True if the object is present for current event
96  TBranch *flagBranch; // Branch for event objects
98  : object(nullptr), objClass(nullptr), objectBranch(nullptr), flag(true), flagBranch(nullptr),
99  objDataType(kOther_t) {}
100  };
101  using EvObjectsBook = std::unordered_map<std::string, EvObjInfo>;
103 
104  // Object info structure for standard global objects and for global object aliases
105  struct GlobObjInfo {
106  // Common fields for standard and for aliases
107  TClass *objClass;
108  void *object; // Input buffer for the global object
109  std::string *name; // Name of the object or alias
110 
111  // The following will be non-empty only for aliases
112  TBranch *aliasedBranch; // Branch of names for aliased global objects corresponding to the alias
113  std::map<std::string, void *> aliasedObjects; // Input buffers for aliased objects
114 
115  GlobObjInfo() : objClass(nullptr), object(nullptr), name(nullptr), aliasedBranch(nullptr) {}
116  };
117  using GlobObjectsBook = std::unordered_map<std::string, GlobObjInfo>;
119 
120  TChain *_eventChain;
121 
122  unsigned int _currentEvent;
123  bool _withoutTree; // true if we are processing a single Root file with no event tree
124  TFile *_fileWoTree; // Pointer to the single input file if it has no event tree (and thus cannot be obtained from
125  // the chain)
126  Long64_t _treeReadEntry; // entry of the current tree which is <= than the chain entry
127  Int_t _treeNumber;
128 };
129 
130 } // namespace EA
131 
132 #endif /* ROOTDATAPROVIDER_H_ */
bool Disconnect() override
Closes the input file(s).
Definition: RootDataProvider.cpp:153
std::unordered_map< std::string, GlobObjInfo > GlobObjectsBook
Definition: RootDataProvider.h:117
observer_ptr< TFile > GetCurrentFile()
Getter method for the current input file.
Definition: RootDataProvider.cpp:165
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:441
Definition: RootDataProvider.h:105
bool Connect() override
Connects to the input file(s).
Definition: RootDataProvider.cpp:28
TBranch * flagBranch
Definition: RootDataProvider.h:96
Long64_t _treeReadEntry
Definition: RootDataProvider.h:126
TFile * _fileWoTree
Definition: RootDataProvider.h:124
EvObjInfo()
Definition: RootDataProvider.h:97
A smart pointer not owning the wrapped object.
Definition: ObserverPtr.h:28
EDataType objDataType
Definition: RootDataProvider.h:93
GlobObjectsBook _globalBook
Definition: RootDataProvider.h:118
TBranch * aliasedBranch
Definition: RootDataProvider.h:112
std::unordered_map< std::string, EvObjInfo > EvObjectsBook
Definition: RootDataProvider.h:101
RetrievalResult
Definition: RetrievalResult.h:16
bool flag
Definition: RootDataProvider.h:95
void * object
Definition: RootDataProvider.h:91
TBranch * objectBranch
Definition: RootDataProvider.h:94
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
RootDataProvider(const std::string &name, const std::string &dataSource)
Constructor.
Definition: RootDataProvider.cpp:24
bool _withoutTree
Definition: RootDataProvider.h:123
void * object
Definition: RootDataProvider.h:108
Int_t _treeNumber
Definition: RootDataProvider.h:127
ObjectCategory
Category of objects.
Definition: ObjectCategory.h:17
std::map< std::string, void * > aliasedObjects
Definition: RootDataProvider.h:113
bool SetCurrentEvent(unsigned int event, std::vector< std::string > &notValidGlobalObjects) override
Set the current event.
Definition: RootDataProvider.cpp:391
Generic wrapper class.
Definition: ObjectWrapper.h:28
EvObjectsBook _eventBook
Definition: RootDataProvider.h:102
TChain * _eventChain
Definition: RootDataProvider.h:120
unsigned int _currentEvent
Definition: RootDataProvider.h:122
std::string * name
Definition: RootDataProvider.h:109
observer_ptr< TChain > GetEventChain()
Getter method for the event chain.
Definition: RootDataProvider.h:87
Status
Aliases for memory occupation levels.
Definition: Memory.h:23
GlobObjInfo()
Definition: RootDataProvider.h:115
TClass * objClass
Definition: RootDataProvider.h:92
Data provider for Root file written by RootPersistenceService.
Definition: RootDataProvider.h:30
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:182
Definition: RootDataProvider.h:90
TClass * objClass
Definition: RootDataProvider.h:107
A base class for data providers.
Definition: DataProvider.h:29