Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

XANAConfigParser.h

Go to the documentation of this file.
00001 // XANAConfigParser.h
00002 //
00003 // A class representing the configuration of the analysis program,
00004 // gathered from the configuration file and the command line
00005 //
00006 // last change : $Date: 2004/02/17 13:48:02 $
00007 // by          : $Author: koblitz $
00008 //
00009 
00010 #ifndef XANACONFIGPARSER_H
00011 #define XANACONFIGPARSER_H
00012 
00013 #include "XANADOO/XANAConfig/interface/XANAConfigFileLine.h"
00014 #include "TROOT.h"
00015 #include "TObject.h"
00016 
00017 #include <stdio.h>
00018 #include <stdexcept>
00019 #include <vector>
00020 #include <iostream>
00021 
00022 class XANAConfigParser: public TObject {
00023  public:
00024 
00025 
00026   FILE *config_file;
00027 
00028   // Constructor which does basically nothing
00029   XANAConfigParser();
00030 
00031   // Initialize configuration using the command line arguments
00032   bool init(const char *fileName=0);
00033 
00034   // Destructor: Deletes the entries in the list of configuration file lines
00035   virtual ~XANAConfigParser();
00036 
00037   // Append the option name of another ConfigFileLine as value
00038   void appendLine(XANAConfigFileLine *line);
00039   
00040   // Deletes a line from the already parsed configuration file lines
00041   bool deleteLine(const char *name, const char *scope=0);
00042 
00043   // Override an option
00044   bool overrideOption(const char *name, std::list<std::string> &values,
00045                       const char *scope=0);
00046 
00047   // Is this option defined?
00048   bool isDefined(const char *name) const;
00049 
00050   // Read Integer Option
00051   int readIntOption(const char *name) const throw(const char *);
00052 
00053   // Read Double Option
00054   double readDoubleOption(const char *name) const throw(const char *);
00055 
00056   // Read Integer Option
00057   const char *readStringOption(const char *name) const throw(const char *);
00058   
00059   // Read Integer List Option
00060   std::vector<int> readIntListOption(const char *name) const throw(const char *);
00061 
00062   // Read Double List Option
00063   std::vector<double> readDoubleListOption(const char *name) 
00064     const throw(const char *);
00065   
00066   // Read String List Option
00067   const std::list<std::string> readStringListOption(const char *name)
00068     const throw(const char *);
00069 
00070 
00071 
00072   // The following versions are to be used together with RootCINT
00073 
00075   int getOptionListSize(const char *name) const{
00076     std::string s(name);
00077     LineIterator I=configLines.begin();
00078     while (I != configLines.end()) {
00079       if((*I)->isOption(s)){
00080         return (*I)->getValues().size();
00081       }
00082       I++;
00083     }
00084     return 0;
00085   }
00086 
00087 
00092   bool readIntOption(const char *name, int &value, int entry=0) const{
00093     value=0;
00094     if(entry>=getOptionListSize(name)) return false;
00095     value=readIntListOption(name)[entry];
00096     return true;
00097   }
00098 
00099 
00104   bool readDoubleOption(const char *name, double &value, int entry=0) const{
00105     value=0;
00106     if(entry>=getOptionListSize(name)) return false;
00107     value=readDoubleListOption(name)[entry];
00108     return true;
00109   }
00110 
00111 
00117   bool readStringOption(const char *name, const char *value, int entry=0)const{
00118     if(entry>=getOptionListSize(name)) return false;
00119     const std::list<std::string> l=readStringListOption(name);
00120     std::list<std::string>::const_iterator I=l.begin();
00121     for(int i=0; i<entry; i++) I++;
00122     strcpy(value, (const char *)((*I).c_str()));
00123     return true;
00124   }
00125 
00126   // Print all options
00127   void print() const;
00128 
00129  private:
00130 
00131   std::list<XANAConfigFileLine *> configLines; 
00132   
00135   typedef std::list<XANAConfigFileLine *>::const_iterator LineIterator;
00136 
00137   ClassDef(XANAConfigParser,0) 
00138 
00139 };
00140 
00141 // Do not forget to define the global variables so that rootcint
00142 // produces the necessary stub
00143 R__EXTERN XANAConfigParser *gConfigParser;
00144 
00145 #endif // #ifndef XANACONFIGPARSER_H

Generated on Tue May 10 10:01:24 2005 for XANADOO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002