| The Gaudi Framework v27r1

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

- File List
- File Members

DataObjectHandleProperty.cpp
Go to the documentation of this file.
1 #include "GaudiKernel/DataObjectHandleProperty.h"
2
3 #include "GaudiKernel/Parsers.h"
4 #include "GaudiKernel/DataObjectHandleBase.h"
5
6 #include <sstream>
7 #include <map>
8 #include <boost/tokenizer.hpp>
9 #include <boost/algorithm/string.hpp>
10
11 // using namespace Gaudi;
12 // using namespace Gaudi::Parsers;
13 // using namespace Gaudi::Utils;
14
15
16
17
18 namespace Gaudi {
19 namespace Parsers {
20
21 StatusCode
22 parse(DataObjectHandleBase& v, const std::string& s) {
23
24 // std::cerr << "parse(DataObjectHandleBase) : " << s << std::endl;
25
26 StatusCode sc(StatusCode::FAILURE);
27 std::string prop;
28 sc = Gaudi::Parsers::parse(prop, s);
29
30 if (sc.isSuccess()) {
31
32 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
33 boost::char_separator<char> sep("|");
34 tokenizer tokens(prop, sep);
35 int nToks(distance(tokens.begin(), tokens.end()));
36 auto it = tokens.begin();
37
38 if (nToks < 3 || nToks > 4) {
39 std::cerr << "Unable to instantiante DataObjectHandle from Property: " << s
40 << " :: Format is bad" << std::endl;
41 return StatusCode::FAILURE;
42 }
43
44 std::string k = *it;
45 boost::erase_all(k,"'");
46 boost::erase_all(k,"(");
47 boost::erase_all(k,")");
48
49 ++it;
50
51 int m = std::stoi(*it);
52 ++it;
53
54 if (v.mode() != m) {
55 std::cerr << "ERROR: mismatch in access mode for DataObjectHandle "
56 << v.fullKey() << " " << v.mode() << " " << m << std::endl;
57 return StatusCode::FAILURE;
58 }
59
60
61 bool o = bool(std::stoi(*it));
62
63 v.setOptional(o);
64 v.setKey( DataObjID(k) );
65
66 // std::cout << "--> key: " << k << " mode: " << m << " opt: " << o << std::endl;
67
68 if (nToks == 4) {
69 // now parse the alt addresses
70 ++it;
71 std::string alt = *it;
72 std::vector<std::string> av = v.alternativeDataProductNames();
73 boost::char_separator<char> sep2("&");
74 tokenizer tok2(alt,sep2);
75
76 for (auto it2 : tok2 ) {
77 std::string aa = it2;
78 av.push_back(aa);
79 // std::cout << " altA: " << aa << std::endl;
80 }
81
82 v.setAlternativeDataProductNames(av);
83
84 }
85 }
86
87 return StatusCode::SUCCESS;
88
89 }
90 }
91
92 namespace Utils {
93
94 std::ostream&
95 toStream(const DataObjectHandleBase& v, std::ostream& o) {
96 o << v;
97 // std::cerr << "toStream(DataObjectHandleBase) : " << v << std::endl;
98 return o;
99 }
100
101 }
102 }
103
104 //---------------------------------------------------------------------------
105
106 DataObjectHandleProperty::DataObjectHandleProperty( const std::string& name,
107 DataObjectHandleBase& ref )
108 : Property( name, typeid( DataObjectHandleBase ) ),
109 m_pValue( &ref )
110 {}
111
112 //---------------------------------------------------------------------------
113
114 DataObjectHandleProperty::~DataObjectHandleProperty()
115 {}
116
117 //---------------------------------------------------------------------------
118
119 StatusCode
120 DataObjectHandleProperty::fromString(const std::string& s)
121 {
122 if (!Gaudi::Parsers::parse(*m_pValue, s).isSuccess()) {
123 return StatusCode::FAILURE;
124 }
125 return useUpdateHandler()
126 ? StatusCode::SUCCESS
127 : StatusCode::FAILURE;
128 }
129
130
131 const std::string
132 DataObjectHandleProperty::pythonRepr() const {
133 // std::cerr << "DataObjectHandleProperty::pythonRepr() " << std::endl;
134 return "DataObjectHandleBase(\"" + toString() + "\")";
135 }
136
137
138 //---------------------------------------------------------------------------
139
140 bool
141 DataObjectHandleProperty::setValue( const DataObjectHandleBase& value )
142 {
143 m_pValue->operator=(value);
144 return useUpdateHandler();
145 }
146
147 //---------------------------------------------------------------------------
148
149 std::string
150 DataObjectHandleProperty::toString( ) const
151 {
152 useReadHandler();
153 std::ostringstream o;
154 Gaudi::Utils::toStream(*m_pValue, o);
155 return o.str();
156 }
157
158 //---------------------------------------------------------------------------
159 void
160 DataObjectHandleProperty::toStream(std::ostream& out) const
161 {
162 useReadHandler();
163 out << this->toString();
164 }
165
166 //---------------------------------------------------------------------------
167
168 DataObjectHandleProperty&
169 DataObjectHandleProperty::operator=( const DataObjectHandleBase& value )
170 {
171 setValue( value );
172 return *this;
173 }
174
175 //---------------------------------------------------------------------------
176
177 DataObjectHandleProperty*
178 DataObjectHandleProperty::clone() const
179 {
180 return new DataObjectHandleProperty( *this );
181 }
182
183 //---------------------------------------------------------------------------
184
185 bool
186 DataObjectHandleProperty::load( Property& destination ) const
187 {
188 return destination.assign( *this );
189 }
190
191 //---------------------------------------------------------------------------
192
193 bool
194 DataObjectHandleProperty::assign( const Property& source )
195 {
196 return fromString( source.toString() ).isSuccess();
197 }
198
199 //---------------------------------------------------------------------------
200
201 const DataObjectHandleBase&
202 DataObjectHandleProperty::value() const
203 {
204 useReadHandler();
205 return *m_pValue;
206 }
Gaudi::DataHandle::setKey
virtual void setKey(const DataObjID &key)
Definition: DataHandle.h:49
DataObjectHandleProperty.h
Property::useReadHandler
virtual void useReadHandler() const
use the call-back function at reading
Definition: Property.cpp:80
Property::assign
virtual bool assign(const Property &source)=0
import the property value form the source
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
Property::toString
virtual std::string toString() const =0
value -> string
DataObjID
Definition: DataObjID.h:38
DataObjectHandleProperty::operator=
DataObjectHandleProperty & operator=(const DataObjectHandleBase &value)
Definition: DataObjectHandleProperty.cpp:169
DataObjectHandleProperty::m_pValue
DataObjectHandleBase * m_pValue
Pointer to the real property.
Definition: DataObjectHandleProperty.h:45
DataObjectHandleProperty::toString
virtual std::string toString() const
value -> string
Definition: DataObjectHandleProperty.cpp:150
Parsers.h
The declaration of major parsing functions used e.g for (re)implementation of new extended properties...
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
DataObjectHandleProperty::toStream
virtual void toStream(std::ostream &out) const
value -> stream
Definition: DataObjectHandleProperty.cpp:160
Gaudi::DataHandle::mode
virtual Mode mode() const
Definition: DataHandle.h:47
DataObjectHandleProperty::fromString
virtual StatusCode fromString(const std::string &s)
string -> value
Definition: DataObjectHandleProperty.cpp:120
std::endl
T endl(T...args)
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
DataObjectHandleBase::setOptional
void setOptional(bool optional=true)
Definition: DataObjectHandleBase.h:46
DataObjectHandleProperty::assign
virtual bool assign(const Property &source)
import the property value form the source
Definition: DataObjectHandleProperty.cpp:194
merge_files.sc
int sc
Definition: merge_files.py:167
DataObjectHandleProperty::~DataObjectHandleProperty
virtual ~DataObjectHandleProperty()
Definition: DataObjectHandleProperty.cpp:114
DataObjectHandleProperty
DataObjectHandleProperty.h GaudiKernel/DataObjectHandleProperty.h.
Definition: DataObjectHandleProperty.h:23
std::string
STL class.
compareRootHistos.ref
string ref
Definition: compareRootHistos.py:14
Gaudi::DataHandle::fullKey
virtual const DataObjID & fullKey() const
Definition: DataHandle.h:53
std::vector::push_back
T push_back(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:319
StatusCode::FAILURE
Definition: StatusCode.h:29
DataObjectHandleProperty::DataObjectHandleProperty
DataObjectHandleProperty(const std::string &name, DataObjectHandleBase &ref)
Definition: DataObjectHandleProperty.cpp:106
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
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:93
std::ostringstream
STL class.
std::ostringstream::str
T str(T...args)
DataObjectHandleProperty::pythonRepr
const std::string pythonRepr() const
Definition: DataObjectHandleProperty.cpp:132
dump_component_properties.value
list value
Definition: dump_component_properties.py:12
DataObjectHandleProperty::setValue
bool setValue(const DataObjectHandleBase &value)
Definition: DataObjectHandleProperty.cpp:141
DataObjectHandleBase.h
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
std::vector< std::string >
DataObjectHandleBase
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
Definition: DataObjectHandleBase.h:24
DataObjectHandleProperty::clone
virtual DataObjectHandleProperty * clone() const
clone: "virtual constructor"
Definition: DataObjectHandleProperty.cpp:178
gaudirun.s
string s
Definition: gaudirun.py:245
DataObjectHandleProperty::load
virtual bool load(Property &destination) const
export the property value to the destination
Definition: DataObjectHandleProperty.cpp:186
DataObjectHandleProperty::value
const DataObjectHandleBase & value() const
Definition: DataObjectHandleProperty.cpp:202
std::cerr
std::stoi
T stoi(T...args)
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
DataObjectHandleBase::alternativeDataProductNames
const std::vector< std::string > & alternativeDataProductNames() const
Definition: DataObjectHandleBase.h:48
DataObjectHandleBase::setAlternativeDataProductNames
void setAlternativeDataProductNames(const std::vector< std::string > &alternativeAddresses)
Definition: DataObjectHandleBase.h:50