1 #include "otsdaq/ConfigurationInterface/ConfigurationManagerRW.h"
8 #define __MF_SUBJECT__ "ConfigurationManagerRW"
10 #define TABLE_INFO_PATH std::string(__ENV__("TABLE_INFO_PATH")) + "/"
11 #define TABLE_INFO_EXT "Info.xml"
13 #define CORE_TABLE_INFO_FILENAME \
14 ((getenv("SERVICE_DATA_PATH") == NULL) \
15 ? (std::string(__ENV__("USER_DATA")) + "/ServiceData") \
16 : (std::string(__ENV__("SERVICE_DATA_PATH")))) + \
17 "/CoreTableInfoNames.dat"
19 std::atomic<bool> ConfigurationManagerRW::firstTimeConstructed_ =
true;
26 __GEN_COUT__ <<
"Instantiating Config Manager with Write Access! (for " << username
27 <<
") time=" << time(0) <<
" runTimeSeconds()=" << runTimeSeconds()
30 theInterface_ = ConfigurationInterface::getInstance(
31 ConfigurationInterface::CONFIGURATION_MODE::
37 if(firstTimeConstructed_)
39 firstTimeConstructed_ =
false;
42 mkdir((ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH).c_str(), 0755);
44 const std::set<std::string>& contextMemberNames = getContextMemberNames();
45 const std::set<std::string>& backboneMemberNames = getBackboneMemberNames();
46 const std::set<std::string>& iterateMemberNames = getIterateMemberNames();
48 FILE* fp = fopen((CORE_TABLE_INFO_FILENAME).c_str(),
"r");
52 std::vector<unsigned int> foundVector;
54 for(
const auto& name : contextMemberNames)
56 foundVector.push_back(
false);
58 while(fgets(line, 100, fp))
62 line[strlen(line) - 1] =
'\0';
63 if(strcmp(line, (
"ContextGroup/" + name).c_str()) == 0)
65 foundVector.back() =
true;
71 for(
const auto& name : backboneMemberNames)
73 foundVector.push_back(
false);
75 while(fgets(line, 100, fp))
79 line[strlen(line) - 1] =
'\0';
80 if(strcmp(line, (
"BackboneGroup/" + name).c_str()) == 0)
82 foundVector.back() =
true;
88 for(
const auto& name : iterateMemberNames)
90 foundVector.push_back(
false);
92 while(fgets(line, 100, fp))
96 line[strlen(line) - 1] =
'\0';
97 if(strcmp(line, (
"IterateGroup/" + name).c_str()) == 0)
99 foundVector.back() =
true;
107 foundVector.push_back(
false);
109 while(fgets(line, 100, fp))
113 line[strlen(line) - 1] =
'\0';
116 ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE)
119 foundVector.back() =
true;
128 fp = fopen((CORE_TABLE_INFO_FILENAME).c_str(),
"a");
132 for(
const auto& name : contextMemberNames)
135 fprintf(fp,
"\nContextGroup/%s", name.c_str());
139 for(
const auto& name : backboneMemberNames)
142 fprintf(fp,
"\nBackboneGroup/%s", name.c_str());
146 for(
const auto& name : iterateMemberNames)
149 fprintf(fp,
"\nIterateGroup/%s", name.c_str());
159 ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE.c_str());
165 __SS__ <<
"Failed to open core table info file for appending: "
166 << CORE_TABLE_INFO_FILENAME << __E__;
172 fp = fopen((CORE_TABLE_INFO_FILENAME).c_str(),
"w");
175 fprintf(fp,
"ARTDAQ/*");
176 fprintf(fp,
"\nConfigCore/*");
177 for(
const auto& name : contextMemberNames)
178 fprintf(fp,
"\nContextGroup/%s", name.c_str());
179 for(
const auto& name : backboneMemberNames)
180 fprintf(fp,
"\nBackboneGroup/%s", name.c_str());
181 for(
const auto& name : iterateMemberNames)
182 fprintf(fp,
"\nIterateGroup/%s", name.c_str());
187 __SS__ <<
"Failed to open core table info file: "
188 << CORE_TABLE_INFO_FILENAME << __E__;
194 __GEN_COUTV__(runTimeSeconds());
206 std::string* accumulatedWarnings ,
207 const std::string& errorFilterName ,
210 bool initializeActiveGroups )
215 return allTableInfo_;
218 allTableInfo_.clear();
225 __GEN_COUT__ <<
"======================================================== "
226 "getAllTableInfo start runTimeSeconds()="
227 << runTimeSeconds() << __E__;
229 __GEN_COUT__ <<
"Refreshing all! Extracting list of tables..." << __E__;
231 struct dirent* entry;
232 std::string path = TABLE_INFO_PATH;
233 char fileExt[] = TABLE_INFO_EXT;
234 const unsigned char MIN_TABLE_NAME_SZ = 3;
237 __GEN_COUT__ <<
" PROCESSOR_COUNT " <<
PROCESSOR_COUNT <<
" ==> " << numOfThreads
238 <<
" threads." << __E__;
241 if((pDIR = opendir(path.c_str())) != 0)
243 while((entry = readdir(pDIR)) != 0)
246 if(strlen(entry->d_name) < strlen(fileExt) + MIN_TABLE_NAME_SZ)
250 if(strcmp(&(entry->d_name[strlen(entry->d_name) - strlen(fileExt)]),
254 entry->d_name[strlen(entry->d_name) - strlen(fileExt)] =
262 theInterface_->get(table,
268 catch(cet::exception
const&)
274 __GEN_COUT__ <<
"Skipping! No valid class found for... "
275 << entry->d_name <<
"\n";
278 catch(std::runtime_error& e)
284 __GEN_COUT__ <<
"Skipping! No valid class found for... "
285 << entry->d_name <<
"\n";
286 __GEN_COUT__ <<
"Error: " << e.what() << __E__;
291 if(accumulatedWarnings)
293 if(errorFilterName ==
"" || errorFilterName == entry->d_name)
295 *accumulatedWarnings += std::string(
"\nIn table '") +
296 entry->d_name +
"'..." +
299 __SS__ <<
"Attempting to allow illegal columns!" << __E__;
300 *accumulatedWarnings += ss.str();
304 __GEN_COUT__ <<
"Attempting to allow illegal columns!"
307 std::string returnedAccumulatedErrors;
311 &returnedAccumulatedErrors);
315 __GEN_COUT__ <<
"Skipping! Allowing illegal columns "
316 "didn't work either... "
317 << entry->d_name <<
"\n";
321 <<
"Error (but allowed): " << returnedAccumulatedErrors
324 if(errorFilterName ==
"" || errorFilterName == entry->d_name)
325 *accumulatedWarnings +=
326 std::string(
"\nIn table '") + entry->d_name +
"'..." +
327 returnedAccumulatedErrors;
333 if(nameToTableMap_[entry->d_name])
336 std::set<TableVersion> versions =
337 nameToTableMap_[entry->d_name]->getStoredVersions();
338 for(
auto& version : versions)
339 if(version.isTemporaryVersion())
343 nameToTableMap_[entry->d_name]->setActiveView(
346 nameToTableMap_[entry->d_name]->getView(),
357 delete nameToTableMap_[entry->d_name];
358 nameToTableMap_[entry->d_name] = 0;
361 nameToTableMap_[entry->d_name] = table;
363 allTableInfo_[entry->d_name].tablePtr_ = table;
364 allTableInfo_[entry->d_name].versions_ =
365 theInterface_->getVersions(table);
369 std::set<TableVersion> versions =
370 nameToTableMap_[entry->d_name]->getStoredVersions();
371 for(
auto& version : versions)
372 if(version.isTemporaryVersion())
374 allTableInfo_[entry->d_name].versions_.emplace(version);
382 int threadsLaunched = 0;
383 int foundThreadIndex = 0;
384 std::string tableName;
386 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
387 for(
int i = 0; i < numOfThreads; ++i)
388 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
390 std::vector<std::shared_ptr<ots::TableInfo>> sharedTableInfoPtrs;
392 if((pDIR = opendir(path.c_str())) != 0)
394 while((entry = readdir(pDIR)) != 0)
397 if(strlen(entry->d_name) < strlen(fileExt) + MIN_TABLE_NAME_SZ)
401 if(strcmp(&(entry->d_name[strlen(entry->d_name) - strlen(fileExt)]),
405 entry->d_name[strlen(entry->d_name) - strlen(fileExt)] =
412 sharedTableInfoPtrs.push_back(std::make_shared<ots::TableInfo>());
413 sharedTableInfoPtrs.back()->accumulatedWarnings_ =
414 accumulatedWarnings ?
"ALLOW"
417 if(threadsLaunched >= numOfThreads)
420 foundThreadIndex = -1;
421 while(foundThreadIndex == -1)
423 for(
int i = 0; i < numOfThreads; ++i)
426 foundThreadIndex = i;
429 if(foundThreadIndex == -1)
431 __GEN_COUT_TYPE__(TLVL_DEBUG + 2)
432 << __COUT_HDR__ <<
"Waiting for available thread..."
437 threadsLaunched = numOfThreads - 1;
439 __GEN_COUTT__ <<
"Starting thread... " << foundThreadIndex
440 <<
" for table " << tableName << __E__;
442 *(threadDone[foundThreadIndex]) =
false;
445 std::string theTableName,
447 std::shared_ptr<ots::TableInfo> theTableInfo,
448 std::shared_ptr<std::atomic<bool>> theThreadDone) {
457 nameToTableMap_[tableName],
458 sharedTableInfoPtrs.back(),
459 threadDone[foundThreadIndex])
471 foundThreadIndex = -1;
472 for(
int i = 0; i < numOfThreads; ++i)
473 if(!*(threadDone[i]))
475 foundThreadIndex = i;
478 if(foundThreadIndex != -1)
480 __GEN_COUTT__ <<
"Waiting for thread to finish... "
481 << foundThreadIndex << __E__;
484 }
while(foundThreadIndex != -1);
487 for(
auto& tableInfo : sharedTableInfoPtrs)
489 __GEN_COUT_TYPE__(TLVL_DEBUG + 2)
490 << __COUT_HDR__ <<
"Copying table info for "
491 << tableInfo->tablePtr_->getTableName() << __E__;
492 nameToTableMap_[tableInfo->tablePtr_->getTableName()] =
493 tableInfo->tablePtr_;
494 allTableInfo_[tableInfo->tablePtr_->getTableName()].tablePtr_ =
495 tableInfo->tablePtr_;
496 allTableInfo_[tableInfo->tablePtr_->getTableName()].versions_ =
497 tableInfo->versions_;
500 __GEN_COUT__ <<
"Extracting list of tables complete." << __E__;
504 if(initializeActiveGroups)
506 __GEN_COUT__ <<
"Now initializing..." << __E__;
508 std::string tmpAccumulateWarnings;
511 accumulatedWarnings ? &tmpAccumulateWarnings :
nullptr);
513 if(accumulatedWarnings && errorFilterName ==
"")
514 *accumulatedWarnings += tmpAccumulateWarnings;
516 __GEN_COUT__ <<
"======================================================== "
517 "getAllTableInfo end runTimeSeconds()="
518 << runTimeSeconds() << __E__;
523 allGroupInfo_.clear();
528 std::set<std::string > tableGroups =
529 theInterface_->getAllTableGroupNames();
530 __GEN_COUT__ <<
"Number of Groups: " << tableGroups.size() << __E__;
532 __GEN_COUTT__ <<
"Group Info start runTimeSeconds()=" << runTimeSeconds()
537 for(
const auto& fullName : tableGroups)
540 cacheGroupKey(name, key);
543 __GEN_COUTT__ <<
"Group Keys end runTimeSeconds()=" << runTimeSeconds()
551 << numOfThreads <<
" threads." << __E__;
553 for(
auto& groupInfo : allGroupInfo_)
559 groupInfo.second.getLatestKey(),
561 &groupInfo.second.latestKeyMemberMap_ ,
564 &groupInfo.second.latestKeyGroupComment_,
565 &groupInfo.second.latestKeyGroupAuthor_,
566 &groupInfo.second.latestKeyGroupCreationTime_,
568 &groupInfo.second.latestKeyGroupTypeString_);
572 __GEN_COUT_WARN__ <<
"Error occurred loading latest group "
573 "info into cache for '"
574 << groupInfo.first <<
"("
575 << groupInfo.second.getLatestKey()
577 groupInfo.second.latestKeyGroupComment_ =
578 ConfigurationManager::UNKNOWN_INFO;
579 groupInfo.second.latestKeyGroupAuthor_ =
580 ConfigurationManager::UNKNOWN_INFO;
581 groupInfo.second.latestKeyGroupCreationTime_ =
582 ConfigurationManager::UNKNOWN_TIME;
583 groupInfo.second.latestKeyGroupTypeString_ =
584 ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
585 groupInfo.second.latestKeyMemberMap_ = {};
590 int threadsLaunched = 0;
591 int foundThreadIndex = 0;
593 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
594 for(
int i = 0; i < numOfThreads; ++i)
595 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
597 std::vector<std::shared_ptr<ots::GroupInfo>> sharedGroupInfoPtrs;
599 for(
auto& groupInfo : allGroupInfo_)
602 sharedGroupInfoPtrs.push_back(std::make_shared<ots::GroupInfo>());
604 if(threadsLaunched >= numOfThreads)
607 foundThreadIndex = -1;
608 while(foundThreadIndex == -1)
610 for(
int i = 0; i < numOfThreads; ++i)
613 foundThreadIndex = i;
616 if(foundThreadIndex == -1)
618 __GEN_COUTT__ <<
"Waiting for available thread..."
623 threadsLaunched = numOfThreads - 1;
625 __GEN_COUTT__ <<
"Starting thread... " << foundThreadIndex
626 <<
" for " << groupInfo.first <<
"("
627 << groupInfo.second.getLatestKey() <<
")" << __E__;
629 *(threadDone[foundThreadIndex]) =
false;
633 std::string theGroupName,
635 std::shared_ptr<ots::GroupInfo> theGroupInfo,
636 std::shared_ptr<std::atomic<bool>> theThreadDone) {
646 groupInfo.second.getLatestKey(),
647 sharedGroupInfoPtrs.back(),
648 threadDone[foundThreadIndex])
658 foundThreadIndex = -1;
659 for(
int i = 0; i < numOfThreads; ++i)
660 if(!*(threadDone[i]))
662 foundThreadIndex = i;
665 if(foundThreadIndex != -1)
667 __GEN_COUTT__ <<
"Waiting for thread to finish... "
668 << foundThreadIndex << __E__;
671 }
while(foundThreadIndex != -1);
675 for(
auto& groupInfo : allGroupInfo_)
677 groupInfo.second.latestKeyGroupComment_ =
678 sharedGroupInfoPtrs[i]->latestKeyGroupComment_;
679 groupInfo.second.latestKeyGroupAuthor_ =
680 sharedGroupInfoPtrs[i]->latestKeyGroupAuthor_;
681 groupInfo.second.latestKeyGroupCreationTime_ =
682 sharedGroupInfoPtrs[i]->latestKeyGroupCreationTime_;
683 groupInfo.second.latestKeyGroupTypeString_ =
684 sharedGroupInfoPtrs[i]->latestKeyGroupTypeString_;
685 groupInfo.second.latestKeyMemberMap_ =
686 sharedGroupInfoPtrs[i]->latestKeyMemberMap_;
693 catch(
const std::runtime_error& e)
696 <<
"A fatal error occurred reading the info for all table groups. Error: "
697 << e.what() << __E__;
698 __GEN_COUT_ERR__ <<
"\n" << ss.str();
699 if(accumulatedWarnings)
700 *accumulatedWarnings += ss.str();
706 __SS__ <<
"An unknown fatal error occurred reading the info for all table "
713 catch(
const std::exception& e)
715 ss <<
"Exception message: " << e.what();
720 __GEN_COUT_ERR__ <<
"\n" << ss.str();
721 if(accumulatedWarnings)
722 *accumulatedWarnings += ss.str();
726 __GEN_COUTT__ <<
"Group Info end runTimeSeconds()=" << runTimeSeconds() << __E__;
729 __GEN_COUTT__ <<
"Table Info end runTimeSeconds()=" << runTimeSeconds() << __E__;
731 return allTableInfo_;
738 std::string tableName,
740 std::shared_ptr<ots::TableInfo> tableInfo,
741 std::shared_ptr<std::atomic<bool>> threadDone)
744 __COUTT__ <<
"Thread started... table " << tableName << __E__;
747 tableInfo->tablePtr_ = 0;
751 cfgMgr->theInterface_->get(tableInfo->tablePtr_,
757 catch(cet::exception
const&)
759 if(tableInfo->tablePtr_)
760 delete tableInfo->tablePtr_;
761 tableInfo->tablePtr_ = 0;
763 __COUT__ <<
"Skipping! No valid class found for... " << tableName <<
"\n";
764 *(threadDone) =
true;
767 catch(std::runtime_error& e)
769 if(tableInfo->tablePtr_)
770 delete tableInfo->tablePtr_;
771 tableInfo->tablePtr_ = 0;
773 __COUT__ <<
"Skipping! No valid class found for... " << tableName <<
"\n";
774 __COUTT__ <<
"Error: " << e.what() << __E__;
779 if(tableInfo->accumulatedWarnings_ ==
"ALLOW")
781 tableInfo->accumulatedWarnings_ =
"";
784 tableInfo->accumulatedWarnings_ += std::string(
"\nIn table '") +
788 __SS__ <<
"Attempting to allow illegal columns!" << __E__;
789 tableInfo->accumulatedWarnings_ += ss.str();
793 __COUT__ <<
"Attempting to allow illegal columns!" << __E__;
795 std::string returnedAccumulatedErrors;
798 tableInfo->tablePtr_ =
799 new TableBase(tableName, &returnedAccumulatedErrors);
803 __COUT__ <<
"Skipping! Allowing illegal columns didn't work either... "
804 << tableName <<
"\n";
805 *(threadDone) =
true;
808 __COUT_WARN__ <<
"Error (but allowed): " << returnedAccumulatedErrors
812 tableInfo->accumulatedWarnings_ +=
813 std::string(
"\nIn table '") + tableName +
"'..." +
814 returnedAccumulatedErrors;
818 tableInfo->accumulatedWarnings_ =
"";
819 *(threadDone) =
true;
826 __COUTT__ <<
"Copying temporary version from existing table object for "
827 << tableName << __E__;
829 std::set<TableVersion> versions = existingTable->getStoredVersions();
830 for(
auto& version : versions)
831 if(version.isTemporaryVersion())
835 existingTable->setActiveView(version);
836 tableInfo->tablePtr_->copyView(
837 existingTable->getView(),
847 delete existingTable;
851 tableInfo->versions_ = cfgMgr->theInterface_->getVersions(tableInfo->tablePtr_);
855 std::set<TableVersion> versions = tableInfo->tablePtr_->getStoredVersions();
856 for(
auto& version : versions)
857 if(version.isTemporaryVersion())
859 tableInfo->versions_.emplace(version);
862 __COUTT__ <<
"Thread done... table " << tableName << __E__;
863 *(threadDone) =
true;
867 __COUT_ERR__ <<
"Error occurred loading latest table info into cache for '"
868 << tableName <<
"'..." << __E__;
869 *(threadDone) =
true;
876 std::string groupName,
878 std::shared_ptr<ots::GroupInfo> groupInfo,
879 std::shared_ptr<std::atomic<bool>> threadDone)
882 __COUTT__ <<
"Thread started... " << groupName <<
"(" << groupKey <<
")" << __E__;
887 &(groupInfo->latestKeyMemberMap_) ,
890 &(groupInfo->latestKeyGroupComment_),
891 &(groupInfo->latestKeyGroupAuthor_),
892 &(groupInfo->latestKeyGroupCreationTime_),
894 &(groupInfo->latestKeyGroupTypeString_));
896 *(threadDone) =
true;
900 __COUT_WARN__ <<
"Error occurred loading latest group info into cache for '"
901 << groupName <<
"(" << groupInfo->getLatestKey() <<
")'..." << __E__;
902 groupInfo->latestKeyGroupComment_ = ConfigurationManager::UNKNOWN_INFO;
903 groupInfo->latestKeyGroupAuthor_ = ConfigurationManager::UNKNOWN_INFO;
904 groupInfo->latestKeyGroupCreationTime_ = ConfigurationManager::UNKNOWN_TIME;
905 groupInfo->latestKeyGroupTypeString_ = ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
906 groupInfo->latestKeyMemberMap_ = {};
907 *(threadDone) =
true;
914 std::string groupName,
916 const std::map<std::string, TableVersion>& groupMemberMap,
917 const std::map<std::string /*name*/, std::string /*alias*/>& memberTableAliases,
918 std::atomic<bool>* foundIdentical,
920 std::mutex* threadMutex,
921 std::shared_ptr<std::atomic<bool>> threadDone)
924 std::map<std::string ,
TableVersion > compareToMemberMap;
925 std::map<std::string , std::string > compareToMemberTableAliases;
926 std::map<std::string , std::string >*
927 compareToMemberTableAliasesPtr =
nullptr;
928 if(memberTableAliases
930 compareToMemberTableAliasesPtr = &compareToMemberTableAliases;
935 &compareToMemberMap ,
943 compareToMemberTableAliasesPtr);
945 bool isDifferent =
false;
946 for(
auto& memberPair : groupMemberMap)
948 if(memberTableAliases.find(memberPair.first) != memberTableAliases.end())
951 if(compareToMemberTableAliases.find(memberPair.first) ==
952 compareToMemberTableAliases.end() ||
953 memberTableAliases.at(memberPair.first) !=
954 compareToMemberTableAliases.at(memberPair.first))
962 else if(compareToMemberTableAliases.find(memberPair.first) !=
963 compareToMemberTableAliases.end())
970 else if(compareToMemberMap.find(memberPair.first) ==
971 compareToMemberMap.end() ||
973 compareToMemberMap.at(memberPair.first))
982 if(!isDifferent && groupMemberMap.size() != compareToMemberMap.size())
988 *foundIdentical =
true;
989 __COUT__ <<
"=====> Found exact match with key: " << groupKeyToCompare << __E__;
991 std::lock_guard<std::mutex> lock(*threadMutex);
992 *identicalKey = groupKeyToCompare;
995 *(threadDone) =
true;
999 __COUT_WARN__ <<
"Error occurred comparing group '" << groupName <<
"("
1000 << groupKeyToCompare <<
")'..." << __E__;
1002 *(threadDone) =
true;
1009 std::map<std::string ,
1013 std::map<std::string ,
1019 if(!ConfigurationInterface::isVersionTrackingEnabled())
1020 for(
const auto& tableInfo : allTableInfo_)
1021 for(
const auto& version : tableInfo.second.versions_)
1022 if(version.isScratchVersion())
1023 retMap[tableInfo.first][ConfigurationManager::SCRATCH_VERSION_ALIAS] =
1035 std::string* accumulatedTreeErrors,
1036 std::string* groupTypeString)
1045 accumulatedTreeErrors,
1054 __GEN_COUT_ERR__ <<
"There were errors, so de-activating group: "
1055 << tableGroupName <<
" (" << tableGroupKey <<
")" << __E__;
1066 __GEN_COUT_INFO__ <<
"Updating persistent active groups to "
1069 __COUT_INFO__ <<
"Active Context table group: " << theContextTableGroup_ <<
"("
1070 << (theContextTableGroupKey_
1071 ? theContextTableGroupKey_->toString().c_str()
1074 __COUT_INFO__ <<
"Active Backbone table group: " << theBackboneTableGroup_ <<
"("
1075 << (theBackboneTableGroupKey_
1076 ? theBackboneTableGroupKey_->toString().c_str()
1079 __COUT_INFO__ <<
"Active Iterate table group: " << theIterateTableGroup_ <<
"("
1080 << (theIterateTableGroupKey_
1081 ? theIterateTableGroupKey_->toString().c_str()
1084 __COUT_INFO__ <<
"Active Configuration table group: " << theConfigurationTableGroup_
1086 << (theConfigurationTableGroupKey_
1087 ? theConfigurationTableGroupKey_->toString().c_str()
1092 FILE* fp = fopen(fn.c_str(),
"w");
1095 __SS__ <<
"Fatal Error! Unable to open the file "
1097 <<
" for editing! Is there a permissions problem?" << __E__;
1098 __GEN_COUT_ERR__ << ss.str();
1102 fprintf(fp,
"%s\n", theContextTableGroup_.c_str());
1106 theContextTableGroupKey_ ? theContextTableGroupKey_->toString().c_str() :
"-1");
1107 fprintf(fp,
"%s\n", theBackboneTableGroup_.c_str());
1111 theBackboneTableGroupKey_ ? theBackboneTableGroupKey_->toString().c_str() :
"-1");
1112 fprintf(fp,
"%s\n", theIterateTableGroup_.c_str());
1116 theIterateTableGroupKey_ ? theIterateTableGroupKey_->toString().c_str() :
"-1");
1117 fprintf(fp,
"%s\n", theConfigurationTableGroup_.c_str());
1120 theConfigurationTableGroupKey_
1121 ? theConfigurationTableGroupKey_->toString().c_str()
1128 std::string(tableGroupName), tableGroupKey);
1129 if(theConfigurationTableGroupKey_ &&
1130 theConfigurationTableGroup_ == tableGroupName &&
1131 *theConfigurationTableGroupKey_ == tableGroupKey)
1132 ConfigurationManager::saveGroupNameAndKey(activatedGroup,
1133 LAST_ACTIVATED_CONFIG_GROUP_FILE);
1134 else if(theContextTableGroupKey_ && theContextTableGroup_ == tableGroupName &&
1135 *theContextTableGroupKey_ == tableGroupKey)
1136 ConfigurationManager::saveGroupNameAndKey(activatedGroup,
1137 LAST_ACTIVATED_CONTEXT_GROUP_FILE);
1138 else if(theBackboneTableGroupKey_ && theBackboneTableGroup_ == tableGroupName &&
1139 *theBackboneTableGroupKey_ == tableGroupKey)
1140 ConfigurationManager::saveGroupNameAndKey(activatedGroup,
1141 LAST_ACTIVATED_BACKBONE_GROUP_FILE);
1142 else if(theIterateTableGroupKey_ && theIterateTableGroup_ == tableGroupName &&
1143 *theIterateTableGroupKey_ == tableGroupKey)
1144 ConfigurationManager::saveGroupNameAndKey(activatedGroup,
1145 LAST_ACTIVATED_ITERATOR_GROUP_FILE);
1157 __GEN_COUT_INFO__ <<
"Creating temporary backbone view from version "
1158 << sourceViewVersion << __E__;
1164 auto backboneMemberNames = ConfigurationManager::getBackboneMemberNames();
1165 for(
auto& name : backboneMemberNames)
1169 if(retTmpVersion < tmpVersion)
1170 tmpVersion = retTmpVersion;
1173 __GEN_COUT__ <<
"Common temporary backbone version found as " << tmpVersion << __E__;
1176 for(
auto& name : backboneMemberNames)
1180 if(retTmpVersion != tmpVersion)
1182 __SS__ <<
"Failure! Temporary view requested was " << tmpVersion
1183 <<
". Mismatched temporary view created: " << retTmpVersion << __E__;
1184 __GEN_COUT_ERR__ << ss.str();
1193 TableBase* ConfigurationManagerRW::getTableByName(
const std::string& tableName)
1195 if(nameToTableMap_.find(tableName) == nameToTableMap_.end())
1197 if(tableName == ConfigurationManager::ARTDAQ_TOP_TABLE_NAME)
1200 <<
"Since target table was the artdaq top configuration level, "
1201 "attempting to help user by appending to core tables file: "
1202 << CORE_TABLE_INFO_FILENAME << __E__;
1203 FILE* fp = fopen((CORE_TABLE_INFO_FILENAME).c_str(),
"a");
1206 fprintf(fp,
"\nARTDAQ/*");
1211 __SS__ <<
"Table not found with name: " << tableName << __E__;
1213 if((f = tableName.find(
' ')) != std::string::npos)
1214 ss <<
"There was a space character found in the table name needle at "
1216 << f <<
" in the string (was this intended?). " << __E__;
1218 ss <<
"\nIf you think this table should exist in the core set of tables, try "
1219 "running 'UpdateOTS.sh --tables' to update your tables, then relaunch ots."
1221 ss <<
"\nTables must be defined at path $USER_DATA/TableInfo/ to exist in ots. "
1222 "Please verify your table definitions, and then restart ots."
1224 __GEN_COUT_ERR__ <<
"\n" << ss.str();
1227 return nameToTableMap_[tableName];
1236 const std::string& tableName,
1238 bool looseColumnMatching ,
1239 std::string* accumulatedErrors ,
1242 auto it = nameToTableMap_.find(tableName);
1243 if(it == nameToTableMap_.end())
1245 __SS__ <<
"\nCan not find table named '" << tableName
1246 <<
"'\n\n\n\nYou need to load the table before it can be used."
1247 <<
"It probably is missing from the member list of the Table "
1248 "Group that was loaded?\n\n\n\n\n"
1256 table->setActiveView(version);
1260 std::stringstream jsonSs;
1261 table->getViewP()->printJSON(jsonSs);
1262 table->getViewP()->doGetSourceRawData(
true);
1268 theInterface_->get(table,
1275 looseColumnMatching,
1293 TableBase* table = getTableByName(tableName);
1298 newVersion = theInterface_->saveNewVersion(table, temporaryVersion);
1300 table->setActiveView(newVersion);
1304 allTableInfo_[tableName].versions_.find(newVersion) !=
1305 allTableInfo_[tableName].versions_.end())
1308 <<
"What happenened!?? ERROR::: new persistent version v" << newVersion
1309 <<
" already exists!? How is it possible? Retrace your steps and "
1317 newVersion = temporaryVersion;
1321 __GEN_COUT_WARN__ <<
"Attempting to recover and use v" << newVersion << __E__;
1325 theInterface_->saveNewVersion(table, temporaryVersion, newVersion);
1327 table->setActiveView(newVersion);
1332 __SS__ <<
"Something went wrong saving the new version v" << newVersion
1333 <<
". What happened?! (duplicates? database error?)" << __E__;
1334 __GEN_COUT_ERR__ <<
"\n" << ss.str();
1339 allTableInfo_[tableName].versions_.insert(newVersion);
1353 TableBase* table = getTableByName(tableName);
1358 if(allTableInfo_.find(tableName) == allTableInfo_.end())
1365 for(
auto it = allTableInfo_[tableName].versions_.begin();
1366 it != allTableInfo_[tableName].versions_.end();
1369 if(it->isTemporaryVersion())
1371 __GEN_COUT__ <<
"Removing '" << tableName <<
"' version info: " << *it
1373 allTableInfo_[tableName].versions_.erase(it++);
1382 auto it = allTableInfo_[tableName].versions_.find(targetVersion);
1383 if(it == allTableInfo_[tableName].versions_.end())
1385 __GEN_COUT__ <<
"Target '" << tableName <<
"' version v" << targetVersion
1386 <<
" was not found in info versions..." << __E__;
1389 allTableInfo_[tableName].versions_.erase(
1390 allTableInfo_[tableName].versions_.find(targetVersion));
1401 TableBase* table = getTableByName(tableName);
1413 for(
auto configInfo : allTableInfo_)
1414 configInfo.second.tablePtr_->trimCache(0);
1420 const std::string& tableName,
TableVersion sourceVersion)
1422 getTableByName(tableName)->reset();
1434 allTableInfo_[tableName].versions_.insert(newTemporaryVersion);
1436 return newTemporaryVersion;
1441 void ConfigurationManagerRW::cacheGroupKey(
const std::string& groupName,
1444 allGroupInfo_[groupName].keys_.emplace(key);
1464 auto it = allGroupInfo_.find(groupName);
1465 if(it == allGroupInfo_.end())
1467 __SS__ <<
"Group name '" << groupName
1468 <<
"' not found in group info! (creating empty info)" << __E__;
1469 __GEN_COUT_WARN__ << ss.str();
1471 return allGroupInfo_[groupName];
1488 const std::string& groupName,
1489 const std::map<std::string, TableVersion>& groupMemberMap,
1490 const std::map<std::string /*name*/, std::string /*alias*/>& memberTableAliases)
1501 const unsigned int MAX_DEPTH_TO_CHECK = 20;
1502 unsigned int keyMinToCheck = 0;
1504 if(groupInfo.keys_.size())
1505 keyMinToCheck = groupInfo.keys_.rbegin()->key();
1506 if(keyMinToCheck > MAX_DEPTH_TO_CHECK)
1508 keyMinToCheck -= MAX_DEPTH_TO_CHECK;
1509 __GEN_COUT__ <<
"Checking groups back to key... " << keyMinToCheck << __E__;
1514 __GEN_COUT__ <<
"Checking all groups." << __E__;
1520 __GEN_COUT__ <<
" PROCESSOR_COUNT " <<
PROCESSOR_COUNT <<
" ==> " << numOfThreads
1521 <<
" threads." << __E__;
1522 if(numOfThreads < 2)
1524 std::map<std::string ,
TableVersion > compareToMemberMap;
1525 std::map<std::string , std::string > compareToMemberTableAliases;
1526 std::map<std::string , std::string >*
1527 compareToMemberTableAliasesPtr =
nullptr;
1528 if(memberTableAliases.size())
1529 compareToMemberTableAliasesPtr = &compareToMemberTableAliases;
1532 for(
const auto& key : groupInfo.keys_)
1534 if(key.key() < keyMinToCheck)
1540 &compareToMemberMap ,
1548 compareToMemberTableAliasesPtr);
1550 isDifferent =
false;
1551 for(
auto& memberPair : groupMemberMap)
1553 if(memberTableAliases.find(memberPair.first) != memberTableAliases.end())
1556 if(compareToMemberTableAliases.find(memberPair.first) ==
1557 compareToMemberTableAliases.end() ||
1558 memberTableAliases.at(memberPair.first) !=
1559 compareToMemberTableAliases.at(memberPair.first))
1567 else if(compareToMemberTableAliases.find(memberPair.first) !=
1568 compareToMemberTableAliases.end())
1575 else if(compareToMemberMap.find(memberPair.first) ==
1576 compareToMemberMap.end() ||
1577 memberPair.second !=
1578 compareToMemberMap.at(
1590 if(groupMemberMap.size() != compareToMemberMap.size())
1594 __GEN_COUT__ <<
"Found exact match with key: " << key << __E__;
1598 __GEN_COUT__ <<
"No match found - this group is new!" << __E__;
1604 int threadsLaunched = 0;
1605 int foundThreadIndex = 0;
1606 std::atomic<bool> foundIdentical =
false;
1608 std::mutex threadMutex;
1610 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
1611 for(
int i = 0; i < numOfThreads; ++i)
1612 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
1614 for(
const auto& key : groupInfo.keys_)
1618 if(key.key() < keyMinToCheck)
1621 if(threadsLaunched >= numOfThreads)
1624 foundThreadIndex = -1;
1625 while(foundThreadIndex == -1)
1630 for(
int i = 0; i < numOfThreads; ++i)
1631 if(*(threadDone[i]))
1633 foundThreadIndex = i;
1636 if(foundThreadIndex == -1)
1638 __GEN_COUTT__ <<
"Waiting for available thread..." << __E__;
1642 threadsLaunched = numOfThreads - 1;
1647 __GEN_COUTT__ <<
"Starting thread... " << foundThreadIndex << __E__;
1648 *(threadDone[foundThreadIndex]) =
false;
1652 std::string theGroupName,
1654 const std::map<std::string, TableVersion>& groupMemberMap,
1655 const std::map<std::string /*name*/, std::string /*alias*/>&
1657 std::atomic<bool>* theFoundIdentical,
1659 std::mutex* theThreadMutex,
1660 std::shared_ptr<std::atomic<bool>> theThreadDone) {
1679 threadDone[foundThreadIndex])
1689 foundThreadIndex = -1;
1690 for(
int i = 0; i < numOfThreads; ++i)
1691 if(!*(threadDone[i]))
1693 foundThreadIndex = i;
1696 if(foundThreadIndex != -1)
1698 __GEN_COUTT__ <<
"Waiting for thread to finish... " << foundThreadIndex
1702 }
while(foundThreadIndex != -1);
1706 __GEN_COUT__ <<
"Found exact match with key: " << identicalKey << __E__;
1707 return identicalKey;
1709 __GEN_COUT__ <<
"No match found - this group is new!" << __E__;
1723 const std::string& groupName,
1724 std::map<std::string, TableVersion>& groupMembers,
1725 const std::string& groupComment,
1726 std::map<std::string /*table*/, std::string /*alias*/>* groupAliases)
1734 if(groupMembers.size() == 0)
1736 __SS__ <<
"Empty group member list. Can not create a group without members!"
1741 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds() << __E__;
1747 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds() << __E__;
1749 __GEN_COUT__ <<
"New Key for group: " << groupName <<
" found as " << newKey << __E__;
1754 for(
auto& memberPair : groupMembers)
1757 if(allCfgInfo.find(memberPair.first) == allCfgInfo.end())
1759 __GEN_COUT_ERR__ <<
"Group member \"" << memberPair.first
1760 <<
"\" not found in database!";
1762 if(groupMetadataTable_.getTableName() == memberPair.first)
1765 <<
"Looks like this is the groupMetadataTable_ '"
1766 << ConfigurationInterface::GROUP_METADATA_TABLE_NAME
1767 <<
".' Note that this table is added to the member map when groups "
1769 <<
"It should not be part of member map when calling this function."
1771 __GEN_COUT__ <<
"Attempting to recover." << __E__;
1772 groupMembers.erase(groupMembers.find(memberPair.first));
1776 __SS__ << (
"Group member not found!") << __E__;
1781 if(allCfgInfo[memberPair.first].versions_.find(memberPair.second) ==
1782 allCfgInfo[memberPair.first].versions_.end())
1784 __SS__ <<
"Group member \"" << memberPair.first <<
"\" version \""
1785 << memberPair.second <<
"\" not found in database!";
1790 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds() << __E__;
1795 for(
auto& aliasPair : *groupAliases)
1798 if(groupMembers.find(aliasPair.first) == groupMembers.end())
1800 __GEN_COUT_ERR__ <<
"Group member \"" << aliasPair.first
1801 <<
"\" not found in group member map!";
1803 __SS__ << (
"Alias table not found in member list!") << __E__;
1813 std::string groupAliasesString =
"";
1816 *groupAliases,
"," ,
":" );
1817 __GEN_COUT__ <<
"Metadata: " << username_ <<
" " << time(0) <<
" " << groupComment
1818 <<
" " << groupAliasesString << __E__;
1822 while(groupMetadataTable_.getViewP()->getNumberOfRows() > 1)
1823 groupMetadataTable_.getViewP()->deleteRow(0);
1824 if(groupMetadataTable_.getViewP()->getNumberOfRows() == 0)
1825 groupMetadataTable_.getViewP()->addRow();
1828 groupMetadataTable_.getViewP()->setValue(
1829 groupAliasesString, 0, ConfigurationManager::METADATA_COL_ALIASES);
1830 groupMetadataTable_.getViewP()->setValue(
1831 groupComment, 0, ConfigurationManager::METADATA_COL_COMMENT);
1832 groupMetadataTable_.getViewP()->setValue(
1833 username_, 0, ConfigurationManager::METADATA_COL_AUTHOR);
1834 groupMetadataTable_.getViewP()->setValue(
1835 time(0), 0, ConfigurationManager::METADATA_COL_TIMESTAMP);
1839 theInterface_->findLatestVersion(&groupMetadataTable_)));
1843 theInterface_->saveActiveVersion(&groupMetadataTable_);
1845 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds()
1849 groupMembers[groupMetadataTable_.getTableName()] =
1850 groupMetadataTable_.getViewVersion();
1852 theInterface_->saveTableGroup(
1854 __GEN_COUT__ <<
"Created table group: " << groupName <<
":" << newKey << __E__;
1856 catch(std::runtime_error& e)
1858 __GEN_COUT_ERR__ <<
"Failed to create table group: " << groupName <<
":" << newKey
1860 __GEN_COUT_ERR__ <<
"\n\n" << e.what() << __E__;
1865 __GEN_COUT_ERR__ <<
"Failed to create table group: " << groupName <<
":" << newKey
1870 __GEN_COUTT__ <<
"saveNewTableGroup runTimeSeconds()=" << runTimeSeconds() << __E__;
1873 cacheGroupKey(groupName, newKey);
1885 __GEN_COUT_INFO__ <<
"Creating new backbone from temporary version "
1886 << temporaryVersion << __E__;
1891 auto backboneMemberNames = ConfigurationManager::getBackboneMemberNames();
1892 for(
auto& name : backboneMemberNames)
1895 __GEN_COUT__ <<
"New version for backbone member (" << name
1896 <<
"): " << retNewVersion << __E__;
1897 if(retNewVersion > newVersion)
1898 newVersion = retNewVersion;
1901 __GEN_COUT__ <<
"Common new backbone version found as " << newVersion << __E__;
1904 for(
auto& name : backboneMemberNames)
1908 getTableByName(name), temporaryVersion, newVersion);
1909 if(retNewVersion != newVersion)
1911 __SS__ <<
"Failure! New view requested was " << newVersion
1912 <<
". Mismatched new view created: " << retNewVersion << __E__;
1913 __GEN_COUT_ERR__ << ss.str();
1927 const std::string& tableName,
1932 bool ignoreDuplicates ,
1933 bool lookForEquivalent ,
1934 bool* foundEquivalent )
1936 bool needToEraseTemporarySource =
1940 *foundEquivalent =
false;
1943 if(!ignoreDuplicates)
1945 __GEN_COUT__ <<
"Checking for duplicate '" << tableName <<
"' tables..." << __E__;
1954 const std::map<std::string, TableInfo>& allTableInfo =
1957 auto versionReverseIterator =
1958 allTableInfo.at(tableName).versions_.rbegin();
1959 __GEN_COUT__ <<
"Filling up '" << tableName <<
"' cache from "
1963 versionReverseIterator != allTableInfo.at(tableName).versions_.rend();
1964 ++versionReverseIterator)
1966 __GEN_COUTT__ <<
"'" << tableName <<
"' versions in reverse order "
1967 << *versionReverseIterator << __E__;
1971 *versionReverseIterator);
1973 catch(
const std::runtime_error& e)
1980 __GEN_COUT__ <<
"Checking '" << tableName <<
"' duplicate..." << __E__;
1983 temporaryModifiedVersion,
1990 if(lookForEquivalent && !duplicateVersion.
isInvalid())
1993 __GEN_COUT__ <<
"Equivalent '" << tableName <<
"' table found in version v"
1994 << duplicateVersion << __E__;
1999 __GEN_COUT__ <<
"Need persistent. Duplicate '" << tableName
2000 <<
"' version was temporary. "
2001 "Abandoning duplicate."
2013 if(needToEraseTemporarySource)
2017 *foundEquivalent =
true;
2019 __GEN_COUT__ <<
"\t\t Equivalent '" << tableName
2020 <<
"' assigned version: " << duplicateVersion << __E__;
2022 return duplicateVersion;
2028 __SS__ <<
"This version of table '" << tableName
2029 <<
"' is identical to another version currently cached v"
2030 << duplicateVersion <<
". No reason to save a duplicate." << __E__;
2031 __GEN_COUT_ERR__ <<
"\n" << ss.str();
2034 table->eraseView(temporaryModifiedVersion);
2038 __GEN_COUT__ <<
"Check for duplicate '" << tableName <<
"' tables complete."
2043 __GEN_COUT__ <<
"\t\t**************************** Save as temporary '"
2044 << tableName <<
"' table version" << __E__;
2046 __GEN_COUT__ <<
"\t\t**************************** Save as new '" << tableName
2047 <<
"' table version" << __E__;
2050 saveNewTable(tableName, temporaryModifiedVersion, makeTemporary);
2052 __GEN_COUTTV__(table->getView().getComment());
2054 if(needToEraseTemporarySource)
2057 __GEN_COUT__ <<
"\t\t '" << tableName
2058 <<
"' new assigned version: " << newAssignedVersion << __E__;
2059 return newAssignedVersion;
2063 GroupEditStruct::GroupEditStruct(
const ConfigurationManager::GroupType& groupType,
2065 : groupType_(groupType)
2066 , originalGroupName_(cfgMgr->getActiveGroupName(groupType))
2067 , originalGroupKey_(cfgMgr->getActiveGroupKey(groupType))
2069 , mfSubject_(cfgMgr->getUsername())
2071 if(originalGroupName_ ==
"" || originalGroupKey_.isInvalid())
2073 __SS__ <<
"Error! No active group found for type '"
2075 <<
".' There must be an active group to edit the group." << __E__ << __E__
2080 __GEN_COUT__ <<
"Extracting Group-Edit Struct for type "
2085 const std::set<std::string>& memberNames =
2086 groupType == ConfigurationManager::GroupType::CONTEXT_TYPE
2087 ? ConfigurationManager::getContextMemberNames()
2092 : cfgMgr->getConfigurationMemberNames()));
2094 for(
auto& memberName : memberNames)
2097 groupMembers_.emplace(
2098 std::make_pair(memberName, activeTables.at(memberName)));
2099 groupTables_.emplace(std::make_pair(
2105 __SS__ <<
"Error! Could not find group member table '" << memberName
2106 <<
"' for group type '"
2108 <<
".' All group members must be present to create the group editing "
2117 GroupEditStruct::~GroupEditStruct()
2119 __GEN_COUT__ <<
"GroupEditStruct from editing '" << originalGroupName_ <<
"("
2120 << originalGroupKey_ <<
")' Destructing..." << __E__;
2122 __GEN_COUT__ <<
"GroupEditStruct from editing '" << originalGroupName_ <<
"("
2123 << originalGroupKey_ <<
")' Desctructed." << __E__;
2131 auto it = groupTables_.find(tableName);
2132 if(it == groupTables_.end())
2134 if(groupType_ == ConfigurationManager::GroupType::CONFIGURATION_TYPE &&
2137 __GEN_COUT__ <<
"Table '" << tableName
2138 <<
"' not found in configuration table members from editing '"
2139 << originalGroupName_ <<
"(" << originalGroupKey_ <<
")..."
2140 <<
" Attempting to add it!" << __E__;
2143 auto newIt = groupTables_.emplace(std::make_pair(
2148 newIt.first->second.modified_ =
2150 groupMembers_.emplace(
2151 std::make_pair(tableName, newIt.first->second.temporaryVersion_));
2152 return newIt.first->second;
2154 __GEN_COUT_ERR__ <<
"Failed to emplace new table..." << __E__;
2157 __SS__ <<
"Table '" << tableName <<
"' not found in table members from editing '"
2158 << originalGroupName_ <<
"(" << originalGroupKey_ <<
")!'" << __E__;
2161 it->second.modified_ =
2167 void GroupEditStruct::dropChanges()
2169 __GEN_COUT__ <<
"Dropping unsaved changes from editing '" << originalGroupName_ <<
"("
2170 << originalGroupKey_ <<
")'..." << __E__;
2175 for(
auto& groupTable : groupTables_)
2176 if(groupTable.second
2177 .createdTemporaryVersion_)
2181 groupTable.second.temporaryVersion_);
2182 groupTable.second.createdTemporaryVersion_ =
false;
2183 groupTable.second.modified_ =
false;
2186 __GEN_COUT__ <<
"Unsaved changes dropped from editing '" << originalGroupName_ <<
"("
2187 << originalGroupKey_ <<
").'" << __E__;
2191 void GroupEditStruct::saveChanges(
const std::string& groupNameToSave,
2193 bool* foundEquivalentGroupKey ,
2194 bool activateNewGroup ,
2195 bool updateGroupAliases ,
2196 bool updateTableAliases ,
2198 bool* foundEquivalentBackboneKey ,
2199 std::string* accumulatedWarnings )
2201 __GEN_COUT__ <<
"Saving changes..." << __E__;
2206 if(foundEquivalentBackboneKey)
2207 *foundEquivalentBackboneKey =
false;
2211 for(
auto& groupTable : groupTables_)
2213 if(!groupTable.second.modified_)
2216 __GEN_COUT__ <<
"Original version is " << groupTable.second.tableName_ <<
"-v"
2217 << groupTable.second.originalVersion_ << __E__;
2220 groupTable.second.tableName_,
2221 groupTable.second.originalVersion_,
2223 groupTable.second.table_,
2224 groupTable.second.temporaryVersion_,
2227 __GEN_COUT__ <<
"Temporary target version is " << groupTable.second.tableName_
2228 <<
"-v" << groupMembers_.at(groupTable.first) <<
"-v"
2229 << groupTable.second.temporaryVersion_ << __E__;
2232 groupTable.second.tableName_,
2233 groupTable.second.originalVersion_,
2235 groupTable.second.table_,
2236 groupTable.second.temporaryVersion_,
2240 __GEN_COUT__ <<
"Final target version is " << groupTable.second.tableName_ <<
"-v"
2241 << groupMembers_.at(groupTable.first) << __E__;
2243 groupTable.second.modified_ =
false;
2244 groupTable.second.createdTemporaryVersion_ =
false;
2247 for(
auto& table : groupMembers_)
2249 __GEN_COUT__ << table.first <<
" v" << table.second << __E__;
2252 __GEN_COUT__ <<
"Checking for duplicate groups..." << __E__;
2253 newGroupKey = cfgMgr->
findTableGroup(groupNameToSave, groupMembers_);
2257 __GEN_COUT__ <<
"Found equivalent group key (" << newGroupKey <<
") for "
2258 << groupNameToSave <<
"." << __E__;
2259 if(foundEquivalentGroupKey)
2260 *foundEquivalentGroupKey =
true;
2265 __GEN_COUT__ <<
"Saved new Context group key (" << newGroupKey <<
") for "
2266 << groupNameToSave <<
"." << __E__;
2269 bool groupAliasChange =
false;
2270 bool tableAliasChange =
false;
2272 GroupEditStruct backboneGroupEdit(ConfigurationManager::GroupType::BACKBONE_TYPE,
2275 if(groupType_ != ConfigurationManager::GroupType::BACKBONE_TYPE && updateGroupAliases)
2280 TableEditStruct& groupAliasTable = backboneGroupEdit.getTableEditStruct(
2281 ConfigurationManager::GROUP_ALIASES_TABLE_NAME,
true );
2282 TableView* tableView = groupAliasTable.tableView_;
2285 unsigned int row = 0;
2287 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
2289 std::string groupName, groupKey;
2290 for(
auto& aliasNodePair : aliasNodePairs)
2292 groupName = aliasNodePair.second.getNode(
"GroupName").getValueAsString();
2293 groupKey = aliasNodePair.second.getNode(
"GroupKey").getValueAsString();
2295 __GEN_COUT__ <<
"Group Alias: " << aliasNodePair.first <<
" => " << groupName
2296 <<
"(" << groupKey <<
"); row=" << row << __E__;
2298 if(groupName == originalGroupName_ &&
2301 __GEN_COUT__ <<
"Found alias! Changing group key from ("
2302 << originalGroupKey_ <<
") to (" << newGroupKey <<
")"
2305 groupAliasChange =
true;
2314 if(groupAliasChange)
2316 std::stringstream ss;
2317 tableView->print(ss);
2318 __GEN_COUT__ << ss.str();
2364 if(groupType_ != ConfigurationManager::GroupType::BACKBONE_TYPE && updateTableAliases)
2369 .getTableEditStruct(ConfigurationManager::VERSION_ALIASES_TABLE_NAME,
2373 for(
auto& groupTable : groupTables_)
2375 if(groupTable.second.originalVersion_ ==
2376 groupMembers_.at(groupTable.second.tableName_))
2379 __GEN_COUT__ <<
"Checking alias... original version is "
2380 << groupTable.second.tableName_ <<
"-v"
2381 << groupTable.second.originalVersion_ <<
" and new version is v"
2382 << groupMembers_.at(groupTable.second.tableName_) << __E__;
2385 unsigned int row = 0;
2387 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
2388 cfgMgr->
getNode(ConfigurationManager::VERSION_ALIASES_TABLE_NAME)
2390 std::string tableName, tableVersion;
2391 for(
auto& aliasNodePair : aliasNodePairs)
2393 tableName = aliasNodePair.second.getNode(
"TableName").getValueAsString();
2394 tableVersion = aliasNodePair.second.getNode(
"Version").getValueAsString();
2396 __GEN_COUT__ <<
"Table Alias: " << aliasNodePair.first <<
" => "
2397 << tableName <<
"-v" << tableVersion <<
"" << __E__;
2399 if(tableName == groupTable.second.tableName_ &&
2400 TableVersion(tableVersion) == groupTable.second.originalVersion_)
2402 __GEN_COUT__ <<
"Found alias! Changing icon table version alias."
2405 tableAliasChange =
true;
2408 groupMembers_.at(groupTable.second.tableName_).toString(),
2410 tableView->
findCol(
"Version"));
2417 if(tableAliasChange)
2419 std::stringstream ss;
2420 tableView->print(ss);
2421 __GEN_COUT__ << ss.str();
2428 if(groupAliasChange || tableAliasChange)
2430 for(
auto& table : backboneGroupEdit.groupMembers_)
2432 __GEN_COUT__ << table.first <<
" v" << table.second << __E__;
2434 backboneGroupEdit.saveChanges(
2435 backboneGroupEdit.originalGroupName_,
2436 localNewBackboneKey,
2437 foundEquivalentBackboneKey ? foundEquivalentBackboneKey :
nullptr);
2440 *newBackboneKey = localNewBackboneKey;
2446 __GEN_COUT__ <<
"Restoring active table groups, before activating new groups..."
2449 std::string localAccumulatedWarnings;
2452 ConfigurationManager::LoadGroupType::
2454 &localAccumulatedWarnings);
2460 localNewBackboneKey,
2461 accumulatedWarnings ? accumulatedWarnings :
nullptr);
2463 if(activateNewGroup)
2466 accumulatedWarnings ? accumulatedWarnings :
nullptr);
2468 __GEN_COUT__ <<
"Changes saved." << __E__;
2477 __GEN_COUTV__(runTimeSeconds());
2479 std::string accumulatedWarningsStr;
2480 std::string* accumulatedWarnings = &accumulatedWarningsStr;
2487 std::set<std::string > tableGroups =
2488 theInterface_->getAllTableGroupNames();
2489 __GEN_COUT__ <<
"Number of Groups: " << tableGroups.size() << __E__;
2491 __GEN_COUTV__(runTimeSeconds());
2494 for(
const auto& fullName : tableGroups)
2497 cacheGroupKey(name, key);
2499 __GEN_COUTV__(runTimeSeconds());
2501 for(
auto& groupInfo : allGroupInfo_)
2506 groupInfo.second.getLatestKey(),
2508 &groupInfo.second.latestKeyMemberMap_ ,
2511 &groupInfo.second.latestKeyGroupComment_,
2512 &groupInfo.second.latestKeyGroupAuthor_,
2513 &groupInfo.second.latestKeyGroupCreationTime_,
2515 &groupInfo.second.latestKeyGroupTypeString_);
2517 catch(
const std::runtime_error& e)
2520 <<
"Error occurred loading latest group info into cache for '"
2521 << groupInfo.first <<
"(" << groupInfo.second.getLatestKey()
2523 << e.what() << __E__;
2525 groupInfo.second.latestKeyGroupComment_ =
2526 ConfigurationManager::UNKNOWN_INFO;
2527 groupInfo.second.latestKeyGroupAuthor_ =
2528 ConfigurationManager::UNKNOWN_INFO;
2529 groupInfo.second.latestKeyGroupCreationTime_ =
2530 ConfigurationManager::UNKNOWN_TIME;
2531 groupInfo.second.latestKeyGroupTypeString_ =
2532 ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
2533 groupInfo.second.latestKeyMemberMap_ = {};
2538 <<
"Error occurred loading latest group info into cache for '"
2539 << groupInfo.first <<
"(" << groupInfo.second.getLatestKey()
2540 <<
")'..." << __E__;
2541 groupInfo.second.latestKeyGroupComment_ =
2542 ConfigurationManager::UNKNOWN_INFO;
2543 groupInfo.second.latestKeyGroupAuthor_ =
2544 ConfigurationManager::UNKNOWN_INFO;
2545 groupInfo.second.latestKeyGroupCreationTime_ =
2546 ConfigurationManager::UNKNOWN_TIME;
2547 groupInfo.second.latestKeyGroupTypeString_ =
2548 ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
2549 groupInfo.second.latestKeyMemberMap_ = {};
2552 __GEN_COUTV__(runTimeSeconds());
2554 catch(
const std::runtime_error& e)
2556 __SS__ <<
"A fatal error occurred reading the info for all table groups. Error: "
2557 << e.what() << __E__;
2558 __GEN_COUT_ERR__ <<
"\n" << ss.str();
2559 if(accumulatedWarnings)
2560 *accumulatedWarnings += ss.str();
2566 __SS__ <<
"An unknown fatal error occurred reading the info for all table groups."
2568 __GEN_COUT_ERR__ <<
"\n" << ss.str();
2569 if(accumulatedWarnings)
2570 *accumulatedWarnings += ss.str();
2574 __GEN_COUT__ <<
"Group Info end runTimeSeconds()=" << runTimeSeconds() << __E__;
2579 __GEN_COUT__ <<
"Loading table..." << __E__;
2585 __GEN_COUT__ << __E__;
2587 __GEN_COUT__ <<
"Value: " << v << __E__;
2588 __GEN_COUT__ <<
"Value index: " << t.
getValue<
int>() << __E__;
2594 __GEN_COUT__ <<
"Failed to load table..." << __E__;
TableVersion saveNewVersion(TableBase *configuration, TableVersion temporaryVersion, TableVersion newVersion=TableVersion())
std::map< std::string, std::map< std::string, TableVersion > > getVersionAliases(void) const
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 onlyLoadIfBackboneOrContext=ConfigurationManager::LoadGroupType::ALL_TYPES, bool ignoreVersionTracking=false)
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 init(std::string *accumulatedErrors=0, bool initForWriteAccess=false, std::string *accumulatedWarnings=0)
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
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())
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)
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
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
const GroupInfo & getGroupInfo(const std::string &groupName)
public group cache handling
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())
TableBase * getVersionedTableByName(const std::string &tableName, TableVersion version, bool looseColumnMatching=false, std::string *accumulatedErrors=0, bool getRawData=false)
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)
compareTableGroupThread()
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()
static void loadTableInfoThread(ConfigurationManagerRW *cfgMgr, std::string tableName, TableBase *existingTable, std::shared_ptr< ots::TableInfo > tableInfo, std::shared_ptr< std::atomic< bool >> threadDone)
loadTableInfoThread()
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)
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="")
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)
int fillFromJSON(const std::string &json)
unsigned int findCol(const std::string &name) const
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 mapToString(const std::map< std::string, T > &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
static std::string stackTrace(void)