The Gaudi Framework  v32r2 (46d42edc)
FixTESPath.cpp
Go to the documentation of this file.
3 #include "boost/tokenizer.hpp"
4 #include <memory>
5 #include <numeric>
6 #include <string>
7 #include <string_view>
8 
9 namespace {
10  // update DataHandles to point to full TES location
11  //
12  template <typename F>
13  class DHHFixer : public IDataHandleVisitor {
14  F m_f;
15 
16  public:
17  DHHFixer( F f ) : m_f( std::move( f ) ) {}
18 
19  void visit( const IDataHandleHolder* idhh ) override {
20  if ( !idhh ) return;
21 
22  std::string r;
23  for ( auto h : idhh->inputHandles() ) {
24  r = m_f( h->objKey() );
25  if ( r != h->objKey() ) h->updateKey( r );
26  }
27  for ( auto h : idhh->outputHandles() ) {
28  r = m_f( h->objKey() );
29  if ( r != h->objKey() ) h->updateKey( r );
30  }
31  }
32  };
33 
34  template <typename F>
35  auto make_unique_DHHFixer( F f ) {
36  return std::make_unique<DHHFixer<F>>( std::move( f ) );
37  }
38 
39 } // namespace
40 
41 namespace FixTESPathDetails {
42 
43  // ============================================================================
44  // Returns the full correct event location given the rootInTes settings
45  // ============================================================================
46  std::string fullTESLocation( std::string_view location, std::string_view rit ) {
47  // The logic is:
48  // if no R.I.T., give back location
49  // if R.I.T., this is the mapping:
50  // (note that R.I.T. contains a trailing '/')
51  // location -> result
52  // -------------------------------------------------
53  // "" -> R.I.T.[:-1] ("rit")
54  // "/Event" -> R.I.T.[:-1] ("rit")
55  // "/Event/MyObj" -> R.I.T. + "MyObj" ("rit/MyObj")
56  // "MyObj" -> R.I.T. + "MyObj" ("rit/MyObj")
57  return rit.empty()
59  : location.empty() || ( location == "/Event" )
60  ? std::string{rit.substr( 0, rit.size() - 1 )}
61  : location.compare( 0, 7, "/Event/" ) == 0
62  ? std::string{rit}.append( location.substr( 7 ) )
63  : location.compare( 0, 1, "/" ) == 0 ? std::string{rit}.append( location.substr( 1 ) )
64  : std::string{rit}.append( location );
65  }
66 
68  if ( !rootName.empty() && '/' != rootName.back() ) rootName += "/";
69  return make_unique_DHHFixer( [rit, rootName = std::move( rootName ), dbg]( std::string const& location ) {
70  auto tokens = boost::tokenizer{location, boost::char_separator{":"}};
71  auto result =
72  std::accumulate( tokens.begin(), tokens.end(), std::string{}, [&]( std::string s, std::string_view tok ) {
73  std::string r = fullTESLocation( tok, rit );
74  // check whether we have an absolute path if yes use it - else prepend DataManager Root
75  if ( r[0] != '/' ) r = rootName + r;
76  return s.empty() ? r : s + ':' + r;
77  } );
78  if ( result != location && dbg ) ( *dbg ) << "Changing " << location << " to " << result << endmsg;
79  return result;
80  } );
81  }
82 } // namespace FixTESPathDetails
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
T empty(T... args)
virtual std::vector< Gaudi::DataHandle * > inputHandles() const =0
STL namespace.
STL class.
virtual void visit(const IDataHandleHolder *)=0
T append(T... args)
std::string fullTESLocation(std::string_view location, std::string_view rit)
Definition: FixTESPath.cpp:46
T move(T... args)
virtual std::vector< Gaudi::DataHandle * > outputHandles() const =0
T back(T... args)
string s
Definition: gaudirun.py:318
T substr(T... args)
T accumulate(T... args)
std::unique_ptr< IDataHandleVisitor > fixDataHandlePath(std::string_view rit, std::string rootName, MsgStream *dbg)
Definition: FixTESPath.cpp:67
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192