Skip to content

Commit

Permalink
Revert "refs #6105. Fix old-style mangled names."
Browse files Browse the repository at this point in the history
This reverts commit 3ab9b12.
  • Loading branch information
OwenArnold committed Nov 16, 2012
1 parent 3ab9b12 commit b03454e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 118 deletions.
14 changes: 4 additions & 10 deletions Code/Mantid/Framework/Algorithms/src/CreateDummyCalFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Detectors will be assigned to group one when using AlignDetector or DiffractionF
#include "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/ConfigService.h"
#include "MantidAPI/InstrumentDataService.h"
#include "MantidGeometry/Instrument/IDFObject.h"

#include <queue>
#include <fstream>
Expand Down Expand Up @@ -140,18 +139,13 @@ namespace Mantid
// Handle used in the singleton constructor for instrument file should append the value
// of the last-modified tag inside the file to determine if it is already in memory so that
// changes to the instrument file will cause file to be reloaded.
auto temp = instshort + pRootElem->getAttribute("last-modified");// Generate the mangled name by hand (old-style)
instshort = instshort + pRootElem->getAttribute("last-modified");

// If instrument not in store, insult the user
if (!API::InstrumentDataService::Instance().doesExist(temp))
if (!API::InstrumentDataService::Instance().doesExist(instshort))
{
Mantid::Geometry::IDFObject idf(directoryName+instshort);
temp = idf.getMangledName(); // new style.
if (!API::InstrumentDataService::Instance().doesExist(temp))
{
g_log.error("Instrument "+instshort+" is not present in data store.");
throw std::runtime_error("Instrument "+instshort+" is not present in data store.");
}
g_log.error("Instrument "+instshort+" is not present in data store.");
throw std::runtime_error("Instrument "+instshort+" is not present in data store.");
}

// Get the names of groups
Expand Down
13 changes: 6 additions & 7 deletions Code/Mantid/Framework/DataHandling/test/LoadInstrumentTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,12 @@ class LoadInstrumentTest : public CxxTest::TestSuite
// This kind of IDF should lead to 2 instrument definitions - the physical and the neutronic
// But only 1 goes into the IDS (the neutronic instrument holds the physical instrument within itself)
TS_ASSERT_EQUALS( IDS.size(), 1 );
if (IDS.size() != 1) return;
TS_ASSERT_EQUALS( IDS.getObjects()[0]->getName(), "INDIRECT");

std::string name("INDIRECT_Definition.xml2011-08-25T12:00:00");
TS_ASSERT( IDS.doesExist(name) );
if (!IDS.doesExist(name)) return;

// Retrieve the neutronic instrument from the InstrumentDataService
Instrument_const_sptr neutronicInst = IDS.getObjects()[0];
Instrument_const_sptr neutronicInst = IDS.retrieve(name);
// And pull out a handle to the physical instrument from within the neutronic one
Instrument_const_sptr physicalInst = neutronicInst->getPhysicalInstrument();
// They should not be the same object
Expand Down Expand Up @@ -525,15 +525,14 @@ class LoadInstrumentTest : public CxxTest::TestSuite
"</instrument>";

LoadInstrument instLoader;
instLoader.setRethrows(true);
instLoader.initialize();
instLoader.setProperty("Workspace",WorkspaceFactory::Instance().create("EventWorkspace",1,1,1));
instLoader.setProperty("InstrumentXML",instrumentXML);
instLoader.setProperty("InstrumentName", "Nonsense"); // Want to make sure it doesn't matter what we call it

instLoader.execute();
TS_ASSERT( instLoader.execute() )

TS_ASSERT_EQUALS(1, IDS.size())
TS_ASSERT( IDS.doesExist("Nonsense2010-10-06T16:21:30") )
}

void test_failure_if_InstrumentXML_property_set_but_not_InstrumentName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class DLLExport AbstractIDFObject
virtual std::string getFileNameOnly() const = 0;
virtual std::string getExtension() const = 0;
virtual Poco::Timestamp getLastModified() const = 0;
virtual std::string getFormattedLastModified() const = 0;
virtual std::string getMangledName() const = 0;
virtual bool exists() const = 0;
virtual ~AbstractIDFObject(){};
private:
Expand All @@ -76,8 +74,6 @@ class DLLExport AbstractIDFObject
virtual std::string getFileNameOnly() const;
virtual std::string getExtension() const;
virtual Poco::Timestamp getLastModified() const;
virtual std::string getFormattedLastModified() const;
virtual std::string getMangledName() const;
virtual bool exists() const;
virtual ~IDFObject();

