Belle II Software  release-05-01-25
ZMQHistogramOutput.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <daq/hbasf2/connections/ZMQHistogramConnection.h>
13 #include <daq/hbasf2/utils/HistogramMapping.h>
14 
15 #include <framework/pcore/zmq/messages/ZMQIdMessage.h>
16 
17 #include <framework/pcore/EvtMessage.h>
18 #include <daq/dqm/DqmMemFile.h>
19 
20 #include <TBufferJSON.h>
21 
22 #include <lz4.h>
23 #include <TH1.h>
24 
25 #include <zmq.hpp>
26 
27 #include <string>
28 #include <memory>
29 #include <map>
30 #include <optional>
31 
32 namespace Belle2 {
57  template<class AConnectionClass>
58  class ZMQHistogramOutput : public AConnectionClass {
59  public:
61  template<class... Args>
62  ZMQHistogramOutput(unsigned int maximalUncompressedBufferSize, Args&& ... args);
63 
65  void handleEvent(std::unique_ptr<ZMQIdMessage> message);
67  void mergeAndSend(EMessageTypes messageType = EMessageTypes::c_eventMessage);
69  void clear();
70 
71  private:
74 
76  std::map<std::string, HistogramMapping> m_storedMessages;
78  std::vector<char> m_uncompressedBuffer;
79 
81  std::optional<unsigned int> m_storedExperiment = {};
83  std::optional<unsigned int> m_storedRun = {};
84  };
85 
86  template<class AConnectionClass>
87  template<class... Args>
88  ZMQHistogramOutput<AConnectionClass>::ZMQHistogramOutput(unsigned int maximalUncompressedBufferSize,
89  Args&& ... args) : AConnectionClass(std::forward<Args>(args)...), m_maximalUncompressedBufferSize(
90  maximalUncompressedBufferSize)
91  {
92  m_uncompressedBuffer.reserve(m_maximalUncompressedBufferSize);
93 
94  AConnectionClass::log("uncompressed_size", 0.0);
95  AConnectionClass::log("stored_identities", 0l);
96  AConnectionClass::log("histogram_clears", 0l);
97  AConnectionClass::log("last_clear", "");
98  }
99 
104 }
Belle2::ZMQHistogramOutput::m_uncompressedBuffer
std::vector< char > m_uncompressedBuffer
The buffer used during decompression.
Definition: ZMQHistogramOutput.h:86
Belle2::EMessageTypes
EMessageTypes
Type the messages can have.
Definition: ZMQDefinitions.h:26
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ZMQHistogramOutput::m_storedMessages
std::map< std::string, HistogramMapping > m_storedMessages
The stored histograms for each sender identity.
Definition: ZMQHistogramOutput.h:84
Belle2::ZMQHistogramOutput::m_storedExperiment
std::optional< unsigned int > m_storedExperiment
If already received: the experiment number of the data (on mismatch, everything is cleared)
Definition: ZMQHistogramOutput.h:89
Belle2::ZMQHistogramOutput::m_maximalUncompressedBufferSize
unsigned int m_maximalUncompressedBufferSize
Paramter for the buffer size (needed during decompression)
Definition: ZMQHistogramOutput.h:81
Belle2::ZMQHistogramOutput::handleEvent
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.
Definition: ZMQHistogramOutput.cc:30
Belle2::ZMQHistogramOutput::m_storedRun
std::optional< unsigned int > m_storedRun
If already received: the run number of the data (on mismatch, everything is cleared)
Definition: ZMQHistogramOutput.h:91
Belle2::ZMQHistogramOutput::ZMQHistogramOutput
ZMQHistogramOutput(unsigned int maximalUncompressedBufferSize, Args &&... args)
Perfectly forward the given arguments to the base class initializer (and init the buffer size)
Definition: ZMQHistogramOutput.h:96
Belle2::ZMQHistogramOutput::mergeAndSend
void mergeAndSend(EMessageTypes messageType=EMessageTypes::c_eventMessage)
Forward a merge call to the base class handing over the stored messages.
Definition: ZMQHistogramOutput.cc:98
Belle2::ZMQHistogramOutput::clear
void clear()
Forward a clear call to the base class and clear the stored messages. Should be called on run start.
Definition: ZMQHistogramOutput.cc:104
Belle2::ZMQHistogramOutput
Add the common functionality to the histogram output classes.
Definition: ZMQHistogramOutput.h:66