EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventFactory.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EventFactory.h
1 
10 #ifndef INCLUDE_EICSMEAR_SMEAR_EVENTFACTORY_H_
11 #define INCLUDE_EICSMEAR_SMEAR_EVENTFACTORY_H_
12 
13 #include <string>
14 
15 #include <TClass.h>
16 #include <TTree.h>
17 #include <TBranch.h>
18 
20 
21 namespace Smear {
22 
29 template<typename T>
31  public:
32  typedef T EventType;
36  virtual ~EventFactory() { }
37 
38  virtual T* Create() = 0;
39 
43  virtual std::string EventName() const {
44  return T::Class()->GetName();
45  }
46 
50  virtual TBranch* Branch(TTree& tree, const std::string& name) {
51  T* event(NULL); // Temporary, just to pass to TTree::Branch()
52  TBranch* branch = tree.Branch(name.c_str(), EventName().c_str(),
53  &event, 32000, 99);
54  branch->ResetAddress();
55  if (event) {
56  delete event;
57  } // if
58  return branch;
59  }
60 
64  virtual void Fill(TBranch& branch) {
65  T* event = Create();
66  branch.ResetAddress();
67  branch.SetAddress(&event);
68  branch.GetTree()->Fill();
69  if (event) {
70  delete event;
71  } // if
72  }
73 };
74 
75 } // namespace Smear
76 
77 #endif // INCLUDE_EICSMEAR_SMEAR_EVENTFACTORY_H_