NOvASocketInputDriver.h
Go to the documentation of this file.
1 #ifndef DAQ2RAWDIGIT_NOVASOCKETINPUTDRIVER_H
2 #define DAQ2RAWDIGIT_NOVASOCKETINPUTDRIVER_H
3 
4 ////////////////////////////////////////////////////////////////////////
5 /// \file NOvASocketInputDriver.h
6 /// \brief Source to read raw Events from a socket, per specifications
7 /// in NOvA-DocDB-3947 and NOvA-DocDB-4390.
8 ///
9 /// \version $Id: NOvASocketInputDriver.h,v 1.5 2012-11-18 18:52:46 gsdavies Exp $
10 /// \author paterno@fnal.gov
11 ////////////////////////////////////////////////////////////////////////
13 
17 
18 #include "boost/asio.hpp" // socket support
19 
20 #include <string>
21 #include <vector>
22 
23 // forward declarations
24 namespace fhicl{
25  class ParameterSet;
26 }
27 namespace art{
28  class ProductRegistryHelper;
29  class FileBlock;
30  class EventPrincipal;
31  class RunPrincipal;
32  class SubRunPrincipal;
33 }
34 
35 
36 namespace daq2raw {
37  class NOvASocketInputDriver;
38 }
39 
40 namespace art {
41  // Specialize this trait from SourceTraits.h
42  template <>
43  struct Source_wantFileServices<daq2raw::NOvASocketInputDriver> {
44  static constexpr bool value = false;
45  };
46 }
47 
48 
50  /// Class to fill the constraints on a template argument to the class,
51  /// art::Source
52 public:
53  // Required constructor
56  art::SourceHelper const &pm);
57 
58  // Required by art::Source:
59  void closeCurrentFile();
60  void readFile(std::string const &name,
61  art::FileBlock* &fb);
62  bool readNext(art::RunPrincipal* const &inR,
63  art::SubRunPrincipal* const &inSR,
64  art::RunPrincipal* &outR,
65  art::SubRunPrincipal* &outSR,
66  art::EventPrincipal* &outE);
67 
68 private:
69  typedef std::vector<uint32_t> eb_t; ///< Event buffer type.
70  typedef eb_t::value_type ebe_t; ///< Event buffer element type.
71  typedef std::vector<uint8_t> cb_t; ///< Command buffer type.
72 
73  static size_t in_bytes(size_t nElements) {
74  return nElements * sizeof(ebe_t);
75  }
76 
77  static size_t in_elements(size_t nBytes) {
78  size_t result = nBytes / sizeof(ebe_t);
79  return (in_bytes(result) == nBytes)?
80  result:
81  result+1;
82  }
83 
84  art::SourceHelper const& fSourceHelper; ///< Class to help with {Run, SubRun, Event}Principal construction.
85  std::string fCurrentFilename; ///< Hang on to the current filename.
86  art::SubRunID fCurrentSubRunID; ///< Keep track of the current subRun details.
87  boost::asio::io_service fIoService; ///< Object representing IO services of the OS.
88  boost::asio::ip::tcp::socket fSocket; ///< Object representing the socket from which we read.
89  size_t fCurrentEventCapacity; ///< Current event capacity in buffer elements (current buffer size is 1 more than this);
90  size_t fMaxEventSizeBytes; ///< Will not try to read an event bigger than this.
91  std::vector<uint32_t> fSocketBuffer; ///< Raw data buffer for socket communication.
92 
93  bool fFilterCorruptedNanoslices;///< Filter the corrupted nanaslices in the unpacking?
94  bool fDoFillFlatDAQData; ///< Do we need to fill FlatDAQData object?
95 
96  int fMaxReadAttempts; ///< Maximum number of read attempts before we throw
97 
98  int fCorruptEventCount; ///< Counter for the total number of corrupt events encountered
99  int fConsecutiveCorruptEventCount; ///< Counter for the number of consecutive corrupt events encountered
100  int fBadReadCount; ///< Counter for the total number of corrupt events encountered
101  int fConsecutiveBadReadCount; ///< Counter for the number of consecutive corrupt events encountered
102 
103  uint32_t trigmask_word1; ///< Lowest word in the trigger mask only the lower 24 bit are used
104  uint32_t trigmask_word2; ///< Middle word (bits 31-63) in the trigger mask
105  uint32_t trigmask_word3; ///< High word (bits 64-96) in the trigger mask
106 
107  int fTransmitDelay; ///< Delay in microseconds to wait between command transmission
108 
109 }; // NOvASocketInputDriver
110 
111 #endif /* DAQ2RAWDIGIT_NOVASOCKETINPUTDRIVER_H */
112 
eb_t::value_type ebe_t
Event buffer element type.
const XML_Char * name
Definition: expat.h:151
socket
Definition: g4zmq.py:12
int fConsecutiveBadReadCount
Counter for the number of consecutive corrupt events encountered.
int fTransmitDelay
Delay in microseconds to wait between command transmission.
static size_t in_elements(size_t nBytes)
static size_t in_bytes(size_t nElements)
int fConsecutiveCorruptEventCount
Counter for the number of consecutive corrupt events encountered.
bool fDoFillFlatDAQData
Do we need to fill FlatDAQData object?
art::SourceHelper const & fSourceHelper
Class to help with {Run, SubRun, Event}Principal construction.
uint32_t trigmask_word2
Middle word (bits 31-63) in the trigger mask.
const XML_Char int const XML_Char * value
Definition: expat.h:331
std::vector< uint32_t > eb_t
Event buffer type.
art::SubRunID fCurrentSubRunID
Keep track of the current subRun details.
size_t fMaxEventSizeBytes
Will not try to read an event bigger than this.
A module to produce rawdata::RawDigits from NOvADDT DAQHits.
bool fFilterCorruptedNanoslices
Filter the corrupted nanaslices in the unpacking?
std::string fCurrentFilename
Hang on to the current filename.
uint32_t trigmask_word1
Lowest word in the trigger mask only the lower 24 bit are used.
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
uint32_t trigmask_word3
High word (bits 64-96) in the trigger mask.
std::vector< uint8_t > cb_t
Command buffer type.
boost::asio::io_service fIoService
Object representing IO services of the OS.
int fCorruptEventCount
Counter for the total number of corrupt events encountered.
boost::asio::ip::tcp::socket fSocket
Object representing the socket from which we read.
int fBadReadCount
Counter for the total number of corrupt events encountered.
int fMaxReadAttempts
Maximum number of read attempts before we throw.
size_t fCurrentEventCapacity
Current event capacity in buffer elements (current buffer size is 1 more than this);.
std::vector< uint32_t > fSocketBuffer
Raw data buffer for socket communication.
enum BeamMode string