diff --git a/app/PrepareNEUT.cxx b/app/PrepareNEUT.cxx index d95d069..10cab79 100644 --- a/app/PrepareNEUT.cxx +++ b/app/PrepareNEUT.cxx @@ -1,416 +1,416 @@ #include "FitLogger.h" #include "PlotUtils.h" #include "StatUtils.h" #include "TFile.h" #include "TH1D.h" #include "TTree.h" #include #include // If you don't have NEUT enabled, you shouldn't compile this... #include "neutpart.h" #include "neutvect.h" std::string fInputFiles = ""; std::string fOutputFile = ""; std::string fFluxFile = ""; bool fFluxInGeV = false; bool fIsMonoEFlux = false; double fMonoEEnergy = 0xdeadbeef; void PrintOptions(); void ParseOptions(int argc, char *argv[]); void AddMonoRateHistogram(std::string inputList, double MonoE, std::string output); void CreateRateHistogram(std::string inputList, std::string flux, std::string output); //******************************* int main(int argc, char *argv[]) { //******************************* - LOG_VERB(FitPar::Config().GetParI("VERBOSITY")); - ERR_VERB(FitPar::Config().GetParI("ERROR")); + SETVERBOSITY(FitPar::Config().GetParI("VERBOSITY")); + SETERRVERBOSITY(FitPar::Config().GetParI("ERROR")); ParseOptions(argc, argv); NUIS_LOG(FIT, "Running PrepareNEUT"); if (fIsMonoEFlux) { AddMonoRateHistogram(fInputFiles, fMonoEEnergy, fOutputFile); } else { CreateRateHistogram(fInputFiles, fFluxFile, fOutputFile); } }; void AddMonoRateHistogram(std::string inputList, double MonoE, std::string output) { // Need to allow for more than one file... will do soon TChain *tn = new TChain("neuttree"); std::vector inputs = GeneralUtils::ParseToStr(inputList, ","); for (std::vector::iterator it = inputs.begin(); it != inputs.end(); ++it) { NUIS_LOG(FIT, "Adding " << *it << " to the output"); tn->AddFile((*it).c_str()); } if (inputs.size() > 1 && output.empty()) { NUIS_ABORT("You must provide a new output file name if you want to have " "more than 1 input file!"); } int nevts = tn->GetEntries(); if (!nevts) { NUIS_ABORT("Either the input file is not from NEUT, or it's empty..."); } NeutVect *fNeutVect = NULL; tn->SetBranchAddress("vectorbranch", &fNeutVect); TH1D *fluxHist = new TH1D("flux", "flux", 1000, 0, fFluxInGeV ? 10 : 10000); fluxHist->Fill(MonoE); fluxHist->Scale(1, "width"); // Make Event Hist TH1D *xsecHist = (TH1D *)fluxHist->Clone(); xsecHist->Reset(); // Make a total cross section hist for shits and giggles TH1D *entryHist = (TH1D *)xsecHist->Clone(); double MeanE = 0; for (int i = 0; i < nevts; ++i) { tn->GetEntry(i); NeutPart *part = fNeutVect->PartInfo(0); double E = part->fP.E(); double xsec = fNeutVect->Totcrs; // Unit conversion if (fFluxInGeV) E *= 1E-3; xsecHist->Fill(E, xsec); entryHist->Fill(E); MeanE += E; if (i % (nevts / 20) == 0) { NUIS_LOG(FIT, "Processed " << i << "/" << nevts << " NEUT events."); } } MeanE /= double(nevts); NUIS_LOG(FIT, "Processed all events"); xsecHist->Divide(entryHist); // This will be the evtrt histogram TH1D *evtHist = (TH1D *)xsecHist->Clone(); evtHist->Multiply(fluxHist); // Check whether the overflow is empty. If not, advise that either the wrong // flux histogram or units were used... // If the events were generated with a limited range of the flux histogram, // this may be benign if (evtHist->Integral(0, -1) != evtHist->Integral() || evtHist->Integral(0, -1) == 0) { NUIS_ERR(WRN, "The input file(" << evtHist->Integral(0, -1) << ") and flux histogram provided do not match... "); NUIS_ERR(WRN, "Are the units correct (MeanE = " << MeanE << ", FluxHistoUpperLim: " << fluxHist->GetXaxis()->GetBinUpEdge(1000) << ")? Did you provide the correct flux file?"); NUIS_ERR(WRN, "Use output with caution..."); } // Pick where the output should go TFile *outFile = NULL; if (!output.empty()) { NUIS_LOG(FIT, "Saving histograms in " << output); outFile = new TFile(output.c_str(), "RECREATE"); } else { NUIS_LOG(FIT, "Saving histograms in " << inputs[0]); outFile = new TFile(inputs[0].c_str(), "UPDATE"); } outFile->cd(); std::string xsec_name = "xsec_PrepareNeut"; std::string flux_name = "flux_PrepareNeut"; std::string rate_name = "evtrt_PrepareNeut"; if (output.empty()) { // Check whether we should overwrite existing histograms std::string input_xsec = PlotUtils::GetObjectWithName(outFile, "xsec"); std::string input_flux = PlotUtils::GetObjectWithName(outFile, "flux"); std::string input_rate = PlotUtils::GetObjectWithName(outFile, "evtrt"); if (!input_xsec.empty()) { NUIS_LOG(FIT, "Updating histogram: " << input_xsec); xsec_name = input_xsec; } if (!input_flux.empty()) { NUIS_LOG(FIT, "Updating histogram: " << input_flux); flux_name = input_flux; } if (!input_rate.empty()) { NUIS_LOG(FIT, "Updating histogram: " << input_rate); rate_name = input_rate; } } else { NUIS_LOG(FIT, "Cloning neuttree into output file."); StopTalking(); TTree *newtree = (TTree *)tn->CloneTree(-1, "fast"); StartTalking(); newtree->Write(); } xsecHist->Write(xsec_name.c_str(), TObject::kOverwrite); fluxHist->Write(flux_name.c_str(), TObject::kOverwrite); evtHist->Write(rate_name.c_str(), TObject::kOverwrite); outFile->Close(); } //******************************* void CreateRateHistogram(std::string inputList, std::string flux, std::string output) { //******************************* // Need to allow for more than one file... will do soon TChain *tn = new TChain("neuttree"); std::vector inputs = GeneralUtils::ParseToStr(inputList, ","); for (std::vector::iterator it = inputs.begin(); it != inputs.end(); ++it) { NUIS_LOG(FIT, "Adding " << *it << " to the output"); tn->AddFile((*it).c_str()); } if (inputs.size() > 1 && output.empty()) { NUIS_ABORT("You must provide a new output file name if you want to have " "more than 1 input file!"); } int nevts = tn->GetEntries(); if (!nevts) { NUIS_ABORT("Either the input file is not from NEUT, or it's empty..."); } NeutVect *fNeutVect = NULL; tn->SetBranchAddress("vectorbranch", &fNeutVect); // Get Flux Hist std::vector fluxvect = GeneralUtils::ParseToStr(flux, ","); TH1D *fluxHist = NULL; if (fluxvect.size() > 1) { TFile *fluxfile = new TFile(fluxvect[0].c_str(), "READ"); fluxHist = (TH1D *)fluxfile->Get(fluxvect[1].c_str()); fluxHist->SetDirectory(0); } else { NUIS_ABORT("NO FLUX SPECIFIED"); } // Decide what type of flux was given if (fFluxInGeV) { NUIS_LOG(FIT, "Assuming flux histogram is in GeV"); } else { NUIS_LOG(FIT, "Assuming flux histogram is in MeV"); } // Make Event Hist TH1D *xsecHist = (TH1D *)fluxHist->Clone(); xsecHist->Reset(); // Make a total cross section hist for shits and giggles TH1D *entryHist = (TH1D *)xsecHist->Clone(); for (int i = 0; i < nevts; ++i) { tn->GetEntry(i); NeutPart *part = fNeutVect->PartInfo(0); double E = part->fP.E(); double xsec = fNeutVect->Totcrs; // Unit conversion if (fFluxInGeV) E *= 1E-3; xsecHist->Fill(E, xsec); entryHist->Fill(E); if (i % (nevts / 20) == 0) { NUIS_LOG(FIT, "Processed " << i << "/" << nevts << " NEUT events." << "(Enu = " << E << ", xsec = " << xsec << ") "); } } NUIS_LOG(FIT, "Processed all events"); xsecHist->Divide(entryHist); // This will be the evtrt histogram TH1D *evtHist = NULL; // If the integral of xsecHist is 0 the input file used a really old version // of NEUT without Totcrs if (!xsecHist->Integral(0, -1)) { NUIS_ERR(WRN, "Old NEUT input file: events will not be correctly normalized"); evtHist = (TH1D *)entryHist->Clone(); if (evtHist->Integral() != 0) evtHist->Scale(fluxHist->Integral() / float(evtHist->Integral())); } else { evtHist = (TH1D *)xsecHist->Clone(); evtHist->Multiply(fluxHist); } // Check whether the overflow is empty. If not, advise that either the wrong // flux histogram or units were used... // If the events were generated with a limited range of the flux histogram, // this may be benign if (evtHist->Integral(0, -1) != evtHist->Integral() || evtHist->Integral(0, -1) == 0) { NUIS_ERR(WRN, "The input file(" << evtHist->Integral(0, -1) << ") and flux histogram provided do not match... "); NUIS_ERR(WRN, "Are the units correct? Did you provide the correct flux file?"); NUIS_ERR(WRN, "Use output with caution..."); } // Pick where the output should go TFile *outFile = NULL; if (!output.empty()) { NUIS_LOG(FIT, "Saving histograms in " << output); outFile = new TFile(output.c_str(), "RECREATE"); } else { NUIS_LOG(FIT, "Saving histograms in " << inputs[0]); outFile = new TFile(inputs[0].c_str(), "UPDATE"); } outFile->cd(); std::string xsec_name = "xsec_PrepareNeut"; std::string flux_name = "flux_PrepareNeut"; std::string rate_name = "evtrt_PrepareNeut"; if (output.empty()) { // Check whether we should overwrite existing histograms std::string input_xsec = PlotUtils::GetObjectWithName(outFile, "xsec"); std::string input_flux = PlotUtils::GetObjectWithName(outFile, "flux"); std::string input_rate = PlotUtils::GetObjectWithName(outFile, "evtrt"); if (!input_xsec.empty()) { NUIS_LOG(FIT, "Updating histogram: " << input_xsec); xsec_name = input_xsec; } if (!input_flux.empty()) { NUIS_LOG(FIT, "Updating histogram: " << input_flux); flux_name = input_flux; } if (!input_rate.empty()) { NUIS_LOG(FIT, "Updating histogram: " << input_rate); rate_name = input_rate; } } else { NUIS_LOG(FIT, "Cloning neuttree into output file."); StopTalking(); TTree *newtree = (TTree *)tn->CloneTree(-1, "fast"); StartTalking(); newtree->Write(); } xsecHist->Write(xsec_name.c_str(), TObject::kOverwrite); fluxHist->Write(flux_name.c_str(), TObject::kOverwrite); evtHist->Write(rate_name.c_str(), TObject::kOverwrite); outFile->Close(); return; } void PrintOptions() { std::cout << "PrepareNEUT NUISANCE app. " << std::endl << "Produces or recalculates evtrt and flux histograms necessary " "for NUISANCE normalization." << std::endl; std::cout << "PrepareNEUT: " << std::endl; std::cout << " [-h,-help,--h,--help]" << std::endl; std::cout << " -i inputfile1.root,inputfile2.root,inputfile3.root,..." << std::endl; std::cout << " Takes any number of files, but assumes all are " "produced with a single flux" << std::endl; std::cout << " -f flux_root_file.root,flux_hist_name" << std::endl; std::cout << " Path to root file containing the flux histogram used " "when generating the NEUT files" << std::endl; std::cout << " [-o outputfile.root] " << std::endl; std::cout << " If an output file is not given, the input file will be used" << std::endl; std::cout << " If more than one input file is given, an output file " "must be given" << std::endl; std::cout << " [-G]" << std::endl; std::cout << " Flux is assumed to be in MeV. This switch indicates " "the input flux is in GeV" << std::endl; std::cout << " [-m E_nu]" << std::endl; std::cout << " Used to add dummy flux and evt rate histograms to " "mono-energetic vectors. Adheres to the -G flag." << std::endl; } void ParseOptions(int argc, char *argv[]) { bool flagopt = false; // If No Arguments print commands for (int i = 1; i < argc; ++i) { if (!std::strcmp(argv[i], "-h")) { flagopt = true; break; } else if (!std::strcmp(argv[i], "-G")) { fFluxInGeV = true; continue; } if (i + 1 != argc) { // Cardfile if (!std::strcmp(argv[i], "-h")) { flagopt = true; break; } else if (!std::strcmp(argv[i], "-i")) { fInputFiles = argv[i + 1]; ++i; } else if (!std::strcmp(argv[i], "-o")) { fOutputFile = argv[i + 1]; ++i; } else if (!std::strcmp(argv[i], "-f")) { fFluxFile = argv[i + 1]; ++i; } else if (!std::strcmp(argv[i], "-m")) { fIsMonoEFlux = true; fMonoEEnergy = GeneralUtils::StrToDbl(argv[i + 1]); ++i; } else { NUIS_ERR(FTL, "ERROR: unknown command line option given! - '" << argv[i] << " " << argv[i + 1] << "'"); PrintOptions(); break; } } } if (fInputFiles == "" && !flagopt) { NUIS_ERR(FTL, "No input file(s) specified!"); flagopt = true; } if (fFluxFile == "" && (!flagopt) && (!fIsMonoEFlux)) { NUIS_ERR(FTL, "No flux input specified!"); flagopt = true; } if (argc < 1 || flagopt) { PrintOptions(); exit(-1); } return; } diff --git a/src/Logger/FitLogger.cxx b/src/Logger/FitLogger.cxx index c94f8af..c6a0759 100644 --- a/src/Logger/FitLogger.cxx +++ b/src/Logger/FitLogger.cxx @@ -1,352 +1,327 @@ // Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret /******************************************************************************* * This file is part of NUISANCE. * * NUISANCE is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * NUISANCE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NUISANCE. If not, see . *******************************************************************************/ #include "FitLogger.h" #include #include namespace Logger { // Logger Variables int log_verb = 4; bool use_colors = true; bool showtrace = true; std::ostream* __LOG_outstream(&std::cout); std::ofstream __LOG_nullstream; // Error Variables int err_verb = 0; std::ostream* __ERR_outstream(&std::cerr); // Extra Variables bool external_verb = false; bool super_rainbow_mode = true; //!< For when fitting gets boring. unsigned int super_rainbow_mode_colour = 0; std::streambuf* default_cout = std::cout.rdbuf(); std::streambuf* default_cerr = std::cerr.rdbuf(); std::ofstream redirect_stream("/dev/null"); int silentfd = open("/dev/null", O_WRONLY); int savedstdoutfd = dup(fileno(stdout)); int savedstderrfd = dup(fileno(stderr)); int nloggercalls = 0; int timelastlog = 0; } // -------- Logging Functions --------- // bool LOGGING(int level) { // std::cout << "LOGGING : " << __FILENAME__ << " " << __FUNCTION__ << // std::endl; return (Logger::log_verb >= (int)__GETLOG_LEVEL(level, __FILENAME__, __FUNCTION__)); }; int __GETLOG_LEVEL(int level, const char* filename, const char* funct) { #ifdef __DEBUG__ int logfile = FitPar::Config().GetParI("logging." + std::string(filename)); if (logfile >= DEB and logfile <= EVT) { level = logfile; } int logfunc = FitPar::Config().GetParI("logging." + std::string(funct)); if (logfunc >= DEB and logfunc <= EVT) { level = logfunc; } #endif return level; }; std::ostream& __OUTLOG(int level, const char* filename, const char* funct, int line) { if (Logger::log_verb < (int)level && Logger::log_verb != (int)DEB) { return (Logger::__LOG_nullstream); } else { if (Logger::use_colors) { switch (level) { case FIT: std::cout << BOLDGREEN; break; case MIN: std::cout << BOLDBLUE; break; case SAM: std::cout << MAGENTA; break; case REC: std::cout << BLUE; break; case SIG: std::cout << GREEN; break; case DEB: std::cout << CYAN; break; default: break; } } switch (level) { case FIT: std::cout << "[LOG Fitter]"; break; case MIN: std::cout << "[LOG Minmzr]"; break; case SAM: std::cout << "[LOG Sample]"; break; case REC: std::cout << "[LOG Reconf]"; break; case SIG: std::cout << "[LOG Signal]"; break; case EVT: std::cout << "[LOG Event ]"; break; case DEB: std::cout << "[LOG DEBUG ]"; break; default: std::cout << "[LOG INFO ]"; break; } // Apply indent if (true) { switch (level) { case FIT: std::cout << ": "; break; case MIN: std::cout << ":- "; break; case SAM: std::cout << ":-- "; break; case REC: std::cout << ":--- "; break; case SIG: std::cout << ":---- "; break; case EVT: std::cout << ":----- "; break; case DEB: std::cout << ":------ "; break; default: std::cout << " "; break; } } if (Logger::use_colors) std::cout << RESET; if (Logger::showtrace) { std::cout << " : " << filename << "::" << funct << "[l. " << line << "] : "; } return *(Logger::__LOG_outstream); } } void SETVERBOSITY(int level) { Logger::log_verb = level; } +void SETERRVERBOSITY(int level) { Logger::err_verb = level; } void SETVERBOSITY(std::string verb) { if (!verb.compare("DEB")) Logger::log_verb = -1; else if (!verb.compare("QUIET")) Logger::log_verb = 0; else if (!verb.compare("FIT")) Logger::log_verb = 1; else if (!verb.compare("MIN")) Logger::log_verb = 2; else if (!verb.compare("SAM")) Logger::log_verb = 3; else if (!verb.compare("REC")) Logger::log_verb = 4; else if (!verb.compare("SIG")) Logger::log_verb = 5; else if (!verb.compare("EVT")) Logger::log_verb = 6; else Logger::log_verb = std::atoi(verb.c_str()); } +//****************************************** +void SETERRVERBOSITY(std::string verb) { + //****************************************** + std::cout << "Setting ERROR VERB" << std::endl; + + if (!verb.compare("ERRQUIET")) + Logger::err_verb = 0; + else if (!verb.compare("FTL")) + Logger::err_verb = 1; + else if (!verb.compare("WRN")) + Logger::err_verb = 2; + // else Logger::err_verb = GeneralUtils::StrToInt(verb); + + std::cout << "Set error verbosity to : " << Logger::err_verb << std::endl; + return; +} + /// Set Trace Option void SETTRACE(bool val) { Logger::showtrace = val; } // ------ ERROR FUNCTIONS ---------- // std::ostream& __OUTERR(int level, const char* filename, const char* funct, int line) { if (Logger::use_colors) std::cerr << RED; switch (level) { case FTL: std::cerr << "[ERR FATAL ]: "; break; case WRN: std::cerr << "[ERR WARN ]: "; break; } if (Logger::use_colors) std::cerr << RESET; // Allows enable error debugging trace if (true or Logger::showtrace) { std::cout << filename << "::" << funct << "[l. " << line << "] : "; } return *(Logger::__ERR_outstream); } // ----------- External Logging ----------- // void SETEXTERNALVERBOSITY(int level) { Logger::external_verb = (level > 0); } void StopTalking() { // Check verbosity set correctly if (!Logger::external_verb) return; // Only redirect if we're not debugging if (Logger::log_verb == (unsigned int)DEB) return; std::cout.rdbuf(Logger::redirect_stream.rdbuf()); std::cerr.rdbuf(Logger::redirect_stream.rdbuf()); shhnuisancepythiaitokay_(); fflush(stdout); fflush(stderr); dup2(Logger::silentfd, fileno(stdout)); dup2(Logger::silentfd, fileno(stderr)); } void StartTalking() { // Check verbosity set correctly if (!Logger::external_verb) return; std::cout.rdbuf(Logger::default_cout); std::cerr.rdbuf(Logger::default_cerr); canihaznuisancepythia_(); fflush(stdout); fflush(stderr); dup2(Logger::savedstdoutfd, fileno(stdout)); dup2(Logger::savedstderrfd, fileno(stderr)); } //****************************************** -void LOG_VERB(std::string verb) { - //****************************************** - - if (!verb.compare("DEB")) - Logger::log_verb = -1; - else if (!verb.compare("QUIET")) - Logger::log_verb = 0; - else if (!verb.compare("FIT")) - Logger::log_verb = 1; - else if (!verb.compare("MIN")) - Logger::log_verb = 2; - else if (!verb.compare("SAM")) - Logger::log_verb = 3; - else if (!verb.compare("REC")) - Logger::log_verb = 4; - else if (!verb.compare("SIG")) - Logger::log_verb = 5; - else if (!verb.compare("EVT")) - Logger::log_verb = 6; - // else Logger::log_verb = GeneralUtils::StrToInt(verb); - - std::cout << "Set logging verbosity to : " << Logger::log_verb << std::endl; - return; -} - -//****************************************** -void ERR_VERB(std::string verb) { - //****************************************** - std::cout << "Setting ERROR VERB" << std::endl; - - if (!verb.compare("ERRQUIET")) - Logger::err_verb = 0; - else if (!verb.compare("FTL")) - Logger::err_verb = 1; - else if (!verb.compare("WRN")) - Logger::err_verb = 2; - // else Logger::err_verb = GeneralUtils::StrToInt(verb); - - std::cout << "Set error verbosity to : " << Logger::err_verb << std::endl; - return; -} - -//****************************************** bool LOG_LEVEL(int level) { //****************************************** if (Logger::log_verb == (unsigned int)DEB) { return true; } if (Logger::log_verb < (int)level) { return false; } return true; } void SET_TRACE(bool val) { Logger::showtrace = val; } //****************************************** std::ostream& _LOG(int level, const char* filename, const char* func, int line) //****************************************** { return __OUTLOG(level, filename, func, line); } //****************************************** std::ostream& _ERR(int level, const char* filename, const char* func, int line) //****************************************** { if (Logger::use_colors) std::cerr << RED; if (Logger::showtrace) { std::cout << filename << "::" << func << "[l. " << line << "] : "; } switch (level) { case FTL: std::cerr << "[ERR FATAL ]: "; break; case WRN: std::cerr << "[ERR WARN ] : "; break; } if (Logger::use_colors) std::cerr << RESET; return *Logger::__ERR_outstream; } diff --git a/src/Logger/FitLogger.h b/src/Logger/FitLogger.h index 4dbd27a..848b3b4 100644 --- a/src/Logger/FitLogger.h +++ b/src/Logger/FitLogger.h @@ -1,199 +1,204 @@ // Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret /******************************************************************************* * This file is part of NUISANCE. * * NUISANCE is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * NUISANCE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NUISANCE. If not, see . *******************************************************************************/ #ifndef FITLOGGER_HPP #define FITLOGGER_HPP /*! * \addtogroup FitBase * @{ */ #include #include #include #include #include "TRandom3.h" #include "Initialiser.h" #include "NuisConfig.h" #define RESET "\033[0m" #define BLACK "\033[30m" /* Black */ #define RED "\033[31m" /* Red */ #define GREEN "\033[32m" /* Green */ #define YELLOW "\033[33m" /* Yellow */ #define BLUE "\033[34m" /* Blue */ #define MAGENTA "\033[35m" /* Magenta */ #define CYAN "\033[36m" /* Cyan */ #define WHITE "\033[37m" /* White */ #define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ #define BOLDRED "\033[1m\033[31m" /* Bold Red */ #define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ #define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ #define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ #define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ #define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ #define BOLDWHITE "\033[1m\033[37m" /* Bold White */ namespace Logger { extern int log_verb; //!< Current VERBOSITY extern int err_verb; //!< Current ERROR VERBOSITY extern bool external_verb; extern bool use_colors; //!< Use BASH Terminal Colors Flag extern bool super_rainbow_mode; //!< For when fitting gets boring. extern unsigned int super_rainbow_mode_colour; extern bool showtrace; // Quick Tracing for debugging extern int nloggercalls; extern int timelastlog; extern std::streambuf *default_cout; //!< Where the STDOUT stream is currently directed extern std::streambuf *default_cerr; //!< Where the STDERR stream is currently directed extern std::ofstream redirect_stream; //!< Where should unwanted messages be thrown } // namespace Logger /// Returns full path to file currently in #define __FILENAME__ \ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) // ------ LOGGER FUNCTIONS ------------ // namespace Logger { /// NULL Output Stream extern std::ofstream __LOG_nullstream; /// Logging Stream extern std::ostream *__LOG_outstream; } // namespace Logger /// Fitter VERBOSITY Enumerations /// These go through the different depths of the fitter. /// /// 0 QUIET - Little output. /// 1 FIT - Top Level Minimizer Status /// 2 MIN - Output from the FCN Minimizer Functions /// 3 SAM - Output from each of the samples during setup etc /// 4 REC - Output during each reconfigure. Percentage progress etc. /// 5 SIG - Output during every signal event that is found. /// 6 EVT - Output during every event. /// -1 DEB - Will print only debugging info wherever a NUIS_LOG(DEB) statement was /// made enum __LOG_levels { QUIET = 0, FIT, MIN, SAM, REC, SIG, EVT, DEB }; /// Returns log level for a given file/function int __GETLOG_LEVEL(int level, const char *filename, const char *funct); bool LOG_LEVEL(int level); /// Actually runs the logger std::ostream &__OUTLOG(int level, const char *filename, const char *funct, int line); /// Global Logging Definitions #define NUIS_LOGN(level, stream) \ { \ if (LOG_LEVEL(level)) { \ __OUTLOG(level, __FILENAME__, __FUNCTION__, __LINE__) << stream; \ } \ }; /// Global Logging Definitions #define NUIS_LOG(level, stream) NUIS_LOGN(level, stream << std::endl) #define BREAK(level) \ { \ \ if (LOG_LEVEL(level)) { \ __OUTLOG(level, __FILENAME__, __FUNCTION__, __LINE__) << std::endl; \ } \ }; /// Return whether logging level is valid bool LOGGING(int level); /// Set Global Verbosity void SETVERBOSITY(int level); /// Set Global Verbosity from String void SETVERBOSITY(std::string verb); +/// Set Global Verbosity +void SETERRVERBOSITY(int level); + +/// Set Global Verbosity from String +void SETERRVERBOSITY(std::string verb); + + + /// Set Trace Option void SETTRACE(bool val); -void LOG_VERB(std::string verb); -void ERR_VERB(std::string verb); - // ----------- ERROR FUNCTIONS ---------- // /// Error Stream extern std::ostream *__ERR_outstream; /// Fitter ERROR VERBOSITY Enumerations /// /// 0 QUIET - No Error Output /// 1 FTL - Show errors only if fatal /// 2 WRN - Show Warning messages enum __ERR_levels { ERRQUIET = 0, FTL, WRN }; /// Actually runs the error messager std::ostream &__OUTERR(int level, const char *filename, const char *funct, int line); /// Error Logging Function #define NUIS_ERR(level, stream) \ { \ __OUTERR(level, __FILENAME__, __FUNCTION__, __LINE__) \ << stream << std::endl; \ }; // ----------- ERROR HANDLING ------------- // /// Exit the program with given error message stream #define NUIS_ABORT(stream) \ { \ __OUTERR(FTL, __FILENAME__, __FUNCTION__, __LINE__) \ << stream << std::endl; \ __OUTERR(FTL, __FILENAME__, __FUNCTION__, __LINE__) \ << "Attempting to save output file." << std::endl; \ if (Config::Get().out && Config::Get().out->IsOpen()) { \ Config::Get().out->Write(); \ Config::Get().out->Close(); \ __OUTERR(FTL, __FILENAME__, __FUNCTION__, __LINE__) \ << "Done." << std::endl; \ } else { \ __OUTERR(FTL, __FILENAME__, __FUNCTION__, __LINE__) \ << "No output file set." << std::endl; \ } \ __OUTERR(FTL, __FILENAME__, __FUNCTION__, __LINE__) \ << "Exiting!" << std::endl; \ std::abort(); \ } // ----------- External Logging ----------- // void SETEXTERNALVERBOSITY(int level); void StopTalking(); void StartTalking(); extern "C" { void shhnuisancepythiaitokay_(void); void canihaznuisancepythia_(void); } #endif