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]));
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
55{
56 for(auto* hit : fHits) {
57 hit->ClearTransients();
58 }
59}
60
61TDetectorHit* TDetector::GetHit(const int& index) const
62{
63 try {
64 return fHits.at(index);
65 } catch(const std::out_of_range& oor) {
66 std::cerr << ClassName() << " is out of range: " << oor.what() << std::endl;
67 throw grsi::exit_exception(1);
68 }
69 return nullptr;
70}
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:54
void Copy(TObject &) const override
!
Definition TDetector.cxx:24
virtual TDetectorHit * GetHit(const int &index) const
Definition TDetector.cxx:61
TDetector()=default