Belle II Software  release-06-01-15
ZMQHistogramOutput.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #pragma once
9 
10 #include <daq/hbasf2/connections/ZMQHistogramConnection.h>
11 #include <daq/hbasf2/utils/HistogramMapping.h>
12 
13 #include <framework/pcore/zmq/messages/ZMQIdMessage.h>
14 
15 #include <framework/pcore/EvtMessage.h>
16 #include <daq/dqm/DqmMemFile.h>
17 
18 #include <TBufferJSON.h>
19 
20 #include <lz4.h>
21 #include <TH1.h>
22 
23 #include <zmq.hpp>
24 
25 #include <string>
26 #include <memory>
27 #include <map>
28 #include <optional>
29 
30 namespace Belle2 {
55  template<class AConnectionClass>
56  class ZMQHistogramOutput : public AConnectionClass {
57  public:
59  template<class... Args>
60  ZMQHistogramOutput(unsigned int maximalUncompressedBufferSize, Args&& ... args);
61 
63  void handleEvent(std::unique_ptr<ZMQIdMessage> message);
65  void mergeAndSend(EMessageTypes messageType = EMessageTypes::c_eventMessage);
67  void clear();
68 
69  private:
72 
74  std::map<std::string, HistogramMapping> m_storedMessages;
76  std::vector<char> m_uncompressedBuffer;
77 
79  std::optional<unsigned int> m_storedExperiment = {};
81  std::optional<unsigned int> m_storedRun = {};
82  };
83 
84  template<class AConnectionClass>
85  template<class... Args>
86  ZMQHistogramOutput<AConnectionClass>::ZMQHistogramOutput(unsigned int maximalUncompressedBufferSize,
87  Args&& ... args) : AConnectionClass(std::forward<Args>(args)...), m_maximalUncompressedBufferSize(
88  maximalUncompressedBufferSize)
89  {
91 
92  AConnectionClass::log("uncompressed_size", 0.0);
93  AConnectionClass::log("stored_identities", 0l);
94  AConnectionClass::log("histogram_clears", 0l);
95  AConnectionClass::log("last_clear", "");
96  }
97 
102 }
Add the common functionality to the histogram output classes.
std::optional< unsigned int > m_storedRun
If already received: the run number of the data (on mismatch, everything is cleared)
std::vector< char > m_uncompressedBuffer
The buffer used during decompression.
unsigned int m_maximalUncompressedBufferSize
Paramter for the buffer size (needed during decompression)
void handleEvent(std::unique_ptr< ZMQIdMessage > message)
Handle a new message to be "sent" (what this means is up to the base class) as described above.
std::map< std::string, HistogramMapping > m_storedMessages
The stored histograms for each sender identity.
std::optional< unsigned int > m_storedExperiment
If already received: the experiment number of the data (on mismatch, everything is cleared)
void clear()
Forward a clear call to the base class and clear the stored messages. Should be called on run start.
void mergeAndSend(EMessageTypes messageType=EMessageTypes::c_eventMessage)
Forward a merge call to the base class handing over the stored messages.
ZMQHistogramOutput(unsigned int maximalUncompressedBufferSize, Args &&... args)
Perfectly forward the given arguments to the base class initializer (and init the buffer size)
EMessageTypes
Type the messages can have.
Abstract base class for different kinds of events.