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

Public Member Functions

 ShallowTree (const edm::ParameterSet &iConfig)
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::SharedResources >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const noexcept
 
bool wantsStreamRuns () const noexcept
 
 ~EDAnalyzerBase () 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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

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

Private Attributes

std::vector< BranchConnector * > connectors_
 
edm::Service< TFileServicefs_
 
TTree * tree_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

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

◆ LEAFTYPE

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 68 of file ShallowTree.h.

Constructor & Destructor Documentation

◆ ShallowTree()

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

Member Function Documentation

◆ analyze()

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

Implements edm::one::EDAnalyzerBase.

Definition at line 171 of file ShallowTree.cc.

References connectors_, iEvent, and tree_.

171  {
172  for (BranchConnector* connector : connectors_) {
173  connector->connect(iEvent);
174  }
175  tree_->Fill();
176 }
int iEvent
Definition: GenABIO.cc:224
TTree * tree_
Definition: ShallowTree.h:62
std::vector< BranchConnector * > connectors_
Definition: ShallowTree.h:63

◆ eat()

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

Definition at line 38 of file ShallowTree.h.

References submitPVResolutionJobs::desc, and ProducerED_cfi::InputTag.

38  {
39  consumes<T>(edm::InputTag(desc->moduleLabel(), desc->productInstanceName()));
40  }

Member Data Documentation

◆ connectors_

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

Definition at line 63 of file ShallowTree.h.

Referenced by analyze(), and ShallowTree().

◆ fs_

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

Definition at line 61 of file ShallowTree.h.

Referenced by ShallowTree().

◆ tree_

TTree* ShallowTree::tree_
private

Definition at line 62 of file ShallowTree.h.

Referenced by analyze(), and ShallowTree().