diff options
author | Brian Helfrich <helfrich9000@gmail.com> | 2008-01-29 01:15:46 +0000 |
---|---|---|
committer | Brian Helfrich <helfrich9000@gmail.com> | 2008-01-29 01:15:46 +0000 |
commit | 0c1762a6afba84ccd01aef8c51cb7aae734a8d1e (patch) | |
tree | d9bc4f9158355e3b8ffdb01b00aeb244676f1702 | |
parent | d5434222bf82fa95a8a5279d610924c6019a8bd9 (diff) | |
download | nanoengineer-0c1762a6afba84ccd01aef8c51cb7aae734a8d1e.tar.gz nanoengineer-0c1762a6afba84ccd01aef8c51cb7aae734a8d1e.zip |
Now handles data stores that are still being written to.
10 files changed, 216 insertions, 22 deletions
diff --git a/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataImportExportPlugin.h b/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataImportExportPlugin.h index d80556c79..891fd811b 100644 --- a/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataImportExportPlugin.h +++ b/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataImportExportPlugin.h @@ -53,6 +53,9 @@ class NXDataImportExportPlugin : public NXPlugin { * handle from dataStoreInfo. If opening a multi-frame file, a handle * to it will be stored in the dataStoreInfo for later use (subsequent * importFromFile calls.) + * + * No modifications to the given moleculeSet will result in deletion + * of the frame with the given frameIndex. */ virtual NXCommandResult* importFromFile (NXMoleculeSet* moleculeSet, NXDataStoreInfo* dataStoreInfo, diff --git a/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataStoreInfo.h b/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataStoreInfo.h index 6d4a34ede..326735adf 100644 --- a/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataStoreInfo.h +++ b/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataStoreInfo.h @@ -20,6 +20,9 @@ class NXDataStoreInfo { public: NXDataStoreInfo() { } + const string& getFilename() { return _filename; } + void setFilename(const string& filename) { _filename = filename; } + void addTrajectory(string name, int id) { _trajectories[name] = id; } int getTrajectoryId(string name) { return _trajectories[name]; } //vector<string> getTrajectoryNames(); @@ -38,6 +41,8 @@ class NXDataStoreInfo { void* getHandle(int id) { return _handle[id]; } private: + string _filename; + // Maps trajectory name to its frame set id. map<string, int> _trajectories; diff --git a/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXEntityManager.h b/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXEntityManager.h index 68901e4e5..d9c305495 100644 --- a/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXEntityManager.h +++ b/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXEntityManager.h @@ -36,11 +36,12 @@ class NXEntityManager { // Import/export plugins // void loadDataImportExportPlugins(NXProperties* properties); - NXCommandResult* importFromFile(const string& filename); + NXCommandResult* importFromFile(const string& filename, + int frameSetId = -1, int frameIndex = 0); NXCommandResult* exportToFile(const string& filename, int frameSetId = -1, int frameIndex = 0); - const NXDataStoreInfo* getDataStoreInfo() { return dataStoreInfo; } + NXDataStoreInfo* getDataStoreInfo() { return dataStoreInfo; } // // Frame sets @@ -55,18 +56,13 @@ class NXEntityManager { moleculeSets[frameSetId].push_back(moleculeSet); return moleculeSets[frameSetId].size() - 1; } + void removeLastFrame(int frameSetId) { + moleculeSets[frameSetId].pop_back(); + } unsigned int getFrameCount(int frameSetId) { return moleculeSets[frameSetId].size(); } - NXMoleculeSet* getRootMoleculeSet(int frameSetId, int frameIndex = 0) { - if (frameIndex < (int)moleculeSets[frameSetId].size()) - return moleculeSets[frameSetId][frameIndex]; - else { - // See if there's a new frame - // or - return 0; - } - } + NXMoleculeSet* getRootMoleculeSet(int frameSetId, int frameIndex); private: NXPluginGroup* dataImpExpPluginGroup; diff --git a/cad/plugins/NanoVision-1/src/Interface/NXEntityManager.cpp b/cad/plugins/NanoVision-1/src/Interface/NXEntityManager.cpp index 8386cf923..101c46d23 100644 --- a/cad/plugins/NanoVision-1/src/Interface/NXEntityManager.cpp +++ b/cad/plugins/NanoVision-1/src/Interface/NXEntityManager.cpp @@ -124,19 +124,32 @@ void NXEntityManager::loadDataImportExportPlugins(NXProperties* properties) { /* FUNCTION: importFromFile */ -NXCommandResult* NXEntityManager::importFromFile(const string& filename) { +/** + * @param frameSetId If -1, import everything, otherwise, resume importing + * the frame set from the given frameIndex. + */ +NXCommandResult* NXEntityManager::importFromFile(const string& filename, + int frameSetId, + int frameIndex) { NXCommandResult* result; //PR_Lock(importExportPluginsMutex); + dataStoreInfo->setFilename(filename); string fileType = getFileType(filename); map<string, NXDataImportExportPlugin*>::iterator iter = dataImportTable.find(fileType); if (iter != dataImportTable.end()) { NXDataImportExportPlugin* plugin = iter->second; - int frameSetId = addFrameSet(); - int frameIndex = addFrame(frameSetId); + + if (frameSetId == -1) { + frameSetId = addFrameSet(); + frameIndex = addFrame(frameSetId); + + } else { + frameIndex = addFrame(frameSetId); + } try { plugin->setMode(fileType); @@ -145,8 +158,16 @@ NXCommandResult* NXEntityManager::importFromFile(const string& filename) { frameIndex), dataStoreInfo, filename, frameSetId, frameIndex); + if (result->getResult() == NX_CMD_SUCCESS) { + // Delete the frame if the molecule set wasn't populated. + NXMoleculeSet* moleculeSet = + getRootMoleculeSet(frameSetId, frameIndex); + if ((moleculeSet->childCount() == 0) && + (moleculeSet->moleculeCount() == 0)) + removeLastFrame(frameSetId); + // TODO: // Finish the current frame set, then examine the dataStoreInfo // for additional files to import. @@ -160,9 +181,12 @@ NXCommandResult* NXEntityManager::importFromFile(const string& filename) { dataStoreInfo, filename, frameSetId, frameIndex); } - } + } else + removeLastFrame(frameSetId); } catch (...) { + removeLastFrame(frameSetId); + string msg = fileType; msg += "->importFromFile() threw exception"; NXLOG_SEVERE("NXEntityManager", msg); @@ -234,7 +258,7 @@ NXCommandResult* NXEntityManager::exportToFile dataStoreInfo->setLastFrame (frameSetId, !allFrameExport || - (frameIndex > (int)moleculeSets[frameSetId].size() - 2)); + (frameIndex > (int)moleculeSets[frameSetId].size() - 2)); vector<NXMoleculeSet*>::iterator iter = moleculeSets[frameSetId].begin(); result = @@ -295,6 +319,31 @@ NXCommandResult* NXEntityManager::exportToFile } +/* FUNCTION: getRootMoleculeSet */ +NXMoleculeSet* NXEntityManager::getRootMoleculeSet(int frameSetId, + int frameIndex) { + + if (frameIndex < (int)moleculeSets[frameSetId].size()) + return moleculeSets[frameSetId][frameIndex]; + else { + if (dataStoreInfo->storeIsComplete(frameSetId)) + return 0; + else { + // See if there's a new frame + NXCommandResult* result = + importFromFile(dataStoreInfo->getFilename(), + frameSetId, + moleculeSets[frameSetId].size()); + // TODO: Handle when result != 0 + if (frameIndex < (int)moleculeSets[frameSetId].size()) + return moleculeSets[frameSetId][frameIndex]; + else + return 0; + } + } +} + + /* FUNCTION: getFileType */ string NXEntityManager::getFileType(const string& filename) { int index = filename.rfind("."); diff --git a/cad/plugins/NanoVision-1/src/KDevelop/Testing/HDF5_Consumer/HDF5_Consumer.pro b/cad/plugins/NanoVision-1/src/KDevelop/Testing/HDF5_Consumer/HDF5_Consumer.pro new file mode 100644 index 000000000..69f0e4cfc --- /dev/null +++ b/cad/plugins/NanoVision-1/src/KDevelop/Testing/HDF5_Consumer/HDF5_Consumer.pro @@ -0,0 +1,16 @@ +SOURCES += ../../../Testing/HDF5_Consumer/HDF5_Consumer.cpp + +TEMPLATE = app + +INCLUDEPATH += $(OPENBABEL_INCPATH) \ +../../../../include +LIBS += -lopenbabel \ +-L../../../../lib \ +-lHDF5_SimResultsImportExport \ +-lNanorexInterface \ +-lNanorexUtility +TARGETDEPS += ../../../../lib/libHDF5_SimResultsImportExport.so \ +../../../../lib/libNanorexInterface.so \ +../../../../lib/libNanorexUtility.so +DESTDIR = ../../../../bin/ + diff --git a/cad/plugins/NanoVision-1/src/KDevelop/Testing/Testing.pro b/cad/plugins/NanoVision-1/src/KDevelop/Testing/Testing.pro index 7440d3dbc..385cf14ca 100644 --- a/cad/plugins/NanoVision-1/src/KDevelop/Testing/Testing.pro +++ b/cad/plugins/NanoVision-1/src/KDevelop/Testing/Testing.pro @@ -1,3 +1,4 @@ TEMPLATE = subdirs -SUBDIRS += CppUnit +SUBDIRS += CppUnit \ + HDF5_Consumer diff --git a/cad/plugins/NanoVision-1/src/KDevelop/nv1.kdevelop b/cad/plugins/NanoVision-1/src/KDevelop/nv1.kdevelop index aa94916ce..a65ce27bb 100644 --- a/cad/plugins/NanoVision-1/src/KDevelop/nv1.kdevelop +++ b/cad/plugins/NanoVision-1/src/KDevelop/nv1.kdevelop @@ -156,21 +156,24 @@ <runarguments> <HDF5_SimResultsImportExport/> <GLT/> - <CppUnit></CppUnit> + <CppUnit/> + <HDF5_Consumer/> </runarguments> <cwd> <HDF5_SimResultsImportExport>/home/rmanoj/Nanorex/SVN/trunk/cad/plugins/NanoVision-1/src/KDevelop</HDF5_SimResultsImportExport> <GLT>/home/rmanoj/Nanorex/SVN/trunk/cad/plugins/NanoVision-1/src/KDevelop</GLT> <CppUnit>/home/bh/11Nano/SVN-D/cad/plugins/NanoVision-1/src/KDevelop/../../../..</CppUnit> + <HDF5_Consumer>/home/bh/11Nano/SVN-D/cad/plugins/NanoVision-1/src/KDevelop</HDF5_Consumer> </cwd> <debugarguments> <HDF5_SimResultsImportExport/> <GLT/> - <CppUnit></CppUnit> + <CppUnit/> + <HDF5_Consumer/> </debugarguments> </run> <general> - <activedir>Testing/CppUnit</activedir> + <activedir>Testing</activedir> </general> <make> <abortonerror>true</abortonerror> diff --git a/cad/plugins/NanoVision-1/src/Plugins/HDF5_SimResultsImportExport/HDF5_SimResultsImportExport.cpp b/cad/plugins/NanoVision-1/src/Plugins/HDF5_SimResultsImportExport/HDF5_SimResultsImportExport.cpp index 9f3887d86..5ec5ba8bd 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/HDF5_SimResultsImportExport/HDF5_SimResultsImportExport.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/HDF5_SimResultsImportExport/HDF5_SimResultsImportExport.cpp @@ -51,6 +51,15 @@ NXCommandResult* HDF5_SimResultsImportExport::importFromFile populateCommandResult(result, message.c_str()); } + simResults->synchronize(); + + // See if the requested frame exists (yet) and abort if it doesn't + // signaling to delete the frame for the given frameIndex. + int frameCount = 0; + simResults->getFrameCount("frame-set-1", frameCount); + if (frameCount == 0) + return result; + // If this is the first call to import the data store, retrieve the meta // information about the data store, and other data. if ((frameIndex == 0) && (frameSetId == 0) && @@ -82,7 +91,9 @@ NXCommandResult* HDF5_SimResultsImportExport::importFromFile unsigned int atomIds[atomCount]; unsigned int atomicNumbers[atomCount]; float positions[atomCount*3]; - void* bonds = (void*)malloc(bondCount*sizeof(SimResultsBond)); + void* bonds = 0; + if (bondCount != 0) + bonds = (void*)malloc(bondCount*sizeof(SimResultsBond)); // Retrieve atom data if (result->getResult() == NX_CMD_SUCCESS) { @@ -105,7 +116,7 @@ NXCommandResult* HDF5_SimResultsImportExport::importFromFile } // Retrieve bond data - if (result->getResult() == NX_CMD_SUCCESS) { + if ((result->getResult() == NX_CMD_SUCCESS) && (bondCount != 0)) { status = simResults->getFrameBonds("frame-set-1", 0, bonds, message); if (status) populateCommandResult(result, message.c_str()); diff --git a/cad/plugins/NanoVision-1/src/Plugins/HDF5_SimResultsImportExport/HDF5_SimResultsImportExportTest.cpp b/cad/plugins/NanoVision-1/src/Plugins/HDF5_SimResultsImportExport/HDF5_SimResultsImportExportTest.cpp index 0f5b0e8c6..aa5c1e259 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/HDF5_SimResultsImportExport/HDF5_SimResultsImportExportTest.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/HDF5_SimResultsImportExport/HDF5_SimResultsImportExportTest.cpp @@ -76,10 +76,12 @@ void HDF5_SimResultsImportExportTest::basicExportTest() { bond = molecule->NewBond(); bond->SetBegin(atomO); bond->SetEnd(atomH2); +printf("\n> 3\n"); // Write it with the HDF5_SimResultsImportExport plugin NXCommandResult* commandResult = entityManager->exportToFile("testHDF5store.nh5", frameSetId, -1); +printf("> 4\n"); if (commandResult->getResult() != NX_CMD_SUCCESS) printf("\n%s\n", qPrintable(GetNV1ResultCodeString(commandResult))); CPPUNIT_ASSERT(commandResult->getResult() == NX_CMD_SUCCESS); diff --git a/cad/plugins/NanoVision-1/src/Testing/HDF5_Consumer/HDF5_Consumer.cpp b/cad/plugins/NanoVision-1/src/Testing/HDF5_Consumer/HDF5_Consumer.cpp new file mode 100644 index 000000000..ba41b91a7 --- /dev/null +++ b/cad/plugins/NanoVision-1/src/Testing/HDF5_Consumer/HDF5_Consumer.cpp @@ -0,0 +1,108 @@ + +// Copyright 2008 Nanorex, Inc. See LICENSE file for details. + +#include <stdlib.h> +#include <stdio.h> +#include <signal.h> +#include <time.h> + +#include <string> + +#include "Nanorex/Interface/NXEntityManager.h" +using namespace Nanorex; + + +/* FUNCTION: set_timespec */ +void set_timespec(struct timespec *tmr, unsigned long long ustime) { + tmr->tv_sec = (time_t) (ustime / 1000000ULL); + tmr->tv_nsec = (long) (1000ULL * (ustime % 1000000ULL)); +} + + +NXEntityManager* entityManager = 0; +int trajId = 0; +unsigned int frameIndex = 0; + + +/* FUNCTION: render */ +void render(int dummy) { + NXMoleculeSet* moleculeSet = + entityManager->getRootMoleculeSet(trajId, frameIndex); + unsigned int frameCount = 0; + if (moleculeSet != 0) { + printf("\n==========================\n"); + frameCount = entityManager->getFrameCount(trajId); + OBMolIterator moleculeIter = moleculeSet->moleculesBegin(); + printf("%d ", (*moleculeIter)->GetAtom(1)->GetAtomicNum()); + printf("%g ", (*moleculeIter)->GetAtom(1)->GetZ()); + printf("%d ", (*moleculeIter)->NumBonds()); + printf("frame:%d/%d\n", frameIndex+1, frameCount); + + frameIndex++; + } +} + + +/* FUNCTION: main */ +int main(int argc, char* argv[]) { + + // Set the entity manager up + // + entityManager = new NXEntityManager(); + + NXProperties* properties = new NXProperties(); + properties->setProperty("NXEntityManager.importExport.0.plugin", + "libHDF5_SimResultsImportExport"); + properties->setProperty("NXEntityManager.importExport.0.pluginConfigFile", + "../lib/HDF5_SimResultsImportExport.cfg"); + entityManager->loadDataImportExportPlugins(properties); + delete properties; + + // Prime read + NXCommandResult* commandResult = + entityManager->importFromFile("Testing/shared.nh5"); + if (commandResult->getResult() != NX_CMD_SUCCESS) { + printf("%s\n", qPrintable(GetNV1ResultCodeString(commandResult))); + exit(1); + } + + // Discover a store-not-complete trajectory frame set + NXDataStoreInfo* dataStoreInfo = entityManager->getDataStoreInfo(); + trajId = dataStoreInfo->getTrajectoryId("frame-set-1"); + if (dataStoreInfo->storeIsComplete(trajId)) { + printf("error: data store is complete\n"); + exit(1); + } + + // Set up a repeating timer and start it + timer_t timerid; + struct sigaction sigact; + struct sigevent sigev; + sigact.sa_handler = render; + sigemptyset(&(sigact.sa_mask)); + sigact.sa_flags = 0; + if (sigaction(SIGUSR1, &sigact, (struct sigaction *)NULL) == -1) { + printf("sigaction failed"); + exit(1); + } + sigev.sigev_notify = SIGEV_SIGNAL; + sigev.sigev_signo = SIGUSR1; + if (timer_create(CLOCK_REALTIME, &sigev, &timerid) == -1) { + printf("timer_create failed"); + exit(1); + } + struct itimerspec tmr; + set_timespec(&tmr.it_value, 1000 * 1000); // 1000 milliseconds + //set_timespec(&tmr.it_value, 100 * 1000); // 100 milliseconds + set_timespec(&tmr.it_interval, 100 * 1000); + if (timer_settime(timerid, 0, &tmr, (struct itimerspec *)NULL) == -1) { + printf("timer_create failed"); + exit(1); + } + + while (!dataStoreInfo->storeIsComplete(trajId)) { + printf(" . "); fflush(0); + pause(); + } + return 0; +} |