Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (f31105fd)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
DataObjID.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 <GaudiKernel/ToStream.h>
17 #include <functional>
18 #include <iomanip>
19 #include <iostream>
20 
21 namespace {
22  std::string quote( std::string_view in ) {
23  if ( !in.empty() && in.front() == in.back() && ( in.front() == '\'' || in.front() == '\"' ) )
24  return std::string{ in };
26  s << std::quoted( in );
27  return s.str();
28  }
29 } // namespace
30 
31 namespace Gaudi {
32  namespace Parsers {
33 
34  template <typename Iterator, typename Skipper>
35  struct DataObjIDGrammar : qi::grammar<Iterator, DataObjID(), Skipper> {
36  using ResultT = DataObjID;
37  struct Operations {
38  template <typename ClassID>
40  dest = { arg.first, arg.second };
41  }
42  void operator()( DataObjID& dest, const std::string& arg ) const { dest = { arg }; }
43  };
45  result = atlas1_style[op( qi::_val, qi::_1 )] | atlas2_style[op( qi::_val, qi::_1 )] |
46  gaudi_style[op( qi::_val, qi::_1 )];
47  }
52  ph::function<Operations> op;
53  };
55  } // namespace Parsers
56 } // namespace Gaudi
57 
58 StatusCode parse( DataObjID& dest, std::string_view src ) { return Gaudi::Parsers::parse_( dest, quote( src ) ); }
59 
60 namespace {
62  IClassIDSvc* getClidSvc() {
63  static IClassIDSvc* clidSvc = Gaudi::svcLocator()->service<IClassIDSvc>( "ClassIDSvc" ).get();
64  return clidSvc;
65  };
66 } // namespace
67 
69 
70  if ( !getClidSvc() || getClidSvc()->getIDOfTypeName( m_className, m_clid ).isFailure() ) {
71  m_clid = 0;
72  m_className = "UNKNOWN_CLASS:" + m_className;
73  }
74 }
75 
78  if ( m_clid != 0 ) {
79  // this is a bit redundant since hash<int> is a pass-through
80  m_hash ^= ( std::hash<CLID>()( m_clid ) << 1 );
81  }
82 }
83 
86  return ( d.m_clid != 0 || !d.className().empty() ) ? toStream( std::tie( d.className(), d.m_key ), os )
87  : toStream( d.m_key, os );
88 }
89 
91 
92  // Set class name once if not done already
93  if ( m_clid != 0 && m_className.empty() ) {
95  if ( !getClidSvc() || getClidSvc()->getTypeNameOfID( m_clid, m_className ).isFailure() ) {
96  m_className = "UNKNOWN_CLID:" + std::to_string( m_clid );
97  }
98  } );
99  }
100  return m_className;
101 }
102 
104  return ( m_clid == 0 && m_className.empty() ) ? m_key : ( className() + '/' + m_key );
105 }
106 
108  return Gaudi::Utils::toString( v );
109 }
110 
112  const std::string& s ) {
114  if ( !Gaudi::Parsers::parse_( c, s ).isSuccess() ) {
115  throw std::invalid_argument( "cannot parse '" + s + "' to DataObjIDColl" );
116  }
117  return c;
118 }
119 
121  return Gaudi::Utils::toString( v );
122 }
123 
125  const std::string& s ) {
127  if ( !Gaudi::Parsers::parse_( c, s ).isSuccess() ) {
128  throw std::invalid_argument( "cannot parse '" + s + "' to DataObjIDVector" );
129  }
130  return c;
131 }
std::call_once
T call_once(T... args)
Gaudi::Parsers::DataObjIDGrammar::Operations
Definition: DataObjID.cpp:37
IClassIDSvc.h
std::string
STL class.
std::unordered_set< DataObjID, DataObjID_Hasher >
std::pair
Gaudi::Parsers::DataObjIDGrammar::gaudi_style
Grammar_< Iterator, std::string, Skipper >::Grammar gaudi_style
Definition: DataObjID.cpp:48
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:49
DataObjID::fullKey
std::string fullKey() const
combination of the key and the ClassName, mostly for debugging
Definition: DataObjID.cpp:103
std::tie
T tie(T... args)
Gaudi::Parsers::DataObjIDGrammar::Operations::operator()
void operator()(DataObjID &dest, const std::pair< ClassID, std::string > &arg) const
Definition: DataObjID.cpp:39
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
Gaudi::Parsers::DataObjIDGrammar::DataObjIDGrammar
DataObjIDGrammar()
Definition: DataObjID.cpp:44
DataObjID::m_className
std::string m_className
Definition: DataObjID.h:98
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:53
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:50
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:48
gaudirun.dest
dest
Definition: gaudirun.py:224
Factory.h
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:357
toStream
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:84
DataObjID::m_clid
CLID m_clid
Definition: DataObjID.h:94
DataObjID::className
const std::string & className() const
return the ClassName (if available)
Definition: DataObjID.cpp:90
DataObjID::hashGen
void hashGen()
Definition: DataObjID.cpp:76
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:42
parse
StatusCode parse(DataObjID &dest, std::string_view src)
Definition: DataObjID.cpp:58
Gaudi::Parsers::Grammar_
Definition: Grammars.h:72
DataObjID::m_hash
std::size_t m_hash
Definition: DataObjID.h:95
Gaudi::Parsers::DataObjIDGrammar::op
ph::function< Operations > op
Definition: DataObjID.cpp:52
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:334
DataObjID::m_key
std::string m_key
Definition: DataObjID.h:97
Bootstrap.h
std::string::empty
T empty(T... args)
Properties.v
v
Definition: Properties.py:122
DataObjID::setClid
void setClid()
Definition: DataObjID.cpp:68
Gaudi::Parsers::DataObjIDGrammar::result
qi::rule< Iterator, DataObjID(), Skipper > result
Definition: DataObjID.cpp:51
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
DataObjID::m_setClassName
std::once_flag m_setClassName
Definition: DataObjID.h:99
Gaudi::Parsers::DataObjIDGrammar
Definition: DataObjID.cpp:35
std::hash< std::string >
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:28