test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends
optutl::CommandLineParser Class Reference

#include <CommandLineParser.h>

Inheritance diagram for optutl::CommandLineParser:
optutl::VariableMapCont

Public Types

enum  { kEventContOpt = 1 << 0 }
 
- Public Types inherited from optutl::VariableMapCont
typedef std::vector< double > DVec
 
typedef DVec::const_iterator DVecConstIter
 
typedef DVec::iterator DVecIter
 
typedef std::vector< int > IVec
 
typedef IVec::const_iterator IVecConstIter
 
typedef IVec::iterator IVecIter
 
enum  OptionType {
  kNone = 0, kInteger, kDouble, kString,
  kBool, kIntegerVector, kDoubleVector, kStringVector,
  kNumOptionTypes
}
 
typedef std::map< std::string,
bool > 
SBMap
 
typedef SBMap::const_iterator SBMapConstIter
 
typedef SBMap::iterator SBMapIter
 
typedef std::map< std::string,
double > 
SDMap
 
typedef SDMap::const_iterator SDMapConstIter
 
typedef SDMap::iterator SDMapIter
 
typedef std::map< std::string,
DVec
SDVecMap
 
typedef SDVecMap::const_iterator SDVecMapConstIter
 
typedef SDVecMap::iterator SDVecMapIter
 
typedef std::map< std::string,
int > 
SIMap
 
typedef SIMap::const_iterator SIMapConstIter
 
typedef SIMap::iterator SIMapIter
 
typedef std::map< std::string,
IVec
SIVecMap
 
typedef SIVecMap::const_iterator SIVecMapConstIter
 
typedef SIVecMap::iterator SIVecMapIter
 
typedef std::map< std::string,
std::string > 
SSMap
 
typedef SSMap::const_iterator SSMapConstIter
 
typedef SSMap::iterator SSMapIter
 
typedef std::map< std::string,
SVec
SSVecMap
 
typedef SSVecMap::const_iterator SSVecMapConstIter
 
typedef SSVecMap::iterator SSVecMapIter
 
typedef std::vector< std::string > SVec
 
typedef SVec::const_iterator SVecConstIter
 
typedef SVec::iterator SVecIter
 

Public Member Functions

void _finishDefaultOptions (std::string tag="")
 
const SVec argVec () const
 
 CommandLineParser (const std::string &usage, unsigned int optionsType=kEventContOpt)
 
void help ()
 
void parseArguments (int argc, char **argv, bool allowArgs=false)
 
void printOptionValues ()
 
void setPrintOptoins (bool print)
 
- Public Member Functions inherited from optutl::VariableMapCont
void _checkKey (std::string &key, const std::string &description="")
 
void addOption (std::string key, OptionType type, const std::string &description="")
 
void addOption (std::string key, OptionType type, const std::string &description, int defaultValue)
 
void addOption (std::string key, OptionType type, const std::string &description, double defaultValue)
 
void addOption (std::string key, OptionType type, const std::string &description, const std::string &defaultValue)
 
void addOption (std::string key, OptionType type, const std::string &description, const char *defaultValue)
 
void addOption (std::string key, OptionType type, const std::string &description, bool defaultValue)
 
void addVariable (std::string key, OptionType type)
 
void addVariable (std::string key, OptionType type, int defaultValue)
 
void addVariable (std::string key, OptionType type, double defaultValue)
 
void addVariable (std::string key, OptionType type, const std::string &defaultValue)
 
void addVariable (std::string key, OptionType type, const char *defaultValue)
 
void addVariable (std::string key, OptionType type, bool defaultValue)
 
bool & boolValue (std::string key)
 
double & doubleValue (std::string key)
 
DVecdoubleVector (std::string key)
 
OptionType hasOption (std::string key)
 
OptionType hasVariable (std::string key)
 
void help ()
 
int & integerValue (std::string key)
 
IVecintegerVector (std::string key)
 
std::string & stringValue (std::string key)
 
SVecstringVector (std::string key)
 
 VariableMapCont ()
 

Static Public Member Functions

static void findCommand (const std::string &line, std::string &command, std::string &rest)
 
static void removeComment (std::string &line)
 
static std::string removeEnding (const std::string &input, const std::string &ending)
 
static void removeLeadingAndTrailingSpaces (std::string &line)
 
static void split (SVec &retval, std::string line, std::string match=" \t", bool ignoreComments=true)
 
- Static Public Member Functions inherited from optutl::VariableMapCont
static void lowercaseString (std::string &arg)
 
static char toLower (char &ch)
 

Static Public Attributes

static const std::string kSpaces = " \t"
 
- Static Public Attributes inherited from optutl::VariableMapCont
static const bool kDefaultBool = false
 
static const double kDefaultDouble = 0.
 
static const int kDefaultInteger = 0
 
static const std::string kDefaultString = ""
 
static const DVec kEmptyDVec
 
static const IVec kEmptyIVec
 
static const SVec kEmptySVec
 

Private Member Functions

