1 #ifndef _ots_TableView_h_
2 #define _ots_TableView_h_
4 #include "otsdaq/Macros/CoutMacros.h"
5 #include "otsdaq/Macros/StringMacros.h"
6 #include "otsdaq/MessageFacility/MessageFacility.h"
15 #include "otsdaq/TableCore/TableVersion.h"
16 #include "otsdaq/TableCore/TableViewColumnInfo.h"
24 static const unsigned int INVALID;
25 typedef std::vector<std::vector<std::string> > DataView;
26 typedef DataView::iterator iterator;
27 typedef DataView::const_iterator const_iterator;
35 const std::string& author);
36 unsigned int copyRows (
const std::string& author,
38 unsigned int srcOffsetRow = 0,
39 unsigned int srcRowsToCopy = (
unsigned int)-1,
40 unsigned int destOffsetRow = (
unsigned int)-1,
41 unsigned char generateUniqueDataColumns =
false,
44 const std::string& baseNameAutoUID =
""
50 unsigned int offsetRow = 0,
51 bool doNotThrow =
false)
const;
52 unsigned int findRow (
unsigned int col,
53 const std::string& value,
54 unsigned int offsetRow = 0,
55 bool doNotThrow =
false)
const;
60 const std::string& groupId,
61 const std::string& childLinkIndex,
62 unsigned int offsetRow = 0)
const;
64 const std::string& value,
65 const std::string& groupId,
66 const std::string& childLinkIndex,
67 unsigned int offsetRow = 0)
const;
68 unsigned int findCol (
const std::string& name)
const;
69 unsigned int findColByType (
const std::string& type,
unsigned int startingCol = 0)
const;
73 const std::string& getTableName (
void)
const {
return tableName_; }
74 const TableVersion& getVersion (
void)
const {
return version_; }
75 const std::string& getComment (
void)
const {
return comment_ ==
"" ? TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT : comment_; }
76 const std::string& getAuthor (
void)
const {
return author_; }
77 const time_t& getCreationTime (
void)
const {
return creationTime_; }
78 const time_t& getLastAccessTime (
void)
const {
return lastAccessTime_; }
79 const bool& getLooseColumnMatching (
void)
const {
return fillWithLooseColumnMatching_; }
81 const unsigned int& getSourceColumnMismatch (
void)
const {
return sourceColumnMismatchCount_; }
82 const unsigned int& getSourceColumnMissing (
void)
const {
return sourceColumnMissingCount_; }
83 const std::set<std::string >& getSourceColumnNames (
void)
const {
return sourceColumnNames_; }
84 std::set<std::string > getColumnNames (
void)
const;
85 std::map<std::string,
unsigned int > getColumnNamesMap (
void)
const;
86 std::set<std::string > getColumnStorageNames (
void)
const;
87 const std::vector<std::string >& getDefaultRowValues (
void)
const {
return rowDefaultValues_; }
88 std::string getMismatchColumnInfo (
void)
const;
90 unsigned int getNumberOfRows (
void)
const {
return theDataView_.size(); }
91 unsigned int getNumberOfColumns (
void)
const {
return columnsInfo_.size(); }
100 bool isEntryInGroupCol (
const unsigned int& row,
101 const unsigned int& groupCol,
102 const std::string& groupNeedle,
103 std::set<std::string>* groupIDList = 0)
const;
107 std::set<std::string >
getSetOfGroupIDs (
const std::string& childLinkIndex,
unsigned int row = -1)
const;
108 std::set<std::string >
getSetOfGroupIDs (
const unsigned int& col,
unsigned int row = -1)
const;
110 const std::string& childLinkIndex,
111 const std::string& groupNeedle)
const;
114 std::pair<
unsigned int ,
115 unsigned int >& linkPair)
const;
117 std::vector<
unsigned int >
getGroupRows (
const unsigned int groupIdCol,
const std::string& groupID,
bool onlyStatusTrue =
false,
bool orderedByPriority =
false)
const;
118 std::vector<std::vector<
unsigned int >>
getGroupRowsByPriority (
const unsigned int groupIdCol,
const std::string& groupID,
bool onlyStatusTrue =
false)
const;
120 std::vector<std::vector<
unsigned int >> getGroupRowsInVectors (
const unsigned int groupIdCol,
const std::string& groupID,
bool onlyStatusTrue,
bool orderedByPriority)
const;
123 const unsigned int& col,
124 const std::string& groupID);
126 const unsigned int& col,
127 const std::string& groupID,
128 bool deleteRowIfNoGroupLeft =
false);
134 bool doConvertEnvironmentVariables =
true)
const;
141 bool doConvertEnvironmentVariables =
true)
const;
146 bool doConvertEnvironmentVariables =
true)
const;
152 bool convertEnvironmentVariables =
true)
const;
155 bool convertEnvironmentVariables =
true)
const;
158 bool convertEnvironmentVariables =
true,
159 bool quotesToDoubleQuotes =
false)
const;
160 bool isURIEncodedCommentTheSame (
const std::string& comment)
const;
162 const DataView& getDataView (
void)
const {
return theDataView_; }
163 const std::vector<TableViewColumnInfo>& getColumnsInfo (
void)
const {
return columnsInfo_; }
164 std::vector<TableViewColumnInfo>* getColumnsInfoP (
void) {
return &columnsInfo_; }
165 const TableViewColumnInfo& getColumnInfo (
unsigned int column)
const;
170 void setComment (
const std::string& comment) { comment_ = comment; }
172 void setAuthor (
const std::string& author);
173 void setCreationTime (time_t t);
174 void setLastAccessTime (time_t t = time(0));
175 void setLooseColumnMatching (
bool setValue);
176 void doGetSourceRawData (
bool setValue);
177 const std::string& getSourceRawData (
void) {
return sourceRawData_; }
182 void setValue (
const T& value,
unsigned int row,
unsigned int col);
183 void setValue (
const std::string& value,
unsigned int row,
unsigned int col);
184 void setValue (
const char* value,
unsigned int row,
unsigned int col);
188 void setValueAsString (
const std::string& value,
unsigned int row,
unsigned int col);
189 const std::string&
setUniqueColumnValue (
unsigned int row,
unsigned int col, std::string baseValueAsString =
"",
190 bool doMathAppendStrategy =
false,
191 std::string childLinkIndex =
"",
192 std::string groupId =
"");
193 void resizeDataView (
unsigned int nRows,
unsigned int nCols);
194 unsigned int addRow (
const std::string& author =
"",
195 unsigned char incrementUniqueData =
false,
198 const std::string& baseNameAutoUID =
"",
199 unsigned int rowToAdd = (
unsigned int)-1,
200 std::string childLinkIndex =
"",
201 std::string groupId =
"");
203 void deleteAllRows (
void) {theDataView_.clear();}
211 iterator
begin (
void) {
return theDataView_.begin(); }
212 iterator end (
void) {
return theDataView_.end(); }
213 const_iterator
begin (
void)
const {
return theDataView_.begin(); }
214 const_iterator end (
void)
const {
return theDataView_.end(); }
216 void print (std::ostream& out = std::cout)
const;
217 void printJSON (std::ostream& out = std::cout)
const;
218 void printCSV (std::ostream& out = std::cout,
const std::string& valueDelimeter =
",",
const std::string& recordDelimeter =
"\n",
bool includeColumnNames =
true)
const;
221 const int& dataOffset = 0,
222 const std::string& author =
"",
223 const char rowDelimter =
',',
224 const char colDelimter =
'\n');
226 const int& dataOffset = 0,
227 const std::string& author =
"");
229 const unsigned int& row,
230 const unsigned int& col,
231 const std::string& author =
"");
236 out << view.getTableName();
241 unsigned int initColUID (
void);
242 unsigned int initColStatus (
void);
243 unsigned int initColPriority (
void);
244 const std::vector<std::string >& initRowDefaults (
void);
250 std::string storageData_;
251 const std::string tableName_;
253 std::string comment_;
255 time_t creationTime_;
256 time_t lastAccessTime_;
258 std::vector<std::string> rowDefaultValues_;
259 unsigned int colUID_, colStatus_, colPriority_;
260 std::map<std::string, unsigned int> colLinkGroupIDs_;
262 bool fillWithLooseColumnMatching_;
263 bool getSourceRawData_;
264 std::string sourceRawData_;
265 unsigned int sourceColumnMismatchCount_, sourceColumnMissingCount_;
266 std::set<std::string> sourceColumnNames_;
268 std::vector<TableViewColumnInfo> columnsInfo_;
269 DataView theDataView_;
272 #include "otsdaq/TableCore/TableView.icc"
unsigned int findRow(unsigned int col, const T &value, unsigned int offsetRow=0, bool doNotThrow=false) const
< in included .icc source
std::string getEscapedValueAsString(unsigned int row, unsigned int col, bool convertEnvironmentVariables=true, bool quotesToDoubleQuotes=false) const
bool isEntryInGroup(const unsigned int &row, const std::string &childLinkIndex, const std::string &groupNeedle) const
void setValueAsString(const std::string &value, unsigned int row, unsigned int col)
std::vector< std::vector< unsigned int > > getGroupRowsByPriority(const unsigned int groupIdCol, const std::string &groupID, bool onlyStatusTrue=false) const
T validateValueForColumn(const std::string &value, unsigned int col, bool doConvertEnvironmentVariables=true) const
< in included .icc source
TableView(const std::string &tableName)
= "");
unsigned int getColStatus(void) const
unsigned int getLinkGroupIDColumn(const std::string &childLinkIndex) const
bool removeRowFromGroup(const unsigned int &row, const unsigned int &col, const std::string &groupID, bool deleteRowIfNoGroupLeft=false)
friend std::ostream & operator<<(std::ostream &out, const TableView &view)
output table name for ostream operator
unsigned int findColByType(const std::string &type, unsigned int startingCol=0) const
bool getChildLink(const unsigned int &col, bool &isGroup, std::pair< unsigned int, unsigned int > &linkPair) const
void addRowToGroup(const unsigned int &row, const unsigned int &col, const std::string &groupID)
, const std::string& colDefault);
unsigned int copyRows(const std::string &author, const TableView &src, unsigned int srcOffsetRow=0, unsigned int srcRowsToCopy=(unsigned int) -1, unsigned int destOffsetRow=(unsigned int) -1, unsigned char generateUniqueDataColumns=false, const std::string &baseNameAutoUID="")
void setVersion(const T &version)
< in included .icc source
unsigned int getColPriority(void) const
const std::string & setUniqueColumnValue(unsigned int row, unsigned int col, std::string baseValueAsString="", bool doMathAppendStrategy=false, std::string childLinkIndex="", std::string groupId="")
std::string getValueAsString(unsigned int row, unsigned int col, bool convertEnvironmentVariables=true) const
std::vector< unsigned int > getGroupRows(const unsigned int groupIdCol, const std::string &groupID, bool onlyStatusTrue=false, bool orderedByPriority=false) const
const std::string & getCustomStorageData(void) const
Getters.
std::set< std::string > getSetOfGroupIDs(const std::string &childLinkIndex, unsigned int row=-1) const
void getValue(T &value, unsigned int row, unsigned int col, bool doConvertEnvironmentVariables=true) const
< in included .icc source
unsigned int getDataColumnSize(void) const
getDataColumnSize
int fillFromJSON(const std::string &json)
unsigned int getColUID(void) const
bool setURIEncodedValue(const std::string &value, const unsigned int &row, const unsigned int &col, const std::string &author="")
void fillFromCSV(const std::string &data, const int &dataOffset=0, const std::string &author="", const char rowDelimter=',', const char colDelimter='\n')
int fillFromEncodedCSV(const std::string &data, const int &dataOffset=0, const std::string &author="")
unsigned int findCol(const std::string &name) const
void setValue(const T &value, unsigned int row, unsigned int col)
< in included .icc source
void setURIEncodedComment(const std::string &uriComment)
unsigned int addRow(const std::string &author="", unsigned char incrementUniqueData=false, const std::string &baseNameAutoUID="", unsigned int rowToAdd=(unsigned int) -1, std::string childLinkIndex="", std::string groupId="")
unsigned int findRowInGroup(unsigned int col, const T &value, const std::string &groupId, const std::string &childLinkIndex, unsigned int offsetRow=0) const
< in included .icc source
void setCustomStorageData(const std::string &storageData)
defines used also by OtsConfigurationWizardSupervisor