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