/** Create and set up output Event Workspace */ void LoadEventPreNexus2::createOutputWorkspace( const std::string event_filename) { // Create the output workspace localWorkspace = EventWorkspace_sptr(new EventWorkspace()); // Make sure to initialize. We can use dummy numbers for arguments, for // event // workspace it doesn't matter localWorkspace->initialize(1, 1, 1); // Set the units localWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); localWorkspace->setYUnit("Counts"); // Set title localWorkspace->setTitle("Dummy Title"); // Property run_start if (this->num_pulses > 0) { // add the start of the run as a ISO8601 date/time string. The start = the // first pulse. // (this is used in LoadInstrument to find the right instrument file to // use). localWorkspace->mutableRun().addProperty( "run_start", pulsetimes[0].toISO8601String(), true); } // Property run_number localWorkspace->mutableRun().addProperty("run_number", getRunnumber(event_filename)); // Get the instrument! prog->report("Loading Instrument"); this->runLoadInstrument(event_filename, localWorkspace); // load the mapping file prog->report("Loading Mapping File"); string mapping_filename = this->getPropertyValue(MAP_PARAM); if (mapping_filename.empty()) { mapping_filename = generateMappingfileName(localWorkspace); if (!mapping_filename.empty()) this->g_log.information() << "Found mapping file \"" << mapping_filename << "\"\n"; } this->loadPixelMap(mapping_filename); // Replace workspace by workspace of correct size // Number of non-monitors in instrument size_t nSpec = localWorkspace->getInstrument()->getDetectorIDs(true).size(); if (!this->spectra_list.empty()) nSpec = this->spectra_list.size(); auto tmp = createWorkspace<EventWorkspace>(nSpec, 2, 1); WorkspaceFactory::Instance().initializeFromParent(*localWorkspace, *tmp, true); localWorkspace = std::move(tmp); }
/** Execute the algorithm */ void LoadEventPreNexus::exec() { // Check 'chunk' properties are valid, if set const int chunks = getProperty("TotalChunks"); if (!isEmpty(chunks) && int(getProperty("ChunkNumber")) > chunks) { throw std::out_of_range("ChunkNumber cannot be larger than TotalChunks"); } prog = new Progress(this, 0.0, 1.0, 100); // what spectra (pixel ID's) to load this->spectra_list = this->getProperty(PID_PARAM); // the event file is needed in case the pulseid fileanme is empty string event_filename = this->getPropertyValue(EVENT_PARAM); string pulseid_filename = this->getPropertyValue(PULSEID_PARAM); bool throwError = true; if (pulseid_filename.empty()) { pulseid_filename = generatePulseidName(event_filename); if (!pulseid_filename.empty()) { if (Poco::File(pulseid_filename).exists()) { this->g_log.information() << "Found pulseid file " << pulseid_filename << std::endl; throwError = false; } else { pulseid_filename = ""; } } } prog->report("Loading Pulse ID file"); this->readPulseidFile(pulseid_filename, throwError); this->openEventFile(event_filename); prog->report("Creating output workspace"); // prep the output workspace EventWorkspace_sptr localWorkspace = EventWorkspace_sptr(new EventWorkspace()); // Make sure to initialize. // We can use dummy numbers for arguments, for event workspace it doesn't // matter localWorkspace->initialize(1, 1, 1); // Set the units localWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); localWorkspace->setYUnit("Counts"); // TODO localWorkspace->setTitle(title); // Add the run_start property // Use the first pulse as the run_start time. if (this->num_pulses > 0) { // add the start of the run as a ISO8601 date/time string. The start = the // first pulse. // (this is used in LoadInstrument to find the right instrument file to // use). localWorkspace->mutableRun().addProperty( "run_start", pulsetimes[0].toISO8601String(), true); } // determine the run number and add it to the run object localWorkspace->mutableRun().addProperty("run_number", getRunnumber(event_filename)); // Get the instrument! prog->report("Loading Instrument"); this->runLoadInstrument(event_filename, localWorkspace); // load the mapping file prog->report("Loading Mapping File"); string mapping_filename = this->getPropertyValue(MAP_PARAM); if (mapping_filename.empty()) { mapping_filename = generateMappingfileName(localWorkspace); if (!mapping_filename.empty()) this->g_log.information() << "Found mapping file \"" << mapping_filename << "\"" << std::endl; } this->loadPixelMap(mapping_filename); // Process the events into pixels this->procEvents(localWorkspace); // Save output this->setProperty<IEventWorkspace_sptr>(OUT_PARAM, localWorkspace); // Cleanup delete prog; }