Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#ifndef DATA_FORMATS_MATH_GRAPH_UTIL_H
#define DATA_FORMATS_MATH_GRAPH_UTIL_H

#include "DataFormats/Math/interface/Graph.h"
#include "DataFormats/Math/interface/GraphWalker.h"
#include <iostream>
#include <string>

template <class N, class E>
void output(const math::Graph<N, E>& g, const N& root) {
  math::GraphWalker<N, E> w(g, root);
  bool go = true;
  while (go) {
    std::cout << w.current().first << ' ';
    go = w.next();
  }
  std::cout << std::endl;
}

template <class N, class E>
void graph_combine(const math::Graph<N, E>& g1,
                   const math::Graph<N, E>& g2,
                   const N& n1,
                   const N& n2,
                   const N& root,
                   math::Graph<N, E>& result) {
  result = g1;
  result.replace(n1, n2);
  math::GraphWalker<N, E> walker(g2, n2);
  while (walker.next()) {
    const N& parent = g2.nodeData((++walker.stack().rbegin())->first->first);
    result.addEdge(parent, walker.current().first, walker.current().second);
  }
  result.replace(n2, root);
}

template <class N, class E>
void graph_tree_output(const math::Graph<N, E>& g, const N& root, std::ostream& os) {
  math::GraphWalker<N, E> w(g, root);
  bool go = true;
  unsigned int depth = 0;
  while (go) {
    std::string s(2 * depth, ' ');
    os << ' ' << s << w.current().first << '(' << w.current().second << ')' << std::endl;
    go = w.firstChild();
    if (go) {
      ++depth;
    } else if (w.stack().size() > 1 && w.nextSibling()) {
      go = true;
    } else {
      go = false;
      while (w.parent()) {
        --depth;
        if (w.stack().size() > 1 && w.nextSibling()) {
          go = true;
          break;
        }
      }
    }
  }
}

#endif