Belle II Software  release-06-01-15
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 #include <framework/database/DBImportObjPtr.h>
10 #include <framework/database/DBObjPtr.h>
11 #include <framework/database/DBStore.h>
12 #include <framework/datastore/StoreObjPtr.h>
13 #include <framework/datastore/DataStore.h>
14 #include <framework/dataobjects/EventMetaData.h>
15 #include <framework/logging/LogSystem.h>
16 #include <ecl/dbobjects/ECLCrystalCalib.h>
17 #include <iostream>
18 
19 using namespace Belle2;
20 
22 namespace {
23  void setupDatabase(int exp, int run, int eventNr = 1)
24  {
26  // simulate the initialize() phase where we can register objects in the DataStore
28  evtPtr.registerInDataStore();
30  // now construct the event metadata
31  evtPtr.construct(eventNr, run, exp);
32  // and update the database contents
33  DBStore& dbstore = DBStore::Instance();
34  dbstore.update();
35  // this is only needed it the payload might be intra-run dependent,
36  // that is if it might change during one run as well
37  dbstore.updateEvent();
38  }
39 }
40 
41 
42 int main()
43 {
44 
56  std::vector<float> tempCalib;
57  std::vector<float> tempCalibUnc;
58 
60  /*
61  float calib = 0.;
62  float calibUnc = 0.;
63  for (int cellID = 1; cellID <= 8736; cellID++) {
64  tempCalib.push_back(calib);
65  tempCalibUnc.push_back(calibUnc);
66  } */
67 
69  /* std::ifstream calibFile("refref1.txt");
70  float cellIDf, amplitude, toff;
71  for(int cellID=1; cellID<=8736; cellID++) {
72  calibFile >> cellIDf >> amplitude >> toff;
73  if(cellID<=1152) {
74  calib = 1.;
75  } else {
76  calib = 17800./amplitude;
77  }
78  calibUnc = 0.;
79  tempCalib.push_back(calib);
80  tempCalibUnc.push_back(calibUnc);
81  if(cellID%100==0) {std::cout << cellID << " ampl = " << amplitude << " calib = " << calib << " " << calibUnc << std::endl;}
82  } */
83 
85  /* TFile f("eclCosmicEAlgorithm.root");
86  TH1F *CalibvsCrys = (TH1F*)f.Get("CalibvsCrys");
87  for(int cellID=1; cellID<=8736; cellID++) {
88  if(cellID<1153) {
89  calib = 4.06902e-05;
90  calibUnc = 0.;
91  } else {
92  calib = CalibvsCrys->GetBinContent(cellID);
93  calibUnc = CalibvsCrys->GetBinError(cellID);
94  }
95  tempCalib.push_back(calib);
96  tempCalibUnc.push_back(calibUnc);
97  if(cellID%100==0) {std::cout << "cellID = " << cellID << " calib = " << calib << " +/- " << calibUnc << std::endl; }
98  } */
99 
106  logging->setLogLevel(LogConfig::c_Debug);
107  logging->setDebugLevel(10);
108 
110  DBObjPtr<Belle2::ECLCrystalCalib> InputCalib("ECLCrystalEnergy");
111 
113  int experiment = 1002;
114  int run = 1;
115  setupDatabase(experiment, run);
116 
118  InputCalib->Dump();
119 
121  std::vector<float> calibIn;
122  std::vector<float> calibInUnc;
123  calibIn = InputCalib->getCalibVector();
124  calibInUnc = InputCalib->getCalibUncVector();
125 
127  tempCalib = calibIn;
128  tempCalibUnc = calibInUnc;
129 
131  for (int ic = 0; ic < 9000; ic += 1000) {
132  std::cout << "crysID " << ic << " calib = " << tempCalib[ic] << " +/- " << tempCalibUnc[ic] << std::endl;
133  }
134 
135  //..Write out to localdb
136  std::cout << "Creating importer" << std::endl;
137  Belle2::DBImportObjPtr<Belle2::ECLCrystalCalib> importer("ECLCrystalEnergyGammaGamma");
138  importer.construct();
139  importer->setCalibVector(tempCalib, tempCalibUnc);
140  importer.import(Belle2::IntervalOfValidity(0, 0, -1, -1));
141  std::cout << "Successfully wrote payload ECLCrystalEnergyGammaGamma" << std::endl;
142 }
Class for importing a single object to the database.
Singleton class to cache database objects.
Definition: DBStore.h:32
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:52
void setInitializeActive(bool active)
Setter for m_initializeActive.
Definition: DataStore.cc:92
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
@ c_Debug
Debug: for code development.
Definition: LogConfig.h:26
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:95
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
Definition: StoreObjPtr.h:118
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:26
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:140
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:77
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:75