Reader.hh

Go to the documentation of this file.
00001 
00007 #ifndef READER_h
00008 #define READER_h
00009 
00010 #include <zlib.h>
00011 #include <string>
00012 #include "RawEvent.hh"
00013 #include "VParameterNode.hh"
00014 
00015 
00019 class Reader{
00020 public:
00022   Reader(const std::string& filename);
00024   ~Reader();
00025 public:
00026   //access functions
00028   bool IsOk(){ return _ok; } 
00030   bool eof(){ return _end_last_file || ( gzeof(_fin) && OpenNextFile() ); }
00031   //All event getters return null pointer if error
00033   RawEventPtr GetNextEvent(bool read_header = true);   
00035   RawEventPtr GetEventWithIndex(int index);
00037   RawEventPtr GetEventWithID(uint32_t id);
00039   RawEventPtr GetLastEvent();
00041   int GetCurrentIndex(){ return _current_index; }
00043   bool GetAssociatedParameter(VParameterNode* par, 
00044                               std::string key="");
00045 
00046   // headers for version control
00047 public:
00048   static const uint32_t magic_number = 0xdec0ded1; 
00049   static const uint32_t latest_global_version = 1;
00050   static const uint32_t latest_event_version = 1;
00051   struct global_header{
00052     uint32_t magic_num_check;
00053     uint32_t global_header_size;
00054     uint32_t global_header_version;
00055     uint32_t event_header_size; 
00056     uint32_t event_header_version;
00057     uint32_t file_size;
00058     uint32_t start_time;
00059     uint32_t end_time;
00060     uint32_t run_id;
00061     uint32_t file_index;
00062     uint32_t nevents;
00063     uint32_t event_id_min;
00064     uint32_t event_id_max;
00065     global_header() : magic_num_check(magic_number), 
00066                       global_header_size(sizeof(global_header)),
00067                       global_header_version(1),
00068                       event_header_size(sizeof(event_header)),
00069                       event_header_version(1) {}
00070     
00071   };
00072   struct event_header{
00073     uint32_t event_size; 
00074     uint32_t event_id;
00075     uint32_t timestamp;
00076     uint32_t nblocks;
00077     event_header() : event_size(sizeof(event_header)){}
00078     void reset(){ event_size=0; event_id=0; timestamp=0; nblocks=0; }
00079   };
00080 
00081   struct datablock_header{
00082     uint32_t total_blocksize_disk;
00083     uint32_t datasize;
00084     uint32_t type;
00085   };
00086   
00087   struct event_header_v0{
00088     uint32_t event_size;
00089     uint32_t event_id;
00090     uint32_t timestamp;
00091   };
00092 
00093 private:
00094   const std::string _filename; 
00095   gzFile _fin; 
00096   bool _ok; 
00097   long _current_index;  
00098   long _current_id; 
00099   global_header _ghead; 
00100   event_header _ehead; 
00101   RawEventPtr _current_event; 
00102   uint32_t _current_file_index; 
00103   std::string _current_file_name; 
00104   static const uint32_t _unset_file_index = 0xFFFFFFFF;
00105   bool _end_last_file; 
00106   
00108   bool ErrorCheck(int bytes_read, int bytes_requested); 
00109   
00111   int Reset();
00113   int ReadNextHeader();
00115   z_off_t SkipNextEvent(bool skip_header = true);
00116   
00118   int OpenNextFile();
00120   int CloseCurrentFile();
00121   
00122 };
00123 
00124 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 20 Jun 2014 for daqman by  doxygen 1.6.1