$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 //#define BOOST_TEST_MODULE ( databaseconfiguration test) 00002 00003 //#include "boost/test/auto_unit_test.hpp" 00004 00005 #include <dirent.h> 00006 #include <cassert> 00007 #include <iostream> 00008 #include <memory> 00009 #include <string> 00010 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h" 00011 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h" 00012 //#include "otsdaq-core/TablePluginDataFormats/Configurations.h" 00013 //#include "otsdaq-core/TablePluginDataFormats/ConfigurationAliases.h" 00014 //#include "otsdaq-core/TablePluginDataFormats/FETable.h" 00015 //#include "otsdaq-core/PluginMakers/makeTable.h" 00016 //#include "otsdaq-core/PluginMakers/MakeInterface.h" 00017 #include "artdaq-database/JsonDocument/JSONDocument.h" 00018 #include "artdaq-database/StorageProviders/FileSystemDB/provider_filedb_index.h" 00019 00020 using namespace ots; 00021 00022 // BOOST_AUTO_TEST_SUITE( databaseconfiguration_test ) 00023 00024 void readxml_writedb_configurations() 00025 { 00026 // artdaq::database::filesystem::index::debug::enable(); 00027 // artdaq::database::jsonutils::debug::enableJSONDocument(); 00028 00029 std::string dbDir = std::string(getenv("ARTDAQ_DATABASE_DATADIR")); 00030 __COUT__ << "Destination DB Directory ARTDAQ_DATABASE_DATADIR: " << dbDir 00031 << std::endl; 00032 00033 if(getenv("USER_DATA") == NULL) 00034 __COUT__ << "Missing env variable: USER_DATA. It must be set!" << std::endl; 00035 00036 std::vector<std::string> configTables; // list of tables to migrate 00037 std::vector<std::string> 00038 failedConfigVersions; // list of tables/versions that failed to migrate 00039 00040 // normally CONFIGURATION_TYPE is set by StartOTS.sh 00041 setenv("CONFIGURATION_DATA_PATH", 00042 (std::string(getenv("USER_DATA")) + "/ConfigurationDataExamples").c_str(), 00043 1); 00044 std::string configDir = std::string(getenv("CONFIGURATION_DATA_PATH")) + '/'; 00045 00046 // CONFIGURATION_TYPE needed by 00047 // otsdaq/otsdaq-core/ConfigurationDataFormats/ConfigurationInfoReader.cc [187] Can 00048 // be File, Database, DatabaseTest 00049 setenv("CONFIGURATION_TYPE", "File", 1); 00050 00051 // add configurations to vector list from directory 00052 { 00053 __COUT__ << "ConfigurationDir: " << configDir << std::endl; 00054 DIR* dp; 00055 00056 struct dirent* dirp; 00057 00058 if((dp = opendir(configDir.c_str())) == 0) 00059 { 00060 __COUT__ << "ERROR:(" << errno << "). Can't open directory: " << configDir 00061 << std::endl; 00062 exit(0); 00063 } 00064 00065 const unsigned char isDir = 0x4; 00066 while((dirp = readdir(dp)) != 0) 00067 if(dirp->d_type == isDir && dirp->d_name[0] != '.') 00068 { 00069 __COUT__ << dirp->d_name << std::endl; 00070 configTables.push_back(dirp->d_name); 00071 } 00072 00073 closedir(dp); 00074 } 00075 00076 unsigned int configurationsCount = 0, skippedConfigurations = 0, skippedVersions = 0, 00077 versionsCount = 0; 00078 00079 ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(true); 00080 00081 for(unsigned int i = 0; i < configTables.size(); ++i) 00082 { 00083 TableBase* base = 0; 00084 __COUT__ << std::endl; 00085 __COUT__ << std::endl; 00086 __COUT__ << (i + 1) << " of " << configTables.size() << ": " << configTables[i] 00087 << std::endl; 00088 00089 try 00090 { 00091 theInterface_->get( 00092 base, 00093 configTables[i], 00094 0, 00095 0, 00096 true); // load an empty instance, just to get all available version 00097 } 00098 catch(cet::exception e) 00099 { 00100 __COUT__ << std::endl << e.what() << std::endl; 00101 __COUT__ << "Caught exception, so skip. (likely not a defined configuration " 00102 "class) " 00103 << std::endl; 00104 00105 ++skippedConfigurations; 00106 failedConfigVersions.push_back(configTables[i] + ":*"); 00107 continue; 00108 } 00109 ++configurationsCount; 00110 00111 auto version = theInterface_->getVersions(base); 00112 00113 for(auto currVersion : version) 00114 { 00115 __COUT__ << "loading " << configTables[i] << " version " << currVersion 00116 << std::endl; 00117 00118 try 00119 { 00120 // reset configurationView and load current version 00121 theInterface_->get(base, 00122 configTables[i], 00123 0, 00124 0, 00125 false, 00126 currVersion, 00127 true); // load version 0 for all, first 00128 } 00129 catch(std::runtime_error e) 00130 { 00131 __COUT__ << std::endl << e.what() << std::endl; 00132 __COUT__ << "Caught exception for version, so skip. (likely invalid " 00133 "column names) " 00134 << std::endl; 00135 00136 ++skippedVersions; 00137 failedConfigVersions.push_back(configTables[i] + ":" + 00138 currVersion.toString()); 00139 continue; 00140 } 00141 ++versionsCount; 00142 00143 __COUT__ << "loaded " << configTables[i] << std::endl; 00144 00145 // save the active version 00146 __COUT__ << "Current version: " << base->getViewVersion() << std::endl; 00147 __COUT__ << "Current version: " << base->getView().getVersion() << std::endl; 00148 00149 // 00150 // **** switch to db style interface?!!?!? **** // 00151 // 00152 theInterface_ = ConfigurationInterface::getInstance( 00153 false); // true for File interface, false for artdaq database 00154 // 00155 //***************************************** 00156 //***************************************** 00157 00158 // =========== Save as Current Version Number ========== // 00159 // uses same version number in migration database 00160 // 00161 theInterface_->saveActiveVersion(base); 00162 // 00163 // =========== END Save as Current Version Number ========== // 00164 00165 // =========== Save as New Version Number ========== // 00166 // if wanted to create a new version number based on this version 00167 // 00168 // int tmpView = base->createTemporaryView(currVersion); 00169 // theInterface_->saveNewVersion(base,tmpView); 00170 // 00171 // =========== END Save as Current Version Number ========== // 00172 00173 __COUT__ << "Version saved " << std::endl; 00174 00175 //***************************************** 00176 //***************************************** 00177 // 00178 // **** switch back db style interface?!!?!? **** // 00179 // 00180 theInterface_ = ConfigurationInterface::getInstance( 00181 true); // true for File interface, false for artdaq database 00182 // 00183 // 00184 00185 // break; //uncomment to just do the one version (for debugging) 00186 } 00187 delete base; // cleanup config instance 00188 // break; //uncomment to just do the one config table (for 00189 // debugging) 00190 } 00191 00192 __COUT__ << "End of migrating Configuration!" << std::endl; 00193 00194 __COUT__ << "\n\nList of failed configs:versions (size=" 00195 << failedConfigVersions.size() << std::endl; 00196 for(auto& f : failedConfigVersions) 00197 __COUT__ << f << std::endl; 00198 00199 __COUT__ << "\n\nEND List of failed configs:versions" << std::endl; 00200 00201 __COUT__ << "\n\n\tStats:" << std::endl; 00202 __COUT__ << "\t\tconfigurationsCount: " << configurationsCount << std::endl; 00203 __COUT__ << "\t\tskippedConfigurations: " << skippedConfigurations << std::endl; 00204 __COUT__ << "\t\tversionsCount: " << versionsCount << std::endl; 00205 __COUT__ << "\t\tskippedVersions: " << skippedVersions << std::endl; 00206 00207 __COUT__ << "\nEnd of migrating Configuration!" << std::endl; 00208 00209 return; 00210 } 00211 00212 int main(int, char**) 00213 { 00214 readxml_writedb_configurations(); 00215 return 0; 00216 } 00217 // BOOST_AUTO_TEST_SUITE_END()