File indexing completed on 2024-11-19 23:20:32
0001
0002
0003
0004 #include "ttreex.h"
0005
0006 using namespace RooUtil;
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 RooUtil::TTreeX::TTreeX() { ttree = 0; }
0018
0019
0020 RooUtil::TTreeX::TTreeX(TString treename, TString title) { ttree = new TTree(treename.Data(), title.Data()); }
0021
0022
0023 RooUtil::TTreeX::TTreeX(TTree* tree) { ttree = tree; }
0024
0025
0026 RooUtil::TTreeX::~TTreeX() {}
0027
0028
0029 void* RooUtil::TTreeX::getValPtr(TString brname) {
0030 TBranch* br = ttree->GetBranch(brname);
0031 unsigned int nleaves = br->GetListOfLeaves()->GetEntries();
0032 if (nleaves != 1)
0033 RooUtil::error("# of leaf for this branch=" + brname + " is not equals to 1!", __FUNCTION__);
0034 if (!(((TLeaf*)br->GetListOfLeaves()->At(0))->GetValuePointer()))
0035 ttree->GetEntry(0);
0036 return ((TLeaf*)br->GetListOfLeaves()->At(0))->GetValuePointer();
0037 }
0038
0039
0040 void RooUtil::TTreeX::clear() {
0041 for (auto& pair : mapInt_t)
0042 pair.second = -999;
0043 for (auto& pair : mapBool_t)
0044 pair.second = 0;
0045 for (auto& pair : mapFloat_t)
0046 pair.second = -999;
0047 for (auto& pair : mapTString)
0048 pair.second = "";
0049 for (auto& pair : mapLV)
0050 pair.second.SetXYZT(0, 0, 0, 0);
0051 for (auto& pair : mapTBits)
0052 pair.second = 0;
0053 for (auto& pair : mapULL)
0054 pair.second = 0;
0055 for (auto& pair : mapUI)
0056 pair.second = 0;
0057 for (auto& pair : mapVecInt_t)
0058 pair.second.clear();
0059 for (auto& pair : mapVecUInt_t)
0060 pair.second.clear();
0061 for (auto& pair : mapVecBool_t)
0062 pair.second.clear();
0063 for (auto& pair : mapVecFloat_t)
0064 pair.second.clear();
0065 for (auto& pair : mapVecTString)
0066 pair.second.clear();
0067 for (auto& pair : mapVecLV)
0068 pair.second.clear();
0069 for (auto& pair : mapVecVInt)
0070 pair.second.clear();
0071 for (auto& pair : mapVecVFloat)
0072 pair.second.clear();
0073 for (auto& pair : mapIsBranchSet)
0074 pair.second = false;
0075 }
0076
0077
0078 void RooUtil::TTreeX::save(TFile* ofile) {
0079 RooUtil::print(Form("TTreeX::save() saving tree to %s", ofile->GetName()));
0080 ofile->cd();
0081 this->ttree->Write();
0082 }
0083
0084
0085 void TTreeX::sortVecBranchesByPt(TString p4_bn,
0086 std::vector<TString> aux_float_bns,
0087 std::vector<TString> aux_int_bns,
0088 std::vector<TString> aux_bool_bns) {
0089
0090
0091
0092
0093
0094 std::vector<std::pair<size_t, lviter>> order(mapVecLV[p4_bn.Data()].size());
0095
0096 size_t n = 0;
0097 for (lviter it = mapVecLV[p4_bn.Data()].begin(); it != mapVecLV[p4_bn.Data()].end(); ++it, ++n)
0098 order[n] = make_pair(n, it);
0099
0100 sort(order.begin(), order.end(), ordering());
0101
0102
0103 mapVecLV[p4_bn.Data()] = sortFromRef<LV>(mapVecLV[p4_bn.Data()], order);
0104
0105 for (auto& aux_float_bn : aux_float_bns)
0106 mapVecFloat_t[aux_float_bn.Data()] = sortFromRef<Float_t>(mapVecFloat_t[aux_float_bn.Data()], order);
0107
0108 for (auto& aux_int_bn : aux_int_bns)
0109 mapVecInt_t[aux_int_bn.Data()] = sortFromRef<Int_t>(mapVecInt_t[aux_int_bn.Data()], order);
0110
0111 for (auto& aux_bool_bn : aux_bool_bns)
0112 mapVecBool_t[aux_bool_bn.Data()] = sortFromRef<Bool_t>(mapVecBool_t[aux_bool_bn.Data()], order);
0113 }
0114
0115
0116 void TTreeX::createFlatBranch(std::vector<TString> p4_bns,
0117 std::vector<TString> float_bns,
0118 std::vector<TString> int_bns,
0119 std::vector<TString> bool_bns,
0120 int multiplicity) {
0121 for (auto& p4_bn : p4_bns) {
0122 for (int i = 0; i < multiplicity; ++i)
0123 createBranch<LV>(TString::Format("%s_%d", p4_bn.Data(), i));
0124 }
0125 for (auto& float_bn : float_bns) {
0126 for (int i = 0; i < multiplicity; ++i)
0127 createBranch<float>(TString::Format("%s_%d", float_bn.Data(), i));
0128 }
0129 for (auto& int_bn : int_bns) {
0130 for (int i = 0; i < multiplicity; ++i)
0131 createBranch<int>(TString::Format("%s_%d", int_bn.Data(), i));
0132 }
0133 for (auto& bool_bn : bool_bns) {
0134 for (int i = 0; i < multiplicity; ++i)
0135 createBranch<bool>(TString::Format("%s_%d", bool_bn.Data(), i));
0136 }
0137 }
0138
0139
0140 void TTreeX::setFlatBranch(std::vector<TString> p4_bns,
0141 std::vector<TString> float_bns,
0142 std::vector<TString> int_bns,
0143 std::vector<TString> bool_bns,
0144 int multiplicity) {
0145 for (auto& p4_bn : p4_bns) {
0146 const std::vector<LV>& vec = getBranch<std::vector<LV>>(p4_bn, false);
0147 for (int i = 0; i < multiplicity && i < (int)vec.size(); ++i)
0148 setBranch<LV>(TString::Format("%s_%d", p4_bn.Data(), i), vec[i]);
0149 }
0150 for (auto& float_bn : float_bns) {
0151 const std::vector<float>& vec = getBranch<std::vector<float>>(float_bn, false);
0152 for (int i = 0; i < multiplicity && i < (int)vec.size(); ++i)
0153 setBranch<float>(TString::Format("%s_%d", float_bn.Data(), i), vec[i]);
0154 }
0155 for (auto& int_bn : int_bns) {
0156 const std::vector<int>& vec = getBranch<std::vector<int>>(int_bn, false);
0157 for (int i = 0; i < multiplicity && i < (int)vec.size(); ++i)
0158 setBranch<int>(TString::Format("%s_%d", int_bn.Data(), i), vec[i]);
0159 }
0160 for (auto& bool_bn : bool_bns) {
0161 const std::vector<bool>& vec = getBranch<std::vector<bool>>(bool_bn, false);
0162 for (int i = 0; i < multiplicity && i < (int)vec.size(); ++i)
0163 setBranch<bool>(TString::Format("%s_%d", bool_bn.Data(), i), vec[i]);
0164 }
0165 }
0166
0167
0168 template <>
0169 void TTreeX::setBranch<Int_t>(TString bn, Int_t val, bool force, bool ignore) {
0170 if (force) {
0171 mapInt_t[bn.Data()] = val;
0172 mapIsBranchSet[bn.Data()] = true;
0173 return;
0174 }
0175 if (mapInt_t.find(bn.Data()) != mapInt_t.end()) {
0176 mapInt_t[bn.Data()] = val;
0177 mapIsBranchSet[bn.Data()] = true;
0178 } else {
0179 if (!ignore)
0180 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0181 }
0182 }
0183 template <>
0184 void TTreeX::setBranch<Bool_t>(TString bn, Bool_t val, bool force, bool ignore) {
0185 if (force) {
0186 mapBool_t[bn.Data()] = val;
0187 mapIsBranchSet[bn.Data()] = true;
0188 return;
0189 }
0190 if (mapBool_t.find(bn.Data()) != mapBool_t.end()) {
0191 mapBool_t[bn.Data()] = val;
0192 mapIsBranchSet[bn.Data()] = true;
0193 } else {
0194 if (!ignore)
0195 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0196 }
0197 }
0198 template <>
0199 void TTreeX::setBranch<Float_t>(TString bn, Float_t val, bool force, bool ignore) {
0200 if (force) {
0201 mapFloat_t[bn.Data()] = val;
0202 mapIsBranchSet[bn.Data()] = true;
0203 return;
0204 }
0205 if (mapFloat_t.find(bn.Data()) != mapFloat_t.end()) {
0206 mapFloat_t[bn.Data()] = val;
0207 mapIsBranchSet[bn.Data()] = true;
0208 } else {
0209 if (!ignore)
0210 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0211 }
0212 }
0213 template <>
0214 void TTreeX::setBranch<TString>(TString bn, TString val, bool force, bool ignore) {
0215 if (force) {
0216 mapTString[bn.Data()] = val;
0217 mapIsBranchSet[bn.Data()] = true;
0218 return;
0219 }
0220 if (mapTString.find(bn.Data()) != mapTString.end()) {
0221 mapTString[bn.Data()] = val;
0222 mapIsBranchSet[bn.Data()] = true;
0223 } else {
0224 if (!ignore)
0225 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0226 }
0227 }
0228 template <>
0229 void TTreeX::setBranch<LV>(TString bn, LV val, bool force, bool ignore) {
0230 if (force) {
0231 mapLV[bn.Data()] = val;
0232 mapIsBranchSet[bn.Data()] = true;
0233 return;
0234 }
0235 if (mapLV.find(bn.Data()) != mapLV.end()) {
0236 mapLV[bn.Data()] = val;
0237 mapIsBranchSet[bn.Data()] = true;
0238 } else {
0239 if (!ignore)
0240 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0241 }
0242 }
0243 template <>
0244 void TTreeX::setBranch<TBits>(TString bn, TBits val, bool force, bool ignore) {
0245 if (force) {
0246 mapTBits[bn.Data()] = val;
0247 mapIsBranchSet[bn.Data()] = true;
0248 return;
0249 }
0250 if (mapTBits.find(bn.Data()) != mapTBits.end()) {
0251 mapTBits[bn.Data()] = val;
0252 mapIsBranchSet[bn.Data()] = true;
0253 } else {
0254 if (!ignore)
0255 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0256 }
0257 }
0258 template <>
0259 void TTreeX::setBranch<unsigned long long>(TString bn, unsigned long long val, bool force, bool ignore) {
0260 if (force) {
0261 mapULL[bn.Data()] = val;
0262 mapIsBranchSet[bn.Data()] = true;
0263 return;
0264 }
0265 if (mapULL.find(bn.Data()) != mapULL.end()) {
0266 mapULL[bn.Data()] = val;
0267 mapIsBranchSet[bn.Data()] = true;
0268 } else {
0269 if (!ignore)
0270 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0271 }
0272 }
0273 template <>
0274 void TTreeX::setBranch<unsigned int>(TString bn, unsigned int val, bool force, bool ignore) {
0275 if (force) {
0276 mapUI[bn.Data()] = val;
0277 mapIsBranchSet[bn.Data()] = true;
0278 return;
0279 }
0280 if (mapUI.find(bn.Data()) != mapUI.end()) {
0281 mapUI[bn.Data()] = val;
0282 mapIsBranchSet[bn.Data()] = true;
0283 } else {
0284 if (!ignore)
0285 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0286 }
0287 }
0288 template <>
0289 void TTreeX::setBranch<std::vector<Int_t>>(TString bn, std::vector<Int_t> val, bool force, bool ignore) {
0290 if (force) {
0291 mapVecInt_t[bn.Data()] = val;
0292 mapIsBranchSet[bn.Data()] = true;
0293 return;
0294 }
0295 if (mapVecInt_t.find(bn.Data()) != mapVecInt_t.end()) {
0296 mapVecInt_t[bn.Data()] = val;
0297 mapIsBranchSet[bn.Data()] = true;
0298 } else {
0299 if (!ignore)
0300 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0301 }
0302 }
0303 template <>
0304 void TTreeX::setBranch<std::vector<UInt_t>>(TString bn, std::vector<UInt_t> val, bool force, bool ignore) {
0305 if (force) {
0306 mapVecUInt_t[bn.Data()] = val;
0307 mapIsBranchSet[bn.Data()] = true;
0308 return;
0309 }
0310 if (mapVecUInt_t.find(bn.Data()) != mapVecUInt_t.end()) {
0311 mapVecUInt_t[bn.Data()] = val;
0312 mapIsBranchSet[bn.Data()] = true;
0313 } else {
0314 if (!ignore)
0315 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0316 }
0317 }
0318 template <>
0319 void TTreeX::setBranch<std::vector<Bool_t>>(TString bn, std::vector<Bool_t> val, bool force, bool ignore) {
0320 if (force) {
0321 mapVecBool_t[bn.Data()] = val;
0322 mapIsBranchSet[bn.Data()] = true;
0323 return;
0324 }
0325 if (mapVecBool_t.find(bn.Data()) != mapVecBool_t.end()) {
0326 mapVecBool_t[bn.Data()] = val;
0327 mapIsBranchSet[bn.Data()] = true;
0328 } else {
0329 if (!ignore)
0330 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0331 }
0332 }
0333 template <>
0334 void TTreeX::setBranch<std::vector<Float_t>>(TString bn, std::vector<Float_t> val, bool force, bool ignore) {
0335 if (force) {
0336 mapVecFloat_t[bn.Data()] = val;
0337 mapIsBranchSet[bn.Data()] = true;
0338 return;
0339 }
0340 if (mapVecFloat_t.find(bn.Data()) != mapVecFloat_t.end()) {
0341 mapVecFloat_t[bn.Data()] = val;
0342 mapIsBranchSet[bn.Data()] = true;
0343 } else {
0344 if (!ignore)
0345 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0346 }
0347 }
0348 template <>
0349 void TTreeX::setBranch<std::vector<TString>>(TString bn, std::vector<TString> val, bool force, bool ignore) {
0350 if (force) {
0351 mapVecTString[bn.Data()] = val;
0352 mapIsBranchSet[bn.Data()] = true;
0353 return;
0354 }
0355 if (mapVecTString.find(bn.Data()) != mapVecTString.end()) {
0356 mapVecTString[bn.Data()] = val;
0357 mapIsBranchSet[bn.Data()] = true;
0358 } else {
0359 if (!ignore)
0360 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0361 }
0362 }
0363 template <>
0364 void TTreeX::setBranch<std::vector<LV>>(TString bn, std::vector<LV> val, bool force, bool ignore) {
0365 if (force) {
0366 mapVecLV[bn.Data()] = val;
0367 mapIsBranchSet[bn.Data()] = true;
0368 return;
0369 }
0370 if (mapVecLV.find(bn.Data()) != mapVecLV.end()) {
0371 mapVecLV[bn.Data()] = val;
0372 mapIsBranchSet[bn.Data()] = true;
0373 } else {
0374 if (!ignore)
0375 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0376 }
0377 }
0378 template <>
0379 void TTreeX::setBranch<std::vector<VInt>>(TString bn, std::vector<VInt> val, bool force, bool ignore) {
0380 if (force) {
0381 mapVecVInt[bn.Data()] = val;
0382 mapIsBranchSet[bn.Data()] = true;
0383 return;
0384 }
0385 if (mapVecVInt.find(bn.Data()) != mapVecVInt.end()) {
0386 mapVecVInt[bn.Data()] = val;
0387 mapIsBranchSet[bn.Data()] = true;
0388 } else {
0389 if (!ignore)
0390 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0391 }
0392 }
0393 template <>
0394 void TTreeX::setBranch<std::vector<VFloat>>(TString bn, std::vector<VFloat> val, bool force, bool ignore) {
0395 if (force) {
0396 mapVecVFloat[bn.Data()] = val;
0397 mapIsBranchSet[bn.Data()] = true;
0398 return;
0399 }
0400 if (mapVecVFloat.find(bn.Data()) != mapVecVFloat.end()) {
0401 mapVecVFloat[bn.Data()] = val;
0402 mapIsBranchSet[bn.Data()] = true;
0403 } else {
0404 if (!ignore)
0405 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0406 }
0407 }
0408 template <>
0409 void TTreeX::pushbackToBranch<Int_t>(TString bn, Int_t val) {
0410 if (mapVecInt_t.find(bn.Data()) != mapVecInt_t.end()) {
0411 mapVecInt_t[bn.Data()].push_back(val);
0412 mapIsBranchSet[bn.Data()] = true;
0413 } else {
0414 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0415 }
0416 }
0417 template <>
0418 void TTreeX::pushbackToBranch<UInt_t>(TString bn, UInt_t val) {
0419 if (mapVecUInt_t.find(bn.Data()) != mapVecUInt_t.end()) {
0420 mapVecUInt_t[bn.Data()].push_back(val);
0421 mapIsBranchSet[bn.Data()] = true;
0422 } else {
0423 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0424 }
0425 }
0426 template <>
0427 void TTreeX::pushbackToBranch<Bool_t>(TString bn, Bool_t val) {
0428 if (mapVecBool_t.find(bn.Data()) != mapVecBool_t.end()) {
0429 mapVecBool_t[bn.Data()].push_back(val);
0430 mapIsBranchSet[bn.Data()] = true;
0431 } else {
0432 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0433 }
0434 }
0435 template <>
0436 void TTreeX::pushbackToBranch<Float_t>(TString bn, Float_t val) {
0437 if (mapVecFloat_t.find(bn.Data()) != mapVecFloat_t.end()) {
0438 mapVecFloat_t[bn.Data()].push_back(val);
0439 mapIsBranchSet[bn.Data()] = true;
0440 } else {
0441 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0442 }
0443 }
0444 template <>
0445 void TTreeX::pushbackToBranch<TString>(TString bn, TString val) {
0446 if (mapVecTString.find(bn.Data()) != mapVecTString.end()) {
0447 mapVecTString[bn.Data()].push_back(val);
0448 mapIsBranchSet[bn.Data()] = true;
0449 } else {
0450 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0451 }
0452 }
0453 template <>
0454 void TTreeX::pushbackToBranch<LV>(TString bn, LV val) {
0455 if (mapVecLV.find(bn.Data()) != mapVecLV.end()) {
0456 mapVecLV[bn.Data()].push_back(val);
0457 mapIsBranchSet[bn.Data()] = true;
0458 } else {
0459 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0460 }
0461 }
0462 template <>
0463 void TTreeX::pushbackToBranch<VInt>(TString bn, VInt val) {
0464 if (mapVecVInt.find(bn.Data()) != mapVecVInt.end()) {
0465 mapVecVInt[bn.Data()].push_back(val);
0466 mapIsBranchSet[bn.Data()] = true;
0467 } else {
0468 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0469 }
0470 }
0471 template <>
0472 void TTreeX::pushbackToBranch<VFloat>(TString bn, VFloat val) {
0473 if (mapVecVFloat.find(bn.Data()) != mapVecVFloat.end()) {
0474 mapVecVFloat[bn.Data()].push_back(val);
0475 mapIsBranchSet[bn.Data()] = true;
0476 } else {
0477 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0478 }
0479 }
0480
0481 template <>
0482 void TTreeX::setBranch<std::function<float()>>(TString bn, std::function<float()> val, bool force, bool ignore) {
0483 if (force) {
0484 mapFloatFunc_t[bn.Data()] = val;
0485 mapIsBranchSet[bn.Data()] = true;
0486 return;
0487 }
0488 if (mapFloatFunc_t.find(bn.Data()) != mapFloatFunc_t.end()) {
0489 mapFloatFunc_t[bn.Data()] = val;
0490 mapIsBranchSet[bn.Data()] = true;
0491 } else {
0492 if (!ignore)
0493 error(TString::Format("branch doesn't exist bn = %s", bn.Data()));
0494 }
0495 }
0496
0497
0498 template <>
0499 const Int_t& TTreeX::getBranch<Int_t>(TString bn, bool check) {
0500 if (check)
0501 if (!mapIsBranchSet[bn.Data()])
0502 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0503 return mapInt_t[bn.Data()];
0504 }
0505 template <>
0506 const Bool_t& TTreeX::getBranch<Bool_t>(TString bn, bool check) {
0507 if (check)
0508 if (!mapIsBranchSet[bn.Data()])
0509 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0510 return mapBool_t[bn.Data()];
0511 }
0512 template <>
0513 const Float_t& TTreeX::getBranch<Float_t>(TString bn, bool check) {
0514 if (check)
0515 if (!mapIsBranchSet[bn.Data()])
0516 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0517 return mapFloat_t[bn.Data()];
0518 }
0519 template <>
0520 const TString& TTreeX::getBranch<TString>(TString bn, bool check) {
0521 if (check)
0522 if (!mapIsBranchSet[bn.Data()])
0523 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0524 return mapTString[bn.Data()];
0525 }
0526 template <>
0527 const LV& TTreeX::getBranch<LV>(TString bn, bool check) {
0528 if (check)
0529 if (!mapIsBranchSet[bn.Data()])
0530 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0531 return mapLV[bn.Data()];
0532 }
0533 template <>
0534 const TBits& TTreeX::getBranch<TBits>(TString bn, bool check) {
0535 if (check)
0536 if (!mapIsBranchSet[bn.Data()])
0537 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0538 return mapTBits[bn.Data()];
0539 }
0540 template <>
0541 const unsigned long long& TTreeX::getBranch<unsigned long long>(TString bn, bool check) {
0542 if (check)
0543 if (!mapIsBranchSet[bn.Data()])
0544 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0545 return mapULL[bn.Data()];
0546 }
0547 template <>
0548 const unsigned int& TTreeX::getBranch<unsigned int>(TString bn, bool check) {
0549 if (check)
0550 if (!mapIsBranchSet[bn.Data()])
0551 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0552 return mapUI[bn.Data()];
0553 }
0554 template <>
0555 const std::vector<Int_t>& TTreeX::getBranch<std::vector<Int_t>>(TString bn, bool check) {
0556 if (check)
0557 if (!mapIsBranchSet[bn.Data()])
0558 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0559 return mapVecInt_t[bn.Data()];
0560 }
0561 template <>
0562 const std::vector<UInt_t>& TTreeX::getBranch<std::vector<UInt_t>>(TString bn, bool check) {
0563 if (check)
0564 if (!mapIsBranchSet[bn.Data()])
0565 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0566 return mapVecUInt_t[bn.Data()];
0567 }
0568 template <>
0569 const std::vector<Bool_t>& TTreeX::getBranch<std::vector<Bool_t>>(TString bn, bool check) {
0570 if (check)
0571 if (!mapIsBranchSet[bn.Data()])
0572 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0573 return mapVecBool_t[bn.Data()];
0574 }
0575 template <>
0576 const std::vector<Float_t>& TTreeX::getBranch<std::vector<Float_t>>(TString bn, bool check) {
0577 if (check)
0578 if (!mapIsBranchSet[bn.Data()])
0579 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0580 return mapVecFloat_t[bn.Data()];
0581 }
0582 template <>
0583 const std::vector<TString>& TTreeX::getBranch<std::vector<TString>>(TString bn, bool check) {
0584 if (check)
0585 if (!mapIsBranchSet[bn.Data()])
0586 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0587 return mapVecTString[bn.Data()];
0588 }
0589 template <>
0590 const std::vector<LV>& TTreeX::getBranch<std::vector<LV>>(TString bn, bool check) {
0591 if (check)
0592 if (!mapIsBranchSet[bn.Data()])
0593 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0594 return mapVecLV[bn.Data()];
0595 }
0596 template <>
0597 const std::vector<VInt>& TTreeX::getBranch<std::vector<VInt>>(TString bn, bool check) {
0598 if (check)
0599 if (!mapIsBranchSet[bn.Data()])
0600 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0601 return mapVecVInt[bn.Data()];
0602 }
0603 template <>
0604 const std::vector<VFloat>& TTreeX::getBranch<std::vector<VFloat>>(TString bn, bool check) {
0605 if (check)
0606 if (!mapIsBranchSet[bn.Data()])
0607 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0608 return mapVecVFloat[bn.Data()];
0609 }
0610
0611 template <>
0612 const std::function<float()>& TTreeX::getBranch<std::function<float()>>(TString bn, bool check) {
0613 if (check)
0614 if (!mapIsBranchSet[bn.Data()])
0615 error(TString::Format("branch hasn't been set yet bn = %s", bn.Data()));
0616 return mapFloatFunc_t[bn.Data()];
0617 }
0618
0619
0620 template <>
0621 const Int_t& TTreeX::getBranchLazy<Int_t>(TString bn) {
0622 return getBranch<Int_t>(bn, false);
0623 }
0624 template <>
0625 const Bool_t& TTreeX::getBranchLazy<Bool_t>(TString bn) {
0626 return getBranch<Bool_t>(bn, false);
0627 }
0628 template <>
0629 const Float_t& TTreeX::getBranchLazy<Float_t>(TString bn) {
0630 return getBranch<Float_t>(bn, false);
0631 }
0632 template <>
0633 const TString& TTreeX::getBranchLazy<TString>(TString bn) {
0634 return getBranch<TString>(bn, false);
0635 }
0636 template <>
0637 const LV& TTreeX::getBranchLazy<LV>(TString bn) {
0638 return getBranch<LV>(bn, false);
0639 }
0640 template <>
0641 const TBits& TTreeX::getBranchLazy<TBits>(TString bn) {
0642 return getBranch<TBits>(bn, false);
0643 }
0644 template <>
0645 const unsigned long long& TTreeX::getBranchLazy<unsigned long long>(TString bn) {
0646 return getBranch<unsigned long long>(bn, false);
0647 }
0648 template <>
0649 const unsigned int& TTreeX::getBranchLazy<unsigned int>(TString bn) {
0650 return getBranch<unsigned int>(bn, false);
0651 }
0652 template <>
0653 const std::vector<Int_t>& TTreeX::getBranchLazy<std::vector<Int_t>>(TString bn) {
0654 return getBranch<std::vector<Int_t>>(bn, false);
0655 }
0656 template <>
0657 const std::vector<UInt_t>& TTreeX::getBranchLazy<std::vector<UInt_t>>(TString bn) {
0658 return getBranch<std::vector<UInt_t>>(bn, false);
0659 }
0660 template <>
0661 const std::vector<Bool_t>& TTreeX::getBranchLazy<std::vector<Bool_t>>(TString bn) {
0662 return getBranch<std::vector<Bool_t>>(bn, false);
0663 }
0664 template <>
0665 const std::vector<Float_t>& TTreeX::getBranchLazy<std::vector<Float_t>>(TString bn) {
0666 return getBranch<std::vector<Float_t>>(bn, false);
0667 }
0668 template <>
0669 const std::vector<TString>& TTreeX::getBranchLazy<std::vector<TString>>(TString bn) {
0670 return getBranch<std::vector<TString>>(bn, false);
0671 }
0672 template <>
0673 const std::vector<LV>& TTreeX::getBranchLazy<std::vector<LV>>(TString bn) {
0674 return getBranch<std::vector<LV>>(bn, false);
0675 }
0676 template <>
0677 const std::vector<VInt>& TTreeX::getBranchLazy<std::vector<VInt>>(TString bn) {
0678 return getBranch<std::vector<VInt>>(bn, false);
0679 }
0680 template <>
0681 const std::vector<VFloat>& TTreeX::getBranchLazy<std::vector<VFloat>>(TString bn) {
0682 return getBranch<std::vector<VFloat>>(bn, false);
0683 }
0684
0685 template <>
0686 const std::function<float()>& TTreeX::getBranchLazy<std::function<float()>>(TString bn) {
0687 return getBranch<std::function<float()>>(bn, false);
0688 }
0689
0690
0691 template <>
0692 bool TTreeX::isBranchSet<Int_t>(TString bn) {
0693 return mapIsBranchSet[bn.Data()];
0694 }
0695 template <>
0696 bool TTreeX::isBranchSet<Bool_t>(TString bn) {
0697 return mapIsBranchSet[bn.Data()];
0698 }
0699 template <>
0700 bool TTreeX::isBranchSet<Float_t>(TString bn) {
0701 return mapIsBranchSet[bn.Data()];
0702 }
0703 template <>
0704 bool TTreeX::isBranchSet<TString>(TString bn) {
0705 return mapIsBranchSet[bn.Data()];
0706 }
0707 template <>
0708 bool TTreeX::isBranchSet<LV>(TString bn) {
0709 return mapIsBranchSet[bn.Data()];
0710 }
0711 template <>
0712 bool TTreeX::isBranchSet<TBits>(TString bn) {
0713 return mapIsBranchSet[bn.Data()];
0714 }
0715 template <>
0716 bool TTreeX::isBranchSet<unsigned long long>(TString bn) {
0717 return mapIsBranchSet[bn.Data()];
0718 }
0719 template <>
0720 bool TTreeX::isBranchSet<unsigned int>(TString bn) {
0721 return mapIsBranchSet[bn.Data()];
0722 }
0723 template <>
0724 bool TTreeX::isBranchSet<std::vector<Int_t>>(TString bn) {
0725 return mapIsBranchSet[bn.Data()];
0726 }
0727 template <>
0728 bool TTreeX::isBranchSet<std::vector<UInt_t>>(TString bn) {
0729 return mapIsBranchSet[bn.Data()];
0730 }
0731 template <>
0732 bool TTreeX::isBranchSet<std::vector<Bool_t>>(TString bn) {
0733 return mapIsBranchSet[bn.Data()];
0734 }
0735 template <>
0736 bool TTreeX::isBranchSet<std::vector<Float_t>>(TString bn) {
0737 return mapIsBranchSet[bn.Data()];
0738 }
0739 template <>
0740 bool TTreeX::isBranchSet<std::vector<TString>>(TString bn) {
0741 return mapIsBranchSet[bn.Data()];
0742 }
0743 template <>
0744 bool TTreeX::isBranchSet<std::vector<LV>>(TString bn) {
0745 return mapIsBranchSet[bn.Data()];
0746 }
0747 template <>
0748 bool TTreeX::isBranchSet<std::vector<VInt>>(TString bn) {
0749 return mapIsBranchSet[bn.Data()];
0750 }
0751 template <>
0752 bool TTreeX::isBranchSet<std::vector<VFloat>>(TString bn) {
0753 return mapIsBranchSet[bn.Data()];
0754 }
0755
0756 template <>
0757 bool TTreeX::isBranchSet<std::function<float()>>(TString bn) {
0758 return mapIsBranchSet[bn.Data()];
0759 }
0760
0761
0762 template <>
0763 Int_t* TTreeX::getBranchAddress<Int_t>(TString bn) {
0764 return &mapInt_t[bn.Data()];
0765 }
0766 template <>
0767 Bool_t* TTreeX::getBranchAddress<Bool_t>(TString bn) {
0768 return &mapBool_t[bn.Data()];
0769 }
0770 template <>
0771 Float_t* TTreeX::getBranchAddress<Float_t>(TString bn) {
0772 return &mapFloat_t[bn.Data()];
0773 }
0774
0775
0776 template <>
0777 void TTreeX::createBranch<Int_t>(TString bn, bool writeToTree) {
0778 if (mapInt_t.find(bn.Data()) == mapInt_t.end()) {
0779 if (writeToTree)
0780 ttree->Branch(bn, &(mapInt_t[bn.Data()]));
0781 else
0782 mapInt_t[bn.Data()];
0783 } else {
0784 error(TString::Format("branch already exists bn = %s", bn.Data()));
0785 }
0786 }
0787 template <>
0788 void TTreeX::createBranch<Bool_t>(TString bn, bool writeToTree) {
0789 if (mapBool_t.find(bn.Data()) == mapBool_t.end()) {
0790 if (writeToTree)
0791 ttree->Branch(bn, &(mapBool_t[bn.Data()]));
0792 else
0793 mapBool_t[bn.Data()];
0794 } else {
0795 error(TString::Format("branch already exists bn = %s", bn.Data()));
0796 }
0797 }
0798 template <>
0799 void TTreeX::createBranch<Float_t>(TString bn, bool writeToTree) {
0800 if (mapFloat_t.find(bn.Data()) == mapFloat_t.end()) {
0801 if (writeToTree)
0802 ttree->Branch(bn, &(mapFloat_t[bn.Data()]));
0803 else
0804 mapFloat_t[bn.Data()];
0805 } else {
0806 error(TString::Format("branch already exists bn = %s", bn.Data()));
0807 }
0808 }
0809 template <>
0810 void TTreeX::createBranch<TString>(TString bn, bool writeToTree) {
0811 if (mapTString.find(bn.Data()) == mapTString.end()) {
0812 if (writeToTree)
0813 ttree->Branch(bn, &(mapTString[bn.Data()]));
0814 else
0815 mapTString[bn.Data()];
0816 } else {
0817 error(TString::Format("branch already exists bn = %s", bn.Data()));
0818 }
0819 }
0820 template <>
0821 void TTreeX::createBranch<LV>(TString bn, bool writeToTree) {
0822 if (mapLV.find(bn.Data()) == mapLV.end()) {
0823 if (writeToTree)
0824 ttree->Branch(bn, &(mapLV[bn.Data()]));
0825 else
0826 mapLV[bn.Data()];
0827 } else {
0828 error(TString::Format("branch already exists bn = %s", bn.Data()));
0829 }
0830 }
0831 template <>
0832 void TTreeX::createBranch<TBits>(TString bn, bool writeToTree) {
0833 if (mapTBits.find(bn.Data()) == mapTBits.end()) {
0834 if (writeToTree)
0835 ttree->Branch(bn, &(mapTBits[bn.Data()]));
0836 else
0837 mapTBits[bn.Data()];
0838 } else {
0839 error(TString::Format("branch already exists bn = %s", bn.Data()));
0840 }
0841 }
0842 template <>
0843 void TTreeX::createBranch<unsigned long long>(TString bn, bool writeToTree) {
0844 if (mapULL.find(bn.Data()) == mapULL.end()) {
0845 if (writeToTree)
0846 ttree->Branch(bn, &(mapULL[bn.Data()]));
0847 else
0848 mapULL[bn.Data()];
0849 } else {
0850 error(TString::Format("branch already exists bn = %s", bn.Data()));
0851 }
0852 }
0853 template <>
0854 void TTreeX::createBranch<unsigned int>(TString bn, bool writeToTree) {
0855 if (mapUI.find(bn.Data()) == mapUI.end()) {
0856 if (writeToTree)
0857 ttree->Branch(bn, &(mapUI[bn.Data()]));
0858 else
0859 mapUI[bn.Data()];
0860 } else {
0861 error(TString::Format("branch already exists bn = %s", bn.Data()));
0862 }
0863 }
0864 template <>
0865 void TTreeX::createBranch<std::vector<Int_t>>(TString bn, bool writeToTree) {
0866 if (mapVecInt_t.find(bn.Data()) == mapVecInt_t.end()) {
0867 if (writeToTree)
0868 ttree->Branch(bn, &(mapVecInt_t[bn.Data()]));
0869 else
0870 mapVecInt_t[bn.Data()];
0871 } else {
0872 error(TString::Format("branch already exists bn = %s", bn.Data()));
0873 }
0874 }
0875 template <>
0876 void TTreeX::createBranch<std::vector<UInt_t>>(TString bn, bool writeToTree) {
0877 if (mapVecUInt_t.find(bn.Data()) == mapVecUInt_t.end()) {
0878 if (writeToTree)
0879 ttree->Branch(bn, &(mapVecUInt_t[bn.Data()]));
0880 else
0881 mapVecUInt_t[bn.Data()];
0882 } else {
0883 error(TString::Format("branch already exists bn = %s", bn.Data()));
0884 }
0885 }
0886 template <>
0887 void TTreeX::createBranch<std::vector<Bool_t>>(TString bn, bool writeToTree) {
0888 if (mapVecBool_t.find(bn.Data()) == mapVecBool_t.end()) {
0889 if (writeToTree)
0890 ttree->Branch(bn, &(mapVecBool_t[bn.Data()]));
0891 else
0892 mapVecBool_t[bn.Data()];
0893 } else {
0894 error(TString::Format("branch already exists bn = %s", bn.Data()));
0895 }
0896 }
0897 template <>
0898 void TTreeX::createBranch<std::vector<Float_t>>(TString bn, bool writeToTree) {
0899 if (mapVecFloat_t.find(bn.Data()) == mapVecFloat_t.end()) {
0900 if (writeToTree)
0901 ttree->Branch(bn, &(mapVecFloat_t[bn.Data()]));
0902 else
0903 mapVecFloat_t[bn.Data()];
0904 } else {
0905 error(TString::Format("branch already exists bn = %s", bn.Data()));
0906 }
0907 }
0908 template <>
0909 void TTreeX::createBranch<std::vector<TString>>(TString bn, bool writeToTree) {
0910 if (mapVecTString.find(bn.Data()) == mapVecTString.end()) {
0911 if (writeToTree)
0912 ttree->Branch(bn, &(mapVecTString[bn.Data()]));
0913 else
0914 mapVecTString[bn.Data()];
0915 } else {
0916 error(TString::Format("branch already exists bn = %s", bn.Data()));
0917 }
0918 }
0919 template <>
0920 void TTreeX::createBranch<std::vector<LV>>(TString bn, bool writeToTree) {
0921 if (mapVecLV.find(bn.Data()) == mapVecLV.end()) {
0922 if (writeToTree)
0923 ttree->Branch(bn, &(mapVecLV[bn.Data()]));
0924 else
0925 mapVecLV[bn.Data()];
0926 } else {
0927 error(TString::Format("branch already exists bn = %s", bn.Data()));
0928 }
0929 }
0930 template <>
0931 void TTreeX::createBranch<std::vector<VInt>>(TString bn, bool writeToTree) {
0932 if (mapVecVInt.find(bn.Data()) == mapVecVInt.end()) {
0933 if (writeToTree)
0934 ttree->Branch(bn, &(mapVecVInt[bn.Data()]));
0935 else
0936 mapVecVInt[bn.Data()];
0937 } else {
0938 error(TString::Format("branch already exists bn = %s", bn.Data()));
0939 }
0940 }
0941 template <>
0942 void TTreeX::createBranch<std::vector<VFloat>>(TString bn, bool writeToTree) {
0943 if (mapVecVFloat.find(bn.Data()) == mapVecVFloat.end()) {
0944 if (writeToTree)
0945 ttree->Branch(bn, &(mapVecVFloat[bn.Data()]));
0946 else
0947 mapVecVFloat[bn.Data()];
0948 } else {
0949 error(TString::Format("branch already exists bn = %s", bn.Data()));
0950 }
0951 }
0952
0953 template <>
0954 void TTreeX::createBranch<std::function<float()>>(TString bn, bool writeToTree) {
0955 if (mapFloatFunc_t.find(bn.Data()) == mapFloatFunc_t.end())
0956 mapFloatFunc_t[bn.Data()];
0957 else
0958 error(TString::Format("branch already exists bn = %s", bn.Data()));
0959 }
0960
0961
0962 template <>
0963 bool TTreeX::hasBranch<Int_t>(TString bn) {
0964 if (mapInt_t.find(bn.Data()) == mapInt_t.end())
0965 return false;
0966 else
0967 return true;
0968 }
0969 template <>
0970 bool TTreeX::hasBranch<Bool_t>(TString bn) {
0971 if (mapBool_t.find(bn.Data()) == mapBool_t.end())
0972 return false;
0973 else
0974 return true;
0975 }
0976 template <>
0977 bool TTreeX::hasBranch<Float_t>(TString bn) {
0978 if (mapFloat_t.find(bn.Data()) == mapFloat_t.end())
0979 return false;
0980 else
0981 return true;
0982 }
0983 template <>
0984 bool TTreeX::hasBranch<TString>(TString bn) {
0985 if (mapTString.find(bn.Data()) == mapTString.end())
0986 return false;
0987 else
0988 return true;
0989 }
0990 template <>
0991 bool TTreeX::hasBranch<LV>(TString bn) {
0992 if (mapLV.find(bn.Data()) == mapLV.end())
0993 return false;
0994 else
0995 return true;
0996 }
0997 template <>
0998 bool TTreeX::hasBranch<TBits>(TString bn) {
0999 if (mapTBits.find(bn.Data()) == mapTBits.end())
1000 return false;
1001 else
1002 return true;
1003 }
1004 template <>
1005 bool TTreeX::hasBranch<unsigned long long>(TString bn) {
1006 if (mapULL.find(bn.Data()) == mapULL.end())
1007 return false;
1008 else
1009 return true;
1010 }
1011 template <>
1012 bool TTreeX::hasBranch<unsigned int>(TString bn) {
1013 if (mapUI.find(bn.Data()) == mapUI.end())
1014 return false;
1015 else
1016 return true;
1017 }
1018 template <>
1019 bool TTreeX::hasBranch<std::vector<Int_t>>(TString bn) {
1020 if (mapVecInt_t.find(bn.Data()) == mapVecInt_t.end())
1021 return false;
1022 else
1023 return true;
1024 }
1025 template <>
1026 bool TTreeX::hasBranch<std::vector<UInt_t>>(TString bn) {
1027 if (mapVecUInt_t.find(bn.Data()) == mapVecUInt_t.end())
1028 return false;
1029 else
1030 return true;
1031 }
1032 template <>
1033 bool TTreeX::hasBranch<std::vector<Bool_t>>(TString bn) {
1034 if (mapVecBool_t.find(bn.Data()) == mapVecBool_t.end())
1035 return false;
1036 else
1037 return true;
1038 }
1039 template <>
1040 bool TTreeX::hasBranch<std::vector<Float_t>>(TString bn) {
1041 if (mapVecFloat_t.find(bn.Data()) == mapVecFloat_t.end())
1042 return false;
1043 else
1044 return true;
1045 }
1046 template <>
1047 bool TTreeX::hasBranch<std::vector<TString>>(TString bn) {
1048 if (mapVecTString.find(bn.Data()) == mapVecTString.end())
1049 return false;
1050 else
1051 return true;
1052 }
1053 template <>
1054 bool TTreeX::hasBranch<std::vector<LV>>(TString bn) {
1055 if (mapVecLV.find(bn.Data()) == mapVecLV.end())
1056 return false;
1057 else
1058 return true;
1059 }
1060 template <>
1061 bool TTreeX::hasBranch<std::vector<VInt>>(TString bn) {
1062 if (mapVecVInt.find(bn.Data()) == mapVecVInt.end())
1063 return false;
1064 else
1065 return true;
1066 }
1067 template <>
1068 bool TTreeX::hasBranch<std::vector<VFloat>>(TString bn) {
1069 if (mapVecVFloat.find(bn.Data()) == mapVecVFloat.end())
1070 return false;
1071 else
1072 return true;
1073 }
1074
1075 template <>
1076 bool TTreeX::hasBranch<std::function<float()>>(TString bn) {
1077 if (mapFloatFunc_t.find(bn.Data()) == mapFloatFunc_t.end())
1078 return false;
1079 else
1080 return true;
1081 }
1082
1083
1084 template <>
1085 void TTreeX::setBranch<std::map<TTREEXSTRING, std::vector<Int_t>>>(std::map<TTREEXSTRING, std::vector<Int_t>>& objidx) {
1086 for (auto& pair : objidx) {
1087 setBranch<Int_t>("n" + pair.first, pair.second.size());
1088 setBranch<std::vector<Int_t>>(pair.first, pair.second);
1089 }
1090 }
1091 template <>
1092 void TTreeX::createBranch<std::map<TTREEXSTRING, std::vector<Int_t>>>(
1093 std::map<TTREEXSTRING, std::vector<Int_t>>& objidx) {
1094 for (auto& pair : objidx) {
1095 createBranch<Int_t>("n" + pair.first);
1096 createBranch<std::vector<Int_t>>(pair.first);
1097 }
1098 }
1099
1100