Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
DataObjID.cpp
Go to the documentation of this file.
6 #include <functional>
7 #include <iomanip>
8 #include <iostream>
9 
10 namespace {
11  std::string quote( const std::string& in ) {
12  if ( !in.empty() && in.front() == in.back() && ( in.front() == '\'' || in.front() == '\"' ) ) return in;
14  s << std::quoted( in );
15  return s.str();
16  }
17 } // namespace
18 
19 namespace Gaudi {
20  namespace Parsers {
21 
22  template <typename Iterator, typename Skipper>
23  struct DataObjIDGrammar : qi::grammar<Iterator, DataObjID(), Skipper> {
24  using ResultT = DataObjID;
25  struct Operations {
26  template <typename ClassID>
28  dest = {arg.first, arg.second};
29  }
30  void operator()( DataObjID& dest, const std::string& arg ) const { dest = {arg}; }
31  };
33  result = atlas1_style[op( qi::_val, qi::_1 )] | atlas2_style[op( qi::_val, qi::_1 )] |
34  gaudi_style[op( qi::_val, qi::_1 )];
35  }
39  qi::rule<Iterator, DataObjID(), Skipper> result;
40  ph::function<Operations> op;
41  };
43  } // namespace Parsers
44 } // namespace Gaudi
45 
46 StatusCode parse( DataObjID& dest, const std::string& src ) { return Gaudi::Parsers::parse_( dest, quote( src ) ); }
47 
50 namespace {
51  auto getClidSvc = []( std::reference_wrapper<IClassIDSvc*> p ) {
52  p.get() = Gaudi::svcLocator()->service<IClassIDSvc>( "ClassIDSvc" ).get();
53  };
54 }
55 
57  std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
58 
59  if ( !p_clidSvc || p_clidSvc->getIDOfTypeName( m_className, m_clid ).isFailure() ) {
60  m_clid = 0;
61  m_className = "UNKNOWN_CLASS:" + m_className;
62  }
63 }
64 
66  std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
67 
68  if ( !p_clidSvc || p_clidSvc->getTypeNameOfID( m_clid, m_className ).isFailure() ) {
69  m_className = "UNKNOW_CLID:" + std::to_string( m_clid );
70  }
71 }
72 
74  m_hash = ( std::hash<std::string>()( m_key ) );
75  if ( m_clid != 0 ) {
76  // this is a bit redundant since hash<int> is a pass-through
77  m_hash ^= ( std::hash<CLID>()( m_clid ) << 1 );
78  }
79 }
80 
81 #include "GaudiKernel/ToStream.h"
84  return ( d.m_clid != 0 || !d.m_className.empty() ) ? toStream( std::tie( d.m_className, d.m_key ), os )
85  : toStream( d.m_key, os );
86 }
87 
89  return ( m_clid == 0 && m_className.empty() ) ? m_key : ( m_className + '/' + m_key );
90 }
91 
93  return Gaudi::Utils::toString( v );
94 }
95 
97  const std::string& s ) {
99  if ( !Gaudi::Parsers::parse_( c, s ).isSuccess() ) {
100  throw std::invalid_argument( "cannot parse '" + s + "' to DataObjIDColl" );
101  }
102  return c;
103 }
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:202
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:284
StatusCode parse_(ResultT &result, const std::string &input)
Definition: Factory.h:29
T tie(T...args)
T front(T...args)
qi::rule< Iterator, DataObjID(), Skipper > result
Definition: DataObjID.cpp:39
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:334
T to_string(T...args)
static IClassIDSvc * p_clidSvc
Definition: DataObjID.h:76
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:73
T call_once(T...args)
STL class.
static std::once_flag m_ip
Definition: DataObjID.h:77
interface to the CLID database
Definition: IClassIDSvc.h:22
ph::function< Operations > op
Definition: DataObjID.cpp:40
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
GAUDI_API ISvcLocator * svcLocator()
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
CLID m_clid
Definition: DataObjID.h:70
T str(T...args)
Grammar_< Iterator, std::pair< std::string, std::string >, Skipper >::Grammar atlas2_style
Definition: DataObjID.cpp:38
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:82
Grammar_< Iterator, std::string, Skipper >::Grammar gaudi_style
Definition: DataObjID.cpp:36
void operator()(DataObjID &dest, const std::string &arg) const
Definition: DataObjID.cpp:30
Grammar_< Iterator, std::pair< unsigned int, std::string >, Skipper >::Grammar atlas1_style
Definition: DataObjID.cpp:37
T ref(T...args)
T back(T...args)
string s
Definition: gaudirun.py:312
implementation of various functions for streaming.
void setClid()
Definition: DataObjID.cpp:56
void setClassName()
Definition: DataObjID.cpp:65
std::string fullKey() const
Definition: DataObjID.cpp:88
void operator()(DataObjID &dest, const std::pair< ClassID, std::string > &arg) const
Definition: DataObjID.cpp:27
std::string m_className
Definition: DataObjID.h:74
STL class.
void hashGen()
Definition: DataObjID.cpp:73
Helper functions to set/get the application return code.
Definition: __init__.py:1
REGISTER_GRAMMAR(GaudiMath::Interpolation::Type, InterpolGrammar)