Rosetta  2016.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
basic::Tracer Class Reference

Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for all your regular io. Channel argument must be related to the location of the source file. For example if you create Tracer object in src/basic/scoring/myfile.cc, then channel must be something like 'src.basic.scoring.myfile'. More...

#include <Tracer.hh>

Inheritance diagram for basic::Tracer:
Inheritance graph
[legend]

Classes

class  TracerProxy
 Small inner class acting as a proxy to an object that hold it. More...
 

Public Types

typedef std::ostream * OstreamPointer
 
- Public Types inherited from utility::pointer::ReferenceCount
typedef platform::Size Size
 
typedef platform::Size size_type
 

Public Member Functions

 Tracer (std::string const &channel="", TracerPriority priority=t_info, bool muted_by_default=false)
 Create Tracer object with given channel and priority. More...
 
 Tracer (std::string const &channel, std::string const &channel_color, std::string const &channel_name_color="", TracerPriority priority=t_info, bool muted_by_default=false)
 Create Tracer object with channel color, channel name color and given channel and priority. More...
 
virtual ~Tracer ()
 
void init (Tracer const &tr)
 re-init using data from another tracer object. More...
 
void flush_all_channels ()
 flush tracer buffer and flush buffers of all sub-channels ie: Fatal, Error, Warning, Info, Debug, Trace More...
 
bool visible () const
 Is this tracer currently visible?. More...
 
bool visible (int priority) const
 is this tracer visible, if it used the given priority value? More...
 
int priority () const
 get/set tracer priority level. More...
 
Traceroperator() (int priority)
 
void priority (int priority)
 
std::string const & channel () const
 
std::string const & channel_color ()
 
void channel_color (std::string const &color)
 
std::string const & channel_name_color ()
 
void channel_name_color (std::string const &color)
 
- Public Member Functions inherited from basic::basic_otstream< CharT, Traits >
 basic_otstream ()
 
virtual ~basic_otstream ()
 
bool is_flushed () const
 Return true if inner string buffer is empty. More...
 
- Public Member Functions inherited from utility::pointer::ReferenceCount
 ReferenceCount ()
 Default constructor. More...
 
virtual ~ReferenceCount ()
 

Static Public Member Functions

static OstreamPointerfinal_stream ()
 set ios hook for final tracer stream (deafult is std::cout). More...
 
static void set_new_final_stream (std::ostream *new_final_stream)
 
static void set_default_final_stream ()
 
static void set_ios_hook (otstreamOP tr, std::string const &monitoring_channels_list, bool raw=true)
 set ios hook for all tracer io operation. More...
 
static std::string const & get_all_channels_string ()
 
static TracerOptionstracer_options ()
 get/set tracer options - global options for Tracer IO. More...
 
static bool super_mute ()
 global super mute flag that allow to mute all io no matter what. More...
 
static void super_mute (bool f)
 
static void flush_all_tracers ()
 
static void calculate_tracer_visibilities ()
 This function should be invoked after the options system has been initialized, so that the visibility for all tracers that have so far been constructed and have been waiting for the options system to be initialized can now have their visibility calculated. After this function completes, all newly-constructed Tracers will calculate their visibility in their constructors. Visibility is no longer be calculated on a just-in-time basis and stored in mutable data members. More...
 

Public Attributes

TracerProxy Fatal
 channels with predefined priority levels. More...
 
TracerProxy Error
 
TracerProxy Warning
 
TracerProxy Info
 
TracerProxy Debug
 
TracerProxy Trace
 

Static Public Attributes

static utility::CSI_Sequence Reset
 
static utility::CSI_Sequence Bold
 
static utility::CSI_Sequence Underline
 
static utility::CSI_Sequence Black
 
static utility::CSI_Sequence Red
 
static utility::CSI_Sequence Green
 
static utility::CSI_Sequence Yellow
 
static utility::CSI_Sequence Blue
 
static utility::CSI_Sequence Magenta
 
static utility::CSI_Sequence Cyan
 
static utility::CSI_Sequence White
 
static utility::CSI_Sequence bgBlack
 
static utility::CSI_Sequence bgRed
 
static utility::CSI_Sequence bgGreen
 
static utility::CSI_Sequence bgYellow
 
