From fb1d930127c1dd2cf5d34e247bb33d51ae6481e0 Mon Sep 17 00:00:00 2001 From: redford_s Date: Wed, 27 Feb 2019 14:52:44 +0100 Subject: [PATCH] Module comparison now uses the most recent gain file. --- JFMC_ModuleComp.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/JFMC_ModuleComp.cpp b/JFMC_ModuleComp.cpp index e7a3b6b..3fd8123 100644 --- a/JFMC_ModuleComp.cpp +++ b/JFMC_ModuleComp.cpp @@ -4,6 +4,7 @@ #include "../sls_detector_calibration/jungfrauCommonFunctions.h" #include +#include #include "TH1F.h" #include "TCanvas.h" @@ -18,6 +19,22 @@ struct GainMaps double hg0VALs[NCH]; }; +std::string stdoutOfCommand(const char* cmd) { + char buffer[128]; + std::string result = ""; + FILE* pipe = popen(cmd, "r"); + if (!pipe) throw std::runtime_error("popen() failed!"); + try { + while (fgets(buffer, sizeof buffer, pipe) != NULL) { + result += buffer; + } + } catch (...) { + pclose(pipe); + throw; + } + pclose(pipe); + return result; +} int main(int argc, char* argv[]) { @@ -54,12 +71,16 @@ int main(int argc, char* argv[]) { } // get gain maps + sprintf(savename,"ls -1 data/M%3.3d/gainMaps_M%3.3d* | tail -1", j, j); + string mostRecentGainFile = stdoutOfCommand(savename); + mostRecentGainFile.erase(std::remove(mostRecentGainFile.begin(), mostRecentGainFile.end(), '\n'), mostRecentGainFile.end()); + fstream infile; - sprintf(savename,"data/M%3.3d/gainMaps_M%3.3d.bin", j, j); - infile.open((char*)savename, ios::in | ios::binary); + infile.open(mostRecentGainFile.c_str(), ios::in | ios::binary); if (not infile.is_open()) { continue; } + cout << "found " << mostRecentGainFile << endl; infile.read((char*)mapsObject->g0VALs, sizeof(mapsObject->g0VALs)); infile.read((char*)mapsObject->g1VALs, sizeof(mapsObject->g1VALs));