CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes

ShallowTree Class Reference

#include <ShallowTree.h>

Inheritance diagram for ShallowTree:
edm::EDAnalyzer

List of all members.

Classes

class  BranchConnector
class  TypedBranchConnector

Public Types

enum  LEAFTYPE {
  BOOL = 1, BOOL_V, SHORT, SHORT_V,
  U_SHORT, U_SHORT_V, INT, INT_V,
  U_INT, U_INT_V, FLOAT, FLOAT_V,
  DOUBLE, DOUBLE_V, LONG, LONG_V,
  U_LONG, U_LONG_V, CHAR, CHAR_V,
  U_CHAR, U_CHAR_V
}

Public Member Functions

 ShallowTree (const edm::ParameterSet &iConfig)

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
virtual void beginJob ()
virtual void endJob ()

Private Attributes

std::vector< BranchConnector * > connectors
edm::Service< TFileServicefs
edm::ParameterSet pset
TTree * tree

Detailed Description

Makes a tree out of C++ standard types and vectors of C++ standard types

This class, which is an EDAnalyzer, takes the same "keep" and "drop" outputCommands parameter as the PoolOutputSource, making a tree of the selected variables, which it obtains from the EDM tree.

See the file python/test_cfg.py for an example configuration.

See the file doc/README for more detailed documentation, including advantages, disadvantages, and use philosophy.

Date:
2010/01/19 11:49:24
Revision:
1.4
Author:
Burt Betchart - University of Rochester <burton.andrew.betchart@cern.ch>

Definition at line 34 of file ShallowTree.h.


Member Enumeration Documentation

Enumerator:
BOOL 
BOOL_V 
SHORT 
SHORT_V 
U_SHORT 
U_SHORT_V 
INT 
INT_V 
U_INT 
U_INT_V 
FLOAT 
FLOAT_V 
DOUBLE 
DOUBLE_V 
LONG 
LONG_V 
U_LONG 
U_LONG_V 
CHAR 
CHAR_V 
U_CHAR 
U_CHAR_V 

Definition at line 66 of file ShallowTree.h.


Constructor & Destructor Documentation

ShallowTree::ShallowTree ( const edm::ParameterSet iConfig) [inline, explicit]

Definition at line 64 of file ShallowTree.h.

: pset(iConfig) {}

Member Function Documentation

void ShallowTree::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDAnalyzer.

Definition at line 13 of file ShallowTree.cc.

References ShallowTree::BranchConnector::connect(), connectors, and tree.

                                                             {
  BOOST_FOREACH( BranchConnector* connector, connectors)
    connector->connect(iEvent);
  tree->Fill();
}
void ShallowTree::beginJob ( void  ) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 42 of file ShallowTree.cc.

