ATLAS Offline Software
CmdLineArgs2.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef UTILITIES_COLLECTION_CMDLINEARGS2
6 #define UTILITIES_COLLECTION_CMDLINEARGS2
7 
8 #include <string>
9 #include <vector>
10 #include <algorithm>
11 #include <map>
13 
14 /**********************************************************
15 
16 CmdLineArgs2 is an extension of a map intended to map
17  qualifiers (e.g. -help) of a CLI to the index of
18  the argv[]. It's state is determined by a list of
19  ArgQual's/QualList. It then uses evalArgs to apply
20  those qualifiers to an argv[].
21 
22  - Qualifier -help is added in constructor
23  - methods described in comments in definition
24 
25 Example of Usage:
26 
27  Args2Container argsVec(thisProgram);
28 
29  QualList markers;
30  markers.insert( make_pair("-somequal", ArgQual()) );
31  markers["-somequal"].desc << "this is a qualifier with default=this";
32 
33  CmdLineArgs2 cmdLineArgs;
34  cmdLineArgs.setArgQuals(markers);
35  cmdLineArgs.evalArgs(argc,argv);
36  argsVec.push_back(&cmdLineArgs); // Add it to the list
37 
38  ...
39 
40 **********************************************************/
41 
42 namespace pool
43 {
44  class Args2Container;
45 
46  class CmdLineArgs2 : public std::map<std::string,std::pair<int,int> >
47  {
48  public:
50  CmdLineArgs2( const std::string& name="General" );
51  CmdLineArgs2( QualList&, const std::string& name="General");
52 
53  virtual ~CmdLineArgs2() {}
54 
56  virtual void init();
57 
59  bool hasQual( const std::string& arg ) const;
60 
62  bool getOpt( const std::string& opt, std::string &optval ) const;
63 
65  bool getOpt( const std::string& opt, int &optval ) const;
66 
68  bool getOpts( const std::string& opt, std::vector<std::string> &optvalvec ) const;
69 
71  virtual bool evalArgs(std::vector<std::string>& argv);
72 
74  virtual bool evalArgsPass2(std::vector<std::string>&, pool::Args2Container&) { return true; }
75 
77  bool valid() const {return m_argsfine;}
78 
80  std::string name() const {return m_id;}
81 
83  ArgQual& getArgQual(const std::string& a) {return m_quals[a];}
84  QualList& getArgQuals( ) {return m_quals;}
85 
87  std::vector<std::string>& allowedTypes() {return m_allowedTypes;}
88 
90  unsigned int nArgs(std::string);
91 
93  void setArgQuals( QualList& quals) {m_quals=quals;}
94 
97 
98  protected:
99 
101  bool m_ignoreMissingArgs;
102  std::vector<std::string> m_argv;
103 
104  private:
105 
107  void initTypes();
108 
110  std::string m_id;
111  std::vector<std::string> m_allowedTypes;
112  };
113 
114 
115  inline void CmdLineArgs2::init()
116  {
117  this->clear();
118  m_argsfine = false;
120  }
121 
122 
123 } // end pool namespace
124 
125 #endif // UTILITIES_COLLECTION_CMDLINEARGS2
126 
pool::CmdLineArgs2::init
virtual void init()
init
Definition: CmdLineArgs2.h:141
pool::CmdLineArgs2::~CmdLineArgs2
virtual ~CmdLineArgs2()
Definition: CmdLineArgs2.h:79
pool::CmdLineArgs2::valid
bool valid() const
Returns true if evalArgs has been called with no errors.
Definition: CmdLineArgs2.h:103
pool::CmdLineArgs2::getOpt
bool getOpt(const std::string &opt, std::string &optval) const
check if option was present and return its (first) value in optval(!)
ArgQual.h
pool::CmdLineArgs2::m_ignoreMissingArgs
bool m_ignoreMissingArgs
Definition: CmdLineArgs2.h:127
pool
pool namespace
Definition: libname.h:15
pool::CmdLineArgs2::name
std::string name() const
identifier
Definition: CmdLineArgs2.h:106
pool::CmdLineArgs2::evalArgsPass2
virtual bool evalArgsPass2(std::vector< std::string > &, pool::Args2Container &)
Second pass options processing.
Definition: CmdLineArgs2.h:100
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
pool::Args2Container
Definition: Args2Container.h:100
pool::CmdLineArgs2::setArgQuals
void setArgQuals(QualList &quals)
set the QualList
Definition: CmdLineArgs2.h:119
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:54
pool::CmdLineArgs2::getOpts
bool getOpts(const std::string &opt, std::vector< std::string > &optvalvec) const
check if option was present and return its values in optvalvec(!)
pool::CmdLineArgs2::initTypes
void initTypes()
Fill the vector m_allowedTypes.
pool::CmdLineArgs2::evalArgs
virtual bool evalArgs(std::vector< std::string > &argv)
Apply the criteria in the QualList to the argv[].
pool::CmdLineArgs2::m_argv
std::vector< std::string > m_argv
Definition: CmdLineArgs2.h:128
pool::CmdLineArgs2::hasQual
bool hasQual(const std::string &arg) const
Check if argument was found in the argv[].
pool::CmdLineArgs2::ignoreMissingArgs
void ignoreMissingArgs(bool ignore)
set flag to suppress error messages about missing arguments e.g. when -xmlInput is present
Definition: CmdLineArgs2.h:122
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
pool::CmdLineArgs2::m_argsfine
bool m_argsfine
Definition: CmdLineArgs2.h:126
pmontree.opt
opt
Definition: pmontree.py:16
pool::CmdLineArgs2::CmdLineArgs2
CmdLineArgs2(const std::string &name="General")
Constructor.
pool::QualList
std::map< std::string, ArgQual > QualList
Definition: ArgQual.h:120
pool::CmdLineArgs2::m_id
std::string m_id
Definition: CmdLineArgs2.h:136
a
TList * a
Definition: liststreamerinfos.cxx:10
pool::CmdLineArgs2::allowedTypes
std::vector< std::string > & allowedTypes()
Hack to bring in allowed types of Collections.
Definition: CmdLineArgs2.h:113
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
pool::CmdLineArgs2::nArgs
unsigned int nArgs(std::string)
Number of arguments for a given qualifer, e.g. nArgs("-src")
pool::CmdLineArgs2::m_allowedTypes
std::vector< std::string > m_allowedTypes
Definition: CmdLineArgs2.h:137
pool::CmdLineArgs2::m_quals
QualList m_quals
Definition: CmdLineArgs2.h:135
pool::CmdLineArgs2::getArgQual
ArgQual & getArgQual(const std::string &a)
Definition: CmdLineArgs2.h:109
pool::CmdLineArgs2::getArgQuals
QualList & getArgQuals()
Definition: CmdLineArgs2.h:110