otsdaq  3.03.00
TableBase.h
1 #ifndef _ots_TableBase_h_
2 #define _ots_TableBase_h_
3 
4 #include <list>
5 #include <map>
6 #include <string>
7 
8 #include "otsdaq/TableCore/TableVersion.h"
9 #include "otsdaq/TableCore/TableView.h"
10 
11 namespace ots
12 {
13 // clang-format off
14 class ConfigurationManager;
15 
17 #define __SELF_NODE__ getNode(getTableName())
18 
19 class TableBase
20 {
21  public:
22  const unsigned int MAX_VIEWS_IN_CACHE;
24  //TableBase(void); //should not be used
25  TableBase(bool specialTable, const std::string& specialTableName);
26  TableBase(const std::string& tableName, std::string* accumulatedExceptions = 0);
27 
28  virtual ~TableBase(void);
29 
31  void specialMetaTableConstructor (void);
32  virtual void init (ConfigurationManager* configManager);
33 
34  void destroy (void) { ; }
35  void reset (bool keepTemporaryVersions = false);
36  void deactivate (void);
37  bool isActive (void);
38 
39  void print (std::ostream& out = std::cout) const;
40 
41  std::string getTypeId (void);
42 
43  void setupMockupView (TableVersion version);
44  void changeVersionAndActivateView (TableVersion temporaryVersion, TableVersion version);
45  bool isStored (const TableVersion& version) const;
46  bool eraseView (TableVersion version);
47  void trimCache (unsigned int trimSize = -1);
48  void trimTemporary (TableVersion targetVersion = TableVersion());
49  TableVersion checkForDuplicate (TableVersion needleVersion, TableVersion ignoreVersion = TableVersion()) const;
50  bool diffTwoVersions (TableVersion v1, TableVersion v2, std::stringstream* diffReport = 0,
51  std::map<std::string /* uid */, std::vector<std::string /* colName */>>* v1ModifiedRecords = 0) const;
52 
54  const std::string& getTableName (void) const;
55  const std::string& getTableDescription (void) const;
56  std::set<TableVersion> getStoredVersions (void) const;
57 
58  const TableView& getView (TableVersion version = TableVersion(TableVersion::INVALID)) const;
59  TableView* getViewP (TableVersion version = TableVersion(TableVersion::INVALID));
60  TableView* getMockupViewP (void);
61  const TableVersion& getViewVersion (void) const;
62 
63  TableView* getTemporaryView (TableVersion temporaryVersion);
65  TableVersion getNextVersion (void) const;
66 
67  virtual std::string getStructureStatusAsJSON (ConfigurationManager* configManager) const {__SS__ << "This function is not implemented for this table '" << getTableName() << "'" << __E__; __SS_THROW__; return configManager?"":"" /*to use param*/;};
68 
70  void setTableName (const std::string& tableName);
71  void setTableDescription (const std::string& tableDescription);
72  bool setActiveView (TableVersion version);
73  TableVersion copyView (const TableView& sourceView, TableVersion destinationVersion, const std::string& author, bool looseColumnMatching = false);
74  TableVersion mergeViews (
75  const TableView& sourceViewA,
76  const TableView& sourceViewB,
77  TableVersion destinationVersion,
78  const std::string& author,
79  const std::string& mergeApproach /*Rename,Replace,Skip*/,
80  std::map<std::pair<std::string /*original table*/, std::string /*original uidB*/>,
81  std::string /*converted uidB*/>& uidConversionMap,
82  std::map<std::pair<std::string /*original table*/,
83  std::pair<std::string /*group linkid*/,
84  std::string /*original gidB*/> >,
85  std::string /*converted gidB*/>& groupidConversionMap,
86  bool fillRecordConversionMaps,
87  bool applyRecordConversionMaps,
88  bool generateUniqueDataColumns = false,
89  std::stringstream* mergeRepoert = nullptr);
90 
91  TableVersion createTemporaryView (TableVersion sourceViewVersion = TableVersion(), TableVersion destTemporaryViewVersion = TableVersion::getNextTemporaryVersion());
92 
93  static std::string convertToCaps (std::string& str, bool isConfigName = false);
94 
95  bool latestAndMockupColumnNumberMismatch(void) const;
96 
97  unsigned int getNumberOfStoredViews (void) const;
98 
100  friend std::ostream& operator<<(std::ostream& out, const TableBase& table)
101  {
102  out << table.getTableName();
103  return out;
104  }
105 
106  // ----- member variables
107 
108  public:
109  static const std::string GROUP_CACHE_PREPEND;
110  static const std::string JSON_DOC_PREPEND;
111  static const std::string GROUP_METADATA_TABLE_NAME;
112 
113  protected:
114  std::string tableName_;
115  std::string tableDescription_;
116 
117  TableView* activeTableView_;
118  TableView mockupTableView_;
119 
123  std::map<TableVersion, TableView> tableViews_;
124 
125 };
126 // clang-format on
127 } // namespace ots
128 
129 #endif
const std::string & getTableName(void) const
Getters.
Definition: TableBase.cc:814
std::map< TableVersion, TableView > tableViews_
Definition: TableBase.h:123
TableVersion createTemporaryView(TableVersion sourceViewVersion=TableVersion(), TableVersion destTemporaryViewVersion=TableVersion::getNextTemporaryVersion())
source of -1, from MockUp, else from valid view version
Definition: TableBase.cc:1734
void setupMockupView(TableVersion version)
Definition: TableBase.cc:292
bool diffTwoVersions(TableVersion v1, TableVersion v2, std::stringstream *diffReport=0, std::map< std::string, std::vector< std::string >> *v1ModifiedRecords=0) const
Definition: TableBase.cc:542
TableBase(bool specialTable, const std::string &specialTableName)
Definition: TableBase.cc:140
void trimTemporary(TableVersion targetVersion=TableVersion())
Definition: TableBase.cc:362
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, std::stringstream *mergeRepoert=nullptr)
Definition: TableBase.cc:984
unsigned int getNumberOfStoredViews(void) const
Definition: TableBase.cc:856
TableVersion checkForDuplicate(TableVersion needleVersion, TableVersion ignoreVersion=TableVersion()) const
Definition: TableBase.cc:404
bool isActive(void)
isActive
Definition: TableBase.cc:950
static std::string convertToCaps(std::string &str, bool isConfigName=false)
Definition: TableBase.cc:1859
friend std::ostream & operator<<(std::ostream &out, const TableBase &table)
output table name for ostream operator
Definition: TableBase.h:100
TableView * getTemporaryView(TableVersion temporaryVersion)
Definition: TableBase.cc:1845
const unsigned int MAX_VIEWS_IN_CACHE
Definition: TableBase.h:22
TableVersion getNextVersion(void) const
Definition: TableBase.cc:1821
const TableVersion & getViewVersion(void) const
always the active one
Definition: TableBase.cc:823
TableVersion copyView(const TableView &sourceView, TableVersion destinationVersion, const std::string &author, bool looseColumnMatching=false)
Definition: TableBase.cc:1675
bool latestAndMockupColumnNumberMismatch(void) const
Definition: TableBase.cc:831
void setTableName(const std::string &tableName)
Setters.
Definition: TableBase.cc:935
virtual ~TableBase(void)
Definition: TableBase.cc:254
void print(std::ostream &out=std::cout) const
always prints active view
Definition: TableBase.cc:277
void deactivate(void)
Definition: TableBase.cc:946
void specialMetaTableConstructor(void)
Methods.
Definition: TableBase.cc:172
TableVersion getNextTemporaryVersion(void) const
Definition: TableBase.cc:1798
void trimCache(unsigned int trimSize=-1)
Definition: TableBase.cc:322
static TableVersion getNextTemporaryVersion(const TableVersion &version=TableVersion())