EventAnalysis  1.3.0
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 
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
104  TClass *objClass;
105  EDataType objDataType;
106  TBranch *objectBranch; // Branch for event objects
107  bool flag; // True if the object is present for current event
108  TBranch *flagBranch; // Branch for event objects
110  : object(nullptr), objClass(nullptr), objectBranch(nullptr), flag(true), flagBranch(nullptr),
111  objDataType(kOther_t) {}
112  };
113  using EvObjectsBook = std::unordered_map<std::string, EvObjInfo>;
115 
116  // Object info structure for standard global objects and for global object aliases
117  struct GlobObjInfo {
118  // Common fields for standard and for aliases
119  TClass *objClass;
120  void *object; // Input buffer for the global object
121  std::string *name; // Name of the object or alias
122 
123  // The following will be non-empty only for aliases
124  TBranch *aliasedBranch; // Branch of names for aliased global objects corresponding to the alias
125  std::map<std::string, void *> aliasedObjects; // Input buffers for aliased objects
126 
127  GlobObjInfo() : objClass(nullptr), object(nullptr), name(nullptr), aliasedBranch(nullptr) {}
128  };
129  using GlobObjectsBook = std::unordered_map<std::string, GlobObjInfo>;
131 
132  TChain *_eventChain;
133 
134  unsigned int _currentEvent;
135  bool _withoutTree; // true if we are processing a single Root file with no event tree
136  TFile *_fileWoTree; // Pointer to the single input file if it has no event tree (and thus cannot be obtained from
137  // the chain)
138  Long64_t _treeReadEntry; // entry of the current tree which is <= than the chain entry
139  Int_t _treeNumber;
140 };
141 
142 } // namespace EA
143 
144 #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:471
TBranch * aliasedBranch
Definition: RootDataProviderV0.h:124
EvObjectsBook _eventBook
Definition: RootDataProviderV0.h:114
std::unordered_map< std::string, EvObjInfo > EvObjectsBook
Definition: RootDataProviderV0.h:113
A smart pointer not owning the wrapped object.
Definition: ObserverPtr.h:28
TClass * objClass
Definition: RootDataProviderV0.h:119
TClass * objClass
Definition: RootDataProviderV0.h:104
RootDataProviderV0(const std::string &name, const std::string &dataSource)
Constructor.
Definition: RootDataProviderV0.cpp:25
RetrievalResult
Definition: RetrievalResult.h:16
Definition: RootDataProviderV0.h:117
std::string * name
Definition: RootDataProviderV0.h:121
Definition: RootDataProviderV0.h:102
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
EvObjInfo()
Definition: RootDataProviderV0.h:109
bool Disconnect() override
Closes the input file(s).
Definition: RootDataProviderV0.cpp:181
TFile * _fileWoTree
Definition: RootDataProviderV0.h:136
GlobObjInfo()
Definition: RootDataProviderV0.h:127
Long64_t _treeReadEntry
Definition: RootDataProviderV0.h:138
observer_ptr< TChain > GetEventChain()
Getter method for the event chain.
Definition: RootDataProviderV0.h:99
EDataType objDataType
Definition: RootDataProviderV0.h:105
TBranch * flagBranch
Definition: RootDataProviderV0.h:108
std::unordered_map< std::string, GlobObjInfo > GlobObjectsBook
Definition: RootDataProviderV0.h:129
Data provider for Root file written by legacy RootPersistenceService.
Definition: RootDataProviderV0.h:33
std::map< std::string, void * > aliasedObjects
Definition: RootDataProviderV0.h:125
ObjectCategory
Category of objects.
Definition: ObjectCategory.h:17
TChain * _eventChain
Definition: RootDataProviderV0.h:132
Generic wrapper class.
Definition: ObjectWrapper.h:28
bool _withoutTree
Definition: RootDataProviderV0.h:135
RetrievalResult GetObject(const std::string &name, ObjectCategory category, ObjectWrapper &wrapper, std::string &actualName) override
Get the requested data object for current event.
Definition: RootDataProviderV0.cpp:210
bool IsEventAvailable(unsigned int event)
Checks if the data provider can provide the given event.
Definition: RootDataProviderV0.cpp:469
void * object
Definition: RootDataProviderV0.h:120
bool flag
Definition: RootDataProviderV0.h:107
unsigned int _currentEvent
Definition: RootDataProviderV0.h:134
bool SetCurrentEvent(unsigned int event, std::vector< std::string > &notValidGlobalObjects) override
Set the current event.
Definition: RootDataProviderV0.cpp:419
void * object
Definition: RootDataProviderV0.h:103
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:106
GlobObjectsBook _globalBook
Definition: RootDataProviderV0.h:130
observer_ptr< TFile > GetCurrentFile()
Getter method for the current input file.
Definition: RootDataProviderV0.cpp:193
Int_t _treeNumber
Definition: RootDataProviderV0.h:139
A base class for data providers.
Definition: DataProvider.h:29