EventAnalysis  1.0.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 
36  bool BeginOfEvent() override;
37  bool EndOfEvent() override;
38  bool BeginOfPass() override;
39  bool EndOfPass() override;
40  bool BeginOfProcessing() override;
41  bool EndOfProcessing() override;
42 
52  std::unique_ptr<PersistenceService> Copy(const std::string &name, const std::string &output) override;
53 
54 protected:
62 
70 
71 private:
72  /* ******* Bookkeeping structs for output data objects ******* */
73  // Event
74  struct EvObjInfo {
75  std::string dataStoreName;
77  TBranch *outputBranch;
78  void *object;
80  TClass *objClass;
81  void *prevObject; // Address used for previous fill
82  bool flag; // True if the object is present for current event
83 
84  EvObjInfo(const std::string &storeName)
85  : dataStoreName(storeName), dataStore(nullptr), outputBranch(nullptr), flag(true), object(nullptr),
86  defaultObject(nullptr), objClass(nullptr), prevObject(nullptr) {}
87  };
88  using EvObjectsBook = std::unordered_map<std::string, EvObjInfo>;
90 
91  // Global
92  struct GlobObjInfo {
93  std::string dataStoreName;
95  bool isGlob; // True if the object name is a glob expression
96  bool isAlias; // True if the object name is an alias
97  bool aliasToBeChecked; // Set to false after checking if the object name is an alias
98  TBranch *nameForEvBranch; // Branch storing the name of aliased global object for each event
99  std::string nameForThisEv;
100  std::set<std::string> actualNames; // Set of all the names assumed by the aliased object
101  bool saved; // Flag for saved global objects
102 
103  GlobObjInfo(const std::string &storeName)
104  : dataStoreName(storeName), dataStore(nullptr), isGlob(false), isAlias(false), aliasToBeChecked(true),
105  nameForEvBranch(nullptr), saved(false) {}
106  };
107  using GlobObjectsBook = std::unordered_map<std::string, GlobObjInfo>;
109 
110  /* ******* Pointers to Root output objects ******* */
111  TFile *_outputFile;
112  TTree *_eventTree;
113 
114  bool _EndOfEventForEventObject(const std::string &objName, EvObjInfo &objInfo);
115  bool _EndOfEventForGlobalObject(const std::string &objName, GlobObjInfo &objInfo);
116  bool _SaveGlobalObject(const std::string &objName, GlobObjInfo &objInfo);
117 };
118 
119 } // namespace EA
120 
121 #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:97
std::set< std::string > actualNames
Definition: RootPersistenceService.h:100
bool _EndOfEventForEventObject(const std::string &objName, EvObjInfo &objInfo)
Definition: RootPersistenceService.cpp:144
bool _SaveGlobalObject(const std::string &objName, GlobObjInfo &objInfo)
Definition: RootPersistenceService.cpp:312
bool BookPassObject(const std::string &objName, const std::string &objStore) override
Definition: RootPersistenceService.cpp:65
Definition: RootPersistenceService.h:92
Definition: PersistenceService.h:20
void * prevObject
Definition: RootPersistenceService.h:81
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:69
Base struct for Root output.
Definition: RootOutputStruct.h:24
std::string dataStoreName
Definition: RootPersistenceService.h:93
bool EndOfProcessing() override
Definition: RootPersistenceService.cpp:236
bool Connect() override
Definition: RootPersistenceService.cpp:27
observer_ptr< TFile > GetOutputFile()
Getter method for the output file.
Definition: RootPersistenceService.h:61
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
TBranch * nameForEvBranch
Definition: RootPersistenceService.h:98
TBranch * outputBranch
Definition: RootPersistenceService.h:77
EvObjectsBook _eventBook
Definition: RootPersistenceService.h:89
bool EndOfEvent() override
Save event objects on persistence medium.
Definition: RootPersistenceService.cpp:82
StorePtr dataStore
Definition: RootPersistenceService.h:76
bool BookGlobalObject(const std::string &objName, const std::string &objStore) override
Definition: RootPersistenceService.cpp:67
void * object
Definition: RootPersistenceService.h:78
bool isGlob
Definition: RootPersistenceService.h:95
std::string nameForThisEv
Definition: RootPersistenceService.h:99
std::string dataStoreName
Definition: RootPersistenceService.h:75
bool BeginOfProcessing() override
Definition: RootPersistenceService.cpp:235
std::unique_ptr< PersistenceService > Copy(const std::string &name, const std::string &output) override
Copies the persistence service.
Definition: RootPersistenceService.cpp:349
bool BeginOfPass() override
Definition: RootPersistenceService.cpp:233
void * defaultObject
Definition: RootPersistenceService.h:79
TTree * _eventTree
Definition: RootPersistenceService.h:112
GlobObjInfo(const std::string &storeName)
Definition: RootPersistenceService.h:103
StorePtr dataStore
Definition: RootPersistenceService.h:94
bool flag
Definition: RootPersistenceService.h:82
EvObjInfo(const std::string &storeName)
Definition: RootPersistenceService.h:84
bool saved
Definition: RootPersistenceService.h:101
GlobObjectsBook _globalBook
Definition: RootPersistenceService.h:108
bool EndOfPass() override
Definition: RootPersistenceService.cpp:234
Definition: RootPersistenceService.h:74
bool _EndOfEventForGlobalObject(const std::string &objName, GlobObjInfo &objInfo)
Definition: RootPersistenceService.cpp:215
TClass * objClass
Definition: RootPersistenceService.h:80
TFile * _outputFile
Definition: RootPersistenceService.h:111
bool isAlias
Definition: RootPersistenceService.h:96
bool BeginOfEvent() override
Definition: RootPersistenceService.cpp:80
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:107
Definition: RootPersistenceService.h:25
std::unordered_map< std::string, EvObjInfo > EvObjectsBook
Definition: RootPersistenceService.h:88