Esempio n. 1
0
// ============================================================================
void DataOnDemandSvc::dump
( const MSG::Level level ,
  const bool       mode  )  const
{
  if ( m_algs.empty()  &&  m_nodes.empty() ) { return ; }

  typedef std::pair<std::string,std::string> Pair ;
  typedef std::map<std::string,Pair>         PMap ;

  PMap _m ;
  for ( AlgMap::const_iterator alg = m_algs.begin() ;
        m_algs.end() != alg ; ++alg )
  {
    PMap::const_iterator check = _m.find(alg->first) ;
    if ( _m.end() != check )
    {
      stream()
        << MSG::WARNING
        << " The data item is activated for '"
        << check->first << "' as '" << check->second.first << "'" << endmsg ;
    }
    const Leaf& l = alg->second ;
    std::string nam = ( l.name == l.type ? l.type  : (l.type+"/"+l.name) ) ;
    //
    if ( !mode && 0 == l.num ) { continue ; }
    //
    std::string val ;
    if ( mode ) { val = ( 0 == l.algorithm ) ? "F" : "T" ; }
    else { val = boost::lexical_cast<std::string>( l.num ) ; }
    //
    _m[ no_prefix ( alg->first , m_prefix ) ] = std::make_pair ( nam , val ) ;
  }
  // nodes:
  for ( NodeMap::const_iterator node = m_nodes.begin() ;
        m_nodes.end() != node ; ++node )
  {
    PMap::const_iterator check = _m.find(node->first) ;
    if ( _m.end() != check )
    {
      stream()
        << MSG::WARNING
        << " The data item is already activated for '"
        << check->first << "' as '" << check->second.first << "'" << endmsg ;
    }
    const Node& n = node->second ;
    std::string nam = "'" + n.name + "'"  ;
    //
    std::string val ;

    if ( !mode && 0 == n.num ) { continue ; }

    if ( mode ) { val = ( 0 == n.clazz ) ? "F" : "T" ; }
    else { val = boost::lexical_cast<std::string>( n.num ) ; }
    //
    _m[ no_prefix ( node->first , m_prefix ) ] = std::make_pair ( nam , val ) ;
  }
  //
  if ( _m.empty() ) { return ; }

  // find the correct formats
  size_t n1 = 0 ;
  size_t n2 = 0 ;
  size_t n3 = 0 ;
  for  ( PMap::const_iterator it = _m.begin() ; _m.end() != it ; ++it )
  {
    n1 = std::max ( n1 , it->first.size()         ) ;
    n2 = std::max ( n2 , it->second.first.size()  ) ;
    n3 = std::max ( n3 , it->second.second.size() ) ;
  }
  if ( 10 > n1 ) { n1 = 10 ; }
  if ( 10 > n2 ) { n2 = 10 ; }
  if ( 60 < n1 ) { n1 = 60 ; }
  if ( 60 < n2 ) { n2 = 60 ; }
  //

  const std::string _f = " | %%1$-%1%.%1%s | %%2$-%2%.%2%s | %%3$%3%.%3%s |" ;
  boost::format _ff ( _f ) ;
  _ff % n1 % n2 % n3 ;

  const std::string _format  = _ff.str() ;

  MsgStream& msg = stream() << level ;

  if ( mode ) { msg << "Data-On-Demand Actions enabled for:"       ; }
  else        { msg << "Data-On-Demand Actions has been used for:" ; }

  boost::format fmt1( _format)  ;
  fmt1 % "Address" % "Creator" % ( mode ? "S" : "#" ) ;
  //
  const std::string header = fmt1.str() ;
  std::string line = std::string( header.size() , '-' ) ;
  line[0] = ' ' ;

  msg << std::endl << line
      << std::endl << header
      << std::endl << line ;

  // make the actual printout:
  for ( PMap::const_iterator item = _m.begin() ;
        _m.end() != item ; ++item )
  {
    boost::format fmt( _format)  ;
    msg << std::endl <<
      ( fmt % item->first % item->second.first % item->second.second ) ;
  }

  msg << std::endl << line << endmsg ;

}
Esempio n. 2
0
static void
init_switches (void)
{
  char *p = short_options;
  size_t i, o = 0;
  for (i = 0; i < sizeof(option_data) / sizeof(option_data[0]); i++)
    {
      struct cmdline_option *opt = &option_data[i];
      struct option *longopt;

      if (!opt->long_name)
        /* The option is disabled. */
        continue;

      longopt = &long_options[o++];
      longopt->name = opt->long_name;
      longopt->val = i;
      if (opt->short_name)
        {
          *p++ = opt->short_name;
          optmap[opt->short_name - 32] = longopt - long_options;
        }
      switch (opt->type)
        {
        case OPT_VALUE:
          longopt->has_arg = required_argument;
          if (opt->short_name)
            *p++ = ':';
          break;
        case OPT_BOOLEAN:
          /* Specify an optional argument for long options, so that
             --option=off works the same as --no-option, for
             compatibility with pre-1.10 Wget.  However, don't specify
             optional arguments short-option booleans because they
             prevent combining of short options.  */
          longopt->has_arg = optional_argument;
          /* For Boolean options, add the "--no-FOO" variant, which is
             identical to "--foo", except it has opposite meaning and
             it doesn't allow an argument.  */
          longopt = &long_options[o++];
          longopt->name = no_prefix (opt->long_name);
          longopt->has_arg = no_argument;
          /* Mask the value so we'll be able to recognize that we're
             dealing with the false value.  */
          longopt->val = i | BOOLEAN_NEG_MARKER;
          break;
        default:
          assert (opt->argtype != -1);
          longopt->has_arg = opt->argtype;
          if (opt->short_name)
            {
              if (longopt->has_arg == required_argument)
                *p++ = ':';
              /* Don't handle optional_argument */
            }
        }
    }
  /* Terminate short_options. */
  *p = '\0';
  /* No need for xzero(long_options[o]) because its storage is static
     and it will be zeroed by default.  */
  assert (o <= sizeof(long_options) / sizeof(long_options[0]));
}
Esempio n. 3
0
// ===========================================================================
// IIncidentListener interfaces overrides: incident handling
// ===========================================================================
void DataOnDemandSvc::handle ( const Incident& incident )
{

  Gaudi::Utils::LockedChrono timer ( m_timer_all , m_locked_all ) ;

  ++m_stat ;
  // proper incident type?
  if ( incident.type() != m_trapType ) { return ; }             // RETURN
  const DataIncident* inc = dynamic_cast<const DataIncident*>(&incident);
  if ( 0 == inc                      ) { return ; }             // RETURN
  // update if needed!
  if ( m_updateRequired ) { update() ; }

  if ( MSG::VERBOSE >= outputLevel() )
  {
    verbose()
      << "Incident: [" << incident.type   () << "] "
      << " = "         << incident.source ()
      << " Location:"  << inc->tag()         << endmsg;
  }
  // ==========================================================================
  // const std::string& tag = inc->tag();
  Gaudi::StringKey tag ( inc->tag() ) ;
  // ==========================================================================
  NodeMap::iterator icl = m_nodes.find ( tag ) ;
  if ( icl != m_nodes.end() )
  {
    StatusCode sc = execHandler ( tag , icl->second ) ;
    if ( sc.isSuccess() ) { ++m_statNode ; }
    return ;                                                        // RETURN
  }
  // ==========================================================================
  AlgMap::iterator ialg = m_algs.find ( tag ) ;
  if ( ialg != m_algs.end() )
  {
    StatusCode sc = execHandler ( tag , ialg->second ) ;
    if ( sc.isSuccess() ) { ++m_statAlg ; }
    return ;                                                        // RETURN
  }
  // ==========================================================================
  // Fall back on the tools
  if (m_toolSvc) {
    if (MSG::VERBOSE >= outputLevel())
      verbose() << "Try to find mapping with mapping tools" << endmsg;
    Finder finder(no_prefix(inc->tag(), m_prefix), m_nodeMappers, m_algMappers);
    //  - try the node mappers
    std::string node = finder.node();
    if (isGood(node)) {
      // if one is found update the internal node mapping and try again.
      if (MSG::VERBOSE >= outputLevel())
        verbose() << "Found Node handler: " << node << endmsg;
      i_setNodeHandler(inc->tag(), node);
      handle(incident);
      --m_stat; // avoid double counting because of recursion
      return;
    }
    //  - try alg mappings
    Gaudi::Utils::TypeNameString alg = finder.alg();
    if (isGood(alg)) {
      // we got an algorithm, update alg map and try to handle again
      if (MSG::VERBOSE >= outputLevel())
        verbose() << "Found Algorithm handler: " << alg << endmsg;
      i_setAlgHandler(inc->tag(), alg).ignore();
      handle(incident);
      --m_stat; // avoid double counting because of recursion
      return;
    }
  }
}