$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 00002 #define BOOST_TEST_MODULE (databaseconfiguration test) 00003 00004 #include "boost/test/auto_unit_test.hpp" 00005 00006 #include <dirent.h> 00007 #include <cassert> 00008 #include <iostream> 00009 #include <memory> 00010 #include <string> 00011 //#include <otsdaq_demo/otsdaq-demo/FEInterfaces/FEWROtsUDPFSSRInterface.h> 00012 //#include 00013 //<otsdaq_demo/otsdaq-demo/UserConfigurationDataFormats/FEWROtsUDPFSSRInterfaceConfiguration.h> 00014 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h" 00015 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h" 00016 //#include "otsdaq-core/TablePluginDataFormats/Configurations.h" 00017 //#include "otsdaq-core/TablePluginDataFormats/ConfigurationAliases.h" 00018 //#include "otsdaq-core/TablePluginDataFormats/FETable.h" 00019 #include "artdaq-database/JsonDocument/JSONDocument.h" 00020 #include "artdaq-database/StorageProviders/FileSystemDB/provider_filedb_index.h" 00021 #include "otsdaq-core/PluginMakers/MakeInterface.h" 00022 #include "otsdaq-core/PluginMakers/MakeInterfaceTable.h" 00023 00024 using namespace ots; 00025 00026 BOOST_AUTO_TEST_SUITE(databaseconfiguration_test) 00027 00028 BOOST_AUTO_TEST_CASE(readxml_writedb_configurations) 00029 { 00030 // artdaq::database::filesystem::index::debug::enable(); 00031 // artdaq::database::jsonutils::debug::enableJSONDocument(); 00032 00033 std::vector<std::string> configTables; 00034 00035 // normally CONFIGURATION_TYPE is set by StartOTS.sh 00036 setenv("CONFIGURATION_DATA_PATH", 00037 (std::string(getenv("USER_DATA")) + "/ConfigurationDataExamples").c_str(), 00038 1); 00039 std::string configDir = std::string(getenv("CONFIGURATION_DATA_PATH")) + '/'; 00040 00041 // CONFIGURATION_TYPE needed by 00042 // otsdaq/otsdaq-core/ConfigurationDataFormats/ConfigurationInfoReader.cc [187] Can 00043 // be File, Database, DatabaseTest 00044 setenv("CONFIGURATION_TYPE", "File", 1); 00045 00046 // add configurations to vector list from directory 00047 { 00048 __COUT__ << "ConfigurationDir: " << configDir << __E__; 00049 DIR* dp; 00050 00051 struct dirent* dirp; 00052 00053 if((dp = opendir(configDir.c_str())) == 0) 00054 { 00055 __COUT__ << "ERROR:(" << errno << "). Can't open directory: " << configDir 00056 << __E__; 00057 exit(0); 00058 } 00059 00060 const unsigned char isDir = 0x4; 00061 while((dirp = readdir(dp)) != 0) 00062 if(dirp->d_type == isDir && dirp->d_name[0] != '.') 00063 { 00064 __COUT__ << dirp->d_name << __E__; 00065 configTables.push_back(dirp->d_name); 00066 } 00067 00068 closedir(dp); 00069 } 00070 00071 ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(true); 00072 00073 for(unsigned int i = 0; i < configTables.size(); ++i) 00074 { 00075 theInterface_ = ConfigurationInterface::getInstance(true); 00076 TableBase* base = 0; 00077 __COUT__ << __E__; 00078 __COUT__ << __E__; 00079 __COUT__ << (i + 1) << " of " << configTables.size() << ": " << configTables[i] 00080 << __E__; 00081 00082 theInterface_->get( 00083 base, 00084 configTables[i], 00085 0, 00086 0, 00087 false, 00088 TableVersion(TableVersion::DEFAULT)); // load version 0 for all 00089 00090 __COUT__ << "loaded " << configTables[i] << __E__; 00091 00092 // if(configTables[i] != "ARTDAQAggregatorConfiguration") continue; 00093 00094 // save the active version 00095 __COUT__ << "Current version: " << base->getViewVersion() << __E__; 00096 00097 // 00098 // **** switch to db style interface?!!?!? **** // 00099 // 00100 theInterface_ = ConfigurationInterface::getInstance(false); 00101 // 00102 // 00103 00104 // theInterface_->saveActiveVersion(base); //saves current version 00105 00106 TableVersion tmpView = 00107 base->createTemporaryView(TableVersion(TableVersion::DEFAULT)); 00108 theInterface_->saveNewVersion(base, tmpView); 00109 00110 delete base; // cleanup config instance 00111 00112 // break; 00113 } 00114 00115 __COUT__ << "end of debugging Configuration!" << __E__; 00116 return; 00117 } 00118 00119 BOOST_AUTO_TEST_CASE(readdb_writexml_configurations) 00120 { 00121 // return; 00122 std::vector<std::string> configTables; 00123 00124 // normally CONFIGURATION_TYPE is set by StartOTS.sh 00125 setenv("CONFIGURATION_DATA_PATH", 00126 (std::string(getenv("USER_DATA")) + "/ConfigurationDataExamples").c_str(), 00127 1); 00128 std::string configDir = std::string(getenv("CONFIGURATION_DATA_PATH")) + '/'; 00129 00130 // CONFIGURATION_TYPE needed by 00131 // otsdaq/otsdaq-core/ConfigurationDataFormats/ConfigurationInfoReader.cc [187] Can 00132 // be File, Database, DatabaseTest 00133 setenv("CONFIGURATION_TYPE", "File", 1); 00134 00135 // add configurations to vector list from directory 00136 { 00137 __COUT__ << "ConfigurationDir: " << configDir << __E__; 00138 DIR* dp; 00139 00140 struct dirent* dirp; 00141 00142 if((dp = opendir(configDir.c_str())) == 0) 00143 { 00144 __COUT__ << "ERROR:(" << errno << "). Can't open directory: " << configDir 00145 << __E__; 00146 exit(0); 00147 } 00148 00149 const unsigned char isDir = 0x4; 00150 while((dirp = readdir(dp)) != 0) 00151 if(dirp->d_type == isDir && dirp->d_name[0] != '.') 00152 { 00153 __COUT__ << dirp->d_name << __E__; 00154 configTables.push_back(dirp->d_name); 00155 } 00156 00157 closedir(dp); 00158 } 00159 00160 ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(false); 00161 00162 for(unsigned int i = 0; i < configTables.size(); ++i) 00163 { 00164 theInterface_ = ConfigurationInterface::getInstance(false); 00165 TableBase* base = 0; 00166 __COUT__ << __E__; 00167 __COUT__ << __E__; 00168 __COUT__ << (i + 1) << " of " << configTables.size() << ": " << configTables[i] 00169 << __E__; 00170 00171 theInterface_->get( 00172 base, 00173 configTables[i], 00174 0, 00175 0, 00176 false, 00177 TableVersion(TableVersion::DEFAULT)); // load version 0 for all 00178 00179 __COUT__ << "loaded " << configTables[i] << __E__; 00180 00181 // save the active version 00182 __COUT__ << "Current version: " << base->getViewVersion() << __E__; 00183 00184 // 00185 // **** switch to db style interface?!!?!? **** // 00186 // 00187 // theInterface_ = ConfigurationInterface::getInstance(true); 00188 // 00189 // 00190 00191 TableVersion tmpView = 00192 base->createTemporaryView(TableVersion(TableVersion::DEFAULT)); 00193 theInterface_->saveNewVersion(base, tmpView); 00194 00195 delete base; // cleanup config instance 00196 // break; 00197 } 00198 00199 __COUT__ << "end of debugging Configuration!" << __E__; 00200 return; 00201 } 00202 00203 BOOST_AUTO_TEST_SUITE_END()