KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVINDRADB_e475s.cpp
Go to the documentation of this file.
1 /*
2 $Id: KVINDRADB_e475s.cpp,v 1.6 2009/04/09 09:23:20 ebonnet Exp $
3 $Revision: 1.6 $
4 $Date: 2009/04/09 09:23:20 $
5 */
6 
7 //Created by KVClassFactory on Tue Sep 18 11:17:53 2007
8 //Author: Eric Bonnet
9 
10 #include "KVINDRADB_e475s.h"
11 #include "Riostream.h"
12 #include "TF1.h"
13 #include "TString.h"
14 #include "TObjString.h"
15 #include "TList.h"
16 
17 #include "KVDBParameterSet.h"
18 #include "KVINDRA.h"
19 #include "KVMultiDetArray.h"
20 #include "KVDataSet.h"
21 #include "KVINDRADB.h"
22 #include "KVNumberList.h"
23 
24 using namespace std;
25 
27 
28 
29 
30 //------------------------------
31 void KVINDRADB_e475s::init()
32 //------------------------------
33 
36 
37 {
38  //Define duplicate run, create the tables of the database.
39  cout << "init de KVINDRADB_e475s" << endl;
40 
41  fCalibrations = AddTable("Calibrations", "List of available calibrations");
42 
43 }
44 
45 
46 
47 //------------------------------
49 //------------------------------
50 
51 
54 {
55  //Default constructor
56  init();
57 }
58 
59 
60 //------------------------------
62 //------------------------------
63 
64 
67 {
68  //Destructor
69 }
70 
71 
72 //------------------------------
74 //------------------------------
75 
78 
79 {
80  //ctor.
81  init();
82 }
83 
84 
85 //------------------------------
86 
89 
91 {
92 //------------------------------
94 
96 
97 }
98 
99 
100 //------------------------------
102 //------------------------------
103 
104 
106 {
107 
108  ifstream finput;
109  if (!OpenCalibFile("Pedestals", finput)) {
110  Error("ReadPedestalList()", "Could not open file %s",
111  GetCalibFileName("Pedestals"));
112  return;
113  }
114 
115  Info("ReadPedestalList()",
116  "Reading calibration parameters...");
117 
118  TString sline;
119  TString stit;
120  TObjArray* toks = NULL;
121  while (finput.good()) {
122  TString calib_det = "", calib_acq = "", calib_file = "";
123  sline.ReadLine(finput);
124  if (!sline.IsNull()) {
125  cout << sline << endl;
126  toks = sline.Tokenize(" ");
127  if (toks->GetEntries() >= 1) {
128  calib_file = ((TObjString*)(*toks)[0])->GetString();
129  if (toks->GetEntries() >= 2) {
130  calib_det = ((TObjString*)(*toks)[1])->GetString();
131  if (toks->GetEntries() >= 3) {
132  calib_acq = ((TObjString*)(*toks)[2])->GetString();
133  }
134  }
135  }
136 
137  stit.Form("%s/%s", gDataSet->GetDataSetDir(), calib_file.Data());
138  ifstream fin(stit.Data());
139  ReadPedestalFile(fin, calib_det, calib_acq);
140  fin.close();
141  }
142  }
143  finput.close();
144 
145 
146 }
147 
148 
149 //------------------------------
151 //------------------------------
152 
153 
155 {
156 
157  ifstream finput;
158  if (!OpenCalibFile("CalibFile", finput)) {
159  Error("ReadCalibrations()", "Could not open file %s",
160  GetCalibFileName("CalibFile"));
161  return;
162  }
163 
164  Info("ReadCalibrations()",
165  "Reading calibration parameters...");
166 
167  TString sline;
168  TString stit;
169  TString calib_det, calib_gain, calib_file;
170  TObjArray* toks = NULL;
171  while (finput.good()) {
172  sline.ReadLine(finput);
173  if (!sline.IsNull()) {
174  cout << sline << endl;
175  toks = sline.Tokenize(" ");
176  calib_det = ((TObjString*)(*toks)[0])->GetString();
177  calib_gain = ((TObjString*)(*toks)[1])->GetString();
178  calib_file = ((TObjString*)(*toks)[2])->GetString();
179  stit.Form("%s/%s", gDataSet->GetDataSetDir(), calib_file.Data());
180  ifstream fin(stit.Data());
181  ReadCalibFile(fin, calib_det, calib_gain);
182  fin.close();
183  }
184  }
185  finput.close();
186 
187 }
188 
189 
190 //------------------------------
191 
194 
195 void KVINDRADB_e475s::ReadCalibFile(ifstream& fin, TString dettype, TString detgain)
196 {
197 //------------------------------
198  Info("ReadCalibFile()",
199  "Reading calibration parameters of file %s%s", dettype.Data(), detgain.Data());
200 
201  KVDBParameterSet* parset = nullptr;
202  TList list_record;
203 
204  TString detname;
205  TString sline;
206  TString calib_type, calib_signal, calib_runs, calib_ring, calib_mods;
207  unique_ptr<TObjArray> toks;
208  unique_ptr<TObjArray> tokspara;
209  while (fin.good()) { //reading the file
210  sline.ReadLine(fin);
211  while (sline.BeginsWith("+KVCalibrator")) {
212  sline.ReadLine(fin);
213  while (sline.BeginsWith("<LIST> Type=")) {
214  sline.ReplaceAll("<LIST> Type=", "");
215  if (sline.Contains("(")) {
216  toks.reset(sline.Tokenize("("));
217  sline = ((TObjString*)toks->At(0))->GetString();
218  }
219  calib_type = sline;
220  sline.ReadLine(fin);
221  while (sline.BeginsWith("<LIST> Signal=")) {
222  sline.ReplaceAll("<LIST> Signal=", "");
223  calib_signal = sline;
224  cout << calib_signal << endl;
225  if (calib_signal != dettype + detgain) Error("ReadCalibFile()", "Erreur de synchro ...");
226  sline.ReadLine(fin);
227  while (sline.BeginsWith("++<LIST> Runs=")) {
228  sline.ReplaceAll("++<LIST> Runs=", "");
229  calib_runs = sline;
230  cout << calib_runs << endl;
231  sline.ReadLine(fin);
232  list_record.RemoveAll();
233  while (sline.BeginsWith("<LIST> Rings=")) {
234  sline.ReplaceAll("<LIST> Rings=", "");
235  calib_ring = sline;
236  cout << calib_ring << endl;
237  sline.ReadLine(fin);
238  while (sline.BeginsWith("<LIST> Modules=") || sline.BeginsWith("<PARAMETER> Function=")) {
239  if (sline.BeginsWith("<LIST> Modules=")) {
240  sline.ReplaceAll("<LIST> Modules=", "");
241  calib_mods = sline;
242  cout << calib_mods << endl;
243  //sprintf(detname,"%s_%02d%02d_%s",dettype.Data(),calib_ring.Atoi(),calib_mods.Atoi(),detgain.Data());
244  detname.Form("%s_%02d%02d", dettype.Data(), calib_ring.Atoi(), calib_mods.Atoi());
245  }
246  else {
247  sline.ReplaceAll("<PARAMETER> Function=", "");
248  cout << sline << endl;
249  toks.reset(sline.Tokenize(":"));
250  TF1 ff(Form("f%s", detname.Data()), ((TObjString*)toks->At(0))->GetString().Data());
251 
252  TString sparaline = ((TObjString*)toks->At(1))->GetString();
253 
254  tokspara.reset(sparaline.Tokenize(" "));
255  if (tokspara->GetEntries() != ff.GetNpar()) cout << tokspara->GetEntries() << " " << ff.GetNpar() << endl;
256  for (Int_t pp = 0; pp < ff.GetNpar(); pp += 1) {
257  ff.SetParameter(pp, ((TObjString*)tokspara->At(pp))->GetString().Atof());
258  printf("%d %g\n", pp, ff.GetParameter(pp));
259  }
260 
261  parset = new KVDBParameterSet(detname, Form("%s(%s)", calib_type.Data(), detgain.Data()), ff.GetNpar() + 3);
262  parset->SetParamName(0, ff.GetExpFormula().Data());
263  for (Int_t pp = 0; pp < ff.GetNpar(); pp += 1) {
264  parset->SetParameter(pp + 1, ff.GetParameter(pp));
265  parset->SetParamName(pp + 1, ff.GetParName(pp));
266  }
267  parset->SetParameter(ff.GetNpar() + 1, 0.);
268  parset->SetParamName(ff.GetNpar() + 1, "xmin");
269  parset->SetParameter(ff.GetNpar() + 2, 4096.);
270  parset->SetParamName(ff.GetNpar() + 2, "xmax");
271 
272  fCalibrations->AddRecord(parset);
273  list_record.Add(parset);
274 
275  }
276  sline.ReadLine(fin);
277  }
278  }
279  KVNumberList nl(calib_runs);
280  nl.Begin();
281  while (!nl.End()) {
282  Int_t run = nl.Next();
283  for (Int_t ll = 0; ll < list_record.GetEntries(); ll += 1)
284  if (!(((KVDBRecord*)list_record.At(ll))->AddLink("Runs", GetRun(run))))
285  Error("ReadCalibFile()", "Pb de chargements ...");
286  }
287  }
288  }
289  }
290  }
291  }
292 
293  fin.close();
294 }
295 
296 
297 //------------------------------
298 
301 
302 void KVINDRADB_e475s::ReadPedestalFile(ifstream& fin, TString dettype, TString detgain)
303 {
304 //------------------------------
305  Info("ReadPedestalFile()",
306  "Reading pedestal value of file %s - %s", dettype.Data(), detgain.Data());
307 
308  KVDBParameterSet* parset = NULL;
309  TList* list_record = new TList();
310 
311  Char_t detname[50];
312  TString sline;
313  TString calib_type, calib_signal, calib_det, calib_acq;
314  TString calib_runs, calib_ring, calib_mods;
315  TObjArray* toks = NULL;
316  TObjArray* tokspara = NULL;
317  while (fin.good()) { //reading the file
318  sline.ReadLine(fin);
319  while (sline.BeginsWith("+KVCalibrator")) {
320  sline.ReadLine(fin);
321  while (sline.BeginsWith("<LIST> Type=")) {
322  sline.ReplaceAll("<LIST> Type=", "");
323  calib_type = sline;
324  cout << calib_type << endl;
325  sline.ReadLine(fin);
326  while (sline.BeginsWith("<LIST> KVDetector=")) {
327  sline.ReplaceAll("<LIST> KVDetector=", "");
328  calib_det = sline;
329  cout << calib_det << endl;
330  sline.ReadLine(fin);
331  while (sline.BeginsWith("<LIST> KVACQParam=")) {
332  sline.ReplaceAll("<LIST> KVACQParam=", "");
333  calib_acq = sline;
334  cout << calib_acq << endl;
335  sline.ReadLine(fin);
336  while (sline.BeginsWith("++<LIST> Runs=")) {
337  sline.ReplaceAll("++<LIST> Runs=", "");
338  calib_runs = sline;
339  cout << calib_runs << endl;
340  sline.ReadLine(fin);
341 
342  list_record->RemoveAll();
343  while (sline.BeginsWith("<LIST> Rings=")) {
344  sline.ReplaceAll("<LIST> Rings=", "");
345  calib_ring = sline;
346  cout << calib_ring << endl;
347  sline.ReadLine(fin);
348  while (sline.BeginsWith("<LIST> Modules=") || sline.BeginsWith("<PARAMETER> Function=")) {
349  if (sline.BeginsWith("<LIST> Modules=")) {
350  sline.ReplaceAll("<LIST> Modules=", "");
351  calib_mods = sline;
352  cout << calib_mods << endl;
353  //sprintf(detname,"%s_%02d%02d_%s",dettype.Data(),calib_ring.Atoi(),calib_mods.Atoi(),detgain.Data());
354  sprintf(detname, "%s_%02d%02d", calib_det.Data(), calib_ring.Atoi(), calib_mods.Atoi());
355  }
356  else {
357  sline.ReplaceAll("<PARAMETER> Function=", "");
358  cout << sline << endl;
359  toks = sline.Tokenize(":");
360  TF1 ff(Form("f%s", detname), ((TObjString*)(*toks)[0])->GetString().Data());
361 
362  TString sparaline = ((TObjString*)(*toks)[1])->GetString();
363  delete toks;
364 
365  tokspara = sparaline.Tokenize(" ");
366  if (tokspara->GetEntries() != ff.GetNpar()) cout << tokspara->GetEntries() << " " << ff.GetNpar() << endl;
367  for (Int_t pp = 0; pp < ff.GetNpar(); pp += 1) {
368  ff.SetParameter(pp, ((TObjString*)(*tokspara)[pp])->GetString().Atof());
369  printf("%d %lf\n", pp, ff.GetParameter(pp));
370  }
371  delete tokspara;
372 
373  parset = new KVDBParameterSet(detname, Form("%s", calib_acq.Data()), ff.GetNpar() + 1);
374  parset->SetParamName(0, ff.GetExpFormula().Data());
375  for (Int_t pp = 0; pp < ff.GetNpar(); pp += 1) {
376  parset->SetParameter(pp + 1, ff.GetParameter(pp));
377  parset->SetParamName(pp + 1, ff.GetParName(pp));
378  }
379 
380  fPedestals->AddRecord(parset);
381  list_record->Add(parset);
382 
383  }
384  sline.ReadLine(fin);
385  }
386  }
387  KVNumberList nl(calib_runs);
388  nl.Begin();
389  while (!nl.End()) {
390  Int_t run = nl.Next();
391  for (Int_t ll = 0; ll < list_record->GetEntries(); ll += 1)
392  if (!(((KVDBRecord*)list_record->At(ll))->AddLink("Runs", GetRun(run))))
393  Error("ReadCalibFile()", "Pb de chargements ...");
394  }
395  }
396  }
397  }
398  }
399  }
400  }
401  fin.close();
402 
403  list_record->Clear();
404  delete list_record;
405 
406 }
407 
408 
int Int_t
KVDataSet * gDataSet
Definition: KVDataSet.cpp:29
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
char * Form(const char *fmt,...)
To store calibration parameters in a database ,.
void SetParamName(UShort_t i, const Char_t *name)
void SetParameter(UShort_t i, Double_t val)
Record folder for the database.
Definition: KVDBRecord.h:42
virtual Bool_t AddRecord(KVDBRecord *add)
Definition: KVDBTable.cpp:74
const Char_t * GetDataSetDir() const
Definition: KVDataSet.cpp:720
TString GetCalibFileName(const Char_t *type) const
Definition: KVExpDB.h:108
Bool_t OpenCalibFile(const Char_t *type, std::ifstream &fs) const
Definition: KVExpDB.cpp:433
Database for E475s experiment (2006)
void init()
Define duplicate run, create the tables of the database.
void ReadPedestalFile(std::ifstream &fin, TString, TString)
virtual ~KVINDRADB_e475s()
Destructor.
KVDBTable * fCalibrations
virtual void Build()
KVINDRADB_e475s()
Default constructor.
void ReadCalibFile(std::ifstream &fin, TString, TString)
DataBase of parameters for an INDRA campaign.
Definition: KVINDRADB.h:58
KVDBTable * fPedestals
table of pedestal files
Definition: KVINDRADB.h:72
KVINDRADBRun * GetRun(Int_t run) const
Definition: KVINDRADB.h:132
virtual void Build()
Definition: KVINDRADB.cpp:893
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:83
Bool_t End(void) const
Definition: KVNumberList.h:197
void Begin(void) const
Int_t Next(void) const
void RemoveAll()
virtual Int_t GetEntries() const
virtual Double_t GetParameter(const TString &name) const
virtual Int_t GetNpar() const
virtual TString GetExpFormula(Option_t *option="") const
virtual const char * GetParName(Int_t ipar) const
virtual void SetParameter(const TString &name, Double_t value)
virtual void Add(TObject *obj)
virtual TObject * At(Int_t idx) const
virtual void Clear(Option_t *option="")
Int_t GetEntries() const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
Int_t Atoi() const
TObjArray * Tokenize(const TString &delim) const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
const char * Data() const
Bool_t IsNull() const
void Form(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
std::istream & ReadLine(std::istream &str, Bool_t skipWhite=kTRUE)