Skip to content

Commit

Permalink
refs #6449 adding tests for AddAndBuild event operations
Browse files Browse the repository at this point in the history
(not finished yet)
  • Loading branch information
abuts committed Apr 16, 2013
1 parent ca0198f commit abe442e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 73 deletions.
6 changes: 1 addition & 5 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,13 @@ class IMDNode
virtual void addEvent(const signal_t Signal, const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId) = 0;
// add a single event and set pointer to the box which needs splitting (if one actually need)
virtual void addAndTraceEvent(const signal_t Signal,const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId,size_t index) = 0;

/// Add a single event, with no mutex locking
virtual void addEventUnsafe(const signal_t Signal,const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId) = 0;

/// Add several events, within a given range
//virtual size_t addEventsPart(const std::vector<coord_t> &coords,const signal_t *Signal,const signal_t *errorSq,const uint16_t *runIndex,const uint32_t *detectorId, const size_t start_at, const size_t stop_at)=0;
virtual size_t addEvents(const std::vector<signal_t> &sigErrSq,const std::vector<coord_t> &Coord,const std::vector<uint16_t> &runIndex,const std::vector<uint32_t> &detectorId)=0;

/// Add several events, within a given range, with no bounds checking
//virtual size_t addEventsPartUnsafe(const std::vector<MDE> & events, const size_t start_at, const size_t stop_at);
//size_t addEventsUnsafe(const std::vector<MDE> & events);


/** Perform centerpoint binning of events
* @param bin :: MDBin object giving the limits of events to accept.
Expand Down
8 changes: 5 additions & 3 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,16 @@ namespace MDEvents
void addEvent(const MDE & Evnt);
void addAndTraceEvent(const MDE & point,size_t index);
void addEventUnsafe(const MDE & Evnt);
size_t addEventsPart(const std::vector<MDE> & events, const size_t start_at, const size_t stop_at);
size_t addEventsPartUnsafe(const std::vector<MDE> & events, const size_t start_at, const size_t stop_at);
size_t addEvents(const std::vector<MDE> & events);

/*---------------> EVENTS from event parts <-------------------------------------------------------------*/
virtual void addEvent(const signal_t Signal,const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId);
virtual void addAndTraceEvent(const signal_t Signal,const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId,size_t index);
virtual void addEventUnsafe(const signal_t Signal,const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId);
virtual size_t addEvents(const std::vector<signal_t> &sigErrSq,const std::vector<coord_t> &Coord,const std::vector<uint16_t> &runIndex,const std::vector<uint32_t> &detectorId);

//---------------------------------------------------------------------------------------------------------------------------------
void centerpointBin(MDBin<MDE,nd> & bin, bool * fullyContained) const;

void generalBin(MDBin<MDE,nd> & bin, Mantid::Geometry::MDImplicitFunction & function) const;

//---------------------------------------------------------------------------------------------------------------------------------
Expand Down
21 changes: 5 additions & 16 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBoxBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,19 @@ namespace MDEvents
virtual void setEventsData(const std::vector<coord_t> &/*coordTable*/){};
/// Return a copy of contained events
virtual std::vector< MDE > * getEventsCopy() = 0;


/// Add a single event
virtual void addEvent(const MDE & point) = 0;
// add a single event and set pointer to the box which needs splitting (if one actually need)
virtual void addAndTraceEvent(const MDE & point,size_t index) = 0;

/// Add a single event, with no mutex locking
virtual void addEventUnsafe(const MDE & point) = 0;

/// Add several events, within a given range
virtual size_t addEventsPart(const std::vector<MDE> & events, const size_t start_at, const size_t stop_at);
/// Add several events
virtual size_t addEvents(const std::vector<MDE> & events);

/// Add several events, within a given range, with no bounds checking
virtual size_t addEventsPartUnsafe(const std::vector<MDE> & events, const size_t start_at, const size_t stop_at);
size_t addEventsUnsafe(const std::vector<MDE> & events);
/// Add several events, with no bounds checking
virtual size_t addEventsUnsafe(const std::vector<MDE> & events);
//----------------------------------------------------------------------------------------------------------------------
/*---------------> EVENTS from event parts <-------------------------------------------------------------*/
virtual void addEvent(const signal_t Signal,const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId);
virtual void addAndTraceEvent(const signal_t Signal,const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId,size_t index);
virtual void addEventUnsafe(const signal_t Signal,const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId);
//virtual size_t addEventsPart(const std::vector<coord_t> &coords,const signal_t *Signal,const signal_t *errorSq,const uint16_t *runIndex,const uint32_t *detectorId, const size_t start_at, const size_t stop_at);
//virtual size_t addEvents(const std::vector<signal_t> &sigErrSq,const std::vector<coord_t> &Coord,
// const std::vector<uint16_t> &runIndex=std::vector<uint16_t>(),const std::vector<uint32_t> &detectorId=std::vector<uint32_t>());