Expand Down Expand Up @@ -106,8 +102,6 @@ class DLLExport AbstractIDFObject
virtual std::string getFileNameOnly() const { return m_emptyResponse;}
virtual std::string getExtension() const { return m_emptyResponse;}
virtual Poco::Timestamp getLastModified() const { throw std::runtime_error("Not implemented on NullIDFObject");}
virtual std::string getFormattedLastModified() const { throw std::runtime_error("Not implemented on NullIDFObject");}
virtual std::string getMangledName() const { throw std::runtime_error("Not implemented on NullIDFObject");}
virtual bool exists() const { return false;}
virtual ~NullIDFObject(){};
};
Expand Down
19 changes: 0 additions & 19 deletions Code/Mantid/Framework/Geometry/src/Instrument/IDFObject.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "MantidGeometry/Instrument/IDFObject.h"
#include <Poco/DateTimeFormatter.h>

namespace Mantid
{
Expand Down Expand Up @@ -87,24 +86,6 @@ namespace Mantid
return m_defFile.getLastModified();
}

/**
Gets a formatted string of the last modified timestamp.
@return timestamp as a formatted string.
*/
std::string IDFObject::getFormattedLastModified() const
{
return Poco::DateTimeFormatter::format(this->getLastModified(), "%Y-%d-%mT%H:%M:%S");
}

/**
Gets the idf file as a mangled name.
@return the idf file as a mangled name.
*/
std::string IDFObject::getMangledName() const
{
return this->getFileNameOnly() + this->getFormattedLastModified();
}

/**
Check that the file exists.
@return True if it exists otherwise False.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "MantidGeometry/Instrument/InstrumentDefinitionParser.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/Component.h"
#include "MantidGeometry/Instrument/Detector.h"
#include "MantidGeometry/Instrument/InstrumentDefinitionParser.h"
#include "MantidGeometry/Instrument/ObjCompAssembly.h"
#include "MantidGeometry/Instrument/ReferenceFrame.h"
#include "MantidGeometry/Instrument/RectangularDetector.h"
Expand Down Expand Up @@ -164,25 +164,15 @@ namespace Geometry
* */
std::string InstrumentDefinitionParser::getMangledName()
{
// Use the file in preference if possible.
if(this->m_xmlFile->exists())
{
return m_xmlFile->getMangledName();
}
else if (pDoc != NULL)
if (!pDoc)
throw std::runtime_error("Call InstrumentDefinitionParser::initialize() before getMangledName.");
std::string lastModified = pRootElem->getAttribute("last-modified");
if (lastModified.length() == 0)
{
std::string lastModified = pRootElem->getAttribute("last-modified");
if (lastModified.length() == 0)
{
g_log.warning() << "The IDF that you are using doesn't contain a 'last-modified' field. ";
g_log.warning() << "You may not get the correct definition file loaded." << std::endl ;
}
return m_xmlFile->getFileNameOnly() + lastModified;
}
else
{
throw std::runtime_error("Call InstrumentDefinitionParser::initialize() before getMangledName.");
}
return m_xmlFile->getFileNameOnly() + lastModified;
}

//----------------------------------------------------------------------------------------------
Expand Down
61 changes: 4 additions & 57 deletions Code/Mantid/Framework/Geometry/test/IDFObjectTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#include <cxxtest/TestSuite.h>
#include "MantidKernel/ConfigService.h"
#include "MantidGeometry/Instrument/IDFObject.h"
#include "MantidTestHelpers/ScopedFileHelper.h"
#include <Poco/Path.h>
#include <Poco/DateTimeFormatter.h>
#include <Poco/Thread.h>

using Mantid::Geometry::IDFObject;
using Mantid::Kernel::ConfigService;
Expand Down Expand Up @@ -67,7 +64,7 @@ class IDFObjectTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(".xml", obj.getExtension());
}

void testGetFileNameOnly()
void testGetLastModified()
{
const std::string filenameonly = "IDF_for_UNIT_TESTING.xml";
const std::string filename = ConfigService::Instance().getInstrumentDirectory() + "/IDFs_for_UNIT_TESTING/" + filenameonly;
Expand All @@ -84,62 +81,12 @@ class IDFObjectTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(file.getLastModified(), obj.getLastModified());
}

