LCOV - code coverage report
Current view: top level - TPC/TPCbase - AliTPCConfigDA.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 57 0.0 %
Date: 2016-06-14 17:26:59 Functions: 0 13 0.0 %

          Line data    Source code
       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             : /// \class AliTPCConfigDA
      17             : /// \brief  Class for Parsing simple text configuration files
      18             : ///
      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             : #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             : 
      44             : AliTPCConfigDA::AliTPCConfigDA() :
      45           0 :   TObject(),
      46           0 :   fConfigMap(new TMap)
      47           0 : {
      48             :  /// default constructor
      49             : 
      50           0 :  fConfigMap->SetOwnerKeyValue();
      51           0 : }
      52             : //_____________________________________________________________________
      53             : AliTPCConfigDA::AliTPCConfigDA(const AliTPCConfigDA &cfg) :
      54           0 :   TObject(),
      55           0 :   fConfigMap((TMap*)cfg.fConfigMap->Clone())
      56           0 : {
      57             :   /// copy constructor
      58             : 
      59           0 :   fConfigMap->SetOwnerKeyValue();
      60           0 : }
      61             : 
      62             : //_____________________________________________________________________
      63             : AliTPCConfigDA::AliTPCConfigDA(const char* cfgfile) :
      64           0 :   TObject(),
      65           0 :   fConfigMap(new TMap)
      66           0 : {
      67             :   /// default constructor using the config file name as input parameter
      68             : 
      69           0 :   fConfigMap->SetOwnerKeyValue();
      70           0 :   if ( !cfgfile ) return;
      71           0 :   ParseConfigFileTxt(cfgfile);
      72           0 : }
      73             : //_____________________________________________________________________
      74             : AliTPCConfigDA& AliTPCConfigDA::operator = (const  AliTPCConfigDA &source)
      75             : {
      76             :   /// assignment operator
      77             : 
      78           0 :   if (&source == this) return *this;
      79           0 :   new (this) AliTPCConfigDA(source);
      80             : 
      81           0 :   return *this;
      82           0 : }
      83             : //_____________________________________________________________________
      84             : AliTPCConfigDA::~AliTPCConfigDA()
      85           0 : {
      86             :  /// dtor
      87             : 
      88           0 :   delete fConfigMap;
      89           0 : }
      90             : //_____________________________________________________________________
      91             : Int_t AliTPCConfigDA::ParseConfigFileTxt(const char* cfgfile)
      92             : {
      93             :  /// Function to parse a configuration file
      94             : 
      95           0 :  ifstream file(cfgfile);
      96           0 :  if ( !file.is_open() ){
      97           0 :   Error("ParseConfigFileTxt","File %s could not be opened!", cfgfile);
      98           0 :   return 1;
      99             :  }
     100           0 :  TString strFile;
     101           0 :  strFile.ReadFile(file);
     102           0 :  TObjArray *arr=strFile.Tokenize("\n");
     103           0 :  if ( !arr ) {
     104           0 :    file.close();
     105           0 :    return 2;
     106             :  }
     107           0 :  TIter nextLine(arr);
     108           0 :  while (TObject *l=nextLine()){
     109           0 :   TString line(((TObjString*)l)->GetString());
     110             :   //remove whitespcaces
     111           0 :   line.Remove(TString::kBoth,' ');
     112           0 :   line.Remove(TString::kBoth,'\t');
     113           0 :   if ( line.BeginsWith("#") || line=="" ) continue;
     114           0 :   TObjArray *arrValues=line.Tokenize(" \t");
     115             :   //currently only name => Value is supported
     116           0 :   if (arrValues->GetEntries()!=2){
     117           0 :     printf("AliTPCConfigDA::ParseConfigFileTxt: Cannot parse line '%s'\n",line.Data());
     118           0 :     delete arrValues;
     119           0 :     continue;
     120             :   }
     121           0 :   fConfigMap->Add(arrValues->At(0)->Clone(),arrValues->At(1)->Clone());
     122           0 :   delete arrValues;
     123           0 :  }
     124             : 
     125           0 :  delete arr;
     126             :  return 0;
     127           0 : }
     128             : //_____________________________________________________________________
     129             : Float_t AliTPCConfigDA::GetValue(const char *key) const
     130             : {
     131             :   /// Get value for the speciefied key
     132             : 
     133           0 :   TObject *val=fConfigMap->GetValue(key);
     134           0 :   if ( !val ) return -999.;
     135           0 :   TString sval(((TObjString*)val)->GetString());
     136           0 :   return sval.Atof();
     137           0 : }
     138             : //_____________________________________________________________________
     139             : void AliTPCConfigDA::ResetMap()
     140             : {
     141             :   /// Reset the map with the configuration values
     142             : 
     143           0 :   fConfigMap->DeleteAll();
     144           0 : }

Generated by: LCOV version 1.11