/** @class MetaSummary @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 the expected size of the arrays to be written to database The SOFIE Level 1 database contains a table that contains the Level 1 Event Class object associated with the index used for access in a given table. The main interest here is ensuring that the count for all parameters for a given event and index field are the same. */ //---------------------------------------------------------------------- // #include #include #include #include "EventVar.h" #include "MetaSummary.h" #include "GATS_DB_Exception.h" #include "GATS_Utilities.hpp" //#include "SOFIELevel1DBUtilities.h" using namespace std; using namespace gatsDBpp; //using namespace GATS_Utilities; bool MetaSummary::EntryExists(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 = "MetaSummary::EntryExists Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } }; string MetaSummary::AssocEntryName(string tableName) const { string strResult; try { GATS_DB_Results results; string strSQL = "SELECT Index_Array FROM " + metaTable + " WHERE TableName = '" + tableName + "'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0 ) strResult = results[0][0].asString(); else strResult = ""; } catch (exception &ex) { string errstr = "MetaSummary::AssocEntryName Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } return strResult; } long MetaSummary::getIndexSize(string tableName) const { try { GATS_DB_Results results; string strErr; string varName; long arraySize; string strSQL = "SELECT Index_Array FROM " + metaTable + " WHERE TableName = '" + tableName +"'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0 ) varName = results[0][0].asString(); else { strErr = string("No entry for table ") + tableName; throw runtime_error(strErr); } switch (inEvent->EventVarExists(varName) ) { case NOVAR: strErr = string("No entry for ") + varName + string(" in ouput Event object"); throw runtime_error(strErr); break; case INTEGER: { EventVar varArray; inEvent->getEventVar(varName, varArray); arraySize = varArray.size(); } break; case FLOAT: { EventVar varArray; inEvent->getEventVar(varName, varArray); arraySize = varArray.size(); } break; case DOUBLE: { EventVar varArray; inEvent->getEventVar(varName, varArray); arraySize = varArray.size(); } break; default: throw runtime_error("programming error in Event::EventVarExists(). Bad Type!"); } return arraySize; } catch (exception &ex) { string errstr = "MetaSummary::getIndexSize() Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } } bool MetaSummary::processTable(string tableName) const { bool processFlag = false; string strResult; try { GATS_DB_Results results; string strSQL = "SELECT WriteFlag FROM " + metaTable + " WHERE TableName = '" + tableName + "'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0 ) { strResult = results[0][0].asString(); if (strResult == "Y") processFlag = true; } else processFlag = false; } catch (exception &ex) { string errstr = "MetaSummary::AssocEntryName Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } return processFlag; }