Big update. Finish implementation of EVBWorkspace. Remove unnecessary includes. Note that std::filesystem clashes with ROOT GUI libs.

This commit is contained in:
Gordon McCann 2022-07-13 10:26:37 -04:00
parent 22c1647ab1
commit 8ecfe5e3f8
28 changed files with 427 additions and 373 deletions

View File

@ -1,4 +1,3 @@
Format: scaler_param_name assoc_binary_file_name_without_runID Format: scaler_param_name assoc_binary_file_name_without_runID
NOTE: As of this version, scalers are pure counting parameters (the total events will be counted and saved as a TParameter with the data) NOTE: As of this version, scalers are pure counting parameters (the total events will be counted and saved as a TParameter with the data)
CH0@V1730_89_Data t1 Data_CH5@V1730_89 beamint
CH5@V1730_89_Data t2

View File

@ -1,6 +1,6 @@
add_subdirectory(spsdict) add_subdirectory(spsdict)
add_subdirectory(guidict)
add_subdirectory(evb) add_subdirectory(evb)
add_subdirectory(guidict)
add_executable(EventBuilder) add_executable(EventBuilder)

View File

@ -10,8 +10,6 @@
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <cstdint> #include <cstdint>
#include <filesystem>
//ROOT //ROOT
#include <TROOT.h> #include <TROOT.h>

View File