static utility::CSI_Sequence bgBlue
 
static utility::CSI_Sequence bgMagenta
 
static utility::CSI_Sequence bgCyan
 
static utility::CSI_Sequence bgWhite
 

Protected Member Functions

virtual void t_flush (std::string const &)
 overload member function. More...
 

Private Member Functions

void init (std::string const &channel, std::string const &channel_color, std::string const &channel_name_color, TracerPriority priority, bool muted_by_default)
 init Tracer object with given parameters. This is a helper function to be called from various constructors More...
 
 Tracer (Tracer const &tr)
 copy constructor. More...
 
template<class out_stream >
void prepend_channel_name (out_stream &sout, std::string const &str)
 
void calculate_visibility ()
 calcualte visibility of the current object depending of the channel name and priority. More...
 
bool visibility_calculated () const
 Adding this function to get around unused class data member warnings; you should never have to worry about whether the visibility for a Tracer has been calculated. More...
 

Static Private Member Functions

static bool in (utility::vector1< std::string > const &, std::string const channel, bool strict)
 return true if channel is inside vector, some logic apply. More...
 
static bool calculate_tracer_level (utility::vector1< std::string > const &v, std::string const ch, bool strict, int &res)
 calculate channel priority with hierarchy in mind. More...
 
static void register_tracer (Tracer *tracer)
 Tracers must register themselves with the static array of all tracers so that they can be flushed en masse if need be. This function is thread safe. More...
 
static void calculate_visibility (std::string const &channel, int priority, bool &visible, bool &muted, int &mute_level_, bool muted_by_default)
 
static void safe_output (std::string const &)
 Output a message in a manner that is safe if the Tracers/output are poorly initialized. More...
 
static otstreamOPios_hook ()
 link to Tracer like object where all output for selecting channels should go. More...
 
static boolios_hook_raw_ ()
 should the ios_hook_ the raw output? More...
 
static boolsuper_mute_ ()
 global super mute flag that allow to mute all io no matter what. More...
 

Private Attributes

std::string channel_
 Data members. More...
 
std::string channel_color_
 default colors for tracer output and tracer channel-name string (ie color of string such as: 'core.pose:') More...
 
std::string channel_name_color_
 
int priority_
 channel output priority level More...
 
int mute_level_
 channel muted priority level (above which level is channel muted), calculated using user suppied -level and -levels options More...
 
bool visible_
 is channel visible? More...
 
bool muted_
 is channel muted ? More...
 
bool muted_by_default_
 is channel muted by default? More...
 
bool begining_of_the_line_
 is current printing position a begining of the line? More...
 
bool visibility_calculated_
 is channel visibility already calculated? More...
 

Static Private Attributes

static utility::vector1
< std::string > 
monitoring_list_
 list of channels for which outout should be redirected. More...
 
static TracerOptions tracer_options_
 global option collection for Tracer IO. More...
 
static bool initial_tracers_visibility_calculated_
 
static int mpi_rank_
 Mpi rank is this process More...
 

Friends

TracerT (std::string const &, TracerPriority)
 T is special function for assign tracer property on the static object. More...
 

Detailed Description

Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for all your regular io. Channel argument must be related to the location of the source file. For example if you create Tracer object in src/basic/scoring/myfile.cc, then channel must be something like 'src.basic.scoring.myfile'.

Member Typedef Documentation

Constructor & Destructor Documentation

basic::Tracer::Tracer ( std::string const &  channel = "",
TracerPriority  priority = t_info,
bool  muted_by_default = false 
)

Create Tracer object with given channel and priority.

Constructor of Tracer object. Since most of the Tracer object will be created as static - they Constuctor will be called before Option system is initialized. So we can't really calculate any vizibility or priority here. Such calculation should be done later, whe first IO operation happend.

Todo:
Default Tracer level should probably be modified to t_info here and in options defn.

References init().

basic::Tracer::Tracer ( std::string const &  channel,
std::string const &  channel_color,
std::string const &  channel_name_color = "",
TracerPriority  priority = t_info,
bool  muted_by_default = false 
)

Create Tracer object with channel color, channel name color and given channel and priority.

References init().

basic::Tracer::~Tracer ( )
virtual
basic::Tracer::Tracer ( Tracer const &  tr)
private

