KaliVeda
Toolkit for HIC analysis
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 
25 using namespace std;
26 
28 
29 
30 
34 {
35  //default ctor
36  fBlockSignals = kFALSE;
37  fRunFiles.SetOwner();
38 }
39 
40 
41 
44 
45 KVDBRun::KVDBRun(Int_t number, const Char_t* title)
46 {
47  //ctor for a given run number
48 
49  SetNumber(number);
50  SetTitle(title);
51  fBlockSignals = kFALSE;
52  fRunFiles.SetOwner();
53 }
54 
55 
56 
57 
58 
60 
62 {
63  cout << "___________________________________________________" << endl
64  << GetName() << " (" << GetTitle() << ")" << endl;
65  if (GetSystem()) {
66  cout << "System : " << GetSystem()->GetName() << endl;
67  if (GetSystem()->GetTarget())
68  cout << "Target : " << GetSystem()->GetTarget()->
69  GetName() << endl;
70  }
71  cout << "___________________________________________________" << endl;
72  //print values of all parameters
73  if (fParameters.GetNpar()) {
74  fParameters.Print("string");
75  cout << "___________________________________________________" << endl;
76  fParameters.Print("double");
77  cout << "___________________________________________________" << endl;
78  fParameters.Print("int");
79  cout << "___________________________________________________" << endl;
80  }
81  std::cout << " -- " << fRunFiles.GetEntries() << " associated files:\n";
82  fRunFiles.ls();
83  cout << "___________________________________________________" << endl;
84 }
85 
86 
87 
88 
92 
93 void KVDBRun::WriteRunListLine(ostream& outstr, Char_t) const
94 {
95  //Write informations on run in format used for runlists, i.e. a line of fields separated by the
96  //separator character '|' (the 'delim' argument is obsolete and is not used)
97 
98  TString _delim = " | ";
99  KVString s;
100  //write run number
101  outstr << GetNumber() << _delim.Data();
102  //write all scalers (integer values)
103  for (int i = 0; i < fParameters.GetNpar(); i++) {
104  if (fParameters.GetParameter(i)->IsInt()) {
105  s.Form("%s=%d", fParameters.GetParameter(i)->GetName(), fParameters.GetParameter(i)->GetInt());
106  outstr << s.Data() << _delim.Data();
107  }
108  }
109  //write all floating point values
110  for (int i = 0; i < fParameters.GetNpar(); i++) {
111  if (fParameters.GetParameter(i)->IsDouble()) {
112  s.Form("%s=%f", fParameters.GetParameter(i)->GetName(), fParameters.GetParameter(i)->GetDouble());
113  outstr << s.Data() << _delim.Data();
114  }
115  }
116  //write all string values
117  for (int i = 0; i < fParameters.GetNpar(); i++) {
118  if (fParameters.GetParameter(i)->IsString()) {
119  // as we write all strings as 'parname=value', there is a problem if the string 'value'
120  // itself contains the '=' symbol !!
121  // therefore we replace any '=' in the string by '\equal' before writing in the file.
122  // when reading back (see ReadRunListLine), we replace '\equal' by '='
123  TString tmp(fParameters.GetParameter(i)->GetString());
124  tmp.ReplaceAll("=", "\\equal");
125  s.Form("%s=%s", fParameters.GetParameter(i)->GetName(), tmp.Data());
126  outstr << s.Data() << _delim.Data();
127  }
128  }
129  outstr << endl;
130 }
131 
132 
133 
134 
139 
141 {
142  //Set run characteristics by reading informations in 'line' (assumed to have been written
143  //by WriteRunListLine).
144 
145  //Break line into fields using delimiter '|'
146  TObjArray* fields = line.Tokenize('|');
147  if (fields->GetEntries() < 1) {
148  //not a valid line for run
149  delete fields;
150  return;
151  }
152 
153  //first field is run number
154  KVString kvs = ((TObjString*)fields->At(0))->String().Remove(TString::kBoth, ' ');
155  if (kvs.IsDigit()) {
156  SetNumber(kvs.Atoi());
157  }
158  else {
159  //not a valid line for run
160  delete fields;
161  return;
162  }
163 
164 // cout << GetName() << endl;
165 
166  //loop over other fields
167  for (int i = 1; i < fields->GetEntries(); i++) {
168 
169  //each field is of the form "parameter=value"
170  KVString kvs = ((TObjString*)fields->At(i))->String().Remove(TString::kBoth, ' ');
171  TObjArray* toks = kvs.Tokenize('=');
172  if (toks->GetEntries() == 2) {
173  KVString parameter = ((TObjString*)toks->At(0))->String().Remove(TString::kBoth, ' ');
174  KVString value = ((TObjString*)toks->At(1))->String().Remove(TString::kBoth, ' ');
175  //set parameter based on value
176  if (value.IsDigit()) {
177  //only true for non-floating point i.e. scaler values
178  SetScaler(parameter.Data(), value.Atoi());
179 // cout << " -- SCA " << parameter.Data() << " = " << GetScaler(parameter.Data()) << endl;
180  }
181  else if (value.IsFloat()) {
182  Set(parameter.Data(), value.Atof());
183  // cout << " -- FLO " << parameter.Data() << " = " << Get(parameter.Data()) << endl;
184  }
185  else { // string value
186  // as we write all strings as 'parname=value', there is a problem if the string 'value'
187  // itself contains the '=' symbol !!
188  // therefore we replace any '=' in the string by '\equal' before writing in the file
189  // (see WriteRunListLine).
190  // when reading back, we replace '\equal' by '='
191  value.ReplaceAll("\\equal", "=");
192  Set(parameter.Data(), value.Data());
193  // cout << " -- STR " << parameter.Data() << " = " << GetString(parameter.Data()) << endl;
194  }
195  }
196  delete toks;
197  }
198 
199  delete fields;
200 }
201 
202 
203 
204 
207 
208 void KVDBRun::WriteRunListHeader(ostream& outstr, Char_t) const
209 {
210  //Write the version flag
211 
212  outstr << "Version=10" << endl;
213 }
214 
215 
216 
221 
223 {
224  //If this run has previously been associated with a system in the database,
225  //this will remove the association. The run will also be removed from the system's
226  //list of associated runs.
227 
228  if (GetSystem()) {
229  GetSystem()->RemoveRun(this);
230  }
231  SetTitle("Experimental run");
232  Modified();
233 }
234 
235 
236 
238 
240 {
241  if (GetKey("Systems")) {
242  if (GetKey("Systems")->GetLinks()->GetSize())
243  return (KVDBSystem*) GetKey("Systems")->GetLinks()->First();
244  }
245  return 0;
246 }
247 
248 
249 
252 
254 {
255  //Set system for run. Any previous system is unassociated (run will be removed from system's list)
256  if (!GetKey("Systems")) {
257  KVDBKey* key = AddKey("Systems", "Physical system used");
258  key->SetUniqueStatus(kTRUE);
259  key->SetSingleStatus(kTRUE);
260  }
261  else {
262  UnsetSystem();
263  }
264  if (!AddLink("Systems", system)) {
265  Warning("SetSystem(KVDBSystem*)",
266  "System %s couldn't be set for Run %d. This bizarre...",
267  system->GetName(), GetNumber());
268  }
269  else {
270  //set title of run = name of system
271  SetTitle(system->GetName());
272  }
273  Modified();
274 }
275 
276 
277 
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 Char_t *key) const
Returns the list of records linked to this record in table "key".
Definition: KVDBRecord.cpp:206
Description of an experimental run in database ,,.
Definition: KVDBRun.h:41
void Print(Option_t *option="") const override
Definition: KVDBRun.cpp:61
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:253
KVDBSystem * GetSystem() const
Definition: KVDBRun.cpp:239
virtual void WriteRunListLine(std::ostream &, Char_t delim='|') const
Definition: KVDBRun.cpp:93
virtual void ReadRunListLine(const KVString &)
Definition: KVDBRun.cpp:140
virtual void UnsetSystem()
Definition: KVDBRun.cpp:222
KVDBRun()
default ctor
Definition: KVDBRun.cpp:33
virtual void WriteRunListHeader(std::ostream &, Char_t delim='|') const
Write the version flag.
Definition: KVDBRun.cpp:208
Database class used to store information on different colliding systems studied during an experiment....
Definition: KVDBSystem.h:52
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
const char * GetName() const override
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
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
void Warning(const char *location, const char *fmt,...)
const char * String
ClassImp(TPyArg)