10 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
11 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h"
17 #include "artdaq-database/StorageProviders/FileSystemDB/provider_filedb_index.h"
18 #include "artdaq-database/JsonDocument/JSONDocument.h"
25 void readxml_writedb_configurations()
33 std::string dbDir = std::string(getenv(
"ARTDAQ_DATABASE_DATADIR"));
34 std::cout << __COUT_HDR_FL__ <<
"Destination DB Directory ARTDAQ_DATABASE_DATADIR: " << dbDir << std::endl;
36 if(getenv(
"USER_DATA") == NULL) std::cout << __COUT_HDR_FL__ <<
"Missing env variable: USER_DATA. It must be set!" << std::endl;
38 std::vector<std::string> configTables;
39 std::vector<std::string> failedConfigVersions;
43 setenv(
"CONFIGURATION_DATA_PATH",(std::string(getenv(
"USER_DATA")) +
"/ConfigurationDataExamples").c_str(),1);
44 std::string configDir = std::string(getenv(
"CONFIGURATION_DATA_PATH")) +
'/';
48 setenv(
"CONFIGURATION_TYPE",
"File",1);
52 std::cout << __COUT_HDR_FL__ <<
"ConfigurationDir: " << configDir << std::endl;
57 if((dp = opendir(configDir.c_str())) == 0)
59 std::cout << __COUT_HDR_FL__<<
"ERROR:(" << errno <<
"). Can't open directory: " << configDir << std::endl;
63 const unsigned char isDir = 0x4;
64 while ((dirp = readdir(dp)) != 0)
65 if(dirp->d_type == isDir && dirp->d_name[0] !=
'.' )
67 std::cout << __COUT_HDR_FL__<< dirp->d_name << std::endl;
68 configTables.push_back(dirp->d_name);
74 unsigned int configurationsCount=0, skippedConfigurations=0,
75 skippedVersions=0, versionsCount=0;
79 for(
unsigned int i = 0; i < configTables.size(); ++i)
82 std::cout << __COUT_HDR_FL__ << std::endl;
83 std::cout << __COUT_HDR_FL__ << std::endl;
84 std::cout << __COUT_HDR_FL__ << (i+1) <<
" of " << configTables.size() <<
": " << configTables[i] << std::endl;
88 theInterface_->get(base,configTables[i], 0, 0,
true);
90 catch(cet::exception e)
92 std::cout << __COUT_HDR_FL__ << std::endl << e.what() << std::endl;
93 std::cout << __COUT_HDR_FL__ <<
94 "Caught exception, so skip. (likely not a defined configuration class) " << std::endl;
96 ++skippedConfigurations;
97 failedConfigVersions.push_back(configTables[i] +
":*");
100 ++configurationsCount;
103 auto version = theInterface_->getVersions(base);
105 for(
auto currVersion:version)
107 std::cout << __COUT_HDR_FL__ <<
"loading " << configTables[i] <<
" version " << currVersion << std::endl;
112 theInterface_->get(base,configTables[i], 0, 0,
false, currVersion,
true);
114 catch(std::runtime_error e)
116 std::cout << __COUT_HDR_FL__ << std::endl << e.what() << std::endl;
117 std::cout << __COUT_HDR_FL__ <<
"Caught exception for version, so skip. (likely invalid column names) " << std::endl;
120 failedConfigVersions.push_back(configTables[i] +
":" + currVersion.toString());
125 std::cout << __COUT_HDR_FL__ <<
"loaded " << configTables[i] << std::endl;
128 std::cout << __COUT_HDR_FL__ <<
"Current version: " << base->getViewVersion() << std::endl;
129 std::cout << __COUT_HDR_FL__ <<
"Current version: " << base->getView().getVersion() << std::endl;
135 theInterface_ = ConfigurationInterface::getInstance(
false);
146 theInterface_->saveActiveVersion(base);
161 std::cout << __COUT_HDR_FL__ <<
"Version saved " << std::endl;
173 theInterface_ = ConfigurationInterface::getInstance(
true);
183 std::cout << __COUT_HDR_FL__ <<
"End of migrating Configuration!" << std::endl;
185 std::cout << __COUT_HDR_FL__ <<
"\n\nList of failed configs:versions (size=" <<
186 failedConfigVersions.size() << std::endl;
187 for(
auto &f : failedConfigVersions)
188 std::cout << __COUT_HDR_FL__ << f << std::endl;
190 std::cout << __COUT_HDR_FL__ <<
"\n\nEND List of failed configs:versions" << std::endl;
193 std::cout << __COUT_HDR_FL__ <<
"\n\n\tStats:" << std::endl;
194 std::cout << __COUT_HDR_FL__ <<
"\t\tconfigurationsCount: " << configurationsCount << std::endl;
195 std::cout << __COUT_HDR_FL__ <<
"\t\tskippedConfigurations: " << skippedConfigurations << std::endl;
196 std::cout << __COUT_HDR_FL__ <<
"\t\tversionsCount: " << versionsCount << std::endl;
197 std::cout << __COUT_HDR_FL__ <<
"\t\tskippedVersions: " << skippedVersions << std::endl;
199 std::cout << __COUT_HDR_FL__ <<
"\nEnd of migrating Configuration!" << std::endl;
205 int main(
int ,
char **)
207 readxml_writedb_configurations();