CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
ShallowTree Class Reference

#include <ShallowTree.h>

Inheritance diagram for ShallowTree:
edm::EDAnalyzer edm::EDConsumerBase

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 Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 

Public Member Functions

 ShallowTree (const edm::ParameterSet &iConfig)
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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.

Author
Burt Betchart - University of Rochester burto.nosp@m.n.an.nosp@m.drew..nosp@m.betc.nosp@m.hart@.nosp@m.cern.nosp@m..ch

Definition at line 32 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 64 of file ShallowTree.h.

Constructor & Destructor Documentation

ShallowTree::ShallowTree ( const edm::ParameterSet iConfig)
inlineexplicit

Definition at line 62 of file ShallowTree.h.

62 : pset(iConfig) {}
edm::ParameterSet pset
Definition: ShallowTree.h:59

Member Function Documentation

void ShallowTree::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDAnalyzer.

Definition at line 11 of file ShallowTree.cc.

References connectors, and tree.

11  {
12  for( BranchConnector* connector: connectors) {
13  connector->connect(iEvent);
14  }
15  tree->Fill();
16 }
TTree * tree
Definition: ShallowTree.h:57
std::vector< BranchConnector * > connectors
Definition: ShallowTree.h:58
void ShallowTree::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 41 of file ShallowTree.cc.

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

