OTSEDSBase.h 6.7 KB

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