FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MyFieldCreator.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- MyConstField header file -----
10 // ----- Created 25/03/14 by M. Al-Turany -----
11 // -------------------------------------------------------------------------
12 
13 #include "MyFieldCreator.h"
14 
15 #include "FairField.h"
16 #include "FairRunAna.h"
17 #include "FairRuntimeDb.h"
18 #include "MyConstField.h"
19 #include "MyFieldPar.h"
20 
21 #include <iostream>
22 using std::cerr;
23 using std::cout;
24 using std::endl;
25 
26 static MyFieldCreator gMyFieldCreator;
27 
30  , fFieldPar(NULL)
31 {
32  fCreator = this;
33 }
34 
36 
38 {
40  FairRuntimeDb *RunDB = Run->GetRuntimeDb();
41  fFieldPar = (MyFieldPar *)RunDB->getContainer("MyFieldPar");
42 }
43 
45 {
46  FairField *fMagneticField = 0;
47 
48  if (!fFieldPar) {
49  cerr << "-E- No field parameters available!" << endl;
50  } else {
51  // Instantiate correct field type
52  Int_t fType = fFieldPar->GetType();
53  if (fType == 0)
54  fMagneticField = new MyConstField(fFieldPar);
55  else
56  cerr << "-W- FairRunAna::GetField: Unknown field type " << fType << endl;
57  cout << "New field at " << fMagneticField << ", type " << fType << endl;
58  // Initialise field
59  if (fMagneticField) {
60  fMagneticField->Init();
61  fMagneticField->Print("");
62  }
63  }
64  return fMagneticField;
65 }
66 
FairFieldFactory * fCreator
list of container factories
Definition: FairRuntimeDb.h:24
ClassImp(FairEventBuilder)
FairParSet * getContainer(const Text_t *)
virtual FairField * createFairField()
static FairRunAna * Instance()
Definition: FairRunAna.cxx:61
Int_t GetType() const
Definition: MyFieldPar.h:47
MyFieldPar * fFieldPar
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
virtual void Print(Option_t *) const
Definition: FairField.h:100
virtual ~MyFieldCreator()
virtual void SetParm()
virtual void Init()
Definition: FairField.h:53