CMS 3D CMS Logo

Defines | Functions | Variables

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Fireworks/Macros/eve_filter.cc File Reference

#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <utility>
#include "TPRegexp.h"
#include "TEveManager.h"
#include "TEveScene.h"
#include "TEveElement.h"
#include "TEveGeoNode.h"
#include "TGeoNode.h"
#include "TCollection.h"
#include "TObjString.h"
#include "split.h"
#include "eve_filter.h"
#include "eve_macros.h"

Go to the source code of this file.

Defines

#define private   public

Functions

void apply_filter (TEveElement *node, int simplify, bool verbose)
void dump (void)
TEveElement * get_root_object (const char *name)
void init_filter (const std::vector< std::pair< std::string, Color_t > > &elements)
TPRegexp make_filter (const std::vector< std::string > &tokens)
TPRegexp make_filter (const std::string &token)
void node_filter (TEveElement *node, int simplify, bool verbose)
static TPRegexp ns_name_index ("([[:alnum:]]+:[[:alnum:]-\\[\\]]+)(_[0-9]+)+")
void split_path (const std::string &path, std::string &name, std::vector< std::string > &parents)

Variables

std::vector< Color_t > colors
std::vector< TPRegexp > filters
unsigned int matching_nodes
TPRegexp parents

Define Documentation

#define private   public

Definition at line 7 of file eve_filter.cc.


Function Documentation

void apply_filter ( TEveElement *  node,
int  simplify,
bool  verbose 
)

Definition at line 178 of file eve_filter.cc.

References gather_cfg::cout, get_name(), matching_nodes, and node_filter().

                                                                      {
  if (node == 0)
    return;

  if (verbose)
    std::cout << get_name(node) << " (look inside...)" << std::endl;

  node_filter( node, simplify );
  node->ElementChanged( true, true );

  std::cout << "found " << matching_nodes << " matching nodes" << std::endl;
}
void dump ( void  )

Definition at line 171 of file eve_filter.cc.

References colors, gather_cfg::cout, filters, i, and parents.

                {
  std::cout << parents.fPattern << std::endl;
  for (unsigned int i = 0; i < filters.size(); ++i)
    std::cout << '\t' << std::setw(32) << std::left << filters[i].fPattern << '\t' << colors[i] << std::endl;
}
TEveElement* get_root_object ( const char *  name)

Definition at line 192 of file eve_filter.cc.

References get_name(), i, and n.

Referenced by calo_filter().

{
  for (TEveElement::List_i i = gEve->GetScenes()->BeginChildren(); i != gEve->GetScenes()->EndChildren(); ++i) {
    TEveScene * scene = dynamic_cast<TEveScene *> (*i);
    if (not scene)
      continue;
    for (TEveElement::List_i n = scene->BeginChildren(); n != scene->EndChildren(); ++n) {
      const char* obj_name = get_name( *n );
      if (obj_name == 0 or strcmp(name, obj_name))
        continue;

      return *n;
    }
  }

  return 0;
}
void init_filter ( const std::vector< std::pair< std::string, Color_t > > &  elements)

Definition at line 149 of file eve_filter.cc.

References colors, asciidump::elements, filters, first, i, make_filter(), matching_nodes, parents, edm::second(), and split_path().

Referenced by calo_filter().

                                                                             {
  std::vector< std::string > all_parents;
  std::vector< std::string > all_names;

  for (unsigned int i = 0; i < elements.size(); ++i) {
    std::vector< std::string > s_parents;
    std::string s_name;
    split_path( elements[i].first, s_name, s_parents );
    all_names.push_back( s_name );
    all_parents.insert( all_parents.end(), s_parents.begin(), s_parents.end() );

    colors.push_back( elements[i].second );
  }

  parents = make_filter( all_parents );
  for (unsigned int i = 0; i < all_names.size(); ++i)
    filters.push_back( make_filter( all_names[i] ) );

  matching_nodes = 0;
}
TPRegexp make_filter ( const std::vector< std::string > &  tokens)

Definition at line 54 of file eve_filter.cc.