void _getSectionFiles (const SVec &inputList, SVec &outputList, int section, int totalSection)
 
bool _runVariableCommandFromString (const std::string &arg)
 
bool _setVariableFromString (const std::string &arg, bool dontOverrideChange=false, int offset=0)
 
bool _setVariablesFromFile (const std::string &filename)
 

Private Attributes

std::string m_argv0
 
SVec m_fullArgVec
 
unsigned int m_optionsType
 
bool m_printOptions
 
std::string m_usageString
 

Friends

std::ostream & operator<< (std::ostream &o_stream, const CommandLineParser &rhs)
 

Additional Inherited Members

- Protected Member Functions inherited from optutl::VariableMapCont
bool _valueHasBeenModified (const std::string &key)
 
- Protected Attributes inherited from optutl::VariableMapCont
SBMap m_boolMap
 
SDMap m_doubleMap
 
SDVecMap m_doubleVecMap
 
SIMap m_integerMap
 
SIVecMap m_integerVecMap
 
SSMap m_stringMap
 
SSVecMap m_stringVecMap
 
SSMap m_variableDescriptionMap
 
SBMap m_variableModifiedMap
 

Detailed Description

Definition at line 11 of file CommandLineParser.h.

Member Enumeration Documentation

anonymous enum
Enumerator
kEventContOpt 

Definition at line 20 of file CommandLineParser.h.

Constructor & Destructor Documentation

CommandLineParser::CommandLineParser ( const std::string &  usage,
unsigned int  optionsType = kEventContOpt 
)

Definition at line 20 of file CommandLineParser.cc.

References optutl::VariableMapCont::addOption(), dtNoiseDBValidation_cfg::cerr, optutl::VariableMapCont::kBool, kEventContOpt, optutl::VariableMapCont::kInteger, optutl::VariableMapCont::kString, optutl::VariableMapCont::kStringVector, and m_optionsType.

21  :
22  m_argv0(""), m_usageString (usage),
23  m_printOptions (true), m_optionsType (optionsType)
24 {
26  {
27  // Integer options
28  addOption ("totalSections", kInteger,
29  "Total number of sections",
30  0);
31  addOption ("section", kInteger,
32  "This section (from 1..totalSections inclusive)",
33  0);
34  addOption ("maxEvents", kInteger,
35  "Maximum number of events to run over (0 for whole file)",
36  0);
37  addOption ("jobID", kInteger,
38  "jobID given by CRAB,etc. (-1 means append nothing)",
39  -1);
40  addOption ("outputEvery", kInteger,
41  "Output something once every N events (0 for never)",
42  0);
43  // String options
44  addOption ("outputFile", kString,
45  "Output filename",
46  "output.root");
47  addOption ("storePrepend", kString,
48  "Prepend location on files starting with '/store/'");
49  addOption ("tag", kString,
50  "A 'tag' to append to output file (e.g., 'v2', etc.)");
51  // Bool options
52  addOption ("logName", kBool,
53  "Print log name and exit");
54  // String vector options
55  addOption ("inputFiles", kStringVector,
56  "List of input files");
57  addOption ("secondaryInputFiles", kStringVector,
58  "List of secondary input files (a.k.a. two-file-solution");
59  addOption ("orderedSecondaryFiles", kBool,
60  "Are the secondary files ordered?",
61  false );
62  return;
63  }
64  // If we're still here, we have a type I don't understand.
65  cerr << "CommandLineParser() Error: type '" << optionsType
66  << "' is not understood. Aborting." << endl;
67  assert (0);
68 }
void addOption(std::string key, OptionType type, const std::string &description="")
void usage()
Definition: array2xmlEB.cc:14

Member Function Documentation

void CommandLineParser::_finishDefaultOptions ( std::string  tag = "")

Definition at line 753 of file CommandLineParser.cc.

References _getSectionFiles(), optutl::VariableMapCont::boolValue(), gather_cfg::cout, cmsRelvalreport::exit, lut2db_cfg::filename, optutl::VariableMapCont::integerValue(), getDQMSummary::iter, kEventContOpt, m_optionsType, m_printOptions, match(), download_sqlite_cfg::outputFile, printOptionValues(), removeEnding(), optutl::VariableMapCont::stringValue(), optutl::VariableMapCont::stringVector(), and GlobalPosition_Frontier_DevDB_cff::tag.

Referenced by fwlite::EventContainer::EventContainer().

