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.

183  {
184  read_file(file);
185  }

References geometryDiff::file, and read_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.

199  {
200  read_file(file);
202  }

References dir2webdir::argc, cmsBatch::argv, geometryDiff::file, process_args(), and read_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.

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  }

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

Referenced by process_args(), and read_file().

◆ 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.

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  }

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

◆ 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.

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  }

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

Referenced by Defaults_Textrep().

◆ 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.

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  }

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

Referenced by Defaults_Textrep().

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

cmsBatch.argv
argv
Definition: cmsBatch.py:279
mps_fire.i
i
Definition: mps_fire.py:428
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
dir2webdir.argc
argc
Definition: dir2webdir.py:39
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
pos
Definition: PixelAliasList.h:18
hitfit::Defaults_Textrep::process_args
void process_args(int argc, char **argv)
Definition: Defaults_Text.cc:230
hitfit::Defaults_Textrep::doline
void doline(string l)
Definition: Defaults_Text.cc:290
hitfit::Defaults_Textrep::read_file
void read_file(string file)
Definition: Defaults_Text.cc:204
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
geometryDiff.file
file
Definition: geometryDiff.py:13
hitfit::Defaults_Textrep::_map
std::map< std::string, std::string > _map
Definition: Defaults_Text.cc:135
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
heppy_batch.val
val
Definition: heppy_batch.py:351
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8