copy constructor.

Functions

Member Function Documentation

bool basic::Tracer::calculate_tracer_level ( utility::vector1< std::string > const &  v,
std::string const  ch,
bool  strict,
int res 
)
staticprivate

calculate channel priority with hierarchy in mind.

Same as before but return integer value for matched channel or closest match (we asume that 'v' in levels format, ie like: <channel name>="">:level )

References ObjexxFCL::len(), ObjexxFCL::lowercased(), basic::options::OptionKeys::in::file::s, safe_output(), amino_acids::size, utility::string2int(), utility::string_split(), basic::t_debug, basic::t_error, basic::t_fatal, basic::t_info, basic::t_trace, and basic::t_warning.

Referenced by calculate_visibility().

void basic::Tracer::calculate_tracer_visibilities ( )
static

This function should be invoked after the options system has been initialized, so that the visibility for all tracers that have so far been constructed and have been waiting for the options system to be initialized can now have their visibility calculated. After this function completes, all newly-constructed Tracers will calculate their visibility in their constructors. Visibility is no longer be calculated on a just-in-time basis and stored in mutable data members.

References basic::TracerManager::get_instance(), test.T200_Scoring::ii, and initial_tracers_visibility_calculated_.

void basic::Tracer::calculate_visibility ( )
private

calcualte visibility of the current object depending of the channel name and priority.

Calculate visibility of current Tracer object and all of its proxies

References basic::Tracer::TracerProxy::calculate_visibility(), channel_, Debug, Error, Fatal, Info, mute_level_, muted_, muted_by_default_, priority_, Trace, visibility_calculated_, visible_, and Warning.

Referenced by basic::Tracer::TracerProxy::calculate_visibility(), init(), and basic::T().

void basic::Tracer::calculate_visibility ( std::string const &  channel,
int  priority,
bool visible,
bool muted,
int mute_level_,
bool  muted_by_default 
)
staticprivate

Calculate visibility (static version) of current Tracer object using channel name and priority. result stored in 'muted' and 'visible'.

References calculate_tracer_level(), in(), basic::TracerOptions::level, basic::TracerOptions::levels, utility::mpi_nprocs(), utility::mpi_rank(), mpi_rank_, basic::TracerOptions::muted, tracer_options_, basic::TracerOptions::unmuted, and visible().

std::string const& basic::Tracer::channel ( ) const
inline

References channel_.

Referenced by init(), and basic::show_time().

std::string const& basic::Tracer::channel_color ( )
inline

References channel_color_.

Referenced by init().

void basic::Tracer::channel_color ( std::string const &  color)
inline

References channel_color_.

std::string const& basic::Tracer::channel_name_color ( )
inline

References channel_name_color_.

Referenced by init().

void basic::Tracer::channel_name_color ( std::string const &  color)
inline

References channel_name_color_.

Tracer::OstreamPointer & basic::Tracer::final_stream ( )
static

set ios hook for final tracer stream (deafult is std::cout).

References utility::io::oc::cout.

Referenced by safe_output(), set_default_final_stream(), set_new_final_stream(), and t_flush().

void basic::Tracer::flush_all_channels ( )

flush tracer buffer and flush buffers of all sub-channels ie: Fatal, Error, Warning, Info, Debug, Trace

References Debug, Error, Fatal, Info, Trace, test.T850_SubClassing::v, and Warning.

Referenced by main().

void basic::Tracer::flush_all_tracers ( )
static
std::string const & basic::Tracer::get_all_channels_string ( )
static

Referenced by t_flush().

bool basic::Tracer::in ( utility::vector1< std::string > const &  v,
std::string const  ch,
bool  strict 
)
staticprivate

return true if channel is inside vector, some logic apply.

Check if string representing channel 'ch' is in vector<string> v. Return true if channel is in vector, false otherwise. Two mode of operation: Strict: strict==true - channels compared verbatim. Regular: strict==false - comparing with hierarchy in mind, ie: ch='basic.pose' v[0]='basic' –> will yield true.

References basic::options::OptionKeys::in::file::s, and amino_acids::size.

Referenced by calculate_visibility(), and t_flush().