754 {
756  {
757  // nothing to see here, folks
758  return;
759  }
761  // Deal with sections //
763  if ( integerValue ("totalSections") )
764  {
765  // we have a request to break this into sections. First, note
766  // this in the output file
767  tag += Form ("_sec%03d", integerValue ("section"));
768  SVec tempVec;
769  _getSectionFiles ( stringVector ("inputFiles"),
770  tempVec,
771  integerValue ("section"),
772  integerValue ("totalSections") );
773  stringVector ("inputFiles") = tempVec;
774  } // if section requested
775 
777  // Store lfn to pfn //
779  const string &kStorePrepend = stringValue ("storePrepend");
780  if (kStorePrepend.length())
781  {
782  string match = "/store/";
783  int matchLen = match.length();
784  SVec tempVec;
785  SVec &currentFiles = stringVector ("inputFiles");
786  for (SVecConstIter iter = currentFiles.begin();
787  currentFiles.end() != iter;
788  ++iter)
789  {
790  const string &filename = *iter;
791  if ((int) filename.length() > matchLen &&
792  filename.substr(0, matchLen) == match)
793  {
794  tempVec.push_back( kStorePrepend + filename );
795  } else {
796  tempVec.push_back( filename);
797  }
798  }
799  currentFiles = tempVec;
800  } // if storePrepend.
801 
803  // //////////////////////////// //
804  // // Modify output filename // //
805  // //////////////////////////// //
807  string outputFile = stringValue ("outputFile");
808  bool modifyOutputFile = ( outputFile.length() );
809  outputFile = removeEnding (outputFile, ".root");
810  outputFile += tag;
811  if ( integerValue ("maxEvents") )
812  {
813  outputFile += Form ("_maxevt%03d", integerValue ("maxEvents"));
814  }
815  if ( integerValue ("jobID") >= 0)
816  {
817  outputFile += Form ("_jobID%03d", integerValue ("jobID"));
818  }
819  if ( stringValue ("tag").length() )
820  {
821  outputFile += "_" + stringValue ("tag");
822  }
823 
825  // Log File Name, if requested //
827  if ( boolValue ("logName") )
828  {
829  cout << outputFile << ".log" << endl;
830  exit(0);
831  }
832  outputFile += ".root";
833  if (modifyOutputFile)
834  {
835  stringValue ("outputFile") = outputFile;
836  }
837 
838  // finally, if they asked us to print all options, let's do so
839  // after we've modified all variables appropriately
840  if (m_printOptions)
841  {
843  } // if printOptions
844 }
void _getSectionFiles(const SVec &inputList, SVec &outputList, int section, int totalSection)
static std::string removeEnding(const std::string &input, const std::string &ending)
std::string & stringValue(std::string key)
std::vector< std::string > SVec
int & integerValue(std::string key)
SVec & stringVector(std::string key)
bool & boolValue(std::string key)
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
SVec::const_iterator SVecConstIter
void CommandLineParser::_getSectionFiles ( const SVec inputList,
SVec outputList,
int  section,
int  totalSection 
)
private

Definition at line 709 of file CommandLineParser.cc.

References cond::rpcobimon::current, python.tagInventory::entries, cmsHarvester::loop, and pileupDistInMC::num.

Referenced by _finishDefaultOptions().

711 {
712  // Make sure the segment numbers make sense
713  assert (section > 0 && section <= totalSections);
714 
715  // The Perl code:
716  // my $entries = @list;
717  // my $perSection = int ($entries / $totalSections);
718  // my $extra = $entries % $totalSections;
719  // --$section; # we want 0..n-1 not 1..n
720  // my $start = $perSection * $section;
721  // my $num = $perSection - 1;
722  // if ($section < $extra) {
723  // $start += $section;
724  // ++$num;
725  // } else {
726  // $start += $extra;
727  // };
728  // my $end = $start + $num;
729  int entries = (int) inputList.size();
730  int perSection = entries / totalSections;
731  int extra = entries % totalSections;
732  --section; // we want 0..n-1, not 1..n.
733  int current = perSection * section;
734  int num = perSection - 1;
735  if (section < extra)
736  {
737  current += section;
738  ++num;
739  } else
740  {
741  current += extra;
742  }
743  outputList.clear();
744  // we want to go from 0 to num inclusive, so make sure we have '<='
745  // and not '='
746  for (int loop = current; loop <= current + num; ++loop)
747  {
748  outputList.push_back( inputList.at( loop ) );
749  } // for loop
750 }
outputList
All other commands ##.
Definition: compareJSON.py:62
int loop
CMSSW
bool CommandLineParser::_runVariableCommandFromString ( const std::string &  arg)
private

Definition at line 606 of file CommandLineParser.cc.

References dtNoiseDBValidation_cfg::cerr, edmPickEvents::command, optutl::VariableMapCont::doubleVector(), lut2db_cfg::filename, optutl::VariableMapCont::hasOption(), recoMuon::in, optutl::VariableMapCont::integerVector(), optutl::VariableMapCont::kDoubleVector, combine::key, optutl::VariableMapCont::kIntegerVector, kSpaces, optutl::VariableMapCont::kStringVector, geometryCSVtoXML::line, optutl::VariableMapCont::lowercaseString(), source, split(), and optutl::VariableMapCont::stringVector().

Referenced by parseArguments().

