Commit 00d4d8ae authored by Gerhard Raven's avatar Gerhard Raven Committed by Benedikt Hegner
Browse files

Replace DataObjID{,Coll}Property with Gaudi::Property<DataObjID{,Coll}>

parent 9d5b5c2e
......@@ -19,10 +19,6 @@
#include <type_traits>
#include <vector>
// ============================================================================
// GaudiKernel
// ============================================================================
#include "GaudiKernel/HistoProperty.h"
// ============================================================================
// GaudiUtils
// ============================================================================
#include "GaudiUtils/HistoTableFormat.h"
......@@ -33,6 +29,10 @@
#include "GaudiAlg/GaudiTool.h"
#include "GaudiAlg/Maps.h"
// ============================================================================
// GaudiKernel
// ============================================================================
#include "GaudiKernel/HistoProperty.h"
// ============================================================================
// Forward declarations
namespace AIDA
{
......
// ============================================================================
// Include files
// ============================================================================
// GaudiAlg
// ============================================================================
#include "GaudiAlg/GaudiAlgorithm.h"
// ============================================================================
// GaudiKernel
// ============================================================================
#define NO_C_ARRAY_AS_PROPERTY_WARNING
#include "GaudiKernel/CArrayAsProperty.h"
// ============================================================================
// GaudiAlg
// ============================================================================
#include "GaudiAlg/GaudiAlgorithm.h"
// ============================================================================
/** @file
* Simple example/test for "array"-properties
* @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
......
......@@ -185,10 +185,10 @@ MyAlg.LegacyToo... INFO String = hundred
MyAlg.LegacyToo... INFO Bool = 1
MyAlg DEBUG Adding private ToolHandle tool MyAlg.LegacyToolHandle (MyTool)
MyAlg DEBUG Data Deps for MyAlg
+ INPUT ('/Event/Rec/Hits')
+ INPUT ('/Event/Rec/Tracks')
+ INPUT ('/Rec/RAW')
+ OUTPUT ('/Event/MyAnalysis/Tracks')
+ INPUT '/Event/Rec/Hits'
+ INPUT '/Event/Rec/Tracks'
+ INPUT '/Rec/RAW'
+ OUTPUT '/Event/MyAnalysis/Tracks'
ToolSvc.ToolA DEBUG Property update for OutputLevel : new value = 2
ToolSvc.ToolA DEBUG Initialize
ToolSvc.ToolA DEBUG Initialize base class GaudiCommon<AlgTool>
......
......@@ -18,12 +18,12 @@ AlgResourcePool INFO Algorithm THDataConsumer is un-Clonable but Cardinalit
AvalancheSchedu... INFO Found 3 algorithms
AvalancheSchedu... INFO Data Dependencies for Algorithms:
THDataProducer
o OUTPUT ('/Event/MyInt')
o OUTPUT '/Event/MyInt'
THDataProducer2
o OUTPUT ('/Event/MyFloat')
o OUTPUT '/Event/MyFloat'
THDataConsumer
o INPUT ('/Event/MyFloat')
o INPUT ('/Event/MyInt')
o INPUT '/Event/MyFloat'
o INPUT '/Event/MyInt'
PrecedenceSvc INFO Assembling CF and DF task precedence rules
PrecedenceSvc INFO PrecedenceSvc initialized successfully
AvalancheSchedu... INFO Concurrency level information:
......
......@@ -3,6 +3,7 @@
// ============================================================================
// Include files
#include "GaudiKernel/CommonMessaging.h"
#include "GaudiKernel/DataObjID.h"
#include "GaudiKernel/IAlgTool.h"
#include "GaudiKernel/IAuditorSvc.h"
#include "GaudiKernel/IDataProviderSvc.h"
......@@ -17,8 +18,6 @@
#include "GaudiKernel/ToolHandle.h"
#include <Gaudi/PluginService.h>
#include "GaudiKernel/DataObjIDProperty.h"
#include "GaudiKernel/DataHandle.h"
#include "GaudiKernel/DataHandleHolderBase.h"
#include "GaudiKernel/IDataHandleHolder.h"
......
......@@ -10,7 +10,6 @@
#include "GaudiKernel/IStateful.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/ITimelineSvc.h"
#include "GaudiKernel/PropertyHolder.h"
#include <mutex>
#include <string>
......@@ -18,6 +17,7 @@
// Extra include files (forward declarations should be sufficient)
#include "GaudiKernel/CommonMessaging.h"
#include "GaudiKernel/DataObjID.h" // must be include before Property.h, which is included in PropertyHolder.h
#include "GaudiKernel/IAlgContextSvc.h"
#include "GaudiKernel/IAuditorSvc.h"
#include "GaudiKernel/IChronoStatSvc.h"
......@@ -31,12 +31,11 @@
#include "GaudiKernel/IRndmGenSvc.h"
#include "GaudiKernel/IToolSvc.h"
#include "GaudiKernel/Property.h"
#include "GaudiKernel/PropertyHolder.h"
#include "GaudiKernel/System.h"
#include "GaudiKernel/ToolHandle.h"
#include <Gaudi/PluginService.h>
#include "GaudiKernel/DataObjIDProperty.h"
// For concurrency
#include "GaudiKernel/DataHandle.h"
#include "GaudiKernel/DataHandleHolderBase.h"
......
......@@ -2,6 +2,7 @@
#define GAUDIKERNEL_DATAHANDLEHOLDERBASE 1
#include "GaudiKernel/DataHandle.h"
#include "GaudiKernel/DataObjID.h"
#include "GaudiKernel/GaudiException.h"
#include "GaudiKernel/IDataHandleHolder.h"
#include "GaudiKernel/Property.h"
......
......@@ -23,7 +23,7 @@
* or a combination of the std::hash<string> of the key and the ClassID
*
* Collections of DataObjIDs are std::unordered_set<DataObjID> with a provided
* allocator DataObjID_Hasher which the hash function
* hash function DataObjID_Hasher
*
* @author Charles Leggett
* @date 2015-09-01
......@@ -39,11 +39,11 @@ class DataObjID
public:
friend DataObjID_Hasher;
DataObjID(){};
DataObjID() = default;
DataObjID( const DataObjID& ) = default;
DataObjID( const std::string& key );
DataObjID( const CLID& clid, const std::string& key );
DataObjID( const std::string& className, const std::string& key );
DataObjID( const DataObjID& ) = default;
// only return the last part of the key
const std::string& key() const { return m_key; }
......@@ -55,14 +55,14 @@ public:
void updateKey( const std::string& key );
friend std::ostream& operator<<( std::ostream& str, const DataObjID& d );
friend bool operator<( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash < rhs.m_hash; }
friend bool operator==( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash == rhs.m_hash; }
friend bool operator!=( const DataObjID& lhs, const DataObjID& rhs ) { return !( lhs == rhs ); }
friend StatusCode parse( DataObjID& dest, const std::string& src );
friend std::ostream& toStream( const DataObjID& v, std::ostream& o );
friend std::ostream& operator<<( std::ostream& os, const DataObjID& d ) { return toStream( d, os ); }
private:
void hashGen();
void parse( const std::string& key );
......@@ -72,10 +72,9 @@ private:
CLID m_clid{0};
std::size_t m_hash{0};
std::string m_className{""};
std::string m_key{"INVALID"};
std::string m_className;
static void getClidSvc();
static IClassIDSvc* p_clidSvc;
static std::once_flag m_ip;
};
......@@ -89,7 +88,7 @@ inline DataObjID::DataObjID( const CLID& clid, const std::string& key ) : m_clid
}
inline DataObjID::DataObjID( const std::string& className, const std::string& key )
: m_className( className ), m_key( key )
: m_key( key ), m_className( className )
{
setClid();
hashGen();
......@@ -105,19 +104,23 @@ struct DataObjID_Hasher {
std::size_t operator()( const DataObjID& k ) const { return k.m_hash; }
};
typedef std::unordered_set<DataObjID, DataObjID_Hasher> DataObjIDColl;
using DataObjIDColl = std::unordered_set<DataObjID, DataObjID_Hasher>;
namespace Gaudi
{
namespace Parsers
{
StatusCode parse( DataObjID&, const std::string& );
StatusCode parse( DataObjIDColl&, const std::string& );
}
namespace Utils
namespace Details
{
GAUDI_API std::ostream& toStream( const DataObjID& v, std::ostream& o );
GAUDI_API std::ostream& toStream( const DataObjIDColl& v, std::ostream& o );
namespace Property
{
template <typename T>
struct StringConverter;
template <>
struct StringConverter<DataObjIDColl> {
std::string toString( const DataObjIDColl& v );
DataObjIDColl fromString( const std::string& s );
};
}
}
}
......
......@@ -2,176 +2,11 @@
#define GAUDIKERNEL_DATAOBJIDPROPERTY_H 1
#include "GaudiKernel/DataObjID.h"
#include "GaudiKernel/Parsers.h"
#include "GaudiKernel/Property.h"
#include "GaudiKernel/StatusCode.h"
#include "GaudiKernel/ToStream.h"
#include <iostream>
//---------------------------------------------------------------------------
/** DataObjIDProperty.h GaudiKernel/DataObjProperty.h
*
* Helper class to manage DataObjIDs and DataObjIDColls as properties
*
* TODO: DataObjIDCollProperty implementation
*
* @author Charles Leggett
* @date 2015-09-01
*/
//---------------------------------------------------------------------------
class GAUDI_API DataObjIDProperty : public PropertyWithHandlers<>
{
public:
DataObjIDProperty( const std::string& name, DataObjID& ref );
DataObjIDProperty& operator=( const DataObjID& value );
~DataObjIDProperty() override;
DataObjIDProperty* clone() const override;
bool load( Property& destination ) const override;
bool assign( const Property& source ) override;
std::string toString() const override;
void toStream( std::ostream& out ) const override;
StatusCode fromString( const std::string& s ) override;
const DataObjID& value() const;
bool setValue( const DataObjID& value );
private:
/** Pointer to the real property. Reference would be better,
* but Reflex does not support references yet
*/
DataObjID* m_pValue;
};
namespace Gaudi
{
template <>
class Property<DataObjID&> : public ::DataObjIDProperty
{
public:
Property( const std::string& name, DataObjID& value ) : ::DataObjIDProperty( name, value ) {}
/// virtual Destructor
virtual ~Property() {}
};
} // namespace Gaudi
inline DataObjIDProperty& DataObjIDProperty::operator=( const DataObjID& value )
{
setValue( value );
return *this;
}
inline DataObjIDProperty* DataObjIDProperty::clone() const { return new DataObjIDProperty( *this ); }
inline bool DataObjIDProperty::load( Gaudi::Details::PropertyBase& destination ) const
{
return destination.assign( *this );
}
inline bool DataObjIDProperty::assign( const Gaudi::Details::PropertyBase& source )
{
return fromString( source.toString() ).isSuccess();
}
inline const DataObjID& DataObjIDProperty::value() const
{
useReadHandler();
return *m_pValue;
}
//---------------------------------------------------------------------------
class GAUDI_API DataObjIDCollProperty : public PropertyWithHandlers<>
{
public:
DataObjIDCollProperty( const std::string& name, DataObjIDColl& ref );
DataObjIDCollProperty& operator=( const DataObjIDColl& value );
virtual ~DataObjIDCollProperty();
DataObjIDCollProperty* clone() const override;
bool load( Property& destination ) const override;
bool assign( const Property& source ) override;
std::string toString() const override;
void toStream( std::ostream& out ) const override;
StatusCode fromString( const std::string& s ) override;
const DataObjIDColl& value() const;
bool setValue( const DataObjIDColl& value );
private:
/** Pointer to the real property. Reference would be better,
* but Reflex does not support references yet
*/
DataObjIDColl* m_pValue;
};
namespace Gaudi
{
template <>
class Property<DataObjIDColl&> : public ::DataObjIDCollProperty
{
public:
Property( const std::string& name, DataObjIDColl& value ) : ::DataObjIDCollProperty( name, value ) {}
/// virtual Destructor
virtual ~Property() {}
};
template <>
class Property<DataObjIDColl> : public ::DataObjIDCollProperty
{
public:
Property( const std::string& name, DataObjIDColl& value ) : ::DataObjIDCollProperty( name, value ) {}
/// Autodeclaring constructor with property name, value and documentation.
template <class OWNER>
inline Property( OWNER* owner, const std::string& name, const DataObjIDColl& initval = DataObjIDColl{},
std::string doc = "" )
: ::DataObjIDCollProperty( name, *( new DataObjIDColl{initval} ) )
{
/// \fixme{DataObjIDCollProperty is a ref property by construction and this
/// is a temporary hack to have a "value" property}
m_data.reset( const_cast<DataObjIDColl*>( &value() ) );
setDocumentation( std::move( doc ) );
owner->declareProperty( *this );
setOwnerType<OWNER>();
}
operator const DataObjIDColl&() const { return value(); }
/// virtual Destructor
virtual ~Property() {}
private:
std::unique_ptr<DataObjIDColl> m_data;
};
} // namespace Gaudi
inline DataObjIDCollProperty& DataObjIDCollProperty::operator=( const DataObjIDColl& value )
{
setValue( value );
return *this;
}
inline DataObjIDCollProperty* DataObjIDCollProperty::clone() const { return new DataObjIDCollProperty( *this ); }
inline bool DataObjIDCollProperty::load( Gaudi::Details::PropertyBase& destination ) const
{
return destination.assign( *this );
}
inline bool DataObjIDCollProperty::assign( const Gaudi::Details::PropertyBase& source )
{
return fromString( source.toString() ).isSuccess();
}
inline const DataObjIDColl& DataObjIDCollProperty::value() const
{
useReadHandler();
return *m_pValue;
}
[[deprecated( "replace DataObjIDProperty by Gaudi::Property<DataObjID>" )]] using DataObjIDProperty =
Gaudi::Property<DataObjID>;
[[deprecated( "replace DataObjIDCollProperty by Gaudi::Property<DataObjIDColl>" )]] using DataObjIDCollProperty =
Gaudi::Property<DataObjIDColl>;
#endif
......@@ -4,6 +4,7 @@
#include <mutex>
#include "GaudiKernel/DataHandle.h"
#include "GaudiKernel/DataObjectHandleProperty.h"
#include "GaudiKernel/IDataProviderSvc.h"
#include "GaudiKernel/IMessageSvc.h"
#include "GaudiKernel/IProperty.h"
......@@ -51,6 +52,8 @@ public:
friend std::ostream& operator<<( std::ostream& str, const DataObjectHandleBase& d );
using PropertyType = DataObjectHandleProperty;
/// Check if the data object declared is optional for the algorithm
bool isOptional() const { return m_optional; }
void setOptional( bool optional = true ) { m_optional = optional; }
......
......@@ -35,8 +35,6 @@ public:
const DataObjectHandleBase& value() const;
bool setValue( const DataObjectHandleBase& value );
std::string pythonRepr() const;
private:
/** Pointer to the real property. Reference would be better,
* but Reflex does not support references yet
......
......@@ -4,6 +4,7 @@
// Includes
#include "GaudiKernel/GaudiException.h"
#include "GaudiKernel/IInterface.h"
#include "GaudiKernel/Property.h"
#include "GaudiKernel/System.h"
#include <algorithm>
......@@ -148,6 +149,8 @@ public:
The corresponding python classes are defined in GaudiPython/GaudiHandles.py */
std::string pythonRepr() const override;
using PropertyType = GaudiHandleProperty;
private:
//
// Data member
......@@ -357,6 +360,7 @@ protected:
}
public:
using PropertyType = GaudiHandleArrayProperty;
typedef std::vector<GaudiHandleBase*> BaseHandleArray;
typedef std::vector<const GaudiHandleBase*> ConstBaseHandleArray;
......
......@@ -14,6 +14,8 @@
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//==============================================================================
// Boost:
......@@ -306,6 +308,14 @@ namespace Gaudi
struct Grammar_<Iterator, std::set<InnerT, CompareT, AllocatorT>, Skipper> {
typedef VectorGrammar<Iterator, std::set<InnerT, CompareT, AllocatorT>, Skipper> Grammar;
};
// ----------------------------------------------------------------------------
// Register VectorGrammar for std::unordered_set:
// ----------------------------------------------------------------------------
template <typename Iterator, typename InnerT, typename HashT, typename CompareT, typename AllocatorT,
typename Skipper>
struct Grammar_<Iterator, std::unordered_set<InnerT, HashT, CompareT, AllocatorT>, Skipper> {
typedef VectorGrammar<Iterator, std::unordered_set<InnerT, HashT, CompareT, AllocatorT>, Skipper> Grammar;
};
//==============================================================================
template <typename Iterator, typename PairT, typename Skipper>
......@@ -315,15 +325,13 @@ namespace Gaudi
typedef typename PairT::first_type first_type;
typedef typename PairT::second_type second_type;
//------------------------------------------------------------------------------
PairGrammar() : PairGrammar::base_type( pair ) { init( "," ); }
PairGrammar( const std::string& delimeter ) : PairGrammar::base_type( pair ) { init( delimeter ); }
//------------------------------------------------------------------------------
struct first {
};
struct second {
};
void init( const std::string& delimeter )
//------------------------------------------------------------------------------
PairGrammar() : PairGrammar( "," ) {}
PairGrammar( const std::string& delimeter ) : PairGrammar::base_type( pair )
{
begin = enc::char_( '(' )[qi::_val = ')'] | enc::char_( '[' )[qi::_val = ']'];
end = qi::char_( qi::_r1 );
......@@ -400,6 +408,14 @@ namespace Gaudi
typedef MapGrammar<Iterator, std::map<KeyT, ValueT, KeyCompareT, AllocatorT>, Skipper> Grammar;
};
// ----------------------------------------------------------------------------
// Register MapGrammar for std::unordered_map:
// ----------------------------------------------------------------------------
template <typename Iterator, typename KeyT, typename ValueT, typename HashT, typename KeyCompareT,
typename AllocatorT, typename Skipper>
struct Grammar_<Iterator, std::unordered_map<KeyT, ValueT, HashT, KeyCompareT, AllocatorT>, Skipper> {
typedef MapGrammar<Iterator, std::unordered_map<KeyT, ValueT, HashT, KeyCompareT, AllocatorT>, Skipper> Grammar;
};
// ----------------------------------------------------------------------------
// Register MapGrammar for GaudiUtils::VectorMap:
// ----------------------------------------------------------------------------
template <typename Iterator, typename KeyT, typename ValueT, typename KeyCompareT, typename AllocatorT,
......
......@@ -55,7 +55,6 @@ namespace Gaudi
template <typename ResultT>
inline StatusCode parse( ResultT& result, const std::string& input )
{
return parse_( result, input );
}
//=========================================================================
......
......@@ -22,23 +22,27 @@
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/Property.h"
#include "GaudiKernel/detected.h"
// ============================================================================
// pre-declaration of GaudiHandles is sufficient
template <class T>
class ToolHandle;
template <class T>
class ServiceHandle;
template <class T>
class ToolHandleArray;
template <class T>
class ServiceHandleArray;
template <class T>
class DataObjectHandle;
namespace Gaudi
{
namespace Details
{
template <typename T>
struct is_gaudi_property : std::false_type {
};
template <typename TYPE, typename VERIFIER, typename HANDLERS>
struct is_gaudi_property<Gaudi::Property<TYPE, VERIFIER, HANDLERS>> : std::true_type {
};
template <typename T>
using PropertyType_t = typename std::remove_reference_t<T>::PropertyType;
template <typename T>
using PropertyType = Gaudi::cpp17::detected_or_t<Gaudi::Property<T>, PropertyType_t, T>;
}
namespace Utils
{
/// Helper for case insensitive string comparison.
......@@ -104,29 +108,14 @@ public:
/// Helper to wrap a regular data member and use it as a regular property.
/// \deprecated Prefer the signatures using a a fully initialized PropertyBase instance.
template <class TYPE, typename = std::enable_if_t<!std::is_base_of<GaudiHandleBase, TYPE>::value &&
!std::is_base_of<GaudiHandleArrayBase, TYPE>::value &&
!std::is_base_of<DataObjectHandleBase, TYPE>::value>>
template <typename TYPE, typename = std::enable_if_t<!Gaudi::Details::is_gaudi_property<TYPE>::value>>
Gaudi::Details::PropertyBase* declareProperty( const std::string& name, TYPE& value, const std::string& doc = "none" )
{
assertUniqueName( name );
m_todelete.emplace_back( new Gaudi::Property<TYPE&>( name, value ) );
m_todelete.push_back( std::make_unique<Gaudi::Details::PropertyType<TYPE&>>( name, value ) );
Gaudi::Details::PropertyBase* p = m_todelete.back().get();
p->setDocumentation( doc );
m_properties.push_back( p );
return p;
}
/// \deprecated Kept for backward compatibility, use the non-const version instead, will be removed in v29r0.
template <class TYPE, typename = std::enable_if_t<!std::is_base_of<GaudiHandleBase, TYPE>::value &&
!std::is_base_of<GaudiHandleArrayBase, TYPE>::value &&
!std::is_base_of<DataObjectHandleBase, TYPE>::value>>
[[deprecated(
"Kept for backward compatibility, use the non-const version instead, will be removed in v29r0" )]] Gaudi::
Details::PropertyBase*
declareProperty( const std::string& name, TYPE& value, const std::string& doc = "none" ) const
{
return const_cast<PropertyHolder*>( this )->declareProperty<TYPE>( name, value, doc );
p->setDocumentation( doc );
return &declareProperty( *p );
}
/// Declare a PropertyBase instance setting name and documentation.
......@@ -136,12 +125,11 @@ public:
Gaudi::Property<TYPE, VERIFIER, HANDLERS>& prop,
const std::string& doc