The Gaudi Framework  v33r1 (b1225454)
DataObjID.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #include "GaudiKernel/DataObjID.h"
12 #include "GaudiKernel/Bootstrap.h"
15 #include <Gaudi/Parsers/Factory.h>
16 #include <functional>
17 #include <iomanip>
18 #include <iostream>
19 
20 namespace {
21  std::string quote( std::string_view in ) {
22  if ( !in.empty() && in.front() == in.back() && ( in.front() == '\'' || in.front() == '\"' ) )
23  return std::string{in};
25  s << std::quoted( in );
26  return s.str();
27  }
28 } // namespace
29 
30 namespace Gaudi {
31  namespace Parsers {
32 
33  template <typename Iterator, typename Skipper>
34  struct DataObjIDGrammar : qi::grammar<Iterator, DataObjID(), Skipper> {
35  using ResultT = DataObjID;
36  struct Operations {
37  template <typename ClassID>
39  dest = {arg.first, arg.second};
40  }
41  void operator()( DataObjID& dest, const std::string& arg ) const { dest = {arg}; }
42  };
44  result = atlas1_style[op( qi::_val, qi::_1 )] | atlas2_style[op( qi::_val, qi::_1 )] |
45  gaudi_style[op( qi::_val, qi::_1 )];
46  }
51  ph::function<Operations> op;
52  };
54  } // namespace Parsers
55 } // namespace Gaudi
56 
57 StatusCode parse( DataObjID& dest, const std::string& src ) { return Gaudi::Parsers::parse_( dest, quote( src ) ); }
58 
61 namespace {
62  auto getClidSvc = []( std::reference_wrapper<IClassIDSvc*> p ) {
63  p.get() = Gaudi::svcLocator()->service<IClassIDSvc>( "ClassIDSvc" ).get();
64  };
65 }
66 
68  std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
69 
71  m_clid = 0;
72  m_className = "UNKNOWN_CLASS:" + m_className;
73  }
74 }
75 
77  std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
78 
80  m_className = "UNKNOW_CLID:" + std::to_string( m_clid );
81  }
82 }
83 
86  if ( m_clid != 0 ) {
87  // this is a bit redundant since hash<int> is a pass-through
88  m_hash ^= ( std::hash<CLID>()( m_clid ) << 1 );
89  }
90 }
91 
92 #include "GaudiKernel/ToStream.h"
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  return ( m_clid == 0 && m_className.empty() ) ? m_key : ( m_className + '/' + m_key );
101 }
102 
104  return Gaudi::Utils::toString( v );
105 }
106 
108  const std::string& s ) {
110  if ( !Gaudi::Parsers::parse_( c, s ).isSuccess() ) {
111  throw std::invalid_argument( "cannot parse '" + s + "' to DataObjIDColl" );
112  }
113  return c;
114 }
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:220
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:291
StatusCode parse_(ResultT &result, const std::string &input)
Definition: Factory.h:39
T tie(T... args)
REGISTER_GRAMMAR(std::string, StringGrammar)
qi::rule< Iterator, DataObjID(), Skipper > result
Definition: DataObjID.cpp:50
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:341
T to_string(T... args)
void operator()(DataObjID &dest, const std::pair< ClassID, std::string > &arg) const
Definition: DataObjID.cpp:38
static IClassIDSvc * p_clidSvc
Definition: DataObjID.h:86
std::string m_key
Definition: DataObjID.h:83
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
T call_once(T... args)
std::string fullKey() const
Definition: DataObjID.cpp:99
virtual StatusCode getIDOfTypeName(const std::string &typeName, CLID &id) const =0
get id associated with type name (if any)
STL class.
static std::once_flag m_ip
Definition: DataObjID.h:87
interface to the CLID database
Definition: IClassIDSvc.h:32
ph::function< Operations > op
Definition: DataObjID.cpp:51
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:86
GAUDI_API ISvcLocator * svcLocator()
virtual StatusCode getTypeNameOfID(const CLID &id, std::string &typeName) const =0
get user assigned type name associated with clID
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
CLID m_clid
Definition: DataObjID.h:80
Grammar_< Iterator, std::pair< std::string, std::string >, Skipper >::Grammar atlas2_style
Definition: DataObjID.cpp:49
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:93
std::size_t m_hash
Definition: DataObjID.h:81
Grammar_< Iterator, std::string, Skipper >::Grammar gaudi_style
Definition: DataObjID.cpp:47
Grammar_< Iterator, std::pair< unsigned int, std::string >, Skipper >::Grammar atlas1_style
Definition: DataObjID.cpp:48
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:57
T ref(T... args)
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:28
string s
Definition: gaudirun.py:328
bool isFailure() const
Definition: StatusCode.h:145
void operator()(DataObjID &dest, const std::string &arg) const
Definition: DataObjID.cpp:41
implementation of various functions for streaming.
void setClid()
Definition: DataObjID.cpp:67
void setClassName()
Definition: DataObjID.cpp:76
std::string m_className
Definition: DataObjID.h:84
STL class.
void hashGen()
Definition: DataObjID.cpp:84
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1