Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

EventBase.cpp

Go to the documentation of this file.
00001 
00002 #include "TObject.h"
00003 
00004 #include "cafe/EventBase.hpp"
00005 #include "cafe/Stat.hpp"
00006 
00007 extern cafe::Stat* STAT ; 
00008 
00009 namespace cafe {
00010 
00011     namespace detail {
00012         const Variables empty;
00013     }
00014 
00015     EventBase::EventBase()
00016         : _tree (0),
00017           _cookie(0),
00018           _partial_read(true)
00019     {
00020     }
00021     
00022     EventBase::~EventBase()
00023     {
00024     }
00025 
00026     // Called when the tree changes.
00027     // Set addresses for reading Branches.
00028     void EventBase::setBranchAddresses(TTree *tree)
00029     {
00030         _tree = tree;
00031         for(BranchMap::iterator it = _branches.begin();
00032             it != _branches.end();
00033             ++it) {
00034             (*it).second->setBranchAddress(tree);
00035         }
00036         _cookie++;
00037     }
00038 
00039     bool EventBase::readBranch(const std::string& branchName) 
00040     {
00041         if(_branches.find(branchName) != _branches.end()) {
00042             BranchHolderBase *branch = _branches[branchName];
00043             branch->readBranch(_tree);
00044             return true;
00045         } else if(TBranch *br = _tree->FindBranch(branchName.c_str())) {
00046             return br->GetEntry(_tree->GetReadEntry()) >= 0;
00047         } else {
00048             return false;
00049         }
00050     }
00051 
00052     bool EventBase::setPartialRead(bool allow)
00053     {
00054         bool ret = _partial_read;
00055         _partial_read = allow;
00056         return ret;
00057     }
00058 
00059     bool EventBase::getPartialRead() const
00060     {
00061         return _partial_read;
00062     }
00063 
00064     void EventBase::clear()
00065     {
00066         for(Map::iterator it = _map.begin();
00067             it != _map.end();
00068             ++it) {
00069             (*it).second->clear();
00070             delete (*it).second;
00071         }
00072         _map.clear();
00073         _tags.clear();
00074         if (STAT) STAT->eventEnd() ;
00075     }
00076 
00077     void EventBase::tag(const std::string& tag)
00078     {
00079         _tags.insert(tag);
00080     }
00081 
00082     bool EventBase::hasTag(const std::string& tag) const
00083     {
00084         return _tags.find(tag) != _tags.end();
00085     }
00086 
00087     bool EventBase::hasTag(const char *tag) const
00088     {
00089         return _tags.find(std::string(tag)) != _tags.end();
00090     }
00091 
00092     void EventBase::untag(const std::string& tag)
00093     {
00094       _tags.erase(tag);
00095     }    
00096 
00097     TTree *EventBase::getTree() const
00098     {
00099         return _tree;
00100     }
00101 
00102     int   EventBase::getCookie() const
00103     {
00104         return _cookie;
00105     }
00106 
00107     const TClonesArray *EventBase::getClonesArray(const std::string& branchName, const Variables& vars) const
00108     {
00109         BranchHolder<TClonesArray> *branch = dynamic_cast<BranchHolder<TClonesArray>*>(_branches[branchName]);
00110         if(branch == 0) {
00111             _branches[branchName] = branch = new BranchHolder<TClonesArray>(branchName);
00112             branch->setBranchAddress(_tree);
00113         }
00114         return branch->getObject(_tree, _partial_read ? vars : cafe::detail::empty, _cookie);
00115     }
00116 
00117 
00118 
00119 }
00120 
00121 ClassImp(cafe::EventBase);
00122 

Generated on Tue Mar 28 10:13:03 2006 for CAF by doxygen 1.3.4