EventAnalysis  1.2.2
RootDataProviderV0.h
Go to the documentation of this file.
1 /*
2  * RootDataProviderV0.h
3  *
4  * Created on: 24 May 2017
5  * Author: Nicola Mori
6  */
7 
10 #ifndef ROOTDATAPROVIDERV0_H_
11 #define ROOTDATAPROVIDERV0_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 
34 public:
43  RootDataProviderV0(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
95  TClass *objClass;
96  EDataType objDataType;
97  TBranch *objectBranch; // Branch for event objects
98  bool flag; // True if the object is present for current event
99  TBranch *flagBranch; // Branch for event objects
101  : object(nullptr), objClass(nullptr), objectBranch(nullptr), flag(true), flagBranch(nullptr),
102  objDataType(kOther_t) {}
103  };
104  using EvObjectsBook = std::unordered_map<std::string, EvObjInfo>;
106 
107  // Object info structure for standard global objects and for global object aliases
108  struct GlobObjInfo {
109  // Common fields for standard and for aliases
110  TClass *objClass;
111  void *object; // Input buffer for the global object
112  std::string *name; // Name of the object or alias
113 
114  // The following will be non-empty only for aliases
115  TBranch *aliasedBranch; // Branch of names for aliased global objects corresponding to the alias
116  std::map<std::string, void *> aliasedObjects; // Input buffers for aliased objects
117 
118  GlobObjInfo() : objClass(nullptr), object(nullptr), name(nullptr), aliasedBranch(nullptr) {}
119  };
120  using GlobObjectsBook = std::unordered_map<std::string, GlobObjInfo>;
122 
123  TChain *_eventChain;
124 
125  unsigned int _currentEvent;
126  bool _withoutTree; // true if we are processing a single Root file with no event tree
127  TFile *_fileWoTree; // Pointer to the single input file if it has no event tree (and thus cannot be obtained from
128  // the chain)
129  Long64_t _treeReadEntry; // entry of the current tree which is <= than the chain entry
130  Int_t _treeNumber;
131 };
132 
133 } // namespace EA
134 
135 #endif /* ROOTDATAPROVIDERV0_H_ */
virtual std::vector< std::string > FreeObjects(const std::vector< std::string > &objs, Memory::Status memStatus) override
Free the memory for given objects.
Definition: RootDataProviderV0.cpp:469
TBranch * aliasedBranch
Definition: RootDataProviderV0.h:115
EvObjectsBook _eventBook
Definition: RootDataProviderV0.h:105
std::unordered_map< std::string, EvObjInfo > EvObjectsBook
Definition: RootDataProviderV0.h:104
A smart pointer not owning the wrapped object.
Definition: ObserverPtr.h:28
TClass * objClass
Definition: RootDataProviderV0.h:110
TClass * objClass
Definition: RootDataProviderV0.h:95
RootDataProviderV0(const std::string &name, const std::string &dataSource)
Constructor.
Definition: RootDataProviderV0.cpp:25
RetrievalResult
Definition: RetrievalResult.h:16
Definition: RootDataProviderV0.h:108
std::string * name
Definition: RootDataProviderV0.h:112
Definition: RootDataProviderV0.h:93
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
EvObjInfo()
Definition: RootDataProviderV0.h:100
bool Disconnect() override
Closes the input file(s).
Definition: RootDataProviderV0.cpp:181
TFile * _fileWoTree
Definition: RootDataProviderV0.h:127
GlobObjInfo()
Definition: RootDataProviderV0.h:118
Long64_t _treeReadEntry
Definition: RootDataProviderV0.h:129
observer_ptr< TChain > GetEventChain()
Getter method for the event chain.
Definition: RootDataProviderV0.h:90
EDataType objDataType
Definition: RootDataProviderV0.h:96
TBranch * flagBranch
Definition: RootDataProviderV0.h:99
std::unordered_map< std::string, GlobObjInfo > GlobObjectsBook
Definition: RootDataProviderV0.h:120
Data provider for Root file written by legacy RootPersistenceService.
Definition: RootDataProviderV0.h:33
std::map< std::string, void * > aliasedObjects
Definition: RootDataProviderV0.h:116
ObjectCategory
Category of objects.
Definition: ObjectCategory.h:17
TChain * _eventChain
Definition: RootDataProviderV0.h:123
Generic wrapper class.
Definition: ObjectWrapper.h:28
bool _withoutTree
Definition: RootDataProviderV0.h:126
RetrievalResult GetObject(const std::string &name, ObjectCategory category, ObjectWrapper &wrapper, std::string &actualName) override
Retrieve the requested data object for current event.
Definition: RootDataProviderV0.cpp:210
void * object
Definition: RootDataProviderV0.h:111
bool flag
Definition: RootDataProviderV0.h:98
unsigned int _currentEvent
Definition: RootDataProviderV0.h:125
bool SetCurrentEvent(unsigned int event, std::vector< std::string > &notValidGlobalObjects) override
Set the current event.
Definition: RootDataProviderV0.cpp:419
void * object
Definition: RootDataProviderV0.h:94
bool Connect() override
Connects to the input file(s).
Definition: RootDataProviderV0.cpp:34
Status
Aliases for memory occupation levels.
Definition: Memory.h:23
TBranch * objectBranch
Definition: RootDataProviderV0.h:97
GlobObjectsBook _globalBook
Definition: RootDataProviderV0.h:121
observer_ptr< TFile > GetCurrentFile()
Getter method for the current input file.
Definition: RootDataProviderV0.cpp:193
Int_t _treeNumber
Definition: RootDataProviderV0.h:130
A base class for data providers.
Definition: DataProvider.h:29