CMS 3D CMS Logo

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

Constructor & Destructor Documentation

◆ Defaults_Textrep() [1/2]

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

References geometryDiff::file, and read_file().

183  {
184  read_file(file);
185  }
void read_file(string file)

◆ Defaults_Textrep() [2/2]

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

References dir2webdir::argc, GCPpyPlots::argv, geometryDiff::file, process_args(), and read_file().

199  {
200  read_file(file);
202  }
void process_args(int argc, char **argv)
void read_file(string file)

Member Function Documentation

◆ doline()

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

References _map, DMR_cfg::cerr, cmsLHEtoEOSManager::l, Skims_PA_cff::name, AlCaHLTBitMon_QueryRunRegistry::string, digitizers_cfi::strip, and heppy_batch::val.

Referenced by process_args(), and read_file().

297  {
298  // Strip spaces from the line and ignore it if it's blank.
299  l = strip(l);
300  if (l.empty())
301  return;
302 
303  // It must contain a `=' character.
304  string::size_type pos = l.find('=');
305  if (pos == string::npos) {
306  cerr << "bad defaults line " << l << "\n";
307  abort();
308  }
309 
310  // Split off name and value parts.
311  std::string name = strip(l.substr(0, pos));
312  std::string val = strip(l.substr(pos + 1));
313 
314  // Add it to the map.
315  _map[name] = val;
316  }
uint16_t size_type
std::map< std::string, std::string > _map

◆ get_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 265 of file Defaults_Text.cc.

References DMR_cfg::cerr, Skims_PA_cff::name, AlCaHLTBitMon_QueryRunRegistry::string, and heppy_batch::val.

276  {
278 
279  if (_map.find(name) == _map.end()) {
280  cerr << "can't find default for " << name << "\n";
281  abort();
282  } else {
283  std::map<string, string>::const_iterator it = _map.find(name);
284  val = it->second;
285  }
286 
287  return val;
288  }
std::map< std::string, std::string > _map

◆ process_args()

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

References dir2webdir::argc, GCPpyPlots::argv, doline(), mps_fire::i, and cmsLHEtoEOSManager::l.

Referenced by Defaults_Textrep().

240  {
241  // Look for arguments starting with `--'.
242  for (int i = 1; i < argc; i++) {
243  if (argv[i][0] == '-' && argv[i][1] == '-') {
244  // Found one.
245  string l;
246  if (strchr(argv[i], '=') != nullptr)
247  // It was of the form `--NAME=VALUE'. Change to `NAME=VALUE'.
248  l = argv[i] + 2;
249  else if (argv[i][2] == 'n' && argv[i][3] == 'o') {
250  // It was of the form `--noNAME'. Change to `NAME=0'.
251  l = argv[i] + 4;
252  l += "=0";
253  } else {
254  // It was of the form `--NAME'. Change to `NAME=1'.
255  l = argv[i] + 2;
256  l += "=1";
257  }
258 
259  // Process it like a line we read from a file.
260  doline(l);
261  }
262  }
263  }

◆ read_file()

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

References DMR_cfg::cerr, doline(), f, geometryDiff::file, and cmsLHEtoEOSManager::l.

Referenced by Defaults_Textrep().

211  {
212  // Just return if we weren't given a file.
213  if (file.empty())
214  return;
215 
216  ifstream f(file.c_str());
217  if (!f.good()) {
218  cerr << "Can't open " << file << "\n";
219  abort();
220  }
221 
222  string l;
223  while (getline(f, l)) {
224  doline(l);
225  }
226 
227  f.close();
228  }
double f[11][100]

Member Data Documentation

◆ _map

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

Referenced by doline().