diff --git a/src/Logger.h b/src/Logger.h index 938e1248324d89e00040b72336bcfa74fe77b8ef..ed5d16f93ebf02aace8c2c904a825e6ae3a01e4b 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 e4101d6293ec9d1f7cb9b3ec3f605272946d26c1..86fad41ee84af64163f5e6728a0ca66b02a0d0f9 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 80208f02d1b44ed4153f98f7c0dee446c80447e6..16db1e3682d6c5f9d3c36c5c69a6bfbca1535dc2 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 a2a71d2f1e559f87d8fa4f785d05c85e8b8ad9d0..b21a795f92c25203105a638ba52b029ecc1a1348 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 30f3d6cfe54726ef37bba0d9b326bccf5e49dcbf..74356d4b1c37d1582d70fa85f95f5d2f2bf9f02c 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 924c38d830da6ec15b1327cdf4f0dc4916ae656d..d9e082f125c17f2d3c20396f53c1407f472e1cd5 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 6a4a1b207536cc17cd50fe2bd73c6c8a3a70594e..2d540230c3b02917d0a0fc11ce21b3c7327c61d6 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 b222cf4173bbfa4de38ef1ac0a4eb9e4c409938e..eb4f21802312d174d6323a31e8d2533ff9eb2f8f 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 dce91765b5d04c85f9d41ecaf4ce85ae2c27ea16..3113776ffe89645a48c610ce7a0ee85d667e791b 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 423a75e9c0ffd07c749fc74a9ca776279482235f..5a18f4527bce089f69f4962ecef315b94685d0dc 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 a3efe12a20546e65b28743257995e239e42508ef..6fdada9b2bba7571e1c7badb4a61c5ae9d88ba61 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 38b192a1c61050f35d6f6e0db8a23255ef203f26..2f31c685684bed50e0070fc6710051eddd9ddb4b 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 628af3b3eb2df70b7ae5cc1a3fc68e245bb61baf..85f41a13ed4a347c612ca288a924627514963605 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 a30aa742e95de64053103e676b93d87b0738eec5..212d4f97563ae2042d853f0dec458db739adad25 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 ae23af024489e6cf8e2729c43a3dba4d17ed8210..fd5fd0195348e9fa365b098f9794b85a9341ae48 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 c03fa438c21b47eec961d19e619ec121d8cd6030..5c102fc23f0d3c0ff50175736557e26e246f753c 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 = "",