/** @class MetaVector @author Brian Magill @datecreated 3/06/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 table entry */ //---------------------------------------------------------------------- // #include #include #include #include "EventVarVect.h" #include "MetaVector.h" #include "GATS_DB_Exception.h" #include "GATS_Utilities.hpp" #include "Vec2Val.hpp" //#include "ExtractVector.h" //#include "SOFIELevel1DBUtilities.h" using namespace std; using namespace gatsDBpp; //using namespace GATS_Utilities; bool MetaVector::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 = "MetaVector::TableExists Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } }; vector > MetaVector::getData(string tableName) const { EventVarVect signalsOut; EventVar workVar; vector > vectorOut; vector wVector; string strErr; string varName; unsigned long i; unsigned long j; try { // GATS_DB_Results results; EventVarVect vectArray; // ExtractVector extractedSignal; varName = getEntryName(tableName); if (varName.size() < 1) { strErr = string("No entry "); throw runtime_error(strErr); } switch (inEvent->EventVarExists(varName) ) { case DOUBLE: inEvent->getEventVar(varName, signalsOut); workVar.resize(signalsOut(0).size()); // extractedSignal = ExtractVector(signalsOut); break; case NOVAR: strErr = string("No entry for ") + varName + string(" in ouput Event object"); throw runtime_error(strErr); case INTEGER: strErr = string("Error ") + varName + string(" is an integer array! Expecting double type."); throw runtime_error(strErr); case FLOAT: strErr = string("Error ") + varName + string(" is a float array! Expecting double type."); throw runtime_error(strErr); default: throw runtime_error("programming error in Event::EventVarExists(). Bad Type!"); } for(i = 0; i < signalsOut.size(); i++) { wVector.clear(); workVar = signalsOut(i); for (j = 0; j < workVar.size(); j++) wVector.push_back(workVar[j]); vectorOut.push_back(wVector); } return vectorOut; } catch (exception &ex) { string errstr = "MetaVector::getData() Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } }; // std::string getEntryName(std::string tableName) const; string MetaVector::getEntryName(std::string tableName) const { string strErr; string vectName; try { GATS_DB_Results results; string strSQL = "SELECT Assoc_Entity FROM " + metaTable + " WHERE TableName = '" + tableName + "'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0) vectName = results[0][0].asString(); else { strErr = string("No entry for table ") + tableName; throw runtime_error(strErr); } } catch (exception &ex) { strErr = "MetaVector::getEntryName() Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(strErr); } return vectName; }; vector MetaVector::getTableList() const { string strErr; vector TableList; try { GATS_DB_Results results; string strSQL = "SELECT 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 = "MetaVector::getTableList() Error: " + string(ex.what()); throw runtime_error(strErr); } return TableList; };