otsdaq  v2_05_02_indev
DataConsumer.h
1 #ifndef _ots_DataConsumer_h_
2 #define _ots_DataConsumer_h_
3 
4 #include <map>
5 #include <string>
6 #include "otsdaq/DataManager/DataProcessor.h"
7 
8 namespace ots
9 {
10 // DataConsumer
11 // This class provides base class functionality for Data Consumer plugin classes to
12 // extracts and process streaming data from a Buffer.
13 class DataConsumer : public DataProcessor, public virtual WorkLoop
14 {
15  public:
16  enum ConsumerPriority
17  {
18  LowConsumerPriority, // If the buffers are full because a low priority consumer
19  // didn't emptied them then overwrite
20  HighConsumerPriority // Can't overwrite but need to wait for sometime before
21  // writing a buffer
22  };
23  DataConsumer(std::string supervisorApplicationUID, std::string bufferUID, std::string processorUID, ConsumerPriority priority);
24  virtual ~DataConsumer(void);
25 
26  virtual void registerToBuffer(void);
27  // virtual void unregisterFromBuffer (void);
28 
29  virtual void startProcessingData(std::string runNumber);
30  virtual void stopProcessingData(void);
31 
32  // Copies the buffer into the passed parameters
33  template<class D, class H>
34  int read(D& buffer, H& header)
35  {
36  return static_cast<CircularBuffer<D, H>*>(theCircularBuffer_)->read(buffer, header, processorUID_);
37  }
38 
39  // Fast version where you point to the buffer without copying
40  template<class D, class H>
41  int read(D*& buffer, H*& header)
42  {
43  return static_cast<CircularBuffer<D, H>*>(theCircularBuffer_)->read(buffer, header, processorUID_);
44  }
45 
46  template<class D, class H>
47  int setReadSubBuffer(void)
48  {
49  return static_cast<CircularBuffer<D, H>*>(theCircularBuffer_)
50  ->getLastReadBuffer(DataProcessor::processorUID_)
51  .setReadSubBuffer(DataProcessor::processorUID_);
52  }
53 
54  template<class D, class H>
55  int read(D& buffer)
56  {
57  return static_cast<CircularBuffer<D, H>*>(theCircularBuffer_)->read(buffer, processorUID_);
58  }
59 
60  ConsumerPriority getPriority(void);
61 
62  private:
63  ConsumerPriority priority_;
64 };
65 
66 } // namespace ots
67 
68 #endif