CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
TableCollection Class Reference

#include <TableOutputFields.h>

Public Member Functions

void add (const edm::EDGetToken &table_token, const nanoaod::FlatTable &table)
 
void createFields (const edm::EventForOutput &event, RNTupleModel &eventModel)
 
void fill (const edm::EventForOutput &event)
 
const std::string & getCollectionName () const
 
bool hasMainTable ()
 
void print () const
 
 TableCollection ()=default
 

Private Attributes

std::shared_ptr< RNTupleCollectionWriter > m_collection
 
std::string m_collectionName
 
std::vector< TableOutputFieldsm_extensions
 
TableOutputFields m_main
 

Detailed Description

Definition at line 100 of file TableOutputFields.h.

Constructor & Destructor Documentation

◆ TableCollection()

TableCollection::TableCollection ( )
default

Member Function Documentation

◆ add()

void TableCollection::add ( const edm::EDGetToken table_token,
const nanoaod::FlatTable table 
)

Definition at line 136 of file TableOutputFields.cc.

References Exception, hasMainTable(), m_collectionName, m_extensions, m_main, and TableParser::table.

Referenced by counter.Counter::register().

136  {
137  if (m_collectionName.empty()) {
138  m_collectionName = table.name();
139  }
140  if (table.extension()) {
141  m_extensions.emplace_back(TableOutputFields(table_token));
142  return;
143  }
144  if (hasMainTable()) {
145  throw cms::Exception("LogicError", "Trying to save multiple main tables for " + m_collectionName + "\n");
146  }
147  m_main = TableOutputFields(table_token);
148 }
TableOutputFields m_main
std::string m_collectionName
std::vector< TableOutputFields > m_extensions

◆ createFields()

void TableCollection::createFields ( const edm::EventForOutput event,
RNTupleModel &  eventModel 
)

Definition at line 150 of file TableOutputFields.cc.

References TableOutputFields::createFields(), runGCPTkAlMap::extension, TableOutputFields::getToken(), patZpeak::handle, m_collection, m_collectionName, m_extensions, m_main, eostools::move(), and TableParser::table.

150  {
151  auto collectionModel = RNTupleModel::Create();
152  m_main.createFields(event, *collectionModel);
153  for (auto& extension : m_extensions) {
154  extension.createFields(event, *collectionModel);
155  }
157  event.getByToken(m_main.getToken(), handle);
158  const nanoaod::FlatTable& table = *handle;
159  collectionModel->SetDescription(table.doc());
160  m_collection = eventModel.MakeCollection(m_collectionName, std::move(collectionModel));
161 }
TableOutputFields m_main
const edm::EDGetToken & getToken() const
std::string m_collectionName
std::shared_ptr< RNTupleCollectionWriter > m_collection
std::vector< TableOutputFields > m_extensions
void createFields(const edm::EventForOutput &event, RNTupleModel &model)
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1

◆ fill()

void TableCollection::fill ( const edm::EventForOutput event)

Definition at line 163 of file TableOutputFields.cc.

References Exception, TableOutputFields::fillEntry(), TableOutputFields::getToken(), patZpeak::handle, mps_fire::i, m_collection, m_collectionName, m_extensions, and m_main.

163  {
165  event.getByToken(m_main.getToken(), handle);
166  const auto& main_table = *handle;
167  auto table_size = main_table.size();
168  for (std::size_t i = 0; i < table_size; i++) {
169  m_main.fillEntry(main_table, i);
170  for (auto& ext : m_extensions) {
172  event.getByToken(ext.getToken(), handle);
173  const auto& ext_table = *handle;
174  if (ext_table.size() != table_size) {
175  throw cms::Exception("LogicError",
176  "Mismatch in number of entries between extension and main table for " + m_collectionName);
177  }
178  ext.fillEntry(ext_table, i);
179  }
180  m_collection->Fill();
181  }
182 }
void fillEntry(const nanoaod::FlatTable &table, std::size_t i)
TableOutputFields m_main
const edm::EDGetToken & getToken() const
std::string m_collectionName
std::shared_ptr< RNTupleCollectionWriter > m_collection
std::vector< TableOutputFields > m_extensions
Definition: memstream.h:15

◆ getCollectionName()

const std::string & TableCollection::getCollectionName ( ) const

Definition at line 195 of file TableOutputFields.cc.

References m_collectionName.

195 { return m_collectionName; }
std::string m_collectionName

◆ hasMainTable()

bool TableCollection::hasMainTable ( )

Definition at line 193 of file TableOutputFields.cc.

References TableOutputFields::getToken(), edm::EDGetToken::isUninitialized(), and m_main.

Referenced by add().

193 { return !m_main.getToken().isUninitialized(); }
TableOutputFields m_main
const edm::EDGetToken & getToken() const
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:55

◆ print()

void TableCollection::print ( void  ) const

Definition at line 184 of file TableOutputFields.cc.

References gather_cfg::cout, m_collectionName, m_extensions, m_main, and TableOutputFields::print().

184  {
185  std::cout << "Collection: " << m_collectionName << " {\n";
186  m_main.print();
187  for (const auto& ext : m_extensions) {
188  ext.print();
189  }
190  std::cout << "}\n";
191 }
TableOutputFields m_main
std::string m_collectionName
std::vector< TableOutputFields > m_extensions
Definition: memstream.h:15

Member Data Documentation

◆ m_collection

std::shared_ptr<RNTupleCollectionWriter> TableCollection::m_collection
private

Definition at line 121 of file TableOutputFields.h.

Referenced by createFields(), and fill().

◆ m_collectionName

std::string TableCollection::m_collectionName
private

Definition at line 117 of file TableOutputFields.h.

Referenced by add(), createFields(), fill(), getCollectionName(), and print().

◆ m_extensions

std::vector<TableOutputFields> TableCollection::m_extensions
private

Definition at line 124 of file TableOutputFields.h.

Referenced by add(), createFields(), fill(), and print().

◆ m_main

TableOutputFields TableCollection::m_main
private

Definition at line 123 of file TableOutputFields.h.

Referenced by add(), createFields(), fill(), hasMainTable(), and print().