1 #ifndef _ots_ConfigurationInterface_h_
2 #define _ots_ConfigurationInterface_h_
7 #include "otsdaq-core/Macros/CoutMacros.h"
9 #include "otsdaq-core/PluginMakers/MakeTable.h"
10 #include "otsdaq-core/TableCore/TableBase.h"
11 #include "otsdaq-core/TableCore/TableGroupKey.h"
12 #include "otsdaq-core/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;
40 const std::string tableName,
41 std::shared_ptr<const TableGroupKey> groupKey = 0,
42 const std::string* groupName = 0,
43 bool dontFill =
false,
45 bool resetConfiguration =
true,
46 bool looseColumnMatching =
false)
53 table = makeTable(tableName);
72 __COUT_WARN__ <<
"Failed to even use TableBase!" << std::endl;
82 if(groupKey != 0 && groupName != 0)
86 __SS__ <<
"FATAL ERROR: new TableGroup and TableGroupKey should be used!"
93 if(version == TableVersion::INVALID &&
94 (version = findLatestVersion(table)) == TableVersion::INVALID)
96 __COUT__ <<
"FATAL ERROR: Can't ask to fill a table object with "
97 "a negative version! "
98 << tableName << std::endl;
99 __SS__ <<
"FATAL ERROR: Invalid latest version." << std::endl
102 <<
"*******************" << std::endl
103 <<
"Suggestion: If you expect a version to exist for this "
104 "table, perhaps this is your first time running with "
105 "the artdaq database. (and your old configurations have not "
106 "been transferred?) "
108 <<
"Try running this once:\n\n\totsdaq_database_migrate"
111 <<
"This will migrate the old ots file system table to "
112 "the artdaq database approach."
120 if(resetConfiguration)
123 std::set<TableVersion> versions = table->getStoredVersions();
124 for(
auto& version : versions)
125 if(!version.isTemporaryVersion())
126 table->eraseView(version);
135 if(table->isStored(version))
140 if(!table->isActive() || version != table->getViewVersion())
141 table->setActiveView(version);
143 table->getViewP()->setLastAccessTime();
149 if(version.isTemporaryVersion())
151 __SS__ <<
"FATAL ERROR: Can not use interface to fill a "
152 "table object with a temporary version!"
154 ss <<
"FATAL ERROR: Invalid temporary version v" << version << std::endl;
158 table->setupMockupView(version);
159 table->setActiveView(version);
162 table->getViewP()->setLooseColumnMatching(looseColumnMatching);
163 fill(table, version);
164 if(looseColumnMatching)
165 table->getViewP()->setLooseColumnMatching(
false);
166 table->getViewP()->setLastAccessTime();
170 if(table->getViewP()->getVersion() != version)
172 __COUT__ <<
"Version mismatch!! " << table->getViewP()->getVersion()
173 <<
" vs " << version << std::endl;
178 bool nameIsMatch =
true;
179 unsigned int nameIsMatchIndex, nameIsMatchStorageIndex;
180 for(nameIsMatchIndex = 0, nameIsMatchStorageIndex = 0;
181 nameIsMatchIndex < table->getViewP()->getTableName().size();
184 if(table->getMockupViewP()->getTableName()[nameIsMatchStorageIndex] ==
186 ++nameIsMatchStorageIndex;
187 if(table->getViewP()->getTableName()[nameIsMatchIndex] ==
'_')
191 if(nameIsMatchStorageIndex >=
192 table->getMockupViewP()->getTableName().size() ||
193 table->getViewP()->getTableName()[nameIsMatchIndex] !=
194 table->getMockupViewP()->getTableName()[nameIsMatchStorageIndex])
200 ++nameIsMatchStorageIndex;
205 table->getViewP()->setTableName(table->getMockupViewP()->getTableName());
209 __COUT__ <<
"View Table Name mismatch!! "
210 << table->getViewP()->getTableName() <<
" vs "
211 << table->getMockupViewP()->getTableName() << std::endl;
222 __COUT__ <<
"Error occurred while getting and filling Table \"" << tableName
223 <<
"\" version:" << version << std::endl;
224 __COUT__ <<
"\t-Configuration interface mode=" << theMode_ << std::endl;
231 virtual std::set<std::string > getAllTableNames()
const
232 throw(std::runtime_error)
236 "ConfigurationInterface::... Must only call "
237 "getAllTableNames in a mode with this functionality "
238 "implemented (e.g. DatabaseConfigurationInterface).");
240 virtual std::set<TableVersion> getVersions(
const TableBase* configuration)
const = 0;
241 const bool& getMode()
const {
return theMode_; }
247 virtual std::set<std::string > getAllTableGroupNames(
248 const std::string& filterString =
"")
const throw(std::runtime_error)
252 "ConfigurationInterface::... Must only call "
253 "getAllTableGroupNames in a mode with this functionality "
254 "implemented (e.g. DatabaseConfigurationInterface).");
256 virtual std::set<TableGroupKey> getKeys(
const std::string& groupName)
const
260 "ConfigurationInterface::... Must only call "
261 "getKeys in a mode with this functionality "
262 "implemented (e.g. DatabaseConfigurationInterface).");
268 virtual std::map<std::string ,
TableVersion > getTableGroupMembers(
269 std::string
const& ,
bool includeMetaDataTable =
false)
const
270 throw(std::runtime_error)
274 "ConfigurationInterface::... Must only call "
275 "getTableGroupMembers in a mode with this functionality "
276 "implemented (e.g. DatabaseConfigurationInterface).");
279 virtual void saveTableGroup(
280 std::map<std::string ,
282 std::string
const& )
const throw(std::runtime_error)
286 "ConfigurationInterface::... Must only call "
287 "saveTableGroup in a mode with this functionality "
288 "implemented (e.g. DatabaseConfigurationInterface).");
299 const std::string& groupName)
const
303 "ConfigurationInterface::... Must only call findLatestGroupKey in a "
304 "mode with this functionality implemented (e.g. "
305 "DatabaseConfigurationInterface).");
309 virtual void saveActiveVersion(
const TableBase* configuration,
310 bool overwrite =
false)
const = 0;
313 ConfigurationHandlerBase* theConfigurationHandler_;
317 static bool theMode_;
319 theVersionTrackingEnabled_;