Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-28 07:02:49

0001 /**
0002  \file
0003  Declaration of class Smear::EventFactory.
0004  
0005  \author    Michael Savastio
0006  \date      2011-08-19
0007  \copyright 2011 Brookhaven National Lab
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  Event factory for events of a particular type.
0025  Handles the Branch methods for that event type.
0026  The template argument can be any event type inheriting
0027  from erhic::VirtualEvent.
0028  */
0029 template<typename T>
0030 class EventFactory : public erhic::VirtualEventFactory {
0031  public:
0032   typedef T EventType;
0033   /**
0034    Destructor.
0035    */
0036   virtual ~EventFactory() { }
0037 
0038   virtual T* Create() = 0;
0039 
0040   /**
0041    Returns the name of the branch object type (Smear::Event).
0042    */
0043   virtual std::string EventName() const {
0044     return T::Class()->GetName();
0045   }
0046 
0047   /**
0048    Create and configure the output branch for smeared events in the tree.
0049    */
0050   virtual TBranch* Branch(TTree& tree, const std::string& name) {
0051     T* event(NULL);  // Temporary, just to pass to TTree::Branch()
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     }  // if
0058     return branch;
0059   }
0060 
0061   /**
0062    Create() the new event and fill the requested tree branch with it.
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     }  // if
0072   }
0073 };
0074 
0075 }  // namespace Smear
0076 
0077 #endif  // INCLUDE_EICSMEAR_SMEAR_EVENTFACTORY_H_