1 #include "otsdaq/ConfigurationInterface/ConfigurationInterface.h"
2 #include "otsdaq/ConfigurationInterface/MakeConfigurationInterface.h"
4 #include "otsdaq/Macros/CoutMacros.h"
5 #include "otsdaq/MessageFacility/MessageFacility.h"
14 #define DEBUG_CONFIGURATION true
18 ConfigurationInterface::CONFIGURATION_MODE ConfigurationInterface::theMode_ =
19 ConfigurationInterface::CONFIGURATION_MODE::DO_NOT_CREATE;
20 bool ConfigurationInterface::theVersionTrackingEnabled_ =
true;
27 ConfigurationInterface::CONFIGURATION_MODE mode )
29 if(mode == CONFIGURATION_MODE::DO_NOT_CREATE)
31 if(theInstance_ ==
nullptr)
34 <<
"WARNING -- returning a nullptr ConfigurationInterface::theInstance_"
39 auto instanceType = (mode == CONFIGURATION_MODE::XML_FILE) ?
"File" :
"Database";
43 theInstance_ =
nullptr;
45 if(theInstance_ ==
nullptr)
47 theInstance_ = makeConfigurationInterface(instanceType);
55 bool ConfigurationInterface::isVersionTrackingEnabled()
57 return ConfigurationInterface::theVersionTrackingEnabled_;
61 void ConfigurationInterface::setVersionTrackingEnabled(
bool setValue)
63 ConfigurationInterface::theVersionTrackingEnabled_ = setValue;
67 const ConfigurationInterface::CONFIGURATION_MODE& ConfigurationInterface::getMode()
69 return ConfigurationInterface::theMode_;
85 __COUT__ <<
"Invalid temporary version number: " << temporaryVersion << std::endl;
89 if(!ConfigurationInterface::isVersionTrackingEnabled())
91 newVersion = TableVersion::SCRATCH;
93 bool rewriteableExists =
false;
95 std::set<TableVersion> versions = getVersions(table);
97 if(newVersion == TableVersion::INVALID)
100 __COUTTV__(*(versions.rbegin()));
101 if(versions.size() > 1)
102 __COUTTV__(*(++versions.rbegin()));
106 *(versions.rbegin()) !=
TableVersion(TableVersion::SCRATCH))
108 else if(versions.size() >
111 *(++(versions.rbegin())));
113 newVersion = TableVersion::DEFAULT;
114 __COUT__ <<
"Next available version number is " << newVersion << std::endl;
125 else if(versions.find(newVersion) != versions.end())
127 __COUT__ <<
"newVersion(" << newVersion <<
") already exists!" << std::endl;
128 rewriteableExists = newVersion == TableVersion::SCRATCH;
131 if(!rewriteableExists || ConfigurationInterface::isVersionTrackingEnabled())
133 __SS__ << (
"New version already exists!") << std::endl;
138 __COUT__ <<
"Version number to save is " << newVersion << std::endl;
141 table->changeVersionAndActivateView(temporaryVersion, newVersion);
147 !ConfigurationInterface::isVersionTrackingEnabled() && rewriteableExists;
148 uint16_t retries = overwrite ? 4 : 0;
149 auto tableView = table->getViewP();
154 saveActiveVersion(table, overwrite);
156 catch(
const std::runtime_error& e)
158 __COUT__ <<
"Caught runtime_error exception during table save." << __E__;
159 if(std::string(e.what()).find(
"there was a collision") != std::string::npos)
161 __COUT_WARN__ <<
"There was a collision saving the new table "
162 << *tableView <<
"(" << newVersion
163 <<
"), trying incremented table version... retries="
169 tableView->setVersion(newVersion);
170 __COUT__ <<
"New version for table: " << *tableView <<
" found as "
171 << newVersion << __E__;
178 __COUT__ <<
"Created table: " << *tableView <<
"-v" << newVersion << __E__;
ConfigurationInterface(void)
Protected constructor.
TableVersion saveNewVersion(TableBase *configuration, TableVersion temporaryVersion, TableVersion newVersion=TableVersion())
static TableVersion getNextVersion(const TableVersion &version=TableVersion())
bool isTemporaryVersion(void) const
static std::string setToString(const std::set< T > &setToReturn, const std::string &delimeter=", ")
setToString ~