CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Member Functions
hitfit::Defaults_Textrep Class Reference

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

Public Member Functions

 Defaults_Textrep (string file)
 Constructor, construct a Defaults_Textrep instance from an ASCII text-file and command line arguments. More...
 
 Defaults_Textrep (string file, int argc, char **argv)
 Constructor, construct a Defaults_Textrep instance from an ASCII text-file. More...
 
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().

190 {
191  read_file (file);
192 }
void read_file(string 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().

207 {
208  read_file (file);
210 }
tuple argc
Definition: dir2webdir.py:41
void process_args(int argc, char **argv)
void read_file(string 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().

312 {
313  // Strip spaces from the line and ignore it if it's blank.
314  l = strip (l);
315  if (l.size() == 0)
316  return;
317 
318  // It must contain a `=' character.
319  string::size_type pos = l.find ('=');
320  if (pos == string::npos) {
321  cerr << "bad defaults line " << l << "\n";
322  abort ();
323  }
324 
325  // Split off name and value parts.
326  std::string name = strip (l.substr (0, pos));
327  std::string val = strip (l.substr (pos+1));
328 
329  // Add it to the map.
330  _map[name] = val;
331 
332 }
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
std::map< std::string, std::string > _map
uint16_t size_type
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.

289 {
290 
291  std::string val;
292 
293  if (_map.find(name) == _map.end()) {
294  cerr << "can't find default for " << name << "\n";
295  abort ();
296  } else {
297  std::map<string,string>::const_iterator it = _map.find(name);
298  val = it->second;
299  }
300 
301  return val;
302 }
std::map< std::string, std::string > _map
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().

250 {
251  // Look for arguments starting with `--'.
252  for (int i=1; i < argc; i++) {
253  if (argv[i][0] == '-' && argv[i][1] == '-') {
254 
255  // Found one.
256  string l;
257  if (strchr (argv[i], '=') != 0)
258  // It was of the form `--NAME=VALUE'. Change to `NAME=VALUE'.
259  l = argv[i] + 2;
260  else if (argv[i][2] == 'n' && argv[i][3] == 'o') {
261  // It was of the form `--noNAME'. Change to `NAME=0'.
262  l = argv[i] + 4;
263  l += "=0";
264  }
265  else {
266  // It was of the form `--NAME'. Change to `NAME=1'.
267  l = argv[i] + 2;
268  l += "=1";
269  }
270 
271  // Process it like a line we read from a file.
272  doline (l);
273  }
274  }
275 }
int i
Definition: DBlmapReader.cc:9
tuple argc
Definition: dir2webdir.py:41
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().

220 {
221  // Just return if we weren't given a file.
222  if (file.size() == 0)
223  return;
224 
225  ifstream f (file.c_str());
226  if (!f.good()) {
227  cerr << "Can't open " << file << "\n";
228  abort ();
229  }
230 
231  string l;
232  while (getline (f, l)) {
233  doline (l);
234  }
235 
236  f.close ();
237 }
double f[11][100]

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<<().