//----------------------------------------------------------------------------------------------------------------------

/** Perform centerpoint binning of events
Expand Down
50 changes: 5 additions & 45 deletions Code/Mantid/Framework/MDEvents/src/MDBoxBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ namespace MDEvents
* @return the number of events that were rejected (because of being out of bounds)
*/
TMDE(
size_t MDBoxBase)::addEventsPart(const std::vector<MDE> & events, const size_t start_at, const size_t stop_at)
size_t MDBoxBase)::addEvents(const std::vector<MDE> & events)
{
size_t numBad = 0;
// --- Go event by event and add them ----
typename std::vector<MDE>::const_iterator it = events.begin() + start_at;
typename std::vector<MDE>::const_iterator it_end = events.begin() + stop_at;
typename std::vector<MDE>::const_iterator it = events.begin();
typename std::vector<MDE>::const_iterator it_end = events.begin();
for (; it != it_end; ++it)
{
//Check out-of-bounds-ness
Expand All @@ -128,35 +128,6 @@ namespace MDEvents
return numBad;
}

//-----------------------------------------------------------------------------------------------
/** Add several events, starting and stopping at particular point in a vector.
* This is the fastest way to add many events because:
* - Bounds checking is NOT performed.
* - This call is NOT thread-safe (no locking is made while adding).
*
* NOTE: You must call refreshCache() after you are done, to calculate the
* nPoints, signal and error.
*
* @param events :: vector of events to be copied.
* @param start_at :: begin at this index in the array
* @param stop_at :: stop at this index in the array
* @return 0 (since no events were rejected)
*/
TMDE(
size_t MDBoxBase)::addEventsPartUnsafe(const std::vector<MDE> & events, const size_t start_at, const size_t stop_at)
{
// --- Go event by event and add them ----
typename std::vector<MDE>::const_iterator it = events.begin() + start_at;
typename std::vector<MDE>::const_iterator it_end = events.begin() + stop_at;
for (; it != it_end; ++it)
{
//Check out-of-bounds-ness
// Event was in bounds; add it
addEventUnsafe(*it);
}

return 0;
}

//---------------------------------------------------------------------------------------------------
/** Add all of the events contained in a vector, with:
Expand All @@ -171,18 +142,7 @@ namespace MDEvents
return this->addEventsPartUnsafe(events, 0, events.size());
}

//---------------------------------------------------------------------------------------------------
/** Add all of the events contained in a vector, with:
* - Bounds checking.
* - Thread-safety.
*
* @param events :: Vector of MDEvent
*/
TMDE(
size_t MDBoxBase)::addEvents(const std::vector<MDE> & events)
{
return this->addEventsPart(events, 0, events.size());
}



//---------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -358,7 +318,7 @@ namespace MDEvents
struct IF
{
public:
static inline MDEvent<nd> BUILD_EVENT(const signal_t Signal, const signal_t Error, const coord_t *Coord,const uint16_t runIndex=0,const uint32_t detectorId=0)
static inline MDEvent<nd> BUILD_EVENT(const signal_t Signal, const signal_t Error, const coord_t *Coord,const uint16_t runIndex,const uint32_t detectorId)
{
return MDEvent<nd>(Signal,Error, runIndex, detectorId, Coord);
}
Expand Down
79 changes: 75 additions & 4 deletions Code/Mantid/Framework/MDEvents/test/MDBoxTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,27 @@ static void destroySuite(MDBoxTest * suite) { delete suite; }
TS_ASSERT_EQUALS( b.getTotalWeight(), 1.0);

}
/** Adding events tracks the total signal */
void test_BuildAndAddEvent()
{
BoxController_sptr sc( new BoxController(2));
MDBox<MDLeanEvent<2>,2> b(sc.get());
std::vector<coord_t> coord(2.,2);
coord[1]=3;

b.addEvent(1.2,3.4,coord,0,0);
TS_ASSERT_EQUALS( b.getNPoints(), 1)

b.refreshCache();

// Did it keep a running total of the signal and error?
TS_ASSERT_DELTA( b.getSignal(), 1.2*1, 1e-5);
TS_ASSERT_DELTA( b.getErrorSquared(), 3.4*1, 1e-5);
// Weight of 1.0 per event.
TS_ASSERT_EQUALS( b.getTotalWeight(), 1.0);

}

/** Adding events in unsafe way also works */
void test_addEventUnsafe()
{
Expand Down Expand Up @@ -165,6 +186,56 @@ static void destroySuite(MDBoxTest * suite) { delete suite; }
TS_ASSERT_DELTA( b.getErrorSquared(), 3.4*3, 1e-5);
}

/** Add a vector of events */
void test_BuildAndAddLeanEvents()
{
BoxController_sptr sc( new BoxController(2));
MDBox<MDLeanEvent<2>,2> b(sc.get());
std::vector<signal_t> SigErrSq(3*2,1.2);
std::vector<coord_t> Coord(3*2,2);
std::vector<uint16_t> ind;
std::vector<uint32_t> RunID;
SigErrSq[1]=SigErrSq[3]=SigErrSq[5]=3.4;
Coord[1]=Coord[3]=Coord[5] = 3.0;

b.addEvents(SigErrSq,Coord,ind,RunID);

b.refreshCache();

TS_ASSERT_EQUALS( b.getNPoints(), 3)
TS_ASSERT_DELTA( b.getEvents()[2].getSignal(), 1.2, 1e-5)
// Did it keep a running total of the signal and error?
TS_ASSERT_DELTA( b.getSignal(), 1.2*3, 1e-5);
TS_ASSERT_DELTA( b.getErrorSquared(), 3.4*3, 1e-5);
}

/** Add a vector of events */
void test_BuildAndAddFatEvents()
{
BoxController_sptr sc( new BoxController(2));
MDBox<MDEvent<2>,2> b(sc.get());
std::vector<signal_t> SigErrSq(3*2,1.2);
std::vector<coord_t> Coord(3*2,2);
std::vector<uint16_t> ind(3,10);
std::vector<uint32_t> RunID(3,20);
SigErrSq[1]=SigErrSq[3]=SigErrSq[5]=3.4;
Coord[1]=Coord[3]=Coord[5] = 3.0;

b.addEvents(SigErrSq,Coord,ind,RunID);

b.refreshCache();

TS_ASSERT_EQUALS( b.getNPoints(), 3)
TS_ASSERT_DELTA( b.getEvents()[2].getSignal(), 1.2, 1e-5)
// Did it keep a running total of the signal and error?
TS_ASSERT_DELTA( b.getSignal(), 1.2*3, 1e-5);
TS_ASSERT_DELTA( b.getErrorSquared(), 3.4*3, 1e-5);

TS_ASSERT_EQUALS(b.getEvents()[2].getRunIndex(),10);
TS_ASSERT_EQUALS(b.getEvents()[2].getDetectorID(),20);
}


/** Add a vector of events and give start/end spots*/
void test_addEvents_with_start_stop()
{
Expand Down Expand Up @@ -429,8 +500,8 @@ static void destroySuite(MDBoxTest * suite) { delete suite; }

// Must call the signal cache first.
b.refreshCache();
coord_t centroid[2];
b.calculateCentroid(centroid);
coord_t centroid[2];
b.calculateCentroid(centroid);
TS_ASSERT_DELTA( centroid[0], 3.333, 0.001);
TS_ASSERT_DELTA( centroid[1], 3.666, 0.001);

Expand All @@ -450,8 +521,8 @@ static void destroySuite(MDBoxTest * suite) { delete suite; }
MDBox<MDLeanEvent<2>,2> b(sc.get());
b.refreshCache();

coord_t centroid[2];
b.calculateCentroid(centroid);
coord_t centroid[2];
b.calculateCentroid(centroid);
TS_ASSERT_DELTA( centroid[0], 0.000, 0.001);
TS_ASSERT_DELTA( centroid[1], 0.000, 0.001);
//#ifdef MDBOX_TRACK_CENTROID
Expand Down

0 comments on commit abe442e

Please sign in to comment.