ATLAS Offline Software
DstInfo.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_DSTINFO
6 #define UTILITIES_COLLECTION_DSTINFO
7 
10 
11 /**********************************************************
12 
13 DstInfo is an concretization of a CmdLineArgs2
14  to contain output collection info.
15 
16 Qualifiers: -dst, -dstconnect
17 
18 **********************************************************/
19 
20 namespace pool
21 {
22 
23  class DstInfo : public CmdLineArgs2
24  {
25  public:
26 
28  DstInfo( );
29 
30  virtual ~DstInfo() {}
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 nDst();
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  DstInfo::DstInfo( ) : CmdLineArgs2("DstInfo")
52  {
54  markers.insert( std::make_pair("-dst", ArgQual(2,true,true)) );
55  markers.insert( std::make_pair("-dstconnect",ArgQual()) );
56  markers["-dst"].desc << "<output collection name> <output collection type> " << std::endl
57  << "List of name-type pairs is space separated; "
58  << "Choices for collection types are " << std::endl;
60  at != this->allowedTypes().end();
61  ++at)
62  {
63  markers["-dst"].desc << *at << std::endl;
64  }
65  markers["-dstconnect"].desc << "[Output database connection string] " << std::endl
66  << "The connection string will be looked up in $CORAL_DBLOOKUP_PATH/dblookup.xml" << std::endl
67  << "Database user authentication is done using CORAL_AUTH_PATH/authentication.xml" << std::endl
68  << " or CORAL_AUTH_USER and CORAL_AUTH_PASSWORD variables" << std::endl;
69  this->setArgQuals(markers);
70  m_NameVec.clear();
71  m_TypeVec.clear();
72  }
73 
74  inline bool
75  DstInfo::evalArgs(std::vector<std::string>& argv)
76  {
77  bool retc = true;
78  retc = this->CmdLineArgs2::evalArgs(argv);
79  if (!retc) return retc;
80 
81  if ( this->hasQual("-dstconnect") ) {
82  int ifirst = (*this)["-dstconnect"].first;
83  m_connection = argv[ifirst];
84  }
85 
86  if ( this->hasQual("-dst") ) {
87  int ifirst = (*this)["-dst"].first;
88  int ilast = (*this)["-dst"].second;
89  std::string dstCollName = "";
90  std::string dstCollType = "";
91  int i = ifirst;
92  while( i < ilast ) {
93  dstCollName = std::string(argv[i]); ++i;
94  dstCollType = 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  dstCollType) == this->allowedTypes().end() ) {
101  std::cerr << " ERROR Collection type " << dstCollType
102  << " is not presently handled by this program."
103  << std::endl;
104  retc = false;
105  }
106  m_NameVec.push_back( dstCollName );
107  m_TypeVec.push_back( dstCollType );
108  ++i;
109  } // end of m_nameAndTypeVec loop
110  } // end of -dst Qual
111 
112  return retc;
113 
114  }
115 
116  inline std::pair<std::string,std::string>
117  DstInfo::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 dst (name,type) pair" << std::endl;
123  return std::pair<std::string,std::string>("BAD","BAD");
124  }
125  }
126 
127  inline std::string
128  DstInfo::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 dst name" << std::endl;
133  return std::string("BAD");
134  }
135  }
136 
137  inline std::string
138  DstInfo::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 dst type" << std::endl;
143  return std::string("BAD");
144  }
145  }
146 
147  inline unsigned int
148  DstInfo::nDst()
149  {
150  //return this->nArgs("-dst")/this->getArgQuals()["-dst"].argsize;
151  return this->nArgs("-dst");
152  }
153 
154 } // end pool namespace
155 
156 #endif // UTILITIES_COLLECTION_DSTINFO
157 
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::DstInfo::m_NameVec
std::vector< std::string > m_NameVec
Definition: DstInfo.h:60
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::DstInfo::type
std::string type(unsigned int)
Definition: DstInfo.h:145
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
pool::DstInfo::m_connection
std::string m_connection
Definition: DstInfo.h:59
pool::DstInfo::nameAndType
std::pair< std::string, std::string > nameAndType(unsigned int)
Definition: DstInfo.h:124
pool::CmdLineArgs2::setArgQuals
void setArgQuals(QualList &quals)
set the QualList
Definition: CmdLineArgs2.h:119
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::DstInfo::evalArgs
bool evalArgs(std::vector< std::string > &argv)
Apply the criteria in the QualList to the argv[].
Definition: DstInfo.h:82
pool::CmdLineArgs2::hasQual
bool hasQual(const std::string &arg) const
Check if argument was found in the argv[].
CoreClass.markers
list markers
Definition: CoreClass.py:17
pool::DstInfo::nDst
unsigned int nDst()
Definition: DstInfo.h:155
pool::QualList
std::map< std::string, ArgQual > QualList
Definition: ArgQual.h:120
pool::DstInfo::m_TypeVec
std::vector< std::string > m_TypeVec
Definition: DstInfo.h:61
pool::DstInfo::DstInfo
DstInfo()
Constructors.
Definition: DstInfo.h:58
pool::CmdLineArgs2::allowedTypes
std::vector< std::string > & allowedTypes()
Hack to bring in allowed types of Collections.
Definition: CmdLineArgs2.h:113
pool::DstInfo::connect
std::string connect()
Definition: DstInfo.h:49
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
pool::DstInfo::~DstInfo
virtual ~DstInfo()
Definition: DstInfo.h:44