diff --git a/src/EventBuilder.h b/src/EventBuilder.h index 30379c7..43014e2 100644 --- a/src/EventBuilder.h +++ b/src/EventBuilder.h @@ -10,6 +10,7 @@ #include #include #include +#include //ROOT diff --git a/src/evb/CMakeLists.txt b/src/evb/CMakeLists.txt index fd518ff..e40ec0c 100644 --- a/src/evb/CMakeLists.txt +++ b/src/evb/CMakeLists.txt @@ -42,6 +42,8 @@ target_sources(EventBuilderCore PRIVATE MassLookup.cpp SFPAnalyzer.cpp SlowSort.h + EVBWorkspace.cpp + EVBWorkspace.h ) target_link_libraries(EventBuilderCore PUBLIC diff --git a/src/evb/CompassRun.cpp b/src/evb/CompassRun.cpp index 6b85425..1f2e587 100644 --- a/src/evb/CompassRun.cpp +++ b/src/evb/CompassRun.cpp @@ -16,18 +16,14 @@ #include "FastSort.h" #include "SFPAnalyzer.h" #include "FlagHandler.h" +#include "EVBApp.h" namespace EventBuilder { - - CompassRun::CompassRun() : - m_directory(""), m_scalerinput(""), m_runNum(0), m_scaler_flag(false), m_progressFraction(0.1) + + CompassRun::CompassRun(const EVBParameters& params) : + m_params(params) { - } - - CompassRun::CompassRun(const std::string& dir) : - m_directory(dir), m_scalerinput(""), m_runNum(0), m_scaler_flag(false), m_progressFraction(0.1) - { - + m_tempDir = m_params.workspaceDir / "temp_binary"; } CompassRun::~CompassRun() {} @@ -36,7 +32,7 @@ namespace EventBuilder { /*Load em into a map*/ void CompassRun::SetScalers() { - std::ifstream input(m_scalerinput); + std::ifstream input(m_params.scalerFile); if(!input.is_open()) return; @@ -49,7 +45,7 @@ namespace EventBuilder { while(input>>filename) { input>>varname; - filename = m_directory+filename+"_run_"+std::to_string(m_runNum)+".BIN"; + filename = m_tempDir.string()+filename+"_run_"+std::to_string(m_runNum)+".BIN"; m_scaler_map[filename] = TParameter(varname.c_str(), init); } input.close(); @@ -214,7 +210,7 @@ namespace EventBuilder { output->Close(); } - void CompassRun::Convert2SortedRoot(const std::string& name, const std::string& mapfile, double window) + void CompassRun::Convert2SortedRoot(const std::string& name) { TFile* output = TFile::Open(name.c_str(), "RECREATE"); TTree* outtree = new TTree("SortTree", "SortTree"); @@ -237,7 +233,7 @@ namespace EventBuilder { unsigned int count = 0, flush = m_totalHits*m_progressFraction, flush_count = 0; startIndex = 0; - SlowSort coincidizer(window, mapfile); + SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile); bool killFlag = false; if(flush == 0) flush = 1; @@ -276,7 +272,7 @@ namespace EventBuilder { output->Close(); } - void CompassRun::Convert2FastSortedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window) + void CompassRun::Convert2FastSortedRoot(const std::string& name) { TFile* output = TFile::Open(name.c_str(), "RECREATE"); TTree* outtree = new TTree("SortTree", "SortTree"); @@ -301,8 +297,8 @@ namespace EventBuilder { startIndex = 0; CoincEvent this_event; std::vector fast_events; - SlowSort coincidizer(window, mapfile); - FastSort speedyCoincidizer(fsi_window, fic_window); + SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile); + FastSort speedyCoincidizer(m_params.fastCoincidenceWindowSABRE, m_params.fastCoincidenceWindowIonCh); FlagHandler flagger; @@ -355,8 +351,7 @@ namespace EventBuilder { } - void CompassRun::Convert2SlowAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, - int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta) + void CompassRun::Convert2SlowAnalyzedRoot(const std::string& name) { TFile* output = TFile::Open(name.c_str(), "RECREATE"); @@ -381,20 +376,20 @@ namespace EventBuilder { startIndex = 0; CoincEvent this_event; - SlowSort coincidizer(window, mapfile); - SFPAnalyzer analyzer(zt, at, zp, ap, ze, ae, bke, theta, b); + SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile); + SFPAnalyzer analyzer(m_params.ZT, m_params.AT, m_params.ZP, m_params.AP, m_params.ZE, m_params.AE, m_params.beamEnergy, m_params.spsAngle, m_params.BField); std::vector> parvec; parvec.reserve(9); - parvec.emplace_back("ZT", zt); - parvec.emplace_back("AT", at); - parvec.emplace_back("ZP", zp); - parvec.emplace_back("AP", ap); - parvec.emplace_back("ZE", ze); - parvec.emplace_back("AE", ae); - parvec.emplace_back("Bfield", b); - parvec.emplace_back("BeamKE", bke); - parvec.emplace_back("Theta", theta); + parvec.emplace_back("ZT", m_params.ZT); + parvec.emplace_back("AT", m_params.AT); + parvec.emplace_back("ZP", m_params.ZP); + parvec.emplace_back("AP", m_params.AP); + parvec.emplace_back("ZE", m_params.ZE); + parvec.emplace_back("AE", m_params.AE); + parvec.emplace_back("Bfield", m_params.BField); + parvec.emplace_back("BeamKE", m_params.beamEnergy); + parvec.emplace_back("Theta", m_params.spsAngle); bool killFlag = false; if(flush == 0) @@ -443,8 +438,7 @@ namespace EventBuilder { output->Close(); } - void CompassRun::Convert2FastAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window, - int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta) + void CompassRun::Convert2FastAnalyzedRoot(const std::string& name) { TFile* output = TFile::Open(name.c_str(), "RECREATE"); @@ -470,21 +464,21 @@ namespace EventBuilder { startIndex = 0; CoincEvent this_event; std::vector fast_events; - SlowSort coincidizer(window, mapfile); - FastSort speedyCoincidizer(fsi_window, fic_window); - SFPAnalyzer analyzer(zt, at, zp, ap, ze, ae, bke, theta, b); + SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile); + FastSort speedyCoincidizer(m_params.fastCoincidenceWindowSABRE, m_params.fastCoincidenceWindowIonCh); + SFPAnalyzer analyzer(m_params.ZT, m_params.AT, m_params.ZP, m_params.AP, m_params.ZE, m_params.AE, m_params.beamEnergy, m_params.spsAngle, m_params.BField); std::vector> parvec; parvec.reserve(9); - parvec.emplace_back("ZT", zt); - parvec.emplace_back("AT", at); - parvec.emplace_back("ZP", zp); - parvec.emplace_back("AP", ap); - parvec.emplace_back("ZE", ze); - parvec.emplace_back("AE", ae); - parvec.emplace_back("Bfield", b); - parvec.emplace_back("BeamKE", bke); - parvec.emplace_back("Theta", theta); + parvec.emplace_back("ZT", m_params.ZT); + parvec.emplace_back("AT", m_params.AT); + parvec.emplace_back("ZP", m_params.ZP); + parvec.emplace_back("AP", m_params.AP); + parvec.emplace_back("ZE", m_params.ZE); + parvec.emplace_back("AE", m_params.AE); + parvec.emplace_back("Bfield", m_params.BField); + parvec.emplace_back("BeamKE", m_params.beamEnergy); + parvec.emplace_back("Theta", m_params.spsAngle); FlagHandler flagger; diff --git a/src/evb/CompassRun.h b/src/evb/CompassRun.h index 8651e4e..d630883 100644 --- a/src/evb/CompassRun.h +++ b/src/evb/CompassRun.h @@ -19,24 +19,20 @@ namespace EventBuilder { + struct EVBParameters; //Foward decl to avoid recursive includes + class CompassRun { public: - CompassRun(); - CompassRun(const std::string& dir); + CompassRun(const EVBParameters& params); ~CompassRun(); - inline void SetDirectory(const std::string& dir) { m_directory = dir; } - inline void SetScalerInput(const std::string& filename) { m_scalerinput = filename; } inline void SetRunNumber(int n) { m_runNum = n; } - inline void SetShiftMap(const std::string& filename) { m_smap.SetFile(filename); } void Convert2RawRoot(const std::string& name); - void Convert2SortedRoot(const std::string& name, const std::string& mapfile, double window); - void Convert2FastSortedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window); - void Convert2SlowAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, - int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta); - void Convert2FastAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window, - int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta); + void Convert2SortedRoot(const std::string& name); + void Convert2FastSortedRoot(const std::string& name); + void Convert2SlowAnalyzedRoot(const std::string& name); + void Convert2FastAnalyzedRoot(const std::string& name); inline void SetProgressCallbackFunc(const ProgressCallbackFunc& function) { m_progressCallback = function; } inline void SetProgressFraction(double frac) { m_progressFraction = frac; } @@ -46,8 +42,10 @@ namespace EventBuilder { bool GetHitsFromFiles(); void SetScalers(); void ReadScalerData(const std::string& filename); + + EVBParameters m_params; + std::filesystem::path m_tempDir; - std::string m_directory, m_scalerinput; std::vector m_datafiles; unsigned int startIndex; //this is the file we start looking at; increases as we finish files. ShiftMap m_smap; diff --git a/src/evb/EVBApp.cpp b/src/evb/EVBApp.cpp index 38fafdb..4fb2670 100644 --- a/src/evb/EVBApp.cpp +++ b/src/evb/EVBApp.cpp @@ -19,9 +19,7 @@ namespace EventBuilder { EVBApp::EVBApp() : - m_rmin(0), m_rmax(0), m_ZT(0), m_AT(0), m_ZP(0), m_AP(0), m_ZE(0), m_AE(0), m_ZR(0), m_AR(0), - m_B(0), m_Theta(0), m_BKE(0), m_progressFraction(0.1), m_workspace("none"), m_mapfile("none"), m_shiftfile("none"), - m_cutList("none"), m_scalerfile("none"), m_SlowWindow(0), m_FastWindowIonCh(0), m_FastWindowSABRE(0) + m_progressFraction(0.1) { SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBApp::DefaultProgressCallback)); } @@ -48,31 +46,31 @@ namespace EventBuilder { std::string junk; std::getline(input, junk); - input>>junk>>m_workspace; + input>>junk>>m_params.workspaceDir; input>>junk; std::getline(input, junk); std::getline(input, junk); - input>>junk>>m_mapfile; - input>>junk>>m_scalerfile; - input>>junk>>m_cutList; - input>>junk>>m_ZT>>junk>>m_AT; - input>>junk>>m_ZP>>junk>>m_AP; - input>>junk>>m_ZE>>junk>>m_AE; - input>>junk>>m_B; - input>>junk>>m_BKE; - input>>junk>>m_Theta; + input>>junk>>m_params.channelMapFile; + input>>junk>>m_params.scalerFile; + input>>junk>>m_params.cutListFile; + input>>junk>>m_params.ZT>>junk>>m_params.AT; + input>>junk>>m_params.ZP>>junk>>m_params.AP; + input>>junk>>m_params.ZE>>junk>>m_params.AE; + input>>junk>>m_params.BField; + input>>junk>>m_params.beamEnergy; + input>>junk>>m_params.spsAngle; input>>junk; std::getline(input, junk); std::getline(input, junk); - input>>junk>>m_shiftfile; - input>>junk>>m_SlowWindow; - input>>junk>>m_FastWindowIonCh; - input>>junk>>m_FastWindowSABRE; + input>>junk>>m_params.timeShiftFile; + input>>junk>>m_params.slowCoincidenceWindow; + input>>junk>>m_params.fastCoincidenceWindowIonCh; + input>>junk>>m_params.fastCoincidenceWindowSABRE; input>>junk; std::getline(input, junk); std::getline(input, junk); - input>>junk>>m_rmin; - input>>junk>>m_rmax; + input>>junk>>m_params.runMin; + input>>junk>>m_params.runMax; input.close(); @@ -93,31 +91,31 @@ namespace EventBuilder { } output<<"-------Data Location----------"< EVBWorkspace::GetBinaryRunRange(int runMin, int runMax) + { + std::vector list; + std::string temp; + for(int run=runMin; run<=runMax; run++) + temp = GetBinaryRun(run); + if(!temp.empty()) + list.push_back(temp); + + return list; + } + + std::vector EVBWorkspace::GetTempFiles() + { + std::vector list; + for(auto& entry : std::filesystem::directory_iterator(m_tempDir)) + { + if(entry.is_regular_file() && entry.path().filename().extension().string() == ".BIN") + list.push_back(entry.path().string()); + } + + return list; + } +} \ No newline at end of file diff --git a/src/evb/EVBWorkspace.h b/src/evb/EVBWorkspace.h new file mode 100644 index 0000000..ac7790f --- /dev/null +++ b/src/evb/EVBWorkspace.h @@ -0,0 +1,42 @@ +#ifndef EVB_WORKSPACE_H +#define EVB_WORKSPACE_H + +namespace EventBuilder { + + class EVBWorkspace + { + public: + EVBWorkspace(const std::filesystem::path& workspace); + ~EVBWorkspace(); + + inline const bool IsValid() const { return m_isValid; } + + inline std::filesystem::path GetBinaryDir() const { return m_binaryDir; } + inline std::filesystem::path GetTempDir() const { return m_tempDir; } + inline std::filesystem::path GetSortedDir() const { return m_sortedDir; } + inline std::filesystem::path GetBuiltDir() const { return m_builtDir; } + inline std::filesystem::path GetAnalyzedDir() const { return m_analyzedDir; } + inline std::filesystem::path GetHistogramDir() const { return m_histogramDir; } + inline std::filesystem::path GetCutDir() const { return m_cutDir; } + + std::vector GetBinaryRunRange(int runMin, int runMax); + std::string GetBinaryRun(int run); + std::vector GetTempFiles(); + + private: + void Init(); + bool m_isValid; + + std::filesystem::path m_workspace; + + std::filesystem::path m_binaryDir; + std::filesystem::path m_tempDir; + std::filesystem::path m_sortedDir; + std::filesystem::path m_builtDir; + std::filesystem::path m_analyzedDir; + std::filesystem::path m_histogramDir; + std::filesystem::path m_cutDir; + }; +} + +#endif \ No newline at end of file