File indexing completed on 2025-04-02 08:47:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef INCLUDE_EICSMEAR_SMEAR_EVENTFACTORY_H_
0011 #define INCLUDE_EICSMEAR_SMEAR_EVENTFACTORY_H_
0012
0013 #include <string>
0014
0015 #include <TClass.h>
0016 #include <TTree.h>
0017 #include <TBranch.h>
0018
0019 #include "eicsmear/erhic/EventFactory.h"
0020
0021 namespace Smear {
0022
0023
0024
0025
0026
0027
0028
0029 template<typename T>
0030 class EventFactory : public erhic::VirtualEventFactory {
0031 public:
0032 typedef T EventType;
0033
0034
0035
0036 virtual ~EventFactory() { }
0037
0038 virtual T* Create() = 0;
0039
0040
0041
0042
0043 virtual std::string EventName() const {
0044 return T::Class()->GetName();
0045 }
0046
0047
0048
0049
0050 virtual TBranch* Branch(TTree& tree, const std::string& name) {
0051 T* event(NULL);
0052 TBranch* branch = tree.Branch(name.c_str(), EventName().c_str(),
0053 &event, 32000, 99);
0054 branch->ResetAddress();
0055 if (event) {
0056 delete event;
0057 }
0058 return branch;
0059 }
0060
0061
0062
0063
0064 virtual void Fill(TBranch& branch) {
0065 T* event = Create();
0066 branch.ResetAddress();
0067 branch.SetAddress(&event);
0068 branch.GetTree()->Fill();
0069 if (event) {
0070 delete event;
0071 }
0072 }
0073 };
0074
0075 }
0076
0077 #endif