Belle II Software  release-08-01-10
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 
12 using namespace std;
13 using namespace Belle2;
14 
15 BFieldMap& BFieldMap::Instance()
16 {
17  static std::unique_ptr<BFieldMap> instance(new BFieldMap());
18  return *instance;
19 }
20 
21 void BFieldMap::initialize()
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 
33 void BFieldMap::clear()
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 
44 BFieldMap::BFieldMap() : m_isMapInitialized(false)
45 {
46 
47 }
48 
50 {
51  if (m_isMapInitialized) {
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
std::list< BFieldComponentAbs * > m_components
The components of the magnetic field.
Definition: BFieldMap.h:69
virtual ~BFieldMap()
The destructor of the BFieldMap class.
Definition: BFieldMap.cc:49
bool m_isMapInitialized
If false the map hasn't been initialized yet.
Definition: BFieldMap.h:74
Abstract base class for different kinds of events.