CMS 3D CMS Logo

NanoAODRNTuples.cc
Go to the documentation of this file.
1 #include "NanoAODRNTuples.h"
2 
5 
6 #include <ROOT/RNTuple.hxx>
7 #include <ROOT/RNTupleModel.hxx>
8 #include <ROOT/RNTupleOptions.hxx>
9 #include <ROOT/RPageStorageFile.hxx>
10 using ROOT::Experimental::RNTupleModel;
11 using ROOT::Experimental::RNTupleWriteOptions;
12 using ROOT::Experimental::RNTupleWriter;
13 using ROOT::Experimental::Detail::RPageSinkFile;
14 
15 #include "RNTupleFieldPtr.h"
17 
19  auto model = RNTupleModel::Create();
20  m_run = RNTupleFieldPtr<UInt_t>("run", "", *model);
21  m_luminosityBlock = RNTupleFieldPtr<UInt_t>("luminosityBlock", "", *model);
22  // TODO use Append when we bump our RNTuple version:
23  // m_ntuple = RNTupleWriter::Append(std::move(model), "LuminosityBlocks", file);
24  RNTupleWriteOptions options;
25  options.SetCompression(file.GetCompressionSettings());
26  m_ntuple = std::make_unique<RNTupleWriter>(std::move(model),
27  std::make_unique<RPageSinkFile>("LuminosityBlocks", file, options));
28 }
29 
30 void LumiNTuple::fill(const edm::LuminosityBlockID& id, TFile& file) {
31  if (!m_ntuple) {
32  createFields(id, file);
33  }
34  m_run.fill(id.run());
36  m_ntuple->Fill();
37 }
38 
40 
42 
43 void RunNTuple::createFields(const edm::RunForOutput& iRun, TFile& file) {
44  auto model = RNTupleModel::Create();
45  m_run = RNTupleFieldPtr<UInt_t>("run", "", *model);
46 
48  for (const auto& token : m_tokens) {
49  iRun.getByToken(token, handle);
51  m_tables.push_back(SummaryTableOutputFields(tab, *model));
52  }
53 
54  // TODO use Append when we bump our RNTuple version
55  RNTupleWriteOptions options;
56  options.SetCompression(file.GetCompressionSettings());
57  m_ntuple = std::make_unique<RNTupleWriter>(std::move(model), std::make_unique<RPageSinkFile>("Runs", file, options));
58 }
59 
60 void RunNTuple::fill(const edm::RunForOutput& iRun, TFile& file) {
61  if (!m_ntuple) {
62  createFields(iRun, file);
63  }
64  m_run.fill(iRun.id().run());
66  for (std::size_t i = 0; i < m_tokens.size(); i++) {
67  iRun.getByToken(m_tokens.at(i), handle);
69  m_tables.at(i).fill(tab);
70  }
71  m_ntuple->Fill();
72 }
73 
75 
77  // use a collection to emulate std::pair
78  auto pairModel = RNTupleModel::Create();
79  m_psetId = RNTupleFieldPtr<std::string>("first", "", *pairModel);
80  m_psetBlob = RNTupleFieldPtr<std::string>("second", "", *pairModel);
81  auto model = RNTupleModel::Create();
83  // TODO use Append when we bump our RNTuple version
84  RNTupleWriteOptions options;
85  options.SetCompression(file.GetCompressionSettings());
86  m_ntuple = std::make_unique<RNTupleWriter>(
87  std::move(model), std::make_unique<RPageSinkFile>(edm::poolNames::parameterSetsTreeName(), file, options));
88 }
89 
91  if (!pset) {
92  throw cms::Exception("LogicError", "null edm::pset::Registry::Instance pointer");
93  }
94  if (!m_ntuple) {
96  }
97  for (const auto& ps : *pset) {
98  std::ostringstream oss;
99  oss << ps.first;
100  m_psetId.fill(oss.str());
101  m_psetBlob.fill(ps.second.toString());
102  m_collection->Fill();
103  m_ntuple->Fill();
104  }
105 }
106 
108 
109 // TODO blocked on RNTuple typedef member field support
111  auto procHistModel = RNTupleModel::Create();
112  // ProcessHistory.transients_.phid_ replacement
113  m_phId = RNTupleFieldPtr<std::string>("transients_phid_", "", *procHistModel);
114  auto model = RNTupleModel::Create();
115  m_procHist = model->MakeCollection(edm::poolNames::processHistoryBranchName(), std::move(procHistModel));
116  RNTupleWriteOptions options;
117  options.SetCompression(file.GetCompressionSettings());
118  m_ntuple = std::make_unique<RNTupleWriter>(
119  std::move(model), std::make_unique<RPageSinkFile>(edm::poolNames::metaDataTreeName(), file, options));
120 }
121 
123  if (!m_ntuple) {
125  }
126  for (const auto& ph : procHist) {
127  std::string phid;
128  ph.second.id().toString(phid);
129  m_phId.fill(phid);
130  m_procHist->Fill();
131  }
132  m_ntuple->Fill();
133 }
134 
RNTupleFieldPtr< std::string > m_psetId
std::unique_ptr< RNTupleWriter > m_ntuple
void finalizeWrite()
std::string const & metaDataTreeName()
Definition: BranchType.cc:159
RNTupleFieldPtr< std::string > m_psetBlob
void fill(const edm::LuminosityBlockID &id, TFile &file)
std::unique_ptr< RNTupleWriter > m_ntuple
RNTupleFieldPtr< UInt_t > m_run
void createFields(TFile &file)
std::string const & processHistoryBranchName()
Definition: BranchType.cc:177
void fill(const T &value)
void registerToken(const edm::EDGetToken &token)
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
std::shared_ptr< RCollectionNTupleWriter > m_collection
RNTupleFieldPtr< UInt_t > m_run
void createFields(const edm::LuminosityBlockID &id, TFile &file)
void finalizeWrite()
void fill(const edm::ProcessHistoryRegistry &procHist, TFile &file)
std::shared_ptr< RCollectionNTupleWriter > m_procHist
std::unique_ptr< RNTupleWriter > m_ntuple
std::string const & parameterSetsTreeName()
Definition: BranchType.cc:216
void createFields(TFile &file)
std::vector< edm::EDGetToken > m_tokens
void createFields(const edm::RunForOutput &iRun, TFile &file)
std::string const & idToParameterSetBlobsBranchName()
Definition: BranchType.cc:218
void fill(edm::pset::Registry *pset, TFile &file)
RNTupleFieldPtr< UInt_t > m_luminosityBlock
std::unique_ptr< RNTupleWriter > m_ntuple
void finalizeWrite()
RunID const & id() const
Definition: RunForOutput.h:55
RNTupleFieldPtr< std::string > m_phId
void fill(const edm::RunForOutput &iRun, TFile &file)
std::vector< SummaryTableOutputFields > m_tables
def move(src, dest)
Definition: eostools.py:511
RunNumber_t run() const
Definition: RunID.h:26