GRUTinizer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TRawEventSource.h
Go to the documentation of this file.
1 #ifndef _TRAWEVENTSOURCE_H_
2 #define _TRAWEVENTSOURCE_H_
3 
4 #include "Globals.h"
5 
6 #include <cstdio>
7 #include <ctime>
8 #include <deque>
9 #include <string>
10 
11 #include "TStopwatch.h"
12 
13 #include "TGRUTTypes.h"
14 #include "TGRUTOptions.h"
15 #include "TRawEvent.h"
16 #include "TSmartBuffer.h"
17 
18 
20 public:
22  : fBytesGiven(0), fLastErrno(0), fIsFinished(0) { }
23  virtual ~TRawEventSource() { }
24 
25  static TRawEventSource* EventSource(const char* filename,
26  bool is_online = false, bool is_ring = false,
27  kFileType file_type = DefaultFileType());
28 
30 
37  int Read(TRawEvent& event);
38 
39  int Read(TRawEvent* event);
40 
41  virtual std::string SourceDescription() const = 0;
42  virtual std::string Status() const = 0;
43 
44  virtual int GetLastErrno() const { return fLastErrno; }
45  virtual std::string GetLastError() const { return fLastError; }
46 
47  bool IsFinished() const { return fIsFinished; }
48  size_t GetBytesGiven() const { return fBytesGiven; }
49  double GetAverageRate() const;
50 
51 protected:
52  void SetLastErrno(int error) { fLastErrno = error; }
53  void SetLastError(std::string error) { fLastError = error; }
54 
55 private:
57 
61  virtual int GetEvent(TRawEvent& event) = 0;
62 
63  void UpdateByteThroughput(int bytes);
64 
65  static kFileType DefaultFileType();
66 
67 
68  size_t fBytesGiven;
71  std::string fLastError;
72 
73  std::deque<size_t> fBytesPerSecond;
74  time_t current_time;
76 
78 };
79 
80 
82 public:
83  TRawEventByteSource(kFileType file_type);
84 
85  virtual std::string Status() const;
86 
87 
88  kFileType GetFileType() const { return fFileType; }
89  long GetFileSize() const { return fFileSize; }
90 
91 protected:
92  void SetFileSize(long file_size) { fFileSize = file_size; }
93 
94 private:
96 
102  virtual int ReadBytes(char* buf, size_t size) = 0;
103 
104  virtual int GetEvent(TRawEvent& event);
105  int FillBuffer(size_t bytes_requested);
106 
108  mutable TStopwatch clock;
109 
110  long fFileSize;
111 
114 
116 };
117 
118 
120 public:
121  TRawEventPipeSource(const std::string& command, kFileType file_type);
123 
124  virtual int ReadBytes(char* buf, size_t size);
125 
126  virtual std::string SourceDescription() const;
127 private:
128  std::string fCommand;
129  FILE* fPipe;
130 
132 };
133 
134 #endif /* _TRAWEVENTSOURCE_H_ */