Belle II Software  release-05-01-25
eclDumpECLCrystalCalib.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - 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  * Read a payload of class ECLCrystalCalib from the specified global *
11  * tag, write a sample to screen, and fill a histogram with the values *
12  * *
13  * Usage: *
14  * eclDumpECLCrystalCalib payloadName globaltag exp run *
15  * *
16  * resulting root file is payload_exp_run.root *
17  * *
18  **************************************************************************/
19 
20 #include <framework/database/DBObjPtr.h>
21 #include <framework/database/DBStore.h>
22 #include <framework/datastore/StoreObjPtr.h>
23 #include <framework/datastore/DataStore.h>
24 #include <framework/dataobjects/EventMetaData.h>
25 #include <framework/database/Configuration.h>
26 #include <ecl/dbobjects/ECLCrystalCalib.h>
27 #include <iostream>
28 #include <TFile.h>
29 #include <TH1F.h>
30 
31 using namespace Belle2;
32 
33 //------------------------------------------------------------------------
34 //..Set experiment, run, and event numbers before reading a payload from the DB
35 namespace {
36  void setupDatabase(int exp, int run, int eventNr = 1)
37  {
39  // simulate the initialize() phase where we can register objects in the DataStore
41  evtPtr.registerInDataStore();
43  std::cout << "about to construct EventMetaData, exp = " << exp << " run = " << run << " eventNr = " << eventNr << std::endl;
44  evtPtr.construct(eventNr, run, exp);
45  DBStore& dbstore = DBStore::Instance();
46  dbstore.update();
47  dbstore.updateEvent();
48  }
49 }
50 
51 //------------------------------------------------------------------------
52 int main(int argc, char** argv)
53 {
54  if (argc < 4 || argc > 5) {
55  std::cout << "incorrect number of arguments for eclDumpECLCrystalCalib" << std::endl;
56  return -1;
57  }
58  std::string payloadName = argv[1];
59  std::string gtName = argv[2];
60  int experiment = std::stoi(argv[3]);
61  int run = std::stoi(argv[4]);
62  std::cout << "eclDumpECLCrystalCalib called with arguments " << payloadName << " " << gtName << " " << experiment << " " << run <<
63  " " <<
64  std::endl;
65 
66  //------------------------------------------------------------------------
67  //..Specify database
69  conf.prependGlobalTag(gtName);
70  conf.prependTestingPayloadLocation("localdb/database.txt");
71 
72  //..Populate database contents
73  std::cout << "calling setupDatabase " << std::endl;
74  setupDatabase(experiment, run);
75 
76  //------------------------------------------------------------------------
77  //..Read payloads from database
78  DBObjPtr<Belle2::ECLCrystalCalib> existingObject(payloadName);
79  std::cout << "Dumping " << payloadName << std::endl;
80  existingObject->Dump();
81 
82  //..Get vectors of values from the payloads
83  std::vector<float> currentValues = existingObject->getCalibVector();
84  std::vector<float> currentUnc = existingObject->getCalibUncVector();
85 
86  //..Print out a few values for quality control
87  std::cout << std::endl << "Values read from database " << std::endl;
88  for (int ic = 0; ic < 9000; ic += 1000) {
89  std::cout << "cellID " << ic + 1 << " " << currentValues[ic] << " +/- " << currentUnc[ic] << std::endl;
90  }
91  std::cout << std::endl;
92 
93  TString payloadTitle = payloadName;
94  payloadTitle += "_";
95  payloadTitle += experiment;
96  payloadTitle += "_";
97  payloadTitle += run;
98  TString fname = payloadTitle;
99  fname += ".root";
100  TFile hfile(fname, "recreate");
101  TString htitle = payloadTitle;
102  htitle += " values;cellID";
103  TH1F* existingPayload = new TH1F("existingPayload", htitle, 8736, 1, 8737);
104 
105  for (int cellID = 1; cellID <= 8736; cellID++) {
106  existingPayload->SetBinContent(cellID, currentValues[cellID - 1]);
107  existingPayload->SetBinError(cellID, currentUnc[cellID - 1]);
108  }
109 
110  hfile.cd();
111  hfile.Write();
112  hfile.Close();
113  std::cout << std::endl << "Values written to " << fname << std::endl;
114 }
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 >
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::Conditions::Configuration::getInstance
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
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::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::DBStore::update
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:87