bool loadAllResources( ExeFile *exeFile ) /****************************************/ { exeFile->tabEnt = (ResTableEntry *) malloc( sizeof( ResTableEntry ) ); if( exeFile->tabEnt == NULL ) { printf( ERR_READ_OUT_OF_MEMORY ); return( false ); } else { return( loadTableEntry( exeFile->tabEnt, exeFile, exeFile->resObj.physical_offset ) ); } }
/** * Load a single entry into a workspace * @param root :: The opened root node * @param entry_name :: The entry name * @param progressStart :: The percentage value to start the progress reporting for this entry * @param progressRange :: The percentage range that the progress reporting should cover * @returns A 2D workspace containing the loaded data */ API::Workspace_sptr LoadNexusProcessed::loadEntry(NXRoot & root, const std::string & entry_name, const double& progressStart, const double& progressRange) { progress(progressStart,"Opening entry " + entry_name + "..."); NXEntry mtd_entry = root.openEntry(entry_name); if (mtd_entry.containsGroup("table_workspace")) { return loadTableEntry(mtd_entry); } bool isEvent = false; std::string group_name = "workspace"; if (mtd_entry.containsGroup("event_workspace")) { isEvent = true; group_name = "event_workspace"; } // Get workspace characteristics NXData wksp_cls = mtd_entry.openNXData(group_name); // Axis information // "X" axis NXDouble xbins = wksp_cls.openNXDouble("axis1"); xbins.load(); std::string unit1 = xbins.attributes("units"); // Non-uniform x bins get saved as a 2D 'axis1' dataset int xlength(-1); if( xbins.rank() == 2 ) { xlength = xbins.dim1(); m_shared_bins = false; } else if( xbins.rank() == 1 ) { xlength = xbins.dim0(); m_shared_bins = true; xbins.load(); m_xbins.access().assign(xbins(), xbins() + xlength); } else { throw std::runtime_error("Unknown axis1 dimension encountered."); } // MatrixWorkspace axis 1 NXDouble axis2 = wksp_cls.openNXDouble("axis2"); std::string unit2 = axis2.attributes("units"); // The workspace being worked on API::MatrixWorkspace_sptr local_workspace; size_t nspectra; int64_t nchannels; // -------- Process as event ? -------------------- if (isEvent) { local_workspace = loadEventEntry(wksp_cls, xbins, progressStart, progressRange); nspectra = local_workspace->getNumberHistograms(); nchannels = local_workspace->blocksize(); } else { NXDataSetTyped<double> data = wksp_cls.openDoubleData(); nspectra = data.dim0(); nchannels = data.dim1(); //// validate the optional spectrum parameters, if set checkOptionalProperties(nspectra); // Actual number of spectra in output workspace (if only a range was going to be loaded) int total_specs=calculateWorkspacesize(nspectra); //// Create the 2D workspace for the output local_workspace = boost::dynamic_pointer_cast<API::MatrixWorkspace> (WorkspaceFactory::Instance().create("Workspace2D", total_specs, xlength, nchannels)); try { local_workspace->setTitle(mtd_entry.getString("title")); } catch (std::runtime_error&) { g_log.debug() << "No title was found in the input file, " << getPropertyValue("Filename") << std::endl; } // Set the YUnit label local_workspace->setYUnit(data.attributes("units")); std::string unitLabel = data.attributes("unit_label"); if (unitLabel.empty()) unitLabel = data.attributes("units"); local_workspace->setYUnitLabel(unitLabel); readBinMasking(wksp_cls, local_workspace); NXDataSetTyped<double> errors = wksp_cls.openNXDouble("errors"); int64_t blocksize(8); //const int fullblocks = nspectra / blocksize; //size of the workspace int64_t fullblocks = total_specs / blocksize; int64_t read_stop = (fullblocks * blocksize); const double progressBegin = progressStart+0.25*progressRange; const double progressScaler = 0.75*progressRange; int64_t hist_index = 0; int64_t wsIndex=0; if( m_shared_bins ) { //if spectrum min,max,list properties are set if(m_interval||m_list) { //if spectrum max,min properties are set read the data as a block(multiple of 8) and //then read the remaining data as finalblock if(m_interval) { //specs at the min-max interval int interval_specs=static_cast<int>(m_spec_max-m_spec_min); fullblocks=(interval_specs)/blocksize; read_stop = (fullblocks * blocksize)+m_spec_min-1; if(interval_specs<blocksize) { blocksize=total_specs; read_stop=m_spec_max-1; } hist_index=m_spec_min-1; for( ; hist_index < read_stop; ) { progress(progressBegin+progressScaler*static_cast<double>(hist_index)/static_cast<double>(read_stop),"Reading workspace data..."); loadBlock(data, errors, blocksize, nchannels, hist_index,wsIndex, local_workspace); } int64_t finalblock = m_spec_max-1 - read_stop; if( finalblock > 0 ) { loadBlock(data, errors, finalblock, nchannels, hist_index,wsIndex,local_workspace); } } // if spectrum list property is set read each spectrum separately by setting blocksize=1 if(m_list) { std::vector<int64_t>::iterator itr=m_spec_list.begin(); for(;itr!=m_spec_list.end();++itr) { int64_t specIndex=(*itr)-1; progress(progressBegin+progressScaler*static_cast<double>(specIndex)/static_cast<double>(m_spec_list.size()),"Reading workspace data..."); loadBlock(data, errors, static_cast<int64_t>(1), nchannels, specIndex,wsIndex, local_workspace); } } } else { for( ; hist_index < read_stop; ) { progress(progressBegin+progressScaler*static_cast<double>(hist_index)/static_cast<double>(read_stop),"Reading workspace data..."); loadBlock(data, errors, blocksize, nchannels, hist_index,wsIndex, local_workspace); } int64_t finalblock = total_specs - read_stop; if( finalblock > 0 ) { loadBlock(data, errors, finalblock, nchannels, hist_index,wsIndex,local_workspace); } } } else { if(m_interval||m_list) { if(m_interval) { int64_t interval_specs=m_spec_max-m_spec_min; fullblocks=(interval_specs)/blocksize; read_stop = (fullblocks * blocksize)+m_spec_min-1; if(interval_specs<blocksize) { blocksize=interval_specs; read_stop=m_spec_max-1; } hist_index=m_spec_min-1; for( ; hist_index < read_stop; ) { progress(progressBegin+progressScaler*static_cast<double>(hist_index)/static_cast<double>(read_stop),"Reading workspace data..."); loadBlock(data, errors, xbins, blocksize, nchannels, hist_index,wsIndex,local_workspace); } int64_t finalblock = m_spec_max-1 - read_stop; if( finalblock > 0 ) { loadBlock(data, errors, xbins, finalblock, nchannels, hist_index,wsIndex, local_workspace); } } // if(m_list) { std::vector<int64_t>::iterator itr=m_spec_list.begin(); for(;itr!=m_spec_list.end();++itr) { int64_t specIndex=(*itr)-1; progress(progressBegin+progressScaler*static_cast<double>(specIndex)/static_cast<double>(read_stop),"Reading workspace data..."); loadBlock(data, errors, xbins, 1, nchannels, specIndex,wsIndex,local_workspace); } } } else { for( ; hist_index < read_stop; ) { progress(progressBegin+progressScaler*static_cast<double>(hist_index)/static_cast<double>(read_stop),"Reading workspace data..."); loadBlock(data, errors, xbins, blocksize, nchannels, hist_index,wsIndex,local_workspace); } int64_t finalblock = total_specs - read_stop; if( finalblock > 0 ) { loadBlock(data, errors, xbins, finalblock, nchannels, hist_index,wsIndex, local_workspace); } } } } //end of NOT an event ------------------------------- //Units try { local_workspace->getAxis(0)->unit() = UnitFactory::Instance().create(unit1); //If this doesn't throw then it is a numeric access so grab the data so we can set it later axis2.load(); m_axis1vals = MantidVec(axis2(), axis2() + axis2.dim0()); } catch( std::runtime_error & ) { g_log.information() << "Axis 0 set to unitless quantity \"" << unit1 << "\"\n"; } // Setting a unit onto a SpectraAxis makes no sense. if ( unit2 == "TextAxis" ) { Mantid::API::TextAxis* newAxis = new Mantid::API::TextAxis(nspectra); local_workspace->replaceAxis(1, newAxis); } else if ( unit2 != "spectraNumber" ) { try { Mantid::API::NumericAxis* newAxis = new Mantid::API::NumericAxis(nspectra); local_workspace->replaceAxis(1, newAxis); newAxis->unit() = UnitFactory::Instance().create(unit2); } catch( std::runtime_error & ) { g_log.information() << "Axis 1 set to unitless quantity \"" << unit2 << "\"\n"; } } //Are we a distribution std::string dist = xbins.attributes("distribution"); if( dist == "1" ) { local_workspace->isDistribution(true); } else { local_workspace->isDistribution(false); } //Get information from all but data group std::string parameterStr; progress(progressStart+0.05*progressRange,"Reading the sample details..."); // Hop to the right point cppFile->openPath(mtd_entry.path()); try { // This loads logs, sample, and instrument. local_workspace->loadExperimentInfoNexus(cppFile, parameterStr); } catch (std::exception & e) { g_log.information("Error loading Instrument section of nxs file"); g_log.information(e.what()); } // Now assign the spectra-detector map readInstrumentGroup(mtd_entry, local_workspace); // Parameter map parsing progress(progressStart+0.11*progressRange,"Reading the parameter maps..."); local_workspace->readParameterMap(parameterStr); if ( ! local_workspace->getAxis(1)->isSpectra() ) { // If not a spectra axis, load the axis data into the workspace. (MW 25/11/10) loadNonSpectraAxis(local_workspace, wksp_cls); } progress(progressStart+0.15*progressRange,"Reading the workspace history..."); try { readAlgorithmHistory(mtd_entry, local_workspace); } catch (std::out_of_range&) { g_log.warning() << "Error in the workspaces algorithm list, its processing history is incomplete\n"; } progress(progressStart+0.2*progressRange,"Reading the workspace history..."); return boost::static_pointer_cast<API::Workspace>(local_workspace); }
bool loadDirEntry( ResDirEntry *dir, ExeFile *exeFile ) /******************************************************/ { long int prevPos; dir->table = NULL; dir->data = NULL; dir->nameID = ID; dir->entryType = TABLE; dir->name = NULL; dir->nameSize = 0; if( fread( (void *) &dir->dir, (size_t) sizeof( resource_dir_entry ), (size_t) 1, exeFile->file ) != 1 ) { printf( ERR_READ_DIR_ENTRY ); return( false ); } if( nameOrID( dir ) == NAME ) { dir->nameID = NAME; prevPos = ftell( exeFile->file ); if( fseek( exeFile->file, getDirNameAbs( dir, exeFile ), SEEK_SET ) ) { printf( ERR_READ_DIR_ENTRY_NAME ); fseek( exeFile->file, prevPos, SEEK_SET ); return( false ); } if( fread( (void *) &dir->nameSize, (size_t) sizeof( unsigned_16 ), (size_t) 1, exeFile->file ) != 1 ) { printf( ERR_READ_DIR_ENTRY_NAME ); fseek( exeFile->file, prevPos, SEEK_SET ); return( false ); } dir->name = (unsigned_16 *) malloc( dir->nameSize * sizeof( unsigned_16 ) ); if( dir->name == NULL ) { printf( ERR_READ_OUT_OF_MEMORY ); fseek( exeFile->file, prevPos, SEEK_SET ); return( false ); } if( fread( (void *) dir->name, (size_t) sizeof( unsigned_16 ), (size_t) dir->nameSize, exeFile->file ) != dir->nameSize ) { printf( ERR_READ_DIR_ENTRY_NAME ); fseek( exeFile->file, prevPos, SEEK_SET ); return( false ); } fseek( exeFile->file, prevPos, SEEK_SET ); } else { dir->nameID = ID; } dir->entryType = tableOrData( dir ); if( dir->entryType == TABLE ) { dir->table = (ResTableEntry *) malloc( (size_t) sizeof( ResTableEntry ) ); if( dir->table == NULL ) { printf( ERR_READ_OUT_OF_MEMORY ); return( false ); } return( loadTableEntry( dir->table, exeFile, getDirChildAbs( dir, exeFile ) ) ); } else { dir->data = (ResDataEntry *) malloc( sizeof( ResDataEntry ) ); if( dir->data == NULL ) { printf( ERR_READ_OUT_OF_MEMORY ); return( false ); } return( loadDataEntry( dir->data, exeFile, getDirChildAbs( dir, exeFile ) ) ); } }