EventAnalysis  1.1.0
RootPersistenceService.h
Go to the documentation of this file.
1 /*
2  * RootPersistenceService.h
3  *
4  * Created on: 12 May 2017
5  * Author: Nicola Mori
6  */
7 
8 #ifndef ROOTPERSISTENCESERVICE_H_
9 #define ROOTPERSISTENCESERVICE_H_
10 
12 
13 class TFile;
14 class TObject;
15 class TTree;
16 class TBranch;
17 class TClass;
18 class RootOutputStruct;
19 
20 #include <set>
21 #include <unordered_map>
22 
23 namespace EA {
24 
26 public:
27  RootPersistenceService(const std::string &name, const std::string &output);
28 
29  bool Connect() override;
30  bool Disconnect() override;
31 
32  bool BookEventObject(const std::string &objName, const std::string &objStore) override;
33  bool BookPassObject(const std::string &objName, const std::string &objStore) override;
34  bool BookGlobalObject(const std::string &objName, const std::string &objStore) override;
35 
40  std::vector<BookedObject> GetBookedEventObjects() override;
41 
46  std::vector<BookedObject> GetBookedPassObjects() override;
47 
52  std::vector<BookedObject> GetBookedGlobalObjects() override;
53 
54  bool BeginOfEvent() override;
55  bool EndOfEvent() override;
56  bool BeginOfPass() override;
57  bool EndOfPass() override;
58  bool BeginOfProcessing() override;
59  bool EndOfProcessing() override;
60 
70  std::unique_ptr<PersistenceService> Copy(const std::string &name, const std::string &output) override;
71 
72 protected:
80 
88 
89 private:
90  /* ******* Bookkeeping structs for output data objects ******* */
91  // Event
92  struct EvObjInfo {
93  std::string dataStoreName;
95  TBranch *outputBranch;
96  void *object;
98  TClass *objClass;
99  void *prevObject; // Address used for previous fill
100  bool flag; // True if the object is present for current event
101 
102  EvObjInfo(const std::string &storeName)
103  : dataStoreName(storeName), dataStore(nullptr), outputBranch(nullptr), flag(true), object(nullptr),
104  defaultObject(nullptr), objClass(nullptr), prevObject(nullptr) {}
105  };
106  using EvObjectsBook = std::unordered_map<std::string, EvObjInfo>;
108 
109  // Global
110  struct GlobObjInfo {
111  std::string dataStoreName;
113  bool isGlob; // True if the object name is a glob expression
114  bool isAlias; // True if the object name is an alias
115  bool aliasToBeChecked; // Set to false after checking if the object name is an alias
116  TBranch *nameForEvBranch; // Branch storing the name of aliased global object for each event
117  std::string nameForThisEv;
118  std::set<std::string> actualNames; // Set of all the names assumed by the aliased object
119  bool saved; // Flag for saved global objects
120 
121  GlobObjInfo(const std::string &storeName)
122  : dataStoreName(storeName), dataStore(nullptr), isGlob(false), isAlias(false), aliasToBeChecked(true),
123  nameForEvBranch(nullptr), saved(false) {}
124  };
125  using GlobObjectsBook = std::unordered_map<std::string, GlobObjInfo>;
127 
128  /* ******* Pointers to Root output objects ******* */
129  TFile *_outputFile;
130  TTree *_eventTree;
131 
132  bool _EndOfEventForEventObject(const std::string &objName, EvObjInfo &objInfo);
133  bool _EndOfEventForGlobalObject(const std::string &objName, GlobObjInfo &objInfo);
134  bool _SaveGlobalObject(const std::string &objName, GlobObjInfo &objInfo);
135 };
136 
137 } // namespace EA
138 
139 #endif /* ROOTPERSISTENCESERVICE_H_ */
bool BookEventObject(const std::string &objName, const std::string &objStore) override
Books an event object for persistence.
Definition: RootPersistenceService.cpp:52
bool aliasToBeChecked
Definition: RootPersistenceService.h:115
std::set< std::string > actualNames
Definition: RootPersistenceService.h:118
bool _EndOfEventForEventObject(const std::string &objName, EvObjInfo &objInfo)
Definition: RootPersistenceService.cpp:164
bool _SaveGlobalObject(const std::string &objName, GlobObjInfo &objInfo)
Definition: RootPersistenceService.cpp:332
bool BookPassObject(const std::string &objName, const std::string &objStore) override
Definition: RootPersistenceService.cpp:65
Definition: RootPersistenceService.h:110
std::vector< BookedObject > GetBookedGlobalObjects() override
Gets the list of booked global objects.
Definition: RootPersistenceService.cpp:91
Definition: PersistenceService.h:20
void * prevObject
Definition: RootPersistenceService.h:99
A smart pointer not owning the wrapped object.
Definition: ObserverPtr.h:28
observer_ptr< TTree > GetEventTree()
Getter method for the event tree.
Definition: RootPersistenceService.h:87
Base struct for Root output.
Definition: RootOutputStruct.h:24
std::string dataStoreName
Definition: RootPersistenceService.h:111
bool EndOfProcessing() override
Definition: RootPersistenceService.cpp:256
bool Connect() override
Definition: RootPersistenceService.cpp:27
observer_ptr< TFile > GetOutputFile()
Getter method for the output file.
Definition: RootPersistenceService.h:79
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
TBranch * nameForEvBranch
Definition: RootPersistenceService.h:116
TBranch * outputBranch
Definition: RootPersistenceService.h:95
EvObjectsBook _eventBook
Definition: RootPersistenceService.h:107
bool EndOfEvent() override
Save event objects on persistence medium.
Definition: RootPersistenceService.cpp:102
StorePtr dataStore
Definition: RootPersistenceService.h:94
bool BookGlobalObject(const std::string &objName, const std::string &objStore) override
Definition: RootPersistenceService.cpp:67
void * object
Definition: RootPersistenceService.h:96
bool isGlob
Definition: RootPersistenceService.h:113
std::string nameForThisEv
Definition: RootPersistenceService.h:117
std::string dataStoreName
Definition: RootPersistenceService.h:93
std::vector< BookedObject > GetBookedPassObjects() override
Gets the list of booked pass objects.
Definition: RootPersistenceService.cpp:89
bool BeginOfProcessing() override
Definition: RootPersistenceService.cpp:255
std::unique_ptr< PersistenceService > Copy(const std::string &name, const std::string &output) override
Copies the persistence service.
Definition: RootPersistenceService.cpp:370
bool BeginOfPass() override
Definition: RootPersistenceService.cpp:253
void * defaultObject
Definition: RootPersistenceService.h:97
TTree * _eventTree
Definition: RootPersistenceService.h:130
GlobObjInfo(const std::string &storeName)
Definition: RootPersistenceService.h:121
StorePtr dataStore
Definition: RootPersistenceService.h:112
bool flag
Definition: RootPersistenceService.h:100
EvObjInfo(const std::string &storeName)
Definition: RootPersistenceService.h:102
bool saved
Definition: RootPersistenceService.h:119
GlobObjectsBook _globalBook
Definition: RootPersistenceService.h:126
bool EndOfPass() override
Definition: RootPersistenceService.cpp:254
Definition: RootPersistenceService.h:92
bool _EndOfEventForGlobalObject(const std::string &objName, GlobObjInfo &objInfo)
Definition: RootPersistenceService.cpp:235
TClass * objClass
Definition: RootPersistenceService.h:98
TFile * _outputFile
Definition: RootPersistenceService.h:129
std::vector< BookedObject > GetBookedEventObjects() override
Gets the list of booked event objects.
Definition: RootPersistenceService.cpp:80
bool isAlias
Definition: RootPersistenceService.h:114
bool BeginOfEvent() override
Definition: RootPersistenceService.cpp:100
RootPersistenceService(const std::string &name, const std::string &output)
Definition: RootPersistenceService.cpp:24
bool Disconnect() override
Definition: RootPersistenceService.cpp:44
std::unordered_map< std::string, GlobObjInfo > GlobObjectsBook
Definition: RootPersistenceService.h:125
Definition: RootPersistenceService.h:25
std::unordered_map< std::string, EvObjInfo > EvObjectsBook
Definition: RootPersistenceService.h:106