CMS 3D CMS Logo

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 ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
template<class T >
void eat (edm::BranchDescription const *desc)
 
void endJob () override
 

Private Attributes

std::vector< BranchConnector * > connectors_
 
edm::Service< TFileServicefs_
 
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 &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- 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 33 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 69 of file ShallowTree.h.

Constructor & Destructor Documentation

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

Definition at line 10 of file ShallowTree.cc.

References edm::ConstProductRegistry::allBranchDescriptions(), analyze(), BOOL, BOOL_V, CHAR, CHAR_V, edm::errors::Configuration, connectors_, DOUBLE, DOUBLE_V, Exception, FLOAT, FLOAT_V, fs_, edm::ProductSelector::initialize(), INT, INT_V, LONG, LONG_V, TFileService::make(), 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.

10  {
11  tree_ = fs_->make<TTree>("tree", "");
12 
13  std::map<std::string, LEAFTYPE> leafmap;
14  leafmap["bool"] = BOOL; leafmap["bools"] = BOOL_V;
15  leafmap["short int"] = SHORT; leafmap["shorts"] = SHORT_V;
16  leafmap["ushort int"]= U_SHORT; leafmap["ushorts"] = U_SHORT_V;
17  leafmap["int"] = INT; leafmap["ints"] = INT_V;
18  leafmap["uint"] = U_INT; leafmap["uints"] = U_INT_V;
19  leafmap["float"] = FLOAT; leafmap["floats"] = FLOAT_V;
20  leafmap["double"] = DOUBLE; leafmap["doubles"] = DOUBLE_V;
21  leafmap["lint"] = LONG; leafmap["longs"] = LONG_V;
22  leafmap["ulint"] = U_LONG; leafmap["ulongs"] = U_LONG_V;
23  leafmap["char"] = CHAR; leafmap["chars"] = CHAR_V;
24  leafmap["uchar"] = U_CHAR; leafmap["uchars"] = U_CHAR_V;
25 
26 
28  auto allBranches = reg->allBranchDescriptions();
29  edm::ProductSelectorRules productSelectorRules_(iConfig, "outputCommands", "ShallowTree");
30  edm::ProductSelector productSelector_;
31  productSelector_.initialize(productSelectorRules_, allBranches);
32 
33  std::set<std::string> branchnames;
34 
35  for( auto const& selection : allBranches) {
36  if(productSelector_.selected(*selection)) {
37 
38  //Check for duplicate branch names
39  if (branchnames.find( selection->productInstanceName()) != branchnames.end() ) {
41  << "More than one branch named: "
42  << selection->productInstanceName() << std::endl
43  << "Exception thrown from ShallowTree::ShallowTree" << std::endl;
44  }
45  else {
46  branchnames.insert( selection->productInstanceName() );
47  }
48 
49  //Create ShallowTree branch
50  switch(leafmap.find( selection->friendlyClassName() )->second) {
51  case BOOL : connectors_.push_back( new TypedBranchConnector <bool> (selection, "/O", tree_) ); eat <bool> (selection); break;
52  case BOOL_V : connectors_.push_back( new TypedBranchConnector<std::vector <bool> >(selection, "", tree_) ); eat<std::vector <bool> >(selection); break;
53  case INT : connectors_.push_back( new TypedBranchConnector <int> (selection, "/I", tree_) ); eat <int> (selection); break;
54  case INT_V : connectors_.push_back( new TypedBranchConnector<std::vector <int> >(selection, "", tree_) ); eat<std::vector <int> >(selection); break;
55  case U_INT : connectors_.push_back( new TypedBranchConnector <unsigned int> (selection, "/i", tree_) ); eat <unsigned int> (selection); break;
56  case U_INT_V : connectors_.push_back( new TypedBranchConnector<std::vector <unsigned int> >(selection, "", tree_) ); eat<std::vector <unsigned int> >(selection); break;
57  case SHORT : connectors_.push_back( new TypedBranchConnector <short> (selection, "/S", tree_) ); eat <short> (selection); break;
58  case SHORT_V : connectors_.push_back( new TypedBranchConnector<std::vector <short> >(selection, "", tree_) ); eat<std::vector <short> >(selection); break;
59  case U_SHORT : connectors_.push_back( new TypedBranchConnector <unsigned short> (selection, "/s", tree_) ); eat <unsigned short> (selection); break;
60  case U_SHORT_V: connectors_.push_back( new TypedBranchConnector<std::vector<unsigned short> >(selection, "", tree_) ); eat<std::vector<unsigned short> >(selection); break;
61  case FLOAT : connectors_.push_back( new TypedBranchConnector <float> (selection, "/F", tree_) ); eat <float> (selection); break;
62  case FLOAT_V : connectors_.push_back( new TypedBranchConnector<std::vector <float> >(selection, "", tree_) ); eat<std::vector <float> >(selection); break;
63  case DOUBLE : connectors_.push_back( new TypedBranchConnector <double> (selection, "/D", tree_) ); eat <double> (selection); break;
64  case DOUBLE_V : connectors_.push_back( new TypedBranchConnector<std::vector <double> >(selection, "", tree_) ); eat<std::vector <double> >(selection); break;
65  case LONG : connectors_.push_back( new TypedBranchConnector <long> (selection, "/L", tree_) ); eat <long> (selection); break;
66  case LONG_V : connectors_.push_back( new TypedBranchConnector<std::vector <long> >(selection, "", tree_) ); eat<std::vector <long> >(selection); break;
67  case U_LONG : connectors_.push_back( new TypedBranchConnector <unsigned long> (selection, "/l", tree_) ); eat <unsigned long> (selection); break;
68  case U_LONG_V : connectors_.push_back( new TypedBranchConnector<std::vector <unsigned long> >(selection, "", tree_) ); eat<std::vector <unsigned long> >(selection); break;
69  case CHAR : connectors_.push_back( new TypedBranchConnector <char> (selection, "/B", tree_) ); eat <char> (selection); break;
70  case CHAR_V : connectors_.push_back( new TypedBranchConnector<std::vector <char> >(selection, "", tree_) ); eat<std::vector <char> >(selection); break;
71  case U_CHAR : connectors_.push_back( new TypedBranchConnector <unsigned char> (selection, "/b", tree_) ); eat <unsigned char> (selection); break;
72  case U_CHAR_V : connectors_.push_back( new TypedBranchConnector<std::vector <unsigned char> >(selection, "", tree_) ); eat<std::vector <unsigned char> >(selection); break;
73  default:
74  {
75  std::string leafstring = "";
76  typedef std::pair<std::string, LEAFTYPE> pair_t;
77  for( const pair_t& leaf: leafmap) {
78  leafstring+= "\t" + leaf.first + "\n";
79  }
80 
82  << "class ShallowTree does not handle leaves of type " << selection->className() << " like\n"
83  << selection->friendlyClassName() << "_"
84  << selection->moduleLabel() << "_"
85  << selection->productInstanceName() << "_"
86  << selection->processName() << std::endl
87  << "Valid leaf types are (friendlyClassName):\n"
88  << leafstring
89  << "Exception thrown from ShallowTree::ShallowTree\n";
90  }
91  }
92  }
93  }
94 }
bool selected(BranchDescription const &desc) const
selection
main part
Definition: corrVsCorr.py:98
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
U second(std::pair< T, U > const &p)
edm::Service< TFileService > fs_
Definition: ShallowTree.h:62
TTree * tree_
Definition: ShallowTree.h:63
void initialize(ProductSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
std::vector< BranchDescription const * > allBranchDescriptions() const
std::vector< BranchConnector * > connectors_
Definition: ShallowTree.h:64

Member Function Documentation

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

Definition at line 98 of file ShallowTree.cc.

References ShallowTree::TypedBranchConnector< T >::connect(), connectors_, and tree_.

Referenced by ShallowTree().

98  {
99  for( BranchConnector* connector: connectors_) {
100  connector->connect(iEvent);
101  }
102  tree_->Fill();
103 }
TTree * tree_
Definition: ShallowTree.h:63
std::vector< BranchConnector * > connectors_
Definition: ShallowTree.h:64
void ShallowTree::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 128 of file ShallowTree.cc.

Referenced by ShallowTree::TypedBranchConnector< T >::TypedBranchConnector().

128  {
129 }
template<class T >
void ShallowTree::eat ( edm::BranchDescription const *  desc)
inlineprivate

Definition at line 40 of file ShallowTree.h.

References edm::BranchDescription::moduleLabel(), and edm::BranchDescription::productInstanceName().

40  {
41  consumes<T>(edm::InputTag(desc->moduleLabel(), desc->productInstanceName()));
42  }
void ShallowTree::endJob ( void  )
inlineoverrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 37 of file ShallowTree.h.

Referenced by o2olib.O2ORunMgr::executeJob().

37 {}

Member Data Documentation

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

Definition at line 64 of file ShallowTree.h.

Referenced by analyze(), and ShallowTree().

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

Definition at line 62 of file ShallowTree.h.

Referenced by ShallowTree().

TTree* ShallowTree::tree_
private

Definition at line 63 of file ShallowTree.h.

Referenced by analyze(), and ShallowTree().