The Gaudi Framework  v30r1 (5d4f4ae2)
DataObjID.cpp
Go to the documentation of this file.
6 #include <functional>
7 
8 namespace Gaudi
9 {
10  namespace Parsers
11  {
12 
13  template <typename Iterator, typename Skipper>
14  struct DataObjIDGrammar : qi::grammar<Iterator, DataObjID(), Skipper> {
15  using ResultT = DataObjID;
16  struct Operations {
17  template <typename ClassID>
19  {
20  dest = {arg.first, arg.second};
21  }
22  void operator()( DataObjID& dest, const std::string& arg ) const { dest = {arg}; }
23  };
25  {
26  result = atlas1_style[op( qi::_val, qi::_1 )] | atlas2_style[op( qi::_val, qi::_1 )] |
27  gaudi_style[op( qi::_val, qi::_1 )];
28  }
32  qi::rule<Iterator, DataObjID(), Skipper> result;
33  ph::function<Operations> op;
34  };
36  }
37 }
38 
41 namespace
42 {
43  auto getClidSvc = []( std::reference_wrapper<IClassIDSvc*> p ) {
44  p.get() = Gaudi::svcLocator()->service<IClassIDSvc>( "ClassIDSvc" ).get();
45  };
46 }
47 
49 {
50  std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
51 
52  if ( !p_clidSvc || p_clidSvc->getIDOfTypeName( m_className, m_clid ).isFailure() ) {
53  m_clid = 0;
54  m_className = "UNKNOWN_CLASS:" + m_className;
55  }
56 }
57 
59 {
60  std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
61 
62  if ( !p_clidSvc || p_clidSvc->getTypeNameOfID( m_clid, m_className ).isFailure() ) {
63  m_className = "UNKNOW_CLID:" + std::to_string( m_clid );
64  }
65 }
66 
68 {
69  m_hash = ( std::hash<std::string>()( m_key ) );
70  if ( m_clid != 0 ) {
71  // this is a bit redundant since hash<int> is a pass-through
72  m_hash ^= ( std::hash<CLID>()( m_clid ) << 1 );
73  }
74 }
75 
76 #include "GaudiKernel/ToStream.h"
78 {
80  return ( d.m_clid != 0 || !d.m_className.empty() ) ? toStream( std::tie( d.m_className, d.m_key ), os )
81  : toStream( d.m_key, os );
82 }
83 
85 {
86  return ( m_clid == 0 && m_className.empty() ) ? m_key : ( m_className + '/' + m_key );
87 }
88 
90 {
91  return Gaudi::Utils::toString( v );
92 }
93 
95 {
97  if ( !Gaudi::Parsers::parse_( c, s ).isSuccess() ) {
98  throw std::invalid_argument( "cannot parse '" + s + "' to DataObjIDColl" );
99  }
100  return c;
101 }
std::string toString(const TYPE &v)
Definition: Property.h:155
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)
qi::rule< Iterator, DataObjID(), Skipper > result
Definition: DataObjID.cpp:32
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:78
std::string m_key
Definition: DataObjID.h:75
T call_once(T...args)
STL class.
static std::once_flag m_ip
Definition: DataObjID.h:79
interface to the CLID database
Definition: IClassIDSvc.h:24
ph::function< Operations > op
Definition: DataObjID.cpp:33
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()
TYPE fromString(const std::string &s)
Definition: Property.h:160
CLID m_clid
Definition: DataObjID.h:72
Grammar_< Iterator, std::pair< std::string, std::string >, Skipper >::Grammar atlas2_style
Definition: DataObjID.cpp:31
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:77
Grammar_< Iterator, std::string, Skipper >::Grammar gaudi_style
Definition: DataObjID.cpp:29
void operator()(DataObjID &dest, const std::string &arg) const
Definition: DataObjID.cpp:22
Grammar_< Iterator, std::pair< unsigned int, std::string >, Skipper >::Grammar atlas1_style
Definition: DataObjID.cpp:30
T ref(T...args)
string s
Definition: gaudirun.py:253
implementation of various functions for streaming.
void setClid()
Definition: DataObjID.cpp:48
void setClassName()
Definition: DataObjID.cpp:58
std::string fullKey() const
Definition: DataObjID.cpp:84
void operator()(DataObjID &dest, const std::pair< ClassID, std::string > &arg) const
Definition: DataObjID.cpp:18
std::string m_className
Definition: DataObjID.h:76
STL class.
void hashGen()
Definition: DataObjID.cpp:67
Helper functions to set/get the application return code.
Definition: __init__.py:1
REGISTER_GRAMMAR(GaudiMath::Interpolation::Type, InterpolGrammar)