1 #ifndef _ots_ConfigurationInterface_h_
2 #define _ots_ConfigurationInterface_h_
7 #include "otsdaq/Macros/CoutMacros.h"
9 #include "otsdaq/PluginMakers/MakeTable.h"
10 #include "otsdaq/TableCore/TableBase.h"
11 #include "otsdaq/TableCore/TableGroupKey.h"
12 #include "otsdaq/TableCore/TableVersion.h"
16 class ConfigurationHandlerBase;
29 static bool isVersionTrackingEnabled();
30 static void setVersionTrackingEnabled(
bool setValue);
32 static const std::string GROUP_METADATA_TABLE_NAME;
43 const std::string tableName,
44 std::shared_ptr<const TableGroupKey> groupKey = 0,
45 const std::string* groupName = 0,
46 bool dontFill =
false,
48 bool resetConfiguration =
true,
49 bool looseColumnMatching =
false,
50 std::string* accumulatedErrors = 0)
57 table = makeTable(tableName);
76 __COUT_WARN__ <<
"Failed to even use TableBase!" << std::endl;
86 if(groupKey != 0 && groupName != 0)
90 __SS__ <<
"FATAL ERROR: new TableGroup and TableGroupKey should be used!"
97 if(version == TableVersion::INVALID &&
98 (version = findLatestVersion(table)) == TableVersion::INVALID)
100 __COUT__ <<
"FATAL ERROR: Can't ask to fill a table object with "
101 "a negative version! "
102 << tableName << std::endl;
103 __SS__ <<
"FATAL ERROR: Invalid latest version." << std::endl
106 <<
"*******************" << std::endl
107 <<
"Suggestion: If you expect a version to exist for this "
108 "table, perhaps this is your first time running with "
109 "the artdaq database. (and your old configurations have not "
110 "been transferred?) "
112 <<
"Try running this once:\n\n\totsdaq_database_migrate"
115 <<
"This will migrate the old ots file system table to "
116 "the artdaq database approach."
124 if(resetConfiguration)
127 std::set<TableVersion> versions = table->getStoredVersions();
128 for(
auto& version : versions)
129 if(!version.isTemporaryVersion())
130 table->eraseView(version);
139 if(table->isStored(version))
144 if(!table->isActive() || version != table->getViewVersion())
145 table->setActiveView(version);
147 table->getViewP()->setLastAccessTime();
152 table->getViewP()->init();
154 catch(
const std::runtime_error& e)
156 __SS__ <<
"Error occurred while getting and filling Table \"" << tableName
157 <<
"\" version:" << version << std::endl;
158 ss <<
"\n" << e.what() << __E__;
159 __COUT__ << StringMacros::stackTrace() << __E__;
162 if(accumulatedErrors)
163 *accumulatedErrors += ss.str();
173 if(version.isTemporaryVersion())
175 __SS__ <<
"FATAL ERROR: Can not use interface to fill a "
176 "table object with a temporary version!"
178 ss <<
"FATAL ERROR: Invalid temporary version v" << version << std::endl;
182 table->setupMockupView(version);
183 table->setActiveView(version);
186 table->getViewP()->setLooseColumnMatching(looseColumnMatching);
187 fill(table, version);
188 if(looseColumnMatching)
189 table->getViewP()->setLooseColumnMatching(
false);
190 table->getViewP()->setLastAccessTime();
194 if(table->getViewP()->getVersion() != version)
196 __SS__ <<
"Version mismatch!! " << table->getViewP()->getVersion()
197 <<
" vs " << version << std::endl;
202 bool nameIsMatch =
true;
203 unsigned int nameIsMatchIndex, nameIsMatchStorageIndex;
204 for(nameIsMatchIndex = 0, nameIsMatchStorageIndex = 0;
205 nameIsMatchIndex < table->getViewP()->getTableName().size();
208 if(table->getMockupViewP()->getTableName()[nameIsMatchStorageIndex] ==
210 ++nameIsMatchStorageIndex;
211 if(table->getViewP()->getTableName()[nameIsMatchIndex] ==
'_')
215 if(nameIsMatchStorageIndex >=
216 table->getMockupViewP()->getTableName().size() ||
217 table->getViewP()->getTableName()[nameIsMatchIndex] !=
218 table->getMockupViewP()->getTableName()[nameIsMatchStorageIndex])
224 ++nameIsMatchStorageIndex;
229 table->getViewP()->setTableName(table->getMockupViewP()->getTableName());
233 __SS__ <<
"View Table Name mismatch!! "
234 << table->getViewP()->getTableName() <<
" vs "
235 << table->getMockupViewP()->getTableName() << std::endl;
242 table->getViewP()->init();
244 catch(
const std::runtime_error& e)
246 __SS__ <<
"Error occurred while getting and filling Table \"" << tableName
247 <<
"\" version:" << version << std::endl;
248 ss <<
"\n" << e.what() << __E__;
249 __COUT__ << StringMacros::stackTrace() << __E__;
252 if(accumulatedErrors)
253 *accumulatedErrors += ss.str();
261 catch(
const std::runtime_error& e)
263 __SS__ <<
"Error occurred while getting and filling Table \"" << tableName
264 <<
"\" version:" << version << std::endl;
265 ss <<
"\n" << e.what() << __E__;
270 __SS__ <<
"Unknown error occurred while getting and filling Table \""
271 << tableName <<
"\" version:" << version << std::endl;
278 virtual std::set<std::string > getAllTableNames()
const
282 "ConfigurationInterface::... Must only call "
283 "getAllTableNames in a mode with this functionality "
284 "implemented (e.g. DatabaseConfigurationInterface).");
286 virtual std::set<TableVersion> getVersions(
const TableBase* configuration)
const = 0;
287 const bool& getMode()
const {
return theMode_; }
293 virtual std::set<std::string > getAllTableGroupNames(
294 const std::string& filterString =
"")
const
298 "ConfigurationInterface::... Must only call "
299 "getAllTableGroupNames in a mode with this functionality "
300 "implemented (e.g. DatabaseConfigurationInterface).");
302 virtual std::set<TableGroupKey> getKeys(
const std::string& groupName)
const
306 "ConfigurationInterface::... Must only call "
307 "getKeys in a mode with this functionality "
308 "implemented (e.g. DatabaseConfigurationInterface).");
314 virtual std::map<std::string ,
TableVersion > getTableGroupMembers(
315 std::string
const& ,
bool includeMetaDataTable =
false)
const
319 "ConfigurationInterface::... Must only call "
320 "getTableGroupMembers in a mode with this functionality "
321 "implemented (e.g. DatabaseConfigurationInterface).");
324 virtual void saveTableGroup(
325 std::map<std::string ,
327 std::string
const& )
const
331 "ConfigurationInterface::... Must only call "
332 "saveTableGroup in a mode with this functionality "
333 "implemented (e.g. DatabaseConfigurationInterface).");
344 const std::string& groupName)
const
348 "ConfigurationInterface::... Must only call findLatestGroupKey in a "
349 "mode with this functionality implemented (e.g. "
350 "DatabaseConfigurationInterface).");
354 virtual void saveActiveVersion(
const TableBase* configuration,
355 bool overwrite =
false)
const = 0;
358 ConfigurationHandlerBase* theConfigurationHandler_;
362 static bool theMode_;
364 theVersionTrackingEnabled_;