8#include <daq/hbasf2/utils/HistogramMapping.h>
10#include <framework/pcore/MsgHandler.h>
11#include <framework/logging/Logger.h>
13#include <boost/range/combine.hpp>
15#include <TDirectory.h>
24 std::vector<TObject*> objects;
25 std::vector<std::string> names;
26 msgHandler.
decode_msg(msg.get(), objects, names);
28 B2ASSERT(
"Objects and names need to align", names.size() == objects.size());
30 for (
const auto& keyValue : boost::combine(names, objects)) {
33 boost::tie(key,
object) = keyValue;
35 TH1* histogram =
dynamic_cast<TH1*
>(object);
36 if (histogram ==
nullptr) {
37 B2WARNING(
"Object " << key <<
" is not a histogram!");
41 m_histograms.insert({key, std::unique_ptr<TH1>(histogram)});
49 const auto& key = keyValue.first;
50 const auto& histogram = keyValue.second;
54 B2DEBUG(100,
"Creating new histogram with name " << key <<
".");
55 auto* copiedHistogram =
dynamic_cast<TH1*
>(histogram->Clone());
56 m_histograms.insert({key, std::unique_ptr<TH1>(copiedHistogram)});
66 histogram->SetDirectory(gDirectory);
84 B2INFO(key <<
": " << histogram->GetName() <<
" -> " << histogram->GetEntries());
92 int objectCounter = 0;
94 msgHandler.
add(histogram.get(), key);
98 std::unique_ptr<Belle2::EvtMessage> msg(msgHandler.
encode_msg(Belle2::ERecordType::MSG_EVENT));
99 (msg->header())->reserved[0] = 0;
100 (msg->header())->reserved[1] = objectCounter;
HistogramMapping()=default
Default constructor needed during summation.
void write() const
Write out all stored histograms in the currently selected ROOT gDirectory.
HistogramMapping(const HistogramMapping &rhs)=delete
As this is a heavy object, make sure to not copy.
bool empty() const
Check if there are no stored histograms.
std::map< std::string, std::unique_ptr< TH1 > > m_histograms
Internal storage of the histograms in the form name -> unique TH1 pointer.
void printMe() const
Debug function to print out the content as into messages.
void clear()
Clear all histograms in the internal map also deleting the pointers.
std::unique_ptr< Belle2::EvtMessage > toMessage() const
Construct an EvtMessage by serializing the content of the internal histogram storage....
void operator+=(const HistogramMapping &rhs)
Add another histogramm tree instance by merging all histograms with the same name.
A class to encode/decode an EvtMessage.
virtual void decode_msg(EvtMessage *msg, std::vector< TObject * > &objlist, std::vector< std::string > &namelist)
Decode an EvtMessage into a vector list of objects with names.
virtual void add(const TObject *, const std::string &name)
Add an object to be streamed.
virtual EvtMessage * encode_msg(ERecordType rectype)
Stream object list into an EvtMessage.
Abstract base class for different kinds of events.