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