Belle II Software development
eclWriteLocalDB.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/DBImportObjPtr.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#include <framework/logging/LogSystem.h>
21
22/* C++ headers. */
23#include <iostream>
24
25using namespace Belle2;
26
28namespace {
29 void setupDatabase(int exp, int run, int eventNr = 1)
30 {
32 // simulate the initialize() phase where we can register objects in the DataStore
34 evtPtr.registerInDataStore();
36 // now construct the event metadata
37 evtPtr.construct(eventNr, run, exp);
38 // and update the database contents
39 DBStore& dbstore = DBStore::Instance();
40 dbstore.update();
41 // this is only needed it the payload might be intra-run dependent,
42 // that is if it might change during one run as well
43 dbstore.updateEvent();
44 }
45}
46
47
48int main()
49{
50
62 std::vector<float> tempCalib;
63 std::vector<float> tempCalibUnc;
64
66 /*
67 float calib = 0.;
68 float calibUnc = 0.;
69 for (int cellID = 1; cellID <= ECLElementNumbers::c_NCrystals; cellID++) {
70 tempCalib.push_back(calib);
71 tempCalibUnc.push_back(calibUnc);
72 } */
73
75 /* std::ifstream calibFile("refref1.txt");
76 float cellIDf, amplitude, toff;
77 for(int cellID=1; cellID <= ECLElementNumbers::c_NCrystals; cellID++) {
78 calibFile >> cellIDf >> amplitude >> toff;
79 if(cellID<=1152) {
80 calib = 1.;
81 } else {
82 calib = 17800./amplitude;
83 }
84 calibUnc = 0.;
85 tempCalib.push_back(calib);
86 tempCalibUnc.push_back(calibUnc);
87 if(cellID%100==0) {std::cout << cellID << " ampl = " << amplitude << " calib = " << calib << " " << calibUnc << std::endl;}
88 } */
89
91 /* TFile f("eclCosmicEAlgorithm.root");
92 TH1F *CalibvsCrys = (TH1F*)f.Get("CalibvsCrys");
93 for(int cellID=1; cellID <= ECLElementNumbers::c_NCrystals; cellID++) {
94 if(cellID<1153) {
95 calib = 4.06902e-05;
96 calibUnc = 0.;
97 } else {
98 calib = CalibvsCrys->GetBinContent(cellID);
99 calibUnc = CalibvsCrys->GetBinError(cellID);
100 }
101 tempCalib.push_back(calib);
102 tempCalibUnc.push_back(calibUnc);
103 if(cellID%100==0) {std::cout << "cellID = " << cellID << " calib = " << calib << " +/- " << calibUnc << std::endl; }
104 } */
105
113 logging->setDebugLevel(10);
114
116 DBObjPtr<Belle2::ECLCrystalCalib> InputCalib("ECLCrystalEnergy");
117
119 int experiment = 1002;
120 int run = 1;
121 setupDatabase(experiment, run);
122
124 InputCalib->Dump();
125
127 std::vector<float> calibIn;
128 std::vector<float> calibInUnc;
129 calibIn = InputCalib->getCalibVector();
130 calibInUnc = InputCalib->getCalibUncVector();
131
133 tempCalib = calibIn;
134 tempCalibUnc = calibInUnc;
135
137 for (int ic = 0; ic < 9000; ic += 1000) {
138 std::cout << "crysID " << ic << " calib = " << tempCalib[ic] << " +/- " << tempCalibUnc[ic] << std::endl;
139 }
140
141 //..Write out to localdb
142 std::cout << "Creating importer" << std::endl;
143 Belle2::DBImportObjPtr<Belle2::ECLCrystalCalib> importer("ECLCrystalEnergyGammaGamma");
144 importer.construct();
145 importer->setCalibVector(tempCalib, tempCalibUnc);
146 importer.import(Belle2::IntervalOfValidity(0, 0, -1, -1));
147 std::cout << "Successfully wrote payload ECLCrystalEnergyGammaGamma" << std::endl;
148}
Class for importing a single object to the database.
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
A class that describes the interval of experiments/runs for which an object in the database is valid.
The LogConfig class.
Definition: LogConfig.h:22
void setDebugLevel(int debugLevel)
Configure the debug messaging level.
Definition: LogConfig.h:98
@ c_Debug
Debug: for code development.
Definition: LogConfig.h:26
void setLogLevel(ELogLevel logLevel)
Configure the log level.
Definition: LogConfig.cc:25
LogConfig * getLogConfig()
Returns global log system configuration.
Definition: LogSystem.h:78
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Definition: LogSystem.cc:31
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
Abstract base class for different kinds of events.