Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaSubDetector.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen 15-June-01
2
4//
5// THaSubDetector
6//
8
9#include "THaSubDetector.h"
10#include "THaDetector.h"
11#include "TString.h"
12#include "TError.h"
13
15
16//_____________________________________________________________________________
17THaSubDetector::THaSubDetector( const char* name, const char* description,
18 THaDetectorBase* parent )
19 : THaDetectorBase(name,description), fParent(parent)
20{
21 // Normal constructor with name and description
22
23 static const char* const here = "THaSubDetector";
24
25 if( !name || !*name ) {
26 Error( Here(here), "Must construct subdetector with valid name! "
27 "Object construction failed." );
28 MakeZombie();
29 return;
30 }
31}
32
33//_____________________________________________________________________________
35{
36 // Return parent apparatus (parent of parent detector)
37
39 return det ? det->GetApparatus() : nullptr;
40}
41
42//_____________________________________________________________________________
44{
45 // Get database file name root. By default, subdetectors use the same
46 // database file as their parent (sub)detector.
47
49 return det ? det->GetDBFileName() : GetPrefix();
50}
51
52//_____________________________________________________________________________
54{
55 // Search up the chain of parent detectors until a THaDetector
56 // (not a THaSubDetector) is found. This is the "main detector"
57 // containing this subdetector
58
59 THaDetectorBase* parent = GetParent();
60 while( parent && dynamic_cast<THaSubDetector*>(parent) )
61 parent = static_cast<THaSubDetector*>(parent)->GetParent();
62 return dynamic_cast<THaDetector*>(parent);
63}
64
65//_____________________________________________________________________________
67{
68 // Set up name prefix for global variables.
69 //
70 // Subdetector prefixes are of form "<parent_prefix><subdetector_name>.",
71 // where <parent_prefix> is the prefix of the immediate parent, which may
72 // be another subdetector. If a different behavior is needed, subdetectors
73 // need to override MakePrefix().
74
75 TString basename;
77 if( det ) {
78 basename = det->GetPrefix();
79 basename.Chop();
80 } else
81 Warning( Here("MakePrefix()"), "No detector defined for this subdetector! "
82 "Fix your code!" );
83
85}
86
87//_____________________________________________________________________________
89{
90 // Associate this subdetector with the given detector or subdetector.
91 // Only possible before initialization.
92
93 static const char* const here = "SetParent()";
94
95 if( IsInit() ) {
96 Error( Here(here), "Cannot set detector. Object already initialized.");
97 return;
98 }
99 if( !detector ) {
100 Error( Here(here), "Cannot set detector to nullptr. Detector not changed.");
101 return;
102 }
103 if( detector == this ) {
104 Error( Here(here), "Cannot set detector to self. Detector not changed.");
105 return;
106 }
107 fParent = detector;
108}
109
char name[80]
static const char *const here
Definition THaVar.cxx:64
virtual const char * Here(const char *) const
const char * GetPrefix() const
virtual void MakePrefix()
virtual const char * GetDBFileName() const
Bool_t IsInit() const
THaApparatus * GetApparatus() const
THaDetectorBase * GetParent() const
virtual void SetParent(THaDetectorBase *)
virtual void MakePrefix()
virtual const char * GetDBFileName() const
THaApparatus * GetApparatus() const
THaDetector * GetMainDetector() const
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Error(const char *method, const char *msgfmt,...) const
const char * Data() const
TString & Chop()
void Error(const char *location, const char *fmt,...)
ClassImp(TPyArg)