Line data Source code
1 : //
2 : // DUNE DAQ modification notice:
3 : // This file has been modified from the original ATLAS oksconfig source for the DUNE DAQ project.
4 : // Fork baseline commit: oksconfig-03-02-00 (2021-04-20).
5 : // Renamed since fork: yes (from test/test_create_oksdb.cpp to test/apps/test_create_oksdb.cxx).
6 : //
7 :
8 : #include <iostream>
9 : #include <stdlib.h>
10 :
11 : #include "conffwk/ConfigObject.hpp"
12 : #include "conffwk/Configuration.hpp"
13 :
14 : using namespace dunedaq;
15 : using namespace dunedaq::conffwk;
16 :
17 : int
18 0 : main(int argc, char* argv[])
19 : {
20 0 : std::string dbname = "oksconflibs:../test/okstest.data.xml:../test/test2.data.xml";
21 :
22 0 : if (argc < 3) {
23 0 : std::cerr << "Usage: test_create_oksdb out-file in-file-1 in-file-2 [...]\n"
24 : " out-file - existing or new file name\n"
25 : " in-file1 - first file to be added to out-file\n"
26 : " in-file2 - second file to be added to out-file\n"
27 0 : " ... - list of files to be added to out-file\n";
28 : return 1;
29 : }
30 :
31 0 : const char* db_name = argv[1];
32 :
33 : // start of real test program
34 :
35 0 : Configuration db("oksconflibs");
36 :
37 0 : try {
38 0 : bool db_exist = false;
39 :
40 0 : try {
41 0 : db.load(db_name);
42 0 : db_exist = true;
43 0 : std::cout << "database file " << db_name << " already created" << std::endl;
44 0 : } catch (dunedaq::conffwk::Exception& dummu) {
45 0 : std::cout << "create database file " << db_name << std::endl;
46 0 : }
47 :
48 : // create db if it does not exist
49 0 : if (!db_exist) {
50 0 : std::list<std::string> includes;
51 0 : for (int i = 2; i < argc; ++i) {
52 0 : std::cout << "- include file " << argv[i] << std::endl;
53 0 : includes.push_back(argv[i]);
54 : }
55 :
56 0 : db.create(db_name, includes);
57 0 : } else {
58 0 : for (int i = 2; i < argc; ++i) {
59 0 : std::cout << "- include file " << argv[i] << std::endl;
60 0 : db.add_include(db_name, argv[i]);
61 : }
62 : }
63 :
64 0 : db.commit("test application (oksconflibs/test/test_create_oksdb.cpp)");
65 :
66 0 : std::cout << "done, see file \'" << db_name << "\'\n";
67 0 : } catch (dunedaq::conffwk::Exception& ex) {
68 0 : std::cerr << "ERROR: " << ex << std::endl;
69 0 : return 1;
70 0 : }
71 :
72 : return 0;
73 0 : }
|