607 {
608  SVec equalWords;
609  split (equalWords, arg, "=");
610  if (2 != equalWords.size())
611  {
612  return false;
613  }
614  SVec commandWords;
615  split (commandWords, equalWords.at(0), "_");
616  if (2 != commandWords.size())
617  {
618  return false;
619  }
620  string &command = commandWords.at(1);
621  lowercaseString (command);
622  if (command != "load" && command != "clear")
623  {
624  return false;
625  }
626  const string &key = commandWords.at(0);
627  OptionType type = hasOption (key);
629  {
630  cerr << "Command '" << command << "' only works on vectors." << endl;
631  return false;
632  }
633 
635  // Clear //
637  if ("clear" == command)
638  {
639  if (kIntegerVector == type)
640  {
641  integerVector(key).clear();
642  } else if (kDoubleVector == type)
643  {
644  doubleVector(key).clear();
645  } else if (kStringVector == type)
646  {
647  stringVector(key).clear();
648  } else {
649  // If we're here, then I made a coding mistake and want to
650  // know about it.
651  assert (0);
652  }
653  return true;
654  }
655 
657  // Load //
659  const string &filename = equalWords.at(1);
660  ifstream source (filename.c_str(), ios::in);
661  if (! source)
662  {
663  cerr << "file " << filename << "could not be opened" << endl;
664  return false;
665  }
666  string line;
667  while (getline (source, line))
668  {
669  // find the first nonspace
670  string::size_type where = line.find_first_not_of (kSpaces);
671  if (string::npos == where)
672  {
673  // no non-spaces
674  continue;
675  }
676  // get rid of leading spaces
677  line = line.substr (where);
678  // get rid of trailing spaces
679  where = line.find_last_not_of (kSpaces);
680  if (line.length() - 1 != where)
681  {
682  line = line.substr (0, where + 1);
683  }
684  if ('#' == line.at(0))
685  {
686  // this is a comment line, ignore it
687  continue;
688  }
689  if (kIntegerVector == type)
690  {
691  integerVector(key).push_back( (int) atof( line.c_str() ) );
692  } else if (kDoubleVector == type)
693  {
694  doubleVector(key).push_back( atof( line.c_str() ) );
695  } else if (kStringVector == type)
696  {
697  stringVector(key).push_back( line );
698  } else {
699  // If we're here, then I made a coding mistake and want to
700  // know about it.
701  assert (0);
702  }
703  } // while getline
704  return true;
705 
706 }
type
Definition: HCALResponse.h:21
std::vector< std::string > SVec
static void split(SVec &retval, std::string line, std::string match=" \t", bool ignoreComments=true)
uint16_t size_type
A arg
Definition: Factorize.h:36
static const std::string kSpaces
DVec & doubleVector(std::string key)
static void lowercaseString(std::string &arg)
IVec & integerVector(std::string key)
SVec & stringVector(std::string key)
list key
Definition: combine.py:13
tuple filename
Definition: lut2db_cfg.py:20
static std::string const source
Definition: EdmProvDump.cc:43
OptionType hasOption(std::string key)
bool CommandLineParser::_setVariableFromString ( const std::string &  arg,
bool  dontOverrideChange = false,
int  offset = 0 
)
private

Definition at line 423 of file CommandLineParser.cc.

References optutl::VariableMapCont::_valueHasBeenModified(), dtNoiseDBValidation_cfg::cerr, optutl::VariableMapCont::lowercaseString(), optutl::VariableMapCont::m_boolMap, optutl::VariableMapCont::m_doubleMap, optutl::VariableMapCont::m_doubleVecMap, optutl::VariableMapCont::m_integerMap, optutl::VariableMapCont::m_integerVecMap, optutl::VariableMapCont::m_stringMap, optutl::VariableMapCont::m_stringVecMap, optutl::VariableMapCont::m_variableModifiedMap, split(), and relativeConstraints::value.

Referenced by _setVariablesFromFile(), and parseArguments().

