1 #include "otsdaq/ConfigurationInterface/ConfigurationManagerRW.h"
9 #define __MF_SUBJECT__ "ConfigurationManagerRW"
11 #define TABLE_INFO_PATH std::string(__ENV__("TABLE_INFO_PATH")) + "/"
12 #define TABLE_INFO_EXT "Info.xml"
14 #define CORE_TABLE_INFO_FILENAME \
15 ((getenv("SERVICE_DATA_PATH") == NULL) \
16 ? (std::string(__ENV__("USER_DATA")) + "/ServiceData") \
17 : (std::string(__ENV__("SERVICE_DATA_PATH")))) + \
18 "/CoreTableInfoNames.dat"
20 std::atomic<bool> ConfigurationManagerRW::firstTimeConstructed_ =
true;
22 std::mutex ConfigurationManagerRW::versionCreationTimeCacheMutex_;
23 std::map<std::string, std::map<TableVersion, time_t>>
24 ConfigurationManagerRW::versionCreationTimeCache_;
31 __GEN_COUT__ <<
"Instantiating Config Manager with Write Access! (for " << username
32 <<
") time=" << time(0) <<
" runTimeSeconds()=" << runTimeSeconds()
35 theInterface_ = ConfigurationInterface::getInstance(
36 ConfigurationInterface::CONFIGURATION_MODE::
42 if(firstTimeConstructed_)
44 firstTimeConstructed_ =
false;
47 mkdir((ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH).c_str(), 0755);
49 const std::set<std::string>& contextMemberNames = getFixedContextMemberNames();
50 const std::set<std::string>& backboneMemberNames = getBackboneMemberNames();
51 const std::set<std::string>& iterateMemberNames = getIterateMemberNames();
53 FILE* fp = fopen((CORE_TABLE_INFO_FILENAME).c_str(),
"r");
57 std::vector<unsigned int> foundVector;
59 for(
const auto& name : contextMemberNames)
61 foundVector.push_back(
false);
63 while(fgets(line, 100, fp))
67 line[strlen(line) - 1] =
'\0';
68 if(strcmp(line, (
"ContextGroup/" + name).c_str()) == 0)
70 foundVector.back() =
true;
76 for(
const auto& name : backboneMemberNames)
78 foundVector.push_back(
false);
80 while(fgets(line, 100, fp))
84 line[strlen(line) - 1] =
'\0';
85 if(strcmp(line, (
"BackboneGroup/" + name).c_str()) == 0)
87 foundVector.back() =
true;
93 for(
const auto& name : iterateMemberNames)
95 foundVector.push_back(
false);
97 while(fgets(line, 100, fp))
101 line[strlen(line) - 1] =
'\0';
102 if(strcmp(line, (
"IterateGroup/" + name).c_str()) == 0)
104 foundVector.back() =
true;
112 foundVector.push_back(
false);
114 while(fgets(line, 100, fp))
118 line[strlen(line) - 1] =
'\0';
121 ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE)
124 foundVector.back() =
true;
133 fp = fopen((CORE_TABLE_INFO_FILENAME).c_str(),
"a");
137 for(
const auto& name : contextMemberNames)
140 fprintf(fp,
"\nContextGroup/%s", name.c_str());
144 for(
const auto& name : backboneMemberNames)
147 fprintf(fp,
"\nBackboneGroup/%s", name.c_str());
151 for(
const auto& name : iterateMemberNames)
154 fprintf(fp,
"\nIterateGroup/%s", name.c_str());
164 ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE.c_str());
170 __SS__ <<
"Failed to open core table info file for appending: "
171 << CORE_TABLE_INFO_FILENAME << __E__;
177 fp = fopen((CORE_TABLE_INFO_FILENAME).c_str(),
"w");
180 fprintf(fp,
"ARTDAQ/*");
181 fprintf(fp,
"\nConfigCore/*");
182 for(
const auto& name : contextMemberNames)
183 fprintf(fp,
"\nContextGroup/%s", name.c_str());
184 for(
const auto& name : backboneMemberNames)
185 fprintf(fp,
"\nBackboneGroup/%s", name.c_str());
186 for(
const auto& name : iterateMemberNames)
187 fprintf(fp,
"\nIterateGroup/%s", name.c_str());
192 __SS__ <<
"Failed to open core table info file: "
193 << CORE_TABLE_INFO_FILENAME << __E__;
199 __GEN_COUTV__(runTimeSeconds());
211 std::string* accumulatedWarnings ,
212 const std::string& errorFilterName ,
215 bool initializeActiveGroups )
220 return allTableInfo_;
223 allTableInfo_.clear();
230 __GEN_COUT__ <<
"======================================================== "
231 "getAllTableInfo start runTimeSeconds()="
232 << runTimeSeconds() << __E__;
234 __GEN_COUT__ <<
"Refreshing all! Extracting list of tables..." << __E__;
236 struct dirent* entry;
237 std::string path = TABLE_INFO_PATH;
238 char fileExt[] = TABLE_INFO_EXT;
239 const unsigned char MIN_TABLE_NAME_SZ = 3;
242 __GEN_COUT__ <<
" PROCESSOR_COUNT " <<
PROCESSOR_COUNT <<
" ==> " << numOfThreads
243 <<
" threads." << __E__;
246 if((pDIR = opendir(path.c_str())) != 0)
248 while((entry = readdir(pDIR)) != 0)
251 if(strlen(entry->d_name) < strlen(fileExt) + MIN_TABLE_NAME_SZ)
255 if(strcmp(&(entry->d_name[strlen(entry->d_name) - strlen(fileExt)]),
259 entry->d_name[strlen(entry->d_name) - strlen(fileExt)] =
267 theInterface_->get(table,
273 catch(cet::exception
const&)
279 __GEN_COUT__ <<
"Skipping! No valid class found for... "
280 << entry->d_name <<
"\n";
283 catch(std::runtime_error& e)
289 __GEN_COUT__ <<
"Skipping! No valid class found for... "
290 << entry->d_name <<
"\n";
291 __GEN_COUT__ <<
"Error: " << e.what() << __E__;
296 if(accumulatedWarnings)
298 if(errorFilterName ==
"" || errorFilterName == entry->d_name)
300 *accumulatedWarnings += std::string(
"\nIn table '") +
301 entry->d_name +
"'..." +
304 __SS__ <<
"Attempting to allow illegal columns!" << __E__;
305 *accumulatedWarnings += ss.str();
309 __GEN_COUT__ <<
"Attempting to allow illegal columns!"
312 std::string returnedAccumulatedErrors;
316 &returnedAccumulatedErrors);
320 __GEN_COUT__ <<
"Skipping! Allowing illegal columns "
321 "didn't work either... "
322 << entry->d_name <<
"\n";
326 <<
"Error (but allowed): " << returnedAccumulatedErrors
329 if(errorFilterName ==
"" || errorFilterName == entry->d_name)
330 *accumulatedWarnings +=
331 std::string(
"\nIn table '") + entry->d_name +
"'..." +
332 returnedAccumulatedErrors;
338 if(nameToTableMap_[entry->d_name])
341 std::set<TableVersion> versions =
342 nameToTableMap_[entry->d_name]->getStoredVersions();
343 for(
auto& version : versions)
344 if(version.isTemporaryVersion())
348 nameToTableMap_[entry->d_name]->setActiveView(
351 nameToTableMap_[entry->d_name]->getView(),
362 delete nameToTableMap_[entry->d_name];
363 nameToTableMap_[entry->d_name] = 0;
366 nameToTableMap_[entry->d_name] = table;
368 allTableInfo_[entry->d_name].tablePtr_ = table;
369 allTableInfo_[entry->d_name].versions_ =
370 theInterface_->getVersions(table);
374 std::set<TableVersion> versions =
375 nameToTableMap_[entry->d_name]->getStoredVersions();
376 for(
auto& version : versions)
377 if(version.isTemporaryVersion())
379 allTableInfo_[entry->d_name].versions_.emplace(version);
387 int threadsLaunched = 0;
388 int foundThreadIndex = 0;
389 std::string tableName;
391 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
392 for(
int i = 0; i < numOfThreads; ++i)
393 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
395 std::vector<std::shared_ptr<ots::TableInfo>> sharedTableInfoPtrs;
397 if((pDIR = opendir(path.c_str())) != 0)
399 while((entry = readdir(pDIR)) != 0)
402 if(strlen(entry->d_name) < strlen(fileExt) + MIN_TABLE_NAME_SZ)
406 if(strcmp(&(entry->d_name[strlen(entry->d_name) - strlen(fileExt)]),
410 entry->d_name[strlen(entry->d_name) - strlen(fileExt)] =
417 sharedTableInfoPtrs.push_back(std::make_shared<ots::TableInfo>());
418 sharedTableInfoPtrs.back()->accumulatedWarnings_ =
419 accumulatedWarnings ?
"ALLOW"
422 if(threadsLaunched >= numOfThreads)
425 foundThreadIndex = -1;
427 while(foundThreadIndex == -1)
429 for(
int i = 0; i < numOfThreads; ++i)
432 foundThreadIndex = i;
435 if(foundThreadIndex == -1)
437 __GEN_COUT_TYPE__(TLVL_DEBUG + 2)
439 <<
"Waiting for available thread... iteration # "
443 __GEN_SS__ <<
"Threads seem to be stuck getting "
444 "table info! Timeout while waiting..."
451 threadsLaunched = numOfThreads - 1;
453 __GEN_COUTT__ <<
"Starting thread... " << foundThreadIndex
454 <<
" for table " << tableName << __E__;
456 *(threadDone[foundThreadIndex]) =
false;
459 std::string theTableName,
461 std::shared_ptr<ots::TableInfo> theTableInfo,
462 std::shared_ptr<std::atomic<bool>> theThreadDone) {
471 nameToTableMap_[tableName],
472 sharedTableInfoPtrs.back(),
473 threadDone[foundThreadIndex])
485 foundThreadIndex = -1;
486 for(
int i = 0; i < numOfThreads; ++i)
487 if(!*(threadDone[i]))
489 foundThreadIndex = i;
492 if(foundThreadIndex != -1)
494 __GEN_COUTT__ <<
"Waiting for thread to finish... "
495 << foundThreadIndex << __E__;
498 }
while(foundThreadIndex != -1);
501 for(
auto& tableInfo : sharedTableInfoPtrs)
503 if(tableInfo->tablePtr_ ==
nullptr)
505 __SS__ <<
"Fatal error occurred loading table info into cache! "
506 "Perhaps there is an illegal Table schema definition? "
507 "Check logs to resolve."
511 __GEN_COUT_TYPE__(TLVL_DEBUG + 3)
512 << __COUT_HDR__ <<
"Copying table info for "
513 << tableInfo->tablePtr_->getTableName() << __E__;
514 nameToTableMap_[tableInfo->tablePtr_->getTableName()] =
515 tableInfo->tablePtr_;
516 allTableInfo_[tableInfo->tablePtr_->getTableName()].tablePtr_ =
517 tableInfo->tablePtr_;
518 allTableInfo_[tableInfo->tablePtr_->getTableName()].versions_ =
519 tableInfo->versions_;
522 __GEN_COUT__ <<
"Extracting list of tables complete." << __E__;
526 if(initializeActiveGroups)
528 __GEN_COUT__ <<
"Now initializing..." << __E__;
530 std::string tmpAccumulateWarnings;
533 accumulatedWarnings ? &tmpAccumulateWarnings :
nullptr);
535 if(accumulatedWarnings && errorFilterName ==
"")
536 *accumulatedWarnings += tmpAccumulateWarnings;
538 __GEN_COUT__ <<
"======================================================== "
539 "getAllTableInfo end runTimeSeconds()="
540 << runTimeSeconds() << __E__;
545 allGroupInfo_.clear();
550 std::set<std::string > tableGroups =
551 theInterface_->getAllTableGroupNames();
552 __GEN_COUT__ <<
"Number of Groups: " << tableGroups.size() << __E__;
554 __GEN_COUTT__ <<
"Group Info start runTimeSeconds()=" << runTimeSeconds()
559 for(
const auto& fullName : tableGroups)
562 allGroupInfo_[name].keys_.emplace(key);
565 __GEN_COUTT__ <<
"Group Keys end runTimeSeconds()=" << runTimeSeconds()
573 << numOfThreads <<
" threads." << __E__;
575 for(
auto& groupInfo : allGroupInfo_)
579 groupInfo.second.latestKey_ = groupInfo.second.getLastKey();
582 groupInfo.second.latestKey_,
584 &groupInfo.second.latestKeyMemberMap_ ,
587 &groupInfo.second.latestKeyGroupComment_,
588 &groupInfo.second.latestKeyGroupAuthor_,
589 &groupInfo.second.latestKeyGroupCreationTime_,
591 &groupInfo.second.latestKeyGroupTypeString_);
595 __GEN_COUT_WARN__ <<
"Error occurred loading latest group "
596 "info into cache for '"
597 << groupInfo.first <<
"("
598 << groupInfo.second.latestKey_ <<
")'..."
600 groupInfo.second.latestKey_ = TableGroupKey::INVALID;
601 groupInfo.second.latestKeyGroupComment_ =
602 ConfigurationManager::UNKNOWN_INFO;
603 groupInfo.second.latestKeyGroupAuthor_ =
604 ConfigurationManager::UNKNOWN_INFO;
605 groupInfo.second.latestKeyGroupCreationTime_ =
606 ConfigurationManager::UNKNOWN_TIME;
607 groupInfo.second.latestKeyGroupTypeString_ =
608 ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
609 groupInfo.second.latestKeyMemberMap_ = {};
614 int threadsLaunched = 0;
615 int foundThreadIndex = 0;
617 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
618 for(
int i = 0; i < numOfThreads; ++i)
619 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
621 std::vector<std::shared_ptr<ots::GroupInfo>> sharedGroupInfoPtrs;
623 for(
auto& groupInfo : allGroupInfo_)
626 sharedGroupInfoPtrs.push_back(std::make_shared<ots::GroupInfo>());
628 if(threadsLaunched >= numOfThreads)
631 foundThreadIndex = -1;
632 while(foundThreadIndex == -1)
634 for(
int i = 0; i < numOfThreads; ++i)
637 foundThreadIndex = i;
640 if(foundThreadIndex == -1)
642 __GEN_COUTT__ <<
"Waiting for available thread..."
647 threadsLaunched = numOfThreads - 1;
649 __GEN_COUTT__ <<
"Starting thread... " << foundThreadIndex
650 <<
" for " << groupInfo.first <<
"("
651 << groupInfo.second.getLastKey() <<
")" << __E__;
653 *(threadDone[foundThreadIndex]) =
false;
657 std::string theGroupName,
659 std::shared_ptr<ots::GroupInfo> theGroupInfo,
660 std::shared_ptr<std::atomic<bool>> theThreadDone) {
670 groupInfo.second.getLastKey(),
671 sharedGroupInfoPtrs.back(),
672 threadDone[foundThreadIndex])
682 foundThreadIndex = -1;
683 for(
int i = 0; i < numOfThreads; ++i)
684 if(!*(threadDone[i]))
686 foundThreadIndex = i;
689 if(foundThreadIndex != -1)
691 __GEN_COUTT__ <<
"Waiting for thread to finish... "
692 << foundThreadIndex << __E__;
695 }
while(foundThreadIndex != -1);
699 for(
auto& groupInfo : allGroupInfo_)
701 groupInfo.second.latestKey_ = sharedGroupInfoPtrs[i]->latestKey_;
702 groupInfo.second.latestKeyGroupComment_ =
703 sharedGroupInfoPtrs[i]->latestKeyGroupComment_;
704 groupInfo.second.latestKeyGroupAuthor_ =
705 sharedGroupInfoPtrs[i]->latestKeyGroupAuthor_;
706 groupInfo.second.latestKeyGroupCreationTime_ =
707 sharedGroupInfoPtrs[i]->latestKeyGroupCreationTime_;
708 groupInfo.second.latestKeyGroupTypeString_ =
709 sharedGroupInfoPtrs[i]->latestKeyGroupTypeString_;
710 groupInfo.second.latestKeyMemberMap_ =
711 sharedGroupInfoPtrs[i]->latestKeyMemberMap_;
718 catch(
const std::runtime_error& e)
721 <<
"A fatal error occurred reading the info for all table groups. Error: "
722 << e.what() << __E__;
723 __GEN_COUT_ERR__ <<
"Error at time: " << time(0) <<
"\n" << ss.str();
724 if(accumulatedWarnings)
725 *accumulatedWarnings += ss.str();
731 __SS__ <<
"An unknown fatal error occurred reading the info for all table "
738 catch(
const std::exception& e)
740 ss <<
"Exception message: " << e.what();
745 __GEN_COUT_ERR__ <<
"\n" << ss.str();
746 if(accumulatedWarnings)
747 *accumulatedWarnings += ss.str();
751 __GEN_COUTT__ <<
"Group Info end runTimeSeconds()=" << runTimeSeconds() << __E__;
754 __GEN_COUTT__ <<
"Table Info end runTimeSeconds()=" << runTimeSeconds() << __E__;
756 return allTableInfo_;
763 std::string tableName,
765 std::shared_ptr<ots::TableInfo> tableInfo,
766 std::shared_ptr<std::atomic<bool>> threadDone)
769 __COUTT__ <<
"Thread started... table " << tableName << __E__;
772 tableInfo->tablePtr_ = 0;
776 cfgMgr->theInterface_->get(tableInfo->tablePtr_,
782 catch(cet::exception
const&)
784 if(tableInfo->tablePtr_)
785 delete tableInfo->tablePtr_;
786 tableInfo->tablePtr_ = 0;
788 __COUT__ <<
"Skipping! No valid class found for... " << tableName <<
"\n";
789 *(threadDone) =
true;
792 catch(std::runtime_error& e)
794 if(tableInfo->tablePtr_)
795 delete tableInfo->tablePtr_;
796 tableInfo->tablePtr_ = 0;
798 __COUT__ <<
"Skipping! No valid class found for... " << tableName <<
"\n";
799 __COUTT__ <<
"Error: " << e.what() << __E__;
804 if(tableInfo->accumulatedWarnings_ ==
"ALLOW")
806 tableInfo->accumulatedWarnings_ =
"";
809 tableInfo->accumulatedWarnings_ += std::string(
"\nIn table '") +
813 __SS__ <<
"Attempting to allow illegal columns!" << __E__;
814 tableInfo->accumulatedWarnings_ += ss.str();
818 __COUT__ <<
"Attempting to allow illegal columns!" << __E__;
820 std::string returnedAccumulatedErrors;
823 tableInfo->tablePtr_ =
824 new TableBase(tableName, &returnedAccumulatedErrors);
828 __COUT__ <<
"Skipping! Allowing illegal columns didn't work either... "
829 << tableName <<
"\n";
830 *(threadDone) =
true;
833 __COUT_WARN__ <<
"Error (but allowed): " << returnedAccumulatedErrors
837 tableInfo->accumulatedWarnings_ +=
838 std::string(
"\nIn table '") + tableName +
"'..." +
839 returnedAccumulatedErrors;
843 tableInfo->accumulatedWarnings_ =
"";
844 *(threadDone) =
true;
851 __COUTT__ <<
"Copying temporary version from existing table object for "
852 << tableName << __E__;
854 std::set<TableVersion> versions = existingTable->getStoredVersions();
855 for(
auto& version : versions)
856 if(version.isTemporaryVersion())
860 existingTable->setActiveView(version);
861 tableInfo->tablePtr_->copyView(
862 existingTable->getView(),
872 delete existingTable;
876 tableInfo->versions_ = cfgMgr->theInterface_->getVersions(tableInfo->tablePtr_);
880 std::set<TableVersion> versions = tableInfo->tablePtr_->getStoredVersions();
881 for(
auto& version : versions)
882 if(version.isTemporaryVersion())
884 tableInfo->versions_.emplace(version);
887 __COUTT__ <<
"Thread done... table " << tableName << __E__;
888 *(threadDone) =
true;
892 __COUT_ERR__ <<
"Error occurred loading latest table info into cache for '"
893 << tableName <<
"'..." << __E__;
894 *(threadDone) =
true;
901 const std::string& groupName,
904 std::map<std::string /*table name*/, TableVersion>*
907 std::string* accumulatedWarnings ,
908 std::string* groupComment ,
909 std::string* groupAuthor ,
910 std::string* groupCreateTime ,
911 bool doNotLoadMembers ,
912 std::string* groupTypeString ,
913 std::map<std::string /*name*/, std::string /*alias*/>*
915 ConfigurationManager::LoadGroupType
917 bool ignoreVersionTracking )
932 ignoreVersionTracking);
934 if(!groupMembers || !groupMembers->size() || !groupComment || groupKey.
isInvalid() ||
935 !groupAuthor || !groupCreateTime)
939 auto groupInfo = allGroupInfo_.find(groupName);
940 if(groupInfo == allGroupInfo_.end())
943 groupInfo->second.latestKey_ = groupKey;
944 groupInfo->second.latestKeyGroupComment_ = *groupComment;
945 groupInfo->second.latestKeyGroupAuthor_ = *groupAuthor;
946 groupInfo->second.latestKeyGroupCreationTime_ = *groupCreateTime;
948 groupInfo->second.latestKeyGroupTypeString_ = *groupTypeString;
949 groupInfo->second.latestKeyMemberMap_ = *groupMembers;
957 std::string groupName,
959 std::shared_ptr<ots::GroupInfo> groupInfo,
960 std::shared_ptr<std::atomic<bool>> threadDone)
963 __COUTT__ <<
"Thread started... " << groupName <<
"(" << groupKey <<
")" << __E__;
965 groupInfo->latestKey_ = groupKey;
969 &(groupInfo->latestKeyMemberMap_) ,
972 &(groupInfo->latestKeyGroupComment_),
973 &(groupInfo->latestKeyGroupAuthor_),
974 &(groupInfo->latestKeyGroupCreationTime_),
976 &(groupInfo->latestKeyGroupTypeString_));
978 *(threadDone) =
true;
982 __COUT_WARN__ <<
"Error occurred loading latest group info into cache for '"
983 << groupName <<
"(" << groupInfo->latestKey_ <<
")'..." << __E__;
984 groupInfo->latestKey_ = TableGroupKey::INVALID;
985 groupInfo->latestKeyGroupComment_ = ConfigurationManager::UNKNOWN_INFO;
986 groupInfo->latestKeyGroupAuthor_ = ConfigurationManager::UNKNOWN_INFO;
987 groupInfo->latestKeyGroupCreationTime_ = ConfigurationManager::UNKNOWN_TIME;
988 groupInfo->latestKeyGroupTypeString_ = ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
989 groupInfo->latestKeyMemberMap_ = {};
990 *(threadDone) =
true;
999 std::string groupName,
1001 const std::map<std::string, TableVersion>& groupMemberMap,
1002 const std::map<std::string /*name*/, std::string /*alias*/>& memberTableAliases,
1003 std::atomic<bool>* foundIdentical,
1005 std::mutex* threadMutex,
1006 std::shared_ptr<std::atomic<bool>> threadDone)
1009 std::map<std::string ,
TableVersion > compareToMemberMap;
1010 std::map<std::string , std::string > compareToMemberTableAliases;
1011 std::map<std::string , std::string >*
1012 compareToMemberTableAliasesPtr =
nullptr;
1013 if(memberTableAliases
1015 compareToMemberTableAliasesPtr = &compareToMemberTableAliases;
1020 &compareToMemberMap ,
1028 compareToMemberTableAliasesPtr);
1034 for(
auto& memberPair : groupMemberMap)
1035 __COUTS__(9) <<
"member " << memberPair.first <<
" (" << memberPair.second
1037 for(
auto& memberPair : compareToMemberMap)
1038 __COUTS__(9) <<
"compare " << groupName <<
" (" << groupKeyToCompare
1039 <<
") member:" << memberPair.first <<
" (" << memberPair.second
1043 bool isDifferent =
false;
1044 for(
auto& memberPair : groupMemberMap)
1048 if(memberTableAliases.find(memberPair.first) != memberTableAliases.end())
1051 if(compareToMemberTableAliases.find(memberPair.first) ==
1052 compareToMemberTableAliases.end() ||
1053 memberTableAliases.at(memberPair.first) !=
1054 compareToMemberTableAliases.at(memberPair.first))
1058 __COUTT__ <<
"diff " << groupName <<
" (" << groupKeyToCompare
1059 <<
") on alias " << memberPair.first << __E__;
1063 else if(compareToMemberTableAliases.find(memberPair.first) !=
1064 compareToMemberTableAliases.end())
1069 __COUTT__ <<
"diff " << groupName <<
" (" << groupKeyToCompare
1070 <<
") on reverse alias " << memberPair.first << __E__;
1076 if(compareToMemberMap.find(memberPair.first) ==
1077 compareToMemberMap.end() ||
1078 memberPair.second !=
1079 compareToMemberMap.at(memberPair.first))
1084 __COUTT__ <<
"diff " << groupName <<
" (" << groupKeyToCompare
1085 <<
") on mismatch " << memberPair.first << __E__;
1092 groupMemberMap.size() !=
1099 __COUTT__ <<
"diff " << groupName <<
" (" << groupKeyToCompare <<
") on size "
1105 *foundIdentical =
true;
1106 __COUT__ <<
"=====> Found exact match with key: " << groupKeyToCompare << __E__;
1108 std::lock_guard<std::mutex> lock(*threadMutex);
1109 *identicalKey = groupKeyToCompare;
1112 *(threadDone) =
true;
1116 __COUT_WARN__ <<
"Error occurred comparing group '" << groupName <<
"("
1117 << groupKeyToCompare <<
")'..." << __E__;
1119 *(threadDone) =
true;
1126 std::map<std::string ,
1130 std::map<std::string ,
1136 if(!ConfigurationInterface::isVersionTrackingEnabled())
1137 for(
const auto& tableInfo : allTableInfo_)
1138 for(
const auto& version : tableInfo.second.versions_)
1139 if(version.isScratchVersion())
1140 retMap[tableInfo.first][ConfigurationManager::SCRATCH_VERSION_ALIAS] =
1152 std::string* accumulatedTreeErrors,
1153 std::string* groupTypeString)
1162 accumulatedTreeErrors,
1171 __GEN_COUT_ERR__ <<
"There were errors, so de-activating group: "
1172 << tableGroupName <<
" (" << tableGroupKey <<
")" << __E__;
1183 __GEN_COUT_INFO__ <<
"Updating persistent active groups to "
1186 __COUT_INFO__ <<
"Active Context table group: " << theContextTableGroup_ <<
"("
1187 << (theContextTableGroupKey_
1188 ? theContextTableGroupKey_->toString().c_str()
1191 __COUT_INFO__ <<
"Active Backbone table group: " << theBackboneTableGroup_ <<
"("
1192 << (theBackboneTableGroupKey_
1193 ? theBackboneTableGroupKey_->toString().c_str()
1196 __COUT_INFO__ <<
"Active Iterate table group: " << theIterateTableGroup_ <<
"("
1197 << (theIterateTableGroupKey_
1198 ? theIterateTableGroupKey_->toString().c_str()
1201 __COUT_INFO__ <<
"Active Configuration table group: " << theConfigurationTableGroup_
1203 << (theConfigurationTableGroupKey_
1204 ? theConfigurationTableGroupKey_->toString().c_str()
1209 FILE* fp = fopen(fn.c_str(),
"w");
1212 __SS__ <<
"Fatal Error! Unable to open the file "
1214 <<
" for editing! Is there a permissions problem?" << __E__;
1215 __GEN_COUT_ERR__ << ss.str();
1219 fprintf(fp,
"%s\n", theContextTableGroup_.c_str());
1223 theContextTableGroupKey_ ? theContextTableGroupKey_->toString().c_str() :
"-1");
1224 fprintf(fp,
"%s\n", theBackboneTableGroup_.c_str());
1228 theBackboneTableGroupKey_ ? theBackboneTableGroupKey_->toString().c_str() :
"-1");
1229 fprintf(fp,
"%s\n", theIterateTableGroup_.c_str());
1233 theIterateTableGroupKey_ ? theIterateTableGroupKey_->toString().c_str() :
"-1");
1234 fprintf(fp,
"%s\n", theConfigurationTableGroup_.c_str());
1237 theConfigurationTableGroupKey_
1238 ? theConfigurationTableGroupKey_->toString().c_str()
1245 std::string(tableGroupName), tableGroupKey);
1246 if(theConfigurationTableGroupKey_ &&
1247 theConfigurationTableGroup_ == tableGroupName &&
1248 *theConfigurationTableGroupKey_ == tableGroupKey)
1250 ConfigurationManager::saveGroupNameAndKey(
1252 ConfigurationManager::LAST_ACTIVATED_CONFIG_GROUP_FILE,
1255 ConfigurationManager::saveGroupNameAndKey(
1257 ConfigurationManager::ACTIVATED_CONFIGS_FILE,
1261 else if(theContextTableGroupKey_ && theContextTableGroup_ == tableGroupName &&
1262 *theContextTableGroupKey_ == tableGroupKey)
1264 ConfigurationManager::saveGroupNameAndKey(
1266 ConfigurationManager::LAST_ACTIVATED_CONTEXT_GROUP_FILE,
1269 ConfigurationManager::saveGroupNameAndKey(
1271 ConfigurationManager::ACTIVATED_CONTEXTS_FILE,
1275 else if(theBackboneTableGroupKey_ && theBackboneTableGroup_ == tableGroupName &&
1276 *theBackboneTableGroupKey_ == tableGroupKey)
1278 ConfigurationManager::saveGroupNameAndKey(
1280 ConfigurationManager::LAST_ACTIVATED_BACKBONE_GROUP_FILE,
1283 ConfigurationManager::saveGroupNameAndKey(
1285 ConfigurationManager::ACTIVATED_BACKBONES_FILE,
1289 else if(theIterateTableGroupKey_ && theIterateTableGroup_ == tableGroupName &&
1290 *theIterateTableGroupKey_ == tableGroupKey)
1292 ConfigurationManager::saveGroupNameAndKey(
1294 ConfigurationManager::LAST_ACTIVATED_ITERATE_GROUP_FILE,
1297 ConfigurationManager::saveGroupNameAndKey(
1299 ConfigurationManager::ACTIVATED_ITERATES_FILE,
1314 __GEN_COUT_INFO__ <<
"Creating temporary backbone view from version "
1315 << sourceViewVersion << __E__;
1321 auto backboneMemberNames = ConfigurationManager::getBackboneMemberNames();
1322 for(
auto& name : backboneMemberNames)
1326 if(retTmpVersion < tmpVersion)
1327 tmpVersion = retTmpVersion;
1330 __GEN_COUT__ <<
"Common temporary backbone version found as " << tmpVersion << __E__;
1333 for(
auto& name : backboneMemberNames)
1337 if(retTmpVersion != tmpVersion)
1339 __SS__ <<
"Failure! Temporary view requested was " << tmpVersion
1340 <<
". Mismatched temporary view created: " << retTmpVersion << __E__;
1341 __GEN_COUT_ERR__ << ss.str();
1350 TableBase* ConfigurationManagerRW::getTableByName(
const std::string& tableName)
1352 if(nameToTableMap_.find(tableName) == nameToTableMap_.end())
1354 if(tableName == ConfigurationManager::ARTDAQ_TOP_TABLE_NAME)
1357 <<
"Since target table was the artdaq top configuration level, "
1358 "attempting to help user by appending to core tables file: "
1359 << CORE_TABLE_INFO_FILENAME << __E__;
1360 FILE* fp = fopen((CORE_TABLE_INFO_FILENAME).c_str(),
"a");
1363 fprintf(fp,
"\nARTDAQ/*");
1368 __SS__ <<
"Table not found with name: " << tableName << __E__;
1370 if((f = tableName.find(
' ')) != std::string::npos)
1371 ss <<
"There was a space character found in the table name needle at "
1373 << f <<
" in the string (was this intended?). " << __E__;
1375 ss <<
"\nIf you think this table should exist in the core set of tables, try "
1376 "running 'UpdateOTS.sh --tables' to update your tables, then relaunch ots."
1378 ss <<
"\nTables must be defined at path $USER_DATA/TableInfo/ to exist in ots. "
1379 "Please verify your table definitions, and then restart ots."
1381 __GEN_COUT_ERR__ <<
"\n" << ss.str();
1384 return nameToTableMap_[tableName];
1396 std::lock_guard<std::mutex> lock(versionCreationTimeCacheMutex_);
1398 auto tableIt = versionCreationTimeCache_.find(tableName);
1399 if(tableIt != versionCreationTimeCache_.end())
1401 auto versionIt = tableIt->second.find(version);
1402 if(versionIt != tableIt->second.end())
1403 return versionIt->second;
1407 std::string localAccumulatedErrors;
1408 const auto loadStartTime = std::chrono::steady_clock::now();
1409 time_t creationTime = getVersionedTableByName(tableName,
1412 &localAccumulatedErrors,
1419 std::chrono::duration<double>(std::chrono::steady_clock::now() - loadStartTime)
1422 __GEN_COUT_WARN__ <<
"Slow creation time lookup: table '" << tableName
1423 <<
"' version v" << version <<
" load took " << loadSec <<
" s"
1428 std::lock_guard<std::mutex> lock(versionCreationTimeCacheMutex_);
1429 versionCreationTimeCache_[tableName][version] = creationTime;
1432 return creationTime;
1444 const auto preloadStartTime = std::chrono::steady_clock::now();
1447 std::vector<std::pair<std::string, std::vector<TableVersion>>> groupedWork;
1448 size_t missingCount = 0;
1450 std::lock_guard<std::mutex> lock(versionCreationTimeCacheMutex_);
1452 for(
const auto& tableInfoPair : allTableInfo_)
1454 auto tableIt = versionCreationTimeCache_.find(tableInfoPair.first);
1456 std::vector<TableVersion> missingVersions;
1457 for(
const auto& version : tableInfoPair.second.versions_)
1459 if(version.isTemporaryVersion() || version.isScratchVersion())
1461 if(tableIt != versionCreationTimeCache_.end() &&
1462 tableIt->second.find(version) != tableIt->second.end())
1464 missingVersions.push_back(version);
1466 if(missingVersions.size())
1468 missingCount += missingVersions.size();
1469 groupedWork.emplace_back(tableInfoPair.first, std::move(missingVersions));
1473 if(groupedWork.empty())
1477 std::vector<std::pair<std::string, TableVersion>> flatWork;
1478 flatWork.reserve(missingCount);
1480 size_t maxVersions = 0;
1481 for(
const auto& gw : groupedWork)
1482 if(gw.second.size() > maxVersions)
1483 maxVersions = gw.second.size();
1484 for(
size_t vi = 0; vi < maxVersions; ++vi)
1485 for(
const auto& gw : groupedWork)
1486 if(vi < gw.second.size())
1487 flatWork.emplace_back(gw.first, gw.second[vi]);
1490 __GEN_COUT__ <<
"preloadVersionCreationTimes() loading " << missingCount
1491 <<
" version creation times for " << groupedWork.size() <<
" tables..."
1495 if(numOfThreads > (
int)flatWork.size())
1496 numOfThreads = flatWork.size();
1498 if(numOfThreads < 2)
1500 for(
const auto& work : flatWork)
1508 __GEN_COUT__ <<
"Failed to get creation time for table '" << work.first
1509 <<
"' version v" << work.second <<
", skipping." << __E__;
1515 std::atomic<size_t> workIndex(0);
1516 std::vector<std::thread> threads;
1517 auto* iface = theInterface_;
1519 for(
int i = 0; i < numOfThreads; ++i)
1520 threads.emplace_back([iface, &workIndex, &flatWork,
this]() {
1521 std::map<std::string, TableBase*> localTables;
1526 while((w = workIndex++) < flatWork.size())
1528 const auto& tableName = flatWork[w].first;
1529 const auto& version = flatWork[w].second;
1533 TableBase*& table = localTables[tableName];
1536 std::string localAccumulatedErrors;
1537 table = new TableBase(tableName, &localAccumulatedErrors);
1540 std::string localAccumulatedErrors;
1550 &localAccumulatedErrors,
1553 time_t creationTime =
1554 table->getView(version).getCreationTime();
1557 std::lock_guard<std::mutex> lock(
1558 versionCreationTimeCacheMutex_);
1559 versionCreationTimeCache_[tableName][version] =
1565 __GEN_COUT__ <<
"Failed to get creation time for table '"
1566 << tableName <<
"' version v" << version
1567 <<
", skipping." << __E__;
1573 __GEN_COUT_ERR__ <<
"Unexpected error in preload thread." << __E__;
1576 for(
auto& pair : localTables)
1581 for(
auto& thread : threads)
1585 __GEN_COUT__ <<
"preloadVersionCreationTimes() loaded " << missingCount
1586 <<
" version creation times with " << numOfThreads <<
" thread(s) in "
1587 << std::chrono::duration<double>(std::chrono::steady_clock::now() -
1600 time_t ConfigurationManagerRW::getVersionLastAccessTime(
const std::string& tableName,
1603 auto it = nameToTableMap_.find(tableName);
1604 if(it == nameToTableMap_.end() || !it->second->isStored(version))
1607 return it->second->getView(version).getLastAccessTime();
1621 TableBase* table = getTableByName(tableName);
1626 newVersion = theInterface_->saveNewVersion(table, temporaryVersion);
1628 table->setActiveView(newVersion);
1632 allTableInfo_[tableName].versions_.find(newVersion) !=
1633 allTableInfo_[tableName].versions_.end())
1636 <<
"What happenened!?? ERROR::: new persistent version v" << newVersion
1637 <<
" already exists!? How is it possible? Retrace your steps and "
1645 newVersion = temporaryVersion;
1649 __GEN_COUT_WARN__ <<
"Attempting to recover and use v" << newVersion << __E__;
1653 theInterface_->saveNewVersion(table, temporaryVersion, newVersion);
1655 table->setActiveView(newVersion);
1660 __SS__ <<
"Something went wrong saving the new version v" << newVersion
1661 <<
". What happened?! (duplicates? database error?)" << __E__;
1662 __GEN_COUT_ERR__ <<
"\n" << ss.str();
1667 allTableInfo_[tableName].versions_.insert(newVersion);
1681 TableBase* table = getTableByName(tableName);
1686 if(allTableInfo_.find(tableName) == allTableInfo_.end())
1693 for(
auto it = allTableInfo_[tableName].versions_.begin();
1694 it != allTableInfo_[tableName].versions_.end();
1697 if(it->isTemporaryVersion())
1699 __GEN_COUT__ <<
"Removing '" << tableName <<
"' version info: " << *it
1701 allTableInfo_[tableName].versions_.erase(it++);
1710 auto it = allTableInfo_[tableName].versions_.find(targetVersion);
1711 if(it == allTableInfo_[tableName].versions_.end())
1713 __GEN_COUT__ <<
"Target '" << tableName <<
"' version v" << targetVersion
1714 <<
" was not found in info versions..." << __E__;
1717 allTableInfo_[tableName].versions_.erase(
1718 allTableInfo_[tableName].versions_.find(targetVersion));
1729 TableBase* table = getTableByName(tableName);
1741 for(
auto configInfo : allTableInfo_)
1742 configInfo.second.tablePtr_->trimCache(0);
1748 const std::string& tableName,
TableVersion sourceVersion)
1750 getTableByName(tableName)->reset();
1755 getVersionedTableByName(tableName,
TableVersion(sourceVersion),
true);
1762 allTableInfo_[tableName].versions_.insert(newTemporaryVersion);
1764 return newTemporaryVersion;
1772 const std::string& groupName,
bool attemptToReloadKeys )
1779 auto it = allGroupInfo_.find(groupName);
1780 if(it == allGroupInfo_.end())
1782 __SS__ <<
"Group name '" << groupName
1783 <<
"' not found in group info! (creating empty info)" << __E__;
1784 __GEN_COUT_WARN__ << ss.str();
1786 return allGroupInfo_[groupName];
1789 if(attemptToReloadKeys)
1791 __GEN_COUT__ <<
"Reloading keys from special db group cache if it exists..."
1794 std::set<TableGroupKey> keys;
1797 bool cacheFailed =
false;
1803 TableBase::GROUP_CACHE_PREPEND + groupName);
1804 auto versions = theInterface_->getVersions(&localGroupMemberCacheLoader);
1805 for(
const auto& version : versions)
1810 __GEN_COUT__ <<
"Ignoring cache loading error. Doing full load of keys..."
1815 if(cacheFailed && 0)
1816 keys = theInterface_->getKeys(groupName);
1820 __GEN_COUT__ <<
"Key from special db group cache were loaded." << __E__;
1821 it->second.keys_ = keys;
1840 const std::string& groupName,
1841 const std::map<std::string, TableVersion>& groupMemberMap,
1842 const std::map<std::string /*name*/, std::string /*alias*/>& memberTableAliases)
1844 if(!groupMemberMap.size() || groupName.empty())
1846 __SS__ <<
"Illegal name/members for requested group of name '" << groupName
1847 <<
"' and member count = " << groupMemberMap.size() << __E__;
1855 std::set<TableGroupKey> keys;
1858 bool cacheFailed =
false;
1864 TableBase::GROUP_CACHE_PREPEND + groupName);
1865 auto versions = theInterface_->getVersions(&localGroupMemberCacheLoader);
1866 for(
const auto& version : versions)
1871 __COUT__ <<
"Ignoring cache loading error. Doing full load of keys..."
1877 keys = theInterface_->getKeys(groupName);
1882 const unsigned int MAX_DEPTH_TO_CHECK = 20;
1883 unsigned int keyMinToCheck = 0;
1886 keyMinToCheck = keys.rbegin()->key();
1887 if(keyMinToCheck > MAX_DEPTH_TO_CHECK)
1889 keyMinToCheck -= MAX_DEPTH_TO_CHECK;
1890 __GEN_COUT__ <<
"Checking groups back to key... " << keyMinToCheck << __E__;
1895 __GEN_COUT__ <<
"Checking all groups." << __E__;
1903 __GEN_COUT__ <<
" PROCESSOR_COUNT " <<
PROCESSOR_COUNT <<
" ==> " << numOfThreads
1904 <<
" threads." << __E__;
1905 if(numOfThreads < 2)
1907 std::map<std::string ,
TableVersion > compareToMemberMap;
1908 std::map<std::string , std::string > compareToMemberTableAliases;
1909 std::map<std::string , std::string >*
1910 compareToMemberTableAliasesPtr =
nullptr;
1911 if(memberTableAliases.size())
1912 compareToMemberTableAliasesPtr = &compareToMemberTableAliases;
1915 for(
const auto& key : keys)
1917 if(key.key() < keyMinToCheck)
1923 &compareToMemberMap ,
1931 compareToMemberTableAliasesPtr);
1933 isDifferent =
false;
1934 for(
auto& memberPair : groupMemberMap)
1936 if(memberTableAliases.find(memberPair.first) != memberTableAliases.end())
1939 if(compareToMemberTableAliases.find(memberPair.first) ==
1940 compareToMemberTableAliases.end() ||
1941 memberTableAliases.at(memberPair.first) !=
1942 compareToMemberTableAliases.at(memberPair.first))
1949 else if(compareToMemberTableAliases.find(memberPair.first) !=
1950 compareToMemberTableAliases.end())
1960 if(compareToMemberMap.find(memberPair.first) ==
1961 compareToMemberMap.end() ||
1962 memberPair.second !=
1963 compareToMemberMap.at(memberPair.first))
1974 if(groupMemberMap.size() != compareToMemberMap.size())
1978 __GEN_COUT__ <<
"Found exact match with key: " << key << __E__;
1982 __GEN_COUT__ <<
"No match found - this group is new!" << __E__;
1988 int threadsLaunched = 0;
1989 int foundThreadIndex = 0;
1990 std::atomic<bool> foundIdentical =
false;
1992 std::mutex threadMutex;
1994 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
1995 for(
int i = 0; i < numOfThreads; ++i)
1996 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
1998 for(
const auto& key : keys)
2002 if(key.key() < keyMinToCheck)
2005 if(threadsLaunched >= numOfThreads)
2008 foundThreadIndex = -1;
2009 while(foundThreadIndex == -1)
2014 for(
int i = 0; i < numOfThreads; ++i)
2015 if(*(threadDone[i]))
2017 foundThreadIndex = i;
2020 if(foundThreadIndex == -1)
2022 __GEN_COUTT__ <<
"Waiting for available thread..." << __E__;
2026 threadsLaunched = numOfThreads - 1;
2031 __GEN_COUTT__ <<
"Starting thread... " << foundThreadIndex << __E__;
2032 *(threadDone[foundThreadIndex]) =
false;
2036 std::string theGroupName,
2038 const std::map<std::string, TableVersion>& groupMemberMap,
2039 const std::map<std::string /*name*/, std::string /*alias*/>&
2041 std::atomic<bool>* theFoundIdentical,
2043 std::mutex* theThreadMutex,
2044 std::shared_ptr<std::atomic<bool>> theThreadDone) {
2063 threadDone[foundThreadIndex])
2073 foundThreadIndex = -1;
2074 for(
int i = 0; i < numOfThreads; ++i)
2075 if(!*(threadDone[i]))
2077 foundThreadIndex = i;
2080 if(foundThreadIndex != -1)
2082 __GEN_COUTT__ <<
"Waiting for thread to finish... " << foundThreadIndex
2086 }
while(foundThreadIndex != -1);
2090 __GEN_COUT__ <<
"Found exact match with key: " << identicalKey << __E__;
2091 return identicalKey;
2108 return &groupMetadataTable_;
2112 std::lock_guard<std::mutex> lock(metaDataTableMutex_);
2115 while(groupMetadataTable_.getView().getNumberOfRows())
2116 groupMetadataTable_.getViewP()->deleteRow(0);
2121 theInterface_->fill(&groupMetadataTable_, fillVersion);
2123 catch(
const std::runtime_error& e)
2125 __GEN_COUT_WARN__ <<
"Failed to load " << groupMetadataTable_.getTableName()
2126 <<
"-v" << fillVersion <<
". Metadata error: " << e.what()
2131 __GEN_COUT_WARN__ <<
"Failed to load " << groupMetadataTable_.getTableName()
2132 <<
"-v" << fillVersion <<
". Ignoring unknown metadata error. "
2137 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
2139 groupMetadataTable_.print();
2140 __GEN_COUT_ERR__ <<
"Ignoring that groupMetadataTable_ v" << fillVersion
2142 "number of rows!' Must "
2143 "be 1. Going with anonymous defaults."
2147 while(groupMetadataTable_.getViewP()->getNumberOfRows() > 1)
2148 groupMetadataTable_.getViewP()->deleteRow(0);
2149 if(groupMetadataTable_.getViewP()->getNumberOfRows() == 0)
2150 groupMetadataTable_.getViewP()->addRow();
2153 return &groupMetadataTable_;
2164 const std::string& groupName,
2165 std::map<std::string, TableVersion>& groupMembers,
2166 const std::string& groupComment,
2167 std::map<std::string /*table*/, std::string /*alias*/>* groupAliases)
2175 if(groupMembers.size() == 0)
2177 __SS__ <<
"Empty group member list. Can not create a group without members!"
2182 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds() << __E__;
2187 for(
auto& memberPair : groupMembers)
2190 if(allCfgInfo.find(memberPair.first) == allCfgInfo.end())
2192 __GEN_COUT_ERR__ <<
"Group member \"" << memberPair.first
2193 <<
"\" not found in database!";
2195 if(groupMetadataTable_.getTableName() == memberPair.first)
2198 <<
"Looks like this is the groupMetadataTable_ '"
2199 << TableBase::GROUP_METADATA_TABLE_NAME
2200 <<
".' Note that this table is added to the member map when groups "
2202 <<
"It should not be part of member map when calling this function."
2204 __GEN_COUT__ <<
"Attempting to recover." << __E__;
2205 groupMembers.erase(groupMembers.find(memberPair.first));
2209 __SS__ << (
"Group member not found!") << __E__;
2214 if(allCfgInfo[memberPair.first].versions_.find(memberPair.second) ==
2215 allCfgInfo[memberPair.first].versions_.end())
2217 __SS__ <<
"Group member \"" << memberPair.first <<
"\" version \""
2218 << memberPair.second <<
"\" not found in database!";
2223 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds() << __E__;
2228 for(
auto& aliasPair : *groupAliases)
2231 if(groupMembers.find(aliasPair.first) == groupMembers.end())
2233 __GEN_COUT_ERR__ <<
"Group member \"" << aliasPair.first
2234 <<
"\" not found in group member map!";
2236 __SS__ << (
"Alias table not found in member list!") << __E__;
2244 __GEN_COUT__ <<
"New Key for group: " << groupName <<
" found as " << newKey << __E__;
2245 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds() << __E__;
2247 time_t groupCreationTime = time(0);
2250 std::map<std::string ,
TableVersion > groupMembersWithoutMeta =
2257 std::string groupAliasesString =
"";
2260 *groupAliases,
"," ,
":" );
2261 __GEN_COUT__ <<
"Metadata: " << username_ <<
" " << groupCreationTime <<
" "
2262 << groupComment <<
" " << groupAliasesString <<
" " << groupType
2267 while(groupMetadataTable_.getViewP()->getNumberOfRows() > 1)
2268 groupMetadataTable_.getViewP()->deleteRow(0);
2269 if(groupMetadataTable_.getViewP()->getNumberOfRows() == 0)
2270 groupMetadataTable_.getViewP()->addRow();
2273 groupMetadataTable_.getViewP()->setValue(
2274 groupAliasesString, 0, ConfigurationManager::METADATA_COL_ALIASES);
2275 groupMetadataTable_.getViewP()->setValue(
2276 groupComment, 0, ConfigurationManager::METADATA_COL_COMMENT);
2277 groupMetadataTable_.getViewP()->setValue(
2278 username_, 0, ConfigurationManager::METADATA_COL_AUTHOR);
2279 groupMetadataTable_.getViewP()->setValue(
2280 groupCreationTime, 0, ConfigurationManager::METADATA_COL_TIMESTAMP);
2284 std::stringstream ss;
2285 groupMetadataTable_.print(ss);
2286 __COUT_MULTI__(2, ss.str());
2293 theInterface_->findLatestVersion(&groupMetadataTable_));
2294 groupMetadataTable_.getViewP()->setVersion(newVersion);
2296 uint16_t retries = 0;
2301 theInterface_->saveActiveVersion(&groupMetadataTable_);
2303 catch(
const std::runtime_error& e)
2305 __GEN_COUT__ <<
"Caught runtime_error exception during table save."
2307 if(std::string(e.what()).find(
"there was a collision") !=
2311 <<
"There was a collision saving the new table "
2312 << groupMetadataTable_ <<
"(" << newVersion
2313 <<
"), trying incremented table version... retries="
2314 << retries << __E__;
2319 groupMetadataTable_.getViewP()->setVersion(newVersion);
2320 __GEN_COUT__ <<
"New version for table: " << groupMetadataTable_
2321 <<
" found as " << newVersion << __E__;
2328 __GEN_COUT__ <<
"Created table: " << groupMetadataTable_ <<
"-v"
2329 << newVersion << __E__;
2334 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds()
2338 groupMembers[groupMetadataTable_.getTableName()] =
2339 groupMetadataTable_.getViewVersion();
2343 uint16_t retries = 0;
2346 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds()
2351 theInterface_->saveTableGroup(
2355 catch(
const std::runtime_error& e)
2357 __GEN_COUT__ <<
"Caught runtime_error exception during group save."
2359 if(std::string(e.what()).find(
"there was a collision") !=
2363 <<
"There was a collision saving the new group " << groupName
2365 <<
"), trying incremented group key... retries=" << retries
2370 __GEN_COUT__ <<
"New Key for group: " << groupName <<
" found as "
2378 __GEN_COUT__ <<
"Created table group: " << groupName <<
"(" << newKey
2384 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds()
2387 catch(std::runtime_error& e)
2389 __GEN_COUT_ERR__ <<
"Failed to create table group: " << groupName <<
"(" << newKey
2391 __GEN_COUT_ERR__ <<
"\n\n" << e.what() << __E__;
2396 __GEN_COUT_ERR__ <<
"Failed to create table group: " << groupName <<
":" << newKey
2401 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds() << __E__;
2404 allGroupInfo_[groupName].keys_.emplace(newKey);
2406 allGroupInfo_.at(groupName).latestKey_ = newKey;
2407 allGroupInfo_.at(groupName).latestKeyGroupAuthor_ = username_;
2408 allGroupInfo_.at(groupName).latestKeyGroupComment_ = groupComment;
2409 allGroupInfo_.at(groupName).latestKeyGroupCreationTime_ = groupCreationTime;
2410 allGroupInfo_.at(groupName).latestKeyGroupTypeString_ = groupType;
2411 allGroupInfo_.at(groupName).latestKeyMemberMap_ = groupMembersWithoutMeta;
2413 __GEN_COUT__ <<
"Saved " << groupName <<
"(" << newKey <<
") of type " << groupType
2416 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds() << __E__;
2428 __GEN_COUT_INFO__ <<
"Creating new backbone from temporary version "
2429 << temporaryVersion << __E__;
2434 auto backboneMemberNames = ConfigurationManager::getBackboneMemberNames();
2435 for(
auto& name : backboneMemberNames)
2438 __GEN_COUT__ <<
"New version for backbone member (" << name
2439 <<
"): " << retNewVersion << __E__;
2440 if(retNewVersion > newVersion)
2441 newVersion = retNewVersion;
2444 __GEN_COUT__ <<
"Common new backbone version found as " << newVersion << __E__;
2447 for(
auto& name : backboneMemberNames)
2451 getTableByName(name), temporaryVersion, newVersion);
2452 if(retNewVersion != newVersion)
2454 __SS__ <<
"Failure! New view requested was " << newVersion
2455 <<
". Mismatched new view created: " << retNewVersion << __E__;
2456 __GEN_COUT_ERR__ << ss.str();
2470 const std::string& tableName,
2475 bool ignoreDuplicates ,
2476 bool lookForEquivalent ,
2477 bool* foundEquivalent )
2479 bool needToEraseTemporarySource =
2483 *foundEquivalent =
false;
2486 if(!ignoreDuplicates)
2488 __GEN_COUT__ <<
"Checking for duplicate '" << tableName <<
"' tables..." << __E__;
2496 const std::map<std::string, TableInfo>& allTableInfo =
2499 auto versionReverseIterator =
2500 allTableInfo.at(tableName).versions_.rbegin();
2501 __GEN_COUT__ <<
"Filling up '" << tableName <<
"' cache from "
2505 versionReverseIterator != allTableInfo.at(tableName).versions_.rend();
2506 ++versionReverseIterator)
2508 __GEN_COUTT__ <<
"'" << tableName <<
"' versions in reverse order "
2509 << *versionReverseIterator << __E__;
2512 getVersionedTableByName(tableName,
2513 *versionReverseIterator);
2515 catch(
const std::runtime_error& e)
2518 __COUTT__ <<
"'" << tableName
2519 <<
"' version failed to load: " << *versionReverseIterator
2525 __GEN_COUT__ <<
"Checking '" << tableName <<
"' for duplicate..." << __E__;
2528 temporaryModifiedVersion,
2534 if(lookForEquivalent && !duplicateVersion.
isInvalid())
2537 __GEN_COUT__ <<
"Equivalent '" << tableName <<
"' table found in version v"
2538 << duplicateVersion << __E__;
2543 __GEN_COUT__ <<
"Need persistent. Duplicate '" << tableName
2544 <<
"' version was temporary. "
2545 "Abandoning duplicate."
2557 if(needToEraseTemporarySource)
2561 *foundEquivalent =
true;
2563 __GEN_COUT__ <<
"\t\t Equivalent '" << tableName
2564 <<
"' assigned version: " << duplicateVersion << __E__;
2566 return duplicateVersion;
2572 __SS__ <<
"This version of table '" << tableName
2573 <<
"' is identical to another version currently cached v"
2574 << duplicateVersion <<
". No reason to save a duplicate." << __E__;
2575 __GEN_COUT_ERR__ <<
"\n" << ss.str();
2578 table->eraseView(temporaryModifiedVersion);
2582 __GEN_COUT__ <<
"Check for duplicate '" << tableName <<
"' tables complete."
2587 __GEN_COUT__ <<
"\t\t**************************** Save as temporary '"
2588 << tableName <<
"' table version" << __E__;
2590 __GEN_COUT__ <<
"\t\t**************************** Save as new '" << tableName
2591 <<
"' table version" << __E__;
2594 saveNewTable(tableName, temporaryModifiedVersion, makeTemporary);
2596 __GEN_COUTTV__(table->getView().getComment());
2598 if(needToEraseTemporarySource)
2601 __GEN_COUT__ <<
"\t\t '" << tableName
2602 <<
"' new assigned version: " << newAssignedVersion << __E__;
2603 return newAssignedVersion;
2607 GroupEditStruct::GroupEditStruct(
const ConfigurationManager::GroupType& groupType,
2609 : groupType_(groupType)
2610 , originalGroupName_(cfgMgr->getActiveGroupName(groupType))
2611 , originalGroupKey_(cfgMgr->getActiveGroupKey(groupType))
2613 , mfSubject_(cfgMgr->getUsername())
2615 if(originalGroupName_ ==
"" || originalGroupKey_.isInvalid())
2617 __SS__ <<
"Error! No active group found for type '"
2619 <<
".' There must be an active group to edit the group." << __E__ << __E__
2624 __GEN_COUT__ <<
"Extracting Group-Edit Struct for type "
2629 const std::set<std::string>& memberNames =
2630 groupType == ConfigurationManager::GroupType::CONTEXT_TYPE
2631 ? cfgMgr->getActiveContextMemberNames()
2632 : (groupType == ConfigurationManager::GroupType::BACKBONE_TYPE
2633 ? ConfigurationManager::getBackboneMemberNames()
2636 : cfgMgr->getConfigurationMemberNames()));
2638 for(
auto& memberName : memberNames)
2641 groupMembers_.emplace(
2642 std::make_pair(memberName, activeTables.at(memberName)));
2643 groupTables_.emplace(std::make_pair(
2650 __SS__ <<
"Error! Could not find group member table '" << memberName
2651 <<
"' for group type '"
2653 <<
".' All group members must be present to create the group editing "
2662 GroupEditStruct::~GroupEditStruct()
2664 __GEN_COUT__ <<
"GroupEditStruct from editing '" << originalGroupName_ <<
"("
2665 << originalGroupKey_ <<
")' Destructing..." << __E__;
2667 __GEN_COUT__ <<
"GroupEditStruct from editing '" << originalGroupName_ <<
"("
2668 << originalGroupKey_ <<
")' Desctructed." << __E__;
2676 auto it = groupTables_.find(tableName);
2677 if(it == groupTables_.end())
2679 if(groupType_ == ConfigurationManager::GroupType::CONFIGURATION_TYPE &&
2682 __GEN_COUT__ <<
"Table '" << tableName
2683 <<
"' not found in configuration table members from editing '"
2684 << originalGroupName_ <<
"(" << originalGroupKey_ <<
")..."
2685 <<
" Attempting to add it!" << __E__;
2688 auto newIt = groupTables_.emplace(std::make_pair(
2693 newIt.first->second.modified_ =
2695 groupMembers_.emplace(
2696 std::make_pair(tableName, newIt.first->second.temporaryVersion_));
2697 return newIt.first->second;
2699 __GEN_COUT_ERR__ <<
"Failed to emplace new table..." << __E__;
2702 __SS__ <<
"Table '" << tableName <<
"' not found in table members from editing '"
2703 << originalGroupName_ <<
"(" << originalGroupKey_ <<
")!'" << __E__;
2706 it->second.modified_ =
2712 void GroupEditStruct::dropChanges()
2714 __GEN_COUT__ <<
"Dropping unsaved changes from editing '" << originalGroupName_ <<
"("
2715 << originalGroupKey_ <<
")'..." << __E__;
2720 for(
auto& groupTable : groupTables_)
2721 if(groupTable.second
2722 .createdTemporaryVersion_)
2726 groupTable.second.temporaryVersion_);
2727 groupTable.second.createdTemporaryVersion_ =
false;
2728 groupTable.second.modified_ =
false;
2731 __GEN_COUT__ <<
"Unsaved changes dropped from editing '" << originalGroupName_ <<
"("
2732 << originalGroupKey_ <<
").'" << __E__;
2736 void GroupEditStruct::saveChanges(
const std::string& groupNameToSave,
2738 bool* foundEquivalentGroupKey ,
2739 bool activateNewGroup ,
2740 bool updateGroupAliases ,
2741 bool updateTableAliases ,
2743 bool* foundEquivalentBackboneKey ,
2744 std::string* accumulatedWarnings )
2746 __GEN_COUT__ <<
"Saving changes..." << __E__;
2751 if(foundEquivalentBackboneKey)
2752 *foundEquivalentBackboneKey =
false;
2756 bool anyTableNew =
false;
2757 for(
auto& groupTable : groupTables_)
2759 if(!groupTable.second.modified_)
2762 __GEN_COUT__ <<
"Original version is " << groupTable.second.tableName_ <<
"-v"
2763 << groupTable.second.originalVersion_ << __E__;
2766 groupTable.second.tableName_,
2767 groupTable.second.originalVersion_,
2769 groupTable.second.table_,
2770 groupTable.second.temporaryVersion_,
2773 __GEN_COUT__ <<
"Temporary target version is " << groupTable.second.tableName_
2774 <<
"-v" << groupMembers_.at(groupTable.first) <<
"-v"
2775 << groupTable.second.temporaryVersion_ << __E__;
2778 groupTable.second.tableName_,
2779 groupTable.second.originalVersion_,
2781 groupTable.second.table_,
2782 groupTable.second.temporaryVersion_,
2786 if(groupTable.second.originalVersion_ != groupMembers_.at(groupTable.first))
2789 __GEN_COUT__ <<
"Final NEW target version is " << groupTable.second.tableName_
2790 <<
"-v" << groupMembers_.at(groupTable.first) << __E__;
2793 __GEN_COUT__ <<
"Final target version is " << groupTable.second.tableName_
2794 <<
"-v" << groupMembers_.at(groupTable.first) << __E__;
2796 groupTable.second.modified_ =
false;
2797 groupTable.second.createdTemporaryVersion_ =
false;
2800 for(
auto& table : groupMembers_)
2802 __GEN_COUT__ << table.first <<
" v" << table.second << __E__;
2807 __GEN_COUT__ <<
"Checking for duplicate groups..." << __E__;
2808 newGroupKey = cfgMgr->
findTableGroup(groupNameToSave, groupMembers_);
2811 __GEN_COUT__ <<
"New table found, so no need to check duplicate groups." << __E__;
2815 __GEN_COUT__ <<
"Found equivalent group key (" << newGroupKey <<
") for "
2816 << groupNameToSave <<
"." << __E__;
2817 if(foundEquivalentGroupKey)
2818 *foundEquivalentGroupKey =
true;
2823 __GEN_COUT__ <<
"Saved new Context group key (" << newGroupKey <<
") for "
2824 << groupNameToSave <<
"." << __E__;
2827 bool groupAliasChange =
false;
2828 bool tableAliasChange =
false;
2831 ConfigurationManager::GroupType::
2834 GroupEditStruct backboneGroupEdit(ConfigurationManager::GroupType::BACKBONE_TYPE,
2837 if(groupType_ != ConfigurationManager::GroupType::BACKBONE_TYPE &&
2843 TableEditStruct& groupAliasTable = backboneGroupEdit.getTableEditStruct(
2844 ConfigurationManager::GROUP_ALIASES_TABLE_NAME,
true );
2845 TableView* tableView = groupAliasTable.tableView_;
2848 unsigned int row = 0;
2850 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
2851 cfgMgr->
getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME)
2853 std::string groupName, groupKey;
2854 for(
auto& aliasNodePair : aliasNodePairs)
2856 groupName = aliasNodePair.second.getNode(
"GroupName").getValueAsString();
2857 groupKey = aliasNodePair.second.getNode(
"GroupKey").getValueAsString();
2859 __GEN_COUT__ <<
"Group Alias: " << aliasNodePair.first <<
" => "
2860 << groupName <<
"(" << groupKey <<
"); row=" << row << __E__;
2862 if(groupName == originalGroupName_ &&
2865 __GEN_COUT__ <<
"Found alias! Changing group key from ("
2866 << originalGroupKey_ <<
") to (" << newGroupKey <<
")"
2869 groupAliasChange =
true;
2878 if(groupAliasChange)
2880 std::stringstream ss;
2881 tableView->print(ss);
2882 __GEN_COUT__ << ss.str();
2886 if(groupType_ != ConfigurationManager::GroupType::BACKBONE_TYPE &&
2892 .getTableEditStruct(ConfigurationManager::VERSION_ALIASES_TABLE_NAME,
2896 for(
auto& groupTable : groupTables_)
2898 if(groupTable.second.originalVersion_ ==
2899 groupMembers_.at(groupTable.second.tableName_))
2902 __GEN_COUT__ <<
"Checking alias... original version is "
2903 << groupTable.second.tableName_ <<
"-v"
2904 << groupTable.second.originalVersion_
2905 <<
" and new version is v"
2906 << groupMembers_.at(groupTable.second.tableName_) << __E__;
2909 unsigned int row = 0;
2911 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
2912 cfgMgr->
getNode(ConfigurationManager::VERSION_ALIASES_TABLE_NAME)
2914 std::string tableName, tableVersion;
2915 for(
auto& aliasNodePair : aliasNodePairs)
2918 aliasNodePair.second.getNode(
"TableName").getValueAsString();
2920 aliasNodePair.second.getNode(
"Version").getValueAsString();
2922 __GEN_COUT__ <<
"Table Alias: " << aliasNodePair.first <<
" => "
2923 << tableName <<
"-v" << tableVersion <<
"" << __E__;
2925 if(tableName == groupTable.second.tableName_ &&
2926 TableVersion(tableVersion) == groupTable.second.originalVersion_)
2928 __GEN_COUT__ <<
"Found alias! Changing icon table version alias."
2931 tableAliasChange =
true;
2934 groupMembers_.at(groupTable.second.tableName_).toString(),
2936 tableView->
findCol(
"Version"));
2943 if(tableAliasChange)
2945 std::stringstream ss;
2946 tableView->print(ss);
2947 __GEN_COUT__ << ss.str();
2953 if(groupAliasChange || tableAliasChange)
2955 for(
auto& table : backboneGroupEdit.groupMembers_)
2957 __GEN_COUT__ << table.first <<
" v" << table.second << __E__;
2959 backboneGroupEdit.saveChanges(
2960 backboneGroupEdit.originalGroupName_,
2961 localNewBackboneKey,
2962 foundEquivalentBackboneKey ? foundEquivalentBackboneKey :
nullptr);
2965 *newBackboneKey = localNewBackboneKey;
2972 <<
"Restoring active table groups, before activating new groups..."
2975 std::string localAccumulatedWarnings;
2979 ConfigurationManager::LoadGroupType::
2981 &localAccumulatedWarnings);
2987 backboneGroupEdit.originalGroupName_,
2988 localNewBackboneKey,
2989 accumulatedWarnings ? accumulatedWarnings :
nullptr);
2998 <<
"Restoring active table groups, before activating new groups..."
3001 std::string localAccumulatedWarnings;
3005 ConfigurationManager::LoadGroupType::
3007 &localAccumulatedWarnings);
3011 if(activateNewGroup)
3014 accumulatedWarnings ? accumulatedWarnings :
nullptr);
3016 __GEN_COUT__ <<
"Changes saved." << __E__;
3025 __GEN_COUTV__(runTimeSeconds());
3027 std::string accumulatedWarningsStr;
3028 std::string* accumulatedWarnings = &accumulatedWarningsStr;
3035 std::string documentNameToLoad =
"XDAQApplicationTable";
3039 std::set<std::string> groupsContainingTable =
3040 theInterface_->findGroupsWithTable(documentNameToLoad,
3041 documentVersionToLoad);
3042 __GEN_COUT__ <<
"Groups containing " << documentNameToLoad <<
"-v"
3043 << documentVersionToLoad
3044 <<
" count: " << groupsContainingTable.size() << __E__;
3045 for(
const auto& group : groupsContainingTable)
3047 __GEN_COUT__ <<
"\t" << group << __E__;
3051 std::string debugGroupName =
"Mu2eHWEmulatorContext";
3056 theInterface_->findLatestGroupKey(debugGroupName);
3057 __GEN_COUTV__(latestGroupKey);
3059 __GEN_COUTV__(runTimeSeconds());
3066 std::set<std::string > tableGroups =
3067 theInterface_->getAllTableGroupNames();
3068 __GEN_COUT__ <<
"Number of Groups: " << tableGroups.size() << __E__;
3070 __GEN_COUTV__(runTimeSeconds());
3075 for(
const auto& fullName : tableGroups)
3078 allGroupInfo_[name].keys_.emplace(key);
3080 if(name == debugGroupName)
3085 __GEN_COUTV__(runTimeSeconds());
3087 std::set<std::string > tableNames = theInterface_->getAllTableNames();
3088 __GEN_COUT__ <<
"Number of Tables: " << tableNames.size() << __E__;
3090 __GEN_COUTV__(runTimeSeconds());
3092 for(
const auto& fullName : tableNames)
3094 if(fullName.find(debugGroupName) != std::string::npos)
3096 __GEN_COUTV__(fullName);
3099 __GEN_COUTV__(runTimeSeconds());
3101 TableGroupKey latestGroupKey = theInterface_->findLatestGroupKey(debugGroupName);
3102 __GEN_COUTV__(latestGroupKey);
3104 __GEN_COUTV__(runTimeSeconds());
3109 TableBase::GROUP_CACHE_PREPEND + debugGroupName);
3111 theInterface_->findLatestVersion(&localGroupMemberCacheSaver);
3112 __GEN_COUTV__(lastestGroupCacheKey);
3114 __GEN_COUTV__(runTimeSeconds());
3120 __GEN_COUT__ <<
"Testing group save of pre-existing " << debugGroupName <<
"("
3121 << groupKey <<
")" << __E__;
3122 std::map<std::string, TableVersion> groupMembers;
3124 theInterface_->saveTableGroup(
3130 __GEN_COUT__ <<
"Exception during group save." << __E__;
3132 __GEN_COUTV__(runTimeSeconds());
3137 std::string debugGroupName =
"testGroupSave";
3139 __GEN_COUT__ <<
"Testing group save of non-existing " << debugGroupName <<
"("
3140 << groupKey <<
")" << __E__;
3141 std::map<std::string, TableVersion> groupMembers;
3143 groupMembers[
"MessageFacilityTable"] =
TableVersion(7);
3144 theInterface_->saveTableGroup(
3150 __GEN_COUT__ <<
"Exception during new group save." << __E__;
3152 __GEN_COUTV__(runTimeSeconds());
3156 std::string documentNameToLoad =
"XDAQApplicationTable";
3159 __GEN_COUT__ <<
"Testing table save of pre-existing " << documentNameToLoad
3164 documentNameToLoad);
3165 localDocLoader.changeVersionAndActivateView(
3167 theInterface_->fill(&localDocLoader, documentVersionToLoad);
3169 localDocLoader.
print(ss);
3170 __GEN_COUTV__(ss.str());
3172 __GEN_COUTV__(runTimeSeconds());
3176 std::string documentNameToSave = documentNameToLoad;
3179 documentNameToSave);
3180 localDocSaver.changeVersionAndActivateView(
3183 std::string json =
"{ }";
3186 __COUTT__ <<
"Saving JSON string: "
3189 __COUTT__ <<
"Saving JSON doc as "
3190 << localDocSaver.getView().getTableName() <<
"("
3191 << localDocSaver.getView().getVersion().
toString() <<
")"
3195 theInterface_->saveActiveVersion(&localDocSaver,
false );
3199 __GEN_COUT__ <<
"Exception during table save." << __E__;
3201 __GEN_COUTV__(runTimeSeconds());
3205 documentNameToLoad);
3206 localDocLoader.changeVersionAndActivateView(
3208 theInterface_->fill(&localDocLoader, documentVersionToLoad);
3210 localDocLoader.
print(ss);
3211 __GEN_COUTV__(ss.str());
3213 __GEN_COUTV__(runTimeSeconds());
3215 __GEN_COUTV__(runTimeSeconds());
3219 std::string documentNameToLoad =
"MessageFacilityTable";
3222 documentNameToLoad);
3224 __GEN_COUT__ <<
"Testing table save of non-existing " << documentNameToLoad
3228 localDocLoader.changeVersionAndActivateView(
3230 theInterface_->fill(&localDocLoader, documentVersionToLoad);
3232 localDocLoader.
print(ss);
3233 __GEN_COUTV__(ss.str());
3234 __GEN_COUTV__(runTimeSeconds());
3236 __GEN_COUTV__(runTimeSeconds());
3243 theInterface_->findLatestVersion(&localDocLoader));
3244 localDocLoader.getViewP()->
setVersion(newVersion);
3246 __GEN_COUTT__ <<
"Saving new table as "
3247 << localDocLoader.getView().getTableName() <<
"("
3248 << localDocLoader.getView().getVersion().
toString() <<
")"
3252 "10.226.9.17", 0, 4);
3255 localDocLoader.
print(ss);
3256 __GEN_COUTV__(ss.str());
3259 theInterface_->saveActiveVersion(&localDocLoader,
false );
3263 __GEN_COUT__ <<
"Exception during new table save." << __E__;
3265 __GEN_COUTV__(runTimeSeconds());
3267 __GEN_COUTV__(runTimeSeconds());
3271 for(
auto& groupInfo : allGroupInfo_)
3275 groupInfo.second.latestKey_ = groupInfo.second.getLastKey();
3277 groupInfo.second.latestKey_,
3279 &groupInfo.second.latestKeyMemberMap_ ,
3282 &groupInfo.second.latestKeyGroupComment_,
3283 &groupInfo.second.latestKeyGroupAuthor_,
3284 &groupInfo.second.latestKeyGroupCreationTime_,
3286 &groupInfo.second.latestKeyGroupTypeString_);
3288 catch(
const std::runtime_error& e)
3291 <<
"Error occurred loading latest group info into cache for '"
3292 << groupInfo.first <<
"(" << groupInfo.second.latestKey_ <<
")': \n"
3293 << e.what() << __E__;
3295 groupInfo.second.latestKey_ = TableGroupKey::INVALID;
3296 groupInfo.second.latestKeyGroupComment_ =
3297 ConfigurationManager::UNKNOWN_INFO;
3298 groupInfo.second.latestKeyGroupAuthor_ =
3299 ConfigurationManager::UNKNOWN_INFO;
3300 groupInfo.second.latestKeyGroupCreationTime_ =
3301 ConfigurationManager::UNKNOWN_TIME;
3302 groupInfo.second.latestKeyGroupTypeString_ =
3303 ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
3304 groupInfo.second.latestKeyMemberMap_ = {};
3309 <<
"Error occurred loading latest group info into cache for '"
3310 << groupInfo.first <<
"(" << groupInfo.second.latestKey_ <<
")'..."
3313 groupInfo.second.latestKey_ = TableGroupKey::INVALID;
3314 groupInfo.second.latestKeyGroupComment_ =
3315 ConfigurationManager::UNKNOWN_INFO;
3316 groupInfo.second.latestKeyGroupAuthor_ =
3317 ConfigurationManager::UNKNOWN_INFO;
3318 groupInfo.second.latestKeyGroupCreationTime_ =
3319 ConfigurationManager::UNKNOWN_TIME;
3320 groupInfo.second.latestKeyGroupTypeString_ =
3321 ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
3322 groupInfo.second.latestKeyMemberMap_ = {};
3325 __GEN_COUTV__(runTimeSeconds());
3327 catch(
const std::runtime_error& e)
3329 __SS__ <<
"A fatal error occurred reading the info for all table groups. Error: "
3330 << e.what() << __E__;
3331 __GEN_COUT_ERR__ <<
"\n" << ss.str();
3332 if(accumulatedWarnings)
3333 *accumulatedWarnings += ss.str();
3339 __SS__ <<
"An unknown fatal error occurred reading the info for all table groups."
3341 __GEN_COUT_ERR__ <<
"\n" << ss.str();
3342 if(accumulatedWarnings)
3343 *accumulatedWarnings += ss.str();
3348 __GEN_COUT__ <<
"testXDAQContext() end runTimeSeconds()=" << runTimeSeconds()
3354 __GEN_COUT__ <<
"Loading table..." << __E__;
3360 __GEN_COUT__ << __E__;
3362 __GEN_COUT__ <<
"Value: " << v << __E__;
3363 __GEN_COUT__ <<
"Value index: " << t.
getValue<
int>() << __E__;
3369 __GEN_COUT__ <<
"Failed to load table..." << __E__;
TableVersion saveNewVersion(TableBase *table, TableVersion temporaryVersion, TableVersion newVersion=TableVersion())
TableVersion saveNewTable(const std::string &tableName, TableVersion temporaryVersion=TableVersion(), bool makeTemporary=false)
modifiers of generic TableBase
TableGroupKey findTableGroup(const std::string &groupName, const std::map< std::string, TableVersion > &groupMembers, const std::map< std::string, std::string > &groupAliases=std::map< std::string, std::string >())
void testXDAQContext(void)
for debugging
TableVersion saveNewBackbone(TableVersion temporaryVersion=TableVersion())
const GroupInfo & getGroupInfo(const std::string &groupName, bool attemptToReloadKeys=false)
public group cache handling
void clearAllCachedVersions(void)
const std::map< std::string, TableInfo > & getAllTableInfo(bool refresh=false, std::string *accumulatedWarnings=0, const std::string &errorFilterName="", bool getGroupKeys=false, bool getGroupInfo=false, bool initializeActiveGroups=false)
void loadTableGroup(const std::string &tableGroupName, const TableGroupKey &tableGroupKey, bool doActivate=false, std::map< std::string, TableVersion > *groupMembers=0, ProgressBar *progressBar=0, std::string *accumulateWarnings=0, std::string *groupComment=0, std::string *groupAuthor=0, std::string *groupCreateTime=0, bool doNotLoadMember=false, std::string *groupTypeString=0, std::map< std::string, std::string > *groupAliases=0, ConfigurationManager::LoadGroupType groupTypeToLoad=ConfigurationManager::LoadGroupType::ALL_TYPES, bool ignoreVersionTracking=false)
TableVersion copyViewToCurrentColumns(const std::string &tableName, TableVersion sourceVersion)
copyViewToCurrentColumns
TableGroupKey saveNewTableGroup(const std::string &groupName, std::map< std::string, TableVersion > &groupMembers, const std::string &groupComment=TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT, std::map< std::string, std::string > *groupAliases=0)
modifiers of a table group based on alias, e.g. "Physics"
void activateTableGroup(const std::string &tableGroupName, TableGroupKey tableGroupKey, std::string *accumulatedTreeErrors=0, std::string *groupTypeString=0)
modifiers of table groups
TableBase * getMetadataTable(TableVersion fillVersion=TableVersion())
created for use in otsdaq_flatten_system_aliases and otsdaq_export_system_aliases,...
TableVersion saveModifiedVersion(const std::string &tableName, TableVersion originalVersion, bool makeTemporary, TableBase *config, TableVersion temporaryModifiedVersion, bool ignoreDuplicates=false, bool lookForEquivalent=false, bool *foundEquivalent=nullptr)
TableVersion createTemporaryBackboneView(TableVersion sourceViewVersion=TableVersion())
-1, from MockUp, else from valid backbone view version
void clearCachedVersions(const std::string &tableName)
std::map< std::string, std::map< std::string, TableVersion > > getVersionAliases(void) const
void eraseTemporaryVersion(const std::string &tableName, TableVersion targetVersion=TableVersion())
void preloadVersionCreationTimes(void)
parallel load of all version creation times into the process-wide cache
static void compareTableGroupThread(ConfigurationManagerRW *cfgMgr, std::string groupName, ots::TableGroupKey groupKeyToCompare, const std::map< std::string, TableVersion > &groupMemberMap, const std::map< std::string, std::string > &memberTableAliases, std::atomic< bool > *theFoundIdentical, ots::TableGroupKey *theIdenticalKey, std::mutex *theThreadMutex, std::shared_ptr< std::atomic< bool >> theThreadDone)
static void loadTableGroupThread(ConfigurationManagerRW *cfgMgr, std::string groupName, ots::TableGroupKey groupKey, std::shared_ptr< ots::GroupInfo > theGroupInfo, std::shared_ptr< std::atomic< bool >> theThreadDone)
loadTableGroupThread()
time_t getVersionCreationTime(const std::string &tableName, TableVersion version)
static void loadTableInfoThread(ConfigurationManagerRW *cfgMgr, std::string tableName, TableBase *existingTable, std::shared_ptr< ots::TableInfo > tableInfo, std::shared_ptr< std::atomic< bool >> threadDone)
loadTableInfoThread()
std::map< std::string, std::map< std::string, TableVersion > > getVersionAliases(void) const
static const unsigned int PROCESSOR_COUNT
Static members.
static const std::string & convertGroupTypeToName(const ConfigurationManager::GroupType &groupTypeId)
void restoreActiveTableGroups(bool throwErrors=false, const std::string &pathToActiveGroupsFile="", ConfigurationManager::LoadGroupType onlyLoadIfBackboneOrContext=ConfigurationManager::LoadGroupType::ALL_TYPES, std::string *accumulatedWarnings=0)
std::map< std::string, TableVersion > getActiveVersions(void) const
getActiveVersions
ConfigurationTree getNode(const std::string &nodeString, bool doNotThrowOnBrokenUIDLinks=false) const
"root/parent/parent/"
void loadTableGroup(const std::string &tableGroupName, const TableGroupKey &tableGroupKey, bool doActivate=false, std::map< std::string, TableVersion > *groupMembers=0, ProgressBar *progressBar=0, std::string *accumulateWarnings=0, std::string *groupComment=0, std::string *groupAuthor=0, std::string *groupCreateTime=0, bool doNotLoadMember=false, std::string *groupTypeString=0, std::map< std::string, std::string > *groupAliases=0, ConfigurationManager::LoadGroupType groupTypeToLoad=ConfigurationManager::LoadGroupType::ALL_TYPES, bool ignoreVersionTracking=false, std::map< std::string, TableVersion > mergeInTables={}, std::map< std::string, TableVersion > overrideTables={})
void init(std::string *accumulatedErrors=0, bool initForWriteAccess=false, std::string *accumulatedWarnings=0)
static const std::string & getTypeNameOfGroup(const std::map< std::string, TableVersion > &memberMap)
void destroyTableGroup(const std::string &theGroup="", bool onlyDeactivate=false)
static const std::string ACTIVE_GROUPS_FILENAME
added env check for otsdaq_flatten_active_to_version to function
const TableBase * getTableByName(const std::string &configurationName) const
friend class ConfigurationManagerRW
void getValue(T &value) const
std::vector< std::pair< std::string, ConfigurationTree > > getChildren(std::map< std::string, std::string > filterMap=std::map< std::string, std::string >(), bool byPriority=false, bool onlyStatusTrue=false) const
TableVersion createTemporaryView(TableVersion sourceViewVersion=TableVersion(), TableVersion destTemporaryViewVersion=TableVersion::getNextTemporaryVersion())
source of -1, from MockUp, else from valid view version
void trimTemporary(TableVersion targetVersion=TableVersion())
unsigned int getNumberOfStoredViews(void) const
TableVersion checkForDuplicate(TableVersion needleVersion, TableVersion ignoreVersion=TableVersion()) const
TableView * getTemporaryView(TableVersion temporaryVersion)
const unsigned int MAX_VIEWS_IN_CACHE
TableVersion getNextVersion(void) const
TableVersion copyView(const TableView &sourceView, TableVersion destinationVersion, const std::string &author, bool looseColumnMatching=false)
void print(std::ostream &out=std::cout) const
always prints active view
TableVersion getNextTemporaryVersion(void) const
void trimCache(unsigned int trimSize=-1)
std::string toString(void) const
toString
static TableGroupKey getNextKey(const TableGroupKey &key=TableGroupKey())
static void getGroupNameAndKey(const std::string &fullGroupString, std::string &groupName, TableGroupKey &key)
requires fullGroupString created as name + "_v" + key + ""
bool isInvalid(void) const
isInvalid
static std::string getFullGroupString(const std::string &groupName, const TableGroupKey &key, const std::string &preKey="_v", const std::string &postKey="")
std::string toString(void) const
toString
bool isInvalid(void) const
isInvalid
static TableVersion getNextVersion(const TableVersion &version=TableVersion())
bool isScratchVersion(void) const
bool isTemporaryVersion(void) const
static TableVersion getNextTemporaryVersion(const TableVersion &version=TableVersion())
void setValueAsString(const std::string &value, unsigned int row, unsigned int col)
void setVersion(const T &version)
< in included .icc source
const std::string & getCustomStorageData(void) const
Getters.
unsigned int findCol(const std::string &name) const
void setCustomStorageData(const std::string &storageData)
defines used also by OtsConfigurationWizardSupervisor
TableEditStruct & getTableEditStruct(const std::string &tableName, bool markModified=false)
Note: if markModified, and table not found in group, this function will try to add it to group.
static std::string setToString(const std::set< T > &setToReturn, const std::string &delimeter=", ")
setToString ~
static std::string mapToString(const std::map< std::string, T > &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
static std::string stackTrace(void)