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"
14 #include "otsdaq/TableCore/TableVersion.h"
15 #include "otsdaq/TableCore/TableViewColumnInfo.h"
23 static const unsigned int INVALID;
24 typedef std::vector<std::vector<std::string> > DataView;
25 typedef DataView::iterator iterator;
26 typedef DataView::const_iterator const_iterator;
34 const std::string& author);
35 unsigned int copyRows (
const std::string& author,
37 unsigned int srcOffsetRow = 0,
38 unsigned int srcRowsToCopy = (
unsigned int)-1,
39 unsigned int destOffsetRow = (
unsigned int)-1,
40 unsigned char generateUniqueDataColumns =
false,
43 const std::string& baseNameAutoUID =
""
49 unsigned int offsetRow = 0,
50 bool doNotThrow =
false)
const;
51 unsigned int findRow (
unsigned int col,
52 const std::string& value,
53 unsigned int offsetRow = 0,
54 bool doNotThrow =
false)
const;
59 const std::string& groupId,
60 const std::string& childLinkIndex,
61 unsigned int offsetRow = 0)
const;
63 const std::string& value,
64 const std::string& groupId,
65 const std::string& childLinkIndex,
66 unsigned int offsetRow = 0)
const;
67 unsigned int findCol (
const std::string& name)
const;
68 unsigned int findColByType (
const std::string& type,
unsigned int startingCol = 0)
const;
72 const std::string& getTableName (
void)
const {
return tableName_; }
73 const TableVersion& getVersion (
void)
const {
return version_; }
74 const std::string& getComment (
void)
const {
return comment_ ==
"" ? TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT : comment_; }
75 const std::string& getAuthor (
void)
const {
return author_; }
76 const time_t& getCreationTime (
void)
const {
return creationTime_; }
77 const time_t& getLastAccessTime (
void)
const {
return lastAccessTime_; }
78 const bool& getLooseColumnMatching (
void)
const {
return fillWithLooseColumnMatching_; }
80 const unsigned int& getSourceColumnMismatch (
void)
const {
return sourceColumnMismatchCount_; }
81 const unsigned int& getSourceColumnMissing (
void)
const {
return sourceColumnMissingCount_; }
82 const std::set<std::string >& getSourceColumnNames (
void)
const {
return sourceColumnNames_; }
83 std::set<std::string > getColumnNames (
void)
const;
84 std::map<std::string,
unsigned int > getColumnNamesMap (
void)
const;
85 std::set<std::string > getColumnStorageNames (
void)
const;
86 const std::vector<std::string >& getDefaultRowValues (
void)
const {
return rowDefaultValues_; }
87 std::string getMismatchColumnInfo (
void)
const;
89 unsigned int getNumberOfRows (
void)
const {
return theDataView_.size(); }
90 unsigned int getNumberOfColumns (
void)
const {
return columnsInfo_.size(); }
99 bool isEntryInGroupCol (
const unsigned int& row,
100 const unsigned int& groupCol,
101 const std::string& groupNeedle,
102 std::set<std::string>* groupIDList = 0)
const;
106 std::set<std::string >
getSetOfGroupIDs (
const std::string& childLinkIndex,
unsigned int row = -1)
const;
107 std::set<std::string >
getSetOfGroupIDs (
const unsigned int& col,
unsigned int row = -1)
const;
109 const std::string& childLinkIndex,
110 const std::string& groupNeedle)
const;
113 std::pair<
unsigned int ,
114 unsigned int >& linkPair)
const;
116 std::vector<
unsigned int >
getGroupRows (
const unsigned int groupIdCol,
const std::string& groupID,
bool onlyStatusTrue =
false,
bool orderedByPriority =
false)
const;
117 std::vector<std::vector<
unsigned int >>
getGroupRowsByPriority (
const unsigned int groupIdCol,
const std::string& groupID,
bool onlyStatusTrue =
false)
const;
119 std::vector<std::vector<
unsigned int >> getGroupRowsInVectors (
const unsigned int groupIdCol,
const std::string& groupID,
bool onlyStatusTrue,
bool orderedByPriority)
const;
122 const unsigned int& col,
123 const std::string& groupID);
125 const unsigned int& col,
126 const std::string& groupID,
127 bool deleteRowIfNoGroupLeft =
false);
133 bool doConvertEnvironmentVariables =
true)
const;
140 bool doConvertEnvironmentVariables =
true)
const;
145 bool doConvertEnvironmentVariables =
true)
const;
151 bool convertEnvironmentVariables =
true)
const;
154 bool convertEnvironmentVariables =
true)
const;
157 bool convertEnvironmentVariables =
true,
158 bool quotesToDoubleQuotes =
false)
const;
159 bool isURIEncodedCommentTheSame (
const std::string& comment)
const;
161 const DataView& getDataView (
void)
const {
return theDataView_; }
162 const std::vector<TableViewColumnInfo>& getColumnsInfo (
void)
const {
return columnsInfo_; }
163 std::vector<TableViewColumnInfo>* getColumnsInfoP (
void) {
return &columnsInfo_; }
164 const TableViewColumnInfo& getColumnInfo (
unsigned int column)
const;
169 void setComment (
const std::string& comment) { comment_ = comment; }
171 void setAuthor (
const std::string& author);
172 void setCreationTime (time_t t);
173 void setLastAccessTime (time_t t = time(0));
174 void setLooseColumnMatching (
bool setValue);
175 void doGetSourceRawData (
bool setValue);
176 const std::string& getSourceRawData (
void) {
return sourceRawData_; }
181 void setValue (
const T& value,
unsigned int row,
unsigned int col);
182 void setValue (
const std::string& value,
unsigned int row,
unsigned int col);
183 void setValue (
const char* value,
unsigned int row,
unsigned int col);
187 void setValueAsString (
const std::string& value,
unsigned int row,
unsigned int col);
188 const std::string&
setUniqueColumnValue (
unsigned int row,
unsigned int col, std::string baseValueAsString =
"",
189 bool doMathAppendStrategy =
false,
190 std::string childLinkIndex =
"",
191 std::string groupId =
"");
192 void resizeDataView (
unsigned int nRows,
unsigned int nCols);
193 unsigned int addRow (
const std::string& author =
"",
194 unsigned char incrementUniqueData =
false,
197 const std::string& baseNameAutoUID =
"",
198 unsigned int rowToAdd = (
unsigned int)-1,
199 std::string childLinkIndex =
"",
200 std::string groupId =
"");
202 void deleteAllRows (
void) {theDataView_.clear();}
210 iterator
begin (
void) {
return theDataView_.begin(); }
211 iterator end (
void) {
return theDataView_.end(); }
212 const_iterator
begin (
void)
const {
return theDataView_.begin(); }
213 const_iterator end (
void)
const {
return theDataView_.end(); }
215 void print (std::ostream& out = std::cout)
const;
216 void printJSON (std::ostream& out = std::cout)
const;
217 void printCSV (std::ostream& out = std::cout,
const std::string& valueDelimeter =
",",
const std::string& recordDelimeter =
"\n",
bool includeColumnNames =
true)
const;
220 const int& dataOffset = 0,
221 const std::string& author =
"",
222 const char rowDelimter =
',',
223 const char colDelimter =
'\n');
225 const int& dataOffset = 0,
226 const std::string& author =
"");
228 const unsigned int& row,
229 const unsigned int& col,
230 const std::string& author =
"");
235 out << view.getTableName();
240 unsigned int initColUID (
void);
241 unsigned int initColStatus (
void);
242 unsigned int initColPriority (
void);
243 const std::vector<std::string >& initRowDefaults (
void);
249 std::string storageData_;
250 const std::string tableName_;
252 std::string comment_;
254 time_t creationTime_;
255 time_t lastAccessTime_;
257 std::vector<std::string> rowDefaultValues_;
258 unsigned int colUID_, colStatus_, colPriority_;
259 std::map<std::string, unsigned int> colLinkGroupIDs_;
261 bool fillWithLooseColumnMatching_;
262 bool getSourceRawData_;
263 std::string sourceRawData_;
264 unsigned int sourceColumnMismatchCount_, sourceColumnMissingCount_;
265 std::set<std::string> sourceColumnNames_;
267 std::vector<TableViewColumnInfo> columnsInfo_;
268 DataView theDataView_;
271 #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)