From 85c5de0c368744781e1a589ea71d1ad985bb2d26 Mon Sep 17 00:00:00 2001 From: Whitney Armstrong <warmstrong@anl.gov> Date: Tue, 11 Dec 2018 00:29:46 -0600 Subject: [PATCH] Added a few more spdlog loggers --- src/Logger.h | 16 ++++++++++++++++ src/THcAnalyzer.cxx | 2 +- src/THcAnalyzer.h | 4 +++- src/THcCherenkov.cxx | 9 +++++---- src/THcCherenkov.h | 5 ++++- src/THcDC.cxx | 17 +++++++++++------ src/THcDetectorMap.cxx | 13 ++++++++----- src/THcDetectorMap.h | 4 +++- src/THcHitList.cxx | 15 ++++++++++++--- src/THcHitList.h | 4 ++++ src/THcParmList.cxx | 5 +++-- src/THcParmList.h | 4 +++- src/THcRaster.cxx | 11 +++++++---- src/THcRaster.h | 4 +++- src/THcShower.cxx | 18 +++++++++--------- src/THcShower.h | 4 +++- 16 files changed, 95 insertions(+), 40 deletions(-) diff --git a/src/Logger.h b/src/Logger.h index 938e124..ed5d16f 100644 --- a/src/Logger.h +++ b/src/Logger.h @@ -18,6 +18,22 @@ namespace hcana { if(!_logger) { _logger = spdlog::stdout_color_mt("config"); } + _logger->set_pattern("[%t] [%n] %^[%l]%$ %v"); + } + + }; + + template <typename Base> + class HitLogging : public Base { + protected: + std::shared_ptr<spdlog::logger> _hit_logger; + public: + template <class... Args> + HitLogging(Args&&... args) : Base(std::forward<Args>(args)...) { + _hit_logger = spdlog::get("hits"); + if(!_hit_logger) { + _hit_logger = spdlog::stdout_color_mt("hits"); + } } }; diff --git a/src/THcAnalyzer.cxx b/src/THcAnalyzer.cxx index e4101d6..86fad41 100644 --- a/src/THcAnalyzer.cxx +++ b/src/THcAnalyzer.cxx @@ -37,7 +37,7 @@ using namespace std; // do we need to "close" scalers/EPICS analysis if we reach the event limit? //_____________________________________________________________________________ -THcAnalyzer::THcAnalyzer() +THcAnalyzer::THcAnalyzer() : hcana::ConfigLogging<THaAnalyzer>() { } diff --git a/src/THcAnalyzer.h b/src/THcAnalyzer.h index 80208f0..16db1e3 100644 --- a/src/THcAnalyzer.h +++ b/src/THcAnalyzer.h @@ -44,7 +44,9 @@ #include <iostream> #include <stdexcept> -class THcAnalyzer : public THaAnalyzer { +#include "Logger.h" + +class THcAnalyzer : public hcana::ConfigLogging<THaAnalyzer> { public: diff --git a/src/THcCherenkov.cxx b/src/THcCherenkov.cxx index a2a71d2..b21a795 100644 --- a/src/THcCherenkov.cxx +++ b/src/THcCherenkov.cxx @@ -45,7 +45,7 @@ using std::setprecision; //_____________________________________________________________________________ THcCherenkov::THcCherenkov( const char* name, const char* description, THaApparatus* apparatus ) : - THaNonTrackingDetector(name,description,apparatus) + hcana::ConfigLogging<THaNonTrackingDetector>(name,description,apparatus) { // Normal constructor with name and description frAdcPedRaw = new TClonesArray("THcSignalHit", MaxNumCerPmt*MaxNumAdcPulse); @@ -77,7 +77,7 @@ THcCherenkov::THcCherenkov( const char* name, const char* description, //_____________________________________________________________________________ THcCherenkov::THcCherenkov( ) : - THaNonTrackingDetector() + hcana::ConfigLogging<THaNonTrackingDetector>() { // Constructor frAdcPedRaw = NULL; @@ -199,8 +199,9 @@ Int_t THcCherenkov::ReadDatabase( const TDatime& date ) Bool_t optional = true; - cout << "Created Cherenkov detector " << GetApparatus()->GetName() << "." - << GetName() << " with " << fNelem << " PMTs" << endl; + _logger->info("Created Cherenkov detector {}.{} with {} PMTs",GetApparatus()->GetName(), GetName(), fNelem); + //cout << "Created Cherenkov detector " << GetApparatus()->GetName() << "." + // << GetName() << " with " << fNelem << " PMTs" << endl; // 6 GeV pedestal paramters fPedLimit = new Int_t[fNelem]; diff --git a/src/THcCherenkov.h b/src/THcCherenkov.h index 30f3d6c..74356d4 100644 --- a/src/THcCherenkov.h +++ b/src/THcCherenkov.h @@ -11,9 +11,12 @@ #include "THaNonTrackingDetector.h" #include "THcHitList.h" #include "THcCherenkovHit.h" + +#include "Logger.h" + class THcHodoscope; -class THcCherenkov : public THaNonTrackingDetector, public THcHitList { +class THcCherenkov : public hcana::ConfigLogging<THaNonTrackingDetector>, public THcHitList { using vec = std::vector<Double_t>; diff --git a/src/THcDC.cxx b/src/THcDC.cxx index 924c38d..d9e082f 100644 --- a/src/THcDC.cxx +++ b/src/THcDC.cxx @@ -225,9 +225,9 @@ THaAnalysisObject::EStatus THcDC::Init( const TDatime& date ) // Should probably put this in ReadDatabase as we will know the // maximum number of hits after setting up the detector map - cout << " DC tdc ref time cut = " << fTDC_RefTimeCut << endl; - InitHitList(fDetMap, "THcRawDCHit", fDetMap->GetTotNumChan()+1, - fTDC_RefTimeCut, 0); + _logger->info("DC tdc ref time cut = {} ", fTDC_RefTimeCut); + //cout << " DC tdc ref time cut = " << fTDC_RefTimeCut << endl; + InitHitList(fDetMap, "THcRawDCHit", fDetMap->GetTotNumChan()+1, fTDC_RefTimeCut, 0); CreateMissReportParms(Form("%sdc",fPrefix)); @@ -391,11 +391,16 @@ Int_t THcDC::ReadDatabase( const TDatime& date ) gHcParms->LoadParmValues((DBRequest*)&listOpt,fPrefix); if(fNTracksMaxFP <= 0) fNTracksMaxFP = 10; // if(fNTracksMaxFP > HNRACKS_MAX) fNTracksMaxFP = NHTRACKS_MAX; - cout << "Plane counts:"; + + std::string plane_counts_string; + //cout << "Plane counts:"; for(Int_t i=0;i<fNPlanes;i++) { - cout << " " << fNWires[i]; + //cout << " " << fNWires[i]; + plane_counts_string += std::string(" "); + plane_counts_string += std::to_string(fNWires[i]); } - cout << endl; + //cout << endl; + _logger->info("Plane counts: {}", plane_counts_string); fIsInit = true; diff --git a/src/THcDetectorMap.cxx b/src/THcDetectorMap.cxx index 6a4a1b2..2d54023 100644 --- a/src/THcDetectorMap.cxx +++ b/src/THcDetectorMap.cxx @@ -28,7 +28,7 @@ inline static bool IsComment( const string& s, string::size_type pos ) } //_____________________________________________________________________________ -THcDetectorMap::THcDetectorMap() : fNchans(0), fNIDs(0) +THcDetectorMap::THcDetectorMap() : hcana::ConfigLogging<TObject>(), fNchans(0), fNIDs(0) { } @@ -405,11 +405,14 @@ void THcDetectorMap::Load(const char *fname) fNchans++; } } - cout << endl << " Detector ID Map" << endl << endl; + _logger->info("Detector ID Map"); + //cout << endl << " Detector ID Map" << endl << endl; + for(Int_t i=0; i < fNIDs; i++) { - cout << " "; - cout << fIDMap[i].name << " " << fIDMap[i].id << endl; + //cout << " "; + //cout << fIDMap[i].name << " " << fIDMap[i].id << endl; + _logger->info(" {:>12} {:<10} ", fIDMap[i].name ,fIDMap[i].id ); } - cout << endl; + //cout << endl; } diff --git a/src/THcDetectorMap.h b/src/THcDetectorMap.h index b222cf4..eb4f218 100644 --- a/src/THcDetectorMap.h +++ b/src/THcDetectorMap.h @@ -11,7 +11,9 @@ #include "THaDetMap.h" #include <list> -class THcDetectorMap : public TObject { +#include "Logger.h" + +class THcDetectorMap : public hcana::ConfigLogging<TObject> { public: THcDetectorMap(); diff --git a/src/THcHitList.cxx b/src/THcHitList.cxx index dce9176..3113776 100644 --- a/src/THcHitList.cxx +++ b/src/THcHitList.cxx @@ -23,6 +23,10 @@ using namespace std; #define SUPPRESSMISSINGADCREFTIMEMESSAGES 1 THcHitList::THcHitList() : fMap(0), fTISlot(0), fDisableSlipCorrection(kFALSE) { + _hitlist_logger = spdlog::get("hitlist"); + if(!_hitlist_logger) { + _hitlist_logger = spdlog::stdout_color_mt("hitlist"); + } /// Normal constructor. fRawHitList = NULL; @@ -59,7 +63,9 @@ a method to ask the OO decoder what kind of module is in a given slot? void THcHitList::InitHitList(THaDetMap* detmap, const char *hitclass, Int_t maxhits, Int_t tdcref_cut, Int_t adcref_cut) { - cout << "InitHitList: " << hitclass << " RefTimeCuts: " << tdcref_cut << " " << adcref_cut << endl; + + _hitlist_logger->info("InitHitList: {} RefTimeCuts: {} {}", hitclass, tdcref_cut, adcref_cut); + //cout << "InitHitList: " << hitclass << " RefTimeCuts: " << tdcref_cut << " " << adcref_cut << endl; fRawHitList = new TClonesArray(hitclass, maxhits); fRawHitClass = fRawHitList->GetClass(); fNMaxRawHits = maxhits; @@ -516,13 +522,16 @@ void THcHitList::CreateMissReportParms(const char *prefix) Parameters created are ${prefix}_tdcref_miss and ${prefix}_adcref_miss */ - cout << "Defining " << Form("%s_tdcref_miss", prefix) << " and " << Form("%s_adcref_miss", prefix) << endl; + _hitlist_logger->info("Defining {}_tdcref_miss and {}_adcref_miss", prefix, prefix); + //cout << "Defining " << Form("%s_tdcref_miss", prefix) << " and " << Form("%s_adcref_miss", prefix) << endl; gHcParms->Define(Form("%s_tdcref_miss", prefix), "Missing TDC reference times", fNTDCRef_miss); gHcParms->Define(Form("%s_adcref_miss", prefix), "Missing ADC reference times", fNADCRef_miss); } void THcHitList::MissReport(const char *name) { - cout << "Missing Ref times:" << setw(20) << name << setw(10) << fNTDCRef_miss << setw(10) << fNADCRef_miss << endl; + + _hitlist_logger->warn("Missing Ref times: {:20} {:10} {:10}", name, fNTDCRef_miss, fNADCRef_miss); + //cout << "Missing Ref times:" << setw(20) << name << setw(10) << fNTDCRef_miss << setw(10) << fNADCRef_miss << endl; } ClassImp(THcHitList) diff --git a/src/THcHitList.h b/src/THcHitList.h index 423a75e..5a18f45 100644 --- a/src/THcHitList.h +++ b/src/THcHitList.h @@ -13,6 +13,8 @@ #include <iomanip> #include <map> +#include "Logger.h" + using namespace std; ////////////////////////////////////////////////////////////////////////// @@ -25,6 +27,8 @@ using namespace std; class THcConfigEvtHandler; class THcHitList { + protected: + std::shared_ptr<spdlog::logger> _hitlist_logger; public: diff --git a/src/THcParmList.cxx b/src/THcParmList.cxx index a3efe12..6fdada9 100644 --- a/src/THcParmList.cxx +++ b/src/THcParmList.cxx @@ -67,7 +67,7 @@ Int_t fDebug = 1; // Keep this at one while we're working on the code ClassImp(THcParmList) /// Create empty numerical and string parameter lists -THcParmList::THcParmList() : THaVarList() +THcParmList::THcParmList() : hcana::ConfigLogging<THaVarList>() { TextList = new THaTextvars; } @@ -180,7 +180,8 @@ The ENGINE CTP support parameter "blocks" which were marked with // cout << line << endl; ifiles[nfiles].open(line.c_str()); if(ifiles[nfiles].is_open()) { - cout << "Opening parameter file: [" << nfiles << "] " << line << endl; + _logger->info("Opening parameter file: [{}] {} ", nfiles, line); + //cout << "Opening parameter file: [" << nfiles << "] " << line << endl; nfiles++; } continue; diff --git a/src/THcParmList.h b/src/THcParmList.h index 38b192a..2f31c68 100644 --- a/src/THcParmList.h +++ b/src/THcParmList.h @@ -10,6 +10,8 @@ #include "THaVarList.h" #include "THaTextvars.h" +#include "Logger.h" + #ifdef WITH_CCDB #ifdef __CINT__ struct pthread_cond_t; @@ -23,7 +25,7 @@ using namespace ccdb; using namespace std; -class THcParmList : public THaVarList { +class THcParmList : public hcana::ConfigLogging<THaVarList> { public: diff --git a/src/THcRaster.cxx b/src/THcRaster.cxx index 628af3b..85f41a1 100644 --- a/src/THcRaster.cxx +++ b/src/THcRaster.cxx @@ -38,7 +38,7 @@ using namespace std; //_____________________________________________________________________________ THcRaster::THcRaster( const char* name, const char* description, THaApparatus* apparatus ) : - THaBeamDet(name,description,apparatus) + hcana::ConfigLogging<THaBeamDet>(name,description,apparatus) { fAnalyzePedestals = 0; @@ -97,7 +97,7 @@ THcRaster::THcRaster( const char* name, const char* description, //_____________________________________________________________________________ THcRaster::THcRaster( ) : - THaBeamDet("THcRaster") // no default constructor available + hcana::ConfigLogging<THaBeamDet>("THcRaster") // no default constructor available { frPosAdcPulseIntRaw = NULL; @@ -246,8 +246,11 @@ Int_t THcRaster::ReadDatabase( const TDatime& date ) if (fgbeam_yoff ==-999.) fgbeam_yoff = 0.; if (fgbeam_xpoff ==-999.) fgbeam_xpoff = 0.; if (fgbeam_ypoff ==-999.) fgbeam_ypoff = 0.; - cout << " THcRaster is using parameters for beam position" << " x = " << fgbeam_xoff<< " y = " << fgbeam_yoff<< endl; - cout << " THcRaster is using parameters for beam angle position" << " xp = " << fgbeam_xpoff<< " yp = " << fgbeam_ypoff<< endl; + + _logger->info("THcRaster parameters for beam position x = {}, y = {}", fgbeam_xoff, fgbeam_yoff); + _logger->info("THcRaster parameters for beam angle position xp= {}, yp= {}", fgbeam_xpoff, fgbeam_ypoff); + //cout << " THcRaster is using parameters for beam position" << " x = " << fgbeam_xoff<< " y = " << fgbeam_yoff<< endl; + //cout << " THcRaster is using parameters for beam angle position" << " xp = " << fgbeam_xpoff<< " yp = " << fgbeam_ypoff<< endl; } diff --git a/src/THcRaster.h b/src/THcRaster.h index a30aa74..212d4f9 100644 --- a/src/THcRaster.h +++ b/src/THcRaster.h @@ -20,7 +20,9 @@ #include "THaOutput.h" #include "THaEpicsEvtHandler.h" -class THcRaster : public THaBeamDet, public THcHitList { +#include "Logger.h" + +class THcRaster : public hcana::ConfigLogging<THaBeamDet>, public THcHitList { public: diff --git a/src/THcShower.cxx b/src/THcShower.cxx index ae23af0..fd5fd01 100644 --- a/src/THcShower.cxx +++ b/src/THcShower.cxx @@ -31,7 +31,7 @@ using namespace std; //_____________________________________________________________________________ THcShower::THcShower( const char* name, const char* description, THaApparatus* apparatus ) : - THaNonTrackingDetector(name,description,apparatus) + hcana::ConfigLogging<THaNonTrackingDetector>(name,description,apparatus) { // Constructor fNLayers = 0; // No layers until we make them @@ -43,7 +43,7 @@ THcShower::THcShower( const char* name, const char* description, //_____________________________________________________________________________ THcShower::THcShower( ) : - THaNonTrackingDetector() + hcana::ConfigLogging<THaNonTrackingDetector>() { // Constructor } @@ -111,13 +111,13 @@ void THcShower::Setup(const char* name, const char* description) // cout << "---------------------------------------------------------------\n"; - cout << "From THcShower::Setup: created Shower planes for " - << GetApparatus()->GetName() << ": "; - - for(UInt_t i=0;i < fNTotLayers;i++) { - cout << fLayerNames[i]; - i < fNTotLayers-1 ? cout << ", " : cout << ".\n"; - } + _logger->info("From THcShower::Setup: created Shower planes for {} ", GetApparatus()->GetName()); + //cout << "From THcShower::Setup: created Shower planes for " + // << GetApparatus()->GetName() << ": "; + //for(UInt_t i=0;i < fNTotLayers;i++) { + // cout << fLayerNames[i]; + // i < fNTotLayers-1 ? cout << ", " : cout << ".\n"; + //} // if(fHasArray) // cout << fLayerNames[fNTotLayers-1] << " has fly\'s eye configuration\n"; diff --git a/src/THcShower.h b/src/THcShower.h index c03fa43..5c102fc 100644 --- a/src/THcShower.h +++ b/src/THcShower.h @@ -15,7 +15,9 @@ #include "THcShowerHit.h" #include "TMath.h" -class THcShower : public THaNonTrackingDetector, public THcHitList { +#include "Logger.h" + +class THcShower : public hcana::ConfigLogging<THaNonTrackingDetector>, public THcHitList { public: THcShower( const char* name, const char* description = "", -- GitLab