1 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h"
2 #include "otsdaq-core/ConfigurationInterface/FileConfigurationInterface.h"
3 #include "otsdaq-core/ConfigurationInterface/DatabaseConfigurationInterface.h"
5 #include "otsdaq-core/MessageFacility/MessageFacility.h"
6 #include "otsdaq-core/Macros/CoutMacros.h"
16 #define DEBUG_CONFIGURATION true
20 bool ConfigurationInterface::theMode_ =
true;
21 bool ConfigurationInterface::theVersionTrackingEnabled_ =
true;
23 const std::string ConfigurationInterface::GROUP_METADATA_TABLE_NAME =
"ConfigurationGroupMetadata";
26 ConfigurationInterface::ConfigurationInterface()
34 if(theInstance_ != 0 && dynamic_cast<FileConfigurationInterface*>(theInstance_) == 0)
39 if( theInstance_ == 0)
44 if(theInstance_ != 0 && dynamic_cast<DatabaseConfigurationInterface*>(theInstance_) == 0)
49 if( theInstance_ == 0)
59 bool ConfigurationInterface::isVersionTrackingEnabled()
61 return ConfigurationInterface::theVersionTrackingEnabled_;
65 void ConfigurationInterface::setVersionTrackingEnabled(
bool setValue)
67 ConfigurationInterface::theVersionTrackingEnabled_ = setValue;
79 if(!temporaryVersion.isTemporaryVersion() ||
80 !configuration->isStored(temporaryVersion))
82 std::cout << __COUT_HDR_FL__ <<
"Invalid temporary version number: " << temporaryVersion << std::endl;
86 if(!ConfigurationInterface::isVersionTrackingEnabled())
87 newVersion = ConfigurationVersion::SCRATCH;
89 bool rewriteableExists =
false;
91 std::set<ConfigurationVersion> versions = getVersions(configuration);
92 if(newVersion == ConfigurationVersion::INVALID)
96 newVersion = ConfigurationVersion::getNextVersion(*(versions.rbegin()));
97 else if(versions.size() > 1)
98 newVersion = ConfigurationVersion::getNextVersion(*(--(versions.rbegin())));
99 else newVersion = ConfigurationVersion::DEFAULT;
100 std::cout << __COUT_HDR_FL__ <<
"Next available version number is " << newVersion << std::endl;
110 else if(versions.find(newVersion) != versions.end())
112 std::cout << __COUT_HDR_FL__ <<
"newVersion(" << newVersion <<
") already exists!" << std::endl;
113 rewriteableExists = newVersion == ConfigurationVersion::SCRATCH;
116 if(!rewriteableExists || ConfigurationInterface::isVersionTrackingEnabled())
118 __SS__ << (
"New version already exists!") << std::endl;
119 std::cout << __COUT_HDR_FL__ << ss.str();
120 throw std::runtime_error(ss.str());
124 std::cout << __COUT_HDR_FL__ <<
"Version number to save is " << newVersion << std::endl;
128 configuration->changeVersionAndActivateView(temporaryVersion,newVersion);
133 saveActiveVersion(configuration,
134 !ConfigurationInterface::isVersionTrackingEnabled() &&