void basic::Tracer::init ( std::string const &  channel,
std::string const &  channel_color,
std::string const &  channel_name_color,
TracerPriority  priority,
bool  muted_by_default 
)
private
void basic::Tracer::init ( Tracer const &  tr)

re-init using data from another tracer object.

re-init using data from another tracer object.

References begining_of_the_line_, calculate_visibility(), channel_, initial_tracers_visibility_calculated_, mute_level_, muted_, priority_, visibility_calculated_, and visible_.

otstreamOP & basic::Tracer::ios_hook ( )
staticprivate

link to Tracer like object where all output for selecting channels should go.

static data members

Referenced by safe_output(), set_ios_hook(), and t_flush().

bool & basic::Tracer::ios_hook_raw_ ( )
staticprivate

should the ios_hook_ the raw output?

References basic::options::OptionKeys::out::file::raw.

Referenced by set_ios_hook(), and t_flush().

Tracer & basic::Tracer::operator() ( int  priority)

References priority().

template<class out_stream >
void basic::Tracer::prepend_channel_name ( out_stream &  sout,
std::string const &  str 
)
private

Write the contents of str to sout prepending the channel name on each line if the print_channel_name flag is set.

References begining_of_the_line_, channel_, channel_color_, channel_name_color_, mpi_rank_, basic::TracerOptions::print_channel_name, Reset, basic::options::OptionKeys::in::file::s, utility::timestamp(), basic::TracerOptions::timestamp, and tracer_options_.

int basic::Tracer::priority ( ) const
inline

get/set tracer priority level.

References priority_.

Referenced by init(), operator()(), and priority().

void basic::Tracer::priority ( int  priority)
static void basic::Tracer::register_tracer ( Tracer tracer)
staticprivate

Tracers must register themselves with the static array of all tracers so that they can be flushed en masse if need be. This function is thread safe.

void basic::Tracer::safe_output ( std::string const &  message)
staticprivate

Output a message in a manner that is safe if the Tracers/output are poorly initialized.

References utility::io::oc::cerr, final_stream(), and ios_hook().

Referenced by calculate_tracer_level().

void basic::Tracer::set_default_final_stream ( )
static
void basic::Tracer::set_ios_hook ( otstreamOP  tr,
std::string const &  monitoring_channels_list,
bool  raw = true 
)
static

set ios hook for all tracer io operation.

Parameters
monitoring_channels_listis space separated list of channels.

Set OStringStream object to which all Tracers output listed in the monitoring_channels_list should be copied. Note this copies the output of channels even if they are invisible or muted. When raw==false same as above above but gives the option get only the visible and unmuted tracers. It can be useful to get the raw output for applications like the comparing tracers, where the output should not change with command line parameters. It can be useful to get the non-raw output in applications like using the jd2 with MPI, where the output each job should match the output if it was run on a single processor.

References ios_hook(), ios_hook_raw_(), monitoring_list_, basic::options::OptionKeys::out::file::raw, utility::split(), and tr().

void basic::Tracer::set_new_final_stream ( std::ostream *  new_final_stream)
static

References final_stream().

static bool basic::Tracer::super_mute ( )
inlinestatic

global super mute flag that allow to mute all io no matter what.

References super_mute_().

static void basic::Tracer::super_mute ( bool  f)
inlinestatic
bool & basic::Tracer::super_mute_ ( )
staticprivate

global super mute flag that allow to mute all io no matter what.

References basic::options::OptionKeys::out::mute.

Referenced by super_mute(), and t_flush().

void basic::Tracer::t_flush ( std::string const &  str)
protectedvirtual

overload member function.

Inform Tracer that is contents was modified, and IO is in order.

Reimplemented from basic::basic_otstream< CharT, Traits >.

Reimplemented in basic::MemTracer.

References channel_, final_stream(), get_all_channels_string(), in(), initial_tracers_visibility_calculated_, ios_hook(), ios_hook_raw_(), monitoring_list_, super_mute_(), visibility_calculated_, and visible().

Referenced by basic::MemTracer::t_flush().

static TracerOptions& basic::Tracer::tracer_options ( )
inlinestatic

get/set tracer options - global options for Tracer IO.

References tracer_options_.

bool basic::Tracer::visibility_calculated ( ) const
inlineprivate