References BOOL, BOOL_V, CHAR, CHAR_V, edm::errors::Configuration, connectors, DOUBLE, DOUBLE_V, Exception, FLOAT, FLOAT_V, fs, edm::GroupSelector::initialize(), INT, INT_V, python::Node::leaf, LONG, LONG_V, pset, edm::second(), edm::GroupSelector::selected(), corrVsCorr::selection, SHORT, SHORT_V, tree, U_CHAR, U_CHAR_V, U_INT, U_INT_V, U_LONG, U_LONG_V, U_SHORT, and U_SHORT_V.

           {
  tree = fs->make<TTree>("tree", ""); 

  std::map<std::string, LEAFTYPE> leafmap;
  leafmap["bool"]      = BOOL;       leafmap["bools"]     = BOOL_V;
  leafmap["short int"] = SHORT;      leafmap["shorts"]    = SHORT_V;
  leafmap["ushort int"]= U_SHORT;    leafmap["ushorts"]   = U_SHORT_V;
  leafmap["int"]       = INT;        leafmap["ints"]      = INT_V;
  leafmap["uint"]      = U_INT;      leafmap["uints"]     = U_INT_V;
  leafmap["float"]     = FLOAT;      leafmap["floats"]    = FLOAT_V;
  leafmap["double"]    = DOUBLE;     leafmap["doubles"]   = DOUBLE_V;
  leafmap["lint"]      = LONG;       leafmap["longs"]     = LONG_V;
  leafmap["ulint"]     = U_LONG;     leafmap["ulongs"]    = U_LONG_V;
  leafmap["char"]      = CHAR;       leafmap["chars"]     = CHAR_V;
  leafmap["uchar"]     = U_CHAR;     leafmap["uchars"]    = U_CHAR_V;


  edm::Service<edm::ConstProductRegistry> reg;
  edm::Selections allBranches = reg->allBranchDescriptions();
  edm::GroupSelectorRules groupSelectorRules_(pset, "outputCommands", "ShallowTree");
  edm::GroupSelector groupSelector_;
  groupSelector_.initialize(groupSelectorRules_, allBranches);

  std::set<std::string> branchnames;

  BOOST_FOREACH( const edm::Selections::value_type& selection, allBranches) {
    if(groupSelector_.selected(*selection)) {

      //Check for duplicate branch names
      if (branchnames.find( selection->productInstanceName()) != branchnames.end() ) {
        throw edm::Exception(edm::errors::Configuration)
          << "More than one branch named: "
          << selection->productInstanceName() << std::endl
          << "Exception thrown from ShallowTree::beginJob" << std::endl;
      }
      else {
        branchnames.insert( selection->productInstanceName() );
      }

      //Create ShallowTree branch
      switch(leafmap.find( selection->friendlyClassName() )->second) {
      case BOOL     :  connectors.push_back( new TypedBranchConnector                      <bool>  (selection, "/O", tree) ); break;
      case BOOL_V   :  connectors.push_back( new TypedBranchConnector<std::vector          <bool> >(selection,   "", tree) ); break;
      case INT      :  connectors.push_back( new TypedBranchConnector                       <int>  (selection, "/I", tree) ); break;
      case INT_V    :  connectors.push_back( new TypedBranchConnector<std::vector           <int> >(selection,   "", tree) ); break;
      case U_INT    :  connectors.push_back( new TypedBranchConnector              <unsigned int>  (selection, "/i", tree) ); break;
      case U_INT_V  :  connectors.push_back( new TypedBranchConnector<std::vector  <unsigned int> >(selection,   "", tree) ); break;
      case SHORT    :  connectors.push_back( new TypedBranchConnector                     <short>  (selection, "/S", tree) ); break;
      case SHORT_V  :  connectors.push_back( new TypedBranchConnector<std::vector         <short> >(selection,   "", tree) ); break;
      case U_SHORT  :  connectors.push_back( new TypedBranchConnector            <unsigned short>  (selection, "/s", tree) ); break;
      case U_SHORT_V:  connectors.push_back( new TypedBranchConnector<std::vector<unsigned short> >(selection,   "", tree) ); break;
      case FLOAT    :  connectors.push_back( new TypedBranchConnector                     <float>  (selection, "/F", tree) ); break;
      case FLOAT_V  :  connectors.push_back( new TypedBranchConnector<std::vector         <float> >(selection,   "", tree) ); break;
      case DOUBLE   :  connectors.push_back( new TypedBranchConnector                    <double>  (selection, "/D", tree) ); break;
      case DOUBLE_V :  connectors.push_back( new TypedBranchConnector<std::vector        <double> >(selection,   "", tree) ); break;
      case LONG     :  connectors.push_back( new TypedBranchConnector                      <long>  (selection, "/L", tree) ); break;
      case LONG_V   :  connectors.push_back( new TypedBranchConnector<std::vector          <long> >(selection,   "", tree) ); break;
      case U_LONG   :  connectors.push_back( new TypedBranchConnector             <unsigned long>  (selection, "/l", tree) ); break;
      case U_LONG_V :  connectors.push_back( new TypedBranchConnector<std::vector <unsigned long> >(selection,   "", tree) ); break;
      case CHAR     :  connectors.push_back( new TypedBranchConnector                      <char>  (selection, "/B", tree) ); break;
      case CHAR_V   :  connectors.push_back( new TypedBranchConnector<std::vector          <char> >(selection,   "", tree) ); break;
      case U_CHAR   :  connectors.push_back( new TypedBranchConnector             <unsigned char>  (selection, "/b", tree) ); break;
      case U_CHAR_V :  connectors.push_back( new TypedBranchConnector<std::vector <unsigned char> >(selection,   "", tree) ); break;
      default: 
        {
          std::string leafstring = "";
          typedef std::pair<std::string, LEAFTYPE> pair_t;
          BOOST_FOREACH( const pair_t& leaf, leafmap) 
            leafstring+= "\t" + leaf.first + "\n";

          throw edm::Exception(edm::errors::Configuration)
            << "class ShallowTree does not handle leaves of type " << selection->className() << " like\n"
            <<   selection->friendlyClassName()   << "_" 
            <<   selection->moduleLabel()         << "_" 
            <<   selection->productInstanceName() << "_"  
            <<   selection->processName()         << std::endl
            << "Valid leaf types are (friendlyClassName):\n"
            <<   leafstring
            << "Exception thrown from ShallowTree::beginJob\n";
        }
      }
    }
  }
}
virtual void ShallowTree::endJob ( void  ) [inline, private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 38 of file ShallowTree.h.

{}

Member Data Documentation

std::vector<BranchConnector*> ShallowTree::connectors [private]

Definition at line 60 of file ShallowTree.h.

Referenced by analyze(), and beginJob().

Definition at line 58 of file ShallowTree.h.

Referenced by beginJob().

Definition at line 61 of file ShallowTree.h.

Referenced by beginJob().

TTree* ShallowTree::tree [private]

Definition at line 59 of file ShallowTree.h.

Referenced by analyze(), and beginJob().