hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Event.cxx
Go to the documentation of this file.
1
8#include "Event.h"
9
10/*~~~~~~~~~~*/
11/* LCIO */
12/*~~~~~~~~~~*/
13#include <EVENT/LCCollection.h>
14
16
17 // Create the tree
18 //tree_ = new TTree("HPS_Event", "HPS event tree");
19
20 // Instantiate the event header
22}
23
25
26void Event::add(const std::string name, TObject* object) {
27
28 // Check if the object has been added to the event.
29 if (objects_.find(name) != objects_.end()) {
30 object->Copy(*objects_[name]);
31 return;
32 }
33
34 // Create a clone of the object
35 TObject* cp = object->Clone();
36 objects_[name] = cp;
37
38 // Add a branch with the given name to the event tree.
39 branches_[name] = tree_->Branch(name.c_str(), cp);
40
41 // Copy the object to the event
42 object->Copy(*cp);
43}
44
45void Event::addCollection(const std::string name, TClonesArray* collection) {
46
47 // Check if the collection has been added
48 if (objects_.find(name) != objects_.end()) return;
49
50 // Add a branch with the given name to the event tree.
51 branches_[name] = tree_->Branch(name.c_str(), collection, 1000000, 3);
52
53 // Keep track of which collections were added to the event
54 objects_[name] = collection;
55}
56
57TClonesArray* Event::getCollection(const std::string name) {
58
59 // Check if the collection already exist
60 auto itc = objects_.find(name);
61 auto itb = branches_.find(name);
62
63 if (itc != objects_.end()) {
64 if (itb != branches_.end()) {
65 itb->second->GetEntry(entry_);
66 }
67 return static_cast<TClonesArray*>(itc->second);
68 } else {
69 throw std::runtime_error("Collection not found.");
70 }
71}
72
73bool Event::exists(const std::string name) {
74
75 // Search the list of collections to find if it exist.
76 auto it = objects_.find(name);
77
78 if (it == objects_.end()) return false;
79 else return true;
80}
81
82void Event::Clear() {
83
84 for (auto& collection : objects_) {
85 collection.second->Clear("C");
86 }
87}
88
89bool Event::hasLCCollection(const std::string name) {
90
91 // Attempt to get the collection of the given name from the event. If it
92 // doesn't exist, an exemption will be thrown. In this case, the exception
93 // will be handled and the method will return false. Otherwise, the
94 // method returns true.
95 try {
96 getLCCollection(name);
97 } catch (EVENT::DataNotAvailableException e) {
98 return false;
99 }
100 return true;
101}
Class defining methods used to access event information and data collections.
int entry_
Definition Event.h:138
EventHeader * event_header_
Definition Event.h:123
TClonesArray * getCollection(const std::string name)
Definition Event.cxx:57
bool exists(const std::string name)
Definition Event.cxx:73
std::map< std::string, TBranch * > branches_
Definition Event.h:135
TTree * tree_
Definition Event.h:126
Event()
Constructor.
Definition Event.cxx:15
~Event()
Destructor.
Definition Event.cxx:24
EVENT::LCCollection * getLCCollection(std::string name)
Definition Event.h:102
std::map< std::string, TObject * > objects_
Definition Event.h:132
void Clear()
Definition Event.cxx:82
virtual void add(const std::string name, TObject *object)
Definition Event.cxx:26
bool hasLCCollection(const std::string name)
Definition Event.cxx:89
void addCollection(const std::string name, TClonesArray *collection)
Definition Event.cxx:45