CMS 3D CMS Logo

Public Member Functions | Public Attributes | Private Member Functions

hitfit::Defaults_Textrep Class Reference

The internal representation for a Defaults_Text object. More...

List of all members.

Public Member Functions

 Defaults_Textrep (string file)
 Constructor, construct a Defaults_Textrep instance from an ASCII text-file and command line arguments.
 Defaults_Textrep (string file, int argc, char **argv)
 Constructor, construct a Defaults_Textrep instance from an ASCII text-file.
string get_val (string name) const

Public Attributes

std::map< std::string,
std::string > 
_map

Private Member Functions

void doline (string l)
void process_args (int argc, char **argv)
void read_file (string file)

Detailed Description

The internal representation for a Defaults_Text object.

Definition at line 107 of file Defaults_Text.cc.


Constructor & Destructor Documentation

hitfit::Defaults_Textrep::Defaults_Textrep ( string  file)

Constructor, construct a Defaults_Textrep instance from an ASCII text-file and command line arguments.

Parameters:
fileThe name of the input ASCII file to read. See the header file for a description of the format for this and the argument list. Pass an empty string to skip reading a file.

Definition at line 180 of file Defaults_Text.cc.

References read_file().

{
  read_file (file);
}
hitfit::Defaults_Textrep::Defaults_Textrep ( string  file,
int  argc,
char **  argv 
)

Constructor, construct a Defaults_Textrep instance from an ASCII text-file.

Parameters:
fileThe name of the input ASCII file to read. See the header file for a description of the format for this and the argument list. Pass an empty string to skip reading a file.
argcThe length of the argument list.
argvThe argument list.

Definition at line 195 of file Defaults_Text.cc.

References process_args(), and read_file().


Member Function Documentation

void hitfit::Defaults_Textrep::doline ( string  l) [private]

Helper function to process a line defining a single parameter.

Parameters:
lThe line to process.

Definition at line 305 of file Defaults_Text.cc.

References _map, dtNoiseDBValidation_cfg::cerr, mergeVDriftHistosByStation::name, pos, and strip().

Referenced by process_args(), and read_file().

{
  // Strip spaces from the line and ignore it if it's blank.
  l = strip (l);
  if (l.size() == 0)
    return;

  // It must contain a `=' character.
  string::size_type pos = l.find ('=');
  if (pos == string::npos) {
    cerr << "bad defaults line " << l << "\n";
    abort ();
  }

  // Split off name and value parts.
  std::string name = strip (l.substr (0, pos));
  std::string val = strip (l.substr (pos+1));

  // Add it to the map.
  _map[name] = val;

}
string hitfit::Defaults_Textrep::get_val ( string  name) const

Look up parameter name and return its value.

Parameters:
nameThe name of the parameter.
Return:
The value of the parameter in C++ string format.

Definition at line 278 of file Defaults_Text.cc.

References dtNoiseDBValidation_cfg::cerr, and mergeVDriftHistosByStation::name.

{

    std::string val;

    if (_map.find(name) == _map.end()) {
    cerr << "can't find default for " << name << "\n";
    abort ();
    } else {
    std::map<string,string>::const_iterator it = _map.find(name);
    val = it->second;
    }

    return val;
}
void hitfit::Defaults_Textrep::process_args ( int  argc,
char **  argv 
) [private]

Look for additional parameter settings in the argument list argc and argv and add the content to data.

Parameters:
argcThe length of the argument list.
argvThe argument list.

Definition at line 240 of file Defaults_Text.cc.

References dir2webdir::argc, doline(), i, and prof2calltree::l.

Referenced by Defaults_Textrep().

{
  // Look for arguments starting with `--'.
  for (int i=1; i < argc; i++) {
    if (argv[i][0] == '-' && argv[i][1] == '-') {

      // Found one. 
      string l;
      if (strchr (argv[i], '=') != 0)
        // It was of the form `--NAME=VALUE'.  Change to `NAME=VALUE'.
        l = argv[i] + 2;
      else if (argv[i][2] == 'n' && argv[i][3] == 'o') {
        // It was of the form `--noNAME'.  Change to `NAME=0'.
        l = argv[i] + 4;
        l += "=0";
      }
      else {
        // It was of the form `--NAME'.  Change to `NAME=1'. 
        l = argv[i] + 2;
        l += "=1";
      }

      // Process it like a line we read from a file.
      doline (l);
    }
  }
}
void hitfit::Defaults_Textrep::read_file ( string  file) [private]

Read parameters from ASCII text file file and add the content to data.

Parameters:
fileThe ASCII text file to read.

Definition at line 213 of file Defaults_Text.cc.

References dtNoiseDBValidation_cfg::cerr, doline(), f, and prof2calltree::l.

Referenced by Defaults_Textrep().

{
  // Just return if we weren't given a file.
  if (file.size() == 0)
    return;

  ifstream f (file.c_str());
  if (!f.good()) {
    cerr << "Can't open " << file << "\n";
    abort ();
  }

  string l;
  while (getline (f, l)) {
    doline (l);
  }

  f.close ();
}

Member Data Documentation

std::map<std::string,std::string> hitfit::Defaults_Textrep::_map

The data, maps from parameter names to values (which are stored as strings)

Definition at line 140 of file Defaults_Text.cc.

Referenced by doline(), and hitfit::operator<<().