Belle II Software  release-05-02-19
writeROIparametersToDB.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Simon Kurz *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/database/DBImportObjPtr.h>
12 #include <framework/database/IntervalOfValidity.h>
13 #include <framework/database/Configuration.h>
14 #include <framework/logging/LogSystem.h>
15 #include <framework/utilities/FileSystem.h>
16 
17 #include <simulation/dbobjects/ROIParameters.h>
18 
19 #include <iostream>
20 
21 //------------------------------------------------------------------------
22 int main(int argc, char** argv)
23 {
24  if (argc < 4 or !(std::stoi(argv[1]) == 0 or std::stoi(argv[1]) == 1)) {
25  std::cout <<
26  "Please specify IOV: 0/1 {=off/on} N {=off for every Nth event; -1 if not used} experiment run [experimentEnd] [runEnd]" <<
27  std::endl;
28  return -1;
29  }
30 
31  bool enableROI = std::stoi(argv[1]) == 1;
32  int disableROIforEveryNth = std::stoi(argv[2]);
33 
34  if (!enableROI) {
35  disableROIforEveryNth = -1;
36  std::cout << "Parameter \"N\" does not have any function if ROI finding turned off. Neglecting." << std::endl;
37  } else if (disableROIforEveryNth == 0 or disableROIforEveryNth == 1) {
38  disableROIforEveryNth = -1;
39  std::cout <<
40  "Parameter \"N\" does not make any sense. Please use positive integer greater than 1 (or negative integer for disabling this feature)."
41  << std::endl;
42  } else if (disableROIforEveryNth < -1) {
43  disableROIforEveryNth = -1;
44  }
45 
46  int experiment = std::stoi(argv[3]);
47  int run = std::stoi(argv[4]);
48  int exp_end = -1;
49  int run_end = -1;
50  if (argc > 5) exp_end = std::stoi(argv[5]);
51  if (argc > 6) run_end = std::stoi(argv[6]);
52 
53  //------------------------------------------------------------------------
54  //..Specify database
56  conf.prependTestingPayloadLocation("localdb/database.txt");
57 
58  //..set debug level
60  logging->setLogLevel(Belle2::LogConfig::c_Debug);
61  logging->setDebugLevel(10);
62 
63  //..create ROI parameters
64  Belle2::ROIParameters roiParameters;
65  roiParameters.setROIfinding(enableROI);
66  roiParameters.setDisableROIforEveryNth(disableROIforEveryNth);
67 
68  //------------------------------------------------------------------------
69  //..Write out to localdb
71  roiParametersDBPtr.construct(roiParameters);
72  roiParametersDBPtr.import(Belle2::IntervalOfValidity(experiment, run, exp_end, run_end));
73  std::cout << "Successfully wrote payload ROIParameters with iov "
74  << experiment << "," << run << "," << exp_end << "," << run_end << std::endl;
75 }
76 
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::DBImportObjPtr::construct
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
Definition: DBImportObjPtr.h:57
Belle2::DBImportBase::import
bool import(const IntervalOfValidity &iov)
Import the object to database.
Definition: DBImportBase.cc:38
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::Conditions::Configuration::getInstance
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
Belle2::DBImportObjPtr
Class for importing a single object to the database.
Definition: DBImportObjPtr.h:33
Belle2::LogSystem::Instance
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Definition: LogSystem.cc:33
Belle2::ROIParameters
The payload containing all PXD ROI parameters.
Definition: ROIParameters.h:32
Belle2::LogConfig::c_Debug
@ c_Debug
Debug: for code development.
Definition: LogConfig.h:36
Belle2::ROIParameters::setROIfinding
void setROIfinding(bool useROIfinding)
Set whether ROI finding was used.
Definition: ROIParameters.h:40
Belle2::LogConfig
The LogConfig class.
Definition: LogConfig.h:32
Belle2::ROIParameters::setDisableROIforEveryNth
void setDisableROIforEveryNth(int disableROIforEveryNth)
Set if ROI finding was disabled for every Nth event (-1 if not used)
Definition: ROIParameters.h:52