Index: applgrid/trunk/appl_grid/file_index.h =================================================================== --- applgrid/trunk/appl_grid/file_index.h (revision 1901) +++ applgrid/trunk/appl_grid/file_index.h (revision 1902) @@ -1,185 +1,189 @@ /* emacs: this is -*- c++ -*- */ /** ** @file file_index.h ** ** @author sutt ** @date Thu 31 Dec 2020 14:42:12 GMT ** ** $Id: file_index.h, v0.0 Thu 31 Dec 2020 14:42:12 GMT sutt $ ** ** Copyright (C) 2020 sutt (sutt@cern.ch) ** **/ #ifndef FILE_INDEX_H #define FILE_INDEX_H #include #include #include #include #include "appl_grid/serialise_base.h" class file_index { public: // histogram error exception class exception : public std::exception { public: exception(const std::string& s) { std::cerr << what() << " " << s << std::endl; }; virtual const char* what() const throw() { return ""; } }; struct entry { entry( int sz=0, int off=0 ) : size(sz), offset(off) { } double size; double offset; }; public: typedef std::map map_t; typedef std::map rmap_t; public: file_index() : mname("index"), mrunning(0) { } virtual ~file_index() { } std::string name() const { return mname; } void add( const std::string& s, int bytes, int offset=-1 ) { mkeys.push_back( s ); mmap.insert( map_t::value_type( s, entry( bytes, mrunning ) ) ); mrmap.insert( rmap_t::value_type( mrunning, s ) ); if ( offset!=-1 && mrunning!=offset ) std::cerr << "index:: offset mismatch" << std::endl; mrunning += bytes; } size_t size() const { return mkeys.size(); } std::vector::const_iterator begin() const { return mkeys.begin(); } std::vector::const_iterator end() const { return mkeys.end(); } entry find( const std::string& s ) const { map_t::const_iterator itr = mmap.find( s ); if ( itr!=mmap.end() ) return itr->second; return entry(); } void clear() { mkeys.clear(); mmap.clear(); mrmap.clear(); } /// serialisation and deserialisation ... std::vector serialise() const { std::vector s; s.push_back( SB::WRITEGUARD ); s.push_back(0); // overall size SB::serialise( s, name() ); s.push_back( mkeys.size() ); for ( size_t i=0 ; i& v ) { mname.clear(); mkeys.clear(); mmap.clear(); mrmap.clear(); std::vector::const_iterator itr = v.begin(); if ( (*itr++) != SB::WRITEGUARD ) throw exception("file_index: read error"); // int ntotal = (*itr++); (*itr++); SB::deserialise( itr, mname ); size_t nkeys = (*itr++); for ( size_t i=0 ; i mkeys; map_t mmap; rmap_t mrmap; int mrunning; }; inline std::ostream& operator<<( std::ostream& s, const file_index::entry& e ) { - return s << "index: 0x" << std::hex << int(e.offset) << std::dec << "\tsize: " << int(e.size); + std::string space = ""; + if ( e.offset<0x10000 ) space += "\t"; + return s << "index: 0x" << std::hex << int(e.offset) << std::dec << space << " size: " << int(e.size); } inline std::ostream& operator<<( std::ostream& s, const file_index& f ) { s << "file index: " << f.size() << " keys\n"; for ( std::vector::const_iterator itr=f.begin() ; itr!=f.end() ; itr++ ) { std::string space = ""; if ( itr->size()<31 ) space += "\t"; + if ( itr->size()<23 ) space += "\t"; + if ( itr->size()<15 ) space += "\t"; if ( itr->size()<7 ) space += "\t"; s << " Key: " << *itr << space << " " << f.find(*itr) << "\n"; } return s; } #endif // FILE_INDEX_H