Belle II Software  release-06-01-15
eclWriteChannelMap.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/DBImportObjPtr.h>
10 #include <framework/database/Configuration.h>
11 #include <framework/logging/LogSystem.h>
12 #include <framework/utilities/FileSystem.h>
13 // ecl
14 #include <ecl/dbobjects/ECLChannelMap.h>
15 #include <ecl/utility/ECLChannelMapper.h>
16 // std
17 #include <iostream>
18 
19 using namespace Belle2;
20 using namespace ECL;
21 
22 //------------------------------------------------------------------------
23 int main(int argc, char** argv)
24 {
25  if (argc < 2) {
26  std::cout << "Usage: eclWriteChannelMap experiment run [experimentEnd] [runEnd]" << std::endl;
27  return -1;
28  }
29  int experiment = std::stoi(argv[1]);
30  int run = std::stoi(argv[2]);
31  int exp_end = -1;
32  int run_end = -1;
33  if (argc > 3) exp_end = std::stoi(argv[3]);
34  if (argc > 4) run_end = std::stoi(argv[4]);
35 
36  //------------------------------------------------------------------------
37  //..Specify database
39  conf.prependTestingPayloadLocation("localdb/database.txt");
40 
41  //..set debug level
43  logging->setLogLevel(LogConfig::c_Debug);
44  logging->setDebugLevel(10);
45 
46  //------------------------------------------------------------------------
47  //..Calculate the new values for requested payload
48  std::string map_path = FileSystem::findFile("ecl/data/ecl_channels_map.txt");
49  if (!FileSystem::fileExists(map_path)) {
50  B2FATAL("eclChannelMapper initialization file " << map_path << " doesn't exist");
51  }
52  ECLChannelMapper mapper;
53  mapper.initFromFile(map_path.c_str());
54 
55  //------------------------------------------------------------------------
56  //..Write out to localdb
57  Belle2::DBImportObjPtr<Belle2::ECLChannelMap> importer("ECLChannelMap");
58  importer.construct(mapper.getDBObject());
59  importer.import(Belle2::IntervalOfValidity(experiment, run, exp_end, run_end));
60  std::cout << "Successfully wrote payload ECLChannelMap with iov "
61  << experiment << "," << run << "," << exp_end << "," << run_end << std::endl;
62 }
63 
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
Class for importing a single object to the database.
This class provides access to ECL channel map that is either a) Loaded from the database (see ecl/dbo...
ECLChannelMap getDBObject()
Convert internal data to ECLChannelMap database object.
bool initFromFile()
Initialize channel mapper using data stored in default location.
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:145
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
Definition: FileSystem.cc:31
A class that describes the interval of experiments/runs for which an object in the database is valid.
The LogConfig class.
Definition: LogConfig.h:22
@ c_Debug
Debug: for code development.
Definition: LogConfig.h:26
LogConfig * getLogConfig()
Returns global log system configuration.
Definition: LogSystem.h:78
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Definition: LogSystem.cc:31
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:75