The Gaudi Framework  v33r0 (d5ea422b)
FixTESPath.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIALG_FIXTESPATH_H
12 #define GAUDIALG_FIXTESPATH_H
13 #include <memory>
14 #include <string>
15 #include <string_view>
16 #include <type_traits>
17 
18 #include "GaudiKernel/AlgTool.h"
19 #include "GaudiKernel/Algorithm.h"
21 #include "GaudiKernel/MsgStream.h"
22 #include "GaudiKernel/Property.h"
23 
24 namespace FixTESPathDetails {
25  std::unique_ptr<IDataHandleVisitor> fixDataHandlePath( std::string_view rit, std::string rootName, MsgStream* dbg );
26  std::string fullTESLocation( std::string_view location, std::string_view rit );
27 } // namespace FixTESPathDetails
28 
29 template <class BASE>
30 class FixTESPath : public BASE {
31 public:
34  template <typename U = BASE, typename = std::enable_if_t<std::is_base_of_v<Gaudi::Algorithm, BASE>, U>>
35  FixTESPath( const std::string& name, ISvcLocator* pSvcLocator ) : BASE( name, pSvcLocator ) {}
36 
39  template <typename U = BASE, typename = std::enable_if_t<std::is_base_of_v<AlgTool, BASE>, U>>
40  FixTESPath( const std::string& type, const std::string& name, const IInterface* ancestor )
41  : BASE( type, name, ancestor ) {
42  // setup RootInTES from parent if available
43  if ( const IProperty* ancestorProp = dynamic_cast<const IProperty*>( ancestor );
44  ancestorProp && ancestorProp->hasProperty( "RootInTES" ) ) {
45  this->setProperty( ancestorProp->getProperty( "RootInTES" ) ).ignore();
46  }
47  }
48 
49  StatusCode initialize() override {
50  const StatusCode sc = BASE::initialize();
51  if ( sc.isFailure() ) return sc;
52  // TODO: just call 'acceptDHVisitor` and remove m_updateDataHandles...
53  SmartIF<IDataManagerSvc> dataMgrSvc{BASE::evtSvc()};
54  this->m_updateDataHandles = FixTESPathDetails::fixDataHandlePath(
55  rootInTES(), dataMgrSvc->rootName(), BASE::msgLevel( MSG::DEBUG ) ? &this->debug() : nullptr );
56  return sc;
57  }
58 
62  const std::string& rootInTES() const { return m_rootInTES; }
63  // ==========================================================================
65  std::string fullTESLocation( std::string_view location, bool useRootInTES ) const {
66  return FixTESPathDetails::fullTESLocation( location, useRootInTES ? rootInTES() : std::string_view{} );
67  }
68  // ==========================================================================
69 private:
71  "RootInTES",
72  {},
73  [=]( Gaudi::Details::PropertyBase& ) { // Check rootInTES ends with a '/'
74  auto& rit = this->m_rootInTES.value();
75  if ( !rit.empty() && rit.back() != '/' ) rit += '/';
76  },
77  "note: overridden by parent settings"};
78 };
79 
80 #endif
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:34
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:35
Implementation of property with value of concrete type.
Definition: Property.h:370
STL class.
FixTESPath(const std::string &type, const std::string &name, const IInterface *ancestor)
Tool constructor - SFINAE-ed to insure this constructor is only defined if BASE derives from AlgTool.
Definition: FixTESPath.h:40
Gaudi::Property< std::string > m_rootInTES
Definition: FixTESPath.h:70
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
Definition of the basic interface.
Definition: IInterface.h:254
virtual bool hasProperty(const std::string &name) const =0
Return true if we have a property with the given name.
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:243
std::string fullTESLocation(std::string_view location, std::string_view rit)
Definition: FixTESPath.cpp:56
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
FixTESPath(const std::string &name, ISvcLocator *pSvcLocator)
Algorithm constructor - the SFINAE constraint below ensures that this is constructor is only defined ...
Definition: FixTESPath.h:35
const std::string & rootInTES() const
Returns the "rootInTES" string.
Definition: FixTESPath.h:62
std::string fullTESLocation(std::string_view location, bool useRootInTES) const
Returns the full correct event location given the rootInTes settings.
Definition: FixTESPath.h:65
StatusCode initialize() override
Definition: FixTESPath.h:49
bool isFailure() const
Definition: StatusCode.h:141
std::unique_ptr< IDataHandleVisitor > fixDataHandlePath(std::string_view rit, std::string rootName, MsgStream *dbg)
Definition: FixTESPath.cpp:77
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition: IProperty.h:30