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 
32 
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  {
75  fParameters.Print("string");
76  cout << "___________________________________________________" << endl;
77  fParameters.Print("double");
78  cout << "___________________________________________________" << endl;
79  fParameters.Print("int");
80  cout << "___________________________________________________" << endl;
81  }
82  std::cout << " -- " << fRunFiles.GetEntries() << " associated files:\n";
83  fRunFiles.ls();
84  cout << "___________________________________________________" << endl;
85 }
86 
87 
88 
89 
93 
94 void KVDBRun::WriteRunListLine(ostream& outstr, Char_t) const
95 {
96  //Write informations on run in format used for runlists, i.e. a line of fields separated by the
97  //separator character '|' (the 'delim' argument is obsolete and is not used)
98 
99  TString _delim = " | ";
100  KVString s;
101  //write run number
102  outstr << GetNumber() << _delim.Data();
103  //write all scalers (integer values)
104  for (int i = 0; i < fParameters.GetNpar(); i++) {
105  if (fParameters.GetParameter(i)->IsInt()) {
106  s.Form("%s=%d", fParameters.GetParameter(i)->GetName(), fParameters.GetParameter(i)->GetInt());
107  outstr << s.Data() << _delim.Data();
108  }
109  }
110  //write all floating point values
111  for (int i = 0; i < fParameters.GetNpar(); i++) {
112  if (fParameters.GetParameter(i)->IsDouble()) {
113  s.Form("%s=%f", fParameters.GetParameter(i)->GetName(), fParameters.GetParameter(i)->GetDouble());
114  outstr << s.Data() << _delim.Data();
115  }
116  }
117  //write all string values
118  for (int i = 0; i < fParameters.GetNpar(); i++) {
119  if (fParameters.GetParameter(i)->IsString()) {
120  // as we write all strings as 'parname=value', there is a problem if the string 'value'
121  // itself contains the '=' symbol !!
122  // therefore we replace any '=' in the string by '\equal' before writing in the file.
123  // when reading back (see ReadRunListLine), we replace '\equal' by '='
124  TString tmp(fParameters.GetParameter(i)->GetString());
125  tmp.ReplaceAll("=", "\\equal");
126  s.Form("%s=%s", fParameters.GetParameter(i)->GetName(), tmp.Data());
127  outstr << s.Data() << _delim.Data();
128  }
129  }
130  outstr << endl;
131 }
132 
133 
134 
135 
140 
142 {
143  //Set run characteristics by reading informations in 'line' (assumed to have been written
144  //by WriteRunListLine).
145 
146  //Break line into fields using delimiter '|'
147  TObjArray* fields = line.Tokenize('|');
148  if (fields->GetEntries() < 1) {
149  //not a valid line for run
150  delete fields;
151  return;
152  }
153 
154  //first field is run number
155  KVString kvs = ((TObjString*)fields->At(0))->String().Remove(TString::kBoth, ' ');
156  if (kvs.IsDigit()) {
157  SetNumber(kvs.Atoi());
158  }
159  else {
160  //not a valid line for run
161  delete fields;
162  return;
163  }
164 
165 // cout << GetName() << endl;
166 
167  //loop over other fields
168  for (int i = 1; i < fields->GetEntries(); i++) {
169 
170  //each field is of the form "parameter=value"
171  KVString kvs = ((TObjString*)fields->At(i))->String().Remove(TString::kBoth, ' ');
172  TObjArray* toks = kvs.Tokenize('=');
173  if (toks->GetEntries() == 2) {
174  KVString parameter = ((TObjString*)toks->At(0))->String().Remove(TString::kBoth, ' ');
175  KVString value = ((TObjString*)toks->At(1))->String().Remove(TString::kBoth, ' ');
176  //set parameter based on value
177  if (value.IsDigit()) {
178  //only true for non-floating point i.e. scaler values
179  SetScaler(parameter.Data(), value.Atoi());
180 // cout << " -- SCA " << parameter.Data() << " = " << GetScaler(parameter.Data()) << endl;
181  }
182  else if (value.IsFloat()) {
183  Set(parameter.Data(), value.Atof());
184  // cout << " -- FLO " << parameter.Data() << " = " << Get(parameter.Data()) << endl;
185  }
186  else { // string value
187  // as we write all strings as 'parname=value', there is a problem if the string 'value'
188  // itself contains the '=' symbol !!
189  // therefore we replace any '=' in the string by '\equal' before writing in the file
190  // (see WriteRunListLine).
191  // when reading back, we replace '\equal' by '='
192  value.ReplaceAll("\\equal", "=");
193  Set(parameter.Data(), value.Data());
194  // cout << " -- STR " << parameter.Data() << " = " << GetString(parameter.Data()) << endl;
195  }
196  }
197  delete toks;
198  }
199 
200  delete fields;
201 }
202 
203 
204 
205 
208 
209 void KVDBRun::WriteRunListHeader(ostream& outstr, Char_t) const
210 {
211  //Write the version flag
212 
213  outstr << "Version=10" << endl;
214 }
215 
216 
217 
222 
224 {
225  //If this run has previously been associated with a system in the database,
226  //this will remove the association. The run will also be removed from the system's
227  //list of associated runs.
228 
229  if (GetSystem()) {
230  GetSystem()->RemoveRun(this);
231  }
232  SetTitle("Experimental run");
233  Modified();
234 }
235 
236 
237 
239 
241 {
242  if (GetKey("Systems")) {
243  if (GetKey("Systems")->GetLinks()->GetSize())
244  return (KVDBSystem*) GetKey("Systems")->GetLinks()->First();
245  }
246  return 0;
247 }
248 
249 
250 
253 
255 {
256  //Set system for run. Any previous system is unassociated (run will be removed from system's list)
257  if (!GetKey("Systems")) {
258  KVDBKey* key = AddKey("Systems", "Physical system used");
259  key->SetUniqueStatus(kTRUE);
260  key->SetSingleStatus(kTRUE);
261  }
262  else {
263  UnsetSystem();
264  }
265  if (!AddLink("Systems", system)) {
266  Warning("SetSystem(KVDBSystem*)",
267  "System %s couldn't be set for Run %d. This bizarre...",
268  system->GetName(), GetNumber());
269  }
270  else {
271  //set title of run = name of system
272  SetTitle(system->GetName());
273  }
274  Modified();
275 }
276 
277 
278 
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:40
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:254
KVDBSystem * GetSystem() const
Definition: KVDBRun.cpp:240
virtual void WriteRunListLine(std::ostream &, Char_t delim='|') const
Definition: KVDBRun.cpp:94
virtual void ReadRunListLine(const KVString &)
Definition: KVDBRun.cpp:141
virtual void UnsetSystem()
Definition: KVDBRun.cpp:223
KVDBRun()
default ctor
Definition: KVDBRun.cpp:33
virtual void WriteRunListHeader(std::ostream &, Char_t delim='|') const
Write the version flag.
Definition: KVDBRun.cpp:209
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)