CMS 3D CMS Logo

ShallowTree.cc
Go to the documentation of this file.
1 #include "ShallowTree.h"
2 
6 
7 #include <map>
8 #include <TBranch.h>
9 
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:
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:
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:
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:
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:
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:
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:
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:
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:
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 }
170 
172  for (BranchConnector* connector : connectors_) {
173  connector->connect(iEvent);
174  }
175  tree_->Fill();
176 }
177 
178 template <class T>
180  edm::Handle<T> handle_;
181  iEvent.getByLabel(ml, pin, handle_);
182  object_ = *handle_;
183 }
184 
185 template <class T>
187  std::string t,
188  TTree* tree)
189  : ml(desc->moduleLabel()), pin(desc->productInstanceName()) {
190  object_ptr_ = &object_;
191  std::string s = pin + t;
192  if (!t.empty()) {
193  tree->Branch(pin.c_str(), object_ptr_, s.c_str());
194  } //raw type
195  else {
196  tree->Branch(pin.c_str(), &object_ptr_);
197  } //vector<type>
198 }
ShallowTree::BranchConnector
Definition: ShallowTree.h:42
ShallowTree::connectors_
std::vector< BranchConnector * > connectors_
Definition: ShallowTree.h:63
ConstProductRegistry.h
ShallowTree::SHORT_V
Definition: ShallowTree.h:72
ShallowTree::DOUBLE
Definition: ShallowTree.h:81
ShallowTree::TypedBranchConnector
Definition: ShallowTree.h:49
ShallowTree::U_INT
Definition: ShallowTree.h:77
ShallowTree::BOOL
Definition: ShallowTree.h:69
tree
Definition: tree.py:1
TFileService::file
TFile & file() const
return opened TFile
Definition: TFileService.h:37
edm::ProductSelector::initialize
void initialize(ProductSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
Definition: ProductSelector.cc:20
ShallowTree::TypedBranchConnector::object_ptr_
T * object_ptr_
Definition: ShallowTree.h:54
ShallowTree::U_SHORT
Definition: ShallowTree.h:73
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
edm::ProductSelector::selected
bool selected(BranchDescription const &desc) const
Definition: ProductSelector.cc:55
ShallowTree::U_SHORT_V
Definition: ShallowTree.h:74
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Handle
Definition: AssociativeIterator.h:50
ShallowTree::CHAR_V
Definition: ShallowTree.h:88
ShallowTree::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: ShallowTree.cc:171
ShallowTree::INT
Definition: ShallowTree.h:75
ShallowTree::U_CHAR_V
Definition: ShallowTree.h:90
alignCSCRings.s
s
Definition: alignCSCRings.py:92
ShallowTree::FLOAT_V
Definition: ShallowTree.h:80
ShallowTree::TypedBranchConnector::TypedBranchConnector
TypedBranchConnector(edm::BranchDescription const *, std::string, TTree *)
Definition: ShallowTree.cc:186
ShallowTree::TypedBranchConnector::pin
std::string pin
Definition: ShallowTree.h:52
ShallowTree::U_LONG
Definition: ShallowTree.h:85
corrVsCorr.selection
selection
main part
Definition: corrVsCorr.py:100
ShallowTree::U_LONG_V
Definition: ShallowTree.h:86
edm::ConstProductRegistry::allBranchDescriptions
std::vector< BranchDescription const * > allBranchDescriptions() const
Definition: ConstProductRegistry.h:55
ShallowTree::BOOL_V
Definition: ShallowTree.h:70
ShallowTree::ShallowTree
ShallowTree(const edm::ParameterSet &iConfig)
Definition: ShallowTree.cc:10
ShallowTree::U_INT_V
Definition: ShallowTree.h:78
ShallowTree::SHORT
Definition: ShallowTree.h:71
edm::ProductSelector
Definition: ProductSelector.h:26
edm::ProductSelectorRules
Definition: ProductSelectorRules.h:24
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ShallowTree::INT_V
Definition: ShallowTree.h:76
edm::ParameterSet
Definition: ParameterSet.h:47
ShallowTree::DOUBLE_V
Definition: ShallowTree.h:82
ShallowTree.h
ShallowTree::U_CHAR
Definition: ShallowTree.h:89
ProductSelector.h
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
ShallowTree::fs_
edm::Service< TFileService > fs_
Definition: ShallowTree.h:61
ShallowTree::TypedBranchConnector::connect
void connect(const edm::Event &) override
Definition: ShallowTree.cc:179
edm::EventSetup
Definition: EventSetup.h:57
ShallowTree::FLOAT
Definition: ShallowTree.h:79
ShallowTree::tree_
TTree * tree_
Definition: ShallowTree.h:62
ShallowTree::LONG
Definition: ShallowTree.h:83
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
Exception
Definition: hltDiff.cc:246
TFileService::kSharedResource
static const std::string kSharedResource
Definition: TFileService.h:76
ShallowTree::CHAR
Definition: ShallowTree.h:87
edm::BranchDescription
Definition: BranchDescription.h:32
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::errors::Configuration
Definition: EDMException.h:36
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
ShallowTree::TypedBranchConnector::object_
T object_
Definition: ShallowTree.h:53
ProductSelectorRules.h
ShallowTree::LONG_V
Definition: ShallowTree.h:84