FairShip
Loading...
Searching...
No Matches
ShipFieldCreator.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5#include "ShipFieldCreator.h"
6
7#include <iostream>
8
9#include "FairField.h"
10#include "FairRunAna.h"
11#include "FairRuntimeDb.h"
12#include "ShipConstField.h"
13#include "ShipFieldPar.h"
14using std::cerr;
15using std::cout;
16using std::endl;
17
18static ShipFieldCreator gShipFieldCreator;
19
20// Marked noexcept so the static `gShipFieldCreator` registration cannot trip
21// bugprone-throwing-static-initialization. FairFieldFactory's own ctor sets a
22// static pointer and never throws in practice; if that ever changes, the
23// resulting std::terminate is preferable to silently calling a destructor we
24// can't reach.
26 : FairFieldFactory(), fFieldPar(nullptr) {}
27
29
31 FairRunAna* Run = FairRunAna::Instance();
32 FairRuntimeDb* RunDB = Run->GetRuntimeDb();
33 fFieldPar = dynamic_cast<ShipFieldPar*>(RunDB->getContainer("ShipFieldPar"));
34}
35
37 FairField* fMagneticField = nullptr;
38
39 if (!fFieldPar) {
40 cerr << "-E- No field parameters available!" << endl;
41 } else {
42 // Instantiate correct field type
43 Int_t fType = fFieldPar->GetType();
44 if (fType == 0)
45 fMagneticField = new ShipConstField(fFieldPar);
46 else
47 cerr << "-W- FairRunAna::GetField: Unknown field type " << fType << endl;
48 cout << "New field at " << fMagneticField << ", type " << fType << endl;
49 // Initialise field
50 if (fMagneticField) {
51 fMagneticField->Init();
52 fMagneticField->Print("");
53 }
54 }
55 return fMagneticField;
56}
~ShipFieldCreator() override
ShipFieldPar * fFieldPar
FairField * createFairField() override
ShipFieldCreator() noexcept
void SetParm() override