void LoadRaw3::separateMonitors(FILE *file, const int64_t &period, const std::vector<specnum_t> &monitorList, DataObjects::Workspace2D_sptr ws_sptr, DataObjects::Workspace2D_sptr mws_sptr) { int64_t histCurrent = -1; int64_t wsIndex = 0; int64_t mwsIndex = 0; double histTotal = static_cast<double>(m_total_specs * m_numberOfPeriods); // loop through spectra for (specnum_t i = 1; i <= m_numberOfSpectra; ++i) { int64_t histToRead = i + period * (m_numberOfSpectra + 1); if ((i >= m_spec_min && i < m_spec_max) || (m_list && find(m_spec_list.begin(), m_spec_list.end(), i) != m_spec_list.end())) { progress(m_prog, "Reading raw file data..."); // read spectrum from raw file if (!readData(file, histToRead)) { throw std::runtime_error("Error reading raw file"); } // if this a monitor store that spectrum to monitor workspace if (isMonitor(monitorList, i)) { setWorkspaceData(mws_sptr, m_timeChannelsVec, mwsIndex, i, m_noTimeRegimes, m_lengthIn, 1); ++mwsIndex; } else { // not a monitor,store the spectrum to normal output workspace setWorkspaceData(ws_sptr, m_timeChannelsVec, wsIndex, i, m_noTimeRegimes, m_lengthIn, 1); ++wsIndex; } if (m_numberOfPeriods == 1) { if (++histCurrent % 100 == 0) { setProg(static_cast<double>(histCurrent) / histTotal); } interruption_point(); } } else { skipData(file, histToRead); } } }
/** This method creates outputworkspace excluding monitors *@param file :: -pointer to file *@param period :: period number *@param monitorList :: a list containing the spectrum numbers for monitors *@param ws_sptr :: shared pointer to workspace */ void LoadRaw3::excludeMonitors(FILE *file, const int &period, const std::vector<specnum_t> &monitorList, DataObjects::Workspace2D_sptr ws_sptr) { int64_t histCurrent = -1; int64_t wsIndex = 0; double histTotal = static_cast<double>(m_total_specs * m_numberOfPeriods); // loop through the spectra for (specnum_t i = 1; i <= m_numberOfSpectra; ++i) { specnum_t histToRead = i + period * (m_numberOfSpectra + 1); if ((i >= m_spec_min && i < m_spec_max) || (m_list && find(m_spec_list.begin(), m_spec_list.end(), i) != m_spec_list.end())) { progress(m_prog, "Reading raw file data..."); // skip monitor spectrum if (isMonitor(monitorList, i)) { skipData(file, histToRead); continue; } // read spectrum if (!readData(file, histToRead)) { throw std::runtime_error("Error reading raw file"); } // set the workspace data setWorkspaceData(ws_sptr, m_timeChannelsVec, wsIndex, i, m_noTimeRegimes, m_lengthIn, 1); // increment workspace index ++wsIndex; if (m_numberOfPeriods == 1) { if (++histCurrent % 100 == 0) { setProg(static_cast<double>(histCurrent) / histTotal); } interruption_point(); } } // end of if loop for spec min,max check else { skipData(file, histToRead); } } // end of for loop }
/**This method creates outputworkspace including monitors *@param file :: -pointer to file *@param period :: period number *@param ws_sptr :: shared pointer to workspace */ void LoadRaw3::includeMonitors(FILE *file, const int64_t &period, DataObjects::Workspace2D_sptr ws_sptr) { int64_t histCurrent = -1; int64_t wsIndex = 0; double histTotal = static_cast<double>(m_total_specs * m_numberOfPeriods); // loop through spectra for (specnum_t i = 1; i <= m_numberOfSpectra; ++i) { int64_t histToRead = i + period * (m_numberOfSpectra + 1); if ((i >= m_spec_min && i < m_spec_max) || (m_list && find(m_spec_list.begin(), m_spec_list.end(), i) != m_spec_list.end())) { progress(m_prog, "Reading raw file data..."); // read spectrum from raw file if (!readData(file, histToRead)) { throw std::runtime_error("Error reading raw file"); } // set workspace data setWorkspaceData(ws_sptr, m_timeChannelsVec, wsIndex, i, m_noTimeRegimes, m_lengthIn, 1); ++wsIndex; if (m_numberOfPeriods == 1) { if (++histCurrent % 100 == 0) { setProg(double(histCurrent) / histTotal); } interruption_point(); } } else { skipData(file, histToRead); } } // loadSpectra(file,period,m_total_specs,ws_sptr,m_timeChannelsVec); }
/** Executes the algorithm. Reading in the file and creating and populating * the output workspace * * @throw Exception::FileError If the RAW file cannot be found/opened * @throw std::invalid_argument If the optional properties are set to invalid values */ void LoadRawBin0::exec() { // Retrieve the filename from the properties m_filename = getPropertyValue("Filename"); bool bLoadlogFiles = getProperty("LoadLogFiles"); //open the raw file FILE* file=openRawFile(m_filename); // Need to check that the file is not a text file as the ISISRAW routines don't deal with these very well, i.e // reading continues until a bad_alloc is encountered. if( isAscii(file) ) { g_log.error() << "File \"" << m_filename << "\" is not a valid RAW file.\n"; throw std::invalid_argument("Incorrect file type encountered."); } std::string title; readTitle(file,title); readworkspaceParameters(m_numberOfSpectra,m_numberOfPeriods,m_lengthIn,m_noTimeRegimes); /// setOptionalProperties(); // to validate the optional parameters, if set checkOptionalProperties(); // Calculate the size of a workspace, given its number of periods & spectra to read m_total_specs = calculateWorkspaceSize(); //no real X values for bin 0,so initialize this to zero boost::shared_ptr<MantidVec> channelsVec(new MantidVec(1,0)); m_timeChannelsVec.push_back(channelsVec); double histTotal = static_cast<double>(m_total_specs * m_numberOfPeriods); int64_t histCurrent = -1; // Create the 2D workspace for the output xlength and ylength is one DataObjects::Workspace2D_sptr localWorkspace = createWorkspace(m_total_specs, 1,1,title); Run& run = localWorkspace->mutableRun(); if (bLoadlogFiles) { runLoadLog(m_filename,localWorkspace, 0.0, 0.0); const int period_number = 1; createPeriodLogs(period_number, localWorkspace); } // Set the total proton charge for this run setProtonCharge(run); WorkspaceGroup_sptr ws_grp = createGroupWorkspace(); setWorkspaceProperty("OutputWorkspace", title, ws_grp, localWorkspace,m_numberOfPeriods, false); // Loop over the number of periods in the raw file, putting each period in a separate workspace for (int period = 0; period < m_numberOfPeriods; ++period) { if (period > 0) { localWorkspace=createWorkspace(localWorkspace); if (bLoadlogFiles) { //remove previous period data std::stringstream prevPeriod; prevPeriod << "PERIOD " << (period); Run& runObj = localWorkspace->mutableRun(); runObj.removeLogData(prevPeriod.str()); runObj.removeLogData("current_period"); //add current period data const int period_number = period + 1; createPeriodLogs(period_number, localWorkspace); } } skipData(file, period * (m_numberOfSpectra + 1)); int64_t wsIndex = 0; for (specid_t i = 1; i <= m_numberOfSpectra; ++i) { int64_t histToRead = i + period * (m_numberOfSpectra + 1); if ((i >= m_spec_min && i < m_spec_max) || (m_list && find(m_spec_list.begin(), m_spec_list.end(), i) != m_spec_list.end())) { progress(m_prog, "Reading raw file data..."); //readData(file, histToRead); //read spectrum if (!readData(file, histToRead)) { throw std::runtime_error("Error reading raw file"); } int64_t binStart=0; setWorkspaceData(localWorkspace, m_timeChannelsVec, wsIndex, i, m_noTimeRegimes,1,binStart); ++wsIndex; if (m_numberOfPeriods == 1) { if (++histCurrent % 100 == 0) { m_prog = double(histCurrent) / histTotal; } interruption_point(); } } else { skipData(file, histToRead); } } if(m_numberOfPeriods>1) { setWorkspaceProperty(localWorkspace, ws_grp, period, false); // progress for workspace groups m_prog = static_cast<double>(period) / static_cast<double>(m_numberOfPeriods - 1); } } // loop over periods // Clean up isisRaw.reset(); fclose(file); }