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

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

Referenced by ShallowTree().

102  {
103  for( BranchConnector* connector: connectors_) {
104  connector->connect(iEvent);
105  }
106  tree_->Fill();
107 }
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 132 of file ShallowTree.cc.

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

132  {
133 }
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().