AliRoot Core  3dc7879 (3dc7879)
AliTPCConfigDA.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
28 
29 
30 #include <fstream>
31 //Root includes
32 #include <TObjString.h>
33 #include <TObjArray.h>
34 #include <TString.h>
35 #include <TIterator.h>
36 #include <TMap.h>
37 //AliRoot includes
38 
39 //header
40 #include "AliTPCConfigDA.h"
41 
42 using std::ifstream;
43 
45  TObject(),
46  fConfigMap(new TMap)
47 {
49 
50  fConfigMap->SetOwnerKeyValue();
51 }
52 //_____________________________________________________________________
54  TObject(),
55  fConfigMap((TMap*)cfg.fConfigMap->Clone())
56 {
58 
59  fConfigMap->SetOwnerKeyValue();
60 }
61 
62 //_____________________________________________________________________
63 AliTPCConfigDA::AliTPCConfigDA(const char* cfgfile) :
64  TObject(),
65  fConfigMap(new TMap)
66 {
68 
69  fConfigMap->SetOwnerKeyValue();
70  if ( !cfgfile ) return;
71  ParseConfigFileTxt(cfgfile);
72 }
73 //_____________________________________________________________________
75 {
77 
78  if (&source == this) return *this;
79  new (this) AliTPCConfigDA(source);
80 
81  return *this;
82 }
83 //_____________________________________________________________________
85 {
87 
88  delete fConfigMap;
89 }
90 //_____________________________________________________________________
91 Int_t AliTPCConfigDA::ParseConfigFileTxt(const char* cfgfile)
92 {
94 
95  ifstream file(cfgfile);
96  if ( !file.is_open() ){
97  Error("ParseConfigFileTxt","File %s could not be opened!", cfgfile);
98  return 1;
99  }
100  TString strFile;
101  strFile.ReadFile(file);
102  TObjArray *arr=strFile.Tokenize("\n");
103  if ( !arr ) {
104  file.close();
105  return 2;
106  }
107  TIter nextLine(arr);
108  while (TObject *l=nextLine()){
109  TString line(((TObjString*)l)->GetString());
110  //remove whitespcaces
111  line.Remove(TString::kBoth,' ');
112  line.Remove(TString::kBoth,'\t');
113  if ( line.BeginsWith("#") || line=="" ) continue;
114  TObjArray *arrValues=line.Tokenize(" \t");
115  //currently only name => Value is supported
116  if (arrValues->GetEntries()!=2){
117  printf("AliTPCConfigDA::ParseConfigFileTxt: Cannot parse line '%s'\n",line.Data());
118  delete arrValues;
119  continue;
120  }
121  fConfigMap->Add(arrValues->At(0)->Clone(),arrValues->At(1)->Clone());
122  delete arrValues;
123  }
124 
125  delete arr;
126  return 0;
127 }
128 //_____________________________________________________________________
129 Float_t AliTPCConfigDA::GetValue(const char *key) const
130 {
132 
133  TObject *val=fConfigMap->GetValue(key);
134  if ( !val ) return -999.;
135  TString sval(((TObjString*)val)->GetString());
136  return sval.Atof();
137 }
138 //_____________________________________________________________________
140 {
142 
143  fConfigMap->DeleteAll();
144 }
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
virtual ~AliTPCConfigDA()
TMap * fConfigMap
Configuration map.
#define TObjArray
Float_t GetValue(const char *name) const
Class for Parsing simple text configuration files.
Int_t ParseConfigFileTxt(const char *cfgfile)
AliTPCConfigDA & operator=(const AliTPCConfigDA &cfg)