12 #include "PhysicsTools/FWLite/interface/dumpSTL.icc" 17 const std::string CommandLineParser::kSpaces =
" \t";
19 CommandLineParser::CommandLineParser(
const string &
usage,
unsigned int optionsType)
20 : m_argv0(
""), m_usageString(
usage), m_printOptions(
true), m_optionsType(optionsType) {
24 addOption(
"section",
kInteger,
"This section (from 1..totalSections inclusive)", 0);
25 addOption(
"maxEvents",
kInteger,
"Maximum number of events to run over (0 for whole file)", 0);
26 addOption(
"jobID",
kInteger,
"jobID given by CRAB,etc. (-1 means append nothing)", -1);
27 addOption(
"outputEvery",
kInteger,
"Output something once every N events (0 for never)", 0);
30 addOption(
"storePrepend",
kString,
"Prepend location on files starting with '/store/'");
31 addOption(
"tag",
kString,
"A 'tag' to append to output file (e.g., 'v2', etc.)");
36 addOption(
"secondaryInputFiles",
kStringVector,
"List of secondary input files (a.k.a. two-file-solution");
37 addOption(
"orderedSecondaryFiles",
kBool,
"Are the secondary files ordered?",
false);
41 cerr <<
"CommandLineParser() Error: type '" << optionsType <<
"' is not understood. Aborting." << endl;
46 bool callHelp =
false;
54 if (string::npos != where) {
61 cerr <<
"Don't understand: " <<
arg << endl;
64 else if (
arg.at(0) ==
'-') {
66 if (string::npos == where) {
68 cerr <<
"Don't understand: " <<
arg << endl;
89 cerr <<
"Don't understand: " <<
arg << endl;
93 argsVec.push_back(
arg);
95 cerr <<
"Don't understand: " <<
arg << endl;
108 cout <<
"--help - This screen" << endl
109 <<
"--noPrint - Do not print out all settings" << endl
110 <<
"--print - Print out all settings" << endl;
116 if (ignoreComments) {
123 char firstCh =
line[start1];
124 if (
'#' == firstCh) {
132 while (string::npos != current) {
134 if (string::npos !=
last) {
142 retval.push_back(
part);
145 current =
line.find_first_of(
match, current + 1);
159 if (string::npos ==
pos) {
168 if (
pos + 1 !=
line.length()) {
187 if (string::npos == nonspace) {
192 if (string::npos == space) {
203 cout <<
"------------------------------------------------------------------" << left << endl;
206 cout << endl <<
"Integer options:" << endl;
210 cout <<
" " << setw(14) << iter->first <<
" = " << setw(14) << iter->second;
219 cout << endl <<
"Double options:" << endl;
223 cout <<
" " << setw(14) << iter->first <<
" = " << setw(14) << iter->second;
232 cout << endl <<
"Bool options:" << endl;
236 cout <<
" " << setw(14) << iter->first <<
" = " << setw(14);
250 cout << endl <<
"String options:" << endl;
254 cout <<
" " << setw(14) << iter->first <<
" = ";
255 const string value =
"'" + iter->second +
"'";
256 cout << setw(14) <<
"";
265 cout << endl <<
"Integer Vector options:" << endl;
269 cout <<
" " << setw(14) << iter->first <<
" = ";
270 dumpSTL(iter->second);
280 cout << endl <<
"Double Vector options:" << endl;
284 cout <<
" " << setw(14) << iter->first <<
" = ";
285 dumpSTL(iter->second);
295 cout << endl <<
"String Vector options:" << endl;
301 cout <<
" " << setw(14) << iter->first <<
" = ";
303 cout << setw(14) <<
"" 307 dumpSTLeachEndl(iter->second, 8);
310 cout <<
"------------------------------------------------------------------" << right << endl;
316 string value =
arg.substr(where + 1);
335 integerIter->second = (
int)atof(
value.c_str());
343 doubleIter->second = atof(
value.c_str());
351 stringIter->second =
value;
359 boolIter->second = 0 != atoi(
value.c_str());
369 for (
SVecConstIter wordIter = words.begin(); words.end() != wordIter; ++wordIter) {
370 integerVecIter->second.push_back((
int)atof(wordIter->c_str()));
383 for (
SVecConstIter wordIter = words.begin(); words.end() != wordIter; ++wordIter) {
384 doubleVecIter->second.push_back(atof(wordIter->c_str()));
397 for (
SVecConstIter wordIter = words.begin(); words.end() != wordIter; ++wordIter) {
398 stringVecIter->second.push_back(*wordIter);
407 cerr <<
"CommandLineParser::SetVeriableFromString() Error: " 408 <<
"Unknown variable and internal fault. Aborting." << endl;
416 cerr <<
"file " <<
filename <<
"could not be opened" << endl;
423 if (string::npos == where) {
431 where =
line.find_first_not_of(
kSpaces, where + 1);
432 if (string::npos == where) {
439 string withspaces =
line.substr(where);
446 }
else if (
' ' == ch ||
'\t' == ch) {
452 cerr <<
"Don't understand line" << endl
454 <<
"in options file '" <<
filename <<
"'. Aborting." << endl;
464 if (2 != equalWords.size()) {
468 split(commandWords, equalWords.at(0),
"_");
469 if (2 != commandWords.size()) {
472 string &
command = commandWords.at(1);
477 const string &
key = commandWords.at(0);
480 cerr <<
"Command '" <<
command <<
"' only works on vectors." << endl;
505 const string &
filename = equalWords.at(1);
508 cerr <<
"file " <<
filename <<
"could not be opened" << endl;
515 if (string::npos == where) {
523 if (
line.length() - 1 != where) {
526 if (
'#' ==
line.at(0)) {
563 int entries = (
int)inputList.size();
564 int perSection = entries / totalSections;
565 int extra = entries % totalSections;
567 int current = perSection *
section;
568 int num = perSection - 1;
603 const string &kStorePrepend =
stringValue(
"storePrepend");
604 if (kStorePrepend.length()) {
605 string match =
"/store/";
606 int matchLen =
match.length();
609 for (
SVecConstIter iter = currentFiles.begin(); currentFiles.end() != iter; ++iter) {
612 tempVec.push_back(kStorePrepend +
filename);
617 currentFiles = tempVec;
626 bool modifyOutputFile = (
outputFile.length());
647 if (modifyOutputFile) {
bool _runVariableCommandFromString(const std::string &arg)
SIMap::const_iterator SIMapConstIter
void _getSectionFiles(const SVec &inputList, SVec &outputList, int section, int totalSection)
void _finishDefaultOptions(std::string tag="")
unsigned int m_optionsType
bool _setVariablesFromFile(const std::string &filename)
static std::string removeEnding(const std::string &input, const std::string &ending)
SDMap::const_iterator SDMapConstIter
SSMap::iterator SSMapIter
static void split(SVec &retval, std::string line, std::string match=" \, bool ignoreComments=true)
SBMap::iterator SBMapIter
std::string m_usageString
SIMap::iterator SIMapIter
std::string & stringValue(std::string key)
void parseArguments(int argc, char **argv, bool allowArgs=false)
static void removeLeadingAndTrailingSpaces(std::string &line)
ostream & operator<<(ostream &o_stream, const CommandLineParser &rhs)
SBMap::const_iterator SBMapConstIter
SIVecMap::iterator SIVecMapIter
SSVecMap::const_iterator SSVecMapConstIter
std::vector< std::string > SVec
static std::string const input
int & integerValue(std::string key)
SSMap::const_iterator SSMapConstIter
static const std::string kSpaces
SIVecMap::const_iterator SIVecMapConstIter
DVec & doubleVector(std::string key)
SBMap m_variableModifiedMap
static void lowercaseString(std::string &arg)
SSVecMap::iterator SSVecMapIter
SDVecMap::iterator SDVecMapIter
bool _setVariableFromString(const std::string &arg, bool dontOverrideChange=false, int offset=0)
SSMap m_variableDescriptionMap
bool _valueHasBeenModified(const std::string &key)
static void removeComment(std::string &line)
IVec & integerVector(std::string key)
SVec & stringVector(std::string key)
static void findCommand(const std::string &line, std::string &command, std::string &rest)
bool & boolValue(std::string key)
static int position[264][3]
void addOption(std::string key, OptionType type, const std::string &description="")
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
SDMap::iterator SDMapIter
static std::string const source
SDVecMap::const_iterator SDVecMapConstIter
SVec::const_iterator SVecConstIter
OptionType hasOption(std::string key)