The Gaudi Framework  v33r0 (d5ea422b)
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( const std::string& in ) {
22  if ( !in.empty() && in.front() == in.back() && ( in.front() == '\'' || in.front() == '\"' ) ) return in;
24  s << std::quoted( in );
25  return s.str();
26  }
27 } // namespace
28 
29 namespace Gaudi {
30  namespace Parsers {
31 
32  template <typename Iterator, typename Skipper>
33  struct DataObjIDGrammar : qi::grammar<Iterator, DataObjID(), Skipper> {
34  using ResultT = DataObjID;
35  struct Operations {
36  template <typename ClassID>
38  dest = {arg.first, arg.second};
39  }
40  void operator()( DataObjID& dest, const std::string& arg ) const { dest = {arg}; }
41  };
43  result = atlas1_style[op( qi::_val, qi::_1 )] | atlas2_style[op( qi::_val, qi::_1 )] |
44  gaudi_style[op( qi::_val, qi::_1 )];
45  }
50  ph::function<Operations> op;
51  };
53  } // namespace Parsers
54 } // namespace Gaudi
55 
56 StatusCode parse( DataObjID& dest, const std::string& src ) { return Gaudi::Parsers::parse_( dest, quote( src ) ); }
57 
60 namespace {
61  auto getClidSvc = []( std::reference_wrapper<IClassIDSvc*> p ) {
62  p.get() = Gaudi::svcLocator()->service<IClassIDSvc>( "ClassIDSvc" ).get();
63  };
64 }
65 
67  std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
68 
70  m_clid = 0;
71  m_className = "UNKNOWN_CLASS:" + m_className;
72  }
73 }
74 
76  std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
77 
79  m_className = "UNKNOW_CLID:" + std::to_string( m_clid );
80  }
81 }
82 
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"
94  return ( d.m_clid != 0 || !d.m_className.empty() ) ? toStream( std::tie( d.m_className, d.m_key ), os )
95  : toStream( d.m_key, os );
96 }
97 
99  return ( m_clid == 0 && m_className.empty() ) ? m_key : ( m_className + '/' + m_key );
100 }
101 
103  return Gaudi::Utils::toString( v );
104 }
105 
107  const std::string& s ) {
109  if ( !Gaudi::Parsers::parse_( c, s ).isSuccess() ) {
110  throw std::invalid_argument( "cannot parse '" + s + "' to DataObjIDColl" );
111  }
112  return c;
113 }
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)
T front(T... args)
qi::rule< Iterator, DataObjID(), Skipper > result
Definition: DataObjID.cpp:49
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:37
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:98
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:50
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:48
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:92
std::size_t m_hash
Definition: DataObjID.h:81
Grammar_< Iterator, std::string, Skipper >::Grammar gaudi_style
Definition: DataObjID.cpp:46
Grammar_< Iterator, std::pair< unsigned int, std::string >, Skipper >::Grammar atlas1_style
Definition: DataObjID.cpp:47
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:56
T ref(T... args)
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:28
T back(T... args)
string s
Definition: gaudirun.py:328
bool isFailure() const
Definition: StatusCode.h:141
void operator()(DataObjID &dest, const std::string &arg) const
Definition: DataObjID.cpp:40
implementation of various functions for streaming.
void setClid()
Definition: DataObjID.cpp:66
void setClassName()
Definition: DataObjID.cpp:75
std::string m_className
Definition: DataObjID.h:84
STL class.
void hashGen()
Definition: DataObjID.cpp:83
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1