| The Gaudi Framework v27r1

- 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 v.emplace( DataObjID( *it ) );
109 ++it;
110
111 } else {
112
113 try {
114 c = std::stoi(*it);
115 } catch (const std::invalid_argument& /*e*/) {
116 // class name, not ClassID
117 cn = *it;
118 boost::erase_all(cn,"'");
119 c = 0;
120 }
121
122 ++it;
123 std::string k = *it;
124 boost::erase_all(k,"'");
125 ++it;
126
127 if ( c != 0) {
128 v.emplace( DataObjID(c,k) );
129 } else {
130 v.emplace( DataObjID(cn,k) );
131 }
132 }
133 }
134 }
135 return sc;
136 }
137
138
139
140 } //> ns Parsers
141
142 namespace Utils {
143
144 std::ostream&
145 toStream(const DataObjID& v, std::ostream& o) {
146 if (v.clid() == 0) {
147 o << "'" << v.key() << "'";
148 } else {
149 o << "(" << v.clid() << ",'" << v.key() << "')";
150 }
151 return o;
152 }
153
154 std::ostream&
155 toStream(const DataObjIDColl& v, std::ostream& o) {
156 o << "[";
157 for (auto &i : v) {
158 toStream(i,o);
159 o << ",";
160 }
161 o << "]";
162 return o;
163 }
164
165 } //> ns Utils
166
167 } //> ns Gaudi
168
169 //---------------------------------------------------------------------------
170
171 DataObjIDProperty::DataObjIDProperty( const std::string& name,
172 DataObjID& ref )
173 : Property( name, typeid( DataObjID ) ),
174 m_pValue( &ref )
175 {}
176
177 //---------------------------------------------------------------------------
178
179 DataObjIDProperty::~DataObjIDProperty()
180 {}
181
182 //---------------------------------------------------------------------------
183
184 StatusCode
185 DataObjIDProperty::fromString(const std::string& s)
186 {
187 if (!Gaudi::Parsers::parse(*m_pValue, s).isSuccess()) {
188 return StatusCode::FAILURE;
189 }
190 return useUpdateHandler()
191 ? StatusCode::SUCCESS
192 : StatusCode::FAILURE;
193 }
194
195 //---------------------------------------------------------------------------
196
197 bool
198 DataObjIDProperty::setValue( const DataObjID& value )
199 {
200 m_pValue->operator=(value);
201 return useUpdateHandler();
202 }
203
204 //---------------------------------------------------------------------------
205
206 std::string
207 DataObjIDProperty::toString( ) const
208 {
209 useReadHandler();
210 std::ostringstream o;
211 Gaudi::Utils::toStream(*m_pValue, o);
212 return o.str();
213 }
214
215 //---------------------------------------------------------------------------
216 void
217 DataObjIDProperty::toStream(std::ostream& out) const
218 {
219 useReadHandler();
220 out << this->toString();
221 }
222
223
224 //---------------------------------------------------------------------------
225 //---------------------------------------------------------------------------
226
227 DataObjIDCollProperty::DataObjIDCollProperty( const std::string& name,
228 DataObjIDColl& ref )
229 : Property( name, typeid( DataObjIDColl ) ),
230 m_pValue( &ref )
231 {}
232
233 //---------------------------------------------------------------------------
234
235 DataObjIDCollProperty::~DataObjIDCollProperty()
236 {}
237
238 //---------------------------------------------------------------------------
239
240 StatusCode
241 DataObjIDCollProperty::fromString(const std::string& s)
242 {
243 if (!Gaudi::Parsers::parse(*m_pValue, s).isSuccess()) {
244 return StatusCode::FAILURE;
245 }
246 return useUpdateHandler()
247 ? StatusCode::SUCCESS
248 : StatusCode::FAILURE;
249 }
250
251 //---------------------------------------------------------------------------
252
253 bool
254 DataObjIDCollProperty::setValue( const DataObjIDColl& value )
255 {
256 m_pValue->operator=(value);
257 return useUpdateHandler();
258 }
259
260 //---------------------------------------------------------------------------
261
262 std::string
263 DataObjIDCollProperty::toString( ) const
264 {
265 useReadHandler();
266 std::ostringstream o;
267 Gaudi::Utils::toStream(*m_pValue, o);
268 return o.str();
269 }
270
271 //---------------------------------------------------------------------------
272 void
273 DataObjIDCollProperty::toStream(std::ostream& out) const
274 {
275 useReadHandler();
276 out << this->toString();
277 }
278
DataObjIDCollProperty::fromString
virtual StatusCode fromString(const std::string &s)
string -> value
Definition: DataObjIDProperty.cpp:241
Property::useReadHandler
virtual void useReadHandler() const
use the call-back function at reading
Definition: Property.cpp:80
DataObjIDProperty::DataObjIDProperty
DataObjIDProperty(const std::string &name, DataObjID &ref)
Definition: DataObjIDProperty.cpp:171
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
DataObjID
Definition: DataObjID.h:38
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
gaudirun.c
tuple c
Definition: gaudirun.py:391
Gaudi::Parsers::Property
Definition: Property.h:16
std::endl
T endl(T...args)
DataObjIDProperty::setValue
bool setValue(const DataObjID &value)
Definition: DataObjIDProperty.cpp:198
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
merge_files.sc
int sc
Definition: merge_files.py:167
DataObjIDProperty::toStream
virtual void toStream(std::ostream &out) const
value -> stream
Definition: DataObjIDProperty.cpp:217
std::string
STL class.
compareRootHistos.ref
string ref
Definition: compareRootHistos.py:14
DataObjIDCollProperty::toStream
virtual void toStream(std::ostream &out) const
value -> stream
Definition: DataObjIDProperty.cpp:273
DataObjIDProperty::m_pValue
DataObjID * m_pValue
Pointer to the real property.
Definition: DataObjIDProperty.h:48
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:319
StatusCode::FAILURE
Definition: StatusCode.h:29
DataObjID::clid
CLID clid() const
Definition: DataObjID.h:54
DataObjIDCollProperty::setValue
bool setValue(const DataObjIDColl &value)
Definition: DataObjIDProperty.cpp:254
StatusCode::SUCCESS
Definition: StatusCode.h:30
Property::useUpdateHandler
virtual bool useUpdateHandler()
use the call-back function at update
Definition: Property.cpp:92
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
DataObjIDProperty::~DataObjIDProperty
virtual ~DataObjIDProperty()
Definition: DataObjIDProperty.cpp:179
std::ostringstream
STL class.
DataObjID::key
const std::string & key() const
Definition: DataObjID.h:49
std::ostringstream::str
T str(T...args)
dump_component_properties.value
list value
Definition: dump_component_properties.py:12
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:96
DataObjIDProperty.h
std::string::find
T find(T...args)
DataObjIDProperty::toString
virtual std::string toString() const
value -> string
Definition: DataObjIDProperty.cpp:207
DataObjIDProperty::fromString
virtual StatusCode fromString(const std::string &s)
string -> value
Definition: DataObjIDProperty.cpp:185
DataObjIDCollProperty::toString
virtual std::string toString() const
value -> string
Definition: DataObjIDProperty.cpp:263
DataObjIDCollProperty::~DataObjIDCollProperty
virtual ~DataObjIDCollProperty()
Definition: DataObjIDProperty.cpp:235
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:124
Gaudi::Utils
Definition: Fill.h:24
DataObjIDCollProperty::value
const DataObjIDColl & value() const
Definition: DataObjIDProperty.h:172
DataObjIDCollProperty::DataObjIDCollProperty
DataObjIDCollProperty(const std::string &name, DataObjIDColl &ref)
Definition: DataObjIDProperty.cpp:227
ana.i
list i
Definition: ana.py:128
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.