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