Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/7715_use_group_naming'
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Aug 22, 2013
2 parents 37ab2c0 + 4c30b11 commit 2d778cc
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ namespace DataHandling
return mUserGiveInstrument;
}

std::string getDescription()
{
return mDescription;
}

bool isGivenDescription()
{
return mUserGiveDescription;
}

/// Data structures to store XML to Group/Detector conversion map
std::map<int, std::vector<std::string> > getGroupComponentsMap()
{
Expand All @@ -133,11 +143,22 @@ namespace DataHandling
return mGroupSpectraMap;
}

std::map<int, std::string> getGroupNamesMap()
{
return mGroupNamesMap;
}

private:
/// Instrument name
std::string mInstrumentName;
/// User-define instrument name
bool mUserGiveInstrument;

/// Grouping description. Empty if not specified.
std::string mDescription;
/// Whether description is given by user
bool mUserGiveDescription;

/// XML document loaded
Poco::XML::Document* pDoc;
/// Root element of the parsed XML
Expand All @@ -148,6 +169,9 @@ namespace DataHandling
std::map<int, std::vector<int> > mGroupSpectraMap;
int mStartGroupID;

/// Map of group names
std::map<int, std::string> mGroupNamesMap;

/// Initialize XML parser
void initializeXMLParser(const std::string & filename);
/// Parse XML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ namespace DataHandling

// 1. Parse XML File
std::string xmlfilename = getProperty("InputFile");
/*
this->initializeXMLParser(xmlfilename);
this->parseXML();
*/

LoadGroupXMLFile loader;
loader.loadXMLFile(xmlfilename);
Expand All @@ -151,11 +147,27 @@ namespace DataHandling
mGroupWS->mutableRun().addProperty("Filename",xmlfilename);
setProperty("OutputWorkspace", mGroupWS);

// 3. Translate and set geometry
// 4. Translate and set geometry
this->setByComponents();
this->setByDetectors();
this->setBySpectrumIDs();

// 5. Add grouping description, if specified
if(loader.isGivenDescription())
{
std::string description = loader.getDescription();
mGroupWS->mutableRun().addProperty("Description", description);
}

// 6. Add group names, if user has specified any
std::map<int, std::string> groupNamesMap = loader.getGroupNamesMap();

for(auto it = groupNamesMap.begin(); it != groupNamesMap.end(); it++)
{
std::string groupIdStr = boost::lexical_cast<std::string>(it->first);
mGroupWS->mutableRun().addProperty("GroupName_" + groupIdStr, it->second);
}

return;
}

Expand Down Expand Up @@ -472,11 +484,6 @@ namespace DataHandling
throw std::runtime_error("Call LoadDetectorsGroupingFile::initialize() before parseXML.");

// 1. Parse and create a structure
/*
NodeList* pNL_type = pRootElem->getElementsByTagName("type");
g_log.information() << "Node Size = " << pNL_type->length() << std::endl;
*/

Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
Poco::XML::Node* pNode = it.nextNode();

Expand All @@ -493,19 +500,15 @@ namespace DataHandling

if (pNode->nodeName().compare("detector-grouping") == 0)
{
// Node "detector-grouping" (first level)

// Node "detector-grouping" (first level). Instrument Name
bool foundname;
mInstrumentName = getAttributeValueByName(pNode, "instrument", foundname);
if (!foundname){
mUserGiveInstrument = false;
}
else
{
mUserGiveInstrument = true;
}
// Optional instrument name
mInstrumentName = getAttributeValueByName(pNode, "instrument", mUserGiveInstrument);

// Optional grouping description
mDescription = getAttributeValueByName(pNode, "description", mUserGiveDescription);

} // "detector-masking"
} // "detector-grouping"
else if (pNode->nodeName().compare("group") == 0)
{
// Group Node: get ID, set map
Expand Down Expand Up @@ -541,6 +544,12 @@ namespace DataHandling
}
else
{
// When group ID is sorted, check if user has specified a group name
bool foundName;
std::string name = getAttributeValueByName(pNode, "name", foundName);
if(foundName)
mGroupNamesMap[curgroupid] = name;

// Set map
std::vector<std::string> tempcomponents;
std::vector<detid_t> tempdetids;
Expand Down
15 changes: 15 additions & 0 deletions Code/Mantid/Framework/DataHandling/src/SaveDetectorsGrouping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ namespace DataHandling
pDoc->appendChild(pRoot);
pRoot->setAttribute("instrument", name);

// Set description if was specified by user
if(mGroupWS->run().hasProperty("Description"))
{
std::string description = mGroupWS->run().getProperty("Description")->value();
pRoot->setAttribute("description", description);
}

// 3. Append Groups
for (std::map<int, std::vector<detid_t> >::iterator it = groupdetidrangemap.begin();
it != groupdetidrangemap.end(); ++it){
Expand All @@ -225,6 +232,14 @@ namespace DataHandling

AutoPtr<Element> pChildGroup = pDoc->createElement("group");
pChildGroup->setAttribute("ID", sid.str());
// Set name if was specified by user
std::string groupNameProp = "GroupName_" + sid.str();
if(mGroupWS->run().hasProperty(groupNameProp))
{
std::string groupName = mGroupWS->run().getProperty(groupNameProp)->value();
pChildGroup->setAttribute("name", groupName);
}

pRoot->appendChild(pChildGroup);

g_log.debug() << "Group ID = " << groupid << std::endl;
Expand Down

0 comments on commit 2d778cc

Please sign in to comment.