Belle II Software  release-06-02-00
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 #include <framework/database/DBObjPtr.h>
10 #include <framework/database/DBStore.h>
11 #include <framework/datastore/StoreObjPtr.h>
12 #include <framework/datastore/DataStore.h>
13 #include <framework/dataobjects/EventMetaData.h>
14 #include <framework/database/Configuration.h>
15 #include <ecl/dbobjects/ECLCrystalCalib.h>
16 #include <iostream>
17 #include <TFile.h>
18 #include <TH1F.h>
19 
20 using namespace Belle2;
21 
22 //------------------------------------------------------------------------
23 //..Set experiment, run, and event numbers before reading a payload from the DB
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  std::cout << "about to construct EventMetaData, exp = " << exp << " run = " << run << " eventNr = " << eventNr << std::endl;
33  evtPtr.construct(eventNr, run, exp);
34  DBStore& dbstore = DBStore::Instance();
35  dbstore.update();
36  dbstore.updateEvent();
37  }
38 }
39 
40 //------------------------------------------------------------------------
41 int main(int argc, char** argv)
42 {
43  if (argc < 4 || argc > 5) {
44  std::cout << "incorrect number of arguments for eclDumpECLCrystalCalib" << std::endl;
45  return -1;
46  }
47  std::string payloadName = argv[1];
48  std::string gtName = argv[2];
49  int experiment = std::stoi(argv[3]);
50  int run = std::stoi(argv[4]);
51  std::cout << "eclDumpECLCrystalCalib called with arguments " << payloadName << " " << gtName << " " << experiment << " " << run <<
52  " " <<
53  std::endl;
54 
55  //------------------------------------------------------------------------
56  //..Specify database
58  conf.prependGlobalTag(gtName);
59  conf.prependTestingPayloadLocation("localdb/database.txt");
60 
61  //..Populate database contents
62  std::cout << "calling setupDatabase " << std::endl;
63  setupDatabase(experiment, run);
64 
65  //------------------------------------------------------------------------
66  //..Read payloads from database
67  DBObjPtr<Belle2::ECLCrystalCalib> existingObject(payloadName);
68  std::cout << "Dumping " << payloadName << std::endl;
69  existingObject->Dump();
70 
71  //..Get vectors of values from the payloads
72  std::vector<float> currentValues = existingObject->getCalibVector();
73  std::vector<float> currentUnc = existingObject->getCalibUncVector();
74 
75  //..Print out a few values for quality control
76  std::cout << std::endl << "Values read from database " << std::endl;
77  for (int ic = 0; ic < 9000; ic += 1000) {
78  std::cout << "cellID " << ic + 1 << " " << currentValues[ic] << " +/- " << currentUnc[ic] << std::endl;
79  }
80  std::cout << std::endl;
81 
82  TString payloadTitle = payloadName;
83  payloadTitle += "_";
84  payloadTitle += experiment;
85  payloadTitle += "_";
86  payloadTitle += run;
87  TString fname = payloadTitle;
88  fname += ".root";
89  TFile hfile(fname, "recreate");
90  TString htitle = payloadTitle;
91  htitle += " values;cellID";
92  TH1F* existingPayload = new TH1F("existingPayload", htitle, 8736, 1, 8737);
93 
94  for (int cellID = 1; cellID <= 8736; cellID++) {
95  existingPayload->SetBinContent(cellID, currentValues[cellID - 1]);
96  existingPayload->SetBinError(cellID, currentUnc[cellID - 1]);
97  }
98 
99  hfile.cd();
100  hfile.Write();
101  hfile.Close();
102  std::cout << std::endl << "Values written to " << fname << std::endl;
103 }
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
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
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