/** Convert events to "fake" events as counts in outWS */ void CountEventsInPulses::convertEvents(DataObjects::EventWorkspace_sptr outWS, bool sumspectra) { // 1. Get run_start time std::string runstartstr = inpWS->run().getProperty("run_start")->value(); Kernel::DateAndTime runstart(runstartstr); int64_t runstarttime = runstart.totalNanoseconds(); // 2. Convert TOF and add to new event workspace double margin_sec = mPulseLength * 0.01; g_log.information() << "Pulse length = " << mPulseLength << " (sec). Margine = " << margin_sec << " For safe binning. " << std::endl; PARALLEL_FOR2(inpWS, outWS) for (int wsindex = 0; wsindex < static_cast<int>(inpWS->getNumberHistograms()); wsindex++) { DataObjects::EventList realevents = inpWS->getEventList(wsindex); DataObjects::EventList *fakeevents; if (sumspectra) { fakeevents = outWS->getEventListPtr(0); } else { fakeevents = outWS->getEventListPtr(wsindex); } size_t numevents = realevents.getNumberEvents(); for (size_t ie = 0; ie < numevents; ie++) { DataObjects::WeightedEvent event = realevents.getEvent(ie); // Swap TOF and pulse time and add to new event list // a) TOF (ms) -> Pulse Time double oldtof = event.tof(); int64_t oldtofns = int64_t(oldtof * 1000); Kernel::DateAndTime newpulsetime(oldtofns); // b) Pulse Time (ns) -> TOF (ms) -> second int64_t oldpulsetime = event.pulseTime().totalNanoseconds() - runstarttime; double newtofinsecond = double(oldpulsetime) * 1.0E-9 + margin_sec; DataObjects::TofEvent fakeevent(newtofinsecond, newpulsetime); fakeevents->addEventQuickly(fakeevent); } // ENDFOR events } // END FOR: Per Spectrum g_log.debug() << "DBx505 Input Events = " << inpWS->getNumberEvents() << "; Output Events = " << outWS->getNumberEvents() << std::endl; return; }
/** Write out an event list into an already-opened group * @param el :: reference to the EventList to write. * @param group_name :: group_name to create. * */ int NexusFileIO::writeEventList( const DataObjects::EventList & el, std::string group_name) const { //write data entry NXstatus status=NXmakegroup(fileID, group_name.c_str(), "NXdata"); if(status==NX_ERROR) return(2); NXopengroup(fileID, group_name.c_str(), "NXdata"); // Copy the detector IDs to an array. const std::set<detid_t>& dets = el.getDetectorIDs(); // Write out the detector IDs if (!dets.empty()) { std::vector<detid_t> detectorIDs(dets.begin(),dets.end()); int dims_array[1]; NXwritedata("detector_IDs", NX_INT64, 1, dims_array, (void*)(detectorIDs.data()), false ); } std::string eventType("UNKNOWN"); size_t num = el.getNumberEvents(); switch (el.getEventType()) { case TOF: eventType = "TOF"; writeEventListData( el.getEvents(), true, true, false, false ); break; case WEIGHTED: eventType = "WEIGHTED"; writeEventListData( el.getWeightedEvents(), true, true, true, true ); break; case WEIGHTED_NOTIME: eventType = "WEIGHTED_NOTIME"; writeEventListData( el.getWeightedEventsNoTime(), true, false, true, true ); break; } // --- Save the type of sorting ----- std::string sortType; switch (el.getSortType()) { case TOF_SORT: sortType = "TOF_SORT"; break; case PULSETIME_SORT: sortType = "PULSETIME_SORT"; break; case UNSORTED: default: sortType = "UNSORTED"; break; } NXputattr (fileID, "sort_type", reinterpret_cast<void*>(const_cast<char*>(sortType.c_str())), static_cast<int>(sortType.size()), NX_CHAR); // Save an attribute with the type of each event. NXputattr (fileID, "event_type", reinterpret_cast<void*>(const_cast<char*>(eventType.c_str())), static_cast<int>(eventType.size()), NX_CHAR); // Save an attribute with the number of events NXputattr (fileID, "num_events", (void*)(&num), 1, NX_INT64); // Close it up! status=NXclosegroup(fileID); return((status==NX_ERROR)?3:0); }