$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include <iostream> 00002 #include "otsdaq-core/ConfigurationPluginDataFormats/Configurations.h" 00003 #include "otsdaq-coreMacros/TablePluginMacros.h" 00004 00005 using namespace ots; 00006 00007 //============================================================================== 00008 Configurations::Configurations(void) : TableBase("Configurations") 00009 { 00011 // WARNING: the names and the order MUST match the ones in the enum // 00013 // ConfigurationsInfo.xml 00014 //<?xml version="1.0" encoding="UTF-8" standalone="no" ?> 00015 //<ROOT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 00016 // xsi:noNamespaceSchemaLocation="TableInfo.xsd"> 00017 // <CONFIGURATION Name="Configurations"> 00018 // <VIEW Name="CONFIGURATIONS" Type="File,Database,DatabaseTest"> 00019 // <COLUMN Name="TableGroupKey" StorageName="CONFIGURATION_KEY" DataType="NUMBER" 00020 // /> <COLUMN Name="KOC" StorageName="KOC" 00021 // DataType="VARCHAR2"/> <COLUMN Name="ConditionVersion" 00022 // StorageName="CONDITION_VERSION" DataType="NUMBER" /> 00023 // </VIEW> 00024 // </CONFIGURATION> 00025 //</ROOT> 00026 } 00027 00028 //============================================================================== 00029 Configurations::~Configurations(void) {} 00030 00031 //============================================================================== 00032 void Configurations::init(ConfigurationManager* configManager) 00033 { 00034 /* 00035 std::string keyName; 00036 unsigned int keyValue; 00037 theKeys_.clear(); 00038 for(unsigned int row=0; row<TableBase::activeTableView_->getNumberOfRows(); row++) 00039 { 00040 TableBase::activeTableView_->getValue(keyName,row,ConfigurationAlias); 00041 TableBase::activeTableView_->getValue(keyValue,row,TableGroupKeyId); 00042 theKeys_[keyName] = keyValue; 00043 } 00044 */ 00045 } 00046 00047 //============================================================================== 00048 bool Configurations::findKOC(TableGroupKey TableGroupKey, std::string koc) const 00049 { 00050 unsigned int tmpTableGroupKey; // this is type to extract from table 00051 std::string tmpKOC; 00052 for(unsigned int row = 0; row < TableBase::activeTableView_->getNumberOfRows(); row++) 00053 { 00054 TableBase::activeTableView_->getValue(tmpTableGroupKey, row, TableGroupKeyAlias); 00055 if(TableGroupKey == tmpTableGroupKey) 00056 { 00057 TableBase::activeTableView_->getValue(tmpKOC, row, KOC); 00058 // std::cout << __COUT_HDR_FL__ << "Looking for KOC: " << tmpKOC << " for " << 00059 // koc << std::endl; 00060 if(tmpKOC == koc) 00061 return true; 00062 } 00063 } 00064 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "ERROR: Can't find KOC " << koc 00065 << std::endl; 00066 return false; 00067 } 00068 00069 //============================================================================== 00070 // getConditionVersion 00071 // FIXME -- new ConfiguratoinGroup and TableGroupKey should be used! 00072 TableVersion Configurations::getConditionVersion(const TableGroupKey& TableGroupKey, 00073 std::string koc) const 00074 { 00075 unsigned int tmpTableGroupKey; // this is type to extract from table 00076 std::string tmpKOC; 00077 unsigned int conditionVersion; // this is type to extract from table 00078 00079 for(unsigned int row = 0; row < TableBase::activeTableView_->getNumberOfRows(); row++) 00080 { 00081 TableBase::activeTableView_->getValue(tmpTableGroupKey, row, TableGroupKeyAlias); 00082 if(TableGroupKey == tmpTableGroupKey) 00083 { 00084 TableBase::activeTableView_->getValue(tmpKOC, row, KOC); 00085 if(tmpKOC == koc) 00086 { 00087 TableBase::activeTableView_->getValue( 00088 conditionVersion, row, ConditionVersion); 00089 // std::cout << __COUT_HDR_FL__ << "\tConditionVersion " << 00090 // ConditionVersion << std::endl; 00091 return TableVersion(conditionVersion); 00092 } 00093 } 00094 } 00095 std::cout << __COUT_HDR_FL__ 00096 << "***********************************************************************" 00097 "*****************************************************" 00098 << std::endl; 00099 std::cout << __COUT_HDR_FL__ << "\tCan't find KOC " << koc << " with TableGroupKey " 00100 << TableGroupKey << " in the Configurations view" << std::endl; 00101 std::cout << __COUT_HDR_FL__ 00102 << "***********************************************************************" 00103 "*****************************************************" 00104 << std::endl; 00105 __THROW__("Could not find koc for TableGroupKey"); 00106 return TableVersion(); // return INVALID 00107 } 00108 00109 //============================================================================== 00110 // setConditionVersion 00111 // returns 1 if no change occurred (because new version was same as existing) 00112 // returns 0 on change success 00113 int Configurations::setConditionVersionForView(TableView* cfgView, 00114 TableGroupKey TableGroupKey, 00115 std::string koc, 00116 TableVersion newKOCVersion) 00117 { 00118 // find first match of KOCAlias and TableGroupKey 00119 unsigned int row = 0; 00120 unsigned int tmpTableGroupKey; // this is type to extract from table 00121 std::string tmpKOC; 00122 unsigned int tmpOldKOCVersion; // this is type to extract from table 00123 for(row = 0; row < cfgView->getNumberOfRows(); row++) 00124 { 00125 cfgView->getValue(tmpTableGroupKey, row, Configurations::TableGroupKeyAlias); 00126 if(TableGroupKey == tmpTableGroupKey) 00127 { 00128 cfgView->getValue(tmpKOC, row, Configurations::KOC); 00129 if(tmpKOC == koc) 00130 { 00131 cfgView->getValue( 00132 tmpOldKOCVersion, row, Configurations::ConditionVersion); 00133 std::cout << __COUT_HDR_FL__ << "Found ConfigKey(" << TableGroupKey 00134 << ") and KOCAlias(" << koc << ") pair." 00135 << " Current version is: " << tmpOldKOCVersion 00136 << " New version is: " << newKOCVersion << std::endl; 00137 if(newKOCVersion == tmpOldKOCVersion) 00138 return 1; // no change necessary 00139 break; // found row! exit search loop 00140 } 00141 } 00142 } 00143 00144 // at this point have row to change 00145 00146 std::cout << __COUT_HDR_FL__ << "Row found is:" << row << std::endl; 00147 cfgView->setValue(newKOCVersion, row, Configurations::ConditionVersion); 00148 std::cout << __COUT_HDR_FL__ << "Version changed to:" << newKOCVersion << std::endl; 00149 return 0; 00150 } 00151 00152 //============================================================================== 00153 // getListOfKocs 00154 // return list of Kind of Conditions that match TableGroupKey for the active 00155 // configuration view. for all KOCs regardless of TableGroupKey, set TableGroupKey = -1 00156 // 00157 std::set<std::string> Configurations::getListOfKocs(TableGroupKey TableGroupKey) const 00158 { 00159 std::set<std::string> kocs; 00160 getListOfKocsForView(TableBase::activeTableView_, kocs, TableGroupKey); 00161 return kocs; 00162 } 00163 00164 //============================================================================== 00165 // getListOfKocsForView 00166 // return list of Kind of Conditions that match TableGroupKey for the active 00167 // configuration view. for all KOCs regardless of TableGroupKey, set TableGroupKey = -1 00168 // 00169 void Configurations::getListOfKocsForView(TableView* cfgView, 00170 std::set<std::string>& kocs, 00171 TableGroupKey TableGroupKey) const 00172 { 00173 if(!cfgView) 00174 { 00175 std::cout << __COUT_HDR_FL__ 00176 << "*******************************************************************" 00177 "*********************************************************" 00178 << std::endl; 00179 std::cout << __COUT_HDR_FL__ 00180 << "\tCan't find list of Kocs for null cfgView pointer" << std::endl; 00181 std::cout << __COUT_HDR_FL__ 00182 << "*******************************************************************" 00183 "*********************************************************" 00184 << std::endl; 00185 __THROW__("Null cfgView configuration view pointer"); 00186 } 00187 00188 std::string tmpKOC; 00189 unsigned int tmpTableGroupKey; // this is type to extract from table 00190 00191 for(unsigned int row = 0; row < cfgView->getNumberOfRows(); row++) 00192 { 00193 cfgView->getValue(tmpTableGroupKey, row, TableGroupKeyAlias); 00194 if(TableGroupKey == TableGroupKey::INVALID || TableGroupKey == tmpTableGroupKey) 00195 { 00196 cfgView->getValue(tmpKOC, row, KOC); 00197 kocs.insert(tmpKOC); 00198 } 00199 } 00200 } 00201 00202 DEFINE_OTS_CONFIGURATION(Configurations)