From facfa467393f67fd2f16958f92ee5cf90deb2497 Mon Sep 17 00:00:00 2001 From: Chao Peng <thor1009@gmail.com> Date: Fri, 22 Nov 2019 21:30:00 -0600 Subject: [PATCH] Follow up: clean up unused files --- src/OnlineMonitor.cxx | 138 ----------------- src/OnlineMonitor.h | 34 ---- src/THcOnlineRun.cxx | 47 +++--- src/THcOnlineRun.h | 8 +- src/include/HallC_LinkDef.h | 2 +- tools/monitor_hms.cpp | 298 ------------------------------------ 6 files changed, 28 insertions(+), 499 deletions(-) delete mode 100644 src/OnlineMonitor.cxx delete mode 100644 src/OnlineMonitor.h delete mode 100644 tools/monitor_hms.cpp diff --git a/src/OnlineMonitor.cxx b/src/OnlineMonitor.cxx deleted file mode 100644 index e6973fd..0000000 --- a/src/OnlineMonitor.cxx +++ /dev/null @@ -1,138 +0,0 @@ -#include "OnlineMonitor.h" -#include "PRadETChannel.h" -#include <csignal> - - -using namespace std::chrono; -volatile std::sig_atomic_t gSignalStatus; - -void signal_handler(int signal) { - gSignalStatus = signal; -} - - -namespace hcana { - -Int_t OnlineMonitor::Monitor(PRadETChannel *ch, std::chrono::seconds interval, int progress) -{ - Int_t total = 0; - fMonitor = true; - static const char* const here = "Monitor"; - - fBench->Begin("Total"); - - std::signal(SIGINT, signal_handler); - - while (fMonitor) { - system_clock::time_point start(system_clock::now()); - system_clock::time_point next(start + interval); - if (total % progress == 0) { - std::cout << "Received " << total << " events...\r" << std::flush; - } - total += ReadOnce(ch); - if (gSignalStatus == SIGINT) - break; - std::this_thread::sleep_until(next); - } - std::cout << "Received " << total << " events..." << std::endl; - - if (fDoBench) - fBench->Begin("Output"); - - if (fOutput && fOutput->GetTree()) { - fFile = fOutput->GetTree()->GetCurrentFile(); - } - if (fFile) - fFile->cd(); - if (fOutput) - fOutput->End(); - if (fFile) { - fFile->Purge(); - } - if (fDoBench) - fBench->Stop("Output"); - - return total; -} - - -Int_t OnlineMonitor::ReadOnce(PRadETChannel *ch, size_t max_events) -try { - Int_t count = 0; - for(size_t num = 0; ch->Read() && (num < max_events); ++num) { - auto buf = ch->GetBuffer(); - count += ReadBuffer((uint32_t*)(ch->GetBuffer())); - } - return count; -} -catch (PRadException e) { - std::cerr << e.FailureType() << ": " << e.FailureDesc() << std::endl; - fMonitor = false; - return 0; -} - - -Int_t OnlineMonitor::ReadBuffer(uint32_t *buf) -try { - switch (fEvData->LoadEvent(buf)) { - case THaEvData::HED_WARN: - case THaEvData::HED_OK: - break; - default: - return 0; - } - - Int_t count = 0; - do { - count += ProcOneEvent(); - } while ( fEvData->IsMultiBlockMode() && - !fEvData->BlockIsDone() && - (fEvData->LoadFromMultiBlock() == THaEvData::HED_OK) ); - - return count; -} -catch (...) { - throw; -} - -Int_t OnlineMonitor::ProcOneEvent() -{ - UInt_t evnum = fEvData->GetEvNum(); - - switch (fCountMode) { - case kCountPhysics: - if (fEvData->IsPhysicsTrigger()) - fNev++; - break; - case kCountAll: - fNev++; - break; - case kCountRaw: - fNev = evnum; - break; - default: - break; - } - - if (fDoBench) - fBench->Begin("Cuts"); - gHaCuts->ClearAll(); - if (fDoBench) - fBench->Stop("Cuts"); - - switch (MainAnalysis()) { - case kOK: - return 1; - case kSkip: - default: - break; - case kTerminate: - throw(PRadException("Termination", "analysis is terminated.")); - case kFatal: - throw(PRadException("Fatal Error", "analysis encountered fatal error.")); - } - - return 0; -} - -} // namespace hcana diff --git a/src/OnlineMonitor.h b/src/OnlineMonitor.h deleted file mode 100644 index afb35c9..0000000 --- a/src/OnlineMonitor.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef hcana_OnlineMonitor_h_ -#define hcana_OnlineMonitor_h_ - -#include "THaBenchmark.h" -#include "THcAnalyzer.h" -#include <thread> -#include <chrono> -#include <iostream> - - -class PRadETChannel; - -namespace hcana { - - class OnlineMonitor : public THcAnalyzer { - public: - OnlineMonitor() : THcAnalyzer() {} - virtual ~OnlineMonitor() {} - - virtual Int_t Monitor(PRadETChannel *ch, - std::chrono::seconds interval = std::chrono::seconds(10), - int progress = 10); - virtual Int_t ReadOnce(PRadETChannel *ch, size_t max_events = 10000); - Int_t ReadBuffer(uint32_t *buf); - Int_t ProcOneEvent(); - //Int_t GoToEndOfCodaFile(); - - ClassDef(OnlineMonitor, 0) // Hall C Analyzer Standard Event Loop - private: - bool fMonitor; - }; - -} // namespace hcana -#endif diff --git a/src/THcOnlineRun.cxx b/src/THcOnlineRun.cxx index bba9e52..a80c948 100644 --- a/src/THcOnlineRun.cxx +++ b/src/THcOnlineRun.cxx @@ -13,16 +13,16 @@ // Constructors -THcOnlineRun::THcOnlineRun(const char* fname, const char* description) : +THcOnlineRun::THcOnlineRun(const char* fname, const char* description) : THcRun(fname, description), et_id(nullptr), stat_id(ID_NULL), att_id(ID_NULL) { - fHcParms = gHcParms; + // place holder } THcOnlineRun::THcOnlineRun(const vector<TString>& pathList, const char* filename, const char* description) -: THaRun(pathList, filename, description), et_id(nullptr), stat_id(ID_NULL), att_id(ID_NULL) -{ - fHcParms = gHcParms; +: THcRun(pathList, filename, description), et_id(nullptr), stat_id(ID_NULL), att_id(ID_NULL) +{ + // place holder } // Copy constructor @@ -33,7 +33,6 @@ THcOnlineRun::THcOnlineRun(const THcOnlineRun& rhs) et_id = nullptr; stat_id = ID_NULL; att_id = ID_NULL; - fHcParms = gHcParms; } // Missing move constructor, not implementing for consistency with the analyzer @@ -41,12 +40,13 @@ THcOnlineRun::THcOnlineRun(const THcOnlineRun& rhs) // Copy assignment operator THcOnlineRun& THcOnlineRun::operator=(const THaRunBase& rhs) { - - if (this != &rhs) { - THaRun::operator=(rhs); - fHcParms = gHcParms; - } - return *this; + if (this != &rhs) { + et_id = nullptr; + stat_id = ID_NULL; + att_id = ID_NULL; + THcRun::operator=(rhs); + } + return *this; } // Missing move assignment operator, not implementing for consistency with the analyzer @@ -83,18 +83,18 @@ Int_t THcOnlineRun::Connect(const char *ip_addr, int port, const char *et_file, sconf.SetSelect(ET_STATION_SELECT_ALL); sconf.SetBlock(ET_STATION_NONBLOCKING); - auto status = CreateStation(s_name, sconf); + status = CreateStation(s_name, sconf); if (status < ET_OK) { _logger->error("THcOnlineRun::Connect : Failed to create a station, abort connection."); Close(); - return status; + return status; } - auto status = Attach(); + status = Attach(); if (status < ET_OK) { _logger->error("THcOnlineRun::Connect : Failed to attach to the station, abort connection."); Close(); - return status; + return status; } return ET_OK; @@ -108,17 +108,16 @@ Int_t THcOnlineRun::Open(const char *et_file, PRadETChannel::Configuration conf) return ID_NULL; } - int csize = strlen(et_file) + 1; - char fname[csize]; - strncpy(fname, et_file, csize); - return et_open(&et_id, fname, config.Get()); + char fname[256]; + strncpy(fname, et_file, 256); + return et_open(&et_id, fname, conf.Get()); } // Close ET Int_t THcOnlineRun::Close() { if ( (et_id != nullptr) && IsOpen() ) { - et_forceclose(et_id); + et_forcedclose(et_id); et_id = nullptr; return 1; } @@ -157,15 +156,15 @@ Int_t THcOnlineRun::RemoveStation() // Attach to a station Int_t THcOnlineRun::Attach() { - return AttachStation(stat_id); + return Attach(stat_id); } // Attach to a station with station id Int_t THcOnlineRun::Attach(et_stat_id sid) { if (!IsOpen()) { - _logger->warn("THcOnlineRun::AttachStation : ET System is not opened, abort attaching to a station."); - return ID_NULL; + _logger->warn("THcOnlineRun::Attach : ET System is not opened, abort attaching to a station."); + return ID_NULL; } return et_station_attach(et_id, sid, &att_id); } diff --git a/src/THcOnlineRun.h b/src/THcOnlineRun.h index eadf7f3..c8eae61 100644 --- a/src/THcOnlineRun.h +++ b/src/THcOnlineRun.h @@ -10,7 +10,7 @@ // Chao Peng, 11/22/2019 // //////////////////////////////////////////////////////////////////////////////// -#include "THcOnlineRun.h" +#include "THcRun.h" #include "THcParmList.h" #include "PRadETChannel.h" #include "PRadETStation.h" @@ -34,8 +34,8 @@ public: virtual Int_t CreateStation(const char *sname, PRadETStation::Configuration conf); virtual Int_t RemoveStation(); virtual Int_t Attach(); - virtual Attach(et_stat_id sid); - virtual Detach(); + virtual Int_t Attach(et_stat_id sid); + virtual Int_t Detach(); virtual Bool_t IsOpen() const { return (et_id == nullptr) || (et_alive(et_id) > 0); }; @@ -49,7 +49,7 @@ private: et_sys_id et_id; et_stat_id stat_id; et_att_id att_id; - ClassDef(THcOnlineRun,0); + ClassDef(THcOnlineRun, 2); }; #endif // ROOT_THcOnlineRun diff --git a/src/include/HallC_LinkDef.h b/src/include/HallC_LinkDef.h index 4bc08c4..c44fbb5 100644 --- a/src/include/HallC_LinkDef.h +++ b/src/include/HallC_LinkDef.h @@ -93,6 +93,6 @@ #pragma link C++ class hcana::Scandalizer+; #pragma link C++ class hcana::TrackingEfficiency+; -#pragma link C++ class hcana::OnlineMonitor+; +#pragma link C++ class THcOnlineRun+; // Postamble for HallC_Linkdef.h file #endif diff --git a/tools/monitor_hms.cpp b/tools/monitor_hms.cpp deleted file mode 100644 index 0d7c798..0000000 --- a/tools/monitor_hms.cpp +++ /dev/null @@ -1,298 +0,0 @@ -#include <chrono> -#include <iostream> -#include <locale> -#include <string> -using namespace std; - -// Logging -#include "spdlog/spdlog.h" - -// Better formatting -#include <fmt/format.h> - -// analyzer includes -#include "THaCut.h" -#include "THaGoldenTrack.h" -#include "THaReactionPoint.h" -#include "THcAerogel.h" -#include "THcAnalyzer.h" -#include "THcCherenkov.h" -#include "THcCoinTime.h" -#include "THcConfigEvtHandler.h" -#include "THcDC.h" -#include "THcDetectorMap.h" -#include "THcExtTarCor.h" -#include "THcGlobals.h" -#include "THcHallCSpectrometer.h" -#include "THcHodoEff.h" -#include "THcHodoscope.h" -#include "THcParmList.h" -#include "THcPrimaryKine.h" -#include "THcRasteredBeam.h" -#include "THcRun.h" -#include "THcScalerEvtHandler.h" -#include "THcSecondaryKine.h" -#include "THcShower.h" -#include "THcTrigApp.h" -#include "THcTrigDet.h" - -#include "OnlineMonitor.h" -#include "ConfigOption.h" -#include "PRadETChannel.h" - -#define DBASE "/u/home/cpeng/ANL/hallc_replay" - - -int monitor(PRadETChannel *ch, int interval, const bool do_all = false, const bool do_coin = false); - -int main(int argc, char *argv[]) try -{ - // setup input arguments - ConfigOption conf_opt; - conf_opt.AddLongOpt(ConfigOption::help_message, "help"); - conf_opt.AddOpt(ConfigOption::arg_require, 'h'); - conf_opt.AddOpt(ConfigOption::arg_require, 'p'); - conf_opt.AddOpt(ConfigOption::arg_require, 'f'); - conf_opt.AddOpt(ConfigOption::arg_require, 'i'); - - conf_opt.SetDesc("usage: %0"); - conf_opt.SetDesc('h', "host address of the ET system, default \"localhost\"."); - conf_opt.SetDesc('p', "port to connect, default 11111."); - conf_opt.SetDesc('f', "memory mapped et file, default \"/tmp/et_feeder\"."); - conf_opt.SetDesc('i', "interval in seconds to update, default \"10\""); - - if (!conf_opt.ParseArgs(argc, argv) || conf_opt.NbofArgs() != 0) { - std::cout << conf_opt.GetInstruction() << std::endl; - return -1; - } - - std::string host = "localhost"; - int port = 11111; - std::string etf = "/tmp/et_feeder"; - int interval = 10; - - for (auto &opt : conf_opt.GetOptions()) { - switch (opt.mark) { - case 'h': - host = opt.var.String(); - break; - case 'c': - port = opt.var.Int(); - break; - case 'f': - etf = opt.var.String(); - break; - case 'i': - interval = opt.var.Int(); - break; - default : - std::cout << conf_opt.GetInstruction() << std::endl; - return -1; - } - } - - // attach to ET system - auto ch = new PRadETChannel(20*1024*1024); - ch->Open(host.c_str(), port, etf.c_str()); - ch->NewStation("Monitor"); - ch->AttachStation(); - - return monitor(ch, interval); - -} catch (PRadException e) { - std::cerr << e.FailureType() << ": " << e.FailureDesc() << std::endl; - return -1; -} - -std::string output_file_pattern(string_view path, string_view content, string_view extension, - bool do_coin, bool do_all) -{ - return fmt::format("{}/hms{}_{}{}_{{:05d}}_{{}}.{}", path, do_coin ? "_coin" : "", content, - do_all ? "_all" : "", extension); -} - -int monitor(PRadETChannel *ch, int interval, const bool do_all, const bool do_coin) -{ - // =========================================================================== - // Setup logging - spdlog::set_level(spdlog::level::warn); - spdlog::flush_every(std::chrono::seconds(5)); - int RunNumber = 2372; - - // 2. Output files - const auto ROOTFileNamePattern = - output_file_pattern("ROOTfiles", "replay_production", "root", do_coin, do_all); - - // Load global parameters - gHcParms->Define("gen_run_number", "Run Number", RunNumber); - gHcParms->AddString("g_ctp_database_filename", - do_coin ? DBASE"DBASE/COIN/standard.database" : DBASE"DBASE/HMS/standard.database"); - gHcParms->Load(gHcParms->GetString("g_ctp_database_filename"), RunNumber); - gHcParms->Load(gHcParms->GetString("g_ctp_parm_filename")); - gHcParms->Load(gHcParms->GetString("g_ctp_kinematics_filename"), RunNumber); - // Load parameters for HMS trigger configuration - gHcParms->Load(DBASE"PARAM/TRIG/thms.param"); - // Load fadc debug parameters - gHcParms->Load(DBASE"PARAM/HMS/GEN/p_fadc_debug.param"); - - // Load the Hall C detector map - gHcDetectorMap = new THcDetectorMap(); - gHcDetectorMap->Load(DBASE"MAPS/HMS/DETEC/STACK/hms_stack.map"); - - // =========================================================================== - // Experimental apparatus - // - // --------------------------------------------------------------------------- - // A. HMS setup - // - // Set up the equipment to be analyzed. - THcHallCSpectrometer* HMS = new THcHallCSpectrometer("H", "HMS"); - if (do_coin) { - HMS->SetEvtType(2); - HMS->AddEvtType(4); - HMS->AddEvtType(5); - HMS->AddEvtType(6); - HMS->AddEvtType(7); - } - gHaApps->Add(HMS); - // 1. Add drift chambers to HMS apparatus - THcDC* hdc = new THcDC("dc", "Drift Chambers"); - HMS->AddDetector(hdc); - // 2. Add hodoscope to HMS apparatus - THcHodoscope* hhod = new THcHodoscope("hod", "Hodoscope"); - HMS->AddDetector(hhod); - // 3. Add Heavy Gas Cherenkov to HMS apparatus - THcCherenkov* hcer = new THcCherenkov("cer", "Heavy Gas Cherenkov"); - HMS->AddDetector(hcer); - // 6. Add calorimeter to HMS apparatus - THcShower* hcal = new THcShower("cal", "Calorimeter"); - HMS->AddDetector(hcal); - // --------------------------------------------------------------------------- - // B. Beamline - // - // Add rastered beam apparatus - THaApparatus* hbeam = new THcRasteredBeam("H.rb", "Rastered Beamline"); - gHaApps->Add(hbeam); - - // --------------------------------------------------------------------------- - // C. Trigger - // - // Add trigger detector to trigger apparatus - THaApparatus* TRG = new THcTrigApp("T", "TRG"); - gHaApps->Add(TRG); - // Add trigger detector to trigger apparatus - THcTrigDet* hms = new THcTrigDet("hms", "HMS Trigger Information"); - hms->SetSpectName("H"); - TRG->AddDetector(hms); - // TODO Add helicity detector to trigger apparatus - // THcHelicity* helicity = new THcHelicity("helicity","Helicity Detector"); - // TRG->AddDetector(helicity); - - // =========================================================================== - // Phyics and derived quantities - // - // 1. Calculate reaction point - THaReactionPoint* hrp = new THaReactionPoint("H.react", "HMS reaction point", "H", "H.rb"); - gHaPhysics->Add(hrp); - // 2. Calculate extended target corrections - THcExtTarCor* hext = - new THcExtTarCor("H.extcor", "HMS extended target corrections", "H", "H.react"); - gHaPhysics->Add(hext); - // 3. Calculate golden track quantites - THaGoldenTrack* hgtr = new THaGoldenTrack("H.gtr", "HMS Golden Track", "H"); - gHaPhysics->Add(hgtr); - // 4. Calculate the hodoscope efficiencies - THcHodoEff* heff = new THcHodoEff("hhodeff", "HMS hodo efficiency", "H.hod"); - gHaPhysics->Add(heff); - // 5. Single arm kinematics - THcPrimaryKine* hkin = new THcPrimaryKine("H.kin", "HMS Single Arm Kinematics", "H", "H.rb"); - gHaPhysics->Add(hkin); - - // =========================================================================== - // Global Objects & Event Handlers - // - // Add event handler for scaler events - THcScalerEvtHandler* hscaler = new THcScalerEvtHandler("H", "Hall C scaler event type 2"); - hscaler->AddEvtType(2); - if (do_coin) { - hscaler->AddEvtType(4); - hscaler->AddEvtType(5); - hscaler->AddEvtType(6); - hscaler->AddEvtType(7); - } - hscaler->AddEvtType(129); - hscaler->SetDelayedType(129); - hscaler->SetUseFirstEvent(kTRUE); - gHaEvtHandlers->Add(hscaler); - - // Add event handler for prestart event 125. - THcConfigEvtHandler* hconfig = new THcConfigEvtHandler("hconfig", "Config Event type 125"); - gHaEvtHandlers->Add(hconfig); - // Add event handler for EPICS events - THaEpicsEvtHandler* hcepics = new THaEpicsEvtHandler( - "epics", do_coin ? "HC EPICS event type 182" : "HC EPICS event type 181"); - gHaEvtHandlers->Add(hcepics); - - // ----------------------------------------------------------- - // Analyzer - // ----------------------------------------------------------- - // - auto analyzer = new hcana::OnlineMonitor; - analyzer->SetCodaVersion(2); - // analyzer->EnableBenchmarks(true); - - // A simple event class to be output to the resulting tree. - // Creating your own descendant of THaEvent is one way of - // defining and controlling the output. - THaEvent* event = new THaEvent; - - // Define the analysis parameters - const auto ROOTFileName = fmt::format(ROOTFileNamePattern, RunNumber, -1); - analyzer->SetCountMode(2); // 0 = counter is # of physics triggers - // 1 = counter is # of all decode reads - // 2 = counter is event number - // Define the run(s) that we want to analyze. - // We just set up one, but this could be many. - THcRun* run = new THcRun; - - // Set to read in Hall C run database parameters - run->SetRunParamClass("THcRunParameters"); - - // Eventually need to learn to skip over, or properly analyze the pedestal events - run->SetEventRange(0, -1); // Physics Event number, does not include scaler or control events. - run->SetNscan(1); - run->SetDataRequired(0x7); - run->Print(); - - analyzer->SetEvent(event); - // Set EPICS event type - analyzer->SetEpicsEvtType(do_coin ? 182 : 181); - // Define crate map - analyzer->SetCrateMapFileName("MAPS/db_cratemap.dat"); - // Define output ROOT file - analyzer->SetOutFile(ROOTFileName.c_str()); - // Define DEF-file+ - // analyzer->SetOdefFile("DEF-files/HMS/PRODUCTION/pstackana_production_all.def"); - analyzer->SetOdefFile(do_all ? "DEF-files/HMS/PRODUCTION/hstackana_production_all.def" - : "DEF-files/HMS/PRODUCTION/hstackana_production.def"); - // Define cuts file - analyzer->SetCutFile("DEF-files/HMS/PRODUCTION/CUTS/hstackana_production_cuts.def"); // optional - // File to record accounting information for cuts - analyzer->SetSummaryFile(fmt::format(output_file_pattern("REPORT_OUTPUT/PRODUCTION", "summary", - "report", do_coin, do_all), - RunNumber, -1) - .c_str()); - // Start the actual analysis. - analyzer->Monitor(ch, std::chrono::seconds(interval)); - // Create report file from template - analyzer->PrintReport( - "TEMPLATES/HMS/PRODUCTION/hstackana_production.template", - fmt::format(output_file_pattern("REPORT_OUTPUT/PRODUCTION", "replay_production", "report", - do_coin, do_all), - RunNumber, -1) - .c_str()); - - delete analyzer; - - return 0; -} -- GitLab