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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
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)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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 70 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(), 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;
19  leafmap["bools"] = BOOL_V;
20  leafmap["short int"] = SHORT;
21  leafmap["shorts"] = SHORT_V;
22  leafmap["ushort int"] = U_SHORT;
23  leafmap["ushorts"] = U_SHORT_V;
24  leafmap["int"] = INT;
25  leafmap["ints"] = INT_V;
26  leafmap["uint"] = U_INT;
27  leafmap["uints"] = U_INT_V;
28  leafmap["float"] = FLOAT;
29  leafmap["floats"] = FLOAT_V;
30  leafmap["double"] = DOUBLE;
31  leafmap["doubles"] = DOUBLE_V;
32  leafmap["lint"] = LONG;
33  leafmap["longs"] = LONG_V;
34  leafmap["ulint"] = U_LONG;
35  leafmap["ulongs"] = U_LONG_V;
36  leafmap["char"] = CHAR;
37  leafmap["chars"] = CHAR_V;
38  leafmap["uchar"] = U_CHAR;
39  leafmap["uchars"] = U_CHAR_V;
40 
42  auto allBranches = reg->allBranchDescriptions();
43  edm::ProductSelectorRules productSelectorRules_(iConfig, "outputCommands", "ShallowTree");
44  edm::ProductSelector productSelector_;
45  productSelector_.initialize(productSelectorRules_, allBranches);
46 
47  std::set<std::string> branchnames;
48 
49  for (auto const& selection : allBranches) {
50  if (productSelector_.selected(*selection)) {
51  //Check for duplicate branch names
52  if (branchnames.find(selection->productInstanceName()) != branchnames.end()) {
54  << "More than one branch named: " << selection->productInstanceName() << std::endl
55  << "Exception thrown from ShallowTree::ShallowTree" << std::endl;
56  } else {
57  branchnames.insert(selection->productInstanceName());
58  }
59 
60  //Create ShallowTree branch
61  switch (leafmap.find(selection->friendlyClassName())->second) {
62  case BOOL:
63  connectors_.push_back(new TypedBranchConnector<bool>(selection, "/O", tree_));
64  eat<bool>(selection);
65  break;
66  case BOOL_V:
67  connectors_.push_back(new TypedBranchConnector<std::vector<bool> >(selection, "", tree_));
68  eat<std::vector<bool> >(selection);
69  break;
70  case INT:
71  connectors_.push_back(new TypedBranchConnector<int>(selection, "/I", tree_));
72  eat<int>(selection);
73  break;
74  case INT_V:
75  connectors_.push_back(new TypedBranchConnector<std::vector<int> >(selection, "", tree_));
76  eat<std::vector<int> >(selection);
77  break;
78  case U_INT:
79  connectors_.push_back(new TypedBranchConnector<unsigned int>(selection, "/i", tree_));
80  eat<unsigned int>(selection);
81  break;
82  case U_INT_V:
83  connectors_.push_back(new TypedBranchConnector<std::vector<unsigned int> >(selection, "", tree_));
84  eat<std::vector<unsigned int> >(selection);
85  break;
86  case SHORT:
87  connectors_.push_back(new TypedBranchConnector<short>(selection, "/S", tree_));
88  eat<short>(selection);
89  break;
90  case SHORT_V:
91  connectors_.push_back(new TypedBranchConnector<std::vector<short> >(selection, "", tree_));
92  eat<std::vector<short> >(selection);
93  break;
94  case U_SHORT:
95  connectors_.push_back(new TypedBranchConnector<unsigned short>(selection, "/s", tree_));
96  eat<unsigned short>(selection);
97  break;
98  case U_SHORT_V:
99  connectors_.push_back(new TypedBranchConnector<std::vector<unsigned short> >(selection, "", tree_));
100  eat<std::vector<unsigned short> >(selection);
101  break;
102  case FLOAT:
103  connectors_.push_back(new TypedBranchConnector<float>(selection, "/F", tree_));
104  eat<float>(selection);
105  break;
106  case FLOAT_V:
107  connectors_.push_back(new TypedBranchConnector<std::vector<float> >(selection, "", tree_));
108  eat<std::vector<float> >(selection);
109  break;
110  case DOUBLE:
111  connectors_.push_back(new TypedBranchConnector<double>(selection, "/D", tree_));
112  eat<double>(selection);
113  break;
114  case DOUBLE_V:
115  connectors_.push_back(new TypedBranchConnector<std::vector<double> >(selection, "", tree_));
116  eat<std::vector<double> >(selection);
117  break;
118  case LONG:
119  connectors_.push_back(new TypedBranchConnector<long>(selection, "/L", tree_));
120  eat<long>(selection);
121  break;
122  case LONG_V:
123  connectors_.push_back(new TypedBranchConnector<std::vector<long> >(selection, "", tree_));
124  eat<std::vector<long> >(selection);
125  break;
126  case U_LONG:
127  connectors_.push_back(new TypedBranchConnector<unsigned long>(selection, "/l", tree_));
128  eat<unsigned long>(selection);
129  break;
130  case U_LONG_V:
131  connectors_.push_back(new TypedBranchConnector<std::vector<unsigned long> >(selection, "", tree_));
132  eat<std::vector<unsigned long> >(selection);
133  break;
134  case CHAR:
135  connectors_.push_back(new TypedBranchConnector<char>(selection, "/B", tree_));
136  eat<char>(selection);
137  break;
138  case CHAR_V:
139  connectors_.push_back(new TypedBranchConnector<std::vector<char> >(selection, "", tree_));
140  eat<std::vector<char> >(selection);
141  break;
142  case U_CHAR:
143  connectors_.push_back(new TypedBranchConnector<unsigned char>(selection, "/b", tree_));
144  eat<unsigned char>(selection);
145  break;
146  case U_CHAR_V:
147  connectors_.push_back(new TypedBranchConnector<std::vector<unsigned char> >(selection, "", tree_));
148  eat<std::vector<unsigned char> >(selection);
149  break;
150  default: {
151  std::string leafstring = "";
152  typedef std::pair<std::string, LEAFTYPE> pair_t;
153  for (const pair_t& leaf : leafmap) {
154  leafstring += "\t" + leaf.first + "\n";
155  }
156 
158  << "class ShallowTree does not handle leaves of type " << selection->className() << " like\n"
159  << selection->friendlyClassName() << "_" << selection->moduleLabel() << "_"
160  << selection->productInstanceName() << "_" << selection->processName() << std::endl
161  << "Valid leaf types are (friendlyClassName):\n"
162  << leafstring << "Exception thrown from ShallowTree::ShallowTree\n";
163  }
164  }
165  }
166  }
167 }
T getUntrackedParameter(std::string const &, T const &) const
bool selected(BranchDescription const &desc) const
selection
main part
Definition: corrVsCorr.py:100
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:63
TFile & file() const
return opened TFile
Definition: TFileService.h:37
TTree * tree_
Definition: ShallowTree.h:64
void initialize(ProductSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
std::vector< BranchDescription const * > allBranchDescriptions() const
std::vector< BranchConnector * > connectors_
Definition: ShallowTree.h:65

Member Function Documentation

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

Definition at line 169 of file ShallowTree.cc.

References connectors_, and tree_.

169  {
170  for (BranchConnector* connector : connectors_) {
171  connector->connect(iEvent);
172  }
173  tree_->Fill();
174 }
TTree * tree_
Definition: ShallowTree.h:64
std::vector< BranchConnector * > connectors_
Definition: ShallowTree.h:65
void ShallowTree::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 198 of file ShallowTree.cc.

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

Definition at line 40 of file ShallowTree.h.

References HLT_2018_cff::InputTag, 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 65 of file ShallowTree.h.

Referenced by analyze(), and ShallowTree().

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

Definition at line 63 of file ShallowTree.h.

Referenced by ShallowTree().

TTree* ShallowTree::tree_
private

Definition at line 64 of file ShallowTree.h.

Referenced by analyze(), and ShallowTree().