OutputFileShare.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2014 by Paul Demorest
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 #ifndef __OutputFileShare_h
10 #define __OutputFileShare_h
11 
12 #include "Error.h"
13 #include "MJD.h"
14 #include "dsp/HasInput.h"
15 #include "dsp/Operation.h"
16 #include "dsp/BitSeries.h"
17 #include "dsp/OutputFile.h"
18 
19 class ThreadContext;
20 
21 namespace dsp {
22 
24 
35  class OutputFileShare : public Reference::Able { public:
36 
38  OutputFileShare (unsigned contributors);
39 
41  virtual ~OutputFileShare ();
42 
44  OutputFile* get_output_file () const { return output_file; }
45 
48 
50  void set_context (ThreadContext* t) { context = t; }
51 
53  ThreadContext* get_context () const { return context; }
54 
56  class Submit;
57 
59  Submit* new_Submit (unsigned contributor);
60 
62  MJD get_next_time () const { return next_time; }
63 
65  void set_next_time (MJD time) { next_time=time; }
66 
68  void signal_ready (unsigned contributor, MJD start_time);
69 
71  void signal_done (unsigned contributor);
72 
73  protected:
74 
76  unsigned contributors;
77 
80 
83 
86 
88  std::vector<MJD> start_times;
89 
91  bool first;
92 
94  unsigned nready;
95 
96  };
97 
98  class OutputFileShare::Submit : public OutputFile
99  {
100  public:
101 
103  Submit (OutputFileShare* parent, unsigned contributor);
104 
106  void operation ();
107 
109  std::string get_extension () const
110  {
111  return parent->output_file->get_extension();
112  };
113 
115  void write_header () { parent->output_file->write_header(); }
116 
117  protected:
118 
120  unsigned contributor;
121 
122  };
123 
124 }
125 
126 #endif // !defined(__OutputFileShare_h)
MJD get_next_time() const
Return next time.
Definition: OutputFileShare.h:62
void set_next_time(MJD time)
set next time
Definition: OutputFileShare.h:65
OutputFile * get_output_file() const
Get the output file.
Definition: OutputFileShare.h:44
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
Reference::To< OutputFile > output_file
The actual output file unloader.
Definition: OutputFileShare.h:79
void set_output_file(OutputFile *f)
Set the output file.
Definition: OutputFileShare.h:47
Share one OutputFile among multiple processing threads.
Definition: OutputFileShare.h:35
MJD next_time
Leading edge time of next output sample.
Definition: OutputFileShare.h:85
ThreadContext * context
Coordinate various threads.
Definition: OutputFileShare.h:82
Pure virtual base class of all objects that can unload BitSeries data.
Definition: OutputFile.h:30
std::vector< MJD > start_times
Current start times of waiting contributors.
Definition: OutputFileShare.h:88
static bool verbose
Global verbosity flag.
Definition: Operation.h:48
unsigned nready
Number of threads currently ready to write data.
Definition: OutputFileShare.h:94
Submit * new_Submit(unsigned contributor)
Return Submit interface for given contributor.
Definition: OutputFileShare.C:49
ThreadContext * get_context() const
Set the thread context.
Definition: OutputFileShare.h:53
OutputFileShare(unsigned contributors)
Constructor.
Definition: OutputFileShare.C:31
bool first
first-time-through flag
Definition: OutputFileShare.h:91
void set_context(ThreadContext *t)
Set the thread context.
Definition: OutputFileShare.h:50
void signal_done(unsigned contributor)
Call when a contributor is done.
Definition: OutputFileShare.C:98
void signal_ready(unsigned contributor, MJD start_time)
Call when a contributor is ready to write.
Definition: OutputFileShare.C:56
virtual ~OutputFileShare()
Destructor.
Definition: OutputFileShare.C:44
unsigned contributors
Number of contributors.
Definition: OutputFileShare.h:76

Generated using doxygen 1.8.17