426 {
427  string::size_type where = arg.find_first_of("=", offset + 1);
428  string varname = arg.substr (offset, where - offset);
429  string value = arg.substr (where + 1);
430  lowercaseString (varname);
431  // check to make sure this is a valid option
432  SBMapConstIter sbiter = m_variableModifiedMap.find (varname);
433  if (m_variableModifiedMap.end() == sbiter)
434  {
435  // Not found. Not a valid option
436  return false;
437  }
438  // if 'dontOverrideChange' is set, then we are being asked to NOT
439  // change any variables that have already been changed.
440  if (dontOverrideChange && _valueHasBeenModified (varname) )
441  {
442  // don't go any further
443  return true;
444  }
445  // integers
446  SIMapIter integerIter = m_integerMap.find(varname);
447  if (m_integerMap.end() != integerIter)
448  {
449  // we found it
450  // use 'atof' instead of 'atoi' to get scientific notation
451  integerIter->second = (int) atof( value.c_str() );
452  m_variableModifiedMap[varname] = true;
453  return true;
454  }
455  // double
456  SDMapIter doubleIter = m_doubleMap.find(varname);
457  if (m_doubleMap.end() != doubleIter)
458  {
459  // we found it
460  doubleIter->second = atof( value.c_str() );
461  m_variableModifiedMap[varname] = true;
462  return true;
463  }
464  // string
465  SSMapIter stringIter = m_stringMap.find(varname);
466  if (m_stringMap.end() != stringIter)
467  {
468  // we found it
469  stringIter->second = value;
470  m_variableModifiedMap[varname] = true;
471  return true;
472  }
473  // bool
474  SBMapIter boolIter = m_boolMap.find(varname);
475  if (m_boolMap.end() != boolIter)
476  {
477  // we found it
478  boolIter->second = 0 != atoi( value.c_str() );
479  m_variableModifiedMap[varname] = true;
480  return true;
481  }
482  // IntegerVec
483  SIVecMapIter integerVecIter = m_integerVecMap.find(varname);
484  if (m_integerVecMap.end() != integerVecIter)
485  {
486  // we found it
487  SVec words;
488  split (words, value, ",");
489  for (SVecConstIter wordIter = words.begin();
490  words.end() != wordIter;
491  ++wordIter)
492  {
493  integerVecIter->second.push_back( (int) atof( wordIter->c_str() ) );
494  }
495  // we don't want to mark this as modified because we can add
496  // many values to this
497  // m_variableModifiedMap[varname] = true;
498  return true;
499  }
500  // DoubleVec
501  SDVecMapIter doubleVecIter = m_doubleVecMap.find(varname);
502  if (m_doubleVecMap.end() != doubleVecIter)
503  {
504  // we found it
505  SVec words;
506  split (words, value, ",");
507  for (SVecConstIter wordIter = words.begin();
508  words.end() != wordIter;
509  ++wordIter)
510  {
511  doubleVecIter->second.push_back( atof( wordIter->c_str() ) );
512  }
513  // we don't want to mark this as modified because we can add
514  // many values to this
515  // m_variableModifiedMap[varname] = true;
516  return true;
517  }
518  // StringVec
519  SSVecMapIter stringVecIter = m_stringVecMap.find(varname);
520  if (m_stringVecMap.end() != stringVecIter)
521  {
522  // we found it
523  SVec words;
524  split (words, value, ",");
525  for (SVecConstIter wordIter = words.begin();
526  words.end() != wordIter;
527  ++wordIter)
528  {
529  stringVecIter->second.push_back( *wordIter );
530  }
531  // we don't want to mark this as modified because we can add
532  // many values to this
533  // m_variableModifiedMap[varname] = true;
534  return true;
535  }
536  // We didn't find your variable. And we really shouldn't be here
537  // because we should have know that we didn't find your variable.
538  cerr << "CommandLineParser::SetVeriableFromString() Error: "
539  << "Unknown variable and internal fault. Aborting." << endl;
540  assert (0);
541  return false;
542 }
SSMap::iterator SSMapIter
SBMap::iterator SBMapIter
SIMap::iterator SIMapIter
std::vector< std::string > SVec
static void split(SVec &retval, std::string line, std::string match=" \t", bool ignoreComments=true)
SBMap::const_iterator SBMapConstIter
SIVecMap::iterator SIVecMapIter
uint16_t size_type
A arg
Definition: Factorize.h:36
static void lowercaseString(std::string &arg)
SSVecMap::iterator SSVecMapIter
unsigned int offset(bool)
SDVecMap::iterator SDVecMapIter
bool _valueHasBeenModified(const std::string &key)
SDMap::iterator SDMapIter
SVec::const_iterator SVecConstIter
bool CommandLineParser::_setVariablesFromFile ( const std::string &  filename)
private

Definition at line 545 of file CommandLineParser.cc.

References _setVariableFromString(), dtNoiseDBValidation_cfg::cerr, cmsRelvalreport::exit, first, recoMuon::in, kSpaces, geometryCSVtoXML::line, position, and source.

546 {
547  ifstream source (filename.c_str(), ios::in);
548  if (! source)
549  {
550  cerr << "file " << filename << "could not be opened" << endl;
551  return false;
552  }
553  string line;
554  while (getline (source, line))
555  {
556  // find the first nonspace
557  string::size_type where = line.find_first_not_of(kSpaces);
558  if (string::npos == where)
559  {
560  // no non-spaces
561  continue;
562  }
563  char first = line.at (where);
564  if ('-' != first)
565  {
566  continue;
567  }
568  where = line.find_first_not_of(kSpaces, where + 1);
569  if (string::npos == where)
570  {
571  // no non-spaces
572  continue;
573  }
574  // Get string starting at first nonspace after '-'. Copy it to
575  // another string without copying any spaces and stopping at the
576  // first '#'.
577  string withspaces = line.substr (where);
578  string nospaces;
579  for (int position = 0;
580  position < (int) withspaces.length();
581  ++position)
582  {
583  char ch = withspaces[position];
584  if ('#' == ch)
585  {
586  // start of a comment
587  break;
588  } else if (' ' == ch || '\t' == ch)
589  {
590  continue;
591  }
592  nospaces += ch;
593  } // for position
594  if (! _setVariableFromString (nospaces, true) )
595  {
596  cerr << "Don't understand line" << endl << line << endl
597  << "in options file '" << filename << "'. Aborting."
598  << endl;
599  exit(0);
600  } // if setting variable failed
601  } // while getline
602  return true;
603 }
uint16_t size_type
static const std::string kSpaces
bool first
Definition: L1TdeRCT.cc:75
bool _setVariableFromString(const std::string &arg, bool dontOverrideChange=false, int offset=0)
static int position[264][3]
Definition: ReadPGInfo.cc:509
tuple filename
Definition: lut2db_cfg.py:20
static std::string const source
Definition: EdmProvDump.cc:43
const SVec optutl::CommandLineParser::argVec ( ) const
inline

