otsdaq  v2_04_01
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-core/TableCore/TableVersion.h"
9 #include "otsdaq-core/TableCore/TableView.h"
10 
11 namespace ots
12 {
13 class ConfigurationManager;
14 
15 // e.g. configManager->__SELF_NODE__; //to get node referring to this table
16 #define __SELF_NODE__ getNode(getTableName())
17 
18 class TableBase
19 {
20  public:
21  const unsigned int MAX_VIEWS_IN_CACHE; // Each inheriting table class could have
22  // varying amounts of cache
23 
24  TableBase();
25  TableBase(std::string tableName, std::string* accumulatedExceptions = 0);
26 
27  virtual ~TableBase(void);
28 
29  // Methods
30  virtual void init(ConfigurationManager* configManager);
31 
32  void destroy(void) { ; }
33  void reset(bool keepTemporaryVersions = false);
34  void deactivate(void);
35  bool isActive(void);
36 
37  void print(std::ostream& out = std::cout) const; // always prints active view
38 
39  std::string getTypeId(void);
40 
41  void setupMockupView(TableVersion version);
42  void changeVersionAndActivateView(TableVersion temporaryVersion,
43  TableVersion version);
44  bool isStored(const TableVersion& version) const;
45  bool eraseView(TableVersion version);
46  void trimCache(unsigned int trimSize = -1);
47  void trimTemporary(TableVersion targetVersion = TableVersion());
48  TableVersion checkForDuplicate(TableVersion needleVersion,
49  TableVersion ignoreVersion = TableVersion()) const;
50 
51  // Getters
52  const std::string& getTableName(void) const;
53  const std::string& getTableDescription(void) const;
54  std::set<TableVersion> getStoredVersions(void) const;
55 
56  const TableView& getView(void) const;
57  TableView* getViewP(void);
58  TableView* getMockupViewP(void);
59  const TableVersion& getViewVersion(void) const; // always the active one
60 
61  TableView* getTemporaryView(TableVersion temporaryVersion);
62  TableVersion getNextTemporaryVersion() const;
63  TableVersion getNextVersion() const;
64 
65  // Setters
66  void setTableName(const std::string& tableName);
67  void setTableDescription(const std::string& tableDescription);
68  bool setActiveView(TableVersion version);
69  TableVersion copyView(const TableView& sourceView,
70  TableVersion destinationVersion,
71  const std::string& author);
73  const TableView& sourceViewA,
74  const TableView& sourceViewB,
75  TableVersion destinationVersion,
76  const std::string& author,
77  const std::string& mergeApproach /*Rename,Replace,Skip*/,
78  std::map<std::pair<std::string /*original table*/, std::string /*original uidB*/>,
79  std::string /*converted uidB*/>& uidConversionMap,
80  std::map<std::pair<std::string /*original table*/,
81  std::pair<std::string /*group linkid*/,
82  std::string /*original gidB*/> >,
83  std::string /*converted gidB*/>& groupidConversionMap,
84  bool fillRecordConversionMaps,
85  bool applyRecordConversionMaps,
86  bool generateUniqueDataColumns = false);
87 
88  TableVersion createTemporaryView(
89  TableVersion sourceViewVersion = TableVersion(),
90  TableVersion destTemporaryViewVersion =
91  TableVersion::getNextTemporaryVersion()); // source of -1, from MockUp, else
92  // from valid view version
93 
94  static std::string convertToCaps(std::string& str, bool isConfigName = false);
95 
96  bool latestAndMockupColumnNumberMismatch(void) const;
97 
98  unsigned int getNumberOfStoredViews(void) const;
99 
100  protected:
101  std::string tableName_;
102  std::string tableDescription_;
103 
104  TableView* activeTableView_;
105  TableView mockupTableView_;
106 
107  // Version and data associated to make it work like a cache.
108  // It will be very likely just 1 version
109  // NOTE: must be very careful to setVersion of view after manipulating (e.g. copy from
110  // different version view)
111  std::map<TableVersion, TableView> tableViews_;
112 };
113 } // namespace ots
114 
115 #endif
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)
Definition: TableBase.cc:550