Belle II Software  release-05-01-25
eclWriteChannelMap.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Mikhail Remnev mikhail.a.remnev@gmail.com *
7  * *
8  * This tool writes generates ECLChannelMap payload from *
9  * ecl/data/ecl_channels_map.txt *
10  * and then writes it to the database. *
11  * *
12  * Code is mostly based on Chris Hearty's eclElectronicPayloads *
13  * *
14  * This software is provided "as is" without any warranty. *
15  **************************************************************************/
16 
17 #include <framework/database/DBImportObjPtr.h>
18 #include <framework/database/Configuration.h>
19 #include <framework/logging/LogSystem.h>
20 #include <framework/utilities/FileSystem.h>
21 // ecl
22 #include <ecl/dbobjects/ECLChannelMap.h>
23 #include <ecl/utility/ECLChannelMapper.h>
24 // std
25 #include <iostream>
26 
27 using namespace Belle2;
28 using namespace ECL;
29 
30 //------------------------------------------------------------------------
31 int main(int argc, char** argv)
32 {
33  if (argc < 2) {
34  std::cout << "Usage: eclWriteChannelMap experiment run [experimentEnd] [runEnd]" << std::endl;
35  return -1;
36  }
37  int experiment = std::stoi(argv[1]);
38  int run = std::stoi(argv[2]);
39  int exp_end = -1;
40  int run_end = -1;
41  if (argc > 3) exp_end = std::stoi(argv[3]);
42  if (argc > 4) run_end = std::stoi(argv[4]);
43 
44  //------------------------------------------------------------------------
45  //..Specify database
47  conf.prependTestingPayloadLocation("localdb/database.txt");
48 
49  //..set debug level
51  logging->setLogLevel(LogConfig::c_Debug);
52  logging->setDebugLevel(10);
53 
54  //------------------------------------------------------------------------
55  //..Calculate the new values for requested payload
56  std::string map_path = FileSystem::findFile("ecl/data/ecl_channels_map.txt");
57  if (!FileSystem::fileExists(map_path)) {
58  B2FATAL("eclChannelMapper initialization file " << map_path << " doesn't exist");
59  }
60  ECLChannelMapper mapper;
61  mapper.initFromFile(map_path.c_str());
62 
63  //------------------------------------------------------------------------
64  //..Write out to localdb
65  Belle2::DBImportObjPtr<Belle2::ECLChannelMap> importer("ECLChannelMap");
66  importer.construct(mapper.getDBObject());
67  importer.import(Belle2::IntervalOfValidity(experiment, run, exp_end, run_end));
68  std::cout << "Successfully wrote payload ECLChannelMap with iov "
69  << experiment << "," << run << "," << exp_end << "," << run_end << std::endl;
70 }
71 
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::ECL::ECLChannelMapper::initFromFile
bool initFromFile()
Initialize channel mapper using data stored in default location.
Definition: ECLChannelMapper.cc:31
Belle2::ECL::ECLChannelMapper
This class provides access to ECL channel map that is either a) Loaded from the database (see ecl/dbo...
Definition: ECLChannelMapper.h:36
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
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DBImportObjPtr
Class for importing a single object to the database.
Definition: DBImportObjPtr.h:33
Belle2::FileSystem::fileExists
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
Definition: FileSystem.cc:33
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::ECL::ECLChannelMapper::getDBObject
ECLChannelMap getDBObject()
Convert internal data to ECLChannelMap database object.
Definition: ECLChannelMapper.cc:183
Belle2::FileSystem::findFile
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:147
Belle2::LogConfig
The LogConfig class.
Definition: LogConfig.h:32