ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  Class for Parsing simple text configuration files                        //
//  It produces a TMap for the Key=>Value pairs found in the                 //
//  Configutation file.                                                      //
//                                                                           //
// The configuration file has a simple structure:                            //
// * Lines starting with a # or empty lines are ignored                      //
// * Key and Value are separated either by a <tab> or <space>es              //
//                                                                           //
//  Currently the class is used in the TPC DAs to allow an adjustment of     //
//  the most relevant parameters without recompiling the DAs                 //
///////////////////////////////////////////////////////////////////////////////


#include <fstream>
//Root includes
#include <TObjString.h>
#include <TObjArray.h>
#include <TString.h>
#include <TIterator.h>
#include <TMap.h>
//AliRoot includes

//header
#include "AliTPCConfigDA.h"

using std::ifstream;

AliTPCConfigDA::AliTPCConfigDA() :
  TObject(),
  fConfigMap(new TMap)
{
 //
 // default constructor
 //
 fConfigMap->SetOwnerKeyValue();
} 
//_____________________________________________________________________
AliTPCConfigDA::AliTPCConfigDA(const AliTPCConfigDA &cfg) :
  TObject(),
  fConfigMap((TMap*)cfg.fConfigMap->Clone())
{
  //
  // copy constructor
  //
  fConfigMap->SetOwnerKeyValue();
}

