StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSimpleMagneticField.cc
1 /***************************************************************************
2  *
3  * $Id: StSimpleMagneticField.cc,v 1.5 2012/06/11 15:04:55 fisyak Exp $
4  *
5  * Author: Thomas Ullrich, May 1998
6  ***************************************************************************
7  *
8  * Description: Class is implemented as a Singleton
9  *
10  ***************************************************************************
11  *
12  * $Log: StSimpleMagneticField.cc,v $
13  * Revision 1.5 2012/06/11 15:04:55 fisyak
14  * std namespace
15  *
16  * Revision 1.4 1999/03/16 01:59:27 lasiuk
17  * Use Units at Initialization
18  *
19  * Revision 1.3 1999/03/15 13:45:44 lasiuk
20  * units consistency added here (tesla)
21  *
22  * Revision 1.2 1999/01/18 21:02:45 lasiuk
23  * comment diagnostics
24  *
25  * Revision 1.1 1998/11/10 17:12:20 fisyak
26  * Put Brian trs versin into StRoot
27  *
28  * Revision 1.2 1998/05/20 19:02:05 ullrich
29  * Renamed getInstance() to instance().
30  *
31  * Revision 1.1 1998/05/20 14:59:28 ullrich
32  * Initial Revision
33  *
34  **************************************************************************/
35 #include "StSimpleMagneticField.hh"
36 #include "StGetConfigValue.hh"
37 using namespace std;
38 StMagneticField* StSimpleMagneticField::mInstance = 0; // static member
39 
40 StSimpleMagneticField::StSimpleMagneticField() {/* noop */}
41 
42 StSimpleMagneticField::StSimpleMagneticField(const StThreeVector<double>& v)
43  : mB(v) {/* noop */}
44 
45 StSimpleMagneticField::StSimpleMagneticField(const char* filename)
46 {
47  StGetConfigValue(filename, "StSimpleMagneticField.mB", mB);
48  //PR(mB);
49  // Make sure units are correct
50  mB *= tesla;
51  PR(mB/tesla);
52 }
53 
54 StSimpleMagneticField::~StSimpleMagneticField() {/* noop */}
55 
57 StSimpleMagneticField::instance(const StThreeVector<double>& B)
58 {
59  if (mInstance == 0)
60  mInstance = new StSimpleMagneticField(B);
61  else {
62  cerr << "StSimpleMagneticField::getInstance(): " << endl;
63  cerr << "\tWARNING" << endl;
64  cerr << "\tSingleton class is already instantiated." << endl;
65  cerr << "\tArgument (StThreeVector) is ignored." << endl;
66  }
67  return mInstance;
68 }
69 
70 StMagneticField* StSimpleMagneticField::instance(const char* file)
71 {
72  if (mInstance == 0)
73  mInstance = new StSimpleMagneticField(file);
74  else {
75  cerr << "StSimpleMagneticField::getInstance(): " << endl;
76  cerr << "\tWARNING" << endl;
77  cerr << "\tSingleton class is already instantiated." << endl;
78  cerr << "\tArgument (const char*) is ignored." << endl;
79  }
80  return mInstance;
81 }
82 
83 
84