20 using namespace kome::objects;
25 #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
26 #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
31 #define MAX_PEAK_NUM 10000
38 #ifdef DATAPOINTS_SOFT_CACHE_TBB
40 #endif // DATAPOINTS_SOFT_CACHE_TBB
49 for(
unsigned int i = 0; i < peaks.
m_charges.size(); i++ ) {
55 #ifdef DATAPOINTS_SOFT_CACHE_TBB
58 *m_dps = *(peaks.m_dps);
62 #endif // DATAPOINTS_SOFT_CACHE_TBB
71 if( peaks.
m_peaks.size() == 0 ) {
76 for(
unsigned int i = 0; i < peaks.
m_peaks.size(); i++ ) {
99 #ifdef DATAPOINTS_SOFT_CACHE_TBB
100 if(m_dps)
delete m_dps;
101 #endif // DATAPOINTS_SOFT_CACHE_TBB
122 for(
unsigned int i = 0; i < other.
m_charges.size(); i++ ) {
129 if( other.
m_peaks.size() == 0 ) {
135 for(
unsigned int i = 0; i < other.
m_peaks.size(); i++ ) {
172 "Charge index must be less than the number of charges. [%d/%d] ",
195 #ifdef DATAPOINTS_SOFT_CACHE_TBB
199 if( m_dps ==
NULL ) {
200 LOG_WARN( FMT(
"Failed to calculate area. Data points object is not set up." ) );
204 if( m_dps->getLength() < 2 ) {
209 for(
unsigned int i = 0; i <
m_peaks.size(); i++ ) {
215 double area = peak->
calcArea( *m_dps );
223 #else // DATAPOINTS_SOFT_CACHE_TBB
232 LOG_WARN( FMT(
"Failed to calculate area. Data points object is not set up." ) );
238 FILE* fp =
fileopen( tmpPath.c_str(),
"rb" );
253 for(
unsigned int i = 0; i <
m_peaks.size(); i++ ) {
259 double area = peak->
calcArea( dps );
267 double fwhm = peak->
calcFwhm( dps );
271 #endif // DATAPOINTS_SOFT_CACHE_TBB
276 #ifdef DATAPOINTS_SOFT_CACHE_TBB
280 for(
unsigned int i = 0; i <
m_peaks.size(); i++ ) {
293 for(
unsigned int i = 0; i < xyData.
getLength(); i++ ) {
294 m_dps->addPoint( xyData.
getX( i ), xyData.
getY( i ) );
298 #else // DATAPOINTS_SOFT_CACHE_TBB
307 for(
unsigned int i = 0; i <
m_peaks.size(); i++ ) {
321 static int tmpDirCnt = 0;
323 std::string dir =
getpath(
"peaks_data", FMT(
"%02x", tmpDirCnt ).c_str() );
324 tmpDirCnt = ( tmpDirCnt + 1 ) % 0x100;
326 std::string tmpFileName = msppMgr.
getTmpFileName(
"profile_data",
".xyd", dir.c_str() );
331 FILE* fp =
fileopen( tmpFilePath.c_str(),
"wb" );
339 for(
unsigned int i = 0; i < xyData.
getLength(); i++ ) {
349 #endif // DATAPOINTS_SOFT_CACHE_TBB
359 unsigned int len =
m_peaks.size();
362 if( x <
m_minX || len == 0 ) {
365 if( x >
m_maxX || len == 0 ) {
368 if( y <
m_minY || len == 0 ) {
371 if( y >
m_maxY || len == 0 ) {
382 if( index >=
m_peaks.size() ) {
385 double x =
getX( index );
391 for(
unsigned int i = 0; i <
m_peaks.size(); i++ ) {
405 if(
m_peaks.size() <= MAX_PEAK_NUM ) {
410 std::vector< PeakElement* > peaks;
411 for(
unsigned int i = 0; i <
m_peaks.size(); i++ ) {
412 peaks.push_back(
m_peaks[ i ] );
415 std::sort( peaks.begin(), peaks.end(),
lessPeakY );
418 for(
unsigned int i = 0; i < MAX_PEAK_NUM; i++ ) {
419 m_peaks.push_back( peaks[ i ] );
423 for(
unsigned int i = MAX_PEAK_NUM; i < peaks.size(); i++ ) {
431 unsigned long len = 0;
432 readFun( &len,
sizeof( len ) );
436 double* arr =
new double[ len * 10 ];
437 readFun( arr,
sizeof(
double ) * len * 10 );
439 int* charges =
new int[ len ];
440 readFun( charges,
sizeof(
int ) * len );
443 for(
unsigned int i = 0; i < len; i++ ) {
445 double x = arr[ idx + 0 ];
446 double y = arr[ idx + 1 ];
447 double lx = arr[ idx + 2 ];
448 double ly = arr[ idx + 3 ];
449 double rx = arr[ idx + 4 ];
450 double ry = arr[ idx + 5 ];
451 double ax = arr[ idx + 6 ];
452 double ay = arr[ idx + 7 ];
453 double ar = arr[ idx + 8 ];
454 double wi = arr[ idx + 9 ];
455 int c = charges[ i ];
478 unsigned long len =
m_peaks.size();
479 writeFun( &len,
sizeof( len ) );
483 double* arr =
new double[ len * 10 ];
485 for(
unsigned int i = 0; i < len; i++ ) {
491 arr[ idx + 0 ] = peak->
getX();
492 arr[ idx + 1 ] = peak->
getY();
503 writeFun( arr,
sizeof(
double ) * len * 10 );
508 int* charges =
new int[ len ];
509 for(
unsigned int i = 0; i < len; i++ ) {
516 writeFun( charges,
sizeof(
int ) * len );
532 int idx = std::min( (
int)index, (
int)
m_peaks.size() );
554 return m_peaks[ index ]->getX();
560 return m_peaks[ index ]->getY();
580 if( peakElement !=
NULL && peakElement->
getId() > 0 ){
581 return peakElement->
getId()+1;
590 for(
unsigned int i=0; i <
m_peaks.size(); i++ ){
591 if(
m_peaks[i]->getId() == id ){
PeakElement * getPeak(const unsigned int index)
gets peak
double calcFwhm(kome::core::XYData &xyData)
calculates FWHM
abstraction class of two dimention coordinate data
unsigned int getNumberOfCharges()
gets the number of charges
double getArea()
gets peak area
int issueId(PeakElement *peakElement)
to issue the peak id
static MsppManager & getInstance()
gets MsppManager object (This is the only object.)
void setX(const double x)
sets x element value
data points data of profile management class
double getPrecursor()
gets precursor
bool hasFwhm()
judges whether this peak has FWHM value of not
virtual int read(void *addr, int size)
reads data (override method)
void setPrecursor(const double precursor)
sets precursor
double getX(const unsigned int index)
gets x coordinate
virtual ~Peaks()
destructor
virtual void onDeletePoint(const unsigned int index)
This method is called by deletePoint method. (override method)
virtual unsigned int onGetLength()
this method is called by getLength method (override method)
void setRight(const double x, const double y)
sets peak right
void searchApex(kome::core::XYData &xyData)
searches apex
virtual void onReserve(const unsigned int num)
This method is called by reserve method. (override method)
virtual double onGetY(const unsigned int index)
This method is called by getY method. (override method)
void calcArea()
calculates area
void setDataPoints(kome::core::XYData &xyData)
sets data points
void clearPoints()
clear all data points
void clearCharge()
clears charge
double calcArea(kome::core::XYData &xyData)
calculates area
short getCharge(const unsigned int index)
gets charge
void setArea(const double area)
sets area
double getRightX()
gets x element of peak right
double getY(const unsigned int index)
gets y coordinate
bool fileexists(const char *path)
judge whether file exists
double getRightY()
gets y elemtn of peak right
std::vector< short > m_charges
void setFwhm(const double fwhm)
sets the FWHM
static bool lessPeakX(PeakElement *p0, PeakElement *p1)
compares to sort peaks by x coordinate
interfaces of Peaks class
void setCharge(const int charge)
sets the charge state
const char * getTmpDir()
gets temporary file directory name
interfaces of PeakElement class
double getLeftX()
gets x element of peak left
double getApexX()
gets x element of peak apex
void addCharge(const short charge)
adds charge
FILE * fileopen(const char *path, const char *mode)
opens file
std::vector< PeakElement * > m_peaks
Peaks & operator=(const Peaks &other)
substitution operator
void reserve(const unsigned int num)
reserves enough contiguous memory of array
double getY()
gets y element value
double getApexY()
gets y element of peak apex
bool importData(boost::function< int(void *, int) > readFun)
imports data
PeakElement * getPeakById(int id)
gets peak element by peak id
virtual bool onLoadData(boost::function< int(void *, int) > readFun)
loads data from file (override method)
bool exportData(boost::function< int(void *, int) > writeFun)
exports data
virtual int write(void *addr, int size)
writes data (override method)
bool hasApex()
judges whether this peak has apex information or not.
virtual bool onSaveData(boost::function< int(void *, int) > writeFun)
saves data to file (override method)
static bool lessPeakY(PeakElement *p0, PeakElement *p1)
compares to sort peaks by y coordinate
void setApex(const double x, const double y)
sets peak apex
virtual void onClearPoints()
This method is called by clearPoints method. (override method)
void setLeft(const double x, const double y)
sets peak left
double getX()
gets x element value
bool hasArea()
judges whether this peak has area value or not
bool removefile(const char *path)
removes file
double getFwhm()
gets the FWHM
void addPoint(const double x, const double y)
adds point
virtual void onInsertPoint(const unsigned int index, const double x, const double y)
This method is called by insertPoint method. (override method)
void setY(const double y)
sets y element value
void arrangePeaks()
arrange peaks
virtual void onAddPoint(const double x, const double y)
This method is called by addPoint method. (override method)
virtual double onGetX(const unsigned int index)
This method is called by getX method. (override method)
std::string getTmpFileName(const char *prefix, const char *suffix, const char *dir=NULL)
gets temporary file name
int getCharge()
gets the charge state
PeakElement * createPeak(const double x, const double y)
creates peak
std::string getpath(const char *dir, const char *file)
get file path
unsigned int getLength()
gets the number of points @return the number of points
double getLeftY()
gets y element of peak left