//_____________________________________________________________________
AliTPCConfigDA::AliTPCConfigDA(const char* cfgfile) :
  TObject(),
  fConfigMap(new TMap)
{
  //
  // default constructor using the config file name as input parameter
  //
  fConfigMap->SetOwnerKeyValue();
  if ( !cfgfile ) return;
  ParseConfigFileTxt(cfgfile);
}
//_____________________________________________________________________
AliTPCConfigDA& AliTPCConfigDA::operator = (const  AliTPCConfigDA &source)
{
  //
  // assignment operator
  //
  if (&source == this) return *this;
  new (this) AliTPCConfigDA(source);

  return *this;
}
//_____________________________________________________________________
AliTPCConfigDA::~AliTPCConfigDA()
{
 //
 // dtor
 //   
  delete fConfigMap;
}
//_____________________________________________________________________
Int_t AliTPCConfigDA::ParseConfigFileTxt(const char* cfgfile)
{
 //
 // Function to parse a configuration file
 //

 ifstream file(cfgfile);
 if ( !file.is_open() ){
  Error("ParseConfigFileTxt","File %s could not be opened!", cfgfile);
  return 1;
 } 
 TString strFile;
 strFile.ReadFile(file);
 TObjArray *arr=strFile.Tokenize("\n");
 if ( !arr ) {
   file.close(); 
   return 2;
 }
 TIter nextLine(arr);
 while (TObject *l=nextLine()){
  TString line(((TObjString*)l)->GetString());
  //remove whitespcaces 
  line.Remove(TString::kBoth,' ');
  line.Remove(TString::kBoth,'\t');
  if ( line.BeginsWith("#") || line=="" ) continue;
  TObjArray *arrValues=line.Tokenize(" \t");
  //currently only name => Value is supported
  if (arrValues->GetEntries()!=2){
    printf("AliTPCConfigDA::ParseConfigFileTxt: Cannot parse line '%s'\n",line.Data());
    delete arrValues;
    continue;
  }
  fConfigMap->Add(arrValues->At(0)->Clone(),arrValues->At(1)->Clone());
  delete arrValues; 
 } 

 delete arr;
 return 0;
}
//_____________________________________________________________________
Float_t AliTPCConfigDA::GetValue(const char *key) const
{
  //
  //Get value for the speciefied key
  //
  TObject *val=fConfigMap->GetValue(key);
  if ( !val ) return -999.;
  TString sval(((TObjString*)val)->GetString());
  return sval.Atof(); 
}
//_____________________________________________________________________
void AliTPCConfigDA::ResetMap()
{
  //
  // Reset the map with the configuration values
  //
  fConfigMap->DeleteAll();
}
 AliTPCConfigDA.cxx:1
 AliTPCConfigDA.cxx:2
 AliTPCConfigDA.cxx:3
 AliTPCConfigDA.cxx:4
 AliTPCConfigDA.cxx:5
 AliTPCConfigDA.cxx:6
 AliTPCConfigDA.cxx:7
 AliTPCConfigDA.cxx:8
 AliTPCConfigDA.cxx:9
 AliTPCConfigDA.cxx:10
 AliTPCConfigDA.cxx:11
 AliTPCConfigDA.cxx:12
 AliTPCConfigDA.cxx:13
 AliTPCConfigDA.cxx:14
 AliTPCConfigDA.cxx:15
 AliTPCConfigDA.cxx:16
 AliTPCConfigDA.cxx:17
 AliTPCConfigDA.cxx:18
 AliTPCConfigDA.cxx:19
 AliTPCConfigDA.cxx:20
 AliTPCConfigDA.cxx:21
 AliTPCConfigDA.cxx:22
 AliTPCConfigDA.cxx:23
 AliTPCConfigDA.cxx:24
 AliTPCConfigDA.cxx:25
 AliTPCConfigDA.cxx:26
 AliTPCConfigDA.cxx:27
 AliTPCConfigDA.cxx:28
 AliTPCConfigDA.cxx:29
 AliTPCConfigDA.cxx:30
 AliTPCConfigDA.cxx:31
 AliTPCConfigDA.cxx:32
 AliTPCConfigDA.cxx:33
 AliTPCConfigDA.cxx:34
 AliTPCConfigDA.cxx:35
 AliTPCConfigDA.cxx:36
 AliTPCConfigDA.cxx:37
 AliTPCConfigDA.cxx:38
 AliTPCConfigDA.cxx:39
 AliTPCConfigDA.cxx:40
 AliTPCConfigDA.cxx:41
 AliTPCConfigDA.cxx:42
 AliTPCConfigDA.cxx:43
 AliTPCConfigDA.cxx:44
 AliTPCConfigDA.cxx:45
 AliTPCConfigDA.cxx:46
 AliTPCConfigDA.cxx:47
 AliTPCConfigDA.cxx:48
 AliTPCConfigDA.cxx:49
 AliTPCConfigDA.cxx:50
 AliTPCConfigDA.cxx:51
 AliTPCConfigDA.cxx:52
 AliTPCConfigDA.cxx:53
 AliTPCConfigDA.cxx:54
 AliTPCConfigDA.cxx:55
 AliTPCConfigDA.cxx:56
 AliTPCConfigDA.cxx:57
 AliTPCConfigDA.cxx:58
 AliTPCConfigDA.cxx:59
 AliTPCConfigDA.cxx:60
 AliTPCConfigDA.cxx:61
 AliTPCConfigDA.cxx:62
 AliTPCConfigDA.cxx:63
 AliTPCConfigDA.cxx:64
 AliTPCConfigDA.cxx:65
 AliTPCConfigDA.cxx:66
 AliTPCConfigDA.cxx:67
 AliTPCConfigDA.cxx:68
 AliTPCConfigDA.cxx:69
 AliTPCConfigDA.cxx:70
 AliTPCConfigDA.cxx:71
 AliTPCConfigDA.cxx:72
 AliTPCConfigDA.cxx:73
 AliTPCConfigDA.cxx:74
 AliTPCConfigDA.cxx:75
 AliTPCConfigDA.cxx:76
 AliTPCConfigDA.cxx:77
 AliTPCConfigDA.cxx:78
 AliTPCConfigDA.cxx:79
 AliTPCConfigDA.cxx:80
 AliTPCConfigDA.cxx:81
 AliTPCConfigDA.cxx:82
 AliTPCConfigDA.cxx:83
 AliTPCConfigDA.cxx:84
 AliTPCConfigDA.cxx:85
 AliTPCConfigDA.cxx:86
 AliTPCConfigDA.cxx:87
 AliTPCConfigDA.cxx:88
 AliTPCConfigDA.cxx:89
 AliTPCConfigDA.cxx:90
 AliTPCConfigDA.cxx:91
 AliTPCConfigDA.cxx:92
 AliTPCConfigDA.cxx:93
 AliTPCConfigDA.cxx:94
 AliTPCConfigDA.cxx:95
 AliTPCConfigDA.cxx:96
 AliTPCConfigDA.cxx:97
 AliTPCConfigDA.cxx:98
 AliTPCConfigDA.cxx:99
 AliTPCConfigDA.cxx:100
 AliTPCConfigDA.cxx:101
 AliTPCConfigDA.cxx:102
 AliTPCConfigDA.cxx:103
 AliTPCConfigDA.cxx:104
 AliTPCConfigDA.cxx:105
 AliTPCConfigDA.cxx:106
 AliTPCConfigDA.cxx:107
 AliTPCConfigDA.cxx:108
 AliTPCConfigDA.cxx:109
 AliTPCConfigDA.cxx:110
 AliTPCConfigDA.cxx:111
 AliTPCConfigDA.cxx:112
 AliTPCConfigDA.cxx:113
 AliTPCConfigDA.cxx:114
 AliTPCConfigDA.cxx:115
 AliTPCConfigDA.cxx:116
 AliTPCConfigDA.cxx:117
 AliTPCConfigDA.cxx:118
 AliTPCConfigDA.cxx:119
 AliTPCConfigDA.cxx:120
 AliTPCConfigDA.cxx:121
 AliTPCConfigDA.cxx:122
 AliTPCConfigDA.cxx:123
 AliTPCConfigDA.cxx:124
 AliTPCConfigDA.cxx:125
 AliTPCConfigDA.cxx:126
 AliTPCConfigDA.cxx:127
 AliTPCConfigDA.cxx:128
 AliTPCConfigDA.cxx:129
 AliTPCConfigDA.cxx:130
 AliTPCConfigDA.cxx:131
 AliTPCConfigDA.cxx:132
 AliTPCConfigDA.cxx:133
 AliTPCConfigDA.cxx:134
 AliTPCConfigDA.cxx:135
 AliTPCConfigDA.cxx:136
 AliTPCConfigDA.cxx:137
 AliTPCConfigDA.cxx:138
 AliTPCConfigDA.cxx:139
 AliTPCConfigDA.cxx:140
 AliTPCConfigDA.cxx:141
 AliTPCConfigDA.cxx:142
 AliTPCConfigDA.cxx:143
 AliTPCConfigDA.cxx:144
 AliTPCConfigDA.cxx:145
 AliTPCConfigDA.cxx:146
 AliTPCConfigDA.cxx:147
 AliTPCConfigDA.cxx:148
 AliTPCConfigDA.cxx:149
 AliTPCConfigDA.cxx:150
 AliTPCConfigDA.cxx:151
 AliTPCConfigDA.cxx:152
 AliTPCConfigDA.cxx:153
 AliTPCConfigDA.cxx:154