tdaq-develop-2025-02-12
DatabaseConfiguration_t.cc
1 
2 #define BOOST_TEST_MODULE (databaseconfiguration test)
3 
4 #include "boost/test/auto_unit_test.hpp"
5 
6 #include <dirent.h>
7 #include <cassert>
8 #include <iostream>
9 #include <memory>
10 #include <string>
11 // #include <otsdaq_demo/otsdaq-demo/FEInterfaces/FEWROtsUDPFSSRInterface.h>
12 // #include
14 #include "otsdaq/ConfigurationInterface/ConfigurationInterface.h"
15 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
16 // #include "otsdaq/TablePlugins/Configurations.h"
17 // #include "otsdaq/TablePlugins/ConfigurationAliases.h"
18 // #include "otsdaq/TablePlugins/FETable.h"
19 #include "artdaq-database/JsonDocument/JSONDocument.h"
20 #include "artdaq-database/StorageProviders/FileSystemDB/provider_filedb_index.h"
21 #include "otsdaq/PluginMakers/MakeInterface.h"
22 #include "otsdaq/PluginMakers/MakeInterfaceTable.h"
23 
24 using namespace ots;
25 
26 BOOST_AUTO_TEST_SUITE(databaseconfiguration_test)
27 
28 BOOST_AUTO_TEST_CASE(readxml_writedb_configurations)
29 {
30  // artdaq::database::filesystem::index::debug::enable();
31  // artdaq::database::jsonutils::debug::enableJSONDocument();
32 
33  std::vector<std::string> configTables;
34 
35  // normally CONFIGURATION_TYPE is set by StartOTS.sh
36  setenv("CONFIGURATION_DATA_PATH",
37  (std::string(__ENV__("USER_DATA")) + "/ConfigurationDataExamples").c_str(),
38  1);
39  std::string configDir = std::string(__ENV__("CONFIGURATION_DATA_PATH")) + '/';
40 
41  // CONFIGURATION_TYPE needed by
42  // otsdaq/otsdaq/ConfigurationDataFormats/ConfigurationInfoReader.cc [187] Can
43  // be File, Database, DatabaseTest
44  setenv("CONFIGURATION_TYPE", "File", 1);
45 
46  // add configurations to vector list from directory
47  {
48  __COUT__ << "ConfigurationDir: " << configDir << __E__;
49  DIR* dp;
50 
51  struct dirent* dirp;
52 
53  if((dp = opendir(configDir.c_str())) == 0)
54  {
55  __COUT__ << "ERROR:(" << errno << "). Can't open directory: " << configDir
56  << __E__;
57  exit(0);
58  }
59 
60  const unsigned char isDir = 0x4;
61  while((dirp = readdir(dp)) != 0)
62  if(dirp->d_type == isDir && dirp->d_name[0] != '.')
63  {
64  __COUT__ << dirp->d_name << __E__;
65  configTables.push_back(dirp->d_name);
66  }
67 
68  closedir(dp);
69  }
70 
71  ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(true);
72 
73  for(unsigned int i = 0; i < configTables.size(); ++i)
74  {
75  theInterface_ = ConfigurationInterface::getInstance(true);
76  TableBase* base = 0;
77  __COUT__ << __E__;
78  __COUT__ << __E__;
79  __COUT__ << (i + 1) << " of " << configTables.size() << ": " << configTables[i]
80  << __E__;
81 
82  theInterface_->get(
83  base,
84  configTables[i],
85  0,
86  0,
87  false,
88  TableVersion(TableVersion::DEFAULT)); // load version 0 for all
89 
90  __COUT__ << "loaded " << configTables[i] << __E__;
91 
92  // save the active version
93  __COUT__ << "Current version: " << base->getViewVersion() << __E__;
94 
95  //
96  // **** switch to db style interface?!!?!? **** //
97  //
98  theInterface_ = ConfigurationInterface::getInstance(false);
99  //
100  //
101 
102  // theInterface_->saveActiveVersion(base); //saves current version
103 
104  TableVersion tmpView =
105  base->createTemporaryView(TableVersion(TableVersion::DEFAULT));
106  theInterface_->saveNewVersion(base, tmpView);
107 
108  delete base; // cleanup config instance
109 
110  // break;
111  }
112 
113  __COUT__ << "end of debugging Configuration!" << __E__;
114  return;
115 }
116 
117 BOOST_AUTO_TEST_CASE(readdb_writexml_configurations)
118 {
119  // return;
120  std::vector<std::string> configTables;
121 
122  // normally CONFIGURATION_TYPE is set by StartOTS.sh
123  setenv("CONFIGURATION_DATA_PATH",
124  (std::string(__ENV__("USER_DATA")) + "/ConfigurationDataExamples").c_str(),
125  1);
126  std::string configDir = std::string(__ENV__("CONFIGURATION_DATA_PATH")) + '/';
127 
128  // CONFIGURATION_TYPE needed by
129  // otsdaq/otsdaq/ConfigurationDataFormats/ConfigurationInfoReader.cc [187] Can
130  // be File, Database, DatabaseTest
131  setenv("CONFIGURATION_TYPE", "File", 1);
132 
133  // add configurations to vector list from directory
134  {
135  __COUT__ << "ConfigurationDir: " << configDir << __E__;
136  DIR* dp;
137 
138  struct dirent* dirp;
139 
140  if((dp = opendir(configDir.c_str())) == 0)
141  {
142  __COUT__ << "ERROR:(" << errno << "). Can't open directory: " << configDir
143  << __E__;
144  exit(0);
145  }
146 
147  const unsigned char isDir = 0x4;
148  while((dirp = readdir(dp)) != 0)
149  if(dirp->d_type == isDir && dirp->d_name[0] != '.')
150  {
151  __COUT__ << dirp->d_name << __E__;
152  configTables.push_back(dirp->d_name);
153  }
154 
155  closedir(dp);
156  }
157 
158  ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(false);
159 
160  for(unsigned int i = 0; i < configTables.size(); ++i)
161  {
162  theInterface_ = ConfigurationInterface::getInstance(false);
163  TableBase* base = 0;
164  __COUT__ << __E__;
165  __COUT__ << __E__;
166  __COUT__ << (i + 1) << " of " << configTables.size() << ": " << configTables[i]
167  << __E__;
168 
169  theInterface_->get(
170  base,
171  configTables[i],
172  0,
173  0,
174  false,
175  TableVersion(TableVersion::DEFAULT)); // load version 0 for all
176 
177  __COUT__ << "loaded " << configTables[i] << __E__;
178 
179  // save the active version
180  __COUT__ << "Current version: " << base->getViewVersion() << __E__;
181 
182  //
183  // **** switch to db style interface?!!?!? **** //
184  //
185  // theInterface_ = ConfigurationInterface::getInstance(true);
186  //
187  //
188 
189  TableVersion tmpView =
190  base->createTemporaryView(TableVersion(TableVersion::DEFAULT));
191  theInterface_->saveNewVersion(base, tmpView);
192 
193  delete base; // cleanup config instance
194  // break;
195  }
196 
197  __COUT__ << "end of debugging Configuration!" << __E__;
198  return;
199 }
200 
201 BOOST_AUTO_TEST_SUITE_END()
TableVersion saveNewVersion(TableBase *configuration, TableVersion temporaryVersion, TableVersion newVersion=TableVersion())
TableVersion createTemporaryView(TableVersion sourceViewVersion=TableVersion(), TableVersion destTemporaryViewVersion=TableVersion::getNextTemporaryVersion())
source of -1, from MockUp, else from valid view version
Definition: TableBase.cc:1601
const TableVersion & getViewVersion(void) const
always the active one
Definition: TableBase.cc:690