CMS 3D CMS Logo

ShallowTree.cc
Go to the documentation of this file.
2 
6 
7 #include <map>
8 #include <TBranch.h>
9 
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:
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:
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:
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:
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:
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:
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:
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:
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:
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 }
168 
170  for (BranchConnector* connector : connectors_) {
171  connector->connect(iEvent);
172  }
173  tree_->Fill();
174 }
175 
176 template <class T>
178  edm::Handle<T> handle_;
179  iEvent.getByLabel(ml, pin, handle_);
180  object_ = *handle_;
181 }
182 
183 template <class T>
185  std::string t,
186  TTree* tree)
187  : ml(desc->moduleLabel()), pin(desc->productInstanceName()) {
188  object_ptr_ = &object_;
189  std::string s = pin + t;
190  if (!t.empty()) {
191  tree->Branch(pin.c_str(), object_ptr_, s.c_str());
192  } //raw type
193  else {
194  tree->Branch(pin.c_str(), &object_ptr_);
195  } //vector<type>
196 }
197 
ShallowTree::BranchConnector
Definition: ShallowTree.h:44
ShallowTree::connectors_
std::vector< BranchConnector * > connectors_
Definition: ShallowTree.h:65
ConstProductRegistry.h
ShallowTree::SHORT_V
Definition: ShallowTree.h:74
ShallowTree::DOUBLE
Definition: ShallowTree.h:83
ShallowTree::TypedBranchConnector
Definition: ShallowTree.h:51
ShallowTree::U_INT
Definition: ShallowTree.h:79
ShallowTree::BOOL
Definition: ShallowTree.h:71
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:56
ShallowTree::U_SHORT
Definition: ShallowTree.h:75
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
edm::ProductSelector::selected
bool selected(BranchDescription const &desc) const
Definition: ProductSelector.cc:55
ShallowTree::U_SHORT_V
Definition: ShallowTree.h:76
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Handle
Definition: AssociativeIterator.h:50
ShallowTree::CHAR_V
Definition: ShallowTree.h:90
ShallowTree::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: ShallowTree.cc:169
ShallowTree::INT
Definition: ShallowTree.h:77
ShallowTree::U_CHAR_V
Definition: ShallowTree.h:92
alignCSCRings.s
s
Definition: alignCSCRings.py:92
ShallowTree::FLOAT_V
Definition: ShallowTree.h:82
ShallowTree::TypedBranchConnector::TypedBranchConnector
TypedBranchConnector(edm::BranchDescription const *, std::string, TTree *)
Definition: ShallowTree.cc:184
ShallowTree::TypedBranchConnector::pin
std::string pin
Definition: ShallowTree.h:54
ShallowTree::U_LONG
Definition: ShallowTree.h:87
corrVsCorr.selection
selection
main part
Definition: corrVsCorr.py:100
ShallowTree::U_LONG_V
Definition: ShallowTree.h:88
edm::ConstProductRegistry::allBranchDescriptions
std::vector< BranchDescription const * > allBranchDescriptions() const
Definition: ConstProductRegistry.h:55
ShallowTree::BOOL_V
Definition: ShallowTree.h:72
ShallowTree::ShallowTree
ShallowTree(const edm::ParameterSet &iConfig)
Definition: ShallowTree.cc:10
OrderedSet.t
t
Definition: OrderedSet.py:90
ShallowTree::U_INT_V
Definition: ShallowTree.h:80
ShallowTree::SHORT
Definition: ShallowTree.h:73
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:78
edm::ParameterSet
Definition: ParameterSet.h:36
ShallowTree::DOUBLE_V
Definition: ShallowTree.h:84
ShallowTree.h
ShallowTree::U_CHAR
Definition: ShallowTree.h:91
ProductSelector.h
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
ShallowTree::fs_
edm::Service< TFileService > fs_
Definition: ShallowTree.h:63
ShallowTree::TypedBranchConnector::connect
void connect(const edm::Event &) override
Definition: ShallowTree.cc:177
edm::EventSetup
Definition: EventSetup.h:57
ShallowTree::FLOAT
Definition: ShallowTree.h:81
ShallowTree::tree_
TTree * tree_
Definition: ShallowTree.h:64
ShallowTree::LONG
Definition: ShallowTree.h:85
ShallowTree::beginJob
void beginJob() override
Definition: ShallowTree.cc:198
Exception
Definition: hltDiff.cc:246
ShallowTree::CHAR
Definition: ShallowTree.h:89
edm::BranchDescription
Definition: BranchDescription.h:32
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
edm::Event
Definition: Event.h:73
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:55
ProductSelectorRules.h
ShallowTree::LONG_V
Definition: ShallowTree.h:86