41  {
42  tree = fs->make<TTree>("tree", "");
43 
44  std::map<std::string, LEAFTYPE> leafmap;
45  leafmap["bool"] = BOOL; leafmap["bools"] = BOOL_V;
46  leafmap["short int"] = SHORT; leafmap["shorts"] = SHORT_V;
47  leafmap["ushort int"]= U_SHORT; leafmap["ushorts"] = U_SHORT_V;
48  leafmap["int"] = INT; leafmap["ints"] = INT_V;
49  leafmap["uint"] = U_INT; leafmap["uints"] = U_INT_V;
50  leafmap["float"] = FLOAT; leafmap["floats"] = FLOAT_V;
51  leafmap["double"] = DOUBLE; leafmap["doubles"] = DOUBLE_V;
52  leafmap["lint"] = LONG; leafmap["longs"] = LONG_V;
53  leafmap["ulint"] = U_LONG; leafmap["ulongs"] = U_LONG_V;
54  leafmap["char"] = CHAR; leafmap["chars"] = CHAR_V;
55  leafmap["uchar"] = U_CHAR; leafmap["uchars"] = U_CHAR_V;
56 
57 
59  auto allBranches = reg->allBranchDescriptions();
60  edm::ProductSelectorRules productSelectorRules_(pset, "outputCommands", "ShallowTree");
61  edm::ProductSelector productSelector_;
62  productSelector_.initialize(productSelectorRules_, allBranches);
63 
64  std::set<std::string> branchnames;
65 
66  for( auto const& selection : allBranches) {
67  if(productSelector_.selected(*selection)) {
68 
69  //Check for duplicate branch names
70  if (branchnames.find( selection->productInstanceName()) != branchnames.end() ) {
72  << "More than one branch named: "
73  << selection->productInstanceName() << std::endl
74  << "Exception thrown from ShallowTree::beginJob" << std::endl;
75  }
76  else {
77  branchnames.insert( selection->productInstanceName() );
78  }
79 
80  //Create ShallowTree branch
81  switch(leafmap.find( selection->friendlyClassName() )->second) {
82  case BOOL : connectors.push_back( new TypedBranchConnector <bool> (selection, "/O", tree) ); break;
83  case BOOL_V : connectors.push_back( new TypedBranchConnector<std::vector <bool> >(selection, "", tree) ); break;
84  case INT : connectors.push_back( new TypedBranchConnector <int> (selection, "/I", tree) ); break;
85  case INT_V : connectors.push_back( new TypedBranchConnector<std::vector <int> >(selection, "", tree) ); break;
86  case U_INT : connectors.push_back( new TypedBranchConnector <unsigned int> (selection, "/i", tree) ); break;
87  case U_INT_V : connectors.push_back( new TypedBranchConnector<std::vector <unsigned int> >(selection, "", tree) ); break;
88  case SHORT : connectors.push_back( new TypedBranchConnector <short> (selection, "/S", tree) ); break;
89  case SHORT_V : connectors.push_back( new TypedBranchConnector<std::vector <short> >(selection, "", tree) ); break;
90  case U_SHORT : connectors.push_back( new TypedBranchConnector <unsigned short> (selection, "/s", tree) ); break;
91  case U_SHORT_V: connectors.push_back( new TypedBranchConnector<std::vector<unsigned short> >(selection, "", tree) ); break;
92  case FLOAT : connectors.push_back( new TypedBranchConnector <float> (selection, "/F", tree) ); break;
93  case FLOAT_V : connectors.push_back( new TypedBranchConnector<std::vector <float> >(selection, "", tree) ); break;
94  case DOUBLE : connectors.push_back( new TypedBranchConnector <double> (selection, "/D", tree) ); break;
95  case DOUBLE_V : connectors.push_back( new TypedBranchConnector<std::vector <double> >(selection, "", tree) ); break;
96  case LONG : connectors.push_back( new TypedBranchConnector <long> (selection, "/L", tree) ); break;
97  case LONG_V : connectors.push_back( new TypedBranchConnector<std::vector <long> >(selection, "", tree) ); break;
98  case U_LONG : connectors.push_back( new TypedBranchConnector <unsigned long> (selection, "/l", tree) ); break;
99  case U_LONG_V : connectors.push_back( new TypedBranchConnector<std::vector <unsigned long> >(selection, "", tree) ); break;
100  case CHAR : connectors.push_back( new TypedBranchConnector <char> (selection, "/B", tree) ); break;
101  case CHAR_V : connectors.push_back( new TypedBranchConnector<std::vector <char> >(selection, "", tree) ); break;
102  case U_CHAR : connectors.push_back( new TypedBranchConnector <unsigned char> (selection, "/b", tree) ); break;
103  case U_CHAR_V : connectors.push_back( new TypedBranchConnector<std::vector <unsigned char> >(selection, "", tree) ); break;
104  default:
105  {
106  std::string leafstring = "";
107  typedef std::pair<std::string, LEAFTYPE> pair_t;
108  for( const pair_t& leaf: leafmap) {
109  leafstring+= "\t" + leaf.first + "\n";
110  }
111 
113  << "class ShallowTree does not handle leaves of type " << selection->className() << " like\n"
114  << selection->friendlyClassName() << "_"
115  << selection->moduleLabel() << "_"
116  << selection->productInstanceName() << "_"
117  << selection->processName() << std::endl
118  << "Valid leaf types are (friendlyClassName):\n"
119  << leafstring
120  << "Exception thrown from ShallowTree::beginJob\n";
121  }
122  }
123  }
124  }
125 }
bool selected(BranchDescription const &desc) const
selection
main part
Definition: corrVsCorr.py:98
edm::ParameterSet pset
Definition: ShallowTree.h:59
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
U second(std::pair< T, U > const &p)
tuple leaf
Definition: Node.py:62
TTree * tree
Definition: ShallowTree.h:57
edm::Service< TFileService > fs
Definition: ShallowTree.h:56
std::vector< BranchConnector * > connectors
Definition: ShallowTree.h:58
void initialize(ProductSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
std::vector< BranchDescription const * > allBranchDescriptions() const
virtual void ShallowTree::endJob ( void  )
inlineprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 36 of file ShallowTree.h.

36 {}

Member Data Documentation

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

Definition at line 58 of file ShallowTree.h.

Referenced by analyze(), and beginJob().

edm::Service<TFileService> ShallowTree::fs
private

Definition at line 56 of file ShallowTree.h.

Referenced by beginJob().

edm::ParameterSet ShallowTree::pset
private
TTree* ShallowTree::tree
private