10 #include "otsdaq/ConfigurationInterface/ConfigurationInterface.h"
11 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
17 #include "artdaq-database/JsonDocument/JSONDocument.h"
18 #include "artdaq-database/StorageProviders/FileSystemDB/provider_filedb_index.h"
24 void readxml_writedb_configurations()
29 std::string dbDir = std::string(__ENV__(
"ARTDAQ_DATABASE_DATADIR"));
30 __COUT__ <<
"Destination DB Directory ARTDAQ_DATABASE_DATADIR: " << dbDir << std::endl;
32 if(__ENV__(
"USER_DATA") == NULL)
33 __COUT__ <<
"Missing env variable: USER_DATA. It must be set!" << std::endl;
35 std::vector<std::string> configTables;
36 std::vector<std::string> failedConfigVersions;
39 setenv(
"CONFIGURATION_DATA_PATH", (std::string(__ENV__(
"USER_DATA")) +
"/ConfigurationDataExamples").c_str(), 1);
40 std::string configDir = std::string(__ENV__(
"CONFIGURATION_DATA_PATH")) +
'/';
45 setenv(
"CONFIGURATION_TYPE",
"File", 1);
49 __COUT__ <<
"ConfigurationDir: " << configDir << std::endl;
54 if((dp = opendir(configDir.c_str())) == 0)
56 __COUT__ <<
"ERROR:(" << errno <<
"). Can't open directory: " << configDir << std::endl;
60 const unsigned char isDir = 0x4;
61 while((dirp = readdir(dp)) != 0)
62 if(dirp->d_type == isDir && dirp->d_name[0] !=
'.')
64 __COUT__ << dirp->d_name << std::endl;
65 configTables.push_back(dirp->d_name);
71 unsigned int configurationsCount = 0, skippedConfigurations = 0, skippedVersions = 0, versionsCount = 0;
75 for(
unsigned int i = 0; i < configTables.size(); ++i)
78 __COUT__ << std::endl;
79 __COUT__ << std::endl;
80 __COUT__ << (i + 1) <<
" of " << configTables.size() <<
": " << configTables[i] << std::endl;
84 theInterface_->get(base, configTables[i], 0, 0,
87 catch(cet::exception e)
89 __COUT__ << std::endl << e.what() << std::endl;
90 __COUT__ <<
"Caught exception, so skip. (likely not a defined configuration "
94 ++skippedConfigurations;
95 failedConfigVersions.push_back(configTables[i] +
":*");
98 ++configurationsCount;
100 auto version = theInterface_->getVersions(base);
102 for(
auto currVersion : version)
104 __COUT__ <<
"loading " << configTables[i] <<
" version " << currVersion << std::endl;
109 theInterface_->get(base, configTables[i], 0, 0,
false, currVersion,
112 catch(std::runtime_error e)
114 __COUT__ << std::endl << e.what() << std::endl;
115 __COUT__ <<
"Caught exception for version, so skip. (likely invalid "
120 failedConfigVersions.push_back(configTables[i] +
":" + currVersion.toString());
125 __COUT__ <<
"loaded " << configTables[i] << std::endl;
128 __COUT__ <<
"Current version: " << base->getViewVersion() << std::endl;
129 __COUT__ <<
"Current version: " << base->getView().getVersion() << std::endl;
134 theInterface_ = ConfigurationInterface::getInstance(
false);
142 theInterface_->saveActiveVersion(base);
154 __COUT__ <<
"Version saved " << std::endl;
161 theInterface_ = ConfigurationInterface::getInstance(
true);
172 __COUT__ <<
"End of migrating Configuration!" << std::endl;
174 __COUT__ <<
"\n\nList of failed configs:versions (size=" << failedConfigVersions.size() << std::endl;
175 for(
auto& f : failedConfigVersions)
176 __COUT__ << f << std::endl;
178 __COUT__ <<
"\n\nEND List of failed configs:versions" << std::endl;
180 __COUT__ <<
"\n\n\tStats:" << std::endl;
181 __COUT__ <<
"\t\tconfigurationsCount: " << configurationsCount << std::endl;
182 __COUT__ <<
"\t\tskippedConfigurations: " << skippedConfigurations << std::endl;
183 __COUT__ <<
"\t\tversionsCount: " << versionsCount << std::endl;
184 __COUT__ <<
"\t\tskippedVersions: " << skippedVersions << std::endl;
186 __COUT__ <<
"\nEnd of migrating Configuration!" << std::endl;
191 int main(
int,
char**)
193 readxml_writedb_configurations();