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