Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:33

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIALG_FIXTESPATH_H
0012 #define GAUDIALG_FIXTESPATH_H
0013 #include <memory>
0014 #include <string>
0015 #include <string_view>
0016 #include <type_traits>
0017 
0018 #include "GaudiKernel/AlgTool.h"
0019 #include "GaudiKernel/Algorithm.h"
0020 #include "GaudiKernel/IDataManagerSvc.h"
0021 #include "GaudiKernel/MsgStream.h"
0022 #include <Gaudi/Property.h>
0023 
0024 namespace FixTESPathDetails {
0025   std::unique_ptr<IDataHandleVisitor> fixDataHandlePath( std::string_view rit, std::string rootName, MsgStream* dbg );
0026   std::string                         fullTESLocation( std::string_view location, std::string_view rit );
0027 } // namespace FixTESPathDetails
0028 
0029 template <class BASE>
0030 class FixTESPath : public BASE {
0031 public:
0032   /// Algorithm constructor - the SFINAE constraint below ensures that this is
0033   /// constructor is only defined if BASE derives from Algorithm
0034   template <typename U = BASE, typename = std::enable_if_t<std::is_base_of_v<Gaudi::Algorithm, BASE>, U>>
0035   FixTESPath( std::string name, ISvcLocator* pSvcLocator ) : BASE( std::move( name ), pSvcLocator ) {}
0036 
0037   /// Tool constructor - SFINAE-ed to insure this constructor is only defined
0038   /// if BASE derives from AlgTool.
0039   template <typename U = BASE, typename = std::enable_if_t<std::is_base_of_v<AlgTool, BASE>, U>>
0040   FixTESPath( std::string type, std::string name, const IInterface* ancestor )
0041       : BASE( std::move( type ), std::move( name ), ancestor ) {
0042     // setup RootInTES from parent if available
0043     if ( const IProperty* ancestorProp = dynamic_cast<const IProperty*>( ancestor );
0044          ancestorProp && ancestorProp->hasProperty( "RootInTES" ) ) {
0045       this->setProperty( ancestorProp->getProperty( "RootInTES" ) ).ignore();
0046     }
0047   }
0048 
0049   StatusCode initialize() override {
0050     return BASE::initialize().andThen( [&] {
0051       // TODO: just call 'acceptDHVisitor` and remove m_updateDataHandles...
0052       SmartIF<IDataManagerSvc> dataMgrSvc{ BASE::evtSvc() };
0053       this->m_updateDataHandles = FixTESPathDetails::fixDataHandlePath(
0054           rootInTES(), dataMgrSvc->rootName(), BASE::msgLevel( MSG::DEBUG ) ? &this->debug() : nullptr );
0055     } );
0056   }
0057 
0058   /** @brief Returns the "rootInTES" string.
0059    *  Used as the directory root in the TES for which all data access refers to (both saving and retrieving).
0060    */
0061   const std::string& rootInTES() const { return m_rootInTES; }
0062   // ==========================================================================
0063   /// Returns the full correct event location given the rootInTes settings
0064   std::string fullTESLocation( std::string_view location, bool useRootInTES ) const {
0065     return FixTESPathDetails::fullTESLocation( location, useRootInTES ? rootInTES() : std::string_view{} );
0066   }
0067   // ==========================================================================
0068 private:
0069   Gaudi::Property<std::string> m_rootInTES{ this,
0070                                             "RootInTES",
0071                                             {},
0072                                             [this]( Gaudi::Details::PropertyBase& ) { // Check rootInTES ends with a '/'
0073                                               auto& rit = this->m_rootInTES.value();
0074                                               if ( !rit.empty() && rit.back() != '/' ) rit += '/';
0075                                             },
0076                                             "note: overridden by parent settings" };
0077 };
0078 
0079 #endif