CbmRoot
CbmStsParSetSensorCond.cxx
Go to the documentation of this file.
1 
6 
7 #include "CbmStsParSensorCond.h" // for CbmStsParSensorCond
8 
9 #include <FairLogger.h> // for Logger, LOG
10 
11 #include <TString.h> // for TString, operator<<, operator+, ope...
12 #include <TSystem.h> // for TSystem, gSystem
13 
14 #include <assert.h> // for assert
15 #include <sstream> // for operator<<, fstream, stringstream
16 #include <string> // for char_traits
17 #include <utility> // for pair
18 
19 using std::string;
20 
22 
23  // ----- Constructor ----------------------------------------------------
25  const char* title,
26  const char* context)
27  : FairParGenericSet(name, title, context) {}
28 // --------------------------------------------------------------------------
29 
30 
31 // ----- Destructor -----------------------------------------------------
33 // --------------------------------------------------------------------------
34 
35 
36 // ----- Reset ----------------------------------------------------------
38  fParams.clear();
39  fIsInit = kFALSE;
40  fGlobal = kFALSE;
41  status = kFALSE;
42  resetInputVersions();
43 }
44 // --------------------------------------------------------------------------
45 
46 
47 // ----- Read parameters from ASCII file --------------------------------
48 Bool_t CbmStsParSetSensorCond::getParams(FairParamList*) {
49  LOG(fatal) << GetName() << ": ASCII input is not defined!";
50  return kFALSE;
51 }
52 // --------------------------------------------------------------------------
53 
54 
55 // ----- Get condition parameters of a sensor ---------------------------
58 
59  if (!fIsInit) Init();
60 
61  // --- Return global conditions, if set
62  if (fGlobal) return fGlobalParams;
63 
64  // --- Else, look in the address map
65  else {
66  assert(fParams.count(address));
67  return fParams.at(address);
68  }
69 }
70 // --------------------------------------------------------------------------
71 
72 
73 // ----- Initialise the conditions --------------------------------------
75 
76  // --- Global conditions
78 
79  // --- Conditions sensor by sensor
80  for (auto& it : fParams)
81  it.second.Init();
82 
83  fIsInit = kTRUE;
84 }
85 // --------------------------------------------------------------------------
86 
87 
88 // ----- Write parameters from ASCII file -------------------------------
89 void CbmStsParSetSensorCond::putParams(FairParamList*) {
90  LOG(fatal) << GetName() << ": ASCII output is not defined!";
91 }
92 // --------------------------------------------------------------------------
93 
94 
95 // ----- Set sensor conditions from file --------------------------------
96 UInt_t CbmStsParSetSensorCond::ReadParams(const char* fileName) {
97 
98  // --- Warn against multiple initialisation
99  if (fGlobal) {
100  LOG(warn) << GetName()
101  << ": Previously defined global settings will be ignored.";
102  }
103  if (!fParams.empty()) {
104  LOG(warn) << GetName()
105  << ": Overwriting previously defined parameter sets.";
106  fParams.clear();
107  }
108 
109  // --- Input file
110  std::fstream inFile;
111  TString inputFile = fileName;
112 
113  // Try with argument as is (absolute path or current directory)
114  inFile.open(inputFile.Data());
115 
116  // If not successful, look in the standard parameter directory
117  if (!inFile.is_open()) {
118  inputFile = gSystem->Getenv("VMCWORKDIR");
119  inputFile += "/parameters/sts/" + TString(fileName);
120  inFile.open(inputFile.Data());
121  }
122 
123  // If still not open, throw an error
124  if (!inFile.is_open()) {
125  LOG(fatal) << GetName() << ": Cannot read file " << fileName << " nor "
126  << inputFile;
127  return 0;
128  }
129 
130  string input;
131  TString sName;
132  UInt_t nSensors = 0;
133  UInt_t address = 0;
134  Double_t vDep = -1.e10;
135  Double_t vBias = -1.e10;
136  Double_t temperature = -1.e10;
137  Double_t cCoupling = -1.e10;
138  Double_t cInterstrip = -1.e10;
139 
140  while (kTRUE) { // read one line per sensor
141  if (inFile.eof()) break;
142  getline(inFile, input);
143  if (input.empty() || input[0] == '#') continue; // Comment line
144  std::stringstream line(input);
145  line >> sName >> address >> vDep >> vBias >> temperature >> cCoupling
146  >> cInterstrip;
147 
148  // Check presence and validity of condition parameters
149  if (vDep < 1.e-9 || vBias < 1.e-9 || temperature < 1.e-9
150  || cCoupling < 1.e-9 || cInterstrip < 1.e-9) {
151  LOG(fatal) << GetName()
152  << ": Missing or illegal condition parameters for address "
153  << address << "; " << vDep << " " << vBias << " "
154  << temperature << " " << cCoupling << " " << cInterstrip;
155  continue;
156  }
157 
158  // Check for double occurrences of addresses
159  if (fParams.count(address)) {
160  LOG(fatal) << GetName() << ": Multiple occurence of address " << address
161  << " in input file";
162  continue;
163  }
164 
165  // Add sensor conditions to set
166  fParams[address].SetParams(
167  vDep, vBias, temperature, cCoupling, cInterstrip);
168  nSensors++;
169  } //# input lines
170 
171  inFile.close();
172  LOG(info) << GetName() << ": Read conditions of " << nSensors
173  << (nSensors == 1 ? " sensor" : " sensors") << " from "
174  << inputFile;
175 
176  return nSensors;
177 }
178 // --------------------------------------------------------------------------
179 
180 
181 // ----- Set the global sensor conditions -------------------------------
183  Double_t vBias,
184  Double_t temperature,
185  Double_t cCoupling,
186  Double_t cInterstrip) {
187  if (fGlobal)
188  LOG(warn) << GetName() << ": Overwriting current global settings!";
189  fGlobalParams.SetParams(vFd, vBias, temperature, cCoupling, cInterstrip);
190  fGlobal = kTRUE;
191 }
192 // -------------------------------------------------------------------------
193 
194 
195 // ----- Set the global sensor conditions ------------------------------
197  const CbmStsParSensorCond& conditions) {
198  Double_t vFd = conditions.GetVfd();
199  Double_t vBias = conditions.GetVbias();
200  Double_t temperature = conditions.GetTemperature();
201  Double_t cCoupling = conditions.GetCcoupling();
202  Double_t cInterstrip = conditions.GetCinterstrip();
203  SetGlobalPar(vFd, vBias, temperature, cCoupling, cInterstrip);
204 }
205 // -------------------------------------------------------------------------
206 
207 
208 // ----- Info to string ------------------------------------------------
210  if (!fIsInit) Init();
211  std::stringstream ss;
212  if (!IsSet())
213  ss << "Empty";
214  else if (fGlobal)
215  ss << "(Global) " << fGlobalParams.ToString();
216  else
217  ss << "Conditions for " << fParams.size() << " sensors";
218  return ss.str();
219 }
220 // -------------------------------------------------------------------------
CbmStsParSensorCond::SetParams
void SetParams(Double_t vFd, Double_t vBias, Double_t temperature, Double_t cCoupling, Double_t cInterstrip)
Set the condition parameters.
Definition: CbmStsParSensorCond.cxx:135
CbmStsParSensorCond::GetCinterstrip
Double_t GetCinterstrip() const
Inter-strip capacitance.
Definition: CbmStsParSensorCond.h:70
CbmStsParSensorCond
Parameters for operating conditions of a STS sensor.
Definition: CbmStsParSensorCond.h:28
CbmStsParSetSensorCond::~CbmStsParSetSensorCond
virtual ~CbmStsParSetSensorCond()
Destructor.
Definition: CbmStsParSetSensorCond.cxx:32
CbmStsParSetSensorCond::SetGlobalPar
void SetGlobalPar(Double_t vDep, Double_t vBias, Double_t temperature, Double_t cCoupling, Double_t cInterstrip)
Set global conditions (for all sensors)
Definition: CbmStsParSetSensorCond.cxx:182
CbmStsParSetSensorCond::clear
virtual void clear()
Reset all parameters.
Definition: CbmStsParSetSensorCond.cxx:37
CbmStsParSensorCond.h
CbmStsParSetSensorCond::IsSet
Bool_t IsSet() const
Check for parameter set being filled.
Definition: CbmStsParSetSensorCond.h:76
CbmStsParSetSensorCond.h
CbmStsParSetSensorCond
Parameters container for CbmStsParSensorCond.
Definition: CbmStsParSetSensorCond.h:30
CbmStsParSetSensorCond::fGlobalParams
CbmStsParSensorCond fGlobalParams
Global parameters, used for all sensors.
Definition: CbmStsParSetSensorCond.h:148
CbmStsParSetSensorCond::CbmStsParSetSensorCond
CbmStsParSetSensorCond(const char *name="CbmStsParSetSensorCond", const char *title="STS parameters", const char *context="Default")
Constructor.
CbmStsParSetSensorCond::ToString
std::string ToString()
Info to string.
Definition: CbmStsParSetSensorCond.cxx:209
CbmStsParSetSensorCond::fGlobal
Bool_t fGlobal
Use global parameters for all sensors.
Definition: CbmStsParSetSensorCond.h:153
ClassImp
ClassImp(CbmStsParSetSensorCond) CbmStsParSetSensorCond
Definition: CbmStsParSetSensorCond.cxx:21
CbmStsParSensorCond::ToString
std::string ToString() const
String output.
Definition: CbmStsParSensorCond.cxx:151
CbmStsParSetSensorCond::fIsInit
Bool_t fIsInit
Definition: CbmStsParSetSensorCond.h:154
CbmStsParSetSensorCond::ReadParams
UInt_t ReadParams(const char *fileName)
Read sensor conditions from file.
Definition: CbmStsParSetSensorCond.cxx:96
CbmStsParSensorCond::GetCcoupling
Double_t GetCcoupling() const
Coupling capacitance.
Definition: CbmStsParSensorCond.h:64
CbmStsParSetSensorCond::putParams
virtual void putParams(FairParamList *parList)
Writing parameters to ASCII. Abstract in base class.
Definition: CbmStsParSetSensorCond.cxx:89
CbmStsParSensorCond::GetTemperature
Double_t GetTemperature() const
Temperature.
Definition: CbmStsParSensorCond.h:95
CbmStsParSensorCond::Init
void Init()
Calculate the derived parameters.
Definition: CbmStsParSensorCond.cxx:57
CbmStsParSetSensorCond::fParams
std::map< UInt_t, CbmStsParSensorCond > fParams
Map of parameters. Key is sensor address.
Definition: CbmStsParSetSensorCond.h:151
CbmStsParSetSensorCond::getParams
virtual Bool_t getParams(FairParamList *parList)
Reading parameters from ASCII. Abstract in base class.
Definition: CbmStsParSetSensorCond.cxx:48
CbmStsParSensorCond::GetVbias
Double_t GetVbias() const
Bias voltage.
Definition: CbmStsParSensorCond.h:101
CbmStsParSensorCond::GetVfd
Double_t GetVfd() const
Definition: CbmStsParSensorCond.h:107
CbmStsParSetSensorCond::GetParSensor
const CbmStsParSensorCond & GetParSensor(UInt_t address)
Get condition parameters of a sensor.
Definition: CbmStsParSetSensorCond.cxx:57
CbmStsParSetSensorCond::Init
void Init()
Initialise all condition parameters.
Definition: CbmStsParSetSensorCond.cxx:74