Definition at line 53 of file CommandLineParser.h.

References m_fullArgVec.

Referenced by fwlite::EventContainer::~EventContainer().

void CommandLineParser::findCommand ( const std::string &  line,
std::string &  command,
std::string &  rest 
)
static

Definition at line 246 of file CommandLineParser.cc.

References kSpaces, and removeLeadingAndTrailingSpaces().

249 {
250  command = rest = "";
251  string::size_type nonspace = line.find_first_not_of (kSpaces);
252  if (string::npos == nonspace)
253  {
254  // we don't have anything here at all. Just quit now
255  return;
256  }
257  string::size_type space = line.find_first_of (kSpaces, nonspace);
258  if (string::npos == space)
259  {
260  // we only have a command and nothing else
261  command = line.substr (nonspace);
262  return;
263  }
264  command = line.substr (nonspace, space - nonspace);
265  rest = line.substr (space + 1);
267 }
static void removeLeadingAndTrailingSpaces(std::string &line)
uint16_t size_type
static const std::string kSpaces
void CommandLineParser::help ( )

Definition at line 143 of file CommandLineParser.cc.

References gather_cfg::cout, cmsRelvalreport::exit, m_argv0, m_usageString, and printOptionValues().

Referenced by main(), and parseArguments().

144 {
145  if (m_usageString.length())
146  {
147  cout << m_argv0 << " - " << m_usageString << endl;
148  }
149  cout << "--help - This screen" << endl
150  << "--noPrint - Do not print out all settings" << endl
151  << "--print - Print out all settings" << endl;
153  exit (0);
154 }
tuple cout
Definition: gather_cfg.py:121
void CommandLineParser::parseArguments ( int  argc,
char **  argv,
bool  allowArgs = false 
)

Definition at line 71 of file CommandLineParser.cc.

References _runVariableCommandFromString(), _setVariableFromString(), dir2webdir::argc, dtNoiseDBValidation_cfg::cerr, cmsRelvalreport::exit, first, help(), cmsHarvester::loop, optutl::VariableMapCont::lowercaseString(), m_argv0, m_fullArgVec, and m_printOptions.

Referenced by main().

72 {
73  bool callHelp = false;
74  SVec argsVec;
75  m_argv0 = argv[0];
76  m_fullArgVec.push_back (argv[0]);
77  for (int loop = 1; loop < argc; ++loop)
78  {
79  string arg = argv[loop];
80  m_fullArgVec.push_back (arg);
81  string::size_type where = arg.find_first_of("=");
82  if (string::npos != where)
83  {
84  if ( _setVariableFromString (arg) )
85  {
86  continue;
87  }
89  {
90  continue;
91  }
92  cerr << "Don't understand: " << arg << endl;
93  exit(0);
94  } // tag=value strings
95  else if (arg.at(0) == '-')
96  {
97  string::size_type where = arg.find_first_not_of("-");
98  if (string::npos == where)
99  {
100  // a poorly formed option
101  cerr << "Don't understand: " << arg << endl;
102  exit(0);
103  continue;
104  }
105  lowercaseString (arg);
106  char first = arg.at (where);
107  // Print the values
108  if ('p' == first)
109  {
110  m_printOptions = true;
111  continue;
112  }
113  if ('n' == first)
114  {
115  m_printOptions = false;
116  continue;
117  }
118  // Exit after printing values
119  if ('h' == first)
120  {
121  callHelp = true;
122  continue;
123  }
124  // if we're still here, then we've got a problem.
125  cerr << "Don't understand: " << arg << endl;
126  exit(0);
127  } // -arg strings
128  if (returnArgs)
129  {
130  argsVec.push_back (arg);
131  } else {
132  cerr << "Don't understand: " << arg << endl;
133  exit(0);
134  }
135  } // for loop
136  if (callHelp)
137  {
138  help();
139  }
140 }
bool _runVariableCommandFromString(const std::string &arg)
std::vector< std::string > SVec
int loop
CMSSW
uint16_t size_type
A arg
Definition: Factorize.h:36
static void lowercaseString(std::string &arg)
bool first
Definition: L1TdeRCT.cc:75
bool _setVariableFromString(const std::string &arg, bool dontOverrideChange=false, int offset=0)
tuple argc
Definition: dir2webdir.py:38
void CommandLineParser::printOptionValues ( )

