1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 // Class for Parsing simple text configuration files //
19 // It produces a TMap for the Key=>Value pairs found in the //
20 // Configutation file. //
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 //
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 ///////////////////////////////////////////////////////////////////////////////
33 #include <TObjString.h>
34 #include <TObjArray.h>
36 #include <TIterator.h>
41 #include "AliTPCConfigDA.h"
45 AliTPCConfigDA::AliTPCConfigDA() :
50 // default constructor
52 fConfigMap->SetOwnerKeyValue();
54 //_____________________________________________________________________
55 AliTPCConfigDA::AliTPCConfigDA(const AliTPCConfigDA &cfg) :
57 fConfigMap((TMap*)cfg.fConfigMap->Clone())
62 fConfigMap->SetOwnerKeyValue();
65 //_____________________________________________________________________
66 AliTPCConfigDA::AliTPCConfigDA(const char* cfgfile) :
71 // default constructor using the config file name as input parameter
73 fConfigMap->SetOwnerKeyValue();
74 if ( !cfgfile ) return;
75 ParseConfigFileTxt(cfgfile);
77 //_____________________________________________________________________
78 AliTPCConfigDA& AliTPCConfigDA::operator = (const AliTPCConfigDA &source)
81 // assignment operator
83 if (&source == this) return *this;
84 new (this) AliTPCConfigDA(source);
88 //_____________________________________________________________________
89 AliTPCConfigDA::~AliTPCConfigDA()
96 //_____________________________________________________________________
97 Int_t AliTPCConfigDA::ParseConfigFileTxt(const char* cfgfile)
100 // Function to parse a configuration file
103 ifstream file(cfgfile);
104 if ( !file.is_open() ){
105 Error("ParseConfigFileTxt","File %s could not be opened!", cfgfile);
109 strFile.ReadFile(file);
110 TObjArray *arr=strFile.Tokenize("\n");
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());
129 fConfigMap->Add(arrValues->At(0)->Clone(),arrValues->At(1)->Clone());
136 //_____________________________________________________________________
137 Float_t AliTPCConfigDA::GetValue(const char *key)
140 //Get value for the speciefied key
142 TObject *val=fConfigMap->GetValue(key);
143 if ( !val ) return -999.;
144 TString sval(((TObjString*)val)->GetString());
147 //_____________________________________________________________________
148 void AliTPCConfigDA::ResetMap()
151 // Reset the map with the configuration values
153 fConfigMap->DeleteAll();