OTSEDSBase.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. // Finished the instance.
  37. // virtual
  38. //virtual void FinishedInstance() = 0;
  39. // Initialization method
  40. // virtual
  41. virtual BOOL Init() = 0;
  42. // To show whether the detector can collect a set of x-Ray one go
  43. // virtual
  44. virtual BOOL IsSupportSetCollection() = 0;
  45. // Quantification
  46. virtual BOOL IsSupportQuantification() = 0;
  47. virtual BOOL GetQuantificationMethods(std::vector<CString>& a_vMethods) = 0;
  48. virtual BOOL QuantifyXrayPoint(CPosXray* a_pXRayPoint, LPCTSTR a_sMethodName) = 0;
  49. virtual BOOL QuantifySpectrumFile(LPCTSTR a_sFilePathName, LPCTSTR a_sMethodName, CElementChemistriesList& a_listElementChemistry) = 0;
  50. virtual BOOL QuantifySpectrumOut(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize, CElementChemistriesList& a_listElementChemistry) = 0;
  51. // collect x ray points
  52. // virtual
  53. /* virtual BOOL CollectXRayPoints(std::vector<CPosXray*>& a_vXRayPoints, const DWORD a_nXRayAQTime) = 0;
  54. virtual BOOL CollectXRayPoints(std::vector<CPosXrayPtr>& a_vXRayPoints, const DWORD a_nXRayAQTime) = 0;
  55. virtual BOOL CollectXRayPointsByFeatures(std::vector<CPosXray*>& a_listXRayPoints,
  56. std::vector<std::vector<BrukerSegment>>& a_listFeatures,
  57. const DWORD a_nXRayAQTime) = 0;*/
  58. // collect spectrum data
  59. // virtual
  60. virtual BOOL CollectSpectrum(DWORD a_nMilliseconds) = 0;
  61. virtual BOOL CollectSpectrum(DWORD a_nMilliseconds, const CPoint& a_oPoint) = 0;
  62. virtual BOOL CollectSpectrum(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize) = 0;
  63. // quantify spectrum
  64. // Get x-Ray data
  65. // virtual
  66. virtual DWORD* GetXRayData() = 0;
  67. // Set Amp Time Index for all detectors
  68. // virtual
  69. virtual BOOL SetAmpTimeIndex(long a_nIndex) = 0;
  70. // get live time
  71. // virtual
  72. virtual float GetLiveTime(void) = 0;
  73. // get max points limit
  74. // virtual
  75. virtual long GetMaxPointLimit(void) = 0;
  76. virtual BOOL GetXRayByPoints(std::vector<CPosXrayPtr>& a_vXRayPoints, const DWORD a_nXRayAQTime) = 0;
  77. virtual BOOL GetXRayByFeatures(std::vector<CPosXrayPtr>& a_listXRayPoints,
  78. std::vector<BrukerFeature>& a_listFeatures,
  79. const DWORD a_nXRayAQTime) = 0;
  80. BOOL GetXRayByFeaturesFromMultiPoint(std::vector<CPosXrayPtr>& a_listXRayPoints,
  81. std::vector<std::vector<BrukerSegment>>& a_listFeatures,
  82. const DWORD a_nXRayAQTime);
  83. // Quantification
  84. virtual void SetQuantification(BOOL a_bQuantification) = 0;
  85. virtual BOOL GetQuantification() = 0;
  86. virtual DWORD GetNumberOfChannels(void) = 0;
  87. BOOL CollectASpectrumFromTxtFile(DWORD* a_pCounts, DWORD a_nBufferSize);
  88. // get company system data path
  89. CString GetCompanySysDataPathName()
  90. {
  91. // get common data pathname string
  92. CString strCommonDataPathName = GetOSCommonDataPathName();
  93. if (strCommonDataPathName.IsEmpty())
  94. {
  95. // failed to get common data pathname string
  96. LogErrorTrace(__FILE__, __LINE__, _T("GetOTSPackSysDataPathName: failed to common data pathname string."));
  97. return _T("");
  98. }
  99. // company system data pathname
  100. // e.g. "c:\ProgramData\Config\"
  101. //CString strCmpSysDataPath = strCommonDataPathName + STR_COMPANYNAME + _T("\\") + STR_SYSTEM_DATA + _T("\\");
  102. CString strCmpSysDataPath = strCommonDataPathName + STR_COMPANYNAME + _T("\\") + STR_SIMULATE_DATA + _T("\\");
  103. // return company system data pathname
  104. return strCmpSysDataPath;
  105. }
  106. // get system common data folder pathname
  107. // return "" if failed
  108. CString GetOSCommonDataPathName()
  109. {
  110. CString strPathName= _T(".\\");
  111. /*if (strPathName.Right(1) != _T('.\\'))
  112. {
  113. strPathName +=
  114. }*/
  115. return strPathName;
  116. }
  117. // check if the file exists or not
  118. BOOL Exists(LPCTSTR a_sPath)
  119. {
  120. return ::PathFileExists(a_sPath) == TRUE;
  121. }
  122. std::vector<CString> LoadTextFileToCStingList(CString a_strPathName, int a_nLine /*= -1*/)
  123. {
  124. // string list
  125. std::vector<CString> listStr;
  126. // load
  127. try
  128. {
  129. // open the file
  130. CStdioFile file;
  131. file.Open(a_strPathName, CFile::modeRead | CFile::shareDenyWrite);
  132. // read the file
  133. CString strLine;
  134. int nLine = 0;
  135. while (file.ReadString(strLine) && nLine != a_nLine)
  136. {
  137. // get a line
  138. // remove comments
  139. int nCommentPos = strLine.Find(OTS_TEXT_FILE_COMMENT);
  140. if (nCommentPos != -1)
  141. {
  142. // remove comments
  143. strLine = strLine.Left(nCommentPos);
  144. }
  145. // process the line
  146. strLine.Trim();
  147. // jump over empty lines
  148. if (strLine.IsEmpty())
  149. {
  150. continue;
  151. }
  152. listStr.push_back(strLine);
  153. }
  154. file.Close();
  155. }
  156. catch (CFileException* pe)
  157. {
  158. pe->Delete();
  159. return listStr;
  160. }
  161. // return string list
  162. return listStr;
  163. }
  164. // Strings to int.
  165. BOOL StringToInt(LPCTSTR a_sValue, int& a_nValue)
  166. {
  167. if (!IsDigitString(a_sValue))
  168. {
  169. LogErrorTrace(__FILE__, __LINE__, _T("StringToInt: value string (%s) is not digit string."), a_sValue);
  170. return FALSE;
  171. }
  172. a_nValue = _ttoi(a_sValue);
  173. return TRUE;
  174. }
  175. // Determines whether is digit string.
  176. BOOL IsDigitString(LPCTSTR a_sValue)
  177. {
  178. CString strInt = a_sValue;
  179. strInt.Trim();
  180. if (strInt.IsEmpty())
  181. {
  182. LogErrorTrace(__FILE__, __LINE__, _T("IsDigitString: value string is an empty string."));
  183. return FALSE;
  184. }
  185. int nStart = 0;
  186. if (strInt[nStart] == _T('-'))
  187. {
  188. ++nStart;
  189. }
  190. // cycle through string and check each character if it is a digit
  191. for (; nStart < strInt.GetLength(); ++nStart)
  192. {
  193. if (!isdigit_t(strInt[nStart]))
  194. {
  195. LogErrorTrace(__FILE__, __LINE__, _T("IsDigitString: value string (%s) is not a digit string."), strInt);
  196. return FALSE;
  197. }
  198. }
  199. return TRUE;
  200. }
  201. protected:
  202. // x-Ray data
  203. DWORD m_nRayData[(long)EDSConst::XANA_CHANNELS];
  204. //amplify time list
  205. float m_list_ampTime[(long)EDSConst::MAX_AMPTIME_CONSTANTS];
  206. //amplify times
  207. long m_nTimeCounts;
  208. // do quantification
  209. BOOL m_bDoQuantification;
  210. };
  211. typedef std::shared_ptr<COTSEDSBase> COTSEDSBasePtr;
  212. } // namespace OTSController