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 106 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 179 of file Defaults_Text.cc.

References read_file().

189 {
190  read_file (file);
191 }
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 194 of file Defaults_Text.cc.

References process_args(), and read_file().

206 {
207  read_file (file);
209 }
tuple argc
Definition: dir2webdir.py:38
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 304 of file Defaults_Text.cc.

References _map, ecal_dqm_sourceclient-live_cfg::cerr, mergeVDriftHistosByStation::name, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by process_args(), and read_file().

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

References ecal_dqm_sourceclient-live_cfg::cerr, mergeVDriftHistosByStation::name, and AlCaHLTBitMon_QueryRunRegistry::string.

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

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

Referenced by Defaults_Textrep().

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

References ecal_dqm_sourceclient-live_cfg::cerr, doline(), f, and prof2calltree::l.

Referenced by Defaults_Textrep().

219 {
220  // Just return if we weren't given a file.
221  if (file.size() == 0)
222  return;
223 
224  ifstream f (file.c_str());
225  if (!f.good()) {
226  cerr << "Can't open " << file << "\n";
227  abort ();
228  }
229 
230  string l;
231  while (getline (f, l)) {
232  doline (l);
233  }
234 
235  f.close ();
236 }
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 139 of file Defaults_Text.cc.

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