otsdaq  v2_04_01
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
13 //<otsdaq_demo/otsdaq-demo/UserConfigurationDataFormats/FEWROtsUDPFSSRInterfaceConfiguration.h>
14 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h"
15 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
16 //#include "otsdaq-core/TablePlugins/Configurations.h"
17 //#include "otsdaq-core/TablePlugins/ConfigurationAliases.h"
18 //#include "otsdaq-core/TablePlugins/FETable.h"
19 #include "artdaq-database/JsonDocument/JSONDocument.h"
20 #include "artdaq-database/StorageProviders/FileSystemDB/provider_filedb_index.h"
21 #include "otsdaq-core/PluginMakers/MakeInterface.h"
22 #include "otsdaq-core/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-core/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  // if(configTables[i] != "ARTDAQAggregatorConfiguration") continue;
93 
94  // save the active version
95  __COUT__ << "Current version: " << base->getViewVersion() << __E__;
96 
97  //
98  // **** switch to db style interface?!!?!? **** //
99  //
100  theInterface_ = ConfigurationInterface::getInstance(false);
101  //
102  //
103 
104  // theInterface_->saveActiveVersion(base); //saves current version
105 
106  TableVersion tmpView =
107  base->createTemporaryView(TableVersion(TableVersion::DEFAULT));
108  theInterface_->saveNewVersion(base, tmpView);
109 
110  delete base; // cleanup config instance
111 
112  // break;
113  }
114 
115  __COUT__ << "end of debugging Configuration!" << __E__;
116  return;
117 }
118 
119 BOOST_AUTO_TEST_CASE(readdb_writexml_configurations)
120 {
121  // return;
122  std::vector<std::string> configTables;
123 
124  // normally CONFIGURATION_TYPE is set by StartOTS.sh
125  setenv("CONFIGURATION_DATA_PATH",
126  (std::string(__ENV__("USER_DATA")) + "/ConfigurationDataExamples").c_str(),
127  1);
128  std::string configDir = std::string(__ENV__("CONFIGURATION_DATA_PATH")) + '/';
129 
130  // CONFIGURATION_TYPE needed by
131  // otsdaq/otsdaq-core/ConfigurationDataFormats/ConfigurationInfoReader.cc [187] Can
132  // be File, Database, DatabaseTest
133  setenv("CONFIGURATION_TYPE", "File", 1);
134 
135  // add configurations to vector list from directory
136  {
137  __COUT__ << "ConfigurationDir: " << configDir << __E__;
138  DIR* dp;
139 
140  struct dirent* dirp;
141 
142  if((dp = opendir(configDir.c_str())) == 0)
143  {
144  __COUT__ << "ERROR:(" << errno << "). Can't open directory: " << configDir
145  << __E__;
146  exit(0);
147  }
148 
149  const unsigned char isDir = 0x4;
150  while((dirp = readdir(dp)) != 0)
151  if(dirp->d_type == isDir && dirp->d_name[0] != '.')
152  {
153  __COUT__ << dirp->d_name << __E__;
154  configTables.push_back(dirp->d_name);
155  }
156 
157  closedir(dp);
158  }
159 
160  ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(false);
161 
162  for(unsigned int i = 0; i < configTables.size(); ++i)
163  {
164  theInterface_ = ConfigurationInterface::getInstance(false);
165  TableBase* base = 0;
166  __COUT__ << __E__;
167  __COUT__ << __E__;
168  __COUT__ << (i + 1) << " of " << configTables.size() << ": " << configTables[i]
169  << __E__;
170 
171  theInterface_->get(
172  base,
173  configTables[i],
174  0,
175  0,
176  false,
177  TableVersion(TableVersion::DEFAULT)); // load version 0 for all
178 
179  __COUT__ << "loaded " << configTables[i] << __E__;
180 
181  // save the active version
182  __COUT__ << "Current version: " << base->getViewVersion() << __E__;
183 
184  //
185  // **** switch to db style interface?!!?!? **** //
186  //
187  // theInterface_ = ConfigurationInterface::getInstance(true);
188  //
189  //
190 
191  TableVersion tmpView =
192  base->createTemporaryView(TableVersion(TableVersion::DEFAULT));
193  theInterface_->saveNewVersion(base, tmpView);
194 
195  delete base; // cleanup config instance
196  // break;
197  }
198 
199  __COUT__ << "end of debugging Configuration!" << __E__;
200  return;
201 }
202 
203 BOOST_AUTO_TEST_SUITE_END()