| The Gaudi Framework v32r1 (f65d50dc)

DataObjID.cpp
Go to the documentation of this file.
1 #include "GaudiKernel/DataObjID.h"
2 #include "GaudiKernel/Bootstrap.h"
3 #include "GaudiKernel/IClassIDSvc.h"
4 #include "GaudiKernel/ISvcLocator.h"
5 #include <Gaudi/Parsers/Factory.h>
6 #include <functional>
7 #include <iomanip>
8 #include <iostream>
9
10 namespace {
11 std::string quote( const std::string& in ) {
12 if ( !in.empty() && in.front() == in.back() && ( in.front() == '\'' || in.front() == '\"' ) ) return in;
13 std::stringstream s;
14 s << std::quoted( in );
15 return s.str();
16 }
17 } // namespace
18
19 namespace Gaudi {
20 namespace Parsers {
21
22 template <typename Iterator, typename Skipper>
23 struct DataObjIDGrammar : qi::grammar<Iterator, DataObjID(), Skipper> {
24 using ResultT = DataObjID;
25 struct Operations {
26 template <typename ClassID>
27 void operator()( DataObjID& dest, const std::pair<ClassID, std::string>& arg ) const {
28 dest = {arg.first, arg.second};
29 }
30 void operator()( DataObjID& dest, const std::string& arg ) const { dest = {arg}; }
31 };
32 DataObjIDGrammar() : DataObjIDGrammar::base_type( result ) {
33 result = atlas1_style[op( qi::_val, qi::_1 )] | atlas2_style[op( qi::_val, qi::_1 )] |
34 gaudi_style[op( qi::_val, qi::_1 )];
35 }
36 typename Grammar_<Iterator, std::string, Skipper>::Grammar gaudi_style;
37 typename Grammar_<Iterator, std::pair<unsigned int, std::string>, Skipper>::Grammar atlas1_style;
38 typename Grammar_<Iterator, std::pair<std::string, std::string>, Skipper>::Grammar atlas2_style;
39 qi::rule<Iterator, DataObjID(), Skipper> result;
40 ph::function<Operations> op;
41 };
42 REGISTER_GRAMMAR( DataObjID, DataObjIDGrammar );
43 } // namespace Parsers
44 } // namespace Gaudi
45
46 StatusCode parse( DataObjID& dest, const std::string& src ) { return Gaudi::Parsers::parse_( dest, quote( src ) ); }
47
48 IClassIDSvc* DataObjID::p_clidSvc( nullptr );
49 std::once_flag DataObjID::m_ip;
50 namespace {
51 auto getClidSvc = []( std::reference_wrapper<IClassIDSvc*> p ) {
52 p.get() = Gaudi::svcLocator()->service<IClassIDSvc>( "ClassIDSvc" ).get();
53 };
54 }
55
56 void DataObjID::setClid() {
57 std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
58
59 if ( !p_clidSvc || p_clidSvc->getIDOfTypeName( m_className, m_clid ).isFailure() ) {
60 m_clid = 0;
61 m_className = "UNKNOWN_CLASS:" + m_className;
62 }
63 }
64
65 void DataObjID::setClassName() {
66 std::call_once( m_ip, getClidSvc, std::ref( p_clidSvc ) );
67
68 if ( !p_clidSvc || p_clidSvc->getTypeNameOfID( m_clid, m_className ).isFailure() ) {
69 m_className = "UNKNOW_CLID:" + std::to_string( m_clid );
70 }
71 }
72
73 void DataObjID::hashGen() {
74 m_hash = ( std::hash<std::string>()( m_key ) );
75 if ( m_clid != 0 ) {
76 // this is a bit redundant since hash<int> is a pass-through
77 m_hash ^= ( std::hash<CLID>()( m_clid ) << 1 );
78 }
79 }
80
81 #include "GaudiKernel/ToStream.h"
82 std::ostream& toStream( const DataObjID& d, std::ostream& os ) {
83 using Gaudi::Utils::toStream;
84 return ( d.m_clid != 0 || !d.m_className.empty() ) ? toStream( std::tie( d.m_className, d.m_key ), os )
85 : toStream( d.m_key, os );
86 }
87
88 std::string DataObjID::fullKey() const {
89 return ( m_clid == 0 && m_className.empty() ) ? m_key : ( m_className + '/' + m_key );
90 }
91
92 std::string Gaudi::Details::Property::StringConverter<DataObjIDColl>::toString( const DataObjIDColl& v ) {
93 return Gaudi::Utils::toString( v );
94 }
95
96 DataObjIDColl Gaudi::Details::Property::StringConverter<DataObjIDColl>::fromString( const DataObjIDColl&,
97 const std::string& s ) {
98 DataObjIDColl c;
99 if ( !Gaudi::Parsers::parse_( c, s ).isSuccess() ) {
100 throw std::invalid_argument( "cannot parse '" + s + "' to DataObjIDColl" );
101 }
102 return c;
103 }
Gaudi::Parsers::DataObjIDGrammar
Definition: DataObjID.cpp:23
Gaudi::Details::Property::DefaultStringConverter::fromString
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:202
std::string::empty
T empty(T... args)
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:284
gaudirun.c
c
Definition: gaudirun.py:487
Gaudi::Parsers::parse_
StatusCode parse_(ResultT &result, const std::string &input)
Definition: Factory.h:29
std::tie
T tie(T... args)
DataObjID
Definition: DataObjID.h:37
Gaudi::Parsers::REGISTER_GRAMMAR
REGISTER_GRAMMAR(std::string, StringGrammar)
std::string::front
T front(T... args)
Gaudi::Parsers::DataObjIDGrammar::result
qi::rule< Iterator, DataObjID(), Skipper > result
Definition: DataObjID.cpp:39
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:334
std::to_string
T to_string(T... args)
Gaudi::Parsers::DataObjIDGrammar::Operations::operator()
void operator()(DataObjID &dest, const std::pair< ClassID, std::string > &arg) const
Definition: DataObjID.cpp:27
DataObjID::p_clidSvc
static IClassIDSvc * p_clidSvc
Definition: DataObjID.h:76
Bootstrap.h
Gaudi::Details::Property::DefaultStringConverterImpl::toString
std::string toString(const TYPE &v)
Definition: Property.h:169
DataObjID::m_key
std::string m_key
Definition: DataObjID.h:73
std::once_flag
std::call_once
T call_once(T... args)
std::stringstream
STL class.
DataObjID::fullKey
std::string fullKey() const
Definition: DataObjID.cpp:88
IClassIDSvc::getIDOfTypeName
virtual StatusCode getIDOfTypeName(const std::string &typeName, CLID &id) const =0
get id associated with type name (if any)
std::string
STL class.
DataObjID::m_ip
static std::once_flag m_ip
Definition: DataObjID.h:77
IClassIDSvc
interface to the CLID database
Definition: IClassIDSvc.h:22
Gaudi::Parsers::DataObjIDGrammar::op
ph::function< Operations > op
Definition: DataObjID.cpp:40
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:76
IClassIDSvc.h
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
IClassIDSvc::getTypeNameOfID
virtual StatusCode getTypeNameOfID(const CLID &id, std::string &typeName) const =0
get user assigned type name associated with clID
std::hash
gaudirun.dest
dest
Definition: gaudirun.py:201
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
DataObjID::m_clid
CLID m_clid
Definition: DataObjID.h:70
Gaudi::Parsers::Grammar_
Definition: Grammars.h:58
Gaudi::Parsers::DataObjIDGrammar::Operations
Definition: DataObjID.cpp:25
Gaudi::Parsers::DataObjIDGrammar::atlas2_style
Grammar_< Iterator, std::pair< std::string, std::string >, Skipper >::Grammar atlas2_style
Definition: DataObjID.cpp:38
std::unordered_set< DataObjID, DataObjID_Hasher >
toStream
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:82
DataObjID::m_hash
std::size_t m_hash
Definition: DataObjID.h:71
Gaudi::Parsers::SkipperGrammar
Definition: Grammar.h:41
Gaudi::Parsers::DataObjIDGrammar::gaudi_style
Grammar_< Iterator, std::string, Skipper >::Grammar gaudi_style
Definition: DataObjID.cpp:36
DataObjID.h
Gaudi::Parsers::DataObjIDGrammar::atlas1_style
Grammar_< Iterator, std::pair< unsigned int, std::string >, Skipper >::Grammar atlas1_style
Definition: DataObjID.cpp:37
std::pair
parse
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:46
Gaudi::Functional::details::get
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
Definition: FunctionalDetails.h:332
Gaudi::Parsers::DataObjIDGrammar::DataObjIDGrammar
DataObjIDGrammar()
Definition: DataObjID.cpp:32
std::ref
T ref(T... args)
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:18
std::reference_wrapper
std::string::back
T back(T... args)
gaudirun.s
string s
Definition: gaudirun.py:316
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
Gaudi::Parsers::DataObjIDGrammar::Operations::operator()
void operator()(DataObjID &dest, const std::string &arg) const
Definition: DataObjID.cpp:30
ToStream.h
implementation of various functions for streaming.
DataObjID::setClid
void setClid()
Definition: DataObjID.cpp:56
DataObjID::setClassName
void setClassName()
Definition: DataObjID.cpp:65
DataObjID::m_className
std::string m_className
Definition: DataObjID.h:74
std::ostream
STL class.
ISvcLocator.h
Factory.h
DataObjID::hashGen
void hashGen()
Definition: DataObjID.cpp:73
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
std::invalid_argument
STL class.