GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TDetector.cxx
Go to the documentation of this file.
1#include "TDetector.h"
2#include "TClass.h"
3
4TDetector::TDetector(const TDetector& rhs) : TObject(rhs)
5{
6 /// Default Copy constructor.
7 rhs.Copy(*this);
8}
9
10TDetector::TDetector(TDetector&& rhs) noexcept : TObject(rhs)
11{
12 /// Default Move constructor.
13 rhs.Copy(*this);
14}
15
17{
18 /// Default Destructor.
19 for(auto* hit : fHits) {
20 delete hit;
21 }
22}
23
24void TDetector::Copy(TObject& rhs) const
25{
26 // if(!rhs.InheritsFrom("TDetector"))
27 // return;
28 TObject::Copy(rhs);
29 static_cast<TDetector&>(rhs).fHits.resize(fHits.size());
30 for(size_t i = 0; i < fHits.size(); ++i) {
31 // we need to use IsA()->New() to make a new hit of whatever derived type this actually is
32 static_cast<TDetector&>(rhs).fHits[i] = static_cast<TDetectorHit*>(fHits[i]->IsA()->New());
33 fHits[i]->Copy(*(static_cast<TDetector&>(rhs).fHits[i]), true);
34 }
35}
36
37void TDetector::Print(Option_t*) const
38{
39 /// Default print statement for TDetector.
40 Print(std::cout);
41}
42
43void TDetector::Print(std::ostream& out) const
44{
45 /// Print detector to stream out. Iterates over hits and prints them.
46 std::ostringstream str;
47 str << "TDetector " << this << ":" << std::endl;
48 for(auto* hit : fHits) {
49 hit->Print(str);
50 }
51 out << str.str();
52}
53
54void TDetector::Clear(Option_t* opt)
55{
56 if(strcmp(opt, "a") == 0) {
57 for(auto* hit : fHits) {
58 delete hit;
59 }
60 }
61 fHits.clear();
62}
63
65{
66 for(auto* hit : fHits) {
67 hit->ClearTransients();
68 }
69}
70
71TDetectorHit* TDetector::GetHit(const int& index) const
72{
73 try {
74 return fHits.at(index);
75 } catch(const std::out_of_range& oor) {
76 std::cerr << ClassName() << " is out of range: " << oor.what() << std::endl;
77 throw grsi::exit_exception(1);
78 }
79 return nullptr;
80}
std::vector< TDetectorHit * > fHits
Definition TDetector.h:88
void Print(Option_t *opt="") const override
!
Definition TDetector.cxx:37
virtual void ClearTransients()
!
Definition TDetector.cxx:64
void Copy(TObject &) const override
!
Definition TDetector.cxx:24
virtual TDetectorHit * GetHit(const int &index) const
Definition TDetector.cxx:71
void Clear(Option_t *="") override
!
Definition TDetector.cxx:54
TDetector()=default