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