Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:17

0001 //
0002 //
0003 // File: hitfit/Defaults_Text.h
0004 // Purpose: A lightweight implementation of the Defaults interface
0005 //          that uses simple text files.
0006 // Created: Jul, 2000, sss.
0007 //
0008 // Create instances of these objects passing in the name of a file.
0009 // Each line of the file should contain a parameter setting like
0010 //
0011 //   NAME = VALUE
0012 //
0013 // Anything following a `;' or `#' is stried off; leading and trailing
0014 // spaces on VALUE are also removed.  Blank lines are ignored.
0015 //
0016 // You can also pass an argument list to the constructor.  After the
0017 // defaults file is read, the argument list will be scanned, to possibly
0018 // override some of the parameter settings.  An argument of the form
0019 //
0020 //   --NAME=VALUE
0021 //
0022 // is equivalent to the parameter setting
0023 //
0024 //     NAME=VALUE
0025 //
0026 // while
0027 //
0028 //   --NAME
0029 //
0030 // is equivalent to
0031 //
0032 //   NAME=1
0033 //
0034 // and
0035 //
0036 //   --noNAME
0037 //
0038 // is equivalent to
0039 //
0040 //   NAME=0
0041 //
0042 // CMSSW File      : interface/Defaults_Text.h
0043 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
0044 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0045 //
0046 
0047 /**
0048     @file Defaults_Text.h
0049     @brief Define a concrete interface for getting parameter settings from
0050     an ASCII text file.
0051 
0052     @par Creation date:
0053     November 2000.
0054 
0055     @author
0056     Scott Stuart Snyder <snyder@bnl.gov>
0057 
0058     @par Modification History:
0059     Apr 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0060     Imported to CMSSW.<br>
0061     Oct 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0062     Added Doxygen tags for automatic generation of documentation.
0063 
0064     @par Terms of Usage:
0065     With consent from the original author (Scott Snyder).
0066  */
0067 #ifndef HITFIT_DEFAULTS_TEXT_H
0068 #define HITFIT_DEFAULTS_TEXT_H
0069 
0070 #include <string>
0071 #include <iosfwd>
0072 #include "TopQuarkAnalysis/TopHitFit/interface/Defaults.h"
0073 
0074 namespace hitfit {
0075 
0076   class Defaults_Textrep;
0077 
0078   /**
0079     @brief A lightweight implementation of the Defaults interface that
0080     uses simple ASCII text files.
0081 
0082     Create instances of these objects passing in the name of a file.
0083     Each line of the file should contain a parameter setting like
0084 
0085     <i>name</i> = <b>value</b>
0086 
0087     Anything following a `;' or `#' is stried off; leading and trailing
0088     whitespaces on <b>value</b> are also removed.  Blank lines are ignored.
0089 
0090     User can also pass an argument list to the constructor.  After the default
0091     ASCII input file is read, the argument list will be scanned, to possibly
0092     override some of the parameter settings.  An argument of the form
0093 
0094     <i>--name=value</i>
0095 
0096     is equivalent to the parameter setting
0097 
0098     <i>name</i> = <b>value</b>
0099 
0100     while
0101 
0102     <i>--name</i>
0103 
0104     is equivalent to
0105 
0106     <i>name</i> = <b>1</b>
0107 
0108     and
0109 
0110     <i>--noname</i>
0111 
0112     is equivalent to
0113 
0114     <i>name</i> = <b>0</b>.
0115 
0116  */
0117   class Defaults_Text : public Defaults
0118   //
0119   // Purpose: A lightweight implementation of the Defaults interface
0120   //          that uses simple text files.
0121   //
0122   {
0123   public:
0124     // Constructor, destructor.
0125 
0126     /**
0127      @brief Constructor, create a Default_Text object from an ASCII text
0128      file. Pass an empty string to skip reading a file.
0129      @param def_file The ASCII text file to read.  Pass an empty string
0130      to skip reading a file.
0131    */
0132     Defaults_Text(std::string def_file);
0133 
0134     /**
0135      @brief Constructor, create a Default_Text object from an ASCII text
0136      file and argument list.
0137      @param def_file The ASCII text file to read.  Pass an empty string
0138      to skip reading a file.
0139      @param argc The length of the argument list.
0140      @param argv The argument list.
0141    */
0142     Defaults_Text(std::string def_file, int argc, char** argv);
0143 
0144     /**
0145     @brief Destructor.
0146   */
0147     ~Defaults_Text() override;
0148 
0149     // Test to see if parameter NAME exists.
0150     /**
0151      Test to see if parameter <i>name</i> exists.
0152      @param name The name of the parameter.
0153      @par Return:
0154      <b>true</b> if the parameter exists.<br>
0155      <b>false</b> if the parameter does not exist.<br>
0156    */
0157     bool exists(std::string name) const override;
0158 
0159     // Get the value of NAME as an integer.
0160     /**
0161      Get the value of <i>name</i> as integer.
0162      @param name The name of the parameter.
0163      @par Return:
0164      The value of the parameter an integer (C/C++ int).
0165    */
0166     int get_int(std::string name) const override;
0167 
0168     // Get the value of NAME as a boolean.
0169     /**
0170      Get the value of <i>name</i> as boolean.
0171      @param name The name of the parameter.
0172      @par Return:
0173      The value of the parameter a C/C++ bool.
0174    */
0175     bool get_bool(std::string name) const override;
0176 
0177     // Get the value of NAME as a float.
0178     /**
0179      Get the value of <i>name</i> as a floating-point of
0180      type double.
0181      @param name The name of the parameter.
0182      @par Return:
0183      The value of the parameter as a floating-point number (C/C++ double).
0184   */
0185     double get_float(std::string name) const override;
0186 
0187     // Get the value of NAME as a string.
0188     /**
0189      Get the value of <i>name</i> as a string.
0190      @param name The name of the parameter.
0191      @par Return:
0192      The value of the parameter as a string.
0193    */
0194     std::string get_string(std::string name) const override;
0195 
0196     // Dump out all parameters.
0197     /**
0198      Output stream operator.  Print out all parameters' names and their
0199      values.
0200      @param s The output stream to write.
0201      @param def The instance to print.
0202      @par Return:
0203      The output stream <i>s</i>
0204    */
0205     friend std::ostream& operator<<(std::ostream& s, const Defaults_Text& def);
0206 
0207   private:
0208     // The internal representation.
0209     /**
0210      The internal representation.
0211    */
0212     Defaults_Textrep* _rep;
0213   };
0214 
0215 }  // namespace hitfit
0216 
0217 #endif  // not HITFIT_DEFAULTS_TEXT_H