Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoGlobalMagField.cxx
Go to the documentation of this file.
1// @(#)root/geom:$Id$
2
3/*************************************************************************
4 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include "TGeoGlobalMagField.h"
12
13#include "TROOT.h"
14#include "TList.h"
15
16/** \class TGeoGlobalMagField
17\ingroup Geometry_classes
18
19Global magnetic field manager. Provides access to
20and owns the actual magnetic field set via `SetField()`. The field is deleted
21upon destruction of the field manager at the end of ROOT session or
22by calling:
23
24~~~ {.cpp}
25TGeoGlobalMagField::Instance()->SetField(0).
26~~~
27
28The previous global field is deleted upon replacement with notification.
29
30The global field manager provides access to the global field via:
31
32~~~ {.cpp}
33 TGeoGlobalMagField::Instance()->GetField()
34~~~
35
36One can directly call the Field() method of a field via the global field manager:
37
38~~~ {.cpp}
39 TGeoGlobalMagField::Instance()->Field(x,B)
40~~~
41*/
42
43
45
46////////////////////////////////////////////////////////////////////////////////
47/// Global field default constructor.
48
50{
51 fField = nullptr;
52 fLock = kFALSE;
53 if (fgInstance) {
54 TVirtualMagField *field = fgInstance->GetField();
55 if (field)
56 Fatal("TGeoGlobalMagField", "A global field manager already existing and containing a field. \
57 \n If you want a new global field please set it via: \
58 \n TGeoGlobalMagField::Instance()->SetField(myField).");
59 else
60 Warning("TGeoGlobalMagField", "A global field manager already existing. Please access via: \
61 \n TGeoGlobalMagField::Instance().");
62 delete fgInstance;
63 }
64 gROOT->GetListOfGeometries()->Add(this); // list of cleanups not deleted
65 fgInstance = this;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Global field destructor.
70
72{
73 gROOT->GetListOfGeometries()->Remove(this);
74 if (fField) {
76 fField = nullptr;
77 delete field;
78 }
79 fgInstance = nullptr;
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Field setter. Deletes previous field if any. Acts only if fLock=kFALSE.
84
86{
87 if (field == fField)
88 return;
89 // Check if we are allowed to change the old field.
90 if (fField) {
91 if (fLock) {
92 Error("SetField", "Global field is already set to <%s> and locked", fField->GetName());
93 return;
94 }
95 // We delete the old global field and notify user.
96 Info("SetField", "Previous magnetic field <%s> will be deleted", fField->GetName());
98 fField = nullptr;
99 delete oldfield;
100 }
101 fField = field;
102 if (fField)
103 Info("SetField", "Global magnetic field set to <%s>", fField->GetName());
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Static getter that does not create the object.
108
113
114////////////////////////////////////////////////////////////////////////////////
115/// Returns always a valid static pointer to the field manager.
116
123
124////////////////////////////////////////////////////////////////////////////////
125/// Locks the global magnetic field if this is set. Cannot be unlocked.
126
128{
129 if (!fField) {
130 Warning("Lock", "Cannot lock global magnetic field since this was not set yet");
131 return;
132 }
133 fLock = kTRUE;
134 Info("Lock", "Global magnetic field <%s> is now locked", fField->GetName());
135}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gROOT
Definition TROOT.h:411
Global magnetic field manager.
TVirtualMagField * fField
void SetField(TVirtualMagField *field)
Field setter. Deletes previous field if any. Acts only if fLock=kFALSE.
TGeoGlobalMagField()
Global field default constructor.
void Lock()
Locks the global magnetic field if this is set. Cannot be unlocked.
~TGeoGlobalMagField() override
Global field destructor.
static TGeoGlobalMagField * fgInstance
static TGeoGlobalMagField * Instance()
Returns always a valid static pointer to the field manager.
static TGeoGlobalMagField * GetInstance()
Static getter that does not create the object.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1099
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1045
Abstract class for magnetic field.