otsdaq  3.06.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:
24  {
25  SKIP,
27  RENAME
28  };
29 
30  const unsigned int MAX_VIEWS_IN_CACHE;
32  //TableBase(void); //should not be used
33  TableBase(bool specialTable, const std::string& specialTableName);
34  TableBase(const std::string& tableName, std::string* accumulatedExceptions = 0);
35 
36  virtual ~TableBase(void);
37 
39  void specialMetaTableConstructor (void);
40  virtual void init (ConfigurationManager* configManager);
41 
42  void destroy (void) { ; }
43  void reset (bool keepTemporaryVersions = false);
44  void deactivate (void);
45  bool isActive (void);
46 
47  void print (std::ostream& out = std::cout) const;
48 
49  std::string getTypeId (void);
50 
51  void setupMockupView (TableVersion version);
52  void changeVersionAndActivateView (TableVersion temporaryVersion, TableVersion version);
53  bool isStored (const TableVersion& version) const;
54  bool eraseView (TableVersion version);
55  void trimCache (unsigned int trimSize = -1);
56  void trimTemporary (TableVersion targetVersion = TableVersion());
57  TableVersion checkForDuplicate (TableVersion needleVersion, TableVersion ignoreVersion = TableVersion()) const;
58  bool diffTwoVersions (TableVersion v1, TableVersion v2, std::stringstream* diffReport = 0,
59  std::map<std::string /* uid */, std::vector<std::string /* colName */>>* v1ModifiedRecords = 0) const;
60 
62  const std::string& getTableName (void) const;
63  const std::string& getTableDescription (void) const;
64  std::set<TableVersion> getStoredVersions (void) const;
65 
66  const TableView& getView (TableVersion version = TableVersion(TableVersion::INVALID)) const;
67  TableView* getViewP (TableVersion version = TableVersion(TableVersion::INVALID));
68  TableView* getMockupViewP (void);
69  const TableVersion& getViewVersion (void) const;
70 
71  TableView* getTemporaryView (TableVersion temporaryVersion);
73  TableVersion getNextVersion (void) const;
74 
75  virtual std::string getStructureAsJSON (const ConfigurationManager* /* configManager */) {__SS__ << "getStructureAsJSON() is not implemented for this table '" << getTableName() << "'" << __E__; __SS_ONLY_THROW__;};
76  virtual void initPrereqsForARTDAQ (const ConfigurationManager* /* configManager */) {__SS__ << "initPrereqsForARTDAQ() is not implemented for this table '" << getTableName() << "'" << __E__; __SS_ONLY_THROW__;};
77  virtual std::string getFclValueForARTDAQ (const ConfigurationManager* /* configManager */, const std::string& /* field = "" */) const {__SS__ << "getFclValueForARTDAQ() is not implemented for this table '" << getTableName() << "'" << __E__; __SS_ONLY_THROW__;};
78 
80  void setTableName (const std::string& tableName);
81  void setTableDescription (const std::string& tableDescription);
82  bool setActiveView (TableVersion version);
83  TableVersion copyView (const TableView& sourceView, TableVersion destinationVersion, const std::string& author, bool looseColumnMatching = false);
84  TableVersion mergeViews (
85  const TableView& sourceViewA,
86  const TableView& sourceViewB,
87  TableVersion destinationVersion,
88  const std::string& author,
89  MergeApproach mergeApproach,
90  std::map<std::pair<std::string /*original table*/, std::string /*original uidB*/>,
91  std::string /*converted uidB*/>& uidConversionMap,
92  std::map<std::pair<std::string /*original table*/,
93  std::pair<std::string /*group linkid*/,
94  std::string /*original gidB*/> >,
95  std::string /*converted gidB*/>& groupidConversionMap,
96  bool fillRecordConversionMaps,
97  bool applyRecordConversionMaps,
98  bool generateUniqueDataColumns = false,
99  std::stringstream* mergeRepoert = nullptr);
100 
101  TableVersion createTemporaryView (TableVersion sourceViewVersion = TableVersion(), TableVersion destTemporaryViewVersion = TableVersion::getNextTemporaryVersion());
102 
103  static std::string convertToCaps (std::string& str, bool isConfigName = false);
104 
105  bool latestAndMockupColumnNumberMismatch(void) const;
106 
107  unsigned int getNumberOfStoredViews (void) const;
108 
110  friend std::ostream& operator<<(std::ostream& out, const TableBase& table)
111  {
112  out << table.getTableName();
113  return out;
114  }
115 
116  // ----- member variables
117 
118  public:
119  static const std::string GROUP_CACHE_PREPEND;
120  static const std::string JSON_DOC_PREPEND;
121  static const std::string GROUP_METADATA_TABLE_NAME;
122 
123  protected:
124  std::string tableName_;
125  std::string tableDescription_;
126 
127  TableView* activeTableView_;
128  TableView mockupTableView_;
129 
133  std::map<TableVersion, TableView> tableViews_;
134  bool isFirstAppInContext_ = false;
135 };
136 // clang-format on
137 } // namespace ots
138 
139 #endif
const std::string & getTableName(void) const
Getters.
Definition: TableBase.cc:814
std::map< TableVersion, TableView > tableViews_
Definition: TableBase.h:133
TableVersion createTemporaryView(TableVersion sourceViewVersion=TableVersion(), TableVersion destTemporaryViewVersion=TableVersion::getNextTemporaryVersion())
source of -1, from MockUp, else from valid view version
Definition: TableBase.cc:1769
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
MergeApproach
Merge approach enumeration for mergeViews function.
Definition: TableBase.h:24
@ RENAME
Rename records with UID conflicts from source view B.
Definition: TableBase.h:27
@ REPLACE
Replace records with UID conflicts from source view B.
Definition: TableBase.h:26
@ SKIP
Skip records with UID conflicts from source view B.
Definition: TableBase.h:25
bool isFirstAppInContext_
for managing things that should only happen once per node (e.g., write files). If used,...
Definition: TableBase.h:134
TableBase(bool specialTable, const std::string &specialTableName)
Definition: TableBase.cc:140
void trimTemporary(TableVersion targetVersion=TableVersion())
Definition: TableBase.cc:362
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
TableVersion mergeViews(const TableView &sourceViewA, const TableView &sourceViewB, TableVersion destinationVersion, const std::string &author, MergeApproach 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
static std::string convertToCaps(std::string &str, bool isConfigName=false)
Definition: TableBase.cc:1894
friend std::ostream & operator<<(std::ostream &out, const TableBase &table)
output table name for ostream operator
Definition: TableBase.h:110
TableView * getTemporaryView(TableVersion temporaryVersion)
Definition: TableBase.cc:1880
const unsigned int MAX_VIEWS_IN_CACHE
Definition: TableBase.h:30
TableVersion getNextVersion(void) const
Definition: TableBase.cc:1856
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:1710
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:1833
void trimCache(unsigned int trimSize=-1)
Definition: TableBase.cc:322
static TableVersion getNextTemporaryVersion(const TableVersion &version=TableVersion())
defines used also by OtsConfigurationWizardSupervisor