Starting to switch to std::filesystem from ROOT based solution. CURRENTLY NOT WORKING, DO NOT PULL, unless you want to contribute to the fix

This commit is contained in:
Gordon McCann 2022-07-11 17:32:48 -04:00
parent dca1b5643a
commit 22c1647ab1
8 changed files with 324 additions and 228 deletions

View File

@ -10,6 +10,7 @@
#include <fstream>
#include <iomanip>
#include <cstdint>
#include <filesystem>
//ROOT

View File

@ -42,6 +42,8 @@ target_sources(EventBuilderCore PRIVATE
MassLookup.cpp
SFPAnalyzer.cpp
SlowSort.h
EVBWorkspace.cpp
EVBWorkspace.h
)
target_link_libraries(EventBuilderCore PUBLIC

View File

@ -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<Long64_t>(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<CoincEvent> 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<TParameter<Double_t>> 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<CoincEvent> 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<TParameter<Double_t>> 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;

View File

@ -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<CompassFile> m_datafiles;
unsigned int startIndex; //this is the file we start looking at; increases as we finish files.
ShiftMap m_smap;

View File

@ -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----------"<<std::endl;
output<<"WorkspaceDirectory: "<<m_workspace<<std::endl;
output<<"WorkspaceDirectory: "<<m_params.workspaceDir<<std::endl;
output<<"-------------------------------"<<std::endl;
output<<"------Experimental Inputs------"<<std::endl;
output<<"ChannelMapFile: "<<m_mapfile<<std::endl;
output<<"ScalerFile: "<<m_scalerfile<<std::endl;
output<<"CutListFile: "<<m_cutList<<std::endl;
output<<"ZT: "<<m_ZT<<std::endl;
output<<"AT: "<<m_AT<<std::endl;
output<<"ZP: "<<m_ZP<<std::endl;
output<<"AP: "<<m_AP<<std::endl;
output<<"ZE: "<<m_ZE<<std::endl;
output<<"AE: "<<m_AE<<std::endl;
output<<"BField(G): "<<m_B<<std::endl;
output<<"BeamKE(MeV): "<<m_BKE<<std::endl;
output<<"Theta(deg): "<<m_Theta<<std::endl;
output<<"ChannelMapFile: "<<m_params.channelMapFile<<std::endl;
output<<"ScalerFile: "<<m_params.scalerFile<<std::endl;
output<<"CutListFile: "<<m_params.cutListFile<<std::endl;
output<<"ZT: "<<m_params.ZT<<std::endl;
output<<"AT: "<<m_params.AT<<std::endl;
output<<"ZP: "<<m_params.ZP<<std::endl;
output<<"AP: "<<m_params.AP<<std::endl;
output<<"ZE: "<<m_params.ZE<<std::endl;
output<<"AE: "<<m_params.AE<<std::endl;
output<<"BField(G): "<<m_params.BField<<std::endl;
output<<"BeamKE(MeV): "<<m_params.beamEnergy<<std::endl;
output<<"Theta(deg): "<<m_params.spsAngle<<std::endl;
output<<"-------------------------------"<<std::endl;
output<<"-------Timing Information------"<<std::endl;
output<<"BoardOffsetFile: "<<m_shiftfile<<std::endl;
output<<"SlowCoincidenceWindow(ps): "<<m_SlowWindow<<std::endl;
output<<"FastCoincidenceWindow_IonCh(ps): "<<m_FastWindowIonCh<<std::endl;
output<<"FastCoincidenceWindow_SABRE(ps): "<<m_FastWindowSABRE<<std::endl;
output<<"BoardOffsetFile: "<<m_params.timeShiftFile<<std::endl;
output<<"SlowCoincidenceWindow(ps): "<<m_params.slowCoincidenceWindow<<std::endl;
output<<"FastCoincidenceWindow_IonCh(ps): "<<m_params.fastCoincidenceWindowIonCh<<std::endl;
output<<"FastCoincidenceWindow_SABRE(ps): "<<m_params.fastCoincidenceWindowSABRE<<std::endl;
output<<"-------------------------------"<<std::endl;
output<<"--------Run Information--------"<<std::endl;
output<<"MinRun: "<<m_rmin<<std::endl;
output<<"MaxRun: "<<m_rmax<<std::endl;
output<<"MinRun: "<<m_params.runMin<<std::endl;
output<<"MaxRun: "<<m_params.runMax<<std::endl;
output<<"-------------------------------"<<std::endl;
output.close();
@ -128,16 +126,16 @@ namespace EventBuilder {
void EVBApp::PlotHistograms()
{
std::string analyze_dir = m_workspace+"/analyzed/";
std::string plot_file = m_workspace+"/histograms/run_"+std::to_string(m_rmin)+"_"+std::to_string(m_rmax)+".root";
std::string analyze_dir = m_params.workspaceDir+"/analyzed/";
std::string plot_file = m_params.workspaceDir+"/histograms/run_"+std::to_string(m_params.runMin)+"_"+std::to_string(m_params.runMax)+".root";
SFPPlotter grammer;
grammer.SetProgressCallbackFunc(m_progressCallback);
grammer.SetProgressFraction(m_progressFraction);
grammer.ApplyCutlist(m_cutList);
EVB_INFO("Generating histograms from analyzed runs [{0}, {1}] with Cut List {2}...", m_rmin, m_rmax, m_cutList);
grammer.ApplyCutlist(m_params.cutListFile);
EVB_INFO("Generating histograms from analyzed runs [{0}, {1}] with Cut List {2}...", m_params.runMin, m_params.runMax, m_params.cutListFile);
EVB_INFO("Output file will be named {0}",plot_file);
grabber.SetSearchParams(analyze_dir, "", ".root", m_rmin, m_rmax);
grabber.SetSearchParams(analyze_dir, "", ".root", m_params.runMin, m_params.runMax);
if(grabber.GrabFilesInRange())
{
grammer.Run(grabber.GetFileList(), plot_file);
@ -152,24 +150,22 @@ namespace EventBuilder {
void EVBApp::Convert2RawRoot()
{
int sys_return;
std::string rawroot_dir = m_workspace+"/raw_root/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
EVB_INFO("Converting binary archives to ROOT files over run range [{0}, {1}]",m_rmin,m_rmax);
std::string rawroot_dir = m_params.workspaceDir+"/raw_root/";
std::string unpack_dir = m_params.workspaceDir+"/temp_binary/";
std::string binary_dir = m_params.workspaceDir+"/raw_binary/";
EVB_INFO("Converting binary archives to ROOT files over run range [{0}, {1}]",m_params.runMin,m_params.runMax);
grabber.SetSearchParams(binary_dir, "", ".tar.gz",0,1000);
std::string rawfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
CompassRun converter(m_params);
converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion...");
for(int i=m_rmin; i<=m_rmax; i++)
for(int i=m_params.runMin; i<=m_params.runMax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
@ -190,13 +186,13 @@ namespace EventBuilder {
void EVBApp::MergeROOTFiles()
{
std::string merge_file = m_workspace+"/merged/run_"+std::to_string(m_rmin)+"_"+std::to_string(m_rmax)+".root";
std::string file_dir = m_workspace+"/analyzed/";
EVB_INFO("Merging ROOT files into single file for runs in range [{0}, {1}]", m_rmin, m_rmax);
std::string merge_file = m_params.workspaceDir+"/merged/run_"+std::to_string(m_params.runMin)+"_"+std::to_string(m_params.runMax)+".root";
std::string file_dir = m_params.workspaceDir.string()+"/analyzed/";
EVB_INFO("Merging ROOT files into single file for runs in range [{0}, {1}]", m_params.runMin, m_params.runMax);
EVB_INFO("Merged file will be named {0}", merge_file);
std::string prefix = "";
std::string suffix = ".root";
grabber.SetSearchParams(file_dir, prefix, suffix,m_rmin,m_rmax);
grabber.SetSearchParams(file_dir, prefix, suffix,m_params.runMin,m_params.runMax);
EVB_INFO("Starting merge...");
if(!grabber.Merge_TChain(merge_file))
{
@ -209,26 +205,24 @@ namespace EventBuilder {
void EVBApp::Convert2SortedRoot()
{
int sys_return;
std::string sortroot_dir = m_workspace+"/sorted/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
EVB_INFO("Converting binary archives to event built ROOT files over run range [{0}, {1}]",m_rmin,m_rmax);
std::string sortroot_dir = m_params.workspaceDir+"/sorted/";
std::string unpack_dir = m_params.workspaceDir+"/temp_binary/";
std::string binary_dir = m_params.workspaceDir+"/raw_binary/";
EVB_INFO("Converting binary archives to event built ROOT files over run range [{0}, {1}]",m_params.runMin,m_params.runMax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_params.runMin,m_params.runMax);
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
CompassRun converter(m_params);
converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion...");
int count=0;
for(int i=m_rmin; i<= m_rmax; i++)
for(int i=m_params.runMin; i<= m_params.runMax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
@ -241,7 +235,7 @@ namespace EventBuilder {
wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str());
converter.Convert2SortedRoot(sortfile, m_mapfile, m_SlowWindow);
converter.Convert2SortedRoot(sortfile);
sys_return = system(wipe_command.c_str());
count++;
}
@ -253,25 +247,23 @@ namespace EventBuilder {
void EVBApp::Convert2FastSortedRoot() {
int sys_return;
std::string sortroot_dir = m_workspace+"/fast/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
EVB_INFO("Converting binary archives to fast event built ROOT files over run range [{0}, {1}]",m_rmin,m_rmax);
std::string sortroot_dir = m_params.workspaceDir+"/fast/";
std::string unpack_dir = m_params.workspaceDir+"/temp_binary/";
std::string binary_dir = m_params.workspaceDir+"/raw_binary/";
EVB_INFO("Converting binary archives to fast event built ROOT files over run range [{0}, {1}]",m_params.runMin,m_params.runMax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_params.runMin,m_params.runMax);
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
CompassRun converter(m_params);
converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion...");
int count=0;
for(int i=m_rmin; i<=m_rmax; i++)
for(int i=m_params.runMin; i<=m_params.runMax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
@ -284,7 +276,7 @@ namespace EventBuilder {
wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str());
converter.Convert2FastSortedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh);
converter.Convert2FastSortedRoot(sortfile);
sys_return = system(wipe_command.c_str());
count++;
}
@ -296,25 +288,23 @@ namespace EventBuilder {
void EVBApp::Convert2SlowAnalyzedRoot() {
int sys_return;
std::string sortroot_dir = m_workspace+"/analyzed/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
EVB_INFO("Converting binary archives to analyzed event built ROOT files over run range [{0}, {1}]",m_rmin,m_rmax);
std::string sortroot_dir = m_params.workspaceDir+"/analyzed/";
std::string unpack_dir = m_params.workspaceDir+"/temp_binary/";
std::string binary_dir = m_params.workspaceDir+"/raw_binary/";
EVB_INFO("Converting binary archives to analyzed event built ROOT files over run range [{0}, {1}]",m_params.runMin,m_params.runMax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin, m_rmax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_params.runMin, m_params.runMax);
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
CompassRun converter(m_params);
converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion...");
int count=0;
for(int i=m_rmin; i<=m_rmax; i++)
for(int i=m_params.runMin; i<=m_params.runMax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
@ -327,7 +317,7 @@ namespace EventBuilder {
wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str());
converter.Convert2SlowAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta);
converter.Convert2SlowAnalyzedRoot(sortfile);
sys_return = system(wipe_command.c_str());
count++;
}
@ -340,25 +330,23 @@ namespace EventBuilder {
void EVBApp::Convert2FastAnalyzedRoot()
{
int sys_return;
std::string sortroot_dir = m_workspace+"/analyzed/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
EVB_INFO("Converting binary archives to analyzed fast event built ROOT files over run range [{0}, {1}]",m_rmin,m_rmax);
std::string sortroot_dir = m_params.workspaceDir+"/analyzed/";
std::string unpack_dir = m_params.workspaceDir+"/temp_binary/";
std::string binary_dir = m_params.workspaceDir+"/raw_binary/";
EVB_INFO("Converting binary archives to analyzed fast event built ROOT files over run range [{0}, {1}]",m_params.runMin,m_params.runMax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_params.runMin,m_params.runMax);
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
CompassRun converter(m_params);
converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion...");
int count=0;
for(int i=m_rmin; i<=m_rmax; i++)
for(int i=m_params.runMin; i<=m_params.runMax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
@ -371,7 +359,7 @@ namespace EventBuilder {
wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str());
converter.Convert2FastAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta);
converter.Convert2FastAnalyzedRoot(sortfile);
sys_return = system(wipe_command.c_str());
count++;
}
@ -380,35 +368,5 @@ namespace EventBuilder {
else
EVB_INFO("Conversion complete.");
}
bool EVBApp::SetKinematicParameters(int zt, int at, int zp, int ap, int ze, int ae, double b, double theta, double bke)
{
if((at + ap - ae) < 0 || (zt + zp - ze) < 0)
{
EVB_WARN("Invalid kinematic parameters, nucleon number not conserved! Parameters not set");
return false;
}
m_ZT = zt; m_AT = at; m_ZP = zp; m_AP = ap; m_ZE = ze; m_AE = ae;
m_B = b; m_Theta = theta; m_BKE = bke;
m_ZR = (zt + zp - ze);
m_AR = (at + ap - ae);
EVB_TRACE("Kinematic paramters updated.");
return true;
}
void EVBApp::SetRunRange(int rmin, int rmax) { EVB_TRACE("Min Run, max run set to [{0}, {1}]", rmin, rmax); m_rmin = rmin; m_rmax = rmax; }
void EVBApp::SetWorkDirectory(const std::string& fullpath) { EVB_TRACE("Workspace set to {0}", fullpath); m_workspace = fullpath; }
void EVBApp::SetChannelMap(const std::string& name) { EVB_TRACE("Channel map set to {0}",name); m_mapfile = name; }
void EVBApp::SetBoardShiftFile(const std::string& name) { EVB_TRACE("Shift file set to {0}", name); m_shiftfile = name; }
void EVBApp::SetSlowCoincidenceWindow(double window) { EVB_TRACE("Slow Coincidence Window set to {0}",window); m_SlowWindow = window; }
void EVBApp::SetFastWindowIonChamber(double window) { EVB_TRACE("Fast Coinc. Window Ion Ch. set to {0}",window); m_FastWindowIonCh = window; }
void EVBApp::SetFastWindowSABRE(double window) { EVB_TRACE("Fast Coinc. Window SABRE set to {0}",window); m_FastWindowSABRE = window; }
void EVBApp::SetCutList(const std::string& name) { EVB_TRACE("Cut List set to {0}", name); m_cutList = name; }
void EVBApp::SetScalerFile(const std::string& fullpath) { EVB_TRACE("Scaler file set to {0}", fullpath); m_scalerfile = fullpath; }
}

View File

@ -13,6 +13,33 @@
#include "ProgressCallback.h"
namespace EventBuilder {
struct EVBParameters
{
std::filesystem::path workspaceDir = "";
std::filesystem::path channelMapFile = "";
std::filesystem::path timeShiftFile = "";
std::filesystem::path cutListFile = "";
std::filesystem::path scalerFile = "";
int runMin = 0;
int runMax = 0;
double slowCoincidenceWindow = 3.0e6;
double fastCoincidenceWindowIonCh = 0.0;
double fastCoincidenceWindowSABRE = 0.0;
int ZT = 6;
int AT = 12;
int ZP = 1;
int AP = 2;
int ZE = 1;
int AE = 1;
double BField = 7.8; //kG
double spsAngle = 15.0; //degrees
double beamEnergy = 16.0; //MeV
};
class EVBApp {
public:
@ -31,38 +58,8 @@ namespace EventBuilder {
void Convert2SlowAnalyzedRoot();
void Convert2FastAnalyzedRoot();
void SetRunRange(int rmin, int rmax);
void SetWorkDirectory(const std::string& fullpath);
void SetChannelMap(const std::string& name);
void SetBoardShiftFile(const std::string& name);
void SetSlowCoincidenceWindow(double window);
void SetFastWindowIonChamber(double window);
void SetFastWindowSABRE(double window);
void SetCutList(const std::string& name);
void SetScalerFile(const std::string& fullpath);
bool SetKinematicParameters(int zt, int at, int zp, int ap, int ze, int ae, double b, double theta, double bke);
inline int GetRunMin() const { return m_rmin; }
inline int GetRunMax() const { return m_rmax; }
inline std::string GetWorkDirectory() const { return m_workspace; }
inline int GetTargetZ() const { return m_ZT; }
inline int GetTargetA() const { return m_AT; }
inline int GetProjectileZ() const { return m_ZP; }
inline int GetProjectileA() const { return m_AP; }
inline int GetEjectileZ() const { return m_ZE; }
inline int GetEjectileA() const { return m_AE; }
inline int GetResidualZ() const { return m_ZR; }
inline int GetResidualA() const { return m_AR; }
inline double GetBField() const { return m_B; }
inline double GetBeamKE() const { return m_BKE; }
inline double GetTheta() const { return m_Theta; }
inline double GetSlowCoincidenceWindow() const { return m_SlowWindow; }
inline double GetFastWindowIonChamber() const { return m_FastWindowIonCh; }
inline double GetFastWindowSABRE() const { return m_FastWindowSABRE; }
inline std::string GetChannelMap() const { return m_mapfile; }
inline std::string GetBoardShiftFile() const { return m_shiftfile; }
inline std::string GetCutList() const { return m_cutList; }
inline std::string GetScalerFile() const { return m_scalerfile; }
inline void SetParameters(const EVBParameters& params) { m_params = params; }
inline EVBParameters& GetParameters() { return m_params; }
void DefaultProgressCallback(long curVal, long totalVal);
inline void SetProgressCallbackFunc(const ProgressCallbackFunc& function) { m_progressCallback = function; }
@ -80,23 +77,9 @@ namespace EventBuilder {
};
private:
int m_rmin, m_rmax;
int m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_ZR, m_AR;
double m_B, m_Theta, m_BKE;
double m_progressFraction;
std::string m_workspace;
std::string m_mapfile, m_shiftfile;
std::string m_cutList;
std::string m_scalerfile;
double m_SlowWindow;
double m_FastWindowIonCh;
double m_FastWindowSABRE;
EVBParameters m_params;
RunCollector grabber;
double m_progressFraction;
ProgressCallbackFunc m_progressCallback;
};

118
src/evb/EVBWorkspace.cpp Normal file
View File

@ -0,0 +1,118 @@
#include "EVBWorkspace.h"
namespace EventBuilder {
static bool CheckSubDirectory(const std::filesystem::path& path)
{
bool status = true;
EVB_TRACE("Checking subdirectory {0}", path);
if(!std::filesystem::exists(path))
{
status = std::filesystem::create_directory(path);
if(!status)
{
EVB_ERROR("Unable to create subdirectory {0}. Please check the pathing.", path.string());
return status;
}
EVB_INFO("Created subdirectory {0}", path);
}
else
EVB_INFO("Found subdirectory {0}", path);
return status;
}
EVBWorkspace::EVBWorkspace(const std::filesystem::path& workspace) :
m_isValid(false), m_workspace(workspace)
{
Init();
}
EVBWorkspace::~EVBWorkspace() {}
void EVBWorkspace::Init()
{
m_isValid = true;
if(!std::filesystem::exists(m_workspace))
{
EVB_TRACE("Workspace {0} does not exist. Attempting to create the workspace directory...", m_workspace.string());
m_isValid = std::filesystem::create_directory(m_workspace);
if(!m_isValid)
{
EVB_ERROR("Unable to create workspace {0}. Please check the pathing.", m_workspace.string());
return;
}
EVB_INFO("Created workspace directory {0}.", m_workspace.string());
}
else
EVB_INFO("Found workspace directory {0}.", m_workspace.string());
EVB_TRACE("Looking for required workspace subdirectories...");
m_binaryDir = m_workspace / "raw_binary";
m_tempDir = m_workspace / "temp_binary";
m_sortedDir = m_workspace / "sorted";
m_builtDir = m_workspace / "built";
m_analyzedDir = m_workspace / "analyzed";
m_histogramDir = m_workspace / "histograms";
m_cutDir = m_workspace / "cuts";
//Check all subdirectories. Terminate if any of them are bad
m_isValid = CheckSubDirectory(m_binaryDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_tempDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_sortedDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_builtDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_analyzedDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_histogramDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_cutDir);
}
std::string EVBWorkspace::GetBinaryRun(int run)
{
std::string file;
std::string runID = "run_" + std::to_string(run) + ".tar.gz";
for(auto& entry : std::filesystem::directory_iterator(m_binaryDir))
{
if(entry.is_regular_file() && entry.path().filename().string() == runID)
{
return entry.path().string();
}
}
return "";
}
std::vector<std::string> EVBWorkspace::GetBinaryRunRange(int runMin, int runMax)
{
std::vector<std::string> 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<std::string> EVBWorkspace::GetTempFiles()
{
std::vector<std::string> 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;
}
}

42
src/evb/EVBWorkspace.h Normal file
View File

@ -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<std::string> GetBinaryRunRange(int runMin, int runMax);
std::string GetBinaryRun(int run);
std::vector<std::string> 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