The Gaudi Framework  v30r3 (a5ef0a68)
HbookName.h
Go to the documentation of this file.
1 #ifndef GAUDIALG_HBOOKNAME_H
2 #define GAUDIALG_HBOOKNAME_H 1
3 // Include files
4 #include <algorithm>
5 #include <string>
6 
16 namespace
17 {
32  inline std::string dirHbookName( const std::string& addr, const int maxLen = 16 )
33  {
34  // ignore empty locations
35  if ( addr.empty() ) {
36  return std::string();
37  }
38  //
39  std::string old( addr );
40  // remove long names
41  if ( 0 < maxLen && maxLen < (int)old.size() ) {
42  auto p1 = old.begin();
43  const char sep( '/' );
44  while ( old.end() != p1 ) {
45  p1 = std::find_if( p1, old.end(), [&]( const char& c ) { return c != sep; } );
46  auto p2 = std::find( p1, old.end(), sep );
47  if ( ( p2 - p1 ) <= (int)maxLen ) {
48  p1 = p2;
49  continue;
50  }
51  old.insert( p1 + maxLen, sep );
52  p1 = old.begin();
53  }
54  }
56  return old;
57  }
58 
59 } // end of anonymous namespace
60 
61 // ============================================================================
62 // The END
63 // ============================================================================
64 #endif // GAUDIALG_HBOOKNAME_H
65 // ============================================================================
T empty(T...args)
STL class.
T find_if(T...args)