summaryrefslogtreecommitdiffstats
path: root/src/DetectorModule/DetectorModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/DetectorModule/DetectorModule.cpp')
-rw-r--r--src/DetectorModule/DetectorModule.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp
index ac9ee27..f0c1a06 100644
--- a/src/DetectorModule/DetectorModule.cpp
+++ b/src/DetectorModule/DetectorModule.cpp
@@ -7,3 +7,63 @@
* Author: Tobias Frust
*/
+#include "DetectorModule.h"
+#include "../ConfigReader/ConfigReader.h"
+
+#include <exception>
+#include <fstream>
+
+template<typename T>
+DetectorModule<T>::DetectorModule(const int detectorID, const std::string& address, const std::string& configPath) :
+ detectorID_{detectorID},
+ numberOfDetectorsPerModule_{16},
+ index_{0},
+ client_{address, detectorID + 4000} {
+
+ if (readConfig(configPath)) {
+ throw std::runtime_error("DetectorModule: Configuration file could not be loaded successfully. Please check!");
+ }
+
+ //read the input data from the file corresponding to the detectorModuleID
+ readInput();
+}
+
+template <typename T>
+auto DetectorModule<T>::sendPeriodically(unsigned int timeIntervall) -> void {
+ client_.send(buffer_.data(), sizeof(T)*numberOfDetectorsPerModule_*numberOfProjections_);
+}
+
+template <typename T>
+auto DetectorModule<T>::readInput() -> void {
+ if(path_.back() != '/')
+ path_.append("/");
+ //open file
+ std::ifstream input(path_ + fileName_ + std::to_string(detectorID_) + fileEnding_, std::ios::in | std::ios::binary);
+ //allocate memory in vector
+ std::streampos fileSize;
+ input.seekg(0, std::ios::end);
+ fileSize = input.tellg();
+ input.seekg(0, std::ios::beg);
+ buffer_.resize(fileSize / sizeof(T));
+ input.read((char*) &buffer_[0], fileSize);
+}
+
+template<typename T>
+auto DetectorModule<T>::readConfig(const std::string& configFile) -> bool {
+ ConfigReader configReader = ConfigReader(configFile.data());
+ int samplingRate, scanRate;
+ if (configReader.lookupValue("numberOfFanDetectors", numberOfDetectors_)
+ && configReader.lookupValue("dataInputPath", path_)
+ && configReader.lookupValue("dataFileName", fileName_)
+ && configReader.lookupValue("dataFileEnding", fileEnding_)
+ && configReader.lookupValue("numberOfPlanes", numberOfPlanes_)
+ && configReader.lookupValue("samplingRate", samplingRate)
+ && configReader.lookupValue("scanRate", scanRate)
+ && configReader.lookupValue("numberOfDataFrames", numberOfFrames_)) {
+ numberOfProjections_ = samplingRate * 1000000 / scanRate;
+ return EXIT_SUCCESS;
+ }
+
+ return EXIT_FAILURE;
+ }
+