$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef _ots_TableView_h_ 00002 #define _ots_TableView_h_ 00003 00004 #include "otsdaq-core/Macros/CoutMacros.h" 00005 #include "otsdaq-core/Macros/StringMacros.h" 00006 #include "otsdaq-core/MessageFacility/MessageFacility.h" 00007 00008 #include <stdlib.h> 00009 #include <time.h> /* time_t, time, ctime */ 00010 #include <cassert> 00011 #include <iostream> 00012 #include <set> 00013 #include <vector> 00014 #include "otsdaq-core/TableCore/TableVersion.h" 00015 #include "otsdaq-core/TableCore/TableViewColumnInfo.h" 00016 00017 namespace ots 00018 { 00019 class TableView 00020 { 00021 public: 00022 static const unsigned int INVALID; 00023 typedef std::vector<std::vector<std::string> > DataView; 00024 typedef DataView::iterator iterator; 00025 typedef DataView::const_iterator const_iterator; 00026 00027 TableView(const std::string& name = ""); 00028 virtual ~TableView(void); 00029 00030 void init(void); 00031 TableView& copy(const TableView& src, 00032 TableVersion destinationVersion, 00033 const std::string& author); 00034 unsigned int copyRows(const std::string& author, 00035 const TableView& src, 00036 unsigned int srcOffsetRow = 0, 00037 unsigned int srcRowsToCopy = (unsigned int)-1, 00038 unsigned int destOffsetRow = (unsigned int)-1, 00039 bool generateUniqueDataColumns = false); 00040 00041 template<class T> // in included .icc source 00042 unsigned int findRow(unsigned int col, 00043 const T& value, 00044 unsigned int offsetRow = 0) const; 00045 unsigned int findRow(unsigned int col, 00046 const std::string& value, 00047 unsigned int offsetRow = 0) const; 00048 00049 template<class T> // in included .icc source 00050 unsigned int findRowInGroup(unsigned int col, 00051 const T& value, 00052 const std::string& groupId, 00053 const std::string& childLinkIndex, 00054 unsigned int offsetRow = 0) const; 00055 unsigned int findRowInGroup(unsigned int col, 00056 const std::string& value, 00057 const std::string& groupId, 00058 const std::string& childLinkIndex, 00059 unsigned int offsetRow = 0) const; 00060 unsigned int findCol(const std::string& name) const; 00061 unsigned int findColByType(const std::string& type, int startingCol = 0) const; 00062 00063 // Getters 00064 const std::string& getUniqueStorageIdentifier(void) const; 00065 const std::string& getTableName(void) const; 00066 const TableVersion& getVersion(void) const; 00067 const std::string& getComment(void) const; 00068 const std::string& getAuthor(void) const; 00069 const time_t& getCreationTime(void) const; 00070 const time_t& getLastAccessTime(void) const; 00071 const bool& getLooseColumnMatching(void) const; 00072 const unsigned int getDataColumnSize(void) const; 00073 const unsigned int& getSourceColumnMismatch(void) const; 00074 const unsigned int& getSourceColumnMissing(void) const; 00075 const std::set<std::string>& getSourceColumnNames(void) const; 00076 std::set<std::string> getColumnNames(void) const; 00077 std::set<std::string> getColumnStorageNames(void) const; 00078 std::vector<std::string> getDefaultRowValues(void) const; 00079 00080 unsigned int getNumberOfRows(void) const; 00081 unsigned int getNumberOfColumns(void) const; 00082 const unsigned int getColUID(void) const; 00083 const unsigned int getColStatus(void) const; 00084 const unsigned int getColPriority(void) const; 00085 00086 // Note: Group link handling should be done in this TableView class 00087 // only by using isEntryInGroup ... 00088 // This is so that multiple group handling is consistent 00089 private: 00090 bool isEntryInGroupCol(const unsigned int& row, 00091 const unsigned int& groupCol, 00092 const std::string& groupNeedle, 00093 std::set<std::string>* groupIDList = 0) const; 00094 00095 public: 00096 // std::set<std::string /*GroupId*/> 00097 std::set<std::string> getSetOfGroupIDs(const std::string& childLinkIndex, 00098 unsigned int row = -1) const; 00099 std::set<std::string> getSetOfGroupIDs(const unsigned int& col, 00100 unsigned int row = -1) const; 00101 bool isEntryInGroup(const unsigned int& row, 00102 const std::string& childLinkIndex, 00103 const std::string& groupNeedle) const; 00104 const bool getChildLink(const unsigned int& col, 00105 bool& isGroup, 00106 std::pair<unsigned int /*link col*/, 00107 unsigned int /*link id col*/>& linkPair) const; 00108 const unsigned int getColLinkGroupID(const std::string& childLinkIndex) const; 00109 void addRowToGroup(const unsigned int& row, 00110 const unsigned int& col, 00111 const std::string& groupID); //, const std::string& colDefault); 00112 bool removeRowFromGroup(const unsigned int& row, 00113 const unsigned int& col, 00114 const std::string& groupID, 00115 bool deleteRowIfNoGroupLeft = false); 00116 00117 template<class T> // in included .icc source 00118 void getValue(T& value, 00119 unsigned int row, 00120 unsigned int col, 00121 bool doConvertEnvironmentVariables = true) const; 00122 // special version of getValue for string type 00123 // Note: necessary because types of std::basic_string<char> cause compiler problems 00124 // if no string specific function 00125 void getValue(std::string& value, 00126 unsigned int row, 00127 unsigned int col, 00128 bool doConvertEnvironmentVariables = true) const; 00129 00130 template<class T> // in included .icc source 00131 T validateValueForColumn(const std::string& value, 00132 unsigned int col, 00133 bool doConvertEnvironmentVariables = true) const; 00134 // special version of getValue for string type 00135 // Note: necessary because types of std::basic_string<char> cause compiler problems 00136 // if no string specific function 00137 std::string validateValueForColumn(const std::string& value, 00138 unsigned int col, 00139 bool convertEnvironmentVariables = true) const; 00140 std::string getValueAsString(unsigned int row, 00141 unsigned int col, 00142 bool convertEnvironmentVariables = true) const; 00143 std::string getEscapedValueAsString(unsigned int row, 00144 unsigned int col, 00145 bool convertEnvironmentVariables = true) const; 00146 bool isURIEncodedCommentTheSame(const std::string& comment) const; 00147 00148 const DataView& getDataView(void) const; 00149 const std::vector<TableViewColumnInfo>& getColumnsInfo(void) const; 00150 std::vector<TableViewColumnInfo>* getColumnsInfoP(void); 00151 const TableViewColumnInfo& getColumnInfo(unsigned int column) const; 00152 00153 // Setters 00154 00155 void setUniqueStorageIdentifier(const std::string& storageUID); 00156 void setTableName(const std::string& name); 00157 void setComment(const std::string& comment); 00158 void setURIEncodedComment(const std::string& uriComment); 00159 void setAuthor(const std::string& author); 00160 void setCreationTime(time_t t); 00161 void setLastAccessTime(time_t t = time(0)); 00162 void setLooseColumnMatching(bool setValue); 00163 00164 template<class T> // in included .icc source 00165 void setVersion(const T& version); 00166 template<class T> // in included .icc source 00167 void setValue(const T& value, unsigned int row, unsigned int col); 00168 void setValue(const std::string& value, unsigned int row, unsigned int col); 00169 void setValue(const char* value, unsigned int row, unsigned int col); 00170 00171 // Careful: The setValueAsString method is used to set the value without any 00172 // consistency check with the data type 00173 void setValueAsString(const std::string& value, unsigned int row, unsigned int col); 00174 00175 void resizeDataView(unsigned int nRows, unsigned int nCols); 00176 unsigned int addRow( 00177 const std::string& author = "", 00178 bool incrementUniqueData = false, 00179 std::string baseNameAutoUID = "", 00180 unsigned int rowToAdd = 00181 (unsigned int)-1); // returns index of added row, default is last row 00182 void deleteRow(int r); 00183 00184 // Lore did not like this.. wants special access through separate Supervisor for 00185 // "Database Management" int addColumn(std::string name, std::string viewName, 00186 // std::string viewType); //returns index of added column, always is last column 00187 // unless 00188 00189 iterator begin(void) { return theDataView_.begin(); } 00190 iterator end(void) { return theDataView_.end(); } 00191 const_iterator begin(void) const { return theDataView_.begin(); } 00192 const_iterator end(void) const { return theDataView_.end(); } 00193 void reset(void); 00194 void print(std::ostream& out = std::cout) const; 00195 void printJSON(std::ostream& out = std::cout) const; 00196 int fillFromJSON(const std::string& json); 00197 int fillFromCSV(const std::string& data, 00198 const int& dataOffset = 0, 00199 const std::string& author = ""); 00200 bool setURIEncodedValue(const std::string& value, 00201 const unsigned int& row, 00202 const unsigned int& col, 00203 const std::string& author = ""); 00204 00205 private: 00206 const unsigned int getOrInitColUID(void); 00207 const unsigned int getOrInitColStatus(void); 00208 const unsigned int getOrInitColPriority(void); 00209 00210 TableView& operator=(const TableView src); // operator= is purposely undefined and 00211 // private (DO NOT USE IT!) - should use 00212 // TableView::copy() 00213 00214 std::string uniqueStorageIdentifier_; // starts empty "", used to implement 00215 // re-writable views ("temporary views") in 00216 // artdaq db 00217 std::string tableName_; // View name (extensionTableName in xml) 00218 TableVersion version_; // Table version 00219 std::string comment_; // Table version comment 00220 std::string author_; 00221 time_t creationTime_; // used more like "construction"(constructor) time 00222 time_t lastAccessTime_; // last time the ConfigurationInterface:get() retrieved this 00223 // view 00224 unsigned int colUID_, colStatus_, colPriority_; // special column pointers 00225 std::map<std::string, unsigned int> 00226 colLinkGroupIDs_; // map from child link index to column 00227 00228 bool fillWithLooseColumnMatching_; 00229 unsigned int sourceColumnMismatchCount_, sourceColumnMissingCount_; 00230 std::set<std::string> sourceColumnNames_; 00231 00232 std::vector<TableViewColumnInfo> columnsInfo_; 00233 DataView theDataView_; 00234 }; 00235 00236 #include "otsdaq-core/TableCore/TableView.icc" //define template functions 00237 00238 } // namespace ots 00239 00240 #endif