Adding this function to get around unused class data member warnings; you should never have to worry about whether the visibility for a Tracer has been calculated.

References visibility_calculated_.

bool basic::Tracer::visible ( ) const
inline

Is this tracer currently visible?.

References visible_.

Referenced by calculate_visibility(), main(), basic::MemTracer::t_flush(), and t_flush().

bool basic::Tracer::visible ( int  priority) const

is this tracer visible, if it used the given priority value?

References mute_level_, and muted_.

Friends And Related Function Documentation

Tracer& T ( std::string const &  ,
TracerPriority   
)
friend

T is special function for assign tracer property on the static object.

Return reference to static Tracer object (after setting it channel and priority).

Member Data Documentation

bool basic::Tracer::begining_of_the_line_
private

is current printing position a begining of the line?

Referenced by init(), prepend_channel_name(), and basic::T().

utility::CSI_Sequence basic::Tracer::bgBlack
static
utility::CSI_Sequence basic::Tracer::bgBlue
static
utility::CSI_Sequence basic::Tracer::bgCyan
static
utility::CSI_Sequence basic::Tracer::bgGreen
static
utility::CSI_Sequence basic::Tracer::bgMagenta
static
utility::CSI_Sequence basic::Tracer::bgRed
static
utility::CSI_Sequence basic::Tracer::bgWhite
static
utility::CSI_Sequence basic::Tracer::bgYellow
static
utility::CSI_Sequence basic::Tracer::Black
static
utility::CSI_Sequence basic::Tracer::Blue
static

Referenced by mg_modeler_test(), and swa_rna_sample().

utility::CSI_Sequence basic::Tracer::Bold
static
std::string basic::Tracer::channel_
private
std::string basic::Tracer::channel_color_
private

default colors for tracer output and tracer channel-name string (ie color of string such as: 'core.pose:')

Referenced by channel_color(), init(), and prepend_channel_name().

std::string basic::Tracer::channel_name_color_
private
utility::CSI_Sequence basic::Tracer::Cyan
static
TracerProxy basic::Tracer::Debug
TracerProxy basic::Tracer::Error
TracerProxy basic::Tracer::Fatal

channels with predefined priority levels.

Referenced by calculate_visibility(), check_option_conflicts(), flush_all_channels(), and ~Tracer().

utility::CSI_Sequence basic::Tracer::Green
static
TracerProxy basic::Tracer::Info
bool basic::Tracer::initial_tracers_visibility_calculated_
staticprivate
utility::CSI_Sequence basic::Tracer::Magenta
static
utility::vector1< std::string > basic::Tracer::monitoring_list_
staticprivate

list of channels for which outout should be redirected.

Referenced by set_ios_hook(), and t_flush().

int basic::Tracer::mpi_rank_
staticprivate

Mpi rank is this process

Referenced by calculate_visibility(), and prepend_channel_name().

int basic::Tracer::mute_level_
private

channel muted priority level (above which level is channel muted), calculated using user suppied -level and -levels options

Referenced by calculate_visibility(), init(), priority(), and visible().

bool basic::Tracer::muted_
private

is channel muted ?

Referenced by calculate_visibility(), init(), priority(), and visible().

bool basic::Tracer::muted_by_default_
private

is channel muted by default?

Referenced by calculate_visibility(), and init().

int basic::Tracer::priority_
private
utility::CSI_Sequence basic::Tracer::Red
static
utility::CSI_Sequence basic::Tracer::Reset
static

Static objects holding various ASCII CSI codes (see utility/CSI_Sequence.hh)

Referenced by mg_modeler_test(), prepend_channel_name(), and swa_rna_sample().

TracerProxy basic::Tracer::Trace
TracerOptions basic::Tracer::tracer_options_
staticprivate

global option collection for Tracer IO.

Referenced by calculate_visibility(), prepend_channel_name(), and tracer_options().

utility::CSI_Sequence basic::Tracer::Underline
static
bool basic::Tracer::visibility_calculated_
private
bool basic::Tracer::visible_
private
TracerProxy basic::Tracer::Warning
utility::CSI_Sequence basic::Tracer::White
static
utility::CSI_Sequence basic::Tracer::Yellow
static

The documentation for this class was generated from the following files: