1 #include "otsdaq/TableCore/TableBase.h"
6 #include "otsdaq/TableCore/TableInfoReader.h"
11 #define __MF_SUBJECT__ "TableBase"
13 #define __COUT_HDR__ ("TableBase-" + getTableName() + "\t<> ")
21 TableBase::TableBase(
const std::string& tableName,
22 std::string* accumulatedExceptions)
23 : MAX_VIEWS_IN_CACHE(20)
25 , tableName_(tableName)
27 , mockupTableView_(tableName)
31 __SS__ <<
"Do not allow anonymous table view construction!" << __E__;
32 ss << StringMacros::stackTrace() << __E__;
36 bool dbg = tableName ==
"ARTDAQEventBuilderTable";
37 if(dbg) __COUTV__(tableName);
40 if(dbg) __COUT__ <<
"Reading..." << __E__;
43 std::string returnedExceptions = tableInfoReader.read(
this);
44 if(dbg) __COUT__ <<
"Read.";
45 if(returnedExceptions !=
"")
46 __COUT_ERR__ << returnedExceptions << __E__;
48 if(accumulatedExceptions)
49 *accumulatedExceptions += std::string(
"\n") + returnedExceptions;
53 __SS__ <<
"Failure in tableInfoReader.read(this). "
54 <<
"Perhaps you need to run otsdaq_convert_config_to_table ?" << __E__;
55 __COUT_ERR__ <<
"\n" << ss.str();
56 if(accumulatedExceptions)
57 *accumulatedExceptions += std::string(
"\n") + ss.str();
62 if(dbg) __COUT__ <<
"Initializing..." << __E__;
66 getMockupViewP()->init();
67 if(dbg) __COUT__ <<
"Init." << __E__;
69 catch(std::runtime_error& e)
71 if(accumulatedExceptions)
72 *accumulatedExceptions += std::string(
"\n") + e.what();
83 TableBase::TableBase(
bool specialTable,
const std::string& specialTableName)
84 : MAX_VIEWS_IN_CACHE(1)
86 , tableName_(specialTableName)
88 , mockupTableView_(specialTableName)
90 __COUT__ <<
"Special table '" << tableName_ <<
"' constructed. " << specialTable << __E__;
104 TableBase::~TableBase(
void) {}
107 std::string TableBase::getTypeId() {
return typeid(
this).name(); }
116 void TableBase::reset(
bool keepTemporaryVersions)
120 if(keepTemporaryVersions)
127 void TableBase::print(std::ostream& out)
const
131 if(!activeTableView_)
133 __COUT_ERR__ <<
"ERROR: No active view set" << __E__;
136 activeTableView_->print(out);
144 if(!isStored(version))
146 tableViews_.emplace(std::make_pair(version,
TableView(tableName_)));
147 tableViews_.at(version).copy(mockupTableView_, version, mockupTableView_.getAuthor());
149 if(!isStored(version))
151 __SS__ <<
"IMPOSSIBLE ERROR: trimCache() is deleting the "
152 "latest view version "
153 << version <<
"!" << __E__;
159 __SS__ <<
"View to fill with mockup already exists: " << version <<
". Cannot overwrite!" << __E__;
160 ss << StringMacros::stackTrace() << __E__;
170 void TableBase::trimCache(
unsigned int trimSize)
174 if(trimSize == (
unsigned int)-1)
175 trimSize = MAX_VIEWS_IN_CACHE;
178 while(getNumberOfStoredViews() > trimSize)
181 time_t stalestTime = -1;
183 for(
auto& viewPair : tableViews_)
184 if(!viewPair.first.isTemporaryVersion())
186 if(stalestTime == -1 || viewPair.second.getLastAccessTime() < stalestTime)
188 versionToDelete = viewPair.first;
189 stalestTime = viewPair.second.getLastAccessTime();
195 if(versionToDelete.isInvalid())
197 __SS__ <<
"Can NOT have a stored view with an invalid version!" << __E__;
201 eraseView(versionToDelete);
210 void TableBase::trimTemporary(
TableVersion targetVersion)
212 if(targetVersion.isInvalid())
214 for(
auto it = tableViews_.begin(); it != tableViews_.end(); )
216 if(it->first.isTemporaryVersion())
219 if(activeTableView_ && getViewVersion() == it->first)
222 tableViews_.erase(it++);
228 else if(targetVersion.isTemporaryVersion())
231 eraseView(targetVersion);
236 __SS__ <<
"Temporary trim target was a persistent version: " << targetVersion << __E__;
237 __COUT_ERR__ <<
"\n" << ss.str();
253 auto needleIt = tableViews_.find(needleVersion);
254 if(needleIt == tableViews_.end())
257 __SS__ <<
"needleVersion does not exist: " << needleVersion << __E__;
258 __COUT_ERR__ <<
"\n" << ss.str();
262 const TableView* needleView = &(needleIt->second);
263 unsigned int rows = needleView->getNumberOfRows();
264 unsigned int cols = needleView->getNumberOfColumns();
267 unsigned int potentialMatchCount = 0;
273 auto viewPairReverseIterator = tableViews_.rbegin();
274 for(; viewPairReverseIterator != tableViews_.rend(); ++viewPairReverseIterator)
276 if(viewPairReverseIterator->first == needleVersion)
278 if(viewPairReverseIterator->first == ignoreVersion)
280 if(viewPairReverseIterator->first.isTemporaryVersion())
283 if(viewPairReverseIterator->second.getNumberOfRows() != rows)
286 if(viewPairReverseIterator->second.getDataColumnSize() != cols || viewPairReverseIterator->second.getSourceColumnMismatch() != 0)
289 ++potentialMatchCount;
290 __COUT__ <<
"Checking version... " << viewPairReverseIterator->first << __E__;
298 match = viewPairReverseIterator->second.getSourceColumnNames().size() == needleView->getSourceColumnNames().size();
301 for(
auto& haystackColName : viewPairReverseIterator->second.getSourceColumnNames())
302 if(needleView->getSourceColumnNames().find(haystackColName) == needleView->getSourceColumnNames().end())
304 __COUT__ <<
"Found column name mismatch for '" << haystackColName <<
"'... So allowing same data!" << __E__;
326 for(
unsigned int row = 0; match && row < rows; ++row)
328 for(
unsigned int col = 0; col < cols - 2; ++col)
329 if(viewPairReverseIterator->second.getDataView()[row][col] != needleView->getDataView()[row][col])
352 __COUT_INFO__ <<
"Duplicate version found: " << viewPairReverseIterator->first << __E__;
353 return viewPairReverseIterator->first;
357 __COUT__ <<
"No duplicates found in " << potentialMatchCount <<
" potential matches." << __E__;
364 auto tmpIt = tableViews_.find(temporaryVersion);
365 if(tableViews_.find(temporaryVersion) == tableViews_.end())
367 __SS__ <<
"ERROR: Temporary view version " << temporaryVersion <<
" doesn't exists!" << __E__;
368 __COUT_ERR__ <<
"\n" << ss.str();
371 if(version.isInvalid())
373 __SS__ <<
"ERROR: Attempting to create an invalid version " << version <<
"! Did you really run out of versions? (this should never happen)" << __E__;
374 __COUT_ERR__ <<
"\n" << ss.str();
378 if(tableViews_.find(version) != tableViews_.end())
379 __COUT_WARN__ <<
"WARNING: View version " << version <<
" already exists! Overwriting." << __E__;
381 auto emplacePair = tableViews_.emplace(std::make_pair(version,
TableView(tableName_)));
382 emplacePair.first->second.copy(tmpIt->second, version, tmpIt->second.getAuthor());
383 setActiveView(version);
384 eraseView(temporaryVersion);
388 bool TableBase::isStored(
const TableVersion& version)
const {
return (tableViews_.find(version) != tableViews_.end()); }
393 if(!isStored(version))
396 if(activeTableView_ && getViewVersion() == version)
399 tableViews_.erase(version);
405 const std::string& TableBase::getTableName(
void)
const {
return tableName_; }
408 const std::string& TableBase::getTableDescription(
void)
const {
return tableDescription_; }
411 const TableVersion& TableBase::getViewVersion(
void)
const {
return getView().getVersion(); }
416 bool TableBase::latestAndMockupColumnNumberMismatch(
void)
const
418 std::set<TableVersion> retSet = getStoredVersions();
419 if(retSet.size() && !retSet.rbegin()->isTemporaryVersion())
421 return tableViews_.find(*(retSet.rbegin()))->second.getNumberOfColumns() != mockupTableView_.getNumberOfColumns();
428 std::set<TableVersion> TableBase::getStoredVersions(
void)
const
430 std::set<TableVersion> retSet;
431 for(
auto& configs : tableViews_)
432 retSet.emplace(configs.first);
440 unsigned int TableBase::getNumberOfStoredViews(
void)
const
443 for(
auto& viewPair : tableViews_)
444 if(viewPair.first.isTemporaryVersion())
446 else if(viewPair.first.isInvalid())
456 __COUT__ <<
"There is an invalid version now!.. where did it come from?" << __E__;
464 const TableView& TableBase::getView(
void)
const
466 if(!activeTableView_)
468 __SS__ <<
"There is no active table view setup! Please check your system configuration." << __E__;
471 return *activeTableView_;
477 if(!activeTableView_)
479 __SS__ <<
"There is no active table view setup! Please check your system configuration." << __E__;
482 return activeTableView_;
486 TableView* TableBase::getMockupViewP(
void) {
return &mockupTableView_; }
489 void TableBase::setTableName(
const std::string& tableName) { tableName_ = tableName; }
492 void TableBase::setTableDescription(
const std::string& tableDescription) { tableDescription_ = tableDescription; }
497 void TableBase::deactivate() { activeTableView_ = 0; }
501 bool TableBase::isActive() {
return activeTableView_ ?
true :
false; }
506 if(!isStored(version))
511 __SS__ <<
"\nsetActiveView() ERROR: View with version " << version <<
" has never been stored before!" << __E__;
515 activeTableView_ = &tableViews_.at(version);
517 if(tableViews_.at(version).getVersion() != version)
519 __SS__ <<
"Something has gone very wrong with the version handling!" << __E__;
538 const std::string& author,
539 const std::string& mergeApproach ,
540 std::map<std::pair<std::string /*original table*/, std::string /*original uidB*/>, std::string >& uidConversionMap,
541 std::map<std::pair<std::string , std::pair<std::string /*group linkid*/, std::string /*original gidB*/> >,
542 std::string >& groupidConversionMap,
543 bool fillRecordConversionMaps,
544 bool applyRecordConversionMaps,
545 bool generateUniqueDataColumns)
547 __COUT__ <<
"mergeViews starting..." << __E__;
559 if(!(mergeApproach ==
"Rename" || mergeApproach ==
"Replace" || mergeApproach ==
"Skip"))
561 __SS__ <<
"Error! Invalid merge approach '" << mergeApproach <<
".'" << __E__;
566 if(sourceViewA.getNumberOfColumns() != mockupTableView_.getNumberOfColumns())
568 __SS__ <<
"Error! Number of Columns of source view A must match destination "
570 <<
"Dimension of source is [" << sourceViewA.getNumberOfColumns() <<
"] and of destination mockup is [" << mockupTableView_.getNumberOfColumns()
575 if(sourceViewB.getNumberOfColumns() != mockupTableView_.getNumberOfColumns())
577 __SS__ <<
"Error! Number of Columns of source view B must match destination "
579 <<
"Dimension of source is [" << sourceViewB.getNumberOfColumns() <<
"] and of destination mockup is [" << mockupTableView_.getNumberOfColumns()
589 if(fillRecordConversionMaps && mergeApproach ==
"Rename")
591 __COUT__ <<
"Filling record conversion map." << __E__;
601 unsigned int uniqueId;
602 std::string uniqueIdString, uniqueIdBase;
603 char indexString[1000];
605 unsigned int numericStartIndex;
608 for(
unsigned int cb = 0; cb < sourceViewB.getNumberOfColumns(); ++cb)
611 if(!(sourceViewA.getColumnInfo(cb).isUID() || sourceViewA.getColumnInfo(cb).isGroupID()))
614 __COUT__ <<
"Have an ID column: " << cb <<
" " << sourceViewA.getColumnInfo(cb).getType() << __E__;
617 if(sourceViewA.getColumnInfo(cb).getType() != sourceViewB.getColumnInfo(cb).getType() ||
618 sourceViewA.getColumnInfo(cb).getType() != mockupTableView_.getColumnInfo(cb).getType())
620 __SS__ <<
"Error! " << sourceViewA.getColumnInfo(cb).getType() <<
" column " << cb
621 <<
" of source view A must match source B and destination mock-up "
623 <<
" Column of source B is [" << sourceViewA.getColumnInfo(cb).getType() <<
"] and of destination mockup is ["
624 << mockupTableView_.getColumnInfo(cb).getType() <<
"]." << __E__;
630 std::vector<std::string > localConvertedIds;
632 if(sourceViewA.getColumnInfo(cb).isGroupID())
634 std::set<std::string> aGroupids = sourceViewA.getSetOfGroupIDs(cb);
635 std::set<std::string> bGroupids = sourceViewB.getSetOfGroupIDs(cb);
637 for(
const auto& bGroupid : bGroupids)
639 if(aGroupids.find(bGroupid) == aGroupids.end())
643 __COUT__ <<
"found conflict: " << getTableName() <<
"/" << bGroupid << __E__;
647 const std::string& str = bGroupid;
648 numericStartIndex = str.size();
651 while(numericStartIndex - 1 < str.size() && str[numericStartIndex - 1] >=
'0' && str[numericStartIndex - 1] <=
'9')
654 if(numericStartIndex < str.size())
656 uniqueId = atoi(str.substr(numericStartIndex).c_str()) + 1;
657 uniqueIdBase = str.substr(0, numericStartIndex);
665 __COUTV__(uniqueIdBase);
671 sprintf(indexString,
"%u", uniqueId);
672 uniqueIdString = uniqueIdBase + indexString;
673 __COUTV__(uniqueIdString);
677 if(aGroupids.find(uniqueIdString) != aGroupids.end())
679 if(!found && bGroupids.find(uniqueIdString) != bGroupids.end())
681 if(!found && bGroupids.find(uniqueIdString) != bGroupids.end())
683 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
684 if(localConvertedIds[ra] == uniqueIdString)
690 sprintf(indexString,
"%u", uniqueId);
691 uniqueIdString = uniqueIdBase + indexString;
692 __COUTV__(uniqueIdString);
696 if(aGroupids.find(uniqueIdString) != aGroupids.end())
698 if(!found && bGroupids.find(uniqueIdString) != bGroupids.end())
700 if(!found && bGroupids.find(uniqueIdString) != bGroupids.end())
702 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
703 if(localConvertedIds[ra] == uniqueIdString)
709 __COUTV__(uniqueIdString);
711 groupidConversionMap[std::pair<std::string , std::pair<std::string , std::string > >(
713 std::pair<std::string , std::string >(sourceViewB.getColumnInfo(cb).getChildLinkIndex(), bGroupid))] =
715 localConvertedIds.push_back(uniqueIdString);
722 __COUTV__(StringMacros::mapToString(groupidConversionMap));
727 for(
unsigned int rb = 0; rb < sourceViewB.getNumberOfRows(); ++rb)
731 for(ra = 0; ra < sourceViewA.getDataView().size(); ++ra)
732 if(sourceViewA.getValueAsString(ra, cb) == sourceViewB.getValueAsString(rb, cb))
742 __COUT__ <<
"found conflict: " << getTableName() <<
"/" << sourceViewB.getDataView()[rb][cb] << __E__;
746 const std::string& str = sourceViewB.getDataView()[rb][cb];
747 numericStartIndex = str.size();
750 while(numericStartIndex - 1 < str.size() && str[numericStartIndex - 1] >=
'0' && str[numericStartIndex - 1] <=
'9')
753 if(numericStartIndex < str.size())
755 uniqueId = atoi(str.substr(numericStartIndex).c_str()) + 1;
756 uniqueIdBase = str.substr(0, numericStartIndex);
764 __COUTV__(uniqueIdBase);
770 sprintf(indexString,
"%u", uniqueId);
771 uniqueIdString = uniqueIdBase + indexString;
772 __COUTV__(uniqueIdString);
776 for(ra = 0; !found && ra < sourceViewA.getDataView().size(); ++ra)
777 if(sourceViewA.getValueAsString(ra, cb) == uniqueIdString)
779 for(ra = 0; !found && ra < sourceViewB.getDataView().size(); ++ra)
782 else if(sourceViewB.getValueAsString(ra, cb) == uniqueIdString)
784 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
785 if(localConvertedIds[ra] == uniqueIdString)
791 sprintf(indexString,
"%u", uniqueId);
792 uniqueIdString = uniqueIdBase + indexString;
793 __COUTV__(uniqueIdString);
797 for(ra = 0; !found && ra < sourceViewA.getDataView().size(); ++ra)
798 if(sourceViewA.getValueAsString(ra, cb) == uniqueIdString)
800 for(ra = 0; !found && ra < sourceViewB.getDataView().size(); ++ra)
803 else if(sourceViewB.getValueAsString(ra, cb) == uniqueIdString)
805 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
806 if(localConvertedIds[ra] == uniqueIdString)
812 __COUTV__(uniqueIdString);
814 uidConversionMap[std::pair<std::string , std::string >(
815 getTableName(), sourceViewB.getValueAsString(rb, cb))] = uniqueIdString;
816 localConvertedIds.push_back(uniqueIdString);
823 __COUTV__(StringMacros::mapToString(uidConversionMap));
830 __COUT__ <<
"Not filling record conversion map." << __E__;
832 if(!applyRecordConversionMaps)
834 __COUT__ <<
"Not applying record conversion map." << __E__;
839 __COUT__ <<
"Applying record conversion map." << __E__;
840 __COUTV__(StringMacros::mapToString(uidConversionMap));
841 __COUTV__(StringMacros::mapToString(groupidConversionMap));
845 destinationVersion = createTemporaryView(
TableVersion(), destinationVersion);
847 __COUT__ <<
"Merging from (A) " << sourceViewA.getTableName() <<
"_v" << sourceViewA.getVersion() <<
" and (B) " << sourceViewB.getTableName() <<
"_v"
848 << sourceViewB.getVersion() <<
" to " << getTableName() <<
"_v" << destinationVersion <<
" with approach '" << mergeApproach <<
".'" << __E__;
855 tableViews_.emplace(std::make_pair(destinationVersion,
TableView(getTableName())));
856 TableView* destinationView = &(tableViews_.at(destinationVersion).copy(
857 sourceViewA, destinationVersion, author));
859 unsigned int destRow, destSize = destinationView->getDataView().size();
862 std::map<std::pair<std::string , std::string >, std::string >::iterator uidConversionIt;
863 std::map<std::pair<std::string , std::pair<std::string , std::string > >,
864 std::string >::iterator groupidConversionIt;
867 std::pair<
unsigned int ,
unsigned int > linkPair;
871 unsigned int colUID = mockupTableView_.getColUID();
874 for(
unsigned int rb = 0; rb < sourceViewB.getNumberOfRows(); ++rb)
876 if(mergeApproach ==
"Rename")
886 destRow = destinationView->copyRows(
887 author, sourceViewB, rb, 1 , -1 , generateUniqueDataColumns );
891 for(cb = 0; cb < sourceViewB.getNumberOfColumns(); ++cb)
893 if(sourceViewB.getColumnInfo(cb).isChildLink())
895 else if(sourceViewB.getColumnInfo(cb).isChildLinkUID())
897 __COUT__ <<
"Checking UID link... col=" << cb << __E__;
898 sourceViewB.getChildLink(cb, linkIsGroup, linkPair);
901 if((uidConversionIt = uidConversionMap.find(std::pair<std::string /*original table*/, std::string /*original uidB*/>(
902 sourceViewB.getValueAsString(rb, linkPair.first), sourceViewB.getValueAsString(rb, linkPair.second)))) !=
903 uidConversionMap.end())
905 __COUT__ <<
"Found entry to remap: " << sourceViewB.getDataView()[rb][linkPair.second] <<
" ==> " << uidConversionIt->second
907 destinationView->setValueAsString(uidConversionIt->second, destRow, linkPair.second);
910 else if(sourceViewB.getColumnInfo(cb).isChildLinkGroupID())
912 __COUT__ <<
"Checking GroupID link... col=" << cb << __E__;
913 sourceViewB.getChildLink(cb, linkIsGroup, linkPair);
916 if((groupidConversionIt = groupidConversionMap.find(
917 std::pair<std::string , std::pair<std::string /*group linkid*/, std::string /*original gidB*/> >(
918 sourceViewB.getValueAsString(rb, linkPair.first),
919 std::pair<std::string , std::string >(
920 sourceViewB.getColumnInfo(cb).getChildLinkIndex(), sourceViewB.getValueAsString(rb, linkPair.second))))) !=
921 groupidConversionMap.end())
923 __COUT__ <<
"Found entry to remap: " << sourceViewB.getDataView()[rb][linkPair.second] <<
" ==> " << groupidConversionIt->second
925 destinationView->setValueAsString(groupidConversionIt->second, destRow, linkPair.second);
928 else if(sourceViewB.getColumnInfo(cb).isUID())
930 __COUT__ <<
"Checking UID... col=" << cb << __E__;
931 if((uidConversionIt = uidConversionMap.find(std::pair<std::string /*original table*/, std::string /*original uidB*/>(
932 getTableName(), sourceViewB.getValueAsString(rb, cb)))) != uidConversionMap.end())
934 __COUT__ <<
"Found entry to remap: " << sourceViewB.getDataView()[rb][cb] <<
" ==> " << uidConversionIt->second << __E__;
935 destinationView->setValueAsString(uidConversionIt->second, destRow, cb);
938 else if(sourceViewB.getColumnInfo(cb).isGroupID())
940 __COUT__ <<
"Checking GroupID... col=" << cb << __E__;
941 if((groupidConversionIt = groupidConversionMap.find(
942 std::pair<std::string , std::pair<std::string /*group linkid*/, std::string /*original gidB*/> >(
944 std::pair<std::string /*group linkid*/, std::string /*original gidB*/>(sourceViewB.getColumnInfo(cb).getChildLinkIndex(),
945 sourceViewB.getValueAsString(rb, cb))))) !=
946 groupidConversionMap.end())
948 __COUT__ <<
"Found entry to remap: " << sourceViewB.getDataView()[rb][cb] <<
" ==> " << groupidConversionIt->second << __E__;
949 destinationView->setValueAsString(groupidConversionIt->second, destRow, cb);
955 strb = sourceViewB.getValueAsString(rb, cb);
956 if(strb.size() > getTableName().size() + 2 && strb[0] ==
'/')
959 __COUT__ <<
"Checking col" << cb <<
" " << strb << __E__;
962 for(
const auto& mapPairToPair : uidConversionMap)
964 if((stri = strb.find(mapPairToPair.first.first +
"/" + mapPairToPair.first.second)) != std::string::npos)
966 __COUT__ <<
"Found a text link match (stri=" << stri <<
")! "
967 << (mapPairToPair.first.first +
"/" + mapPairToPair.first.second) <<
" ==> " << mapPairToPair.second << __E__;
970 destinationView->setValueAsString(
971 strb.substr(0, stri) + (mapPairToPair.first.first +
"/" + mapPairToPair.first.second) +
972 strb.substr(stri + (mapPairToPair.first.first +
"/" + mapPairToPair.first.second).size()),
976 __COUT__ <<
"Found entry to remap: " << sourceViewB.getDataView()[rb][cb] <<
" ==> "
977 << destinationView->getDataView()[destRow][cb] << __E__;
992 for(destRow = 0; destRow < destSize; ++destRow)
993 if(destinationView->getValueAsString(destRow, colUID) == sourceViewB.getValueAsString(rb, colUID))
1000 __COUT__ <<
"No " << mergeApproach <<
" conflict: " << __E__;
1002 if(mergeApproach ==
"replace" || mergeApproach ==
"skip")
1006 destinationView->copyRows(author, sourceViewB, rb, 1 );
1015 __COUT__ <<
"found " << mergeApproach <<
" conflict: " << sourceViewB.getDataView()[rb][colUID] << __E__;
1017 if(mergeApproach ==
"replace")
1023 destinationView->deleteRow(destRow--);
1028 destinationView->copyRows(author, sourceViewB, rb, 1 );
1033 destinationView->print();
1037 __COUT_ERR__ <<
"Failed to merge " << sourceViewA.getTableName() <<
"_v" << sourceViewA.getVersion() <<
" and " << sourceViewB.getTableName() <<
"_v"
1038 << sourceViewB.getVersion() <<
" into " << getTableName() <<
"_v" << destinationVersion << __E__;
1039 __COUT_WARN__ <<
"Deleting the failed destination version " << destinationVersion << __E__;
1040 eraseView(destinationVersion);
1044 return destinationVersion;
1058 if(sourceView.getNumberOfColumns() != mockupTableView_.getNumberOfColumns())
1060 __SS__ <<
"Error! Number of Columns of source view must match destination "
1062 <<
"Dimension of source is [" << sourceView.getNumberOfColumns() <<
"] and of destination mockup is [" << mockupTableView_.getNumberOfColumns()
1068 if(!destinationVersion.isInvalid() && tableViews_.find(destinationVersion) != tableViews_.end())
1070 __SS__ <<
"Error! Asked to copy a view with a conflicting version: " << destinationVersion << __E__;
1075 destinationVersion = createTemporaryView(
TableVersion(), destinationVersion);
1077 __COUT__ <<
"Copying from " << sourceView.getTableName() <<
"_v" << sourceView.getVersion() <<
" to " << getTableName() <<
"_v" << destinationVersion
1082 tableViews_.emplace(std::make_pair(destinationVersion,
TableView(tableName_)));
1083 tableViews_.at(destinationVersion).copy(sourceView, destinationVersion, author);
1087 __COUT_ERR__ <<
"Failed to copy from " << sourceView.getTableName() <<
"_v" << sourceView.getVersion() <<
" to " << getTableName() <<
"_v"
1088 << destinationVersion << __E__;
1089 __COUT_WARN__ <<
"Deleting the failed destination version " << destinationVersion << __E__;
1090 eraseView(destinationVersion);
1094 return destinationVersion;
1113 if(tmpVersion.isInvalid())
1114 tmpVersion = TableVersion::getNextTemporaryVersion();
1115 while(isStored(tmpVersion) &&
1116 !(tmpVersion = TableVersion::getNextTemporaryVersion(tmpVersion)).isInvalid())
1118 if(isStored(tmpVersion) || tmpVersion.isInvalid())
1120 __SS__ <<
"Invalid destination temporary version: " << destTemporaryViewVersion <<
". Expected next temporary version < " << tmpVersion << __E__;
1121 __COUT_ERR__ << ss.str();
1125 if(sourceViewVersion == TableVersion::INVALID ||
1126 tableViews_.find(sourceViewVersion) == tableViews_.end())
1128 if(sourceViewVersion != -1)
1130 __SS__ <<
"ERROR: sourceViewVersion " << sourceViewVersion <<
" not found. "
1131 <<
"Invalid source version. Version requested is not stored (yet?) or "
1134 __COUT_ERR__ << ss.str();
1137 __COUT__ <<
"Using Mock-up view" << __E__;
1138 tableViews_.emplace(std::make_pair(tmpVersion,
TableView(tableName_)));
1139 tableViews_.at(tmpVersion).copy(mockupTableView_, tmpVersion, mockupTableView_.getAuthor());
1145 tableViews_.emplace(std::make_pair(tmpVersion,
TableView(tableName_)));
1146 tableViews_.at(tmpVersion).copy(
1147 tableViews_.at(sourceViewVersion), tmpVersion,
1148 tableViews_.at(sourceViewVersion).getAuthor());
1152 __COUT_WARN__ <<
"createTemporaryView() Source view failed init(). "
1153 <<
"This is being ignored (hopefully the new copy is being fixed)." << __E__;
1164 TableVersion TableBase::getNextTemporaryVersion()
const
1169 if(tableViews_.size() != 0 && tableViews_.begin()->first.isTemporaryVersion())
1170 tmpVersion = TableVersion::getNextTemporaryVersion(tableViews_.begin()->first);
1172 tmpVersion = TableVersion::getNextTemporaryVersion();
1175 if(isStored(tmpVersion) || tmpVersion.isInvalid() || !tmpVersion.isTemporaryVersion())
1177 __SS__ <<
"Invalid destination temporary version: " << tmpVersion << __E__;
1178 __COUT_ERR__ << ss.str();
1193 if(tableViews_.size() != 0 && !tableViews_.rbegin()->first.isTemporaryVersion())
1194 tmpVersion = TableVersion::getNextVersion(tableViews_.rbegin()->first);
1196 tmpVersion = TableVersion::getNextVersion();
1199 if(isStored(tmpVersion) || tmpVersion.isInvalid() || tmpVersion.isTemporaryVersion())
1201 __SS__ <<
"Invalid destination next version: " << tmpVersion << __E__;
1202 __COUT_ERR__ << ss.str();
1215 if(!temporaryVersion.isTemporaryVersion() || !isStored(temporaryVersion))
1217 __SS__ << getTableName() <<
":: Error! Temporary version not found!" << __E__;
1218 __COUT_ERR__ << ss.str();
1221 return &tableViews_.at(temporaryVersion);
1228 std::string TableBase::convertToCaps(std::string& str,
bool isTableName)
1231 unsigned int configPos = (
unsigned int)std::string::npos;
1232 if(isTableName && (configPos = str.find(
"Table")) != str.size() - strlen(
"Table"))
1237 std::string capsStr =
"";
1238 for(
unsigned int c = 0; c < str.size(); ++c)
1239 if(str[c] >=
'A' && str[c] <=
'Z')
1242 if(c == configPos || (c && str[c - 1] >=
'a' && str[c - 1] <=
'z') ||
1243 (c && str[c - 1] >=
'A' && str[c - 1] <=
'Z' &&
1244 c + 1 < str.size() && str[c + 1] >=
'a' && str[c + 1] <=
'z'))
1248 else if(str[c] >=
'a' && str[c] <=
'z')
1249 capsStr += char(str[c] - 32);
1250 else if(str[c] >=
'0' && str[c] <=
'9')
1253 __THROW__(std::string(
"TableBase::convertToCaps::") +
"Invalid character found in name (allowed: A-Z, a-z, 0-9):" + str);
TableVersion mergeViews(const TableView &sourceViewA, const TableView &sourceViewB, TableVersion destinationVersion, const std::string &author, const std::string &mergeApproach, std::map< std::pair< std::string, std::string >, std::string > &uidConversionMap, std::map< std::pair< std::string, std::pair< std::string, std::string > >, std::string > &groupidConversionMap, bool fillRecordConversionMaps, bool applyRecordConversionMaps, bool generateUniqueDataColumns=false)