The Gaudi Framework  v30r3 (a5ef0a68)
DataObjID.cpp
Go to the documentation of this file.
6 #include <functional>
7 #include <iomanip>
8 #include <iostream>
9 
10 namespace
11 {
12  std::string quote( const std::string& in )
13  {
14  if ( !in.empty() && in.front() == in.back() && ( in.front() == '\'' || in.front() == '\"' ) ) return in;
16  s << std::quoted( in );
17  return s.str();
18  }
19 }
20 
21 namespace Gaudi
22 {
23  namespace Parsers
24  {
25 
26  template <typename Iterator, typename Skipper>
27  struct DataObjIDGrammar : qi::grammar<Iterator, DataObjID(), Skipper> {
28  using ResultT = DataObjID;
29  struct Operations {
30  template <typename ClassID>
32  {
33  dest = {arg.first, arg.second};
34  }
35  void operator()( DataObjID& dest, const std::string& arg ) const { dest = {arg}; }
36  };
38  {
39  result = atlas1_style[op( qi::_val, qi::_1 )] | atlas2_style[op( qi::_val, qi::_1 )] |
40  gaudi_style[op( qi::_val, qi::_1 )];
41  }
45  qi::rule<Iterator, DataObjID(), Skipper> result;
46  ph::function<Operations> op;
47  };
49  }
50 }
51 
52 StatusCode parse( DataObjID& dest, const std::string& src ) { return Gaudi::Parsers::parse_( dest, quote( src ) ); }
53 
56 namespace
57 {
58  auto getClidSvc = []( std::reference_wrapper<IClassIDSvc*> p ) {
59  p.get() = Gaudi::svcLocator()->service<IClassIDSvc>( "ClassIDSvc" ).get();
60  };
61 }
62 
64 {
65  std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
66 
67  if ( !p_clidSvc || p_clidSvc->getIDOfTypeName( m_className, m_clid ).isFailure() ) {
68  m_clid = 0;
69  m_className = "UNKNOWN_CLASS:" + m_className;
70  }
71 }
72 
74 {
75  std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
76 
77  if ( !p_clidSvc || p_clidSvc->getTypeNameOfID( m_clid, m_className ).isFailure() ) {
78  m_className = "UNKNOW_CLID:" + std::to_string( m_clid );
79  }
80 }
81 
83 {
84  m_hash = ( std::hash<std::string>()( m_key ) );
85  if ( m_clid != 0 ) {
86  // this is a bit redundant since hash<int> is a pass-through
87  m_hash ^= ( std::hash<CLID>()( m_clid ) << 1 );
88  }
89 }
90 
91 #include "GaudiKernel/ToStream.h"
93 {
95  return ( d.m_clid != 0 || !d.m_className.empty() ) ? toStream( std::tie( d.m_className, d.m_key ), os )
96  : toStream( d.m_key, os );
97 }
98 
100 {
101  return ( m_clid == 0 && m_className.empty() ) ? m_key : ( m_className + '/' + m_key );
102 }
103 
105 {
106  return Gaudi::Utils::toString( v );
107 }
108 
110  const std::string& s )
111 {
113  if ( !Gaudi::Parsers::parse_( c, s ).isSuccess() ) {
114  throw std::invalid_argument( "cannot parse '" + s + "' to DataObjIDColl" );
115  }
116  return c;
117 }
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:213
T empty(T...args)
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
Definition: ToStream.h:303
StatusCode parse_(ResultT &result, const std::string &input)
T tie(T...args)
T front(T...args)
qi::rule< Iterator, DataObjID(), Skipper > result
Definition: DataObjID.cpp:45
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:356
T to_string(T...args)
static IClassIDSvc * p_clidSvc
Definition: DataObjID.h:77
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
std::string m_key
Definition: DataObjID.h:74
T call_once(T...args)
STL class.
static std::once_flag m_ip
Definition: DataObjID.h:78
interface to the CLID database
Definition: IClassIDSvc.h:24
ph::function< Operations > op
Definition: DataObjID.cpp:46
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
GAUDI_API ISvcLocator * svcLocator()
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
CLID m_clid
Definition: DataObjID.h:71
T str(T...args)
Grammar_< Iterator, std::pair< std::string, std::string >, Skipper >::Grammar atlas2_style
Definition: DataObjID.cpp:44
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:92
Grammar_< Iterator, std::string, Skipper >::Grammar gaudi_style
Definition: DataObjID.cpp:42
void operator()(DataObjID &dest, const std::string &arg) const
Definition: DataObjID.cpp:35
Grammar_< Iterator, std::pair< unsigned int, std::string >, Skipper >::Grammar atlas1_style
Definition: DataObjID.cpp:43
T ref(T...args)
T back(T...args)
string s
Definition: gaudirun.py:253
implementation of various functions for streaming.
void setClid()
Definition: DataObjID.cpp:63
void setClassName()
Definition: DataObjID.cpp:73
std::string fullKey() const
Definition: DataObjID.cpp:99
void operator()(DataObjID &dest, const std::pair< ClassID, std::string > &arg) const
Definition: DataObjID.cpp:31
std::string m_className
Definition: DataObjID.h:75
STL class.
void hashGen()
Definition: DataObjID.cpp:82
Helper functions to set/get the application return code.
Definition: __init__.py:1
REGISTER_GRAMMAR(GaudiMath::Interpolation::Type, InterpolGrammar)