References align_tpl::filter, i, and ns_name_index().

                                                          {
  if (tokens.empty())
    return TPRegexp();

  std::string filter;
  filter += "(";
  if (ns_name_index.MatchB( tokens[0] ))
    filter += ((TObjString*)(ns_name_index.MatchS( tokens[0] )->At(1)))->GetString();
  else
    filter += tokens[0];
  for (unsigned int i = 1; i < tokens.size(); ++i) {
    filter += "|";
    if (ns_name_index.MatchB( tokens[i] ))
      filter += ((TObjString*)(ns_name_index.MatchS( tokens[i] )->At(1)))->GetString();
    else
      filter += tokens[i];
  }
  filter += ")_[0-9]+";
  return TPRegexp( filter.c_str() );
}
TPRegexp make_filter ( const std::string &  token)

Definition at line 42 of file eve_filter.cc.

References align_tpl::filter, and ns_name_index().

Referenced by init_filter().

                                              {
  std::string filter;
  filter += "(";
  if (ns_name_index.MatchB( token ))
    filter += ((TObjString*)(ns_name_index.MatchS( token )->At(1)))->GetString();
  else
    filter += token;
  filter += ")_[0-9]+";
  return TPRegexp( filter.c_str() );
}
void node_filter ( TEveElement *  node,
int  simplify,
bool  verbose 
)

Definition at line 76 of file eve_filter.cc.

References colors, gather_cfg::cout, do_hide, do_nothing, do_remove, expand_node(), filters, newFWLiteAna::found, i, tablePrinter::indent(), matching_nodes, node_filter(), and parents.

Referenced by apply_filter(), and node_filter().

                                                                     {
  static int indent = 0;
  ++indent;

  expand_node(node);

  for (TEveElement::List_i i = node->BeginChildren(); i != node->EndChildren(); ++i)
  {
    bool found = false;
    TEveGeoNode * child = (TEveGeoNode*)(*i);
    for (unsigned int det = 0; det < filters.size(); ++det) {
      if (filters[det].MatchB( child->GetName() )) {
        // found a selcted leaf
        if (verbose) {
          for (int _t = 0; _t < indent; ++_t) std::cout << "  ";
          std::cout << child->GetName() << " (found)" << std::endl;
        }
        child->SetRnrSelf( true );
        child->SetMainColor( colors[det] );
        // simplify - hide or delete its children
        switch (simplify) {
          case do_hide:
            child->SetRnrSelf( true );
            child->SetRnrChildren( false );
            break;
          case do_remove:
            child->Destroy();
            break;
          case do_nothing:
            break;
        }

        found = true;
        ++matching_nodes;
        break;  // breaks out of the loop on "det"
      }
    }
    if (found)
      continue;
    else if (parents.MatchB( child->GetName() )) {
      // found a possible parent
      if (verbose) {
        for (int _t = 0; _t < indent; ++_t) std::cout << "  ";
        std::cout << child->GetName() << " (look inside...)" << std::endl;
      }
      child->SetRnrSelf( false );
      child->SetRnrChildren( true );
      node_filter( child );
    } else {
      // enything else
      if (verbose) {
        for (int _t = 0; _t < indent; ++_t) std::cout << "  ";
        std::cout << child->GetName() << " (unused)" << std::endl;
      }
      // simplify - hide or delete this
      switch (simplify) {
        case do_hide:
          child->SetRnrSelf( false );
          child->SetRnrChildren( false );
          break;
        case do_remove:
          child->Destroy();
          break;
        case do_nothing:
          break;
      }
    }
  }

  --indent;
}
static TPRegexp ns_name_index ( "([[:alnum:]]+:[[:alnum:]-\\[\\]]+)(_[0-9]+)+"  ) [static]

Referenced by make_filter().

void split_path ( const std::string &  path,
std::string &  name,
std::vector< std::string > &  parents 
)

Definition at line 29 of file eve_filter.cc.

References split.

Referenced by init_filter().

                                                                                          {
  split( path, parents, '/', false );
  if (parents.empty()) {
    name = "";
  } else {
    name = parents.back();
    parents.pop_back();
  }
}

Variable Documentation

std::vector<Color_t> colors
std::vector<TPRegexp> filters
unsigned int matching_nodes

Definition at line 27 of file eve_filter.cc.

Referenced by apply_filter(), init_filter(), and node_filter().

TPRegexp parents