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/RPageStorageFile.hxx>
9 using ROOT::Experimental::RNTupleModel;
10 #if ROOT_VERSION_CODE < ROOT_VERSION(6, 31, 0)
11 using ROOT::Experimental::RNTupleWriter;
12 using ROOT::Experimental::Detail::RPageSinkFile;
13 #define MakeRNTupleWriter std::make_unique<RNTupleWriter>
14 #include <ROOT/RNTupleOptions.hxx>
15 #else
16 using ROOT::Experimental::Internal::RPageSinkFile;
17 #define MakeRNTupleWriter ROOT::Experimental::Internal::CreateRNTupleWriter
18 #include <ROOT/RNTupleWriteOptions.hxx>
19 #endif
20 using ROOT::Experimental::RNTupleWriteOptions;
21 
22 #include "RNTupleFieldPtr.h"
24 
26  auto model = RNTupleModel::Create();
27  m_run = RNTupleFieldPtr<UInt_t>("run", "", *model);
28  m_luminosityBlock = RNTupleFieldPtr<UInt_t>("luminosityBlock", "", *model);
29  // TODO use Append when we bump our RNTuple version:
30  // m_ntuple = RNTupleWriter::Append(std::move(model), "LuminosityBlocks", file);
31  RNTupleWriteOptions options;
32  options.SetCompression(file.GetCompressionSettings());
33  m_ntuple = MakeRNTupleWriter(std::move(model), std::make_unique<RPageSinkFile>("LuminosityBlocks", file, options));
34 }
35 
36 void LumiNTuple::fill(const edm::LuminosityBlockID& id, TFile& file) {
37  if (!m_ntuple) {
38  createFields(id, file);
39  }
40  m_run.fill(id.run());
42  m_ntuple->Fill();
43 }
44 
46 
48 
49 void RunNTuple::createFields(const edm::RunForOutput& iRun, TFile& file) {
50  auto model = RNTupleModel::Create();
51  m_run = RNTupleFieldPtr<UInt_t>("run", "", *model);
52 
54  for (const auto& token : m_tokens) {
55  iRun.getByToken(token, handle);
57  m_tables.push_back(SummaryTableOutputFields(tab, *model));
58  }
59 
60  // TODO use Append when we bump our RNTuple version
61  RNTupleWriteOptions options;
62  options.SetCompression(file.GetCompressionSettings());
63  m_ntuple = MakeRNTupleWriter(std::move(model), std::make_unique<RPageSinkFile>("Runs", file, options));
64 }
65 
66 void RunNTuple::fill(const edm::RunForOutput& iRun, TFile& file) {
67  if (!m_ntuple) {
68  createFields(iRun, file);
69  }
70  m_run.fill(iRun.id().run());
72  for (std::size_t i = 0; i < m_tokens.size(); i++) {
73  iRun.getByToken(m_tokens.at(i), handle);
75  m_tables.at(i).fill(tab);
76  }
77  m_ntuple->Fill();
78 }
79 
81 
83  // use a collection to emulate std::pair
84  auto pairModel = RNTupleModel::Create();
85  m_psetId = RNTupleFieldPtr<std::string>("first", "", *pairModel);
86  m_psetBlob = RNTupleFieldPtr<std::string>("second", "", *pairModel);
87  auto model = RNTupleModel::Create();
89  // TODO use Append when we bump our RNTuple version
90  RNTupleWriteOptions options;
91  options.SetCompression(file.GetCompressionSettings());
93  std::make_unique<RPageSinkFile>(edm::poolNames::parameterSetsTreeName(), file, options));
94 }
95 
97  if (!pset) {
98  throw cms::Exception("LogicError", "null edm::pset::Registry::Instance pointer");
99  }
100  if (!m_ntuple) {
102  }
103  for (const auto& ps : *pset) {
104  std::ostringstream oss;
105  oss << ps.first;
106  m_psetId.fill(oss.str());
107  m_psetBlob.fill(ps.second.toString());
108  m_collection->Fill();
109  m_ntuple->Fill();
110  }
111 }
112 
114 
115 // TODO blocked on RNTuple typedef member field support
117  auto procHistModel = RNTupleModel::Create();
118  // ProcessHistory.transients_.phid_ replacement
119  m_phId = RNTupleFieldPtr<std::string>("transients_phid_", "", *procHistModel);
120  auto model = RNTupleModel::Create();
121  m_procHist = model->MakeCollection(edm::poolNames::processHistoryBranchName(), std::move(procHistModel));
122  RNTupleWriteOptions options;
123  options.SetCompression(file.GetCompressionSettings());
125  std::make_unique<RPageSinkFile>(edm::poolNames::metaDataTreeName(), file, options));
126 }
127 
129  if (!m_ntuple) {
131  }
132  for (const auto& ph : procHist) {
133  std::string phid;
134  ph.second.id().toString(phid);
135  m_phId.fill(phid);
136  m_procHist->Fill();
137  }
138  m_ntuple->Fill();
139 }
140 
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
#define MakeRNTupleWriter
RNTupleFieldPtr< UInt_t > m_run
std::shared_ptr< RNTupleCollectionWriter > m_procHist
void createFields(const edm::LuminosityBlockID &id, TFile &file)
void finalizeWrite()
void fill(const edm::ProcessHistoryRegistry &procHist, TFile &file)
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::shared_ptr< RNTupleCollectionWriter > m_collection
std::vector< SummaryTableOutputFields > m_tables
def move(src, dest)
Definition: eostools.py:511
RunNumber_t run() const
Definition: RunID.h:26