12 #include "PhysicsTools/FWLite/interface/dumpSTL.icc"
15 using namespace optutl;
17 const std::string CommandLineParser::kSpaces =
" \t";
20 CommandLineParser::CommandLineParser (
const string &
usage,
21 unsigned int optionsType) :
22 m_argv0(
""), m_usageString (usage),
23 m_printOptions (
true), m_optionsType (optionsType)
29 "Total number of sections",
32 "This section (from 1..totalSections inclusive)",
35 "Maximum number of events to run over (0 for whole file)",
38 "jobID given by CRAB,etc. (-1 means append nothing)",
41 "Output something once every N events (0 for never)",
48 "Prepend location on files starting with '/store/'");
50 "A 'tag' to append to output file (e.g., 'v2', etc.)");
53 "Print log name and exit");
56 "List of input files");
58 "List of secondary input files (a.k.a. two-file-solution");
60 "Are the secondary files ordered?",
65 cerr <<
"CommandLineParser() Error: type '" << optionsType
66 <<
"' is not understood. Aborting." << endl;
73 bool callHelp =
false;
82 if (string::npos != where)
92 cerr <<
"Don't understand: " << arg << endl;
95 else if (arg.at(0) ==
'-')
98 if (string::npos == where)
101 cerr <<
"Don't understand: " << arg << endl;
106 char first = arg.at (where);
125 cerr <<
"Don't understand: " << arg << endl;
130 argsVec.push_back (arg);
132 cerr <<
"Don't understand: " << arg << endl;
149 cout <<
"--help - This screen" << endl
150 <<
"--noPrint - Do not print out all settings" << endl
151 <<
"--print - Print out all settings" << endl;
169 char firstCh = line[start1];
179 while (string::npos != current)
182 if (string::npos != last)
188 string part = line.substr( pos, current - last - 1);
192 retval.push_back(part);
195 current = line.find_first_of(match, current + 1);
203 if (string::npos != location)
206 line = line.substr (0, location - 1);
214 if (string::npos == pos)
222 line = line.substr (pos);
224 pos = line.find_last_not_of (
kSpaces);
225 if (pos + 1 != line.length())
228 line = line.substr (0, pos + 1);
236 if (input.length() - ending.length() ==
position)
239 return input.substr(0, position);
252 if (string::npos == nonspace)
258 if (string::npos == space)
261 command = line.substr (nonspace);
264 command = line.substr (nonspace, space - nonspace);
265 rest = line.substr (space + 1);
273 cout <<
"------------------------------------------------------------------"
278 cout << endl <<
"Integer options:" << endl;
285 cout <<
" " << setw(14) << iter->first <<
" = " << setw(14)
287 if (description.length())
297 cout << endl <<
"Double options:" << endl;
304 cout <<
" " << setw(14) << iter->first <<
" = " << setw(14)
306 if (description.length())
316 cout << endl <<
"Bool options:" << endl;
323 cout <<
" " << setw(14) << iter->first <<
" = " << setw(14);
330 if (description.length())
340 cout << endl <<
"String options:" << endl;
347 cout <<
" " << setw(14) << iter->first <<
" = ";
348 const string value =
"'" + iter->second +
"'";
349 cout << setw(14) <<
"";
350 if (description.length())
354 cout << endl <<
" " << value << endl;
360 cout << endl <<
"Integer Vector options:" << endl;
367 cout <<
" " << setw(14) << iter->first <<
" = ";
368 dumpSTL (iter->second);
370 if (description.length())
380 cout << endl <<
"Double Vector options:" << endl;
387 cout <<
" " << setw(14) << iter->first <<
" = ";
388 dumpSTL (iter->second);
390 if (description.length())
400 cout << endl <<
"String Vector options:" << endl;
409 cout <<
" " << setw(14) << iter->first <<
" = ";
410 if (description.length())
415 dumpSTLeachEndl (iter->second, 8);
418 cout <<
"------------------------------------------------------------------"
424 bool dontOverrideChange,
428 string varname = arg.substr (offset, where - offset);
429 string value = arg.substr (where + 1);
451 integerIter->second = (int) atof( value.c_str() );
460 doubleIter->second = atof( value.c_str() );
469 stringIter->second =
value;
478 boolIter->second = 0 != atoi( value.c_str() );
488 split (words, value,
",");
490 words.end() != wordIter;
493 integerVecIter->second.push_back( (
int) atof( wordIter->c_str() ) );
506 split (words, value,
",");
508 words.end() != wordIter;
511 doubleVecIter->second.push_back( atof( wordIter->c_str() ) );
524 split (words, value,
",");
526 words.end() != wordIter;
529 stringVecIter->second.push_back( *wordIter );
538 cerr <<
"CommandLineParser::SetVeriableFromString() Error: "
539 <<
"Unknown variable and internal fault. Aborting." << endl;
550 cerr <<
"file " << filename <<
"could not be opened" << endl;
554 while (getline (
source, line))
558 if (string::npos == where)
563 char first = line.at (where);
568 where = line.find_first_not_of(
kSpaces, where + 1);
569 if (string::npos == where)
577 string withspaces = line.substr (where);
580 position < (int) withspaces.length();
588 }
else if (
' ' == ch ||
'\t' == ch)
596 cerr <<
"Don't understand line" << endl << line << endl
597 <<
"in options file '" << filename <<
"'. Aborting."
609 split (equalWords, arg,
"=");
610 if (2 != equalWords.size())
615 split (commandWords, equalWords.at(0),
"_");
616 if (2 != commandWords.size())
620 string &
command = commandWords.at(1);
622 if (command !=
"load" && command !=
"clear")
626 const string &
key = commandWords.at(0);
630 cerr <<
"Command '" << command <<
"' only works on vectors." << endl;
637 if (
"clear" == command)
645 }
else if (kStringVector == type)
659 const string &
filename = equalWords.at(1);
663 cerr <<
"file " << filename <<
"could not be opened" << endl;
667 while (getline (
source, line))
671 if (string::npos == where)
677 line = line.substr (where);
679 where = line.find_last_not_of (
kSpaces);
680 if (line.length() - 1 != where)
682 line = line.substr (0, where + 1);
684 if (
'#' == line.at(0))
695 }
else if (kStringVector == type)
710 int section,
int totalSections)
713 assert (section > 0 && section <= totalSections);
729 int entries = (int) inputList.size();
730 int perSection = entries / totalSections;
731 int extra = entries % totalSections;
733 int current = perSection * section;
734 int num = perSection - 1;
748 outputList.push_back( inputList.at(
loop ) );
779 const string &kStorePrepend =
stringValue (
"storePrepend");
780 if (kStorePrepend.length())
782 string match =
"/store/";
783 int matchLen = match.length();
787 currentFiles.end() != iter;
791 if ((
int) filename.length() > matchLen &&
792 filename.substr(0, matchLen) ==
match)
794 tempVec.push_back( kStorePrepend + filename );
796 tempVec.push_back( filename);
799 currentFiles = tempVec;
808 bool modifyOutputFile = ( outputFile.length() );
813 outputFile += Form (
"_maxevt%03d",
integerValue (
"maxEvents"));
817 outputFile += Form (
"_jobID%03d",
integerValue (
"jobID"));
829 cout << outputFile <<
".log" << endl;
832 outputFile +=
".root";
833 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
SBMap::iterator SBMapIter
std::string m_usageString
SIMap::iterator SIMapIter
std::string & stringValue(std::string key)
std::vector< std::string > SVec
void parseArguments(int argc, char **argv, bool allowArgs=false)
static void removeLeadingAndTrailingSpaces(std::string &line)
static void split(SVec &retval, std::string line, std::string match=" \t", bool ignoreComments=true)
SBMap::const_iterator SBMapConstIter
SIVecMap::iterator SIVecMapIter
outputList
All other commands ##.
SSVecMap::const_iterator SSVecMapConstIter
std::ostream & operator<<(std::ostream &out, const ALILine &li)
static int position[TOTALCHAMBERS][3]
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
unsigned int offset(bool)
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)
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
SDVecMap::const_iterator SDVecMapConstIter
SVec::const_iterator SVecConstIter
OptionType hasOption(std::string key)