DataObjectHandleProperty.cpp
Go to the documentation of this file.
2 
3 #include "GaudiKernel/Parsers.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
23 
24  // std::cerr << "parse(DataObjectHandleBase) : " << s << std::endl;
25 
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;
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 
83 
84  }
85  }
86 
87  return StatusCode::SUCCESS;
88 
89  }
90  }
91 
92  namespace Utils {
93 
94  std::ostream&
96  o << v;
97  // std::cerr << "toStream(DataObjectHandleBase) : " << v << std::endl;
98  return o;
99  }
100 
101  }
102 }
103 
104 //---------------------------------------------------------------------------
105 
108  : Property( name, typeid( DataObjectHandleBase ) ),
109  m_pValue( &ref )
110 {}
111 
112 //---------------------------------------------------------------------------
113 
115 {}
116 
117 //---------------------------------------------------------------------------
118 
119 StatusCode
121 {
122  if (!Gaudi::Parsers::parse(*m_pValue, s).isSuccess()) {
123  return StatusCode::FAILURE;
124  }
125  return useUpdateHandler()
128 }
129 
130 
131 const std::string
133  // std::cerr << "DataObjectHandleProperty::pythonRepr() " << std::endl;
134  return "DataObjectHandleBase(\"" + toString() + "\")";
135 }
136 
137 
138 //---------------------------------------------------------------------------
139 
140 bool
142 {
143  m_pValue->operator=(value);
144  return useUpdateHandler();
145 }
146 
147 //---------------------------------------------------------------------------
148 
151 {
152  useReadHandler();
155  return o.str();
156 }
157 
158 //---------------------------------------------------------------------------
159 void
161 {
162  useReadHandler();
163  out << this->toString();
164 }
165 
166 //---------------------------------------------------------------------------
167 
170 {
171  setValue( value );
172  return *this;
173 }
174 
175 //---------------------------------------------------------------------------
176 
179 {
180  return new DataObjectHandleProperty( *this );
181 }
182 
183 //---------------------------------------------------------------------------
184 
185 bool
187 {
188  return destination.assign( *this );
189 }
190 
191 //---------------------------------------------------------------------------
192 
193 bool
195 {
196  return fromString( source.toString() ).isSuccess();
197 }
198 
199 //---------------------------------------------------------------------------
200 
201 const DataObjectHandleBase&
203 {
204  useReadHandler();
205  return *m_pValue;
206 }
virtual void setKey(const DataObjID &key)
Definition: DataHandle.h:49
virtual void useReadHandler() const
use the call-back function at reading
Definition: Property.cpp:80
virtual bool assign(const Property &source)=0
import the property value form the source
virtual std::string toString() const =0
value -> string
DataObjectHandleProperty & operator=(const DataObjectHandleBase &value)
DataObjectHandleBase * m_pValue
Pointer to the real property.
virtual std::string toString() const
value -> string
The declaration of major parsing functions used e.g for (re)implementation of new extended properties...
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
virtual void toStream(std::ostream &out) const
value -> stream
virtual Mode mode() const
Definition: DataHandle.h:47
virtual StatusCode fromString(const std::string &s)
string -> value
T endl(T...args)
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
void setOptional(bool optional=true)
virtual bool assign(const Property &source)
import the property value form the source
DataObjectHandleProperty.h GaudiKernel/DataObjectHandleProperty.h.
STL class.
virtual const DataObjID & fullKey() const
Definition: DataHandle.h:53
T push_back(T...args)
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
DataObjectHandleProperty(const std::string &name, DataObjectHandleBase &ref)
virtual bool useUpdateHandler()
use the call-back function at update
Definition: Property.cpp:92
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
constexpr double m
Definition: SystemOfUnits.h:93
const std::string pythonRepr() const
bool setValue(const DataObjectHandleBase &value)
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
virtual DataObjectHandleProperty * clone() const
clone: "virtual constructor"
string s
Definition: gaudirun.py:245
virtual bool load(Property &destination) const
export the property value to the destination
const DataObjectHandleBase & value() const
T stoi(T...args)
Helper functions to set/get the application return code.
Definition: __init__.py:1
const std::vector< std::string > & alternativeDataProductNames() const
void setAlternativeDataProductNames(const std::vector< std::string > &alternativeAddresses)