void testGetFormattedModifiedTimestamp()
{
const std::string filename = ConfigService::Instance().getInstrumentDirectory() + "/IDFs_for_UNIT_TESTING/IDF_for_UNIT_TESTING.xml";
Poco::File file(filename);

IDFObject obj(filename);
TS_ASSERT_EQUALS(Poco::DateTimeFormatter::format(file.getLastModified(), "%Y-%d-%mT%H:%M:%S"), obj.getFormattedLastModified());
}

void testGetMangledName()
{
const std::string filename = ConfigService::Instance().getInstrumentDirectory() + "/IDFs_for_UNIT_TESTING/IDF_for_UNIT_TESTING.xml";

Poco::File file(filename);
auto head = "IDF_for_UNIT_TESTING.xml";
auto tail = Poco::DateTimeFormatter::format(file.getLastModified(), "%Y-%d-%mT%H:%M:%S");

IDFObject obj(filename);

TS_ASSERT_EQUALS(head+tail, obj.getMangledName());
}

// Test that the last modified date fetched on each platform does actually make sense!
void testGetModifiedTimestampAfterChange()
{
const std::string fileName = "check_last_modified_date.xml";
const std::string fileContents = "some_idf_contents_that_donesn't_matter";
// Create a file.
ScopedFileHelper::ScopedFile file(fileContents, fileName);
IDFObject IDF(file.getFileName());
// Record the modification timestamp
Poco::Timestamp timeOfCreation = IDF.getLastModified();
// Delay
const int delay = 1;
Poco::Thread::sleep(delay);
// Modify the file.
std::ofstream modIDF;
modIDF.open(IDF.getFileFullPathStr(), std::ios::out | std::ios::app);
if (!modIDF.is_open())
{
throw std::runtime_error("Cannot run test since file cannot be opened.");
}
modIDF << "\nchange" << std::endl;
modIDF.close();
// Record the modification timestamp.
Poco::Timestamp timeOfModification = IDF.getLastModified();

// Compare the modification dates.
TSM_ASSERT_LESS_THAN("The file modification dates do not reflect the fact that the file has been modified.", timeOfCreation, timeOfModification);
}

void testGetFileFullPathStr()
{
const std::string filename = ConfigService::Instance().getInstrumentDirectory() + "/IDFs_for_UNIT_TESTING/IDF_for_UNIT_TESTING.xml";
IDFObject obj(filename);
TS_ASSERT_EQUALS(Poco::Path(filename).toString(), obj.getFileFullPathStr());
IDFObject obj(filename);
TS_ASSERT_EQUALS(Poco::Path(filename).toString(), obj.getFileFullPathStr());

}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "MantidTestHelpers/ScopedFileHelper.h"

#include <gmock/gmock.h>
#include <boost/tuple/tuple.hpp>
#include "boost/tuple/tuple.hpp"

using namespace Mantid;
using namespace Mantid::Kernel;
Expand Down Expand Up @@ -156,6 +156,9 @@ class InstrumentDefinitionParserTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING( parser.initialize(filename, "For Unit Testing", xmlText); );
TS_ASSERT_THROWS_NOTHING( i = parser.parseXML(NULL); );

// Check the mangled name
TS_ASSERT_EQUALS( parser.getMangledName(), "IDF_for_UNIT_TESTING.xmlHello!");
// Remove it for clean test
try
{
Poco::File vtpFile(vtpFilename);
Expand Down Expand Up @@ -759,6 +762,8 @@ void testLoadingAndParsing()
TS_ASSERT_THROWS_NOTHING( parser.initialize(filename, "For Unit Testing", xmlText); );
TS_ASSERT_THROWS_NOTHING( i = parser.parseXML(NULL); );

// Check the mangled name
TS_ASSERT_EQUALS( parser.getMangledName(), "IDF_for_UNIT_TESTING.xmlHello!");
// Remove it for clean test
try
{
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/TestHelpers/src/ScopedFileHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ namespace ScopedFileHelper
}

/**
Getter for the filename with path.
@return File name and path.
Getter for the filename
@return File name only.
*/
std::string ScopedFile::getFileName() const
{
Expand Down

0 comments on commit b03454e

Please sign in to comment.