Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSelectWriter.hh
Go to the documentation of this file.
1 #ifndef __JNET__JSELECTWRITER__
2 #define __JNET__JSELECTWRITER__
3 
4 #include <sys/select.h>
5 #include <limits>
6 #include <errno.h>
7 
8 #include "JLang/JException.hh"
10 #include "JLang/JAbstractFile.hh"
11 #include "JLang/JTimeval.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace JNET {}
19 namespace JPP { using namespace JNET; }
20 
21 namespace JNET {
22 
26  using JLANG::JTimeval;
27 
28 
29  /**
30  * Wrapper class for select call.
31  */
32  class JSelectWriter {
33  public:
34  /**
35  * Default constructor.
36  */
38  {}
39 
40 
41  /**
42  * Get writer mask.
43  *
44  * \return mask
45  */
47  {
48  return writerMask;
49  }
50 
51 
52  /**
53  * Set writer mask.
54  *
55  * \param file file
56  */
58  {
59  writerMask.set(file);
60  }
61 
62 
63  /**
64  * Has writer file.
65  *
66  * \param file file
67  * \return true if file set; else false
68  */
69  bool hasWriterMask(const JAbstractFile& file) const
70  {
71  return writerMask.has(file);
72  }
73 
74 
75  /**
76  * Reset.
77  */
78  void reset()
79  {
80  writerMask.reset(true); // hard reset
81  }
82 
83 
84  /**
85  * Select call.
86  *
87  * \param timeout timeout
88  * \return number of valid file descriptors
89  */
90  int operator()(JTimeval timeout)
91  {
92  return this->operator()(&timeout);
93  }
94 
95 
96  /**
97  * Select call.
98  *
99  * \param timeout timeout
100  * \return number of valid file descriptors
101  */
102  int operator()(timeval* timeout = NULL)
103  {
105 
106  nfds += 1;
107  nfds = ::select(nfds, NULL, &writerMask, NULL, timeout);
108 
109  if (nfds != 0) {
110 
111  if (nfds < 0) {
112  if (errno != EINTR) {
113  THROW(JSelectException, "JSelectWriter(..) failed.");
114  }
115  }
116 
117  } else {
118 
119  writerMask.reset(false); // soft reset
120  }
121 
122  return nfds;
123  }
124 
125 
126  protected:
128  };
129 }
130 
131 #endif
Exceptions.
bool select(const Trk &trk, const Evt &evt)
Event selection.
JFileDescriptorMask writerMask
then usage $script[< detector identifier >< run range >]< QA/QCfile > nExample script to produce data quality plots nWhen a detector identifier and run range are data are downloaded from the database nand subsequently stored in the given QA QC file
Definition: JDataQuality.sh:19
bool has(const int file_descriptor) const
Has file descriptor.
void set(const int file_descriptor)
Set file descriptor.
JFileDescriptorMask & getWriterMask()
Get writer mask.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
void setWriterMask(const JAbstractFile &file)
Set writer mask.
JSelectWriter()
Default constructor.
int operator()(JTimeval timeout)
Select call.
void reset()
Reset.
Exception for select call.
Definition: JException.hh:448
Auxiliary class for time values.
Definition: JTimeval.hh:26
void reset(const bool option=true)
Reset mask.
Auxiliary class for method select.
The JAbstractFile class encapsulates the c-style file descriptor.
int getNumberOfFileDescriptors() const
Get number of file descriptors.
int operator()(timeval *timeout=NULL)
Select call.
bool hasWriterMask(const JAbstractFile &file) const
Has writer file.
Wrapper class for select call.