PAASS
Software suite to Acquire and Analyze Data from Pixie16
hribf_buffers.h
Go to the documentation of this file.
1 
22 #ifndef HRIBF_BUFFERS_H
23 #define HRIBF_BUFFERS_H
24 
25 #include <fstream>
26 #include <vector>
27 
28 #define HRIBF_BUFFERS_VERSION "1.3.00"
29 #define HRIBF_BUFFERS_DATE "Sept. 19th, 2016"
30 
31 #define ACTUAL_BUFF_SIZE 8194
32 
33 class Client;
34 
35 class BufferType{
36  protected:
37  unsigned int bufftype;
38  unsigned int buffsize;
39  unsigned int buffend;
40  unsigned int zero;
41  bool debug_mode;
42 
43  BufferType(unsigned int bufftype_, unsigned int buffsize_, unsigned int buffend_=0xFFFFFFFF);
44 
46  virtual bool Write(std::ofstream *file_);
47 
49  virtual bool Read(std::ifstream *file_);
50 
52  virtual void Reset(){ }
53 
54  public:
55  unsigned int GetBufferType(){ return bufftype; }
56 
57  unsigned int GetBufferSize(){ return buffsize; }
58 
59  unsigned int GetBufferEndFlag(){ return buffend; }
60 
61  bool DebugMode(){ return debug_mode; }
62 
63  void SetDebugMode(bool debug_=true){ debug_mode = debug_; }
64 
66  bool ReadHeader(std::ifstream *file_);
67 };
68 
70 class PLD_header : public BufferType{
71  private:
72  unsigned int run_num; // Run number
73  unsigned int max_spill_size; // Maximum size of spill in file (in words)
74  float run_time; // Total length of run (time acquisition is running in seconds)
75  char format[17]; // 'PIXIE LIST DATA ' (16 bytes)
76  char facility[17]; // 'U OF TENNESSEE ' (16 bytes)
77  char start_date[25]; // Wed Feb 13 16:06:10 2013 (24 bytes)
78  char end_date[25]; // Wed Feb 13 16:06:10 2013 (24 bytes)
79  char *run_title; // Unlimited length
80 
81  time_t runStartTime;
82  time_t runStopTime;
83 
84  public:
85  PLD_header();
86  ~PLD_header();
87 
88  unsigned int GetBufferLength();
89 
90  char *GetFacility(){ return facility; }
91 
92  char *GetFormat(){ return format; }
93 
94  char *GetStartDate(){ return start_date; }
95 
96  char *GetEndDate(){ return end_date; }
97 
98  char *GetRunTitle(){ return run_title; }
99 
100  unsigned int GetRunNumber(){ return run_num; }
101 
102  unsigned int GetMaxSpillSize(){ return max_spill_size; }
103 
104  float GetRunTime(){ return run_time; }
105 
106  void SetStartDateTime();
107 
108  void SetEndDateTime();
109 
110  void SetFacility(std::string input_);
111 
112  void SetTitle(std::string input_);
113 
114  void SetRunNumber(unsigned int input_){ run_num = input_; }
115 
116  void SetMaxSpillSize(unsigned int max_spill_size_){ max_spill_size = max_spill_size_; }
117 
118  void SetRunTime(float time_){ run_time = time_; }
119 
122  virtual bool Write(std::ofstream *file_);
123 
125  virtual bool Read(std::ifstream *file_);
126 
128  virtual void Reset();
129 
131  void Print();
132 
134  void PrintDelimited(const char &delimiter_='\t');
135 };
136 
138 class PLD_data : public BufferType{
139  private:
140 
141  public:
142  PLD_data();
143 
145  virtual bool Write(std::ofstream *file_, char *data_, unsigned int nWords_);
146 
148  virtual bool Read(std::ifstream *file_, char *data_, unsigned int &nBytes, unsigned int max_bytes_, bool dry_run_mode=false);
149 
151  virtual void Reset(){ }
152 };
153 
154 /* The DIR buffer is written at the beginning of each .ldf file. When the file is ready
155  to be closed, the data within the DIR buffer is re-written with run information. */
156 class DIR_buffer : public BufferType{
157  private:
158  unsigned int total_buff_size;
159  unsigned int run_num;
160  unsigned int unknown[3];
161 
162  public:
163  DIR_buffer();
164 
165  unsigned int GetTotalBufferSize(){ return total_buff_size; }
166 
167  unsigned int GetRunNumber(){ return run_num; }
168 
169  void SetRunNumber(unsigned int input_){ run_num = input_; }
170 
171  /* DIR buffer (1 word buffer type, 1 word buffer size, 1 word for total buffer length,
172  1 word for total number of buffers, 2 unknown words, 1 word for run number, 1 unknown word,
173  and 8186 zeros) */
174  virtual bool Write(std::ofstream *file_);
175 
177  virtual bool Read(std::ifstream *file_);
178 
180  virtual void Reset();
181 
183  void Print();
184 
186  void PrintDelimited(const char &delimiter_='\t');
187 };
188 
189 /* The HEAD buffer is written after the DIR buffer for each .ldf file. HEAD contains information
190  about the run including the date/time, the title, and the run number. */
191 class HEAD_buffer : public BufferType{
192  private:
193  char facility[9];
194  char format[9];
195  char type[17];
196  char date[17];
197  char run_title[81];
198  unsigned int run_num;
199 
200  public:
201  HEAD_buffer();
202 
203  char *GetFacility(){ return facility; }
204 
205  char *GetFormat(){ return format; }
206 
207  char *GetType(){ return type; }
208 
209  char *GetDate(){ return date; }
210 
211  char *GetRunTitle(){ return run_title; }
212 
213  unsigned int GetRunNumber(){ return run_num; }
214 
215  bool SetDateTime();
216 
217  bool SetTitle(std::string input_);
218 
219  void SetRunNumber(unsigned int input_){ run_num = input_; }
220 
224  virtual bool Write(std::ofstream *file_);
225 
227  virtual bool Read(std::ifstream *file_);
228 
230  virtual void Reset();
231 
233  void Print();
234 
236  void PrintDelimited(const char &delimiter_='\t');
237 };
238 
240 class DATA_buffer : public BufferType{
241  private:
242  int retval;
243 
244  unsigned int buffer1[ACTUAL_BUFF_SIZE];
245  unsigned int buffer2[ACTUAL_BUFF_SIZE];
246 
247  unsigned int *curr_buffer;
248  unsigned int *next_buffer;
249 
250  unsigned int bcount;
251  unsigned int buff_head;
252  unsigned int buff_size;
253  unsigned int good_chunks;
254  unsigned int missing_chunks;
255 
256  unsigned int buff_pos;
257 
259  bool open_(std::ofstream *file_);
260 
261  bool read_next_buffer(std::ifstream *f_, bool force_=false);
262 
263  public:
264  DATA_buffer();
265 
267  bool Close(std::ofstream *file_);
268 
272  int GetSpillSize(std::ifstream *file_);
273 
283  int GetRetval(){ return retval; }
284 
286  unsigned int GetNumChunks(){ return good_chunks; }
287 
289  unsigned int GetNumMissing(){ return missing_chunks; }
290 
292  virtual bool Write(std::ofstream *file_, char *data_, unsigned int nWords_, int &buffs_written);
293 
295  virtual bool Read(std::ifstream *file_, char *data_, unsigned int &nBytes_, unsigned int max_bytes_, bool &full_spill, bool &bad_spill, bool dry_run_mode=false);
296 
298  virtual void Reset();
299 };
300 
302 class EOF_buffer : public BufferType{
303  public:
304  EOF_buffer();
305 
307  virtual bool Write(std::ofstream *file_);
308 
310  virtual bool Read(std::ifstream *file_);
311 
313  virtual void Reset(){ }
314 };
315 
317  private:
318  std::ofstream output_file;
319  std::string fname_prefix;
320  std::string current_filename;
328  unsigned int max_spill_size;
329  unsigned int current_file_num;
330  unsigned int output_format;
331  unsigned int number_spills;
332  unsigned int run_num;
334 
335  unsigned int current_depth;
336  std::string current_directory;
337  std::vector<std::string> directories;
338 
340  std::string get_filename();
341 
343  bool get_full_filename(std::string &output);
344 
348  bool overwrite_dir(int total_buffers_=-1);
349 
351  void initialize();
352 
353  public:
354  PollOutputFile();
355 
356  PollOutputFile(std::string filename_);
357 
358  ~PollOutputFile(){ CloseFile(); }
359 
361  std::streampos GetFilesize(){ return output_file.tellp(); }
362 
364  std::string GetCurrentFilename(){ return current_filename; }
365 
367  unsigned int GetNumberSpills(){ return number_spills; }
368 
371 
373  PLD_data *GetPLDdata(){ return &pldData; }
374 
376  DIR_buffer *GetDIRbuffer(){ return &dirBuff; }
377 
379  HEAD_buffer *GetHEADbuffer(){ return &headBuff; }
380 
382  DATA_buffer *GetDATAbuffer(){ return &dataBuff; }
383 
385  EOF_buffer *GetEOFbuffer(){ return &eofBuff; }
386 
388  void SetDebugMode(bool debug_=true);
389 
391  bool SetFileFormat(unsigned int format_);
392 
394  void SetFilenamePrefix(std::string filename_);
395 
397  bool IsOpen(){ return (output_file.is_open() && output_file.good()); }
398 
400  int Write(char *data_, unsigned int nWords_);
401 
404  int SendPacket(Client *cli_);
405 
407  bool OpenNewFile(std::string title_, unsigned int &run_num_, std::string prefix, std::string output_dir="./", bool continueRun = false);
408 
409  std::string GetNextFileName(unsigned int &run_num_, std::string prefix, std::string output_dir, bool continueRun = false);
410 
411  unsigned int GetRunNumber();
412 
414  void CloseFile(float total_run_time_=0.0);
415 };
416 
417 #endif
void SetRunTime(float time_)
PLD_header pldHead
Definition: headReader.cpp:11
HEAD_buffer headBuff
unsigned int good_chunks
Total size of ldf buffer (in 4 byte words).
char * GetEndDate()
Definition: hribf_buffers.h:96
unsigned int run_num
unsigned int GetBufferEndFlag()
Definition: hribf_buffers.h:59
unsigned int GetRunNumber()
virtual bool Read(std::ifstream *file_)
Returns only false if not overloaded.
unsigned int buffend
Definition: hribf_buffers.h:39
DATA_buffer dataBuff
unsigned int bufftype
Definition: hribf_buffers.h:37
virtual bool Write(std::ofstream *file_)
Returns only false if not overloaded.
bool DebugMode()
Definition: hribf_buffers.h:61
void SetRunNumber(unsigned int input_)
std::string current_full_filename
#define ACTUAL_BUFF_SIZE
Definition: hribf_buffers.h:31
unsigned int current_file_num
unsigned int GetMaxSpillSize()
unsigned int GetBufferSize()
Definition: hribf_buffers.h:57
unsigned int run_num
std::string current_directory
unsigned int buff_head
The total number of ldf buffers read from file.
unsigned int buff_size
The ldf buffer header ID.
char * GetRunTitle()
The pld header contains information about the run including the date/time, the title, and the run number.
Definition: hribf_buffers.h:70
time_t runStopTime
Definition: hribf_buffers.h:82
unsigned int GetRunNumber()
unsigned int run_num
HEAD_buffer * GetHEADbuffer()
Return a pointer to the HEAD buffer object.
PLD_data pldData
char * GetDate()
char * GetFormat()
unsigned int buff_pos
Count of the number of missing spill chunks which were dropped.
float run_time
Definition: hribf_buffers.h:74
PLD_header pldHead
float GetRunTime()
unsigned int total_buff_size
std::vector< std::string > directories
unsigned int GetNumChunks()
Return the number of good spill chunks which were read.
unsigned int output_format
DIR_buffer dirBuff
DATA_buffer * GetDATAbuffer()
Return a pointer to the DATA buffer object.
unsigned int max_spill_size
A single EOF buffer signals the end of a run (pacman .ldf format). A double EOF signals the end of th...
unsigned int zero
Definition: hribf_buffers.h:40
unsigned int max_spill_size
Definition: hribf_buffers.h:73
char * GetRunTitle()
Definition: hribf_buffers.h:98
EOF_buffer * GetEOFbuffer()
Return a pointer to the EOF buffer object.
unsigned int missing_chunks
Count of the number of good spill chunks which were read.
unsigned int GetRunNumber()
bool debug_mode
Definition: hribf_buffers.h:41
void SetRunNumber(unsigned int input_)
unsigned int GetNumMissing()
Return the number of missing or dropped spill chunks.
void SetDebugMode(bool debug_=true)
Definition: hribf_buffers.h:63
void SetMaxSpillSize(unsigned int max_spill_size_)
DIR_buffer * GetDIRbuffer()
Return a pointer to the DIR buffer object.
std::ofstream output_file
unsigned int GetBufferType()
Definition: hribf_buffers.h:55
unsigned int bcount
Pointer to the next ldf buffer.
unsigned int number_spills
virtual void Reset()
Does nothing if not overloaded.
Definition: hribf_buffers.h:52
std::string GetCurrentFilename()
Get the name of the current output file.
char * GetFacility()
virtual void Reset()
Set initial values.
PLD_header * GetPLDheader()
Return a pointer to the PLD header object.
BufferType(unsigned int bufftype_, unsigned int buffsize_, unsigned int buffend_=0xFFFFFFFF)
Generic BufferType constructor.
EOF_buffer eofBuff
PLD_data * GetPLDdata()
Return a pointer to the PLD data object.
char * GetFormat()
Definition: hribf_buffers.h:92
char * run_title
Definition: hribf_buffers.h:79
std::string current_filename
unsigned int * next_buffer
Pointer to the current ldf buffer.
unsigned int current_depth
unsigned int GetNumberSpills()
Return the total number of spills written since the current file was opened.
void SetRunNumber(unsigned int input_)
unsigned int GetTotalBufferSize()
unsigned int run_num
Definition: hribf_buffers.h:72
char * GetStartDate()
Definition: hribf_buffers.h:94
bool ReadHeader(std::ifstream *file_)
Return true if the first word of the current buffer is equal to this buffer type. ...
bool IsOpen()
Return true if an output file is open and writable and false otherwise.
unsigned int buffsize
Definition: hribf_buffers.h:38
std::string fname_prefix
char * GetType()
time_t runStartTime
Definition: hribf_buffers.h:81
char * GetFacility()
Get the total length of the buffer (in bytes)
Definition: hribf_buffers.h:90
std::streampos GetFilesize()
Get the size of the current file, in bytes.
virtual void Reset()
Set initial values.
The DATA buffer contains all physics data within the .pld file.
unsigned int * curr_buffer
Container for a second ldf buffer.