| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

DataObjIDProperty.cpp
Go to the documentation of this file.
1
2 // stl includes
3 #include <boost/algorithm/string.hpp>
4 #include <boost/tokenizer.hpp>
5 #include <map>
6 #include <sstream>
7
8 // StoreGate includes
9 #include "GaudiKernel/DataObjIDProperty.h"
10
11 using namespace Gaudi;
12 using namespace Gaudi::Parsers;
13 using namespace Gaudi::Utils;
14
15 namespace Gaudi
16 {
17 namespace Parsers
18 {
19
20 StatusCode parse( DataObjID& v, const std::string& s )
21 {
22 // default values
23 StatusCode sc( StatusCode::FAILURE );
24 std::string prop;
25 sc = Gaudi::Parsers::parse( prop, s );
26
27 if ( sc.isSuccess() ) {
28 // split the string in 1 or 2 words:
29 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
30 boost::char_separator<char> sep( "(), " );
31 tokenizer tokens( prop, sep );
32 int nToks( distance( tokens.begin(), tokens.end() ) );
33 auto it = tokens.begin();
34
35 if ( nToks == 1 ) {
36 // Gaudi style /path/to/object
37 std::string k = *it;
38 boost::erase_all( k, "'" );
39 v = DataObjID( k );
40
41 } else if ( nToks == 2 ) {
42 // ATLAS style (clid, 'key') or ('ClassName', 'key')
43 CLID c( 0 );
44 std::string cn( *it );
45 DataObjID id;
46
47 try {
48 c = std::stoi( *it );
49 } catch ( const std::invalid_argument& /*e*/ ) {
50 // not a number
51 boost::erase_all( cn, "'" );
52 c = 0;
53 }
54
55 ++it;
56 std::string k = *it;
57 boost::erase_all( k, "'" );
58 ++it;
59
60 if ( c != 0 ) {
61 v = DataObjID( c, k );
62 } else {
63 v = DataObjID( cn, k );
64 }
65 } else {
66 std::cerr << "Unable to instantiate a DataObjID from a Property " << s << " :: Format is bad" << std::endl;
67 sc = StatusCode::FAILURE;
68 return sc;
69 }
70 }
71 return sc;
72 }
73
74 //---------------------------------------------------------------------------
75
76 StatusCode parse( DataObjIDColl& v, const std::string& s )
77 {
78 // default values
79 StatusCode sc( StatusCode::FAILURE );
80 std::string prop;
81 sc = Gaudi::Parsers::parse( prop, s );
82
83 if ( sc.isSuccess() ) {
84
85 // Reset Collection
86 v.clear();
87
88 bool isGaudi( true );
89
90 // Gaudi style [ '/path/to/data', '/other/data' ] or
91 // ATLAS style [ ('ClassName', 'key') , (ClassID, 'key2') ]
92 if ( s.find( "(" ) != std::string::npos ) {
93 isGaudi = false;
94 }
95
96 // split the string in 1 or 2 words:
97 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
98 boost::char_separator<char> sep( "[](), " );
99 tokenizer tokens( prop, sep );
100 auto it = tokens.begin();
101
102 CLID c( 0 );
103 std::string cn;
104
105 while ( it != tokens.end() ) {
106
107 if ( isGaudi ) {
108
109 std::string k = *it;
110 boost::erase_all( k, "'" );
111 v.emplace( DataObjID( k ) );
112 ++it;
113
114 } else {
115
116 try {
117 c = std::stoi( *it );
118 } catch ( const std::invalid_argument& /*e*/ ) {
119 // class name, not ClassID
120 cn = *it;
121 boost::erase_all( cn, "'" );
122 c = 0;
123 }
124
125 ++it;
126 std::string k = *it;
127 boost::erase_all( k, "'" );
128 ++it;
129
130 if ( c != 0 ) {
131 v.emplace( DataObjID( c, k ) );
132 } else {
133 v.emplace( DataObjID( cn, k ) );
134 }
135 }
136 }
137 }
138 return sc;
139 }
140
141 } //> ns Parsers
142
143 namespace Utils
144 {
145
146 std::ostream& toStream( const DataObjID& v, std::ostream& o )
147 {
148 if ( v.clid() == 0 ) {
149 o << "'" << v.key() << "'";
150 } else {
151 o << "(" << v.clid() << ",'" << v.key() << "')";
152 }
153 return o;
154 }
155
156 std::ostream& toStream( const DataObjIDColl& v, std::ostream& o )
157 {
158 o << "[";
159 for ( auto& i : v ) {
160 toStream( i, o );
161 o << ",";
162 }
163 o << "]";
164 return o;
165 }
166
167 } //> ns Utils
168
169 } //> ns Gaudi
170
171 //---------------------------------------------------------------------------
172
173 DataObjIDProperty::DataObjIDProperty( const std::string& name, DataObjID& ref )
174 : PropertyWithHandlers( name, typeid( DataObjID ) ), m_pValue( &ref )
175 {
176 }
177
178 //---------------------------------------------------------------------------
179
180 DataObjIDProperty::~DataObjIDProperty() {}
181
182 //---------------------------------------------------------------------------
183
184 StatusCode DataObjIDProperty::fromString( const std::string& s )
185 {
186 if ( !Gaudi::Parsers::parse( *m_pValue, s ).isSuccess() ) {
187 return StatusCode::FAILURE;
188 }
189 return useUpdateHandler() ? StatusCode::SUCCESS : StatusCode::FAILURE;
190 }
191
192 //---------------------------------------------------------------------------
193
194 bool DataObjIDProperty::setValue( const DataObjID& value )
195 {
196 m_pValue->operator=( value );
197 return useUpdateHandler();
198 }
199
200 //---------------------------------------------------------------------------
201
202 std::string DataObjIDProperty::toString() const
203 {
204 useReadHandler();
205 std::ostringstream o;
206 Gaudi::Utils::toStream( *m_pValue, o );
207 return o.str();
208 }
209
210 //---------------------------------------------------------------------------
211 void DataObjIDProperty::toStream( std::ostream& out ) const
212 {
213 useReadHandler();
214 out << this->toString();
215 }
216
217 //---------------------------------------------------------------------------
218 //---------------------------------------------------------------------------
219
220 DataObjIDCollProperty::DataObjIDCollProperty( const std::string& name, DataObjIDColl& ref )
221 : PropertyWithHandlers( name, typeid( DataObjIDColl ) ), m_pValue( &ref )
222 {
223 }
224
225 //---------------------------------------------------------------------------
226
227 DataObjIDCollProperty::~DataObjIDCollProperty() {}
228
229 //---------------------------------------------------------------------------
230
231 StatusCode DataObjIDCollProperty::fromString( const std::string& s )
232 {
233 if ( !Gaudi::Parsers::parse( *m_pValue, s ).isSuccess() ) {
234 return StatusCode::FAILURE;
235 }
236 return useUpdateHandler() ? StatusCode::SUCCESS : StatusCode::FAILURE;
237 }
238
239 //---------------------------------------------------------------------------
240
241 bool DataObjIDCollProperty::setValue( const DataObjIDColl& value )
242 {
243 m_pValue->operator=( value );
244 return useUpdateHandler();
245 }
246
247 //---------------------------------------------------------------------------
248
249 std::string DataObjIDCollProperty::toString() const
250 {
251 useReadHandler();
252 std::ostringstream o;
253 Gaudi::Utils::toStream( *m_pValue, o );
254 return o.str();
255 }
256
257 //---------------------------------------------------------------------------
258 void DataObjIDCollProperty::toStream( std::ostream& out ) const
259 {
260 useReadHandler();
261 out << this->toString();
262 }
StatusCode::SUCCESS
Definition: StatusCode.h:31
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:293
DataObjIDProperty::DataObjIDProperty
DataObjIDProperty(const std::string &name, DataObjID &ref)
Definition: DataObjIDProperty.cpp:173
gaudirun.c
c
Definition: gaudirun.py:407
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
StatusCode::FAILURE
Definition: StatusCode.h:31
DataObjID
Definition: DataObjID.h:37
DataObjIDCollProperty::toStream
void toStream(std::ostream &out) const override
value -> stream
Definition: DataObjIDProperty.cpp:258
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: Property.h:40
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
std::endl
T endl(T...args)
DataObjIDProperty::toString
std::string toString() const override
value -> string
Definition: DataObjIDProperty.cpp:202
DataObjIDProperty::setValue
bool setValue(const DataObjID &value)
Definition: DataObjIDProperty.cpp:194
Gaudi::Parsers::parse
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
Definition: DODBasicMapper.cpp:13
DataObjIDCollProperty::toString
std::string toString() const override
value -> string
Definition: DataObjIDProperty.cpp:249
DataObjIDProperty::~DataObjIDProperty
~DataObjIDProperty() override
Definition: DataObjIDProperty.cpp:180
DataObjIDCollProperty::fromString
StatusCode fromString(const std::string &s) override
string -> value
Definition: DataObjIDProperty.cpp:231
PropertyWithHandlers
Helper class to simplify the migration old properties deriving directly from PropertyBase.
Definition: Property.h:786
std::string
STL class.
compareRootHistos.ref
string ref
Definition: compareRootHistos.py:14
GaudiMath::Interpolation::toStream
std::ostream & toStream(const Type &, std::ostream &)
Definition: Interpolation.cpp:47
DataObjIDProperty::m_pValue
DataObjID * m_pValue
Pointer to the real property.
Definition: DataObjIDProperty.h:46
DataObjID::clid
CLID clid() const
Definition: DataObjID.h:54
DataObjIDCollProperty::setValue
bool setValue(const DataObjIDColl &value)
Definition: DataObjIDProperty.cpp:241
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
std::ostringstream
STL class.
DataObjID::key
const std::string & key() const
Definition: DataObjID.h:49
DataObjIDProperty::fromString
StatusCode fromString(const std::string &s) override
string -> value
Definition: DataObjIDProperty.cpp:184
std::ostringstream::str
T str(T...args)
std::unordered_set< DataObjID, DataObjID_Hasher >
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
std::unordered_set::clear
T clear(T...args)
DataObjIDProperty::value
const DataObjID & value() const
Definition: DataObjIDProperty.h:80
DataObjIDProperty.h
std::string::find
T find(T...args)
PropertyWithHandlers<>::useReadHandler
void useReadHandler() const
use the call-back function at reading, if available
Definition: Property.h:812
PropertyWithHandlers<>::useUpdateHandler
bool useUpdateHandler() override
use the call-back function at update, if available
Definition: Property.h:815
DataObjIDCollProperty::~DataObjIDCollProperty
virtual ~DataObjIDCollProperty()
Definition: DataObjIDProperty.cpp:227
Gaudi::Parsers
Definition: DODBasicMapper.cpp:8
std::unordered_set::emplace
T emplace(T...args)
gaudirun.s
string s
Definition: gaudirun.py:253
DataObjIDCollProperty::m_pValue
DataObjIDColl * m_pValue
Pointer to the real property.
Definition: DataObjIDProperty.h:108
Gaudi::Utils
Definition: Fill.h:26
DataObjIDCollProperty::value
const DataObjIDColl & value() const
Definition: DataObjIDProperty.h:171
DataObjIDProperty::toStream
void toStream(std::ostream &out) const override
value -> stream
Definition: DataObjIDProperty.cpp:211
DataObjIDCollProperty::DataObjIDCollProperty
DataObjIDCollProperty(const std::string &name, DataObjIDColl &ref)
Definition: DataObjIDProperty.cpp:220
std::cerr
std::stoi
T stoi(T...args)
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
std::invalid_argument
STL class.