00001 #ifndef BESIII_EVTIDX_HANDLER_H
00002 #define BESIII_EVTIDX_HANDLER_H
00003
00004 #include <vector>
00005 #include <string>
00006 #include <fstream>
00007
00008 class EvtIdxHandler
00009 {
00010 public :
00011
00012 static uint32_t IdxFileStartMarker() { return 0xFFFFAAAA; }
00013 static uint32_t IdxIdBlockMarker() { return 0xFFFFBBBB; }
00014 static uint32_t IdxPosBlockMarker() { return 0xFFFFCCCC; }
00015
00016 static EvtIdxHandler* instance(const std::vector<std::string>& fnames);
00017 static void release();
00018
00019 EvtIdxHandler();
00020 virtual ~EvtIdxHandler();
00021
00022
00023 void next_file();
00024
00025 uint32_t nextPos(int nIgnore);
00026 uint32_t findPosById(uint32_t evtId);
00027
00028 int nEvtLeft(int nIgnore) const {
00029 return ( m_totEvt - (m_idxPos+nIgnore) );
00030 }
00031
00032
00033 void addPos(uint32_t evtId, uint32_t pos);
00034 void write(std::string fname);
00035
00036
00037 private :
00038
00039 EvtIdxHandler(const std::vector<std::string>& idxfnames);
00040
00041 void init_idx();
00042 void enlarge_block(int min_size);
00043
00044
00045 private :
00046
00047 int m_totEvt;
00048 int m_idxPos;
00049
00050 int m_blockSize;
00051 uint32_t* m_EIdBlock;
00052 uint32_t* m_PosBlock;
00053
00054 std::vector<std::string> m_fnames;
00055 std::vector<std::string>::iterator m_curFile;
00056 std::fstream m_fs;
00057
00058 static int _nHandler;
00059 static EvtIdxHandler* _instance;
00060 };
00061
00062 #endif