@ -44,6 +44,7 @@ target_sources(EventBuilderCore PRIVATE
SlowSort.h SlowSort.h
EVBWorkspace.cpp EVBWorkspace.cpp
EVBWorkspace.h EVBWorkspace.h
EVBParameters.h
) )
target_link_libraries(EventBuilderCore PUBLIC target_link_libraries(EventBuilderCore PUBLIC

View File

@ -6,7 +6,6 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include "ChannelMap.h" #include "ChannelMap.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -8,7 +8,6 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include "CompassFile.h" #include "CompassFile.h"
namespace EventBuilder { namespace EventBuilder {
@ -44,7 +43,6 @@ namespace EventBuilder {
m_hitUsedFlag = true; m_hitUsedFlag = true;
m_filename = filename; m_filename = filename;
m_file->open(m_filename, std::ios::binary | std::ios::in); m_file->open(m_filename, std::ios::binary | std::ios::in);
m_file->seekg(0, std::ios_base::end); m_file->seekg(0, std::ios_base::end);
m_size = m_file->tellg(); m_size = m_file->tellg();
if(m_size == 2) if(m_size == 2)

View File

@ -9,9 +9,7 @@
Updated to also handle scaler data. -- GWM Oct. 2020 Updated to also handle scaler data. -- GWM Oct. 2020
*/ */
#include "EventBuilder.h"
#include "CompassRun.h" #include "CompassRun.h"
#include "RunCollector.h"
#include "SlowSort.h" #include "SlowSort.h"
#include "FastSort.h" #include "FastSort.h"
#include "SFPAnalyzer.h" #include "SFPAnalyzer.h"
@ -20,10 +18,10 @@
namespace EventBuilder { namespace EventBuilder {
CompassRun::CompassRun(const EVBParameters& params) : CompassRun::CompassRun(const EVBParameters& params, const std::shared_ptr<EVBWorkspace>& workspace) :
m_params(params) m_params(params), m_workspace(workspace)
{ {
m_tempDir = m_params.workspaceDir / "temp_binary"; m_smap.SetFile(m_params.timeShiftFile);
} }
CompassRun::~CompassRun() {} CompassRun::~CompassRun() {}
@ -45,7 +43,7 @@ namespace EventBuilder {
while(input>>filename) while(input>>filename)
{ {
input>>varname; input>>varname;
filename = m_tempDir.string()+filename+"_run_"+std::to_string(m_runNum)+".BIN"; filename = m_workspace->GetTempDir()+filename+"_run_"+std::to_string(m_runNum)+".BIN";
m_scaler_map[filename] = TParameter<Long64_t>(varname.c_str(), init); m_scaler_map[filename] = TParameter<Long64_t>(varname.c_str(), init);
} }
input.close(); input.close();
@ -53,17 +51,14 @@ namespace EventBuilder {
bool CompassRun::GetBinaryFiles() bool CompassRun::GetBinaryFiles()
{ {
std::string prefix = ""; auto files = m_workspace->GetTempFiles();
std::string suffix = ".BIN"; //binaries
RunCollector grabber(m_directory, prefix, suffix);
grabber.GrabAllFiles();
m_datafiles.clear(); //so that the CompassRun can be reused m_datafiles.clear(); //so that the CompassRun can be reused
m_datafiles.reserve(grabber.GetFileList().size()); m_datafiles.reserve(files.size()); //NOTE: This line is mandatory. We need the memory preallocated to avoid any move semantics with the filestreams.
bool scalerd; bool scalerd;
m_totalHits = 0; //reset total run size m_totalHits = 0; //reset total run size
for(auto& entry : grabber.GetFileList()) for(auto& entry : files)
{ {
//Handle scaler files, if they exist //Handle scaler files, if they exist
if(m_scaler_flag) if(m_scaler_flag)
@ -133,8 +128,9 @@ namespace EventBuilder {
for(unsigned int i=startIndex; i<m_datafiles.size(); i++) for(unsigned int i=startIndex; i<m_datafiles.size(); i++)
{ {
if(m_datafiles[i].CheckHitHasBeenUsed()) if(m_datafiles[i].CheckHitHasBeenUsed())
{
m_datafiles[i].GetNextHit(); m_datafiles[i].GetNextHit();
}
if(m_datafiles[i].IsEOF()) if(m_datafiles[i].IsEOF())
{ {
if(i == startIndex) if(i == startIndex)
@ -259,7 +255,8 @@ namespace EventBuilder {
{ {
event = coincidizer.GetEvent(); event = coincidizer.GetEvent();
outtree->Fill(); outtree->Fill();
if(killFlag) break; if(killFlag)
break;
} }
} }

View File

@ -12,20 +12,19 @@
#include "CompassFile.h" #include "CompassFile.h"
#include "DataStructs.h" #include "DataStructs.h"
#include "RunCollector.h"
#include "ShiftMap.h" #include "ShiftMap.h"
#include "ProgressCallback.h" #include "ProgressCallback.h"
#include "EVBWorkspace.h"
#include "EVBParameters.h"
#include <TParameter.h> #include <TParameter.h>
namespace EventBuilder { namespace EventBuilder {
struct EVBParameters; //Foward decl to avoid recursive includes
class CompassRun class CompassRun
{ {
public: public:
CompassRun(const EVBParameters& params); CompassRun(const EVBParameters& params, const std::shared_ptr<EVBWorkspace>& workspace);
~CompassRun(); ~CompassRun();
inline void SetRunNumber(int n) { m_runNum = n; } inline void SetRunNumber(int n) { m_runNum = n; }
void Convert2RawRoot(const std::string& name); void Convert2RawRoot(const std::string& name);
@ -44,7 +43,7 @@ namespace EventBuilder {
void ReadScalerData(const std::string& filename); void ReadScalerData(const std::string& filename);
EVBParameters m_params; EVBParameters m_params;
std::filesystem::path m_tempDir; std::shared_ptr<EVBWorkspace> m_workspace;
std::vector<CompassFile> m_datafiles; std::vector<CompassFile> m_datafiles;
unsigned int startIndex; //this is the file we start looking at; increases as we finish files. unsigned int startIndex; //this is the file we start looking at; increases as we finish files.

View File

@ -1,4 +1,3 @@
#include "EventBuilder.h"
#include "CutHandler.h" #include "CutHandler.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -6,20 +6,15 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include <cstdlib> #include <cstdlib>
#include "EVBApp.h" #include "EVBApp.h"
#include "RunCollector.h"
#include "CompassRun.h" #include "CompassRun.h"
#include "SlowSort.h"
#include "FastSort.h"
#include "SFPAnalyzer.h"
#include "SFPPlotter.h" #include "SFPPlotter.h"
namespace EventBuilder { namespace EventBuilder {
EVBApp::EVBApp() : EVBApp::EVBApp() :
m_progressFraction(0.1) m_workspace(nullptr), m_progressFraction(0.1)
{ {
SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBApp::DefaultProgressCallback)); SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBApp::DefaultProgressCallback));
} }
@ -34,6 +29,18 @@ namespace EventBuilder {
EVB_INFO("Percent of run built: {0}", fraction*100); EVB_INFO("Percent of run built: {0}", fraction*100);
} }
void EVBApp::SetParameters(const EVBParameters& params)
{
if(m_params.workspaceDir != params.workspaceDir)
{
m_workspace.reset(new EVBWorkspace(params.workspaceDir));
if(!m_workspace->IsValid())
EVB_ERROR("Unable to process new parameters due to bad workspace");
}
m_params = params;
}
bool EVBApp::ReadConfigFile(const std::string& fullpath) bool EVBApp::ReadConfigFile(const std::string& fullpath)
{ {
EVB_INFO("Reading in EVB configuration from file {0}...", fullpath); EVB_INFO("Reading in EVB configuration from file {0}...", fullpath);
@ -47,6 +54,12 @@ namespace EventBuilder {
std::getline(input, junk); std::getline(input, junk);
input>>junk>>m_params.workspaceDir; input>>junk>>m_params.workspaceDir;
m_workspace.reset(new EVBWorkspace(m_params.workspaceDir)); //frees underlying and sets to new pointer
if(!m_workspace->IsValid())
{
EVB_ERROR("Unable to process input configuration due to bad workspace.");
return false;
}
input>>junk; input>>junk;
std::getline(input, junk); std::getline(input, junk);
std::getline(input, junk); std::getline(input, junk);
@ -126,8 +139,12 @@ namespace EventBuilder {
void EVBApp::PlotHistograms() void EVBApp::PlotHistograms()
{ {
std::string analyze_dir = m_params.workspaceDir+"/analyzed/"; if(m_workspace == nullptr || !m_workspace->IsValid())
std::string plot_file = m_params.workspaceDir+"/histograms/run_"+std::to_string(m_params.runMin)+"_"+std::to_string(m_params.runMax)+".root"; {
EVB_ERROR("Unable to preform event building request due to bad workspace.");
}
std::string plot_file = m_workspace->GetHistogramDir()+"run_"+std::to_string(m_params.runMin)+"_"+std::to_string(m_params.runMax)+".root";
SFPPlotter grammer; SFPPlotter grammer;
grammer.SetProgressCallbackFunc(m_progressCallback); grammer.SetProgressCallbackFunc(m_progressCallback);
grammer.SetProgressFraction(m_progressFraction); grammer.SetProgressFraction(m_progressFraction);
@ -135,10 +152,10 @@ namespace EventBuilder {
EVB_INFO("Generating histograms from analyzed runs [{0}, {1}] with Cut List {2}...", m_params.runMin, m_params.runMax, 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); EVB_INFO("Output file will be named {0}",plot_file);
grabber.SetSearchParams(analyze_dir, "", ".root", m_params.runMin, m_params.runMax); auto files = m_workspace->GetAnalyzedRunRange(m_params.runMin, m_params.runMax);
if(grabber.GrabFilesInRange()) if(files.size() > 0)
{ {
grammer.Run(grabber.GetFileList(), plot_file); grammer.Run(files, plot_file);
EVB_INFO("Finished."); EVB_INFO("Finished.");
} }
else else
@ -149,54 +166,56 @@ namespace EventBuilder {
void EVBApp::Convert2RawRoot() void EVBApp::Convert2RawRoot()
{ {
int sys_return; if(m_workspace == nullptr || !m_workspace->IsValid())
std::string rawroot_dir = m_params.workspaceDir+"/raw_root/"; {
std::string unpack_dir = m_params.workspaceDir+"/temp_binary/"; EVB_ERROR("Unable to preform event building request due to bad workspace.");
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 rawroot_dir = m_workspace->GetSortedDir();
EVB_INFO("Converting binary archives to ROOT files over run range [{0}, {1}]", m_params.runMin, m_params.runMax);
std::string rawfile, binfile; std::string rawfile;
std::string unpack_command, wipe_command;
CompassRun converter(m_params); CompassRun converter(m_params, m_workspace);
converter.SetProgressCallbackFunc(m_progressCallback); converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction); converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion..."); EVB_INFO("Beginning conversion...");
int count = 0;
for(int i=m_params.runMin; i<=m_params.runMax; i++) for(int i=m_params.runMin; i<=m_params.runMax; i++)
{ {
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
EVB_INFO("Converting file {0}...", binfile);
rawfile = rawroot_dir + "compass_run_"+ std::to_string(i) + ".root"; rawfile = rawroot_dir + "compass_run_"+ std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir; EVB_INFO("Converting file {0}...", rawfile);
wipe_command = "rm -r "+unpack_dir+"*.BIN"; m_workspace->ClearTempDirectory(); //In case something weird happened
if(m_workspace->UnpackBinaryRunToTemp(i))
sys_return = system(unpack_command.c_str()); {
converter.SetRunNumber(i);
converter.Convert2RawRoot(rawfile); converter.Convert2RawRoot(rawfile);
sys_return = system(wipe_command.c_str()); ++count;
} }
m_workspace->ClearTempDirectory();
}
if(count != 0)
EVB_INFO("Conversion complete."); EVB_INFO("Conversion complete.");
else
EVB_WARN("Nothing converted, no files found in the range [{0}, {1}]", m_params.runMin, m_params.runMax);
} }
void EVBApp::MergeROOTFiles() void EVBApp::MergeROOTFiles()
{ {
std::string merge_file = m_params.workspaceDir+"/merged/run_"+std::to_string(m_params.runMin)+"_"+std::to_string(m_params.runMax)+".root"; if(m_workspace == nullptr || !m_workspace->IsValid())
std::string file_dir = m_params.workspaceDir.string()+"/analyzed/"; {
EVB_ERROR("Unable to preform event building request due to bad workspace.");
}
std::string merge_file = m_workspace->GetMergedDir()+"run_"+std::to_string(m_params.runMin)+"_"+std::to_string(m_params.runMax)+".root";
EVB_INFO("Merging ROOT files into single file for runs in range [{0}, {1}]", m_params.runMin, m_params.runMax); 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); EVB_INFO("Merged file will be named {0}", merge_file);
std::string prefix = "";
std::string suffix = ".root";
grabber.SetSearchParams(file_dir, prefix, suffix,m_params.runMin,m_params.runMax);
EVB_INFO("Starting merge..."); EVB_INFO("Starting merge...");
if(!grabber.Merge_TChain(merge_file)) if(!m_workspace->MergeAnalyzedFiles(merge_file, m_params.runMin, m_params.runMax))
{ {
EVB_ERROR("Unable to find files for merge at EVBApp::MergeROOTFiles()!"); EVB_ERROR("Unable to merge at EVBApp::MergeROOTFiles()!");
return; return;
} }
EVB_INFO("Finished."); EVB_INFO("Finished.");
@ -204,169 +223,157 @@ namespace EventBuilder {
void EVBApp::Convert2SortedRoot() void EVBApp::Convert2SortedRoot()
{ {
int sys_return; if(m_workspace == nullptr || !m_workspace->IsValid())
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_params.runMin,m_params.runMax);
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(m_params);
converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion...");
int count=0;
for(int i=m_params.runMin; i<= m_params.runMax; i++)
{ {
binfile = grabber.GrabFile(i); EVB_ERROR("Unable to preform event building request due to bad workspace.");
if(binfile == "")
continue;
converter.SetRunNumber(i);
EVB_INFO("Converting file {0}...",binfile);
sortfile = sortroot_dir +"run_"+std::to_string(i)+ ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str());
converter.Convert2SortedRoot(sortfile);
sys_return = system(wipe_command.c_str());
count++;
}
if(count==0)
EVB_WARN("Conversion failed, no archives were found!");
else
EVB_INFO("Conversion complete.");
} }
void EVBApp::Convert2FastSortedRoot() { std::string sortroot_dir = m_workspace->GetBuiltDir();
int sys_return; EVB_INFO("Converting binary archives to event built ROOT files over run range [{0}, {1}]", m_params.runMin, m_params.runMax);
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_params.runMin,m_params.runMax); std::string sortfile;
std::string sortfile, binfile; CompassRun converter(m_params, m_workspace);
std::string unpack_command, wipe_command;
CompassRun converter(m_params);
converter.SetProgressCallbackFunc(m_progressCallback); converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction); converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion..."); EVB_INFO("Beginning conversion...");
int count=0; int count = 0;
for(int i=m_params.runMin; i<=m_params.runMax; i++) for(int i=m_params.runMin; i<=m_params.runMax; i++)
{ {
binfile = grabber.GrabFile(i); sortfile = sortroot_dir + "run_"+ std::to_string(i) + ".root";
if(binfile == "") EVB_INFO("Converting file {0}...", sortfile);
continue; m_workspace->ClearTempDirectory(); //In case something weird happened
if(m_workspace->UnpackBinaryRunToTemp(i))
{
converter.SetRunNumber(i); converter.SetRunNumber(i);
EVB_INFO("Converting file {0}...",binfile); converter.Convert2SortedRoot(sortfile);
EVB_INFO("Finished converting");
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root"; ++count;
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str());
converter.Convert2FastSortedRoot(sortfile);
sys_return = system(wipe_command.c_str());
count++;
} }
if(count==0) m_workspace->ClearTempDirectory();
EVB_WARN("Conversion failed, no archives were found!"); }
else
if(count != 0)
EVB_INFO("Conversion complete."); EVB_INFO("Conversion complete.");
else
EVB_WARN("Nothing converted, no files found in the range [{0}, {1}]", m_params.runMin, m_params.runMax);
} }
void EVBApp::Convert2SlowAnalyzedRoot() { void EVBApp::Convert2FastSortedRoot()
int sys_return; {
std::string sortroot_dir = m_params.workspaceDir+"/analyzed/"; if(m_workspace == nullptr || !m_workspace->IsValid())
std::string unpack_dir = m_params.workspaceDir+"/temp_binary/"; {
std::string binary_dir = m_params.workspaceDir+"/raw_binary/"; EVB_ERROR("Unable to preform event building request due to bad workspace.");
}
std::string sortroot_dir = m_workspace->GetBuiltDir();
EVB_INFO("Converting binary archives to fast event built ROOT files over run range [{0}, {1}]", m_params.runMin, m_params.runMax);
std::string sortfile;
CompassRun converter(m_params, m_workspace);
converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion...");
int count = 0;
for(int i=m_params.runMin; i<=m_params.runMax; i++)
{
sortfile = sortroot_dir + "run_"+ std::to_string(i) + ".root";
EVB_INFO("Converting file {0}...", sortfile);
m_workspace->ClearTempDirectory(); //In case something weird happened
if(m_workspace->UnpackBinaryRunToTemp(i))
{
converter.SetRunNumber(i);
converter.Convert2FastSortedRoot(sortfile);
++count;
}
m_workspace->ClearTempDirectory();
}
if(count != 0)
EVB_INFO("Conversion complete.");
else
EVB_WARN("Nothing converted, no files found in the range [{0}, {1}]", m_params.runMin, m_params.runMax);
}
void EVBApp::Convert2SlowAnalyzedRoot()
{
if(m_workspace == nullptr || !m_workspace->IsValid())
{
EVB_ERROR("Unable to preform event building request due to bad workspace.");
}
std::string sortroot_dir = m_workspace->GetAnalyzedDir();
EVB_INFO("Converting binary archives to analyzed event built ROOT files over run range [{0}, {1}]",m_params.runMin,m_params.runMax); 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_params.runMin, m_params.runMax); std::string sortfile;
std::string sortfile, binfile; CompassRun converter(m_params, m_workspace);
std::string unpack_command, wipe_command;
CompassRun converter(m_params);
converter.SetProgressCallbackFunc(m_progressCallback); converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction); converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion..."); EVB_INFO("Beginning conversion...");
int count=0; int count = 0;
for(int i=m_params.runMin; i<=m_params.runMax; i++) for(int i=m_params.runMin; i<=m_params.runMax; i++)
{ {
binfile = grabber.GrabFile(i); sortfile = sortroot_dir + "run_"+ std::to_string(i) + ".root";
if(binfile == "") EVB_INFO("Converting file {0}...", sortfile);
continue; m_workspace->ClearTempDirectory(); //In case something weird happened
if(m_workspace->UnpackBinaryRunToTemp(i))
{
converter.SetRunNumber(i); converter.SetRunNumber(i);
EVB_INFO("Converting file {0}...",binfile);
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str());
converter.Convert2SlowAnalyzedRoot(sortfile); converter.Convert2SlowAnalyzedRoot(sortfile);
sys_return = system(wipe_command.c_str()); ++count;
count++;
} }
if(count==0) m_workspace->ClearTempDirectory();
EVB_WARN("Conversion failed, no archives were found!"); }
else
if(count != 0)
EVB_INFO("Conversion complete."); EVB_INFO("Conversion complete.");
else
EVB_WARN("Nothing converted, no files found in the range [{0}, {1}]", m_params.runMin, m_params.runMax);
} }
void EVBApp::Convert2FastAnalyzedRoot() void EVBApp::Convert2FastAnalyzedRoot()
{ {
int sys_return; if(m_workspace == nullptr || !m_workspace->IsValid())
std::string sortroot_dir = m_params.workspaceDir+"/analyzed/"; {
std::string unpack_dir = m_params.workspaceDir+"/temp_binary/"; EVB_ERROR("Unable to preform event building request due to bad workspace.");
std::string binary_dir = m_params.workspaceDir+"/raw_binary/"; }
std::string sortroot_dir = m_workspace->GetAnalyzedDir();
EVB_INFO("Converting binary archives to analyzed fast event built ROOT files over run range [{0}, {1}]",m_params.runMin,m_params.runMax); 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_params.runMin,m_params.runMax);
std::string sortfile, binfile; std::string sortfile;
std::string unpack_command, wipe_command;
CompassRun converter(m_params); CompassRun converter(m_params, m_workspace);
converter.SetProgressCallbackFunc(m_progressCallback); converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction); converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion..."); EVB_INFO("Beginning conversion...");
int count=0; int count = 0;
for(int i=m_params.runMin; i<=m_params.runMax; i++) for(int i=m_params.runMin; i<=m_params.runMax; i++)
{ {
binfile = grabber.GrabFile(i); sortfile = sortroot_dir + "run_"+ std::to_string(i) + ".root";
if(binfile == "") EVB_INFO("Converting file {0}...", sortfile);
continue; m_workspace->ClearTempDirectory(); //In case something weird happened
if(m_workspace->UnpackBinaryRunToTemp(i))
{
converter.SetRunNumber(i); converter.SetRunNumber(i);
EVB_INFO("Converting file {0}...",binfile);
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str());
converter.Convert2FastAnalyzedRoot(sortfile); converter.Convert2FastAnalyzedRoot(sortfile);
sys_return = system(wipe_command.c_str()); ++count;
count++;
} }
if(count==0) m_workspace->ClearTempDirectory();
EVB_WARN("Conversion failed, no archives were found!"); }
else
if(count != 0)
EVB_INFO("Conversion complete."); EVB_INFO("Conversion complete.");
else
EVB_WARN("Nothing converted, no files found in the range [{0}, {1}]", m_params.runMin, m_params.runMax);
} }
} }

View File

@ -9,38 +9,12 @@
#ifndef EVBAPP_H #ifndef EVBAPP_H
#define EVBAPP_H #define EVBAPP_H
#include "RunCollector.h" #include "EVBParameters.h"
#include "EVBWorkspace.h"
#include "ProgressCallback.h" #include "ProgressCallback.h"
namespace EventBuilder { 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 { class EVBApp {
public: public:
@ -52,13 +26,13 @@ namespace EventBuilder {
void PlotHistograms(); void PlotHistograms();
void MergeROOTFiles(); void MergeROOTFiles();
void Convert2RawRoot();
void Convert2SortedRoot(); void Convert2SortedRoot();
void Convert2FastSortedRoot(); void Convert2FastSortedRoot();
void Convert2RawRoot();
void Convert2SlowAnalyzedRoot(); void Convert2SlowAnalyzedRoot();
void Convert2FastAnalyzedRoot(); void Convert2FastAnalyzedRoot();
inline void SetParameters(const EVBParameters& params) { m_params = params; } void SetParameters(const EVBParameters& params);
inline EVBParameters& GetParameters() { return m_params; } inline EVBParameters& GetParameters() { return m_params; }
void DefaultProgressCallback(long curVal, long totalVal); void DefaultProgressCallback(long curVal, long totalVal);
@ -78,7 +52,7 @@ namespace EventBuilder {
private: private:
EVBParameters m_params; EVBParameters m_params;
RunCollector grabber; std::shared_ptr<EVBWorkspace> m_workspace;
double m_progressFraction; double m_progressFraction;
ProgressCallbackFunc m_progressCallback; ProgressCallbackFunc m_progressCallback;

34
src/evb/EVBParameters.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef EVB_PARAMETERS_H
#define EVB_PARAMETERS_H
namespace EventBuilder {
struct EVBParameters
{
std::string workspaceDir = "";
std::string channelMapFile = "";
std::string timeShiftFile = "";
std::string cutListFile = "";
std::string 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
};
}
#endif

View File

@ -1,8 +1,11 @@
#include "EVBWorkspace.h" #include "EVBWorkspace.h"
#include <filesystem>
#include <TFile.h>
#include <TChain.h>
namespace EventBuilder { namespace EventBuilder {
static bool CheckSubDirectory(const std::filesystem::path& path) static bool CheckSubDirectory(const std::string& path)
{ {
bool status = true; bool status = true;
EVB_TRACE("Checking subdirectory {0}", path); EVB_TRACE("Checking subdirectory {0}", path);
@ -11,7 +14,7 @@ namespace EventBuilder {
status = std::filesystem::create_directory(path); status = std::filesystem::create_directory(path);
if(!status) if(!status)
{ {
EVB_ERROR("Unable to create subdirectory {0}. Please check the pathing.", path.string()); EVB_ERROR("Unable to create subdirectory {0}. Please check the pathing.", path);
return status; return status;
} }
EVB_INFO("Created subdirectory {0}", path); EVB_INFO("Created subdirectory {0}", path);
@ -21,7 +24,7 @@ namespace EventBuilder {
return status; return status;
} }
EVBWorkspace::EVBWorkspace(const std::filesystem::path& workspace) : EVBWorkspace::EVBWorkspace(const std::string& workspace) :
m_isValid(false), m_workspace(workspace) m_isValid(false), m_workspace(workspace)
{ {
Init(); Init();
@ -34,27 +37,27 @@ namespace EventBuilder {
m_isValid = true; m_isValid = true;
if(!std::filesystem::exists(m_workspace)) if(!std::filesystem::exists(m_workspace))
{ {
EVB_TRACE("Workspace {0} does not exist. Attempting to create the workspace directory...", m_workspace.string()); EVB_TRACE("Workspace {0} does not exist. Attempting to create the workspace directory...", m_workspace);
m_isValid = std::filesystem::create_directory(m_workspace); m_isValid = std::filesystem::create_directory(m_workspace);
if(!m_isValid) if(!m_isValid)
{ {
EVB_ERROR("Unable to create workspace {0}. Please check the pathing.", m_workspace.string()); EVB_ERROR("Unable to create workspace {0}. Please check the pathing.", m_workspace);
return; return;
} }
EVB_INFO("Created workspace directory {0}.", m_workspace.string()); EVB_INFO("Created workspace directory {0}.", m_workspace);
} }
else else
EVB_INFO("Found workspace directory {0}.", m_workspace.string()); EVB_INFO("Found workspace directory {0}.", m_workspace);
EVB_TRACE("Looking for required workspace subdirectories..."); EVB_TRACE("Looking for required workspace subdirectories...");
m_binaryDir = m_workspace / "raw_binary"; m_binaryDir = m_workspace + "raw_binary/";
m_tempDir = m_workspace / "temp_binary"; m_tempDir = m_workspace + "temp_binary/";
m_sortedDir = m_workspace / "sorted"; m_sortedDir = m_workspace + "sorted/";
m_builtDir = m_workspace / "built"; m_builtDir = m_workspace + "built/";
m_analyzedDir = m_workspace / "analyzed"; m_analyzedDir = m_workspace + "analyzed/";
m_histogramDir = m_workspace / "histograms"; m_histogramDir = m_workspace + "histograms/";
m_cutDir = m_workspace / "cuts"; m_cutDir = m_workspace + "cuts/";
//Check all subdirectories. Terminate if any of them are bad //Check all subdirectories. Terminate if any of them are bad
m_isValid = CheckSubDirectory(m_binaryDir); m_isValid = CheckSubDirectory(m_binaryDir);
@ -92,6 +95,20 @@ namespace EventBuilder {
return ""; return "";
} }
std::string EVBWorkspace::GetAnalyzedRun(int run)
{
std::string file;
std::string runID = "run_" + std::to_string(run) + ".root";
for(auto& entry : std::filesystem::directory_iterator(m_analyzedDir))
{
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> EVBWorkspace::GetBinaryRunRange(int runMin, int runMax)
{ {
std::vector<std::string> list; std::vector<std::string> list;
@ -104,6 +121,29 @@ namespace EventBuilder {
return list; return list;
} }
std::vector<std::string> EVBWorkspace::GetAnalyzedRunRange(int runMin, int runMax)
{
std::vector<std::string> list;
std::string temp;
for(int run=runMin; run<=runMax; run++)
temp = GetAnalyzedRun(run);
if(!temp.empty())
list.push_back(temp);
return list;
}
bool EVBWorkspace::UnpackBinaryRunToTemp(int run)
{
std::string runfile = GetBinaryRun(run);
std::string unpack_command = "tar -xzf "+runfile+" --directory "+m_tempDir;
int sys_return = system(unpack_command.c_str());
if(sys_return == 0)
return true;
else
return false;
}
std::vector<std::string> EVBWorkspace::GetTempFiles() std::vector<std::string> EVBWorkspace::GetTempFiles()
{ {
std::vector<std::string> list; std::vector<std::string> list;
@ -115,4 +155,50 @@ namespace EventBuilder {
return list; return list;
} }
bool EVBWorkspace::ClearTempDirectory()
{
std::vector<std::filesystem::path> files;
for(auto& entry : std::filesystem::directory_iterator(m_tempDir))
{
if(entry.is_regular_file())
files.push_back(entry.path());
else
EVB_WARN("Detected non-file element in temp directory {0} named {1}", m_tempDir, entry.path().string());
}
for(size_t i=0; i<files.size(); i++)
{
if(!std::filesystem::remove(files[i]))
{
EVB_ERROR("Unable to clear temp directory {0}! File-like entry {1} could not be deleted. Please manually clear the directory.",
m_tempDir, files[i].string());
return false;
}
}
return true;
}
bool EVBWorkspace::MergeAnalyzedFiles(const std::string& outputname, int runMin, int runMax)
{
auto files = GetAnalyzedRunRange(runMin, runMax);
if(files.size() == 0)
return false;
TFile* output = TFile::Open(outputname.c_str(), "RECREATE");
if(!output->IsOpen())
{
EVB_ERROR("Could not open output file {0} for merge", outputname);
output->Close();
return false;
}
TChain* chain = new TChain("SPSTree", "SPSTree");
for(auto& entry : files)
chain->Add(entry.c_str());
chain->Merge(output, 0, "fast");
output->Close();
return true;
}
} }

View File

@ -6,36 +6,45 @@ namespace EventBuilder {
class EVBWorkspace class EVBWorkspace
{ {
public: public:
EVBWorkspace(const std::filesystem::path& workspace); EVBWorkspace(const std::string& workspace);
~EVBWorkspace(); ~EVBWorkspace();
inline const bool IsValid() const { return m_isValid; } inline const bool IsValid() const { return m_isValid; }
inline std::filesystem::path GetBinaryDir() const { return m_binaryDir; } inline std::string GetBinaryDir() const { return m_binaryDir; }
inline std::filesystem::path GetTempDir() const { return m_tempDir; } inline std::string GetTempDir() const { return m_tempDir; }
inline std::filesystem::path GetSortedDir() const { return m_sortedDir; } inline std::string GetSortedDir() const { return m_sortedDir; }
inline std::filesystem::path GetBuiltDir() const { return m_builtDir; } inline std::string GetBuiltDir() const { return m_builtDir; }
inline std::filesystem::path GetAnalyzedDir() const { return m_analyzedDir; } inline std::string GetAnalyzedDir() const { return m_analyzedDir; }
inline std::filesystem::path GetHistogramDir() const { return m_histogramDir; } inline std::string GetHistogramDir() const { return m_histogramDir; }
inline std::filesystem::path GetCutDir() const { return m_cutDir; } inline std::string GetCutDir() const { return m_cutDir; }
inline std::string GetMergedDir() const { return m_mergedDir; }
std::vector<std::string> GetBinaryRunRange(int runMin, int runMax); std::vector<std::string> GetBinaryRunRange(int runMin, int runMax);
std::string GetBinaryRun(int run); std::vector<std::string> GetAnalyzedRunRange(int runMin, int runMax);
bool UnpackBinaryRunToTemp(int run); //Currently Linux/MacOS only. Windows support to come.
std::vector<std::string> GetTempFiles(); std::vector<std::string> GetTempFiles();
bool ClearTempDirectory();
//Maybe offload to another class? Idk. Feel like EVBWorkspace shouldn't know about ROOT
bool MergeAnalyzedFiles(const std::string& outputname, int runMin, int runMax);
private: private:
void Init(); void Init();
std::string GetBinaryRun(int run);
std::string GetAnalyzedRun(int run);
bool m_isValid; bool m_isValid;
std::filesystem::path m_workspace; std::string m_workspace;
std::filesystem::path m_binaryDir; std::string m_binaryDir;
std::filesystem::path m_tempDir; std::string m_tempDir;
std::filesystem::path m_sortedDir; std::string m_sortedDir;
std::filesystem::path m_builtDir; std::string m_builtDir;
std::filesystem::path m_analyzedDir; std::string m_analyzedDir;
std::filesystem::path m_histogramDir; std::string m_histogramDir;
std::filesystem::path m_cutDir; std::string m_cutDir;
std::string m_mergedDir;
}; };
} }

View File

@ -31,7 +31,6 @@
*/ */
#include "EventBuilder.h"
#include <cmath> #include <cmath>
#include "MassLookup.h" #include "MassLookup.h"
#include "FP_kinematics.h" #include "FP_kinematics.h"

View File

@ -1,4 +1,3 @@
#include "EventBuilder.h"
#include "FastSort.h" #include "FastSort.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -1,4 +1,3 @@
#include "EventBuilder.h"
#include "FlagHandler.h" #include "FlagHandler.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -1,4 +1,3 @@
#include "EventBuilder.h"
#include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/stdout_color_sinks.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -8,7 +8,6 @@ of this map (MASS) for use throughout code it is included into.
Written by G.W. McCann Aug. 2020 Written by G.W. McCann Aug. 2020
*/ */
#include "EventBuilder.h"
#include "MassLookup.h" #include "MassLookup.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -5,7 +5,6 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include "OrderChecker.h" #include "OrderChecker.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -1,4 +1,3 @@
#include "EventBuilder.h"
#include "RunCollector.h" #include "RunCollector.h"
#include <TSystemDirectory.h> #include <TSystemDirectory.h>
#include <TSystemFile.h> #include <TSystemFile.h>

View File

@ -9,7 +9,6 @@
* *
* Position calibrations swapped as of Aug. 2021 due to detector fixes -- GWM * Position calibrations swapped as of Aug. 2021 due to detector fixes -- GWM
*/ */
#include "EventBuilder.h"
#include "SFPAnalyzer.h" #include "SFPAnalyzer.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -6,7 +6,6 @@
*Created Jan 2020 by GWM *Created Jan 2020 by GWM
*/ */
#include "EventBuilder.h"
#include "SFPPlotter.h" #include "SFPPlotter.h"
#include <TSystem.h> #include <TSystem.h>

View File

@ -9,7 +9,6 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include "ShiftMap.h" #include "ShiftMap.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -7,7 +7,6 @@
* *
*Refurbished and updated Jan 2020 GWM *Refurbished and updated Jan 2020 GWM
*/ */
#include "EventBuilder.h"
#include "SlowSort.h" #include "SlowSort.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -5,7 +5,6 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include "Stopwatch.h" #include "Stopwatch.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -29,7 +29,6 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
TGLabel* workLabel = new TGLabel(WorkFrame, "Workspace Directory:"); TGLabel* workLabel = new TGLabel(WorkFrame, "Workspace Directory:");
fWorkField = new TGTextEntry(WorkFrame, new TGTextBuffer(120), WorkDir); fWorkField = new TGTextEntry(WorkFrame, new TGTextBuffer(120), WorkDir);
fWorkField->Resize(w*0.25, fWorkField->GetDefaultHeight()); fWorkField->Resize(w*0.25, fWorkField->GetDefaultHeight());
fWorkField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateWorkdir()");
fOpenWorkButton = new TGTextButton(WorkFrame, "Open"); fOpenWorkButton = new TGTextButton(WorkFrame, "Open");
fOpenWorkButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenWorkdir()"); fOpenWorkButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenWorkdir()");
WorkFrame->AddFrame(workLabel, lhints); WorkFrame->AddFrame(workLabel, lhints);
@ -40,7 +39,6 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
TGLabel* cmaplabel = new TGLabel(CMapFrame, "Channel Map File:"); TGLabel* cmaplabel = new TGLabel(CMapFrame, "Channel Map File:");
fCMapField = new TGTextEntry(CMapFrame, new TGTextBuffer(120), Cmap); fCMapField = new TGTextEntry(CMapFrame, new TGTextBuffer(120), Cmap);
fCMapField->Resize(w*0.25, fCMapField->GetDefaultHeight()); fCMapField->Resize(w*0.25, fCMapField->GetDefaultHeight());
fCMapField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateCMap()");
fOpenCMapButton = new TGTextButton(CMapFrame, "Open"); fOpenCMapButton = new TGTextButton(CMapFrame, "Open");
fOpenCMapButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenCMapfile()"); fOpenCMapButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenCMapfile()");
CMapFrame->AddFrame(cmaplabel, lhints); CMapFrame->AddFrame(cmaplabel, lhints);
@ -51,7 +49,6 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
TGLabel* smaplabel = new TGLabel(SMapFrame, "Board Shift File:"); TGLabel* smaplabel = new TGLabel(SMapFrame, "Board Shift File:");
fSMapField = new TGTextEntry(SMapFrame, new TGTextBuffer(120), Smap); fSMapField = new TGTextEntry(SMapFrame, new TGTextBuffer(120), Smap);
fSMapField->Resize(w*0.25, fSMapField->GetDefaultHeight()); fSMapField->Resize(w*0.25, fSMapField->GetDefaultHeight());
fSMapField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateSMap()");
fOpenSMapButton = new TGTextButton(SMapFrame, "Open"); fOpenSMapButton = new TGTextButton(SMapFrame, "Open");
fOpenSMapButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenSMapfile()"); fOpenSMapButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenSMapfile()");
SMapFrame->AddFrame(smaplabel, lhints); SMapFrame->AddFrame(smaplabel, lhints);
@ -61,7 +58,6 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
TGHorizontalFrame *ScalerFrame = new TGHorizontalFrame(NameFrame, w, h*0.06); TGHorizontalFrame *ScalerFrame = new TGHorizontalFrame(NameFrame, w, h*0.06);
TGLabel* sclabel = new TGLabel(ScalerFrame, "Scaler File: "); TGLabel* sclabel = new TGLabel(ScalerFrame, "Scaler File: ");
fScalerField = new TGTextEntry(ScalerFrame, new TGTextBuffer(120), Scaler); fScalerField = new TGTextEntry(ScalerFrame, new TGTextBuffer(120), Scaler);
fScalerField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateScaler()");
fOpenScalerButton = new TGTextButton(ScalerFrame, "Open"); fOpenScalerButton = new TGTextButton(ScalerFrame, "Open");
fOpenScalerButton->Connect("Clicked()","EVBMainFrame", this, "DoOpenScalerfile()"); fOpenScalerButton->Connect("Clicked()","EVBMainFrame", this, "DoOpenScalerfile()");
ScalerFrame->AddFrame(sclabel, lhints); ScalerFrame->AddFrame(sclabel, lhints);
@ -71,7 +67,6 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
TGHorizontalFrame *CutFrame = new TGHorizontalFrame(NameFrame, w, h*0.06); TGHorizontalFrame *CutFrame = new TGHorizontalFrame(NameFrame, w, h*0.06);
TGLabel* clabel = new TGLabel(CutFrame, "Cut List: "); TGLabel* clabel = new TGLabel(CutFrame, "Cut List: ");
fCutField = new TGTextEntry(CutFrame, new TGTextBuffer(120), Cut); fCutField = new TGTextEntry(CutFrame, new TGTextBuffer(120), Cut);
fCutField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateCut()");
fOpenCutButton = new TGTextButton(CutFrame, "Open"); fOpenCutButton = new TGTextButton(CutFrame, "Open");
fOpenCutButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenCutfile()"); fOpenCutButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenCutfile()");
CutFrame->AddFrame(clabel, lhints); CutFrame->AddFrame(clabel, lhints);
@ -250,8 +245,8 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
AddFrame(ParamFrame, new TGLayoutHints(kLHintsCenterX|kLHintsExpandY,5,5,5,5)); AddFrame(ParamFrame, new TGLayoutHints(kLHintsCenterX|kLHintsExpandY,5,5,5,5));
AddFrame(PBFrame, fpbhints); AddFrame(PBFrame, fpbhints);
fBuilder.SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBMainFrame::SetProgressBarPosition)); m_builder.SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBMainFrame::SetProgressBarPosition));
fBuilder.SetProgressFraction(0.01); m_builder.SetProgressFraction(0.01);
SetWindowName("GWM Event Builder"); SetWindowName("GWM Event Builder");
MapSubwindows(); MapSubwindows();
Resize(); Resize();
@ -291,7 +286,12 @@ void EVBMainFrame::HandleMenuSelection(int id)
void EVBMainFrame::DoOpenWorkdir() void EVBMainFrame::DoOpenWorkdir()
{ {
new FileViewFrame(gClient->GetRoot(), this, MAIN_W*0.5, MAIN_H, this, WorkDir); new TGFileDialog(gClient->GetRoot(), this, kDOpen, fInfo);
if(fInfo->fFilename)
{
std::string path_wtrailer = fInfo->fFilename + std::string("/");
DisplayWorkdir(path_wtrailer.c_str());
}
} }
void EVBMainFrame::DoOpenCMapfile() void EVBMainFrame::DoOpenCMapfile()
@ -335,37 +335,37 @@ void EVBMainFrame::DoRun()
{ {
case EventBuilder::EVBApp::Operation::Plot : case EventBuilder::EVBApp::Operation::Plot :
{ {
RunPlot(); m_builder.PlotHistograms();
break; break;
} }
case EventBuilder::EVBApp::Operation::Convert : case EventBuilder::EVBApp::Operation::Convert :
{ {
fBuilder.Convert2RawRoot(); m_builder.Convert2RawRoot();
break; break;
} }
case EventBuilder::EVBApp::Operation::Merge : case EventBuilder::EVBApp::Operation::Merge :
{ {
fBuilder.MergeROOTFiles(); m_builder.MergeROOTFiles();
break; break;
} }
case EventBuilder::EVBApp::Operation::ConvertSlow : case EventBuilder::EVBApp::Operation::ConvertSlow :
{ {
fBuilder.Convert2SortedRoot(); m_builder.Convert2SortedRoot();
break; break;
} }
case EventBuilder::EVBApp::Operation::ConvertFast : case EventBuilder::EVBApp::Operation::ConvertFast :
{ {
fBuilder.Convert2FastSortedRoot(); m_builder.Convert2FastSortedRoot();
break; break;
} }
case EventBuilder::EVBApp::Operation::ConvertSlowA : case EventBuilder::EVBApp::Operation::ConvertSlowA :
{ {
fBuilder.Convert2SlowAnalyzedRoot(); m_builder.Convert2SlowAnalyzedRoot();
break; break;
} }
case EventBuilder::EVBApp::Operation::ConvertFastA : case EventBuilder::EVBApp::Operation::ConvertFastA :
{ {
fBuilder.Convert2FastAnalyzedRoot(); m_builder.Convert2FastAnalyzedRoot();
break; break;
} }
} }
@ -380,126 +380,97 @@ void EVBMainFrame::HandleTypeSelection(int box, int entry)
bool EVBMainFrame::SetParameters() bool EVBMainFrame::SetParameters()
{ {
fBuilder.SetRunRange(fRMinField->GetIntNumber(), fRMaxField->GetIntNumber()); m_parameters.runMin = fRMinField->GetIntNumber();
fBuilder.SetSlowCoincidenceWindow(fSlowWindowField->GetNumber()); m_parameters.runMax = fRMaxField->GetIntNumber();
fBuilder.SetFastWindowIonChamber(fFastICField->GetNumber()); m_parameters.slowCoincidenceWindow = fSlowWindowField->GetNumber();
fBuilder.SetFastWindowSABRE(fFastSABREField->GetNumber()); m_parameters.fastCoincidenceWindowIonCh = fFastICField->GetNumber();
UpdateWorkdir(); m_parameters.fastCoincidenceWindowSABRE = fFastSABREField->GetNumber();
UpdateSMap(); m_parameters.workspaceDir = fWorkField->GetText();
UpdateCMap(); m_parameters.channelMapFile = fCMapField->GetText();
UpdateScaler(); m_parameters.scalerFile = fScalerField->GetText();
UpdateCut(); m_parameters.timeShiftFile = fSMapField->GetText();
bool test = fBuilder.SetKinematicParameters(fZTField->GetIntNumber(), fATField->GetIntNumber(), m_parameters.cutListFile = fCutField->GetText();
fZPField->GetIntNumber(), fAPField->GetIntNumber(), m_parameters.ZT = fZTField->GetIntNumber();
fZEField->GetIntNumber(), fAEField->GetIntNumber(), m_parameters.AT = fATField->GetIntNumber();
fBField->GetNumber(), fThetaField->GetNumber(), m_parameters.ZP = fZPField->GetIntNumber();
fBKEField->GetNumber()); m_parameters.AP = fAPField->GetIntNumber();
return test; m_parameters.ZE = fZEField->GetIntNumber();
m_parameters.AE = fAEField->GetIntNumber();
m_parameters.BField = fBField->GetNumber();
m_parameters.beamEnergy = fBKEField->GetNumber();
m_parameters.spsAngle = fThetaField->GetNumber();
m_builder.SetParameters(m_parameters);
return true;
} }
void EVBMainFrame::DisplayWorkdir(const char* dir) void EVBMainFrame::DisplayWorkdir(const char* dir)
{ {
fWorkField->SetText(dir); fWorkField->SetText(dir);
fBuilder.SetWorkDirectory(dir); SetParameters();
} }
void EVBMainFrame::DisplayCMap(const char* file) void EVBMainFrame::DisplayCMap(const char* file)
{ {
fCMapField->SetText(file); fCMapField->SetText(file);
fBuilder.SetChannelMap(file); SetParameters();
} }
void EVBMainFrame::DisplaySMap(const char* file) void EVBMainFrame::DisplaySMap(const char* file)
{ {
fSMapField->SetText(file); fSMapField->SetText(file);
fBuilder.SetBoardShiftFile(file); SetParameters();
} }
void EVBMainFrame::DisplayScaler(const char* file) void EVBMainFrame::DisplayScaler(const char* file)
{ {
fScalerField->SetText(file); fScalerField->SetText(file);
fBuilder.SetScalerFile(file); SetParameters();
} }
void EVBMainFrame::DisplayCut(const char* file) void EVBMainFrame::DisplayCut(const char* file)
{ {
fCutField->SetText(file); fCutField->SetText(file);
fBuilder.SetCutList(file); SetParameters();
} }
void EVBMainFrame::SaveConfig(const char* file) void EVBMainFrame::SaveConfig(const char* file)
{ {
std::string filename = file; std::string filename = file;
fBuilder.WriteConfigFile(filename); m_builder.WriteConfigFile(filename);
} }
void EVBMainFrame::LoadConfig(const char* file) void EVBMainFrame::LoadConfig(const char* file)
{ {
std::string filename = file; std::string filename = file;
fBuilder.ReadConfigFile(filename); m_builder.ReadConfigFile(filename);
m_parameters = m_builder.GetParameters();
fWorkField->SetText(fBuilder.GetWorkDirectory().c_str()); fWorkField->SetText(m_parameters.workspaceDir.c_str());
fCMapField->SetText(fBuilder.GetChannelMap().c_str()); fCMapField->SetText(m_parameters.channelMapFile.c_str());
fSMapField->SetText(fBuilder.GetBoardShiftFile().c_str()); fSMapField->SetText(m_parameters.timeShiftFile.c_str());
fCutField->SetText(fBuilder.GetCutList().c_str()); fCutField->SetText(m_parameters.cutListFile.c_str());
fScalerField->SetText(fBuilder.GetScalerFile().c_str()); fScalerField->SetText(m_parameters.scalerFile.c_str());
fZTField->SetIntNumber(fBuilder.GetTargetZ()); fZTField->SetIntNumber(m_parameters.ZT);
fATField->SetIntNumber(fBuilder.GetTargetA()); fATField->SetIntNumber(m_parameters.AT);
fZPField->SetIntNumber(fBuilder.GetProjectileZ()); fZPField->SetIntNumber(m_parameters.ZP);
fAPField->SetIntNumber(fBuilder.GetProjectileA()); fAPField->SetIntNumber(m_parameters.AP);
fZEField->SetIntNumber(fBuilder.GetEjectileZ()); fZEField->SetIntNumber(m_parameters.ZE);
fAEField->SetIntNumber(fBuilder.GetEjectileA()); fAEField->SetIntNumber(m_parameters.AE);
fBKEField->SetNumber(fBuilder.GetBeamKE()); fBKEField->SetNumber(m_parameters.beamEnergy);
fBField->SetNumber(fBuilder.GetBField()); fBField->SetNumber(m_parameters.BField);
fThetaField->SetNumber(fBuilder.GetTheta()); fThetaField->SetNumber(m_parameters.spsAngle);
fSlowWindowField->SetNumber(fBuilder.GetSlowCoincidenceWindow()); fSlowWindowField->SetNumber(m_parameters.slowCoincidenceWindow);
fFastSABREField->SetNumber(fBuilder.GetFastWindowSABRE()); fFastSABREField->SetNumber(m_parameters.fastCoincidenceWindowSABRE);
fFastICField->SetNumber(fBuilder.GetFastWindowIonChamber()); fFastICField->SetNumber(m_parameters.fastCoincidenceWindowIonCh);
fRMaxField->SetIntNumber(fBuilder.GetRunMax()); fRMaxField->SetIntNumber(m_parameters.runMax);
fRMinField->SetIntNumber(fBuilder.GetRunMin()); fRMinField->SetIntNumber(m_parameters.runMin);
} }
void EVBMainFrame::UpdateWorkdir()
{
const char* dir = fWorkField->GetText();
fBuilder.SetWorkDirectory(dir);
}
void EVBMainFrame::UpdateSMap()
{
const char* file = fSMapField->GetText();
fBuilder.SetBoardShiftFile(file);
}
void EVBMainFrame::UpdateCMap()
{
const char* file = fCMapField->GetText();
fBuilder.SetChannelMap(file);
}
void EVBMainFrame::UpdateScaler()
{
const char* file = fScalerField->GetText();
fBuilder.SetScalerFile(file);
}
void EVBMainFrame::UpdateCut()
{
const char* file = fCutField->GetText();
fBuilder.SetCutList(file);
}
void EVBMainFrame::RunPlot()
{
fBuilder.PlotHistograms();
}
void EVBMainFrame::RunMerge(const char* file, const char* dir) {}
void EVBMainFrame::DisableAllInput() void EVBMainFrame::DisableAllInput()
{ {
fRunButton->SetState(kButtonDisabled); fRunButton->SetState(kButtonDisabled);

View File

@ -1,6 +1,7 @@
#ifndef EVBMAINFRAME_H #ifndef EVBMAINFRAME_H
#define EVBMAINFRAME_H #define EVBMAINFRAME_H
#include "../EventBuilder.h"
#include <TGClient.h> #include <TGClient.h>
#include <TGWindow.h> #include <TGWindow.h>
#include <TGFrame.h> #include <TGFrame.h>
@ -38,13 +39,6 @@ public:
void DisplayCut(const char* file); void DisplayCut(const char* file);
void SaveConfig(const char* file); void SaveConfig(const char* file);
void LoadConfig(const char* file); void LoadConfig(const char* file);
void UpdateWorkdir();
void UpdateCMap();
void UpdateSMap();
void UpdateScaler();
void UpdateCut();
void RunPlot();
void RunMerge(const char* dir, const char* file);
void DisableAllInput(); void DisableAllInput();
void EnableAllInput(); void EnableAllInput();
void SetProgressBarPosition(long value, long total); void SetProgressBarPosition(long value, long total);
@ -98,7 +92,8 @@ private:
TGFileInfo* fInfo; TGFileInfo* fInfo;
EventBuilder::EVBApp fBuilder; EventBuilder::EVBApp m_builder;
EventBuilder::EVBParameters m_parameters;
int counter; int counter;
UInt_t MAIN_W, MAIN_H; UInt_t MAIN_W, MAIN_H;