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