The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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\***********************************************************************************/
17#include <functional>
18#include <iomanip>
19#include <iostream>
20
21namespace {
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 };
25 std::stringstream s;
26 s << std::quoted( in );
27 return s.str();
28 }
29} // namespace
30
31namespace Gaudi {
32 namespace Parsers {
33
34 template <typename Iterator, typename Skipper>
35 struct DataObjIDGrammar : qi::grammar<Iterator, DataObjID(), Skipper> {
37 struct Operations {
38 template <typename ClassID>
39 void operator()( DataObjID& dest, const std::pair<ClassID, std::string>& arg ) const {
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
58StatusCode parse( DataObjID& dest, std::string_view src ) { return Gaudi::Parsers::parse_( dest, quote( src ) ); }
59
60namespace {
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
77 m_hash = ( std::hash<std::string>()( m_key ) );
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
84std::ostream& toStream( const DataObjID& d, std::ostream& os ) {
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
90const std::string& DataObjID::className() const {
91
92 // Set class name once if not done already
93 if ( m_clid != 0 && m_className.empty() ) {
94 std::call_once( m_setClassName, [&]() {
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
103std::string DataObjID::fullKey() const {
104 return ( m_clid == 0 && m_className.empty() ) ? m_key : ( className() + '/' + m_key );
105}
106
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
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::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition DataObjID.cpp:84
StatusCode parse(DataObjID &dest, std::string_view src)
Definition DataObjID.cpp:58
std::unordered_set< DataObjID, DataObjID_Hasher > DataObjIDColl
Definition DataObjID.h:121
std::vector< DataObjID > DataObjIDVector
Definition DataObjID.h:122
#define REGISTER_GRAMMAR(ResultType, GrammarName)
Definition Grammars.h:71
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition Iterator.h:18
implementation of various functions for streaming.
void setClid()
Definition DataObjID.cpp:68
std::size_t m_hash
Definition DataObjID.h:93
std::string fullKey() const
combination of the key and the ClassName, mostly for debugging
void hashGen()
Definition DataObjID.cpp:76
const std::string & className() const
return the ClassName (if available)
Definition DataObjID.cpp:90
std::string m_key
Definition DataObjID.h:95
std::once_flag m_setClassName
Definition DataObjID.h:97
CLID m_clid
Definition DataObjID.h:92
DataObjID()=default
std::string m_className
Definition DataObjID.h:96
interface to the CLID database
Definition IClassIDSvc.h:24
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
SkipperGrammar< IteratorT > Skipper
Definition Factory.h:24
StatusCode parse_(ResultT &result, std::string_view input)
Definition Factory.h:26
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition ToStream.h:326
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:304
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
GAUDI_API ISvcLocator * svcLocator()
virtual TYPE fromString(const TYPE &ref_value, const std::string &s)=0
void operator()(DataObjID &dest, const std::pair< ClassID, std::string > &arg) const
Definition DataObjID.cpp:39
void operator()(DataObjID &dest, const std::string &arg) const
Definition DataObjID.cpp:42
Grammar_< Iterator, std::string, Skipper >::Grammar gaudi_style
Definition DataObjID.cpp:48
Grammar_< Iterator, std::pair< unsignedint, std::string >, Skipper >::Grammar atlas1_style
Definition DataObjID.cpp:49
qi::rule< Iterator, DataObjID(), Skipper > result
Definition DataObjID.cpp:51
ph::function< Operations > op
Definition DataObjID.cpp:52
Grammar_< Iterator, std::pair< std::string, std::string >, Skipper >::Grammar atlas2_style
Definition DataObjID.cpp:50