Belle II Software  release-05-02-19
BFieldMap.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Andreas Moll *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <geometry/bfieldmap/BFieldMap.h>
12 #include <framework/logging/Logger.h>
13 
14 using namespace std;
15 using namespace Belle2;
16 
17 BFieldMap& BFieldMap::Instance()
18 {
19  static std::unique_ptr<BFieldMap> instance(new BFieldMap());
20  return *instance;
21 }
22 
23 void BFieldMap::initialize()
24 {
25  if (!m_isMapInitialized) {
26  for (BFieldComponentAbs* comp : m_components) {
27  comp->initialize();
28  }
29 
30  m_isMapInitialized = true;
31  B2DEBUG(10, "The magnetic field map has been initialized.");
32  }
33 }
34 
35 void BFieldMap::clear()
36 {
37  m_isMapInitialized = false;
38  for (auto ptr : m_components) delete ptr;
39  m_components.clear();
40 }
41 
42 //====================================================================
43 // Private methods
44 //====================================================================
45 
46 BFieldMap::BFieldMap() : m_isMapInitialized(false)
47 {
48 
49 }
50 
52 {
53  if (m_isMapInitialized) {
54  //Delete the magnetic field components by calling their terminate() method and freeing their memory.
55  for (BFieldComponentAbs* comp : m_components) {
56  comp->terminate();
57  delete comp;
58  }
59  }
60 }
Belle2::BFieldMap::m_isMapInitialized
bool m_isMapInitialized
If false the map hasn't been initialized yet.
Definition: BFieldMap.h:85
Belle2::BFieldMap
This class represents the magnetic field of the Belle II detector.
Definition: BFieldMap.h:41
Belle2::BFieldMap::initialize
void initialize()
Initialize the magnetic field after adding all components.
Definition: BFieldMap.cc:23
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::BFieldMap::~BFieldMap
virtual ~BFieldMap()
The destructor of the BFieldMap class.
Definition: BFieldMap.cc:51
Belle2::BFieldComponentAbs
The BFieldComponentAbs class.
Definition: BFieldComponentAbs.h:41
Belle2::BFieldMap::m_components
std::list< BFieldComponentAbs * > m_components
The components of the magnetic field.
Definition: BFieldMap.h:80