Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r0 (2143aa4c)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FixTESPath.cpp
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 \***********************************************************************************/
12 #include "GaudiKernel/MsgStream.h"
13 #include "boost/tokenizer.hpp"
14 #include <memory>
15 #include <numeric>
16 #include <string>
17 #include <string_view>
18 
19 namespace {
20  // update DataHandles to point to full TES location
21  //
22  template <typename F>
23  class DHHFixer : public IDataHandleVisitor {
24  F m_f;
25 
26  public:
27  DHHFixer( F f ) : m_f( std::move( f ) ) {}
28 
29  void visit( const IDataHandleHolder* idhh ) override {
30  if ( !idhh ) return;
31 
32  std::string r;
33  for ( auto h : idhh->inputHandles() ) {
34  r = m_f( h->objKey() );
35  if ( r != h->objKey() ) h->updateKey( r );
36  }
37  for ( auto h : idhh->outputHandles() ) {
38  r = m_f( h->objKey() );
39  if ( r != h->objKey() ) h->updateKey( r );
40  }
41  }
42  };
43 
44  template <typename F>
45  auto make_unique_DHHFixer( F f ) {
46  return std::make_unique<DHHFixer<F>>( std::move( f ) );
47  }
48 
49 } // namespace
50 
51 namespace FixTESPathDetails {
52 
53  // ============================================================================
54  // Returns the full correct event location given the rootInTes settings
55  // ============================================================================
56  std::string fullTESLocation( std::string_view location, std::string_view rit ) {
57  // The logic is:
58  // if no R.I.T., give back location
59  // if R.I.T., this is the mapping:
60  // (note that R.I.T. contains a trailing '/')
61  // location -> result
62  // -------------------------------------------------
63  // "" -> R.I.T.[:-1] ("rit")
64  // "/Event" -> R.I.T.[:-1] ("rit")
65  // "/Event/MyObj" -> R.I.T. + "MyObj" ("rit/MyObj")
66  // "MyObj" -> R.I.T. + "MyObj" ("rit/MyObj")
67  return rit.empty() ? std::string{ location }
68  : location.empty() || ( location == "/Event" ) ? std::string{ rit.substr( 0, rit.size() - 1 ) }
69  : location.compare( 0, 7, "/Event/" ) == 0 ? std::string{ rit }.append( location.substr( 7 ) )
70  : location.compare( 0, 1, "/" ) == 0 ? std::string{ rit }.append( location.substr( 1 ) )
71  : std::string{ rit }.append( location );
72  }
73 
75  if ( !rootName.empty() && '/' != rootName.back() ) rootName += "/";
76  return make_unique_DHHFixer( [rit, rootName = std::move( rootName ), dbg]( std::string const& location ) {
77  auto tokens = boost::tokenizer{ location, boost::char_separator{ ":" } };
78  auto result =
79  std::accumulate( tokens.begin(), tokens.end(), std::string{}, [&]( std::string s, std::string_view tok ) {
80  std::string r = fullTESLocation( tok, rit );
81  // check whether we have an absolute path if yes use it - else prepend DataManager Root
82  if ( r[0] != '/' ) r = rootName + r;
83  return s.empty() ? r : s + ':' + r;
84  } );
85  if ( result != location && dbg ) ( *dbg ) << "Changing " << location << " to " << result << endmsg;
86  return result;
87  } );
88  }
89 } // namespace FixTESPathDetails
IDataHandleHolder
Definition: IDataHandleHolder.h:24
std::string
STL class.
std::move
T move(T... args)
GaudiAlg.HistoUtils.location
location
Definition: HistoUtils.py:964
gaudirun.s
string s
Definition: gaudirun.py:346
FixTESPathDetails::fullTESLocation
std::string fullTESLocation(std::string_view location, std::string_view rit)
Definition: FixTESPath.cpp:56
std::string::back
T back(T... args)
AlgSequencer.h
h
Definition: AlgSequencer.py:31
std::accumulate
T accumulate(T... args)
FixTESPathDetails
Definition: FixTESPath.h:24
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
IDataHandleHolder::inputHandles
virtual std::vector< Gaudi::DataHandle * > inputHandles() const =0
MsgStream
Definition: MsgStream.h:34
std::string::append
T append(T... args)
IDataHandleVisitor
Definition: IDataHandleHolder.h:46
std::string::substr
T substr(T... args)
IDataHandleHolder.h
std
STL namespace.
IDataHandleHolder::outputHandles
virtual std::vector< Gaudi::DataHandle * > outputHandles() const =0
std::string::empty
T empty(T... args)
std::unique_ptr< IDataHandleVisitor >
FixTESPathDetails::fixDataHandlePath
std::unique_ptr< IDataHandleVisitor > fixDataHandlePath(std::string_view rit, std::string rootName, MsgStream *dbg)
Definition: FixTESPath.cpp:74
MsgStream.h
IDataHandleVisitor::visit
virtual void visit(const IDataHandleHolder *)=0