Definition at line 271 of file CommandLineParser.cc.

References gather_cfg::cout, idDealer::description, getDQMSummary::iter, optutl::VariableMapCont::m_boolMap, optutl::VariableMapCont::m_doubleMap, optutl::VariableMapCont::m_doubleVecMap, optutl::VariableMapCont::m_integerMap, optutl::VariableMapCont::m_integerVecMap, optutl::VariableMapCont::m_stringMap, optutl::VariableMapCont::m_stringVecMap, optutl::VariableMapCont::m_variableDescriptionMap, and relativeConstraints::value.

Referenced by _finishDefaultOptions(), and help().

272 {
273  cout << "------------------------------------------------------------------"
274  << left << endl;
275  // Print the integers next
276  if (m_integerMap.size())
277  {
278  cout << endl << "Integer options:" << endl;
279  }
280  for (SIMapConstIter iter = m_integerMap.begin();
281  m_integerMap.end() != iter;
282  ++iter)
283  {
284  const string &description = m_variableDescriptionMap[ iter->first ];
285  cout << " " << setw(14) << iter->first << " = " << setw(14)
286  << iter->second;
287  if (description.length())
288  {
289  cout << " - " << description;
290  }
291  cout << endl;
292  } // for iter
293 
294  // Print the doubles next
295  if (m_doubleMap.size())
296  {
297  cout << endl << "Double options:" << endl;
298  }
299  for (SDMapConstIter iter = m_doubleMap.begin();
300  m_doubleMap.end() != iter;
301  ++iter)
302  {
303  const string &description = m_variableDescriptionMap[ iter->first ];
304  cout << " " << setw(14) << iter->first << " = " << setw(14)
305  << iter->second;
306  if (description.length())
307  {
308  cout << " - " << description;
309  }
310  cout << endl;
311  } // for iter
312 
313  // Print the bools first
314  if (m_boolMap.size())
315  {
316  cout << endl << "Bool options:" << endl;
317  }
318  for (SBMapConstIter iter = m_boolMap.begin();
319  m_boolMap.end() != iter;
320  ++iter)
321  {
322  const string &description = m_variableDescriptionMap[ iter->first ];
323  cout << " " << setw(14) << iter->first << " = " << setw(14);
324  if (iter->second)
325  {
326  cout << "true";
327  } else {
328  cout << "false";
329  }
330  if (description.length())
331  {
332  cout << " - " << description;
333  }
334  cout << endl;
335  } // for iter
336 
337  // Print the strings next
338  if (m_stringMap.size())
339  {
340  cout << endl << "String options:" << endl;
341  }
342  for (SSMapConstIter iter = m_stringMap.begin();
343  m_stringMap.end() != iter;
344  ++iter)
345  {
346  const string &description = m_variableDescriptionMap[ iter->first ];
347  cout << " " << setw(14) << iter->first << " = ";
348  const string value = "'" + iter->second + "'";
349  cout << setw(14) << "";
350  if (description.length())
351  {
352  cout << " - " << description;
353  }
354  cout << endl << " " << value << endl;
355  } // for iter
356 
357  // Integer Vec
358  if (m_integerVecMap.size())
359  {
360  cout << endl << "Integer Vector options:" << endl;
361  }
362  for (SIVecMapConstIter iter = m_integerVecMap.begin();
363  m_integerVecMap.end() != iter;
364  ++iter)
365  {
366  const string &description = m_variableDescriptionMap[ iter->first ];
367  cout << " " << setw(14) << iter->first << " = ";
368  dumpSTL (iter->second);
369  cout << endl;
370  if (description.length())
371  {
372  cout << " - " << description;
373  }
374  cout << endl;
375  } // for iter
376 
377  // Double Vec
378  if (m_doubleVecMap.size())
379  {
380  cout << endl << "Double Vector options:" << endl;
381  }
382  for (SDVecMapConstIter iter = m_doubleVecMap.begin();
383  m_doubleVecMap.end() != iter;
384  ++iter)
385  {
386  const string &description = m_variableDescriptionMap[ iter->first ];
387  cout << " " << setw(14) << iter->first << " = ";
388  dumpSTL (iter->second);
389  cout << endl;
390  if (description.length())
391  {
392  cout << " - " << description;
393  }
394  cout << endl;
395  } // for iter
396 
397  // String Vec
398  if (m_stringVecMap.size())
399  {
400  cout << endl << "String Vector options:" << endl;
401  } else {
402  cout << endl;
403  }
404  for (SSVecMapConstIter iter = m_stringVecMap.begin();
405  m_stringVecMap.end() != iter;
406  ++iter)
407  {
408  const string &description = m_variableDescriptionMap[ iter->first ];
409  cout << " " << setw(14) << iter->first << " = ";
410  if (description.length())
411  {
412  cout << setw(14) << "" << " - " << description;
413  }
414  cout << endl;
415  dumpSTLeachEndl (iter->second, 8);
416  } // for iter
417 
418  cout << "------------------------------------------------------------------"
419  << right << endl;
420 }
SIMap::const_iterator SIMapConstIter
SDMap::const_iterator SDMapConstIter
SBMap::const_iterator SBMapConstIter
SSVecMap::const_iterator SSVecMapConstIter
SSMap::const_iterator SSMapConstIter
SIVecMap::const_iterator SIVecMapConstIter
tuple description
Definition: idDealer.py:66
tuple cout
Definition: gather_cfg.py:121
SDVecMap::const_iterator SDVecMapConstIter
void CommandLineParser::removeComment ( std::string &  line)
static

