| The Gaudi Framework v28r2p1 (f1a77ff4)

- 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 <sstream>
4 #include <map>
5 #include <boost/tokenizer.hpp>
6 #include <boost/algorithm/string.hpp>
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 namespace Parsers {
17
18 StatusCode
19 parse(DataObjID& v, const std::string& s) {
20 // default values
21 StatusCode sc(StatusCode::FAILURE);
22 std::string prop;
23 sc = Gaudi::Parsers::parse(prop, s);
24
25 if (sc.isSuccess()) {
26 //split the string in 1 or 2 words:
27 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
28 boost::char_separator<char> sep("(), ");
29 tokenizer tokens(prop, sep);
30 int nToks(distance(tokens.begin(), tokens.end()));
31 auto it = tokens.begin();
32
33 if (nToks == 1) {
34 // Gaudi style /path/to/object
35 std::string k = *it;
36 boost::erase_all(k,"'");
37 v = DataObjID( k );
38
39 } else if (nToks == 2) {
40 // ATLAS style (clid, 'key') or ('ClassName', 'key')
41 CLID c(0);
42 std::string cn(*it);
43 DataObjID id;
44
45 try {
46 c = std::stoi(*it);
47 } catch (const std::invalid_argument& /*e*/) {
48 // not a number
49 boost::erase_all(cn,"'");
50 c = 0;
51 }
52
53 ++it;
54 std::string k = *it;
55 boost::erase_all(k,"'");
56 ++it;
57
58 if ( c != 0) {
59 v = DataObjID(c,k);
60 } else {
61 v = DataObjID(cn,k);
62 }
63 } else {
64 std::cerr << "Unable to instantiate a DataObjID from a Property " << s
65 << " :: Format is bad" << std::endl;
66 sc = StatusCode::FAILURE;
67 return sc;
68 }
69
70 }
71 return sc;
72 }
73
74 //---------------------------------------------------------------------------
75
76 StatusCode
77 parse (DataObjIDColl& v, const std::string& s) {
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
142
143 } //> ns Parsers
144
145 namespace Utils {
146
147 std::ostream&
148 toStream(const DataObjID& v, std::ostream& o) {
149 if (v.clid() == 0) {
150 o << "'" << v.key() << "'";
151 } else {
152 o << "(" << v.clid() << ",'" << v.key() << "')";
153 }
154 return o;
155 }
156
157 std::ostream&
158 toStream(const DataObjIDColl& v, std::ostream& o) {
159 o << "[";
160 for (auto &i : v) {
161 toStream(i,o);
162 o << ",";
163 }
164 o << "]";
165 return o;
166 }
167
168 } //> ns Utils
169
170 } //> ns Gaudi
171
172 //---------------------------------------------------------------------------
173
174 DataObjIDProperty::DataObjIDProperty( const std::string& name,
175 DataObjID& ref )
176 : PropertyWithHandlers( name, typeid( DataObjID ) ),
177 m_pValue( &ref )
178 {}
179
180 //---------------------------------------------------------------------------
181
182 DataObjIDProperty::~DataObjIDProperty()
183 {}
184
185 //---------------------------------------------------------------------------
186
187 StatusCode
188 DataObjIDProperty::fromString(const std::string& s)
189 {
190 if (!Gaudi::Parsers::parse(*m_pValue, s).isSuccess()) {
191 return StatusCode::FAILURE;
192 }
193 return useUpdateHandler()
194 ? StatusCode::SUCCESS
195 : StatusCode::FAILURE;
196 }
197
198 //---------------------------------------------------------------------------
199
200 bool
201 DataObjIDProperty::setValue( const DataObjID& value )
202 {
203 m_pValue->operator=(value);
204 return useUpdateHandler();
205 }
206
207 //---------------------------------------------------------------------------
208
209 std::string
210 DataObjIDProperty::toString( ) const
211 {
212 useReadHandler();
213 std::ostringstream o;
214 Gaudi::Utils::toStream(*m_pValue, o);
215 return o.str();
216 }
217
218 //---------------------------------------------------------------------------
219 void
220 DataObjIDProperty::toStream(std::ostream& out) const
221 {
222 useReadHandler();
223 out << this->toString();
224 }
225
226
227 //---------------------------------------------------------------------------
228 //---------------------------------------------------------------------------
229
230 DataObjIDCollProperty::DataObjIDCollProperty( const std::string& name,
231 DataObjIDColl& ref )
232 : PropertyWithHandlers( name, typeid( DataObjIDColl ) ),
233 m_pValue( &ref )
234 {}
235
236 //---------------------------------------------------------------------------
237
238 DataObjIDCollProperty::~DataObjIDCollProperty()
239 {}
240
241 //---------------------------------------------------------------------------
242
243 StatusCode
244 DataObjIDCollProperty::fromString(const std::string& s)
245 {
246 if (!Gaudi::Parsers::parse(*m_pValue, s).isSuccess()) {
247 return StatusCode::FAILURE;
248 }
249 return useUpdateHandler()
250 ? StatusCode::SUCCESS
251 : StatusCode::FAILURE;
252 }
253
254 //---------------------------------------------------------------------------
255
256 bool
257 DataObjIDCollProperty::setValue( const DataObjIDColl& value )
258 {
259 m_pValue->operator=(value);
260 return useUpdateHandler();
261 }
262
263 //---------------------------------------------------------------------------
264
265 std::string
266 DataObjIDCollProperty::toString( ) const
267 {
268 useReadHandler();
269 std::ostringstream o;
270 Gaudi::Utils::toStream(*m_pValue, o);
271 return o.str();
272 }
273
274 //---------------------------------------------------------------------------
275 void
276 DataObjIDCollProperty::toStream(std::ostream& out) const
277 {
278 useReadHandler();
279 out << this->toString();
280 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
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:315
DataObjIDProperty::DataObjIDProperty
DataObjIDProperty(const std::string &name, DataObjID &ref)
Definition: DataObjIDProperty.cpp:174
gaudirun.c
c
Definition: gaudirun.py:391
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
StatusCode::FAILURE
Definition: StatusCode.h:29
DataObjID
Definition: DataObjID.h:38
DataObjIDCollProperty::toStream
void toStream(std::ostream &out) const override
value -> stream
Definition: DataObjIDProperty.cpp:276
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:74
std::endl
T endl(T...args)
DataObjIDProperty::toString
std::string toString() const override
value -> string
Definition: DataObjIDProperty.cpp:210
DataObjIDProperty::setValue
bool setValue(const DataObjID &value)
Definition: DataObjIDProperty.cpp:201
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:11
DataObjIDCollProperty::toString
std::string toString() const override
value -> string
Definition: DataObjIDProperty.cpp:266
DataObjIDProperty::~DataObjIDProperty
~DataObjIDProperty() override
Definition: DataObjIDProperty.cpp:182
DataObjIDCollProperty::fromString
StatusCode fromString(const std::string &s) override
string -> value
Definition: DataObjIDProperty.cpp:244
PropertyWithHandlers
Helper class to simplify the migration old properties deriving directly from PropertyBase.
Definition: Property.h:751
std::string
STL class.
compareRootHistos.ref
string ref
Definition: compareRootHistos.py:14
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:257
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
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:188
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:777
PropertyWithHandlers<>::useUpdateHandler
bool useUpdateHandler() override
use the call-back function at update, if available
Definition: Property.h:780
DataObjIDCollProperty::~DataObjIDCollProperty
virtual ~DataObjIDCollProperty()
Definition: DataObjIDProperty.cpp:238
Gaudi::Parsers
Definition: DODBasicMapper.cpp:7
std::unordered_set::emplace
T emplace(T...args)
gaudirun.s
string s
Definition: gaudirun.py:245
DataObjIDCollProperty::m_pValue
DataObjIDColl * m_pValue
Pointer to the real property.
Definition: DataObjIDProperty.h:108
Gaudi::Utils
Definition: Fill.h:24
DataObjIDCollProperty::value
const DataObjIDColl & value() const
Definition: DataObjIDProperty.h:170
DataObjIDProperty::toStream
void toStream(std::ostream &out) const override
value -> stream
Definition: DataObjIDProperty.cpp:220
DataObjIDCollProperty::DataObjIDCollProperty
DataObjIDCollProperty(const std::string &name, DataObjIDColl &ref)
Definition: DataObjIDProperty.cpp:230
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.