Skip to content

Commit

Permalink
Re #5838. Saving the changes to a branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Sep 21, 2012
1 parent 0fda64b commit 34bffa9
Show file tree
Hide file tree
Showing 14 changed files with 311 additions and 59 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: 2 additions & 1 deletion Code/Mantid/Framework/API/src/FileFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ 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();
size_t nZero = instr.zeroPadding(irunPart);
// 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: 5 additions & 0 deletions Code/Mantid/Framework/API/test/ExperimentInfoTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class ExperimentInfoTest : public CxxTest::TestSuite
{
public:

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

void test_GetInstrument_default()
{
Expand Down Expand Up @@ -546,6 +550,7 @@ 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: 10 additions & 5 deletions Code/Mantid/Framework/API/test/FileFinderTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,27 @@ class FileFinderTest: public CxxTest::TestSuite
" <instrument name=\"HRPD\" shortname=\"HRP\">"
" <technique>Powder Diffraction</technique>"
" </instrument>"
" <instrument name=\"ABCD\" shortname=\"ABC\" zeropadding=\"8\">"
" <instrument name=\"ABCD\" shortname=\"ABC\" >"
" <zeropadding size=\"8\"/>"
" <technique>Powder Diffraction</technique>"
" </instrument>"
" <instrument name=\"EFG2H\" shortname=\"EFG2H\" zeropadding=\"8\">"
" <instrument name=\"EFG2H\" shortname=\"EFG2H\">"
" <zeropadding size=\"8\"/>"
" <technique>Powder Diffraction</technique>"
" </instrument>"
" <instrument name=\"CRISP\" shortname=\"CSP\">"
" <technique>Technique</technique>"
" </instrument>"
" <instrument name=\"MUSR\" zeropadding=\"8\">"
" <instrument name=\"MUSR\">"
" <zeropadding size=\"8\"/>"
" <technique>Powder Diffraction</technique>"
" </instrument>"
" <instrument name=\"LOQ\" zeropadding=\"5\">"
" <instrument name=\"LOQ\">"
" <zeropadding size=\"5\"/>"
" <technique>Small Angle Scattering</technique>"
" </instrument>"
" <instrument name=\"OFFSPEC\" zeropadding=\"8\">"
" <instrument name=\"OFFSPEC\">"
" <zeropadding size=\"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[outputdir.size()-1] != '/')
if (!outputdir.empty() && outputdir[outputdir.size()-1] != '/')
outputdir += "/";

std::string ofilename = outputdir + "errordeltatime.txt";
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataObjects/src/Workspace2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Mantid
///Destructor
Workspace2D::~Workspace2D()
{
// Clear out the memory.
// Clear out the memory
for (size_t i=0; i<data.size(); i++)
{
delete data[i];
Expand Down
18 changes: 15 additions & 3 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/InstrumentInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "MantidKernel/Logger.h"
#include <set>
#include <string>
#include <map>

//----------------------------------------------------------------------
// Forward declarations
Expand Down Expand Up @@ -63,8 +64,10 @@ 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
int zeroPadding() 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 the default delimiter between instrument name and run number
std::string delimiter() const;
/// Returns the name of the live listener
Expand All @@ -79,11 +82,20 @@ 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
int m_zeroPadding; ///< Zero padding
ZeroPaddingMap m_zeroPadding; ///< Run number-dependent 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, int zeroPadding);
GenerateFileName(const std::string & prefix, const std::string & suffix, const std::string & instString);

/// 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;
/// The length of zero padding needed.
int m_zeroPadding;
/// String that identifies the instrument
std::string m_instString;
};

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

#include <boost/lexical_cast.hpp>

#include <algorithm>

namespace Mantid
Expand All @@ -27,11 +29,6 @@ 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 @@ -55,6 +52,7 @@ namespace Mantid

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

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

/// Returns zero padding for this instrument
int InstrumentInfo::zeroPadding() const
int InstrumentInfo::zeroPadding(unsigned int runNumber) const
{
return m_zeroPadding;
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);
}

/// Returns the name of the live listener
Expand Down Expand Up @@ -118,6 +161,68 @@ 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 34bffa9

Please sign in to comment.