| The Gaudi Framework v32r1 (f65d50dc)

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