ATLAS Offline Software
SrcInfo.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef UTILITIES_COLLECTION_SRCINFO
6 #define UTILITIES_COLLECTION_SRCINFO
7 
10 
11 /**********************************************************
12 
13 SrcInfo is an concretization of a CmdLineArgs2
14  to contain input collection info.
15 
16 Qualifiers: -src, -srcconnect
17 
18 **********************************************************/
19 
20 namespace pool
21 {
22 
23  class SrcInfo : public CmdLineArgs2
24  {
25  public:
26 
28  SrcInfo( );
29 
30  virtual ~SrcInfo() {}
31 
33  bool evalArgs(std::vector<std::string>& argv);
34 
35  std::string connect() {return m_connection;}
36 
37  std::pair<std::string,std::string> nameAndType(unsigned int);
38 
39  std::string name(unsigned int);
40  std::string type(unsigned int);
41 
42  unsigned int nSrc();
43 
44  private:
45  std::string m_connection;
46  std::vector<std::string> m_NameVec;
47  std::vector<std::string> m_TypeVec;
48 
49  };
50 
51 
52 
53  inline
54  SrcInfo::SrcInfo( ) : CmdLineArgs2("SrcInfo")
55  {
57  markers.insert( std::make_pair("-src", ArgQual(2,true,true)) );
58  markers.insert( std::make_pair("-srcconnect",ArgQual()) );
59  markers["-src"].desc << "<input collection name> <input collection type> " << std::endl
60  << "List of name-type pairs is space separated; "
61  << "Choices for collection types are " << std::endl;
63  at != this->allowedTypes().end();
64  ++at)
65  markers["-src"].desc << *at << std::endl;
66  markers["-srcconnect"].desc << "[Input database connection string] " << std::endl
67  << "The connection string will be looked up in $CORAL_DBLOOKUP_PATH/dblookup.xml" << std::endl
68  << "Database user authentication is done using CORAL_AUTH_PATH/authentication.xml" << std::endl
69  << " or CORAL_AUTH_USER and CORAL_AUTH_PASSWORD variables" << std::endl;
70  this->setArgQuals(markers);
71  m_NameVec.clear();
72  m_TypeVec.clear();
73  }
74 
75  inline bool SrcInfo::evalArgs(std::vector<std::string>& argv)
76  {
77  // Call underlying parser in the base class
78  bool retc = this->CmdLineArgs2::evalArgs(argv);
79  if(!retc) return retc;
80 
81  if ( this->hasQual("-srcconnect") ) {
82  int ifirst = (*this)["-srcconnect"].first;
83  m_connection = argv[ifirst];
84  }
85 
86  if ( this->hasQual("-src") ) {
87  int ifirst = (*this)["-src"].first;
88  int ilast = (*this)["-src"].second;
89  std::string srcCollName = "";
90  std::string srcCollType = "";
91  int i = ifirst;
92  while( i < ilast ) {
93  srcCollName = std::string(argv[i]); ++i;
94  srcCollType = std::string(argv[i]);
95  // First check if it is a:
96  // file based or logical type collection
97  // Or is it gibberish, and they need to try again.
98  if ( std::find(this->allowedTypes().begin(),
99  this->allowedTypes().end(),
100  srcCollType) == this->allowedTypes().end() ) {
101  std::cerr << " ERROR Collection type " << srcCollType
102  << " is not presently handled by this program."
103  << std::endl;
104  retc = false;
105  }
106  m_NameVec.push_back( srcCollName );
107  m_TypeVec.push_back( srcCollType );
108  ++i;
109  } // end of m_nameAndTypeVec loop
110  } // end of -src Qual
111 
112  return retc;
113 
114  }
115 
116  inline std::pair<std::string,std::string>
117  SrcInfo::nameAndType(unsigned int ind)
118  {
119  if ( ind < m_TypeVec.size() )
120  return std::pair<std::string,std::string>(m_NameVec[ind],m_TypeVec[ind]);
121  else {
122  std::cerr << "Out of range request for src (name,type) pair" << std::endl;
123  return std::pair<std::string,std::string>("BAD","BAD");
124  }
125  }
126 
127  inline std::string
128  SrcInfo::name(unsigned int ind)
129  {
130  if ( ind < m_NameVec.size() ) return m_NameVec[ind];
131  else {
132  std::cerr << "Out of range request for src name" << std::endl;
133  return std::string("BAD");
134  }
135  }
136 
137  inline std::string
138  SrcInfo::type(unsigned int ind)
139  {
140  if ( ind < m_TypeVec.size() ) return m_TypeVec[ind];
141  else {
142  std::cerr << "Out of range request for src type" << std::endl;
143  return std::string("BAD");
144  }
145  }
146 
147  inline unsigned int
148  SrcInfo::nSrc()
149  {
150  return this->nArgs("-src");
151  }
152 
153 } // end pool namespace
154 
155 #endif // UTILITIES_COLLECTION_SRCINFO
156 
157 
158 
159 
160 
161 
162 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
ArgQual.h
pool
pool namespace
Definition: libname.h:15
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
pool::CmdLineArgs2::name
std::string name() const
identifier
Definition: CmdLineArgs2.h:106
pool::SrcInfo::m_NameVec
std::vector< std::string > m_NameVec
Definition: SrcInfo.h:60
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
pool::CmdLineArgs2::setArgQuals
void setArgQuals(QualList &quals)
set the QualList
Definition: CmdLineArgs2.h:119
pool::SrcInfo::nameAndType
std::pair< std::string, std::string > nameAndType(unsigned int)
Definition: SrcInfo.h:124
pool::SrcInfo::m_TypeVec
std::vector< std::string > m_TypeVec
Definition: SrcInfo.h:61
CaloCondBlobAlgs_fillNoiseFromASCII.desc
desc
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:54
pool::SrcInfo::nSrc
unsigned int nSrc()
Definition: SrcInfo.h:155
lumiFormat.i
int i
Definition: lumiFormat.py:92
CmdLineArgs2.h
pool::CmdLineArgs2::evalArgs
virtual bool evalArgs(std::vector< std::string > &argv)
Apply the criteria in the QualList to the argv[].
pool::SrcInfo::~SrcInfo
virtual ~SrcInfo()
Definition: SrcInfo.h:44
pool::CmdLineArgs2::hasQual
bool hasQual(const std::string &arg) const
Check if argument was found in the argv[].
pool::SrcInfo::evalArgs
bool evalArgs(std::vector< std::string > &argv)
Apply the criteria in the QualList to the argv[].
Definition: SrcInfo.h:82
CoreClass.markers
list markers
Definition: CoreClass.py:17
pool::SrcInfo::connect
std::string connect()
Definition: SrcInfo.h:49
pool::QualList
std::map< std::string, ArgQual > QualList
Definition: ArgQual.h:120
pool::SrcInfo::type
std::string type(unsigned int)
Definition: SrcInfo.h:145
pool::CmdLineArgs2::allowedTypes
std::vector< std::string > & allowedTypes()
Hack to bring in allowed types of Collections.
Definition: CmdLineArgs2.h:113
pool::SrcInfo::SrcInfo
SrcInfo()
Constructors.
Definition: SrcInfo.h:61
pool::SrcInfo::m_connection
std::string m_connection
Definition: SrcInfo.h:59
pool::ArgQual
Definition: ArgQual.h:81
pool::CmdLineArgs2::nArgs
unsigned int nArgs(std::string)
Number of arguments for a given qualifer, e.g. nArgs("-src")
pool::CmdLineArgs2
Definition: CmdLineArgs2.h:73
checkFileSG.ind
list ind
Definition: checkFileSG.py:118