Belle II Software development
eclDumpECLCrystalCalib.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
9/* ECL headers. */
10#include <ecl/dataobjects/ECLElementNumbers.h>
11#include <ecl/dbobjects/ECLCrystalCalib.h>
12
13/* Basf2 headers. */
14#include <framework/database/Configuration.h>
15#include <framework/database/DBObjPtr.h>
16#include <framework/database/DBStore.h>
17#include <framework/dataobjects/EventMetaData.h>
18#include <framework/datastore/DataStore.h>
19#include <framework/datastore/StoreObjPtr.h>
20
21/* ROOT headers. */
22#include <TFile.h>
23#include <TH1F.h>
24
25/* C++ headers. */
26#include <iostream>
27
28using namespace Belle2;
29
30//------------------------------------------------------------------------
31//..Set experiment, run, and event numbers before reading a payload from the DB
32namespace {
33 void setupDatabase(int exp, int run, int eventNr = 1)
34 {
36 // simulate the initialize() phase where we can register objects in the DataStore
38 evtPtr.registerInDataStore();
40 std::cout << "about to construct EventMetaData, exp = " << exp << " run = " << run << " eventNr = " << eventNr << std::endl;
41 evtPtr.construct(eventNr, run, exp);
42 DBStore& dbstore = DBStore::Instance();
43 dbstore.update();
44 dbstore.updateEvent();
45 }
46}
47
48//------------------------------------------------------------------------
49int main(int argc, char** argv)
50{
51 if (argc < 4 || argc > 5) {
52 std::cout << "incorrect number of arguments for eclDumpECLCrystalCalib" << std::endl;
53 return -1;
54 }
55 std::string payloadName = argv[1];
56 std::string gtName = argv[2];
57 int experiment = std::stoi(argv[3]);
58 int run = std::stoi(argv[4]);
59 std::cout << "eclDumpECLCrystalCalib called with arguments " << payloadName << " " << gtName << " " << experiment << " " << run <<
60 " " <<
61 std::endl;
62
63 //------------------------------------------------------------------------
64 //..Specify database
66 conf.prependGlobalTag(gtName);
67 conf.prependTestingPayloadLocation("localdb/database.txt");
68
69 //..Populate database contents
70 std::cout << "calling setupDatabase " << std::endl;
71 setupDatabase(experiment, run);
72
73 //------------------------------------------------------------------------
74 //..Read payloads from database
75 DBObjPtr<Belle2::ECLCrystalCalib> existingObject(payloadName);
76 std::cout << "Dumping " << payloadName << std::endl;
77 existingObject->Dump();
78
79 //..Get vectors of values from the payloads
80 std::vector<float> currentValues = existingObject->getCalibVector();
81 std::vector<float> currentUnc = existingObject->getCalibUncVector();
82
83 //..Print out a few values for quality control
84 std::cout << std::endl << "Values read from database " << std::endl;
85 for (int ic = 0; ic < 9000; ic += 1000) {
86 std::cout << "cellID " << ic + 1 << " " << currentValues[ic] << " +/- " << currentUnc[ic] << std::endl;
87 }
88 std::cout << std::endl;
89
90 TString payloadTitle = payloadName;
91 payloadTitle += "_";
92 payloadTitle += experiment;
93 payloadTitle += "_";
94 payloadTitle += run;
95 TString fname = payloadTitle;
96 fname += ".root";
97 TFile hfile(fname, "recreate");
98 TString htitle = payloadTitle;
99 htitle += " values;cellID";
100 TH1F* existingPayload = new TH1F("existingPayload", htitle, ECLElementNumbers::c_NCrystals, 1, 8737);
101
102 for (int cellID = 1; cellID <= ECLElementNumbers::c_NCrystals; cellID++) {
103 existingPayload->SetBinContent(cellID, currentValues[cellID - 1]);
104 existingPayload->SetBinError(cellID, currentUnc[cellID - 1]);
105 }
106
107 hfile.cd();
108 hfile.Write();
109 hfile.Close();
110 std::cout << std::endl << "Values written to " << fname << std::endl;
111}
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
Singleton class to cache database objects.
Definition: DBStore.h:31
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
void setInitializeActive(bool active)
Setter for m_initializeActive.
Definition: DataStore.cc:94
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
Definition: StoreObjPtr.h:119
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:28
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:142
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:79
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.