File indexing completed on 2024-04-06 12:23:40
0001 #include "PhysicsTools/NanoAOD/plugins/EventStringOutputBranches.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/ParameterSet/interface/Registry.h"
0004
0005 #include <iostream>
0006
0007 void EventStringOutputBranches::updateEventStringNames(TTree &tree, const std::string &evstring) {
0008 bool found = false;
0009 for (auto &existing : m_evStringBranches) {
0010 existing.buffer = false;
0011 if (evstring == existing.name) {
0012 existing.buffer = true;
0013 found = true;
0014 }
0015 }
0016 if (!found && (!evstring.empty())) {
0017 NamedBranchPtr nb(evstring, "EventString bit");
0018 bool backFillValue = false;
0019 nb.branch = tree.Branch(nb.name.c_str(), &backFillValue, (nb.name + "/O").c_str());
0020 nb.branch->SetTitle(nb.title.c_str());
0021 for (size_t i = 0; i < m_fills; i++)
0022 nb.branch->Fill();
0023 nb.buffer = true;
0024 m_evStringBranches.push_back(nb);
0025 for (auto &existing : m_evStringBranches)
0026 existing.branch->SetAddress(&(existing.buffer));
0027 }
0028 }
0029
0030 void EventStringOutputBranches::fill(const edm::EventForOutput &iEvent, TTree &tree) {
0031 if ((!m_update_only_at_new_lumi) || m_lastLumi != iEvent.id().luminosityBlock()) {
0032 edm::Handle<std::string> handle;
0033 iEvent.getByToken(m_token, handle);
0034 const std::string &evstring = *handle;
0035 m_lastLumi = iEvent.id().luminosityBlock();
0036 updateEventStringNames(tree, evstring);
0037 }
0038 m_fills++;
0039 }