/** Write out all of the event lists in the given workspace * @param ws :: an EventWorkspace */ int NexusFileIO::writeNexusProcessedDataEvent( const DataObjects::EventWorkspace_const_sptr& ws) { //write data entry NXstatus status=NXmakegroup(fileID,"event_workspace","NXdata"); if(status==NX_ERROR) return(2); NXopengroup(fileID,"event_workspace","NXdata"); for (size_t wi=0; wi < ws->getNumberHistograms(); wi++) { std::ostringstream group_name; group_name << "event_list_" << wi; this->writeEventList( ws->getEventList(wi), group_name.str()); } // Close up the overall group status=NXclosegroup(fileID); return((status==NX_ERROR)?3:0); }
/** * Create an output EventWorkspace w/o any events */ DataObjects::EventWorkspace_sptr CountEventsInPulses::createEventWorkspace( DataObjects::EventWorkspace_const_sptr parentws, bool sumspectrum) { size_t numspec; bool diffsize; if (sumspectrum) { numspec = 1; diffsize = true; } else { numspec = parentws->getNumberHistograms(); diffsize = false; } DataObjects::EventWorkspace_sptr outputWS = boost::dynamic_pointer_cast<DataObjects::EventWorkspace>( API::WorkspaceFactory::Instance().create("EventWorkspace", numspec, 1, 1)); API::WorkspaceFactory::Instance().initializeFromParent(parentws, outputWS, diffsize); outputWS->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create("Time"); return outputWS; }
/** Check whether 2 event lists are identical */ bool CompareWorkspaces::compareEventWorkspaces( DataObjects::EventWorkspace_const_sptr ews1, DataObjects::EventWorkspace_const_sptr ews2) { bool checkallspectra = getProperty("CheckAllData"); int numspec2print = getProperty("NumberMismatchedSpectraToPrint"); int wsindex2print = getProperty("DetailedPrintIndex"); // Compare number of spectra if (ews1->getNumberHistograms() != ews2->getNumberHistograms()) { recordMismatch("Mismatched number of histograms."); return false; } if (ews1->getEventType() != ews2->getEventType()) { recordMismatch("Mismatched type of events in the EventWorkspaces."); return false; } // Both will end up sorted anyway ews1->sortAll(PULSETIMETOF_SORT, m_Prog); ews2->sortAll(PULSETIMETOF_SORT, m_Prog); // Determine the tolerance for "tof" attribute and "weight" of events double toleranceWeight = Tolerance; // Standard tolerance int64_t tolerancePulse = 1; double toleranceTOF = 0.05; if ((ews1->getAxis(0)->unit()->label().ascii() != "microsecond") || (ews2->getAxis(0)->unit()->label().ascii() != "microsecond")) { g_log.warning() << "Event workspace has unit as " << ews1->getAxis(0)->unit()->label().ascii() << " and " << ews2->getAxis(0)->unit()->label().ascii() << ". Tolerance of TOF is set to 0.05 still. " << "\n"; toleranceTOF = 0.05; } g_log.notice() << "TOF Tolerance = " << toleranceTOF << "\n"; bool mismatchedEvent = false; int mismatchedEventWI = 0; size_t numUnequalNumEventsSpectra = 0; size_t numUnequalEvents = 0; size_t numUnequalTOFEvents = 0; size_t numUnequalPulseEvents = 0; size_t numUnequalBothEvents = 0; std::vector<int> vec_mismatchedwsindex; PARALLEL_FOR_IF(m_ParallelComparison && ews1->threadSafe() && ews2->threadSafe()) for (int i = 0; i < static_cast<int>(ews1->getNumberHistograms()); ++i) { PARALLEL_START_INTERUPT_REGION m_Prog->report("EventLists"); if (!mismatchedEvent || checkallspectra) // This guard will avoid checking unnecessarily { const EventList &el1 = ews1->getEventList(i); const EventList &el2 = ews2->getEventList(i); bool printdetail = (i == wsindex2print); if (printdetail) { g_log.information() << "Spectrum " << i << " is set to print out in details. " << "\n"; } if (!el1.equals(el2, toleranceTOF, toleranceWeight, tolerancePulse)) { size_t tempNumTof = 0; size_t tempNumPulses = 0; size_t tempNumBoth = 0; int tempNumUnequal = 0; if (el1.getNumberEvents() != el2.getNumberEvents()) { // Number of events are different tempNumUnequal = -1; } else { tempNumUnequal = compareEventsListInDetails( el1, el2, toleranceTOF, toleranceWeight, tolerancePulse, printdetail, tempNumPulses, tempNumTof, tempNumBoth); } mismatchedEvent = true; mismatchedEventWI = i; PARALLEL_CRITICAL(CompareWorkspaces) { if (tempNumUnequal == -1) { // 2 spectra have different number of events ++numUnequalNumEventsSpectra; } else { // 2 spectra have some events different to each other numUnequalEvents += static_cast<size_t>(tempNumUnequal); numUnequalTOFEvents += tempNumTof; numUnequalPulseEvents += tempNumPulses; numUnequalBothEvents += tempNumBoth; } vec_mismatchedwsindex.push_back(i); } // Parallel critical region } // If elist 1 is not equal to elist 2 } PARALLEL_END_INTERUPT_REGION }