Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
SampleSet.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "SampleSet.h"
14 #include "Sample.h"
15 #include "DataGroupNode.h"
16 #include "ActiveObjectsManager.h"
17 
18 
19 using namespace kome::objects;
20 
21 
22 #include <crtdbg.h>
23 #ifdef _DEBUG
24  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
25  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
26 #endif // _DEBUG
27 
28 
29 
30 // static member
32 int SampleSet::m_currentSampleSetId = 0;
33 
34 
35 // construcotr
37  m_opened = false;
38  // >>>>>> @Date:2013/06/13 <Add> A.Ozaki
40  // <<<<<< @Date:2013/06/13 <Add> A.Ozaki
41 
43 }
44 
45 // destructor
47  clearSamples();
48 }
49 
50 // get sample set ID
52  return m_sampleSetId;
53 }
54 
55 // set file path
56 void SampleSet::setFilePath( const char* path ) {
57  m_filePath = NVL( path, "" );
58 
59  for( unsigned int i = 0; i < m_samples.size(); i++ ) {
60  kome::objects::Sample* sample = m_samples[ i ];
62  if( root != NULL ) {
63  root->getProperties().setValue( "File Path", m_filePath.c_str() );
64  }
65  }
66 }
67 
68 // get file path
69 const char* SampleSet::getFilePath() {
70  return m_filePath.c_str();
71 }
72 
73 // get file name
74 const char* SampleSet::getFileName() {
75  return m_fileName.c_str();
76 }
77 
78 // judge whter sample set file is opened
80  return m_opened;
81 }
82 
83 // clear samples
85  // clear samples
86  for( unsigned int i = 0; i < m_samples.size(); i++ ) {
87  delete m_samples[ i ];
88  }
89  m_samples.clear();
90 
91  // opened flag
92  m_opened = false;
93 
94  // remove from opened sample sets
96 }
97 
98 // add sample
99 void SampleSet::addSample( Sample* sample ) {
100  // check the parameter
101  if( sample == NULL ) {
102  return;
103  }
104  if( sample->getSampleSet() != this ) {
105  LOG_WARN( FMT( "Sample set is different." ) );
106  return;
107  }
108 
109  // add
110  sample->setSampleIndex( (int)m_samples.size() );
111  m_samples.push_back( sample );
112 }
113 
114 // get the number of samples
116  return m_samples.size();
117 }
118 
119 // get sample
120 Sample* SampleSet::getSample( const unsigned int index ) {
121  if( index >= m_samples.size() ) {
122  return NULL;
123  }
124  return m_samples[ index ];
125 }
126 
127 // open file
128 bool SampleSet::openFile( const char* path, kome::core::Progress* progress ) { // add param @date 2014.07.08 <Mod> M.Izumi
129  if( m_opened ) { // already opened
130  return true;
131  }
132 
133  // set file path
134  m_filePath = absolutepath( path );
135  m_fileName = getfilename( m_filePath.c_str() );
136 
137  // log
138  LOG_DEBUG( FMT( "Open the raw data. [%s]", m_filePath.c_str() ) );
139 
140  // open
142 
143  bool ret = false;
144  try {
145  ret = onOpenFile( m_filePath.c_str(), progress );// add param
146  }
147  catch( ... ) {
148  ret = false;
149  }
150 
152 
153  if( ret ) {
154  m_opened = true;
155  }
156  else {
157  clearSamples();
158  LOG_ERROR( FMT( "Failed to open the file.[%s]", m_filePath.c_str() ) );
159  }
160 
161  return ret;
162 }
163 
164 // close file
166  if( !m_opened ) {
167  return true;
168  }
169 
170  // close
171  for( unsigned int i = 0; i < m_samples.size(); i++ ) {
172  m_samples[ i ]->closeSample();
173  }
174  bool ret = onCloseFile();
175 
176  // clear
177  clearSamples();
178 
179  return ret;
180 }
181 
182 // start loading timer
185 }
186 
187 // stop loading timer
190 }
191 
192 // get total loading time
194  return m_loadingTimer.getTotalTime();
195 }
196 
197 // issue sample set ID
199  int sampleSetId = m_currentSampleSetId;
200  m_currentSampleSetId++;
201 
202  return sampleSetId;
203 }
204 
205 // >>>>>> @Date:2013/06/13 <Add> A.Ozaki
206 // get error code of file access.
208 {
209  return m_errorCode;
210 }
211 
212 // set error code of file access.
213 void SampleSet::setErrorCode( const int errorCode )
214 {
215  m_errorCode = errorCode;
216 
217  return;
218 }
219 // <<<<<< @Date:2013/06/13 <Add> A.Ozaki
std::string getfilename(const char *path)
get file name
interfaces of ActiveObjectsManager class
group of spectrum management class
Definition: DataGroupNode.h:33
SampleSet * getSampleSet()
gets sample set object
Definition: Sample.cpp:77
bool isOpened()
judges whther this sample set file is opened or not
Definition: SampleSet.cpp:79
static double getTotalLoadingTime()
gets total loading time
Definition: SampleSet.cpp:193
bool openFile(const char *path, kome::core::Progress *progress=NULL)
opens file
Definition: SampleSet.cpp:128
static kome::core::Timer m_loadingTimer
Definition: SampleSet.h:57
sample information management class
Definition: Sample.h:34
std::vector< Sample * > m_samples
Definition: SampleSet.h:51
std::string m_fileName
Definition: SampleSet.h:48
static ActiveObjectsManager & getInstance()
get active object manager object (This is the only object.)
active object management class
virtual bool onOpenFile(const char *path, kome::core::Progress *progress=NULL)=0
This method is called by openFile method. (abstract method)
void setValue(const char *key, const char *value)
sets parameter value
Definition: Properties.cpp:39
timer class
Definition: Timer.h:26
std::string m_filePath
Definition: SampleSet.h:45
void start()
starts timer
Definition: Timer.cpp:46
interfaces of SampleSet class
const char * getFileName()
gets file name
Definition: SampleSet.cpp:74
static void stopLoadingTimer()
stops loading timer
Definition: SampleSet.cpp:188
kome::core::Properties & getProperties()
gets properties
progress display abstract class
Definition: Progress.h:31
virtual bool onCloseFile()=0
This method is called by closeFile method. (abstract method)
interfaces of DataGroupNode class
const unsigned int ERR_OK
Definition: ErrorCode.h:39
int getErrorCode(void)
get error code of file access.
Definition: SampleSet.cpp:207
interfaces of Sample class
SampleSet()
constructor
Definition: SampleSet.cpp:36
void clearSamples()
clears samples
Definition: SampleSet.cpp:84
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
Sample * getSample(const unsigned int index)
gets sample object
Definition: SampleSet.cpp:120
#define NULL
Definition: CoreMacros.h:18
void addSample(Sample *sample)
adds sample
Definition: SampleSet.cpp:99
bool closeFile()
closes file
Definition: SampleSet.cpp:165
double getTotalTime()
gets total time
Definition: Timer.cpp:83
static int issueSampleSetId()
issues sample set ID
Definition: SampleSet.cpp:198
unsigned int getNumberOfSamples()
gets the nubmer of samples
Definition: SampleSet.cpp:115
int getSampleSetId()
gets the sample set ID
Definition: SampleSet.cpp:51
DataGroupNode * getRootDataGroupNode()
gets root spectrum group
Definition: Sample.cpp:219
void setSampleIndex(const int index)
sets sample index
Definition: Sample.cpp:82
std::string absolutepath(const char *path)
get absolute path
void setFilePath(const char *path)
sets the file path
Definition: SampleSet.cpp:56
double stop()
stops timer
Definition: Timer.cpp:52
static void startLoadingTimer()
starts loading timer
Definition: SampleSet.cpp:183
const char * getFilePath()
gets file path
Definition: SampleSet.cpp:69
virtual ~SampleSet()
destructor
Definition: SampleSet.cpp:46
void setErrorCode(const int errorCode)
set error code of file access.
Definition: SampleSet.cpp:213