KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVDBRun.cpp
Go to the documentation of this file.
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 
33 KVDBRun::KVDBRun(): fDatime()
34 {
35  //default ctor
37 }
38 
39 
40 
43 
44 KVDBRun::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 
59 KVDBRun::~KVDBRun()
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 
96 void 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++) {
114  if (fParameters.GetParameter(i)->IsDouble()) {
115  s.Form("%s=%f", fParameters.GetParameter(i)->GetName(), fParameters.GetParameter(i)->GetDouble());
116  outstr << s.Data() << _delim.Data();
117  }
118  }
119  //write all string values
120  for (int i = 0; i < fParameters.GetNpar(); i++) {
121  if (fParameters.GetParameter(i)->IsString()) {
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 
211 void 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");
261  key->SetUniqueStatus(kTRUE);
262  key->SetSingleStatus(kTRUE);
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
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
const Bool_t kFALSE
const Bool_t kTRUE
const char Option_t
Cross-reference in a KVDataBase.
Definition: KVDBKey.h:37
virtual void SetUniqueStatus(Bool_t unique)
Definition: KVDBKey.h:72
virtual void SetSingleStatus(Bool_t single)
Definition: KVDBKey.h:77
virtual KVRList * GetLinks() const
return the list of cross-referenced objects
Definition: KVDBKey.h:64
virtual KVDBKey * GetKey(const Char_t *key) const
Definition: KVDBRecord.cpp:290
virtual Bool_t AddKey(KVDBKey *key, Bool_t check=kTRUE)
Definition: KVDBRecord.cpp:65
virtual Bool_t AddLink(const Char_t *key_name, KVDBRecord *rec, Bool_t linkback=kTRUE)
Definition: KVDBRecord.cpp:122
virtual KVRList * GetLinks(const Char_t *key) const
Returns the list of records linked to this record in table "key".
Definition: KVDBRecord.cpp:206
virtual Int_t GetNumber() const
Definition: KVDBRecord.h:72
Description of an experimental run in database ,.
Definition: KVDBRun.h:35
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:42
KVTarget * GetTarget() const
Return target used for this run (actually target of KVDBSystem associated to run)
Definition: KVDBRun.h:164
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:38
void Set(const Char_t *param, Double_t val)
Set numerical (non-scaler) characteristic of run.
Definition: KVDBRun.h:230
virtual void Print(Option_t *option="") const
Definition: KVDBRun.cpp:69
Double_t GetSize() const
Definition: KVDBRun.h:141
virtual void ReadRunListLine(const KVString &)
Definition: KVDBRun.cpp:143
void Modified()
Definition: KVDBRun.h:66
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:208
void SetNumber(Int_t n)
Definition: KVDBRun.h:92
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:51
void RemoveRun(KVDBRecord *)
Definition: KVDBSystem.cpp:479
KVTarget * GetTarget() const
Definition: KVDBSystem.h:78
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
Int_t GetInt() 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:72
virtual const char * GetName() const
virtual void SetTitle(const char *title="")
virtual const char * GetTitle() const
Int_t GetEntries() const
TObject * At(Int_t idx) const
virtual void Warning(const char *method, const char *msgfmt,...) const
TObject * First() const
Int_t Atoi() const
Double_t Atof() const
Bool_t IsFloat() const
Bool_t IsDigit() const
TObjArray * Tokenize(const TString &delim) const
const char * Data() const
TString & ReplaceAll(const char *s1, const char *s2)
TLine * line
const long double s
Definition: KVUnits.h:94
const char * String