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
4
TDetector::TDetector
(
const
TDetector
& rhs) : TObject(rhs)
5
{
6
/// Default Copy constructor.
7
rhs.
Copy
(*
this
);
8
}
9
10
TDetector::TDetector
(
TDetector
&& rhs) noexcept : TObject(rhs)
11
{
12
/// Default Move constructor.
13
rhs.Copy(*
this
);
14
}
15
16
TDetector::~TDetector
()
17
{
18
/// Default Destructor.
19
for
(
auto
* hit :
fHits
) {
20
delete
hit;
21
}
22
}
23
24
void
TDetector::Copy
(TObject& rhs)
const
25
{
26
TObject::Copy(rhs);
27
// to copy the hits without creating a memory leak we need to check
28
// if the right-hand side has more hits than this
29
// if so, we need to delete the hits pointed to by the right-hand side
30
auto
& rhsHits =
static_cast<
TDetector
&
>
(rhs).
fHits
;
31
if
(rhsHits.size() >
fHits
.size()) {
32
for
(
size_t
i =
fHits
.size(); i < rhsHits.size(); ++i) {
33
delete
rhsHits[i];
34
}
35
rhsHits.resize(
fHits
.size());
36
}
else
if
(rhsHits.size() <
fHits
.size()) {
37
size_t
oldSize = rhsHits.size();
38
rhsHits.resize(
fHits
.size(),
nullptr
);
39
for
(
size_t
i = oldSize; i < rhsHits.size(); ++i) {
40
// we need to use IsA()->New() to make a new hit of whatever derived type this actually is
41
rhsHits[i] =
static_cast<
TDetectorHit
*
>
(
fHits
[i]->IsA()->New());
42
}
43
}
44
// we have now ensured that the size of the two vectors is the same, so we can copy the contents of the hits
45
for
(
size_t
i = 0; i <
fHits
.size(); ++i) {
46
fHits
[i]->Copy(*(rhsHits[i]),
true
);
47
}
48
}
49
50
void
TDetector::Print
(Option_t*)
const
51
{
52
/// Default print statement for TDetector.
53
Print
(std::cout);
54
}
55
56
void
TDetector::Print
(std::ostream& out)
const
57
{
58
/// Print detector to stream out. Iterates over hits and prints them.
59
std::ostringstream str;
60
str <<
"TDetector "
<<
this
<<
":"
<< std::endl;
61
for
(
auto
* hit :
fHits
) {
62
hit->Print(str);
63
}
64
out << str.str();
65
}
66
67
void
TDetector::Clear
(Option_t* opt)
68
{
69
if
(strcmp(opt,
"a"
) == 0) {
70
for
(
auto
* hit :
fHits
) {
71
delete
hit;
72
}
73
}
74
fHits
.clear();
75
}
76
77
void
TDetector::ClearTransients
()
78
{
79
for
(
auto
* hit :
fHits
) {
80
hit->ClearTransients();
81
}
82
}
83
84
TDetectorHit
*
TDetector::GetHit
(
const
int
& index)
const
85
{
86
try
{
87
return
fHits
.at(index);
88
}
catch
(
const
std::out_of_range& oor) {
89
std::cerr << ClassName() <<
" is out of range: "
<< oor.what() << std::endl;
90
throw
grsi::exit_exception
(1);
91
}
92
return
nullptr
;
93
}
TDetector.h
TDetectorHit
Definition
TDetectorHit.h:45
TDetector
Definition
TDetector.h:31
TDetector::fHits
std::vector< TDetectorHit * > fHits
Definition
TDetector.h:84
TDetector::Print
void Print(Option_t *opt="") const override
!
Definition
TDetector.cxx:50
TDetector::ClearTransients
virtual void ClearTransients()
!
Definition
TDetector.cxx:77
TDetector::Copy
void Copy(TObject &) const override
!
Definition
TDetector.cxx:24
TDetector::~TDetector
~TDetector()
Definition
TDetector.cxx:16
TDetector::GetHit
virtual TDetectorHit * GetHit(const int &index) const
Definition
TDetector.cxx:84
TDetector::Clear
void Clear(Option_t *="") override
!
Definition
TDetector.cxx:67
TDetector::TDetector
TDetector()=default
grsi::exit_exception
Definition
Globals.h:74
libraries
TFormat
TDetector.cxx
GRSISort ("v4.0.0.5") Reference Guide Generated on Mon Oct 27 2025 15:12:33.