OTSEDSBase.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #pragma once
  2. // FileName: OTSEDSBase.h
  3. // Brief: EDS Base Class , x-Ray acquisition system
  4. // Author: Anna.Hao
  5. // Data: 6/30/2017
  6. #include "PosXray.h"
  7. #include "Element.h"
  8. #include "SEMCommonConst.h"
  9. #include "Bruker\OTSBrukerImpl_const.h"
  10. namespace OTSController
  11. {
  12. using namespace OTSDATA;
  13. const CString SIMULATION_SPECTRUM_FILENAME = _T("SimSpectrum.txt");
  14. #ifdef UNICODE
  15. #define isdigit_t iswdigit
  16. #else
  17. #define isdigit_t isdigit
  18. #endif
  19. // Class OTSController::COTSEDS define.
  20. class __declspec(dllexport) COTSEDSBase
  21. {
  22. public:
  23. COTSEDSBase(void);
  24. ~COTSEDSBase(void);
  25. // Get the name of EDS
  26. // Input: void
  27. // Output: CString, name of EDS
  28. CString GetName()
  29. {
  30. CString strR = EDSController::GetName((int)GetType());
  31. return strR;
  32. }
  33. // Get EDS type
  34. // virtual
  35. virtual EDSController::EDS_ID GetType() = 0;
  36. virtual BOOL Init() = 0;
  37. // To show whether the detector can collect a set of x-Ray one go
  38. // virtual
  39. virtual BOOL IsSupportSetCollection() = 0;
  40. // Quantification
  41. virtual BOOL IsSupportQuantification() = 0;
  42. virtual BOOL GetQuantificationMethods(std::vector<CString>& a_vMethods) = 0;
  43. virtual BOOL QuantifyXrayPoint(CPosXray* a_pXRayPoint, LPCTSTR a_sMethodName) = 0;
  44. virtual BOOL QuantifySpectrumFile(LPCTSTR a_sFilePathName, LPCTSTR a_sMethodName, CElementChemistriesList& a_listElementChemistry) = 0;
  45. virtual BOOL QuantifySpectrumOut(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize, CElementChemistriesList& a_listElementChemistry) = 0;
  46. // collect spectrum data
  47. // virtual
  48. virtual BOOL CollectSpectrum(DWORD a_nMilliseconds) = 0;
  49. virtual BOOL CollectSpectrum(DWORD a_nMilliseconds, const CPoint& a_oPoint) = 0;
  50. virtual BOOL CollectSpectrum(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize) = 0;
  51. virtual BOOL StopXrayAcquistion() = 0;
  52. // quantify spectrum
  53. // Get x-Ray data
  54. // virtual
  55. virtual DWORD* GetXRayData() = 0;
  56. // Set Amp Time Index for all detectors
  57. // virtual
  58. virtual BOOL SetAmpTimeIndex(long a_nIndex) = 0;
  59. // get live time
  60. // virtual
  61. virtual float GetLiveTime(void) = 0;
  62. // get max points limit
  63. // virtual
  64. virtual long GetMaxPointLimit(void) = 0;
  65. virtual BOOL GetXRayByPoints(std::vector<CPosXrayPtr>& a_vXRayPoints, const DWORD a_nXRayAQTime) = 0;
  66. virtual BOOL QuantifyXrayByParts(std::vector<CPosXrayPtr>& a_vXRayParts)=0;//in our system ,one particle has one CPosXray object.
  67. virtual BOOL QuantifyXrayByPart(CPosXrayPtr& a_vXRayPart)=0;
  68. virtual BOOL GetXRayByFeatures(std::vector<CPosXrayPtr>& a_listXRayPoints,
  69. std::vector<BrukerFeature>& a_listFeatures,
  70. const DWORD a_nXRayAQTime) = 0;
  71. BOOL GetXRayByFeaturesFromMultiPoint(std::vector<CPosXrayPtr>& a_listXRayPoints,
  72. std::vector<std::vector<BrukerSegment>>& a_listFeatures,
  73. const DWORD a_nXRayAQTime);
  74. // Quantification
  75. virtual void SetQuantification(BOOL a_bQuantification) = 0;
  76. virtual BOOL GetQuantification() = 0;
  77. virtual DWORD GetNumberOfChannels(void) = 0;
  78. BOOL CollectASpectrumFromTxtFile(DWORD* a_pCounts, DWORD a_nBufferSize);
  79. // get company system data path
  80. CString GetCompanySysDataPathName()
  81. {
  82. // get common data pathname string
  83. CString strCommonDataPathName = GetOSCommonDataPathName();
  84. if (strCommonDataPathName.IsEmpty())
  85. {
  86. // failed to get common data pathname string
  87. LogErrorTrace(__FILE__, __LINE__, _T("GetOTSPackSysDataPathName: failed to common data pathname string."));
  88. return _T("");
  89. }
  90. // company system data pathname
  91. // e.g. "c:\ProgramData\Config\"
  92. //CString strCmpSysDataPath = strCommonDataPathName + STR_COMPANYNAME + _T("\\") + STR_SYSTEM_DATA + _T("\\");
  93. CString strCmpSysDataPath = strCommonDataPathName + STR_COMPANYNAME + _T("\\") + STR_SIMULATE_DATA + _T("\\");
  94. // return company system data pathname
  95. return strCmpSysDataPath;
  96. }
  97. // get system common data folder pathname
  98. // return "" if failed
  99. CString GetOSCommonDataPathName()
  100. {
  101. CString strPathName= _T(".\\");
  102. /*if (strPathName.Right(1) != _T('.\\'))
  103. {
  104. strPathName +=
  105. }*/
  106. return strPathName;
  107. }
  108. // check if the file exists or not
  109. BOOL Exists(LPCTSTR a_sPath)
  110. {
  111. return ::PathFileExists(a_sPath) == TRUE;
  112. }
  113. std::vector<CString> LoadTextFileToCStingList(CString a_strPathName, int a_nLine /*= -1*/)
  114. {
  115. // string list
  116. std::vector<CString> listStr;
  117. // load
  118. try
  119. {
  120. // open the file
  121. CStdioFile file;
  122. file.Open(a_strPathName, CFile::modeRead | CFile::shareDenyWrite);
  123. // read the file
  124. CString strLine;
  125. int nLine = 0;
  126. while (file.ReadString(strLine) && nLine != a_nLine)
  127. {
  128. // get a line
  129. // remove comments
  130. int nCommentPos = strLine.Find(OTS_TEXT_FILE_COMMENT);
  131. if (nCommentPos != -1)
  132. {
  133. // remove comments
  134. strLine = strLine.Left(nCommentPos);
  135. }
  136. // process the line
  137. strLine.Trim();
  138. // jump over empty lines
  139. if (strLine.IsEmpty())
  140. {
  141. continue;
  142. }
  143. listStr.push_back(strLine);
  144. }
  145. file.Close();
  146. }
  147. catch (CFileException* pe)
  148. {
  149. pe->Delete();
  150. return listStr;
  151. }
  152. // return string list
  153. return listStr;
  154. }
  155. // Strings to int.
  156. BOOL StringToInt(LPCTSTR a_sValue, int& a_nValue)
  157. {
  158. if (!IsDigitString(a_sValue))
  159. {
  160. LogErrorTrace(__FILE__, __LINE__, _T("StringToInt: value string (%s) is not digit string."), a_sValue);
  161. return FALSE;
  162. }
  163. a_nValue = _ttoi(a_sValue);
  164. return TRUE;
  165. }
  166. // Determines whether is digit string.
  167. BOOL IsDigitString(LPCTSTR a_sValue)
  168. {
  169. CString strInt = a_sValue;
  170. strInt.Trim();
  171. if (strInt.IsEmpty())
  172. {
  173. LogErrorTrace(__FILE__, __LINE__, _T("IsDigitString: value string is an empty string."));
  174. return FALSE;
  175. }
  176. int nStart = 0;
  177. if (strInt[nStart] == _T('-'))
  178. {
  179. ++nStart;
  180. }
  181. // cycle through string and check each character if it is a digit
  182. for (; nStart < strInt.GetLength(); ++nStart)
  183. {
  184. if (!isdigit_t(strInt[nStart]))
  185. {
  186. LogErrorTrace(__FILE__, __LINE__, _T("IsDigitString: value string (%s) is not a digit string."), strInt);
  187. return FALSE;
  188. }
  189. }
  190. return TRUE;
  191. }
  192. virtual void SetExpectCount(int expectcount)=0 ;
  193. virtual int GetExpectCount() = 0;
  194. protected:
  195. // x-Ray data
  196. DWORD m_nRayData[(long)EDSConst::XANA_CHANNELS];
  197. //amplify time list
  198. float m_list_ampTime[(long)EDSConst::MAX_AMPTIME_CONSTANTS];
  199. //amplify times
  200. long m_nTimeCounts;
  201. // do quantification
  202. BOOL m_bDoQuantification;
  203. };
  204. typedef std::shared_ptr<COTSEDSBase> COTSEDSBasePtr;
  205. } // namespace OTSController