Definition at line 200 of file CommandLineParser.cc.

Referenced by split().

201 {
202  string::size_type location = line.find ("#");
203  if (string::npos != location)
204  {
205  // we've got a comment. Strip it out
206  line = line.substr (0, location - 1);
207  } // if found
208 }
uint16_t size_type
string CommandLineParser::removeEnding ( const std::string &  input,
const std::string &  ending 
)
static

Definition at line 233 of file CommandLineParser.cc.

References input, and position.

Referenced by _finishDefaultOptions().

234 {
235  string::size_type position = input.rfind(ending);
236  if (input.length() - ending.length() == position)
237  {
238  // we've got it
239  return input.substr(0, position);
240  }
241  // If we're still here, it wasn't there
242  return input;
243 }
uint16_t size_type
static std::string const input
Definition: EdmProvDump.cc:44
static int position[264][3]
Definition: ReadPGInfo.cc:509
void CommandLineParser::removeLeadingAndTrailingSpaces ( std::string &  line)
static

Definition at line 211 of file CommandLineParser.cc.

References kSpaces.

Referenced by findCommand().

212 {
213  string::size_type pos = line.find_first_not_of (kSpaces);
214  if (string::npos == pos)
215  {
216  // we don't have anything here at all. Just quit now
217  return;
218  }
219  if (pos)
220  {
221  // We have spaces at the beginning.
222  line = line.substr (pos);
223  }
224  pos = line.find_last_not_of (kSpaces);
225  if (pos + 1 != line.length())
226  {
227  // we've got spaces at the end
228  line = line.substr (0, pos + 1);
229  }
230 }
uint16_t size_type
static const std::string kSpaces
void optutl::CommandLineParser::setPrintOptoins ( bool  print)
inline

Definition at line 50 of file CommandLineParser.h.

References m_printOptions, and reco::print().

50 { m_printOptions = print; }
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8
void CommandLineParser::split ( SVec retval,
std::string  line,
std::string  match = " \t",
bool  ignoreComments = true 
)
static

Definition at line 158 of file CommandLineParser.cc.

References cond::rpcobimon::current, kSpaces, prof2calltree::last, match(), and removeComment().

Referenced by _runVariableCommandFromString(), and _setVariableFromString().

160 {
161  if (ignoreComments)
162  {
164  } // if ignoreComments
165  retval.clear();
166  // find the first non-space
167  string::size_type start1 = line.find_first_not_of (kSpaces);
168  // Is the first non-space character a '#'
169  char firstCh = line[start1];
170  if ('#' == firstCh)
171  {
172  // this line is a comment
173  return;
174  }
175 
176  line += match; // get last word of line
177  string::size_type last = string::npos;
178  string::size_type current = line.find_first_of(match);
179  while (string::npos != current)
180  {
181  string::size_type pos;
182  if (string::npos != last)
183  {
184  pos = last + 1;
185  } else {
186  pos = 0;
187  }
188  string part = line.substr( pos, current - last - 1);
189  // don't bother adding 0 length strings
190  if (part.length())
191  {
192  retval.push_back(part);
193  }
194  last = current;
195  current = line.find_first_of(match, current + 1);
196  } // while we're finding spaces
197 }
uint16_t size_type
static const std::string kSpaces
static void removeComment(std::string &line)
part
Definition: HCALResponse.h:20
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o_stream,
const CommandLineParser rhs 
)
friend

Member Data Documentation

const std::string CommandLineParser::kSpaces = " \t"
static
std::string optutl::CommandLineParser::m_argv0
private

Definition at line 132 of file CommandLineParser.h.

Referenced by help(), and parseArguments().

SVec optutl::CommandLineParser::m_fullArgVec
private

Definition at line 131 of file CommandLineParser.h.

Referenced by argVec(), and parseArguments().

unsigned int optutl::CommandLineParser::m_optionsType
private

Definition at line 135 of file CommandLineParser.h.

Referenced by _finishDefaultOptions(), and CommandLineParser().

bool optutl::CommandLineParser::m_printOptions
private

Definition at line 134 of file CommandLineParser.h.

Referenced by _finishDefaultOptions(), parseArguments(), and setPrintOptoins().

std::string optutl::CommandLineParser::m_usageString
private

Definition at line 133 of file CommandLineParser.h.

Referenced by help().