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