Gaudi Framework, version v23r7

Home   Generated: Wed Mar 20 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HbookName.h
Go to the documentation of this file.
1 // $Id: HbookName.h,v 1.2 2006/12/10 19:11:56 leggett Exp $
2 // ============================================================================
3 #ifndef GAUDIALG_HBOOKNAME_H
4 #define GAUDIALG_HBOOKNAME_H 1
5 // Include files
6 #include <string>
7 #include <algorithm>
8 
18 namespace
19 {
34  inline std::string dirHbookName
35  ( const std::string& addr ,
36  const int maxLen = 16 )
37  {
38  // ignore empty locations
39  if( addr.empty() ) { return std::string(); }
40  //
41  std::string old( addr );
42  // remove long names
43  if( 0 < maxLen && maxLen < (int) old.size() )
44  {
46  p1 = old.begin();
47  const char sep('/');
48  while( old.end() != p1 )
49  {
50  p1 =
51  std::find_if( p1 ,
52  old.end() ,
54  p2 = std::find( p1 , old.end() , sep ) ;
55  if( ( p2 - p1 ) <= (int) maxLen ) { p1 = p2 ; continue ; }
56  old.insert( p1 + maxLen , sep ) ;
57  p1 = old.begin() ;
58  }
59  }
61  return old;
62  }
63 
81  inline std::string histoHbookName
82  ( const std::string& addr ,
83  const int maxLen = 8 )
84  {
85  // ignore empty locations
86  if( addr.empty() ) { return std::string(); }
87  //
88  std::string old( addr );
89  { // make valid histogram ID (integer)
91  = old.find_last_of( '/' );
92  if ( std::string::npos == pos ) { old += "/1" ; }
93  else if ( old.size() - 1 == pos ) { old += '1' ; }
94  else
95  {
96  const int id =
97  atoi( std::string( old , pos + 1 , std::string::npos ).c_str() );
98  if( 0 == id ) { old+="/1"; }
99  }
100  }
101  // remove long names
102  if( 0 < maxLen && maxLen < (int) old.size() )
103  {
104  std::string::iterator p1,p2;
105  p1 = old.begin();
106  const char sep('/');
107  while( old.end() != p1 )
108  {
109  p1 =
110  std::find_if( p1 ,
111  old.end() ,
113  p2 = std::find( p1 , old.end() , sep ) ;
114  if( ( p2 - p1 ) <= (int) maxLen ) { p1 = p2 ; continue ; }
115  old.insert( p1 + maxLen , sep ) ;
116  p1 = old.begin() ;
117  }
118  }
119  //
120  return old;
121  }
122 
123 } // end of anonymous namespace
124 
125 // ============================================================================
126 // The END
127 // ============================================================================
128 #endif // GAUDIALG_HBOOKNAME_H
129 // ============================================================================

Generated at Wed Mar 20 2013 17:59:36 for Gaudi Framework, version v23r7 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004