All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
DataObjectHandleProperty.cpp
Go to the documentation of this file.
2 
4 #include "GaudiKernel/Parsers.h"
5 
6 #include <boost/algorithm/string.hpp>
7 #include <boost/tokenizer.hpp>
8 #include <map>
9 #include <sstream>
10 
11 namespace Gaudi
12 {
13  namespace Parsers
14  {
15 
17  {
18 
19  // std::cerr << "parse(DataObjectHandleBase) : " << s << std::endl;
20 
22  std::string prop;
23  sc = Gaudi::Parsers::parse( prop, s );
24 
25  if ( sc.isSuccess() ) {
26 
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 < 3 || nToks > 4 ) {
34  std::cerr << "Unable to instantiante DataObjectHandle from Property: " << s << " :: Format is bad"
35  << std::endl;
36  return StatusCode::FAILURE;
37  }
38 
39  std::string k = *it;
40  boost::erase_all( k, "'" );
41  boost::erase_all( k, "(" );
42  boost::erase_all( k, ")" );
43 
44  ++it;
45 
46  int m = std::stoi( *it );
47  ++it;
48 
49  if ( v.mode() != m ) {
50  std::cerr << "ERROR: mismatch in access mode for DataObjectHandle " << v.fullKey() << " " << v.mode() << " "
51  << m << std::endl;
52  return StatusCode::FAILURE;
53  }
54 
55  bool o = bool( std::stoi( *it ) );
56 
57  v.setOptional( o );
58  v.setKey( DataObjID( k ) );
59 
60  // std::cout << "--> key: " << k << " mode: " << m << " opt: " << o << std::endl;
61 
62  if ( nToks == 4 ) {
63  // now parse the alt addresses
64  ++it;
65  std::string alt = *it;
67  boost::char_separator<char> sep2( "&" );
68  tokenizer tok2( alt, sep2 );
69 
70  for ( auto it2 : tok2 ) {
71  std::string aa = it2;
72  av.push_back( aa );
73  // std::cout << " altA: " << aa << std::endl;
74  }
75 
77  }
78  }
79 
80  return StatusCode::SUCCESS;
81  }
82  }
83 
84  namespace Utils
85  {
86 
88  {
89  o << v;
90  // std::cerr << "toStream(DataObjectHandleBase) : " << v << std::endl;
91  return o;
92  }
93  }
94 }
95 
96 //---------------------------------------------------------------------------
97 
99  : PropertyWithHandlers( name, typeid( DataObjectHandleBase ) ), m_pValue( &ref )
100 {
101 }
102 
103 //---------------------------------------------------------------------------
104 
106 
107 //---------------------------------------------------------------------------
108 
110 {
111  if ( !Gaudi::Parsers::parse( *m_pValue, s ).isSuccess() ) {
112  return StatusCode::FAILURE;
113  }
115 }
116 
118 {
119  // std::cerr << "DataObjectHandleProperty::pythonRepr() " << std::endl;
120  return "DataObjectHandleBase(\"" + toString() + "\")";
121 }
122 
123 //---------------------------------------------------------------------------
124 
126 {
127  m_pValue->operator=( value );
128  return useUpdateHandler();
129 }
130 
131 //---------------------------------------------------------------------------
132 
134 {
135  useReadHandler();
138  return o.str();
139 }
140 
141 //---------------------------------------------------------------------------
143 {
144  useReadHandler();
145  out << this->toString();
146 }
147 
148 //---------------------------------------------------------------------------
149 
151 {
152  setValue( value );
153  return *this;
154 }
155 
156 //---------------------------------------------------------------------------
157 
159 
160 //---------------------------------------------------------------------------
161 
163 {
164  return destination.assign( *this );
165 }
166 
167 //---------------------------------------------------------------------------
168 
170 {
171  return fromString( source.toString() ).isSuccess();
172 }
173 
174 //---------------------------------------------------------------------------
175 
177 {
178  useReadHandler();
179  return *m_pValue;
180 }
bool load(Property &destination) const override
virtual void setKey(const DataObjID &key)
Definition: DataHandle.h:49
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
DataObjectHandleProperty & operator=(const DataObjectHandleBase &value)
DataObjectHandleBase * m_pValue
Pointer to the real property.
virtual bool assign(const PropertyBase &source)=0
import the property value form the source
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:74
virtual Mode mode() const
Definition: DataHandle.h:47
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 std::string toString() const =0
value -> string
bool assign(const Property &source) override
DataObjectHandleProperty.h GaudiKernel/DataObjectHandleProperty.h.
Helper class to simplify the migration old properties deriving directly from PropertyBase.
Definition: Property.h:736
void toStream(std::ostream &out) const override
value -> stream
STL class.
DataObjectHandleProperty * clone() const override
clones the current property
virtual const DataObjID & fullKey() const
Definition: DataHandle.h:53
T push_back(T...args)
DataObjectHandleProperty(const std::string &name, DataObjectHandleBase &ref)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
constexpr double m
Definition: SystemOfUnits.h:93
bool useUpdateHandler() override
use the call-back function at update, if available
Definition: Property.h:765
const std::string pythonRepr() const
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
void useReadHandler() const
use the call-back function at reading, if available
Definition: Property.h:762
bool setValue(const DataObjectHandleBase &value)
StatusCode fromString(const std::string &s) override
string -> value
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
string s
Definition: gaudirun.py:245
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)
std::string toString() const override
value -> string