1 #ifndef _ots_ConfigurationInterface_h_
2 #define _ots_ConfigurationInterface_h_
4 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationGroupKey.h"
5 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationVersion.h"
6 #include "otsdaq-core/Macros/CoutMacros.h"
7 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationBase.h"
9 #include "otsdaq-core/PluginMakers/MakeInterfaceConfiguration.h"
17 class ConfigurationHandlerBase;
28 static bool isVersionTrackingEnabled();
29 static void setVersionTrackingEnabled(
bool setValue);
31 static const std::string GROUP_METADATA_TABLE_NAME;
39 const std::string configurationName,
40 std::shared_ptr<const ConfigurationGroupKey> groupKey = 0,
41 const std::string* groupName = 0,
42 bool dontFill =
false,
44 bool resetConfiguration =
true,
45 bool looseColumnMatching =
false)
47 if(configuration == 0)
52 configuration = makeInterfaceConfiguration(configurationName);
57 if(configuration == 0)
69 __COUT_WARN__ <<
"Failed to even use ConfigurationBase!" << std::endl;
80 if(groupKey != 0 && groupName != 0)
83 __SS__ <<
"FATAL ERROR: new ConfigurationGroup and ConfigurationGroupKey should be used!" << std::endl;
84 throw std::runtime_error(ss.str());
89 if(version == ConfigurationVersion::INVALID &&
90 (version=findLatestVersion(configuration)) == ConfigurationVersion::INVALID)
92 __COUT__ <<
"FATAL ERROR: Can't ask to fill a configuration object with a negative version! " <<
93 configurationName << std::endl;
94 __SS__ <<
"FATAL ERROR: Invalid latest version." <<
95 std::endl << std::endl << std::endl <<
96 "*******************" << std::endl <<
97 "Suggestion: If you expect a version to exist for this configuration, perhaps this is your first time running with the artdaq database. (and your old configurations have not been transferred?) " <<
98 std::endl <<
"Try running this once:\n\n\totsdaq_database_migrate" <<
99 std::endl << std::endl <<
"This will migrate the old ots file system configuration to the artdaq database approach." <<
100 std::endl << std::endl << std::endl;
101 throw std::runtime_error(ss.str());
105 if(resetConfiguration)
107 configuration->deactivate();
108 std::set<ConfigurationVersion> versions =
109 configuration->getStoredVersions();
110 for(
auto &version:versions)
111 if(!version.isTemporaryVersion())
112 configuration->eraseView(version);
121 if(configuration->isStored(version))
126 if(!configuration->isActive() || version != configuration->getViewVersion())
127 configuration->setActiveView(version);
129 configuration->getViewP()->setLastAccessTime();
135 if(version.isTemporaryVersion())
137 __COUT_ERR__ <<
"FATAL ERROR: Can not use interface to fill a configuration object with a temporary version!" << std::endl;
138 __SS__ <<
"FATAL ERROR: Invalid temporary version v" << version << std::endl;
139 throw std::runtime_error(ss.str());
142 configuration->setupMockupView(version);
143 configuration->setActiveView(version);
146 configuration->getViewP()->setLooseColumnMatching(looseColumnMatching);
147 fill(configuration,version);
148 if(looseColumnMatching) configuration->getViewP()->setLooseColumnMatching(
false);
149 configuration->getViewP()->setLastAccessTime();
153 if(configuration->getViewP()->getVersion() != version)
155 __COUT__ <<
"Version mismatch!! " <<
156 configuration->getViewP()->getVersion() <<
157 " vs " << version << std::endl;
162 bool nameIsMatch =
true;
163 unsigned int nameIsMatchIndex,nameIsMatchStorageIndex;
164 for(nameIsMatchIndex=0, nameIsMatchStorageIndex=0;
165 nameIsMatchIndex<configuration->getViewP()->getTableName().size();
168 if(configuration->getMockupViewP()->getTableName()[nameIsMatchStorageIndex] ==
'_')
169 ++nameIsMatchStorageIndex;
170 if(configuration->getViewP()->getTableName()[nameIsMatchIndex] ==
'_')
174 if(nameIsMatchStorageIndex >= configuration->getMockupViewP()->getTableName().size() ||
175 configuration->getViewP()->getTableName()[nameIsMatchIndex] !=
176 configuration->getMockupViewP()->getTableName()[nameIsMatchStorageIndex])
182 ++nameIsMatchStorageIndex;
186 configuration->getViewP()->setTableName(configuration->getMockupViewP()->getTableName());
189 __COUT__ <<
"View Table Name mismatch!! " <<
190 configuration->getViewP()->getTableName() <<
191 " vs " << configuration->getMockupViewP()->getTableName() << std::endl;
194 configuration->getViewP()->init();
201 __COUT__ <<
"Error occurred while getting and filling Configuration \"" <<
202 configurationName <<
"\" version:" << version << std::endl;
203 __COUT__ <<
"\t-Configuration interface mode=" << theMode_ << std::endl;
211 virtual std::set<std::string > getAllConfigurationNames()
const throw(std::runtime_error) { __SS__;
throw std::runtime_error(ss.str() +
"ConfigurationInterface::... Must only call findAllGlobalConfigurations in a mode with this functionality implemented (e.g. DatabaseConfigurationInterface).");}
212 virtual std::set<ConfigurationVersion> getVersions (
const ConfigurationBase* configuration)
const = 0;
213 const bool& getMode ()
const {
return theMode_;}
218 virtual std::set<std::string > getAllConfigurationGroupNames(
const std::string &filterString =
"")
const throw(std::runtime_error) { __SS__;
throw std::runtime_error(ss.str() +
"ConfigurationInterface::... Must only call findAllGlobalConfigurations in a mode with this functionality implemented (e.g. DatabaseConfigurationInterface).");}
219 virtual std::set<ConfigurationGroupKey> getKeys(
const std::string &groupName)
const { __SS__;
throw std::runtime_error(ss.str() +
"ConfigurationInterface::... Must only call findAllGlobalConfigurations in a mode with this functionality implemented (e.g. DatabaseConfigurationInterface).");}
220 virtual std::map<std::string ,
ConfigurationVersion > getConfigurationGroupMembers(std::string
const& ,
bool includeMetaDataTable =
false)
const throw(std::runtime_error) { __SS__;
throw std::runtime_error(ss.str() +
"ConfigurationInterface::... Must only call findAllGlobalConfigurations in a mode with this functionality implemented (e.g. DatabaseConfigurationInterface).");}
221 virtual void saveConfigurationGroup(std::map<std::string /*name*/, ConfigurationVersion /*version*/>
const& , std::string
const& )
const throw(std::runtime_error) { __SS__;
throw std::runtime_error(ss.str() +
"ConfigurationInterface::... Must only call findAllGlobalConfigurations in a mode with this functionality implemented (e.g. DatabaseConfigurationInterface).");};
230 virtual void saveActiveVersion (
const ConfigurationBase* configuration,
bool overwrite =
false)
const = 0;
234 ConfigurationHandlerBase* theConfigurationHandler_;
238 static bool theMode_;
239 static bool theVersionTrackingEnabled_;