The Gaudi Framework  master (37c0b60a)
DataObjID.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 <Gaudi/Parsers/Factory.h>
12 #include <GaudiKernel/Bootstrap.h>
13 #include <GaudiKernel/DataObjID.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, std::string_view 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 }
115 
117  return Gaudi::Utils::toString( v );
118 }
119 
121  const std::string& s ) {
123  if ( !Gaudi::Parsers::parse_( c, s ).isSuccess() ) {
124  throw std::invalid_argument( "cannot parse '" + s + "' to DataObjIDVector" );
125  }
126  return c;
127 }
std::call_once
T call_once(T... args)
IClassIDSvc::getIDOfTypeName
virtual StatusCode getIDOfTypeName(const std::string &typeName, CLID &id) const =0
get id associated with type name (if any)
Gaudi::Parsers::DataObjIDGrammar::Operations
Definition: DataObjID.cpp:36
IClassIDSvc.h
DataObjID::m_ip
static std::once_flag m_ip
Definition: DataObjID.h:93
std::string
STL class.
DataObjID::setClassName
void setClassName()
Definition: DataObjID.cpp:76
std::unordered_set< DataObjID, DataObjID_Hasher >
std::pair
Gaudi::Parsers::DataObjIDGrammar::gaudi_style
Grammar_< Iterator, std::string, Skipper >::Grammar gaudi_style
Definition: DataObjID.cpp:47
gaudirun.s
string s
Definition: gaudirun.py:346
std::vector< DataObjID >
GaudiPartProp.decorators.get
get
decorate the vector of properties
Definition: decorators.py:283
std::stringstream
STL class.
Gaudi::Parsers::parse_
StatusCode parse_(ResultT &result, std::string_view input)
Definition: Factory.h:39
gaudirun.c
c
Definition: gaudirun.py:525
DataObjID.h
ToStream.h
Gaudi::Parsers::DataObjIDGrammar::atlas1_style
Grammar_< Iterator, std::pair< unsigned int, std::string >, Skipper >::Grammar atlas1_style
Definition: DataObjID.cpp:48
DataObjID::fullKey
std::string fullKey() const
combination of the key and the ClassName, mostly for debugging
Definition: DataObjID.cpp:99
std::tie
T tie(T... args)
std::once_flag
Gaudi::Parsers::DataObjIDGrammar::Operations::operator()
void operator()(DataObjID &dest, const std::pair< ClassID, std::string > &arg) const
Definition: DataObjID.cpp:38
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
Gaudi::Parsers::DataObjIDGrammar::DataObjIDGrammar
DataObjIDGrammar()
Definition: DataObjID.cpp:43
DataObjID::m_className
std::string m_className
Definition: DataObjID.h:90
std::reference_wrapper
StatusCode
Definition: StatusCode.h:65
std::ostream
STL class.
Gaudi::Details::Property::DefaultStringConverter< TYPE >::fromString
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:85
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:98
std::to_string
T to_string(T... args)
Gaudi::Parsers::SkipperGrammar
Definition: Grammar.h:51
std::invalid_argument
STL class.
Gaudi::Parsers::DataObjIDGrammar::atlas2_style
Grammar_< Iterator, std::pair< std::string, std::string >, Skipper >::Grammar atlas2_style
Definition: DataObjID.cpp:49
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
DataObjID
Definition: DataObjID.h:47
gaudirun.dest
dest
Definition: gaudirun.py:224
Factory.h
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:353
toStream
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:93
DataObjID::m_clid
CLID m_clid
Definition: DataObjID.h:86
DataObjID::hashGen
void hashGen()
Definition: DataObjID.cpp:84
Gaudi::Parsers::REGISTER_GRAMMAR
REGISTER_GRAMMAR(std::string, StringGrammar)
Gaudi::Parsers::DataObjIDGrammar::Operations::operator()
void operator()(DataObjID &dest, const std::string &arg) const
Definition: DataObjID.cpp:41
parse
StatusCode parse(DataObjID &dest, std::string_view src)
Definition: DataObjID.cpp:57
Gaudi::Parsers::Grammar_
Definition: Grammars.h:68
DataObjID::m_hash
std::size_t m_hash
Definition: DataObjID.h:87
Gaudi::Parsers::DataObjIDGrammar::op
ph::function< Operations > op
Definition: DataObjID.cpp:51
Gaudi::Utils::toStream
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:299
DataObjID::m_key
std::string m_key
Definition: DataObjID.h:89
DataObjID::p_clidSvc
static IClassIDSvc * p_clidSvc
Definition: DataObjID.h:92
Bootstrap.h
std::string::empty
T empty(T... args)
Properties.v
v
Definition: Properties.py:122
DataObjID::setClid
void setClid()
Definition: DataObjID.cpp:67
Gaudi::Parsers::DataObjIDGrammar::result
qi::rule< Iterator, DataObjID(), Skipper > result
Definition: DataObjID.cpp:50
IClassIDSvc::getTypeNameOfID
virtual StatusCode getTypeNameOfID(const CLID &id, std::string &typeName) const =0
get user assigned type name associated with clID
ISvcLocator.h
IClassIDSvc
interface to the CLID database
Definition: IClassIDSvc.h:25
Gaudi::Details::Property::DefaultStringConverterImpl::toString
std::string toString(const TYPE &v)
Definition: Property.h:51
Gaudi::Parsers::DataObjIDGrammar
Definition: DataObjID.cpp:34
std::ref
T ref(T... args)
std::hash
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:28