otsdaq  v2_05_02_indev
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/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", (std::string(__ENV__("USER_DATA")) + "/ConfigurationDataExamples").c_str(), 1);
37  std::string configDir = std::string(__ENV__("CONFIGURATION_DATA_PATH")) + '/';
38 
39  // CONFIGURATION_TYPE needed by
40  // otsdaq/otsdaq/ConfigurationDataFormats/ConfigurationInfoReader.cc [187] Can
41  // be File, Database, DatabaseTest
42  setenv("CONFIGURATION_TYPE", "File", 1);
43 
44  // add configurations to vector list from directory
45  {
46  __COUT__ << "ConfigurationDir: " << configDir << __E__;
47  DIR* dp;
48 
49  struct dirent* dirp;
50 
51  if((dp = opendir(configDir.c_str())) == 0)
52  {
53  __COUT__ << "ERROR:(" << errno << "). Can't open directory: " << configDir << __E__;
54  exit(0);
55  }
56 
57  const unsigned char isDir = 0x4;
58  while((dirp = readdir(dp)) != 0)
59  if(dirp->d_type == isDir && dirp->d_name[0] != '.')
60  {
61  __COUT__ << dirp->d_name << __E__;
62  configTables.push_back(dirp->d_name);
63  }
64 
65  closedir(dp);
66  }
67 
68  ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(true);
69 
70  for(unsigned int i = 0; i < configTables.size(); ++i)
71  {
72  theInterface_ = ConfigurationInterface::getInstance(true);
73  TableBase* base = 0;
74  __COUT__ << __E__;
75  __COUT__ << __E__;
76  __COUT__ << (i + 1) << " of " << configTables.size() << ": " << configTables[i] << __E__;
77 
78  theInterface_->get(base, configTables[i], 0, 0, false,
79  TableVersion(TableVersion::DEFAULT)); // load version 0 for all
80 
81  __COUT__ << "loaded " << configTables[i] << __E__;
82 
83  // save the active version
84  __COUT__ << "Current version: " << base->getViewVersion() << __E__;
85 
86  //
87  // **** switch to db style interface?!!?!? **** //
88  //
89  theInterface_ = ConfigurationInterface::getInstance(false);
90  //
91  //
92 
93  // theInterface_->saveActiveVersion(base); //saves current version
94 
95  TableVersion tmpView = base->createTemporaryView(TableVersion(TableVersion::DEFAULT));
96  theInterface_->saveNewVersion(base, tmpView);
97 
98  delete base; // cleanup config instance
99 
100  // break;
101  }
102 
103  __COUT__ << "end of debugging Configuration!" << __E__;
104  return;
105 }
106 
107 BOOST_AUTO_TEST_CASE(readdb_writexml_configurations)
108 {
109  // return;
110  std::vector<std::string> configTables;
111 
112  // normally CONFIGURATION_TYPE is set by StartOTS.sh
113  setenv("CONFIGURATION_DATA_PATH", (std::string(__ENV__("USER_DATA")) + "/ConfigurationDataExamples").c_str(), 1);
114  std::string configDir = std::string(__ENV__("CONFIGURATION_DATA_PATH")) + '/';
115 
116  // CONFIGURATION_TYPE needed by
117  // otsdaq/otsdaq/ConfigurationDataFormats/ConfigurationInfoReader.cc [187] Can
118  // be File, Database, DatabaseTest
119  setenv("CONFIGURATION_TYPE", "File", 1);
120 
121  // add configurations to vector list from directory
122  {
123  __COUT__ << "ConfigurationDir: " << configDir << __E__;
124  DIR* dp;
125 
126  struct dirent* dirp;
127 
128  if((dp = opendir(configDir.c_str())) == 0)
129  {
130  __COUT__ << "ERROR:(" << errno << "). Can't open directory: " << configDir << __E__;
131  exit(0);
132  }
133 
134  const unsigned char isDir = 0x4;
135  while((dirp = readdir(dp)) != 0)
136  if(dirp->d_type == isDir && dirp->d_name[0] != '.')
137  {
138  __COUT__ << dirp->d_name << __E__;
139  configTables.push_back(dirp->d_name);
140  }
141 
142  closedir(dp);
143  }
144 
145  ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(false);
146 
147  for(unsigned int i = 0; i < configTables.size(); ++i)
148  {
149  theInterface_ = ConfigurationInterface::getInstance(false);
150  TableBase* base = 0;
151  __COUT__ << __E__;
152  __COUT__ << __E__;
153  __COUT__ << (i + 1) << " of " << configTables.size() << ": " << configTables[i] << __E__;
154 
155  theInterface_->get(base, configTables[i], 0, 0, false,
156  TableVersion(TableVersion::DEFAULT)); // load version 0 for all
157 
158  __COUT__ << "loaded " << configTables[i] << __E__;
159 
160  // save the active version
161  __COUT__ << "Current version: " << base->getViewVersion() << __E__;
162 
163  //
164  // **** switch to db style interface?!!?!? **** //
165  //
166  // theInterface_ = ConfigurationInterface::getInstance(true);
167  //
168  //
169 
170  TableVersion tmpView = base->createTemporaryView(TableVersion(TableVersion::DEFAULT));
171  theInterface_->saveNewVersion(base, tmpView);
172 
173  delete base; // cleanup config instance
174  // break;
175  }
176 
177  __COUT__ << "end of debugging Configuration!" << __E__;
178  return;
179 }
180 
181 BOOST_AUTO_TEST_SUITE_END()