Skip to content

Commit

Permalink
Revert "Re #5838. Added support for multiple file name formats"
Browse files Browse the repository at this point in the history
This reverts commit c3722b3.

It looks like the original commit of this was deleted after it had
already been pushed up, which has made bad things happen.
  • Loading branch information
RussellTaylor committed Sep 20, 2012
1 parent b95e86e commit 4099931
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 310 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ set ( TEST_FILES
ILiveListenerTest.h
IMDWorkspaceTest.h
ISpectrumTest.h
# IkedaCarpenterModeratorTest.h
IkedaCarpenterModeratorTest.h
ImmutableCompositeFunctionTest.h
ImplicitFunctionParserFactoryTest.h
InstrumentDataServiceTest.h
Expand Down
3 changes: 1 addition & 2 deletions Code/Mantid/Framework/API/src/FileFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,8 @@ namespace Mantid
runPart = hint.substr(nChars);
}

unsigned int irunPart = boost::lexical_cast<unsigned int>( runPart );
Kernel::InstrumentInfo instr = Kernel::ConfigService::Instance().getInstrument(instrPart);
size_t nZero = instr.zeroPadding(irunPart);
size_t nZero = instr.zeroPadding();
// remove any leading zeros in case there are too many of them
std::string::size_type i = runPart.find_first_not_of('0');
runPart.erase(0, i);
Expand Down
5 changes: 0 additions & 5 deletions Code/Mantid/Framework/API/test/ExperimentInfoTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ class ExperimentInfoTest : public CxxTest::TestSuite
{
public:

ExperimentInfoTest()
{
ConfigService::Instance().updateFacilities();
}

void test_GetInstrument_default()
{
Expand Down Expand Up @@ -550,7 +546,6 @@ class ExperimentInfoTest : public CxxTest::TestSuite
//
void testHelperFunctions()
{
ConfigService::Instance().updateFacilities();
ExperimentInfo helper;
std::string boevs = helper.getInstrumentFilename("BIOSANS", "2100-01-31 22:59:59");
TS_ASSERT(!boevs.empty());
Expand Down
15 changes: 5 additions & 10 deletions Code/Mantid/Framework/API/test/FileFinderTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,22 @@ class FileFinderTest: public CxxTest::TestSuite
" <instrument name=\"HRPD\" shortname=\"HRP\">"
" <technique>Powder Diffraction</technique>"
" </instrument>"
" <instrument name=\"ABCD\" shortname=\"ABC\" >"
" <zeropadding size=\"8\"/>"
" <instrument name=\"ABCD\" shortname=\"ABC\" zeropadding=\"8\">"
" <technique>Powder Diffraction</technique>"
" </instrument>"
" <instrument name=\"EFG2H\" shortname=\"EFG2H\">"
" <zeropadding size=\"8\"/>"
" <instrument name=\"EFG2H\" shortname=\"EFG2H\" zeropadding=\"8\">"
" <technique>Powder Diffraction</technique>"
" </instrument>"
" <instrument name=\"CRISP\" shortname=\"CSP\">"
" <technique>Technique</technique>"
" </instrument>"
" <instrument name=\"MUSR\">"
" <zeropadding size=\"8\"/>"
" <instrument name=\"MUSR\" zeropadding=\"8\">"
" <technique>Powder Diffraction</technique>"
" </instrument>"
" <instrument name=\"LOQ\">"
" <zeropadding size=\"5\"/>"
" <instrument name=\"LOQ\" zeropadding=\"5\">"
" <technique>Small Angle Scattering</technique>"
" </instrument>"
" <instrument name=\"OFFSPEC\">"
" <zeropadding size=\"8\"/>"
" <instrument name=\"OFFSPEC\" zeropadding=\"8\">"
" <technique>Reflectometer</technique>"
" </instrument>"
" </facility>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ namespace Algorithms
void GetTimeSeriesLogInformation::exportErrorLog(API::MatrixWorkspace_sptr ws, std::vector<Kernel::DateAndTime> abstimevec, double dts)
{
std::string outputdir = getProperty("OutputDirectory");
if (!outputdir.empty() && outputdir[outputdir.size()-1] != '/')
if (outputdir[outputdir.size()-1] != '/')
outputdir += "/";

std::string ofilename = outputdir + "errordeltatime.txt";
Expand Down
18 changes: 3 additions & 15 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/InstrumentInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "MantidKernel/Logger.h"
#include <set>
#include <string>
#include <map>

//----------------------------------------------------------------------
// Forward declarations
Expand Down Expand Up @@ -64,10 +63,8 @@ class MANTID_KERNEL_DLL InstrumentInfo
const std::string name() const;
/// Return the short name of the instrument
const std::string shortName() const ;
/// Returns zero padding for this instrument and a run number
int zeroPadding(unsigned int runNumber) const;
/// Returns file prefix for this instrument and a run number
std::string filePrefix(unsigned int runNumber) const;
/// Returns zero padding for this instrument
int zeroPadding() const;
/// Returns the default delimiter between instrument name and run number
std::string delimiter() const;
/// Returns the name of the live listener
Expand All @@ -82,20 +79,11 @@ class MANTID_KERNEL_DLL InstrumentInfo
private:
void fillTechniques(const Poco::XML::Element* elem);
void fillLiveData(const Poco::XML::Element* elem);
void fillZeroPadding(const Poco::XML::Element* elem);

/// Typedef for the zeropadding holder, first is starting run-number,
/// second is file prefix - zero padding pair
typedef std::map<unsigned int, std::pair<std::string,int> > ZeroPaddingMap;
/// get the zeropadding part
int getZeroPadding(ZeroPaddingMap::const_iterator it) const {return it->second.second;}
/// get the prefix part
const std::string& getPrefix(ZeroPaddingMap::const_iterator it) const {return it->second.first;}

const FacilityInfo* m_facility; ///< Facility
std::string m_name; ///< Instrument name
std::string m_shortName; ///< Instrument short name
ZeroPaddingMap m_zeroPadding; ///< Run number-dependent zero padding
int m_zeroPadding; ///< Zero padding
std::string m_delimiter; ///< Delimiter between instrument name and run number
std::string m_liveListener; ///< Name of the live listener class
std::string m_liveDataAddress; ///< Host & port for live data connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace Kernel
/// The various sections of the given string to parse.
std::string m_dirString, m_instString, m_underscoreString, m_runString, m_extString;
/// The instrument-specific run zero padding value.
//int m_zeroPadding;
int m_zeroPadding;
/// All the valid instrument names.
std::set<std::string, ReverseCaselessCompare> m_validInstNames;
};
Expand All @@ -134,7 +134,7 @@ namespace Kernel
{
public:
/// Constructor.
GenerateFileName(const std::string & prefix, const std::string & suffix, const std::string & instString);
GenerateFileName(const std::string & prefix, const std::string & suffix, int zeroPadding);

/// Overloaded function operator that generates a vector of file names from a vector of runs.
std::vector<std::string> operator()(const std::vector<unsigned int> & runs);
Expand All @@ -146,8 +146,8 @@ namespace Kernel
std::string m_prefix;
/// String that suffixes any generated file names.
std::string m_suffix;
/// String that identifies the instrument
std::string m_instString;
/// The length of zero padding needed.
int m_zeroPadding;
};

/**
Expand Down
119 changes: 7 additions & 112 deletions Code/Mantid/Framework/Kernel/src/InstrumentInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <Poco/DOM/NodeList.h>
#include <Poco/DOM/Text.h>

#include <boost/lexical_cast.hpp>

#include <algorithm>

namespace Mantid
Expand All @@ -29,6 +27,11 @@ namespace Mantid
InstrumentInfo::InstrumentInfo(const FacilityInfo* f,const Poco::XML::Element* elem)
: m_facility(f), m_liveListener(), m_liveDataAddress()
{
std::string paddingStr = elem->getAttribute("zeropadding");
if ( paddingStr.empty() || !Mantid::Kernel::Strings::convert(paddingStr,m_zeroPadding) )
{
m_zeroPadding = f->zeroPadding();
}

m_name = elem->getAttribute("name");
if (m_name.empty())
Expand All @@ -52,7 +55,6 @@ namespace Mantid

fillTechniques(elem);
fillLiveData(elem);
fillZeroPadding(elem);
}

/**
Expand Down Expand Up @@ -84,54 +86,9 @@ namespace Mantid
}

/// Returns zero padding for this instrument
int InstrumentInfo::zeroPadding(unsigned int runNumber) const
int InstrumentInfo::zeroPadding() const
{
if ( m_zeroPadding.empty() ) return m_facility->zeroPadding();
if ( m_zeroPadding.size() == 1 )
{
auto padding = m_zeroPadding.begin();
if ( runNumber >= padding->first )
return getZeroPadding(padding);
else
return m_facility->zeroPadding();
}
auto last = m_zeroPadding.end(); --last;
for(auto it = m_zeroPadding.begin(); it != last; ++it)
{
auto next = it; ++next;
if ( runNumber >= it->first && runNumber < next->first )
{
return getZeroPadding(it);
}
}
return getZeroPadding(last);
}

/**
* Returns file prefix for this instrument and a run number.
* @param runNumber :: A run number.
*/
std::string InstrumentInfo::filePrefix(unsigned int runNumber) const
{
if ( m_zeroPadding.empty() ) return m_shortName;
if ( m_zeroPadding.size() == 1 )
{
auto padding = m_zeroPadding.begin();
if ( runNumber >= padding->first )
return getPrefix(padding);
else
return m_shortName;
}
auto last = m_zeroPadding.end(); --last;
for(auto it = m_zeroPadding.begin(); it != last; ++it)
{
auto next = it; ++next;
if ( runNumber >= it->first && runNumber < next->first )
{
return getPrefix(it);
}
}
return getPrefix(last);
return m_zeroPadding;
}

/// Returns the name of the live listener
Expand Down Expand Up @@ -161,68 +118,6 @@ namespace Mantid
return *m_facility;
}

/// Called from constructor to fill zero padding
void InstrumentInfo::fillZeroPadding(const Poco::XML::Element* elem)
{
Poco::XML::NodeList* pNL_zeropadding = elem->getElementsByTagName("zeropadding");
unsigned long n = pNL_zeropadding->length();

for (unsigned long i = 0; i < n; ++i)
{
auto elem = dynamic_cast<Poco::XML::Element*>( pNL_zeropadding->item(i) );
if ( !elem ) continue;
// read the zero padding size
if ( !elem->hasAttribute("size") )
{
g_log.error("Zeropadding size is missing for instrument "+m_name);
throw std::runtime_error("Zeropadding size is missing for instrument "+m_name);
}
auto& sizeStr = elem->getAttribute("size");
int size = 0;
if ( !Mantid::Kernel::Strings::convert(sizeStr,size) )
{
g_log.error("Zeropadding size must be an integer value (instrument "+m_name+")");
throw std::runtime_error("Zeropadding size must be an integer value (instrument "+m_name+")");
}
// read the start run number
unsigned int startRunNumber = 0;
if ( !elem->hasAttribute("startRunNumber") )
{
if ( !m_zeroPadding.empty() )
{
g_log.error("Zeropadding size is missing for instrument "+m_name);
throw std::runtime_error("Zeropadding size is missing for instrument "+m_name);
}
}
else
{
auto& startRunNumberStr = elem->getAttribute("startRunNumber");
try
{
startRunNumber = boost::lexical_cast<unsigned int>( startRunNumberStr );
}
catch(...)
{
g_log.error("Zeropadding start run number must be an integer value (instrument "+m_name+")");
throw std::runtime_error("Zeropadding start run number must be an integer value (instrument "+m_name+")");
}
}
// read the file prefix
std::string prefix = m_shortName;
if ( elem->hasAttribute("prefix") )
{
prefix = elem->getAttribute("prefix");
}
m_zeroPadding[startRunNumber] = std::make_pair(prefix,size);
}
pNL_zeropadding->release();

if (m_zeroPadding.empty())
{
m_zeroPadding[0] = std::make_pair(m_shortName,m_facility->zeroPadding());
}
}

/// Called from constructor to fill live listener name
void InstrumentInfo::fillTechniques(const Poco::XML::Element* elem)
{
Expand Down

0 comments on commit 4099931

Please sign in to comment.