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
33 if(__ENV__(
"USER_DATA") == NULL)
34 __COUT__ <<
"Missing env variable: USER_DATA. It must be set!" << std::endl;
36 std::vector<std::string> configTables;
37 std::vector<std::string>
41 setenv(
"CONFIGURATION_DATA_PATH",
42 (std::string(__ENV__(
"USER_DATA")) +
"/ConfigurationDataExamples").c_str(),
44 std::string configDir = std::string(__ENV__(
"CONFIGURATION_DATA_PATH")) +
'/';
49 setenv(
"CONFIGURATION_TYPE",
"File", 1);
53 __COUT__ <<
"ConfigurationDir: " << configDir << std::endl;
58 if((dp = opendir(configDir.c_str())) == 0)
60 __COUT__ <<
"ERROR:(" << errno <<
"). Can't open directory: " << configDir
65 const unsigned char isDir = 0x4;
66 while((dirp = readdir(dp)) != 0)
67 if(dirp->d_type == isDir && dirp->d_name[0] !=
'.')
69 __COUT__ << dirp->d_name << std::endl;
70 configTables.push_back(dirp->d_name);
76 unsigned int configurationsCount = 0, skippedConfigurations = 0, skippedVersions = 0,
81 for(
unsigned int i = 0; i < configTables.size(); ++i)
84 __COUT__ << std::endl;
85 __COUT__ << std::endl;
86 __COUT__ << (i + 1) <<
" of " << configTables.size() <<
": " << configTables[i]
98 catch(cet::exception e)
100 __COUT__ << std::endl << e.what() << std::endl;
101 __COUT__ <<
"Caught exception, so skip. (likely not a defined configuration "
105 ++skippedConfigurations;
106 failedConfigVersions.push_back(configTables[i] +
":*");
109 ++configurationsCount;
111 auto version = theInterface_->getVersions(base);
113 for(
auto currVersion : version)
115 __COUT__ <<
"loading " << configTables[i] <<
" version " << currVersion
121 theInterface_->get(base,
129 catch(std::runtime_error e)
131 __COUT__ << std::endl << e.what() << std::endl;
132 __COUT__ <<
"Caught exception for version, so skip. (likely invalid "
137 failedConfigVersions.push_back(configTables[i] +
":" +
138 currVersion.toString());
143 __COUT__ <<
"loaded " << configTables[i] << std::endl;
146 __COUT__ <<
"Current version: " << base->
getViewVersion() << std::endl;
147 __COUT__ <<
"Current version: " << base->getView().getVersion() << std::endl;
152 theInterface_ = ConfigurationInterface::getInstance(
161 theInterface_->saveActiveVersion(base);
173 __COUT__ <<
"Version saved " << std::endl;
180 theInterface_ = ConfigurationInterface::getInstance(
192 __COUT__ <<
"End of migrating Configuration!" << std::endl;
194 __COUT__ <<
"\n\nList of failed configs:versions (size="
195 << failedConfigVersions.size() << std::endl;
196 for(
auto& f : failedConfigVersions)
197 __COUT__ << f << std::endl;
199 __COUT__ <<
"\n\nEND List of failed configs:versions" << std::endl;
201 __COUT__ <<
"\n\n\tStats:" << std::endl;
202 __COUT__ <<
"\t\tconfigurationsCount: " << configurationsCount << std::endl;
203 __COUT__ <<
"\t\tskippedConfigurations: " << skippedConfigurations << std::endl;
204 __COUT__ <<
"\t\tversionsCount: " << versionsCount << std::endl;
205 __COUT__ <<
"\t\tskippedVersions: " << skippedVersions << std::endl;
207 __COUT__ <<
"\nEnd of migrating Configuration!" << std::endl;
212 int main(
int,
char**)
214 readxml_writedb_configurations();
const TableVersion & getViewVersion(void) const
always the active one