Logo ROOT   6.16/01
Reference Guide
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 "TROOT.h"
12#include "TGeoGlobalMagField.h"
13
14/** \class TGeoGlobalMagField
15\ingroup Geometry_classes
16
17Global magnetic field manager. Provides access to
18and owns the actual magnetic field set via `SetField()`. The field is deleted
19upon destruction of the field manager at the end of ROOT session or
20by calling:
21
22~~~ {.cpp}
23TGeoGlobalMagField::Instance()->SetField(0).
24~~~
25
26The previous global field is deleted upon replacement with notification.
27
28The global field manager provides access to the global field via:
29
30~~~ {.cpp}
31 TGeoGlobalMagField::Instance()->GetField()
32~~~
33
34One can directly call the Field() method of a field via the global field manager:
35
36~~~ {.cpp}
37 TGeoGlobalMagField::Instance()->Field(x,B)
38~~~
39*/
40
42
44
45////////////////////////////////////////////////////////////////////////////////
46/// Global field default constructor.
47
49{
50 fField = NULL;
51 fLock = kFALSE;
52 if (fgInstance) {
54 if (field)
55 Fatal("TGeoGlobalMagField", "A global field manager already existing and containing a field. \
56 \n If you want a new global field please set it via: \
57 \n TGeoGlobalMagField::Instance()->SetField(myField).");
58 else
59 Warning("TGeoGlobalMagField", "A global field manager already existing. Please access via: \
60 \n TGeoGlobalMagField::Instance().");
61 delete fgInstance;
62 }
63 gROOT->GetListOfGeometries()->Add(this); // list of cleanups not deleted
64 fgInstance = this;
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Global field destructor.
69
71{
72 gROOT->GetListOfGeometries()->Remove(this);
73 if (fField) {
74 TVirtualMagField *field = fField;
75 fField = NULL;
76 delete field;
77 }
78 fgInstance = NULL;
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Field setter. Deletes previous field if any. Acts only if fLock=kFALSE.
83
85{
86 if (field==fField) return;
87 // Check if we are allowed to change the old field.
88 if (fField) {
89 if (fLock) {
90 Error("SetField", "Global field is already set to <%s> and locked", fField->GetName());
91 return;
92 }
93 // We delete the old global field and notify user.
94 Info("SetField", "Previous magnetic field <%s> will be deleted", fField->GetName());
95 TVirtualMagField *oldfield = fField;
96 fField = NULL;
97 delete oldfield;
98 }
99 fField = field;
100 if (fField) Info("SetField", "Global magnetic field set to <%s>", fField->GetName());
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Static getter that does not create the object.
105
107{
108 return fgInstance;
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Returns always a valid static pointer to the field manager.
113
115{
116 if (fgInstance) return fgInstance;
117 return new TGeoGlobalMagField();
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Locks the global magnetic field if this is set. Cannot be unlocked.
122
124{
125 if (!fField) {
126 Warning("Lock", "Cannot lock global magnetic field since this was not set yet");
127 return;
128 }
129 fLock = kTRUE;
130 Info("Lock", "Global magnetic field <%s> is now locked", fField->GetName());
131}
const Bool_t kFALSE
Definition: RtypesCore.h:88
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
#define gROOT
Definition: TROOT.h:410
Global magnetic field manager.
virtual ~TGeoGlobalMagField()
Global field destructor.
TVirtualMagField * fField
void SetField(TVirtualMagField *field)
Field setter. Deletes previous field if any. Acts only if fLock=kFALSE.
TVirtualMagField * GetField() const
TGeoGlobalMagField()
Global field default constructor.
void Lock()
Locks the global magnetic field if this is set. Cannot be unlocked.
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.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:908
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
Abstract class for magnetic field.