Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:40

0001 #include "SummaryTableOutputFields.h"
0002 
0003 template <typename T, typename Col>
0004 std::vector<RNTupleFieldPtr<T>> SummaryTableOutputFields::makeFields(const std::vector<Col> &tabcols,
0005                                                                      RNTupleModel &model) {
0006   std::vector<RNTupleFieldPtr<T>> fields;
0007   fields.reserve(tabcols.size());
0008   for (const auto &col : tabcols) {
0009     // TODO field description
0010     fields.emplace_back(RNTupleFieldPtr<T>(col.name, col.doc, model));
0011   }
0012   return fields;
0013 }
0014 
0015 template <typename T, typename Col>
0016 void SummaryTableOutputFields::fillScalarFields(const std::vector<Col> &tabcols,
0017                                                 std::vector<RNTupleFieldPtr<T>> fields) {
0018   if (tabcols.size() != fields.size()) {
0019     throw cms::Exception("LogicError", "Mismatch in table columns");
0020   }
0021   for (std::size_t i = 0; i < tabcols.size(); ++i) {
0022     if (tabcols[i].name != fields[i].getFieldName()) {
0023       throw cms::Exception("LogicError", "Mismatch in table columns");
0024     }
0025     fields[i].fill(tabcols[i].value);
0026   }
0027 }
0028 
0029 template <typename T, typename Col>
0030 void SummaryTableOutputFields::fillVectorFields(const std::vector<Col> &tabcols,
0031                                                 std::vector<RNTupleFieldPtr<T>> fields) {
0032   if (tabcols.size() != fields.size()) {
0033     throw cms::Exception("LogicError", "Mismatch in table columns");
0034   }
0035   for (std::size_t i = 0; i < tabcols.size(); ++i) {
0036     if (tabcols[i].name != fields[i].getFieldName()) {
0037       throw cms::Exception("LogicError", "Mismatch in table columns");
0038     }
0039     auto data = tabcols[i].values;
0040     // TODO remove this awful hack when std::int64_t is supported
0041     // -- turns std::vector<int64_t> into std::vector<uint64_t>
0042     T casted_data(data.begin(), data.end());
0043     fields[i].fill(casted_data);
0044   }
0045 }
0046 
0047 SummaryTableOutputFields::SummaryTableOutputFields(const nanoaod::MergeableCounterTable &tab, RNTupleModel &model) {
0048   // TODO use std::int64_t when supported
0049   m_intFields = makeFields<std::uint64_t>(tab.intCols(), model);
0050   m_floatFields = makeFields<double>(tab.floatCols(), model);
0051   m_floatWithNormFields = makeFields<double>(tab.floatWithNormCols(), model);
0052   m_vintFields = makeFields<std::vector<std::uint64_t>>(tab.vintCols(), model);
0053   m_vfloatFields = makeFields<std::vector<double>>(tab.vfloatCols(), model);
0054   m_vfloatWithNormFields = makeFields<std::vector<double>>(tab.vfloatWithNormCols(), model);
0055 }
0056 
0057 void SummaryTableOutputFields::fill(const nanoaod::MergeableCounterTable &tab) {
0058   fillScalarFields(tab.intCols(), m_intFields);
0059   fillScalarFields(tab.floatCols(), m_floatFields);
0060   fillScalarFields(tab.floatWithNormCols(), m_floatWithNormFields);
0061   fillVectorFields(tab.vintCols(), m_vintFields);
0062   fillVectorFields(tab.vfloatCols(), m_vfloatFields);
0063   fillVectorFields(tab.vfloatWithNormCols(), m_vfloatWithNormFields);
0064 }