Belle II Software  release-05-01-25
eclWriteLocalDB.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Christopher Hearty hearty@physics.ubc.ca *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/database/DBImportObjPtr.h>
12 #include <framework/database/DBObjPtr.h>
13 #include <framework/database/DBStore.h>
14 #include <framework/datastore/StoreObjPtr.h>
15 #include <framework/datastore/DataStore.h>
16 #include <framework/dataobjects/EventMetaData.h>
17 #include <framework/logging/LogSystem.h>
18 #include <ecl/dbobjects/ECLCrystalCalib.h>
19 #include <iostream>
20 
21 using namespace Belle2;
22 
24 namespace {
25  void setupDatabase(int exp, int run, int eventNr = 1)
26  {
28  // simulate the initialize() phase where we can register objects in the DataStore
30  evtPtr.registerInDataStore();
32  // now construct the event metadata
33  evtPtr.construct(eventNr, run, exp);
34  // and update the database contents
35  DBStore& dbstore = DBStore::Instance();
36  dbstore.update();
37  // this is only needed it the payload might be intra-run dependent,
38  // that is if it might change during one run as well
39  dbstore.updateEvent();
40  }
41 }
42 
43 
44 int main()
45 {
46 
58  std::vector<float> tempCalib;
59  std::vector<float> tempCalibUnc;
60 
62  /*
63  float calib = 0.;
64  float calibUnc = 0.;
65  for (int cellID = 1; cellID <= 8736; cellID++) {
66  tempCalib.push_back(calib);
67  tempCalibUnc.push_back(calibUnc);
68  } */
69 
71  /* std::ifstream calibFile("refref1.txt");
72  float cellIDf, amplitude, toff;
73  for(int cellID=1; cellID<=8736; cellID++) {
74  calibFile >> cellIDf >> amplitude >> toff;
75  if(cellID<=1152) {
76  calib = 1.;
77  } else {
78  calib = 17800./amplitude;
79  }
80  calibUnc = 0.;
81  tempCalib.push_back(calib);
82  tempCalibUnc.push_back(calibUnc);
83  if(cellID%100==0) {std::cout << cellID << " ampl = " << amplitude << " calib = " << calib << " " << calibUnc << std::endl;}
84  } */
85 
87  /* TFile f("eclCosmicEAlgorithm.root");
88  TH1F *CalibvsCrys = (TH1F*)f.Get("CalibvsCrys");
89  for(int cellID=1; cellID<=8736; cellID++) {
90  if(cellID<1153) {
91  calib = 4.06902e-05;
92  calibUnc = 0.;
93  } else {
94  calib = CalibvsCrys->GetBinContent(cellID);
95  calibUnc = CalibvsCrys->GetBinError(cellID);
96  }
97  tempCalib.push_back(calib);
98  tempCalibUnc.push_back(calibUnc);
99  if(cellID%100==0) {std::cout << "cellID = " << cellID << " calib = " << calib << " +/- " << calibUnc << std::endl; }
100  } */
101 
108  logging->setLogLevel(LogConfig::c_Debug);
109  logging->setDebugLevel(10);
110 
112  DBObjPtr<Belle2::ECLCrystalCalib> InputCalib("ECLCrystalEnergy");
113 
115  int experiment = 1002;
116  int run = 1;
117  setupDatabase(experiment, run);
118 
120  InputCalib->Dump();
121 
123  std::vector<float> calibIn;
124  std::vector<float> calibInUnc;
125  calibIn = InputCalib->getCalibVector();
126  calibInUnc = InputCalib->getCalibUncVector();
127 
129  tempCalib = calibIn;
130  tempCalibUnc = calibInUnc;
131 
133  for (int ic = 0; ic < 9000; ic += 1000) {
134  std::cout << "crysID " << ic << " calib = " << tempCalib[ic] << " +/- " << tempCalibUnc[ic] << std::endl;
135  }
136 
137  //..Write out to localdb
138  std::cout << "Creating importer" << std::endl;
139  Belle2::DBImportObjPtr<Belle2::ECLCrystalCalib> importer("ECLCrystalEnergyGammaGamma");
140  importer.construct();
141  importer->setCalibVector(tempCalib, tempCalibUnc);
142  importer.import(Belle2::IntervalOfValidity(0, 0, -1, -1));
143  std::cout << "Successfully wrote payload ECLCrystalEnergyGammaGamma" << std::endl;
144 }
Belle2::IntervalOfValidity
A class that describes the interval of experiments/runs for which an object in the database is valid.
Definition: IntervalOfValidity.h:35
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
Belle2::DBObjPtr< Belle2::ECLCrystalCalib >
Belle2::LogSystem::getLogConfig
LogConfig * getLogConfig()
Returns global log system configuration.
Definition: LogSystem.h:88
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
Belle2::DBStore
Singleton class to cache database objects.
Definition: DBStore.h:42
Belle2::StoreObjPtr::construct
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
Definition: StoreObjPtr.h:128
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::DBImportObjPtr
Class for importing a single object to the database.
Definition: DBImportObjPtr.h:33
Belle2::DBStore::Instance
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:36
Belle2::DBStore::updateEvent
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:150
Belle2::LogSystem::Instance
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Definition: LogSystem.cc:33
Belle2::LogConfig::c_Debug
@ c_Debug
Debug: for code development.
Definition: LogConfig.h:36
Belle2::LogConfig
The LogConfig class.
Definition: LogConfig.h:32
Belle2::DBStore::update
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:87