Belle II Software development
BFieldMap.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <geometry/bfieldmap/BFieldMap.h>
10#include <framework/logging/Logger.h>
11
12using namespace std;
13using namespace Belle2;
14
16{
17 static std::unique_ptr<BFieldMap> instance(new BFieldMap());
18 return *instance;
19}
20
22{
23 if (!m_isMapInitialized) {
24 for (BFieldComponentAbs* comp : m_components) {
25 comp->initialize();
26 }
27
28 m_isMapInitialized = true;
29 B2DEBUG(10, "The magnetic field map has been initialized.");
30 }
31}
32
34{
35 m_isMapInitialized = false;
36 for (auto ptr : m_components) delete ptr;
37 m_components.clear();
38}
39
40//====================================================================
41// Private methods
42//====================================================================
43
44BFieldMap::BFieldMap() : m_isMapInitialized(false)
45{
46
47}
48
50{
52 //Delete the magnetic field components by calling their terminate() method and freeing their memory.
53 for (BFieldComponentAbs* comp : m_components) {
54 comp->terminate();
55 delete comp;
56 }
57 }
58}
The BFieldComponentAbs class.
This class represents the magnetic field of the Belle II detector.
Definition: BFieldMap.h:30
BFieldMap()
The constructor is hidden to avoid that someone creates an instance of this class.
Definition: BFieldMap.cc:44
std::list< BFieldComponentAbs * > m_components
The components of the magnetic field.
Definition: BFieldMap.h:69
void initialize()
Initialize the magnetic field after adding all components.
Definition: BFieldMap.cc:21
virtual ~BFieldMap()
The destructor of the BFieldMap class.
Definition: BFieldMap.cc:49
void clear()
Clear the existing components.
Definition: BFieldMap.cc:33
static BFieldMap & Instance()
Static method to get a reference to the BFieldMap instance.
Definition: BFieldMap.cc:15
bool m_isMapInitialized
If false the map hasn't been initialized yet.
Definition: BFieldMap.h:74
Abstract base class for different kinds of events.
STL namespace.