]>
Commit | Line | Data |
---|---|---|
92793671 | 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 | ||
16 | /////////////////////////////////////////////////////////////////////////////// | |
17 | // // | |
18 | // Class for Parsing simple text configuration files // | |
19 | // It produces a TMap for the Key=>Value pairs found in the // | |
20 | // Configutation file. // | |
21 | // // | |
22 | // The configuration file has a simple structure: // | |
23 | // * Lines starting with a # or empty lines are ignored // | |
24 | // * Key and Value are separated either by a <tab> or <space>es // | |
25 | // // | |
26 | // Currently the class is used in the TPC DAs to allow an adjustment of // | |
27 | // the most relevant parameters without recompiling the DAs // | |
28 | /////////////////////////////////////////////////////////////////////////////// | |
29 | ||
30 | ||
31 | #include <fstream> | |
32 | //Root includes | |
33 | #include <TObjString.h> | |
34 | #include <TObjArray.h> | |
35 | #include <TString.h> | |
36 | #include <TIterator.h> | |
37 | #include <TMap.h> | |
38 | //AliRoot includes | |
39 | ||
40 | //header | |
41 | #include "AliTPCConfigDA.h" | |
42 | ||
43 | ||
44 | ||
45 | AliTPCConfigDA::AliTPCConfigDA() : | |
46 | TObject(), | |
47 | fConfigMap(new TMap) | |
48 | { | |
49 | // | |
50 | // default constructor | |
51 | // | |
52 | fConfigMap->SetOwnerKeyValue(); | |
53 | } | |
54 | //_____________________________________________________________________ | |
55 | AliTPCConfigDA::AliTPCConfigDA(const AliTPCConfigDA &cfg) : | |
56 | TObject(), | |
57 | fConfigMap((TMap*)cfg.fConfigMap->Clone()) | |
58 | { | |
59 | // | |
60 | // copy constructor | |
61 | // | |
62 | fConfigMap->SetOwnerKeyValue(); | |
63 | } | |
64 | ||
65 | //_____________________________________________________________________ | |
66 | AliTPCConfigDA::AliTPCConfigDA(const char* cfgfile) : | |
67 | TObject(), | |
68 | fConfigMap(new TMap) | |
69 | { | |
70 | // | |
71 | // default constructor using the config file name as input parameter | |
72 | // | |
73 | fConfigMap->SetOwnerKeyValue(); | |
74 | if ( !cfgfile ) return; | |
75 | ParseConfigFileTxt(cfgfile); | |
76 | } | |
77 | //_____________________________________________________________________ | |
78 | AliTPCConfigDA& AliTPCConfigDA::operator = (const AliTPCConfigDA &source) | |
79 | { | |
80 | // | |
81 | // assignment operator | |
82 | // | |
83 | if (&source == this) return *this; | |
84 | new (this) AliTPCConfigDA(source); | |
85 | ||
86 | return *this; | |
87 | } | |
88 | //_____________________________________________________________________ | |
89 | AliTPCConfigDA::~AliTPCConfigDA() | |
90 | { | |
91 | // | |
92 | // dtor | |
93 | // | |
94 | delete fConfigMap; | |
95 | } | |
96 | //_____________________________________________________________________ | |
97 | Int_t AliTPCConfigDA::ParseConfigFileTxt(const char* cfgfile) | |
98 | { | |
99 | // | |
100 | // Function to parse a configuration file | |
101 | // | |
102 | ||
103 | ifstream file(cfgfile); | |
104 | if ( !file.is_open() ){ | |
105 | Error("ParseConfigFileTxt","File %s could not be opened!", cfgfile); | |
106 | return 1; | |
107 | } | |
108 | TString strFile; | |
109 | strFile.ReadFile(file); | |
110 | TObjArray *arr=strFile.Tokenize("\n"); | |
111 | if ( !arr ) { | |
112 | file.close(); | |
113 | return 2; | |
114 | } | |
115 | TIter nextLine(arr); | |
116 | while (TObject *l=nextLine()){ | |
117 | TString line(((TObjString*)l)->GetString()); | |
118 | //remove whitespcaces | |
119 | line.Remove(TString::kBoth,' '); | |
120 | line.Remove(TString::kBoth,'\t'); | |
121 | if ( line.BeginsWith("#") || line=="" ) continue; | |
122 | TObjArray *arrValues=line.Tokenize(" \t"); | |
123 | //currently only name => Value is supported | |
124 | if (arrValues->GetEntries()!=2){ | |
125 | printf("AliTPCConfigDA::ParseConfigFileTxt: Cannot parse line '%s'\n",line.Data()); | |
126 | delete arrValues; | |
127 | continue; | |
128 | } | |
129 | fConfigMap->Add(arrValues->At(0)->Clone(),arrValues->At(1)->Clone()); | |
130 | delete arrValues; | |
131 | } | |
132 | ||
133 | delete arr; | |
134 | return 0; | |
135 | } | |
136 | //_____________________________________________________________________ | |
7442bceb | 137 | Float_t AliTPCConfigDA::GetValue(const char *key) const |
92793671 | 138 | { |
139 | // | |
140 | //Get value for the speciefied key | |
141 | // | |
142 | TObject *val=fConfigMap->GetValue(key); | |
143 | if ( !val ) return -999.; | |
144 | TString sval(((TObjString*)val)->GetString()); | |
145 | return sval.Atof(); | |
146 | } | |
147 | //_____________________________________________________________________ | |
148 | void AliTPCConfigDA::ResetMap() | |
149 | { | |
150 | // | |
151 | // Reset the map with the configuration values | |
152 | // | |
153 | fConfigMap->DeleteAll(); | |
154 | } |