Rosetta Utilities  2014.35
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>

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...
 
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 ()
 get/set tracer priority level. More...
 
Traceroperator() (int priority)
 
void priority (int priority)
 
std::string const & channel ()
 
- 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
void ctor ()
 
virtual ~ReferenceCount ()
 Destructor. More...
 
Size ref_count () const
 Reference count. More...
 

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 ()
 

Public Attributes

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

Static Public Attributes

static CSI_Sequence Reset
 pre-created objects to hold various ASCII CSI codes, treat them as almost-const's Codes below is all Hogwarts-approved magic numbers, so do not modify them. For reference see: http://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes More...
 
static CSI_Sequence Bold
 
static CSI_Sequence Underline
 
static CSI_Sequence Black
 
static CSI_Sequence Red
 
static CSI_Sequence Green
 
static CSI_Sequence Yellow
 
static CSI_Sequence Blue
 
static CSI_Sequence Magenta
 
static CSI_Sequence Cyan
 
static CSI_Sequence White
 
static CSI_Sequence bgBlack
 
static CSI_Sequence bgRed
 
static CSI_Sequence bgGreen
 
static CSI_Sequence bgYellow
 
static CSI_Sequence bgBlue
 
static CSI_Sequence bgMagenta
 
static CSI_Sequence bgCyan
 
static CSI_Sequence bgWhite
 

Protected Member Functions

virtual void t_flush (std::string const &)
 overload member function. More...
 
- Protected Member Functions inherited from utility::pointer::ReferenceCount
 ReferenceCount ()
 Default constructor. More...
 
 ReferenceCount (ReferenceCount const &)
 Copy constructor. More...
 
ReferenceCountoperator= (ReferenceCount const &)
 Copy assignment. More...
 

Private Member Functions

 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 (void) const
 calcualte visibility of the current object depending of the channel name and priority. 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 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 ()
 system priority level 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...
 
static std::vector< Tracer * > & all_tracers ()
 static collection of all Tracer objects More...
 

Private Attributes

std::string channel_
 Data members. More...
 
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 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 all_tracers(), channel(), channel_, priority(), and priority_.

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

copy constructor.

Functions

Member Function Documentation

std::vector< Tracer * > & basic::Tracer::all_tracers ( )
staticprivate

static collection of all Tracer objects

static collection of all Tracer objects

Referenced by flush_all_tracers(), Tracer(), and ~Tracer().

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 basic::options::OptionKeys::in::file::s, safe_output(), 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_visibility ( void  ) const
private

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

Calculate visibility of current Tracer object.

References channel_, mute_level_, muted_, muted_by_default_, priority_, visibility_calculated_, and visible_.

Referenced by basic::T(), t_flush(), visible(), and basic::Tracer::TracerProxy::visible().

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 ( )
inline

References channel_.

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

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, and Warning.

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.

Referenced by calculate_visibility(), and t_flush().

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_, channel_, mute_level_, muted_, priority_, visibility_calculated_, and visible_.

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

system priority level

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

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_, mpi_rank_, basic::TracerOptions::print_channel_name, basic::options::OptionKeys::in::file::s, utility::timestamp(), basic::TracerOptions::timestamp, and tracer_options_.

int basic::Tracer::priority ( )
inline

get/set tracer priority level.

References priority_.

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

void basic::Tracer::priority ( int  priority)
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 basic::datacache::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

References super_mute_().

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 calculate_visibility(), channel_, final_stream(), get_all_channels_string(), in(), 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::visible ( ) const

Is this tracer currently visible?.

References calculate_visibility(), visibility_calculated_, and visible_.

Referenced by calculate_visibility(), 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 calculate_visibility(), mute_level_, muted_, and visibility_calculated_.

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().

CSI_Sequence basic::Tracer::bgBlack
static
CSI_Sequence basic::Tracer::bgBlue
static
CSI_Sequence basic::Tracer::bgCyan
static
CSI_Sequence basic::Tracer::bgGreen
static
CSI_Sequence basic::Tracer::bgMagenta
static
CSI_Sequence basic::Tracer::bgRed
static
CSI_Sequence basic::Tracer::bgWhite
static
CSI_Sequence basic::Tracer::bgYellow
static
CSI_Sequence basic::Tracer::Black
static
CSI_Sequence basic::Tracer::Blue
static
CSI_Sequence basic::Tracer::Bold
static
std::string basic::Tracer::channel_
private

Data members.

channel name

Referenced by calculate_visibility(), channel(), init(), prepend_channel_name(), basic::T(), t_flush(), and Tracer().

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 flush_all_channels(), and ~Tracer().

CSI_Sequence basic::Tracer::Green
static
TracerProxy basic::Tracer::Info

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

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_
mutableprivate

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_
mutableprivate

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 basic::Tracer::TracerProxy::visible().

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

pre-created objects to hold various ASCII CSI codes, treat them as almost-const's Codes below is all Hogwarts-approved magic numbers, so do not modify them. For reference see: http://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes

Static objects to hold various ASCII CSI codes, treat them as almost-const's Codes below is all Hogwarts-approved magic numbers, so do not modify them. For reference see: http://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes

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().

CSI_Sequence basic::Tracer::Underline
static
bool basic::Tracer::visibility_calculated_
mutableprivate

is channel visibility already calculated?

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

bool basic::Tracer::visible_
mutableprivate

is channel visible?

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

TracerProxy basic::Tracer::Warning
CSI_Sequence basic::Tracer::White
static
CSI_Sequence basic::Tracer::Yellow
static

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