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