/** * Create the simple API * @param nrhs :: The number of parameters in the Matlab function call * @param prhs :: The data from the Matlab function call * @returns An integer indicating success/failure */ int CreateSimpleAPI(int, mxArray **, int nrhs, const mxArray *prhs[]) { // Ensure all libraries are loaded FrameworkManager::Instance(); // Create directory to store mfiles std::string mpath(""); if (nrhs == 0) { mpath = "MantidSimpleAPI"; } else if (nrhs == 1) { char buffer[256]; mxGetString(prhs[0], buffer, sizeof(buffer)); mpath = std::string(buffer) + "/MantidSimpleAPI"; } else { mexErrMsgTxt("SimpleAPI_Create takes either 0 or 1 arguments."); } Poco::File simpleAPI(mpath); if (simpleAPI.exists()) { simpleAPI.remove(true); } try { simpleAPI.createDirectory(); } catch (std::exception &) { mexErrMsgTxt( "An error occurred while creating the directory for the simple API."); } std::vector<std::string> algKeys = AlgorithmFactory::Instance().getKeys(); std::vector<std::string>::const_iterator sIter = algKeys.begin(); typedef std::map<std::string, unsigned int> VersionMap; VersionMap vMap; for (; sIter != algKeys.end(); ++sIter) { std::string key = (*sIter); std::string name = key.substr(0, key.find("|")); VersionMap::iterator vIter = vMap.find(name); if (vIter == vMap.end()) vMap.emplace(name, 1); else ++(vIter->second); } std::string contents_path = simpleAPI.path() + "/Contents.m"; std::ofstream contents(contents_path.c_str()); contents << "%A simpler API for Mantid\n%\n%The algorithms available are:\n"; VersionMap::const_iterator vIter = vMap.begin(); for (; vIter != vMap.end(); ++vIter) { contents << "% " << vIter->first << "\n"; CreateSimpleAPIHelper(vIter->first, mpath + std::string("/")); } contents << "% For help with an individual command type \"help algorithm_name\"\n"; contents.close(); return 0; }
// Validates that the ranges and versions are valid given the chunks void validate( const BSONArray& chunks, RangeMap* ranges, ShardChunkVersion maxVersion, const VersionMap& maxShardVersions ){ BSONObjIterator it( chunks ); int chunkCount = 0; ShardChunkVersion foundMaxVersion; VersionMap foundMaxShardVersions; // // Validate that all the chunks are there and collect versions // while( it.more() ){ BSONObj chunkDoc = it.next().Obj(); chunkCount++; if( ranges != NULL ){ // log() << "Validating chunk " << chunkDoc << " size : " << ranges->size() << " vs " << chunkCount << endl; RangeMap::iterator chunkRange = ranges->find( _inverse ? chunkDoc["max"].Obj() : chunkDoc["min"].Obj() ); ASSERT( chunkRange != ranges->end() ); ASSERT( chunkRange->second.woCompare( _inverse ? chunkDoc["min"].Obj() : chunkDoc["max"].Obj() ) == 0 ); } ShardChunkVersion version = ShardChunkVersion::fromBSON( chunkDoc["lastmod"] ); if( version > foundMaxVersion ) foundMaxVersion = version; ShardChunkVersion shardMaxVersion = foundMaxShardVersions[ chunkDoc["shard"].String() ]; if( version > shardMaxVersion ) foundMaxShardVersions[ chunkDoc["shard"].String() ] = version; } // Make sure all chunks are accounted for if( ranges != NULL ) ASSERT( chunkCount == (int) ranges->size() ); // log() << "Validating that all shard versions are up to date..." << endl; // Validate that all the versions are the same ASSERT( foundMaxVersion.isEquivalentTo( maxVersion ) ); for( VersionMap::iterator it = foundMaxShardVersions.begin(); it != foundMaxShardVersions.end(); it++ ){ ShardChunkVersion foundVersion = it->second; VersionMap::const_iterator maxIt = maxShardVersions.find( it->first ); ASSERT( maxIt != maxShardVersions.end() ); ASSERT( foundVersion.isEquivalentTo( maxIt->second ) ); } // Make sure all shards are accounted for ASSERT( foundMaxShardVersions.size() == maxShardVersions.size() ); }