/** @class MetaQuality @author Brian Magill @datecreated 7/11/2007 $Date:$ $Revision:$ @copyright (©) Copyright 2006 by GATS Inc. 11864 Canon Blvd., Suite 101, Newport News, VA 23606 All Rights Reserved. No part of this software or publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise without the prior written permission of GATS Inc. @brief Class returns a vector of data associated with a given quality Quality */ //---------------------------------------------------------------------- // #include #include #include #include "EventVar.h" #include "MetaQuality.h" #include "GATS_DB_Exception.h" #include "GATS_Utilities.hpp" #include "Vec2Val.hpp" //#include "SOFIELevel1DBUtilities.h" using namespace std; using namespace gatsDBpp; bool MetaQuality::TableExists(std::string tableName) const { try { GATS_DB_Results results; string strSQL = "SELECT COUNT(*) FROM " + metaTable + " WHERE TableName = '" + tableName + "'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0 ) return (results[0][0].asLong() > 0); else return false; } catch (exception &ex) { string errstr = "MetaQuality::TableExists Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } }; bool MetaQuality::EntryExists(string tableName, string Parameter) const { try { GATS_DB_Results results; string strSQL = "SELECT COUNT(*) FROM " + metaTable + " WHERE TableName = '" + tableName + "' AND Parameter = '" + Parameter + "'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0 ) return (results[0][0].asLong() > 0); else return false; } catch (exception &ex) { string errstr = "MetaQuality::TableExists Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } }; string MetaQuality::getEntryName(string tableName, string parameter) const { string varName; string strErr; try { GATS_DB_Results results; string strSQL = "SELECT Assoc_Entity FROM " + metaTable + " WHERE TableName = '" + tableName +"'" + " AND Parameter = '" + parameter +"'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0 ) varName = results[0][0].asString(); else varName = ""; } catch (exception &ex) { string errstr = "MetaQuality::getEntryName() Error: " + string(ex.what() ) + string(" for table ") + tableName + " and Parameter " + parameter; throw runtime_error(errstr); } return varName; } vector MetaQuality::getData(string tableName, string parameter) const { vector outVector; string strErr; string varName; try { EventVar varArray; // varName = getEntryName(tableName, parameter); if (varName.size() < 1) { strErr = string("No entry "); throw runtime_error(strErr); } switch (inEvent->EventVarExists(varName) ) { case INTEGER: { inEvent->getEventVar(varName, varArray); } break; case NOVAR: strErr = string("No entry for ") + varName + string(" in ouput Event object"); throw runtime_error(strErr); break; case DOUBLE: { strErr = string("Error ") + varName + string(" is an double array! Expecting integer type."); throw runtime_error(strErr); break; } break; case FLOAT: { strErr = string("Error ") + varName + string(" is a float array! Expecting integer type."); throw runtime_error(strErr); break; } break; default: throw runtime_error("programming error in Event::EventVarExists(). Bad Type!"); } outVector = Val2Vec(varArray); return outVector; } catch (exception &ex) { string errstr = "MetaQuality::getData() Error: " + string(ex.what() ) + string(" for table ") + tableName + " and Parameter " + parameter; throw runtime_error(errstr); } }; vector MetaQuality::getParameterList(std::string tableName) const { string strErr; vector paramList; try { GATS_DB_Results results; // EventVar varArray; string strSQL = "SELECT Parameter FROM " + metaTable + " WHERE TableName = '" + tableName + "'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0) for(unsigned long i = 0; i < results.size(); i++) { paramList.push_back(results[i][0].asString()); } else { strErr = string("No entry for table ") + tableName; throw runtime_error(strErr); } } catch (exception &ex) { strErr = "MetaQuality::getParameterList() Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(strErr); } return paramList; }; vector MetaQuality::getTableList() const { string strErr; vector TableList; try { GATS_DB_Results results; string strSQL = "SELECT DISTINCT TableName FROM " + metaTable; results = dbConn->Query(strSQL.c_str()); for(unsigned long i = 0; i < results.size(); i++) { TableList.push_back(results[i][0].asString()); } } catch (exception &ex) { strErr = "MetaQuality::getTableList() Error: " + string(ex.what()); throw runtime_error(strErr); } return TableList; };