KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVDBRun.cpp
1/***************************************************************************
2$Id: KVDBRun.cpp,v 1.14 2009/03/12 14:01:02 franklan Exp $
3 KVDBRun.cpp - description
4 -------------------
5 begin : jeu fév 13 2003
6 copyright : (C) 2003 by Alexis Mignon
7 email : mignon@ganil.fr
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18#include "KVDBRun.h"
19#include "Riostream.h"
20#include "TEnv.h"
21#include "TObjString.h"
22#include "TObjArray.h"
23#include "KVDBKey.h"
24
25using namespace std;
26
28
29
32
33KVDBRun::KVDBRun(): fDatime()
34{
35 //default ctor
37}
38
39
40
43
44KVDBRun::KVDBRun(Int_t number, const Char_t* title): fDatime()
45{
46 //ctor for a given run number
47
48 SetNumber(number);
49 SetTitle(title);
51}
52
53
54
55
58
60{
61 //dtor
62}
63
64
65
66
68
70{
71 cout << "___________________________________________________" << endl
72 << GetName() << " (" << GetTitle() << ")" << endl;
73 if (GetSystem()) {
74 cout << "System : " << GetSystem()->GetName() << endl;
75 if (GetSystem()->GetTarget())
76 cout << "Target : " << GetSystem()->GetTarget()->
77 GetName() << endl;
78 }
79 cout << "___________________________________________________" << endl;
80 //print values of all parameters
81 fParameters.Print("string");
82 cout << "___________________________________________________" << endl;
83 fParameters.Print("double");
84 cout << "___________________________________________________" << endl;
85 fParameters.Print("int");
86 cout << "___________________________________________________" << endl;
87}
88
89
90
91
95
96void KVDBRun::WriteRunListLine(ostream& outstr, Char_t) const
97{
98 //Write informations on run in format used for runlists, i.e. a line of fields separated by the
99 //separator character '|' (the 'delim' argument is obsolete and is not used)
100
101 TString _delim = " | ";
102 KVString s;
103 //write run number
104 outstr << GetNumber() << _delim.Data();
105 //write all scalers (integer values)
106 for (int i = 0; i < fParameters.GetNpar(); i++) {
107 if (fParameters.GetParameter(i)->IsInt()) {
108 s.Form("%s=%d", fParameters.GetParameter(i)->GetName(), fParameters.GetParameter(i)->GetInt());
109 outstr << s.Data() << _delim.Data();
110 }
111 }
112 //write all floating point values
113 for (int i = 0; i < fParameters.GetNpar(); i++) {
116 outstr << s.Data() << _delim.Data();
117 }
118 }
119 //write all string values
120 for (int i = 0; i < fParameters.GetNpar(); i++) {
122 // as we write all strings as 'parname=value', there is a problem if the string 'value'
123 // itself contains the '=' symbol !!
124 // therefore we replace any '=' in the string by '\equal' before writing in the file.
125 // when reading back (see ReadRunListLine), we replace '\equal' by '='
127 tmp.ReplaceAll("=", "\\equal");
128 s.Form("%s=%s", fParameters.GetParameter(i)->GetName(), tmp.Data());
129 outstr << s.Data() << _delim.Data();
130 }
131 }
132 outstr << endl;
133}
134
135
136
137
142
144{
145 //Set run characteristics by reading informations in 'line' (assumed to have been written
146 //by WriteRunListLine).
147
148 //Break line into fields using delimiter '|'
149 TObjArray* fields = line.Tokenize('|');
150 if (fields->GetEntries() < 1) {
151 //not a valid line for run
152 delete fields;
153 return;
154 }
155
156 //first field is run number
157 KVString kvs = ((TObjString*)fields->At(0))->String().Remove(TString::kBoth, ' ');
158 if (kvs.IsDigit()) {
159 SetNumber(kvs.Atoi());
160 }
161 else {
162 //not a valid line for run
163 delete fields;
164 return;
165 }
166
167// cout << GetName() << endl;
168
169 //loop over other fields
170 for (int i = 1; i < fields->GetEntries(); i++) {
171
172 //each field is of the form "parameter=value"
173 KVString kvs = ((TObjString*)fields->At(i))->String().Remove(TString::kBoth, ' ');
174 TObjArray* toks = kvs.Tokenize('=');
175 if (toks->GetEntries() == 2) {
176 KVString parameter = ((TObjString*)toks->At(0))->String().Remove(TString::kBoth, ' ');
177 KVString value = ((TObjString*)toks->At(1))->String().Remove(TString::kBoth, ' ');
178 //set parameter based on value
179 if (value.IsDigit()) {
180 //only true for non-floating point i.e. scaler values
181 SetScaler(parameter.Data(), value.Atoi());
182// cout << " -- SCA " << parameter.Data() << " = " << GetScaler(parameter.Data()) << endl;
183 }
184 else if (value.IsFloat()) {
185 Set(parameter.Data(), value.Atof());
186 // cout << " -- FLO " << parameter.Data() << " = " << Get(parameter.Data()) << endl;
187 }
188 else { // string value
189 // as we write all strings as 'parname=value', there is a problem if the string 'value'
190 // itself contains the '=' symbol !!
191 // therefore we replace any '=' in the string by '\equal' before writing in the file
192 // (see WriteRunListLine).
193 // when reading back, we replace '\equal' by '='
194 value.ReplaceAll("\\equal", "=");
195 Set(parameter.Data(), value.Data());
196 // cout << " -- STR " << parameter.Data() << " = " << GetString(parameter.Data()) << endl;
197 }
198 }
199 delete toks;
200 }
201
202 delete fields;
203}
204
205
206
207
210
211void KVDBRun::WriteRunListHeader(ostream& outstr, Char_t) const
212{
213 //Write the version flag
214
215 outstr << "Version=10" << endl;
216}
217
218
219
224
226{
227 //If this run has previously been associated with a system in the database,
228 //this will remove the association. The run will also be removed from the system's
229 //list of associated runs.
230
231 if (GetSystem()) {
232 GetSystem()->RemoveRun(this);
233 }
234 SetTitle("Experimental run");
235 Modified();
236}
237
238
239
241
243{
244 if (GetKey("Systems")) {
245 if (GetKey("Systems")->GetLinks()->GetSize())
246 return (KVDBSystem*) GetKey("Systems")->GetLinks()->First();
247 }
248 return 0;
249}
250
251
252
255
257{
258 //Set system for run. Any previous system is unassociated (run will be removed from system's list)
259 if (!GetKey("Systems")) {
260 KVDBKey* key = AddKey("Systems", "Physical system used");
263 }
264 else {
265 UnsetSystem();
266 }
267 if (!AddLink("Systems", system)) {
268 Warning("SetSystem(KVDBSystem*)",
269 "System %s couldn't be set for Run %d. This bizarre...",
270 system->GetName(), GetNumber());
271 }
272 else {
273 //set title of run = name of system
274 SetTitle(system->GetName());
275 }
276 Modified();
277}
278
279
280
int Int_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Cross-reference in a KVDataBase.
Definition KVDBKey.h:38
virtual void SetUniqueStatus(Bool_t unique)
Definition KVDBKey.h:73
virtual void SetSingleStatus(Bool_t single)
Definition KVDBKey.h:78
virtual KVRList * GetLinks() const
return the list of cross-referenced objects
Definition KVDBKey.h:65
virtual KVDBKey * GetKey(const Char_t *key) const
virtual Bool_t AddKey(KVDBKey *key, Bool_t check=kTRUE)
virtual Bool_t AddLink(const Char_t *key_name, KVDBRecord *rec, Bool_t linkback=kTRUE)
virtual KVRList * GetLinks(const Char_t *key) const
Returns the list of records linked to this record in table "key".
virtual Int_t GetNumber() const
Definition KVDBRecord.h:73
Description of an experimental run in database ,,.
Definition KVDBRun.h:36
virtual void SetSystem(KVDBSystem *system)
Set system for run. Any previous system is unassociated (run will be removed from system's list)
Definition KVDBRun.cpp:256
KVNameValueList fParameters
list of named parameters for run
Definition KVDBRun.h:43
KVTarget * GetTarget() const
Return target used for this run (actually target of KVDBSystem associated to run)
Definition KVDBRun.h:165
KVDBSystem * GetSystem() const
Definition KVDBRun.cpp:242
virtual void WriteRunListLine(std::ostream &, Char_t delim='|') const
Definition KVDBRun.cpp:96
Bool_t fBlockSignals
Definition KVDBRun.h:39
void Set(const Char_t *param, Double_t val)
Set numerical (non-scaler) characteristic of run.
Definition KVDBRun.h:231
virtual void Print(Option_t *option="") const
Definition KVDBRun.cpp:69
Double_t GetSize() const
Definition KVDBRun.h:142
virtual ~KVDBRun()
dtor
Definition KVDBRun.cpp:59
virtual void ReadRunListLine(const KVString &)
Definition KVDBRun.cpp:143
void Modified()
Definition KVDBRun.h:67
virtual void UnsetSystem()
Definition KVDBRun.cpp:225
KVDBRun()
default ctor
Definition KVDBRun.cpp:33
virtual void SetScaler(const Char_t *name, Int_t val)
Set value for the scaler with the given name for this run.
Definition KVDBRun.h:209
void SetNumber(Int_t n)
Definition KVDBRun.h:93
virtual void WriteRunListHeader(std::ostream &, Char_t delim='|') const
Write the version flag.
Definition KVDBRun.cpp:211
Database class used to store information on different colliding systems studied during an experiment....
Definition KVDBSystem.h:52
void RemoveRun(KVDBRecord *)
KVTarget * GetTarget() const
Definition KVDBSystem.h:79
virtual void Print(Option_t *opt="") const
KVNamedParameter * GetParameter(Int_t idx) const
return the parameter object with index idx
Int_t GetNpar() const
return the number of stored parameters
Bool_t IsDouble() const
const Char_t * GetString() const
Bool_t IsInt() const
Bool_t IsString() const
Double_t GetDouble() const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
virtual void SetTitle(const char *title="")
const char * GetName() const override
const char * GetTitle() const override
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
virtual void Warning(const char *method, const char *msgfmt,...) const
TObject * First() const override
Int_t Atoi() const
const char * Data() const
Bool_t IsDigit() const
TObjArray * Tokenize(const TString &delim) const
TString & ReplaceAll(const char *s1, const char *s2)
TLine * line
const char * String
ClassImp(TPyArg)