Belle II Software  release-05-01-25
b2hlt_create_histos.cc
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 #include <daq/dqm/DqmMemFile.h>
11 #include <daq/rfarm/event/hltsocket/HLTMainLoop.h>
12 #include <framework/datastore/DataStore.h>
13 #include <framework/datastore/StoreObjPtr.h>
14 #include <framework/dataobjects/EventMetaData.h>
15 #include <framework/logging/Logger.h>
16 
17 #include <daq/hbasf2/utils/HLTStreamHelper.h>
18 #include <TH1.h>
19 
20 #include <boost/program_options.hpp>
21 #include <fstream>
22 #include <iostream>
23 
24 
25 namespace po = boost::program_options;
26 using namespace Belle2;
27 
28 int main(int argc, char* argv[])
29 {
30  std::string outputFileName;
31 
32  po::options_description
33  desc("b2hlt_create_histos - helper tool to create a single histogram raw file for testing.");
34  desc.add_options()
35  ("help,h", "Print this help message")
36  ("output", po::value<std::string>(&outputFileName)->required(),
37  "where to store the histograms to");
38 
39  po::positional_options_description p;
40 
41  po::variables_map vm;
42  try {
43  po::store(
44  po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
45  } catch (std::exception& e) {
46  B2FATAL(e.what());
47  }
48 
49  if (vm.count("help")) {
50  std::cout << desc << std::endl;
51  exit(1);
52  }
53 
54  try {
55  po::notify(vm);
56  } catch (std::exception& e) {
57  B2FATAL(e.what());
58  }
59 
61  StoreObjPtr<EventMetaData> eventMetaData;
62  eventMetaData.registerInDataStore();
64 
65  eventMetaData.create();
66 
67  TH1F histogram("my_histogram", "Some title", 1, 0, 1);
68  histogram.Fill(0.5);
69  histogram.Fill(0.5);
70 
71  HLTStreamHelper streamHelper;
72  auto message = streamHelper.streamHistograms();
73  const auto& histogramMessage = message->getDataMessage();
74 
75  std::ofstream outfile(outputFileName, std::ofstream::binary);
76  outfile.write(histogramMessage.data<char>(), histogramMessage.size());
77  outfile.close();
78 }
Belle2::HLTStreamHelper
Helper class for data store serialization.
Definition: HLTStreamHelper.h:52
prepareAsicCrosstalkSimDB.e
e
aux.
Definition: prepareAsicCrosstalkSimDB.py:53
Belle2::DataStore::Instance
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
Belle2::DataStore::setInitializeActive
void setInitializeActive(bool active)
Setter for m_initializeActive.
Definition: DataStore.cc:94
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::HLTStreamHelper::streamHistograms
std::unique_ptr< ZMQNoIdMessage > streamHistograms(bool compressed=true)
Stream all objects derived from TH1 into a message. Only the last subfolder is streamed by prefixing ...
Definition: HLTStreamHelper.cc:155