00001
00002
00003
00004
00005 #include <string>
00006 #include <iostream>
00007 #include <memory>
00008 #include <cassert>
00009 #include <dirent.h>
00010 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00011 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h"
00012
00013
00014
00015
00016
00017 #include "artdaq-database/StorageProviders/FileSystemDB/provider_filedb_index.h"
00018 #include "artdaq-database/JsonDocument/JSONDocument.h"
00019
00020
00021 using namespace ots;
00022
00023
00024
00025 void readxml_writedb_configurations()
00026 {
00027
00028
00029
00030
00031
00032
00033 std::string dbDir = std::string(getenv("ARTDAQ_DATABASE_DATADIR"));
00034 std::cout << __COUT_HDR_FL__ << "Destination DB Directory ARTDAQ_DATABASE_DATADIR: " << dbDir << std::endl;
00035
00036 if(getenv("USER_DATA") == NULL) std::cout << __COUT_HDR_FL__ << "Missing env variable: USER_DATA. It must be set!" << std::endl;
00037
00038 std::vector<std::string> configTables;
00039 std::vector<std::string> failedConfigVersions;
00040
00041
00042
00043 setenv("CONFIGURATION_DATA_PATH",(std::string(getenv("USER_DATA")) + "/ConfigurationDataExamples").c_str(),1);
00044 std::string configDir = std::string(getenv("CONFIGURATION_DATA_PATH")) + '/';
00045
00046
00047
00048 setenv("CONFIGURATION_TYPE","File",1);
00049
00050
00051 {
00052 std::cout << __COUT_HDR_FL__ << "ConfigurationDir: " << configDir << std::endl;
00053 DIR *dp;
00054
00055 struct dirent *dirp;
00056
00057 if((dp = opendir(configDir.c_str())) == 0)
00058 {
00059 std::cout << __COUT_HDR_FL__<< "ERROR:(" << errno << "). Can't open directory: " << configDir << std::endl;
00060 exit(0);
00061 }
00062
00063 const unsigned char isDir = 0x4;
00064 while ((dirp = readdir(dp)) != 0)
00065 if(dirp->d_type == isDir && dirp->d_name[0] != '.' )
00066 {
00067 std::cout << __COUT_HDR_FL__<< dirp->d_name << std::endl;
00068 configTables.push_back(dirp->d_name);
00069 }
00070
00071 closedir(dp);
00072 }
00073
00074 unsigned int configurationsCount=0, skippedConfigurations=0,
00075 skippedVersions=0, versionsCount=0;
00076
00077 ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(true);
00078
00079 for(unsigned int i = 0; i < configTables.size(); ++i)
00080 {
00081 ConfigurationBase* base = 0;
00082 std::cout << __COUT_HDR_FL__ << std::endl;
00083 std::cout << __COUT_HDR_FL__ << std::endl;
00084 std::cout << __COUT_HDR_FL__ << (i+1) << " of " << configTables.size() << ": " << configTables[i] << std::endl;
00085
00086 try
00087 {
00088 theInterface_->get(base,configTables[i], 0, 0, true);
00089 }
00090 catch(cet::exception e)
00091 {
00092 std::cout << __COUT_HDR_FL__ << std::endl << e.what() << std::endl;
00093 std::cout << __COUT_HDR_FL__ <<
00094 "Caught exception, so skip. (likely not a defined configuration class) " << std::endl;
00095
00096 ++skippedConfigurations;
00097 failedConfigVersions.push_back(configTables[i] + ":*");
00098 continue;
00099 }
00100 ++configurationsCount;
00101
00102
00103 auto version = theInterface_->getVersions(base);
00104
00105 for(auto currVersion:version)
00106 {
00107 std::cout << __COUT_HDR_FL__ << "loading " << configTables[i] << " version " << currVersion << std::endl;
00108
00109 try
00110 {
00111
00112 theInterface_->get(base,configTables[i], 0, 0, false, currVersion, true);
00113 }
00114 catch(std::runtime_error e)
00115 {
00116 std::cout << __COUT_HDR_FL__ << std::endl << e.what() << std::endl;
00117 std::cout << __COUT_HDR_FL__ << "Caught exception for version, so skip. (likely invalid column names) " << std::endl;
00118
00119 ++skippedVersions;
00120 failedConfigVersions.push_back(configTables[i] + ":" + currVersion.toString());
00121 continue;
00122 }
00123 ++versionsCount;
00124
00125 std::cout << __COUT_HDR_FL__ << "loaded " << configTables[i] << std::endl;
00126
00127
00128 std::cout << __COUT_HDR_FL__ << "Current version: " << base->getViewVersion() << std::endl;
00129 std::cout << __COUT_HDR_FL__ << "Current version: " << base->getView().getVersion() << std::endl;
00130
00131
00132
00133
00134
00135 theInterface_ = ConfigurationInterface::getInstance(false);
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 theInterface_->saveActiveVersion(base);
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 std::cout << __COUT_HDR_FL__ << "Version saved " << std::endl;
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 theInterface_ = ConfigurationInterface::getInstance(true);
00174
00175
00176
00177
00178 }
00179 delete base;
00180
00181 }
00182
00183 std::cout << __COUT_HDR_FL__ << "End of migrating Configuration!" << std::endl;
00184
00185 std::cout << __COUT_HDR_FL__ << "\n\nList of failed configs:versions (size=" <<
00186 failedConfigVersions.size() << std::endl;
00187 for(auto &f : failedConfigVersions)
00188 std::cout << __COUT_HDR_FL__ << f << std::endl;
00189
00190 std::cout << __COUT_HDR_FL__ << "\n\nEND List of failed configs:versions" << std::endl;
00191
00192
00193 std::cout << __COUT_HDR_FL__ << "\n\n\tStats:" << std::endl;
00194 std::cout << __COUT_HDR_FL__ << "\t\tconfigurationsCount: " << configurationsCount << std::endl;
00195 std::cout << __COUT_HDR_FL__ << "\t\tskippedConfigurations: " << skippedConfigurations << std::endl;
00196 std::cout << __COUT_HDR_FL__ << "\t\tversionsCount: " << versionsCount << std::endl;
00197 std::cout << __COUT_HDR_FL__ << "\t\tskippedVersions: " << skippedVersions << std::endl;
00198
00199 std::cout << __COUT_HDR_FL__ << "\nEnd of migrating Configuration!" << std::endl;
00200
00201
00202 return;
00203 }
00204
00205 int main(int ,char **)
00206 {
00207 readxml_writedb_configurations();
00208 return 0;
00209 }
00210
00211