otsdaq  v2_04_01
Configurations_configuration.cc
1 #include <iostream>
2 #include "otsdaq-core/ConfigurationPluginDataFormats/Configurations.h"
3 #include "otsdaq-coreMacros/TablePluginMacros.h"
4 
5 using namespace ots;
6 
7 //==============================================================================
8 Configurations::Configurations(void) : TableBase("Configurations")
9 {
11  // WARNING: the names and the order MUST match the ones in the enum //
13  // ConfigurationsInfo.xml
14  //<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
15  //<ROOT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
16  // xsi:noNamespaceSchemaLocation="TableInfo.xsd">
17  // <CONFIGURATION Name="Configurations">
18  // <VIEW Name="CONFIGURATIONS" Type="File,Database,DatabaseTest">
19  // <COLUMN Name="TableGroupKey" StorageName="CONFIGURATION_KEY" DataType="NUMBER"
20  // /> <COLUMN Name="KOC" StorageName="KOC"
21  // DataType="VARCHAR2"/> <COLUMN Name="ConditionVersion"
22  // StorageName="CONDITION_VERSION" DataType="NUMBER" />
23  // </VIEW>
24  // </CONFIGURATION>
25  //</ROOT>
26 }
27 
28 //==============================================================================
29 Configurations::~Configurations(void) {}
30 
31 //==============================================================================
32 void Configurations::init(ConfigurationManager* configManager)
33 {
34  /*
35  std::string keyName;
36  unsigned int keyValue;
37  theKeys_.clear();
38  for(unsigned int row=0; row<TableBase::activeTableView_->getNumberOfRows(); row++)
39  {
40  TableBase::activeTableView_->getValue(keyName,row,ConfigurationAlias);
41  TableBase::activeTableView_->getValue(keyValue,row,TableGroupKeyId);
42  theKeys_[keyName] = keyValue;
43  }
44  */
45 }
46 
47 //==============================================================================
48 bool Configurations::findKOC(TableGroupKey TableGroupKey, std::string koc) const
49 {
50  unsigned int tmpTableGroupKey; // this is type to extract from table
51  std::string tmpKOC;
52  for(unsigned int row = 0; row < TableBase::activeTableView_->getNumberOfRows(); row++)
53  {
54  TableBase::activeTableView_->getValue(tmpTableGroupKey, row, TableGroupKeyAlias);
55  if(TableGroupKey == tmpTableGroupKey)
56  {
57  TableBase::activeTableView_->getValue(tmpKOC, row, KOC);
58  // std::cout << __COUT_HDR_FL__ << "Looking for KOC: " << tmpKOC << " for " <<
59  // koc << std::endl;
60  if(tmpKOC == koc)
61  return true;
62  }
63  }
64  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "ERROR: Can't find KOC " << koc
65  << std::endl;
66  return false;
67 }
68 
69 //==============================================================================
70 // getConditionVersion
71 // FIXME -- new ConfiguratoinGroup and TableGroupKey should be used!
72 TableVersion Configurations::getConditionVersion(const TableGroupKey& TableGroupKey,
73  std::string koc) const
74 {
75  unsigned int tmpTableGroupKey; // this is type to extract from table
76  std::string tmpKOC;
77  unsigned int conditionVersion; // this is type to extract from table
78 
79  for(unsigned int row = 0; row < TableBase::activeTableView_->getNumberOfRows(); row++)
80  {
81  TableBase::activeTableView_->getValue(tmpTableGroupKey, row, TableGroupKeyAlias);
82  if(TableGroupKey == tmpTableGroupKey)
83  {
84  TableBase::activeTableView_->getValue(tmpKOC, row, KOC);
85  if(tmpKOC == koc)
86  {
87  TableBase::activeTableView_->getValue(
88  conditionVersion, row, ConditionVersion);
89  // std::cout << __COUT_HDR_FL__ << "\tConditionVersion " <<
90  // ConditionVersion << std::endl;
91  return TableVersion(conditionVersion);
92  }
93  }
94  }
95  std::cout << __COUT_HDR_FL__
96  << "***********************************************************************"
97  "*****************************************************"
98  << std::endl;
99  std::cout << __COUT_HDR_FL__ << "\tCan't find KOC " << koc << " with TableGroupKey "
100  << TableGroupKey << " in the Configurations view" << std::endl;
101  std::cout << __COUT_HDR_FL__
102  << "***********************************************************************"
103  "*****************************************************"
104  << std::endl;
105  __THROW__("Could not find koc for TableGroupKey");
106  return TableVersion(); // return INVALID
107 }
108 
109 //==============================================================================
110 // setConditionVersion
111 // returns 1 if no change occurred (because new version was same as existing)
112 // returns 0 on change success
113 int Configurations::setConditionVersionForView(TableView* cfgView,
114  TableGroupKey TableGroupKey,
115  std::string koc,
116  TableVersion newKOCVersion)
117 {
118  // find first match of KOCAlias and TableGroupKey
119  unsigned int row = 0;
120  unsigned int tmpTableGroupKey; // this is type to extract from table
121  std::string tmpKOC;
122  unsigned int tmpOldKOCVersion; // this is type to extract from table
123  for(row = 0; row < cfgView->getNumberOfRows(); row++)
124  {
125  cfgView->getValue(tmpTableGroupKey, row, Configurations::TableGroupKeyAlias);
126  if(TableGroupKey == tmpTableGroupKey)
127  {
128  cfgView->getValue(tmpKOC, row, Configurations::KOC);
129  if(tmpKOC == koc)
130  {
131  cfgView->getValue(
132  tmpOldKOCVersion, row, Configurations::ConditionVersion);
133  std::cout << __COUT_HDR_FL__ << "Found ConfigKey(" << TableGroupKey
134  << ") and KOCAlias(" << koc << ") pair."
135  << " Current version is: " << tmpOldKOCVersion
136  << " New version is: " << newKOCVersion << std::endl;
137  if(newKOCVersion == tmpOldKOCVersion)
138  return 1; // no change necessary
139  break; // found row! exit search loop
140  }
141  }
142  }
143 
144  // at this point have row to change
145 
146  std::cout << __COUT_HDR_FL__ << "Row found is:" << row << std::endl;
147  cfgView->setValue(newKOCVersion, row, Configurations::ConditionVersion);
148  std::cout << __COUT_HDR_FL__ << "Version changed to:" << newKOCVersion << std::endl;
149  return 0;
150 }
151 
152 //==============================================================================
153 // getListOfKocs
154 // return list of Kind of Conditions that match TableGroupKey for the active
155 // configuration view. for all KOCs regardless of TableGroupKey, set TableGroupKey = -1
156 //
157 std::set<std::string> Configurations::getListOfKocs(TableGroupKey TableGroupKey) const
158 {
159  std::set<std::string> kocs;
160  getListOfKocsForView(TableBase::activeTableView_, kocs, TableGroupKey);
161  return kocs;
162 }
163 
164 //==============================================================================
165 // getListOfKocsForView
166 // return list of Kind of Conditions that match TableGroupKey for the active
167 // configuration view. for all KOCs regardless of TableGroupKey, set TableGroupKey = -1
168 //
169 void Configurations::getListOfKocsForView(TableView* cfgView,
170  std::set<std::string>& kocs,
171  TableGroupKey TableGroupKey) const
172 {
173  if(!cfgView)
174  {
175  std::cout << __COUT_HDR_FL__
176  << "*******************************************************************"
177  "*********************************************************"
178  << std::endl;
179  std::cout << __COUT_HDR_FL__
180  << "\tCan't find list of Kocs for null cfgView pointer" << std::endl;
181  std::cout << __COUT_HDR_FL__
182  << "*******************************************************************"
183  "*********************************************************"
184  << std::endl;
185  __THROW__("Null cfgView configuration view pointer");
186  }
187 
188  std::string tmpKOC;
189  unsigned int tmpTableGroupKey; // this is type to extract from table
190 
191  for(unsigned int row = 0; row < cfgView->getNumberOfRows(); row++)
192  {
193  cfgView->getValue(tmpTableGroupKey, row, TableGroupKeyAlias);
194  if(TableGroupKey == TableGroupKey::INVALID || TableGroupKey == tmpTableGroupKey)
195  {
196  cfgView->getValue(tmpKOC, row, KOC);
197  kocs.insert(tmpKOC);
198  }
199  }
200 }
201 
202 DEFINE_OTS_CONFIGURATION(Configurations)