Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-23 15:57:35

0001 #include "DataFormats/NanoAOD/interface/FlatTable.h"
0002 
0003 int nanoaod::FlatTable::columnIndex(const std::string& name) const {
0004   for (unsigned int i = 0, n = columns_.size(); i < n; ++i) {
0005     if (columns_[i].name == name)
0006       return i;
0007   }
0008   return -1;
0009 }
0010 
0011 void nanoaod::FlatTable::addExtension(const nanoaod::FlatTable& other) {
0012   if (extension() || !other.extension() || name() != other.name() || size() != other.size())
0013     throw cms::Exception("LogicError", "Mismatch in adding extension");
0014   for (unsigned int i = 0, n = other.nColumns(); i < n; ++i) {
0015     switch (other.columnType(i)) {
0016       case ColumnType::UInt8:
0017         addColumn<uint8_t>(other.columnName(i), other.columnData<uint8_t>(i), other.columnDoc(i));
0018         break;
0019       case ColumnType::Int16:
0020         addColumn<int16_t>(other.columnName(i), other.columnData<int16_t>(i), other.columnDoc(i));
0021         break;
0022       case ColumnType::UInt16:
0023         addColumn<uint16_t>(other.columnName(i), other.columnData<uint16_t>(i), other.columnDoc(i));
0024         break;
0025       case ColumnType::Int32:
0026         addColumn<int32_t>(other.columnName(i), other.columnData<int32_t>(i), other.columnDoc(i));
0027         break;
0028       case ColumnType::UInt32:
0029         addColumn<uint32_t>(other.columnName(i), other.columnData<uint32_t>(i), other.columnDoc(i));
0030         break;
0031       case ColumnType::Int64:
0032         addColumn<int64_t>(other.columnName(i), other.columnData<int64_t>(i), other.columnDoc(i));
0033         break;
0034       case ColumnType::UInt64:
0035         addColumn<uint64_t>(other.columnName(i), other.columnData<uint64_t>(i), other.columnDoc(i));
0036         break;
0037       case ColumnType::Bool:
0038         addColumn<bool>(other.columnName(i), other.columnData<bool>(i), other.columnDoc(i));
0039         break;
0040       case ColumnType::Float:
0041         addColumn<float>(other.columnName(i), other.columnData<float>(i), other.columnDoc(i));
0042         break;
0043       case ColumnType::Double:
0044         addColumn<double>(other.columnName(i), other.columnData<double>(i), other.columnDoc(i));
0045         break;
0046       default:
0047         throw cms::Exception("LogicError", "Unsupported type");
0048     }
0049   }
0050 }
0051 
0052 double nanoaod::FlatTable::getAnyValue(unsigned int row, unsigned int column) const {
0053   if (column >= nColumns())
0054     throw cms::Exception("LogicError", "Invalid column");
0055   switch (columnType(column)) {
0056     case ColumnType::UInt8:
0057       return *(beginData<uint8_t>(column) + row);
0058     case ColumnType::Int16:
0059       return *(beginData<int16_t>(column) + row);
0060     case ColumnType::UInt16:
0061       return *(beginData<uint16_t>(column) + row);
0062     case ColumnType::Int32:
0063       return *(beginData<int32_t>(column) + row);
0064     case ColumnType::UInt32:
0065       return *(beginData<uint32_t>(column) + row);
0066     case ColumnType::Int64:
0067       return *(beginData<int64_t>(column) + row);
0068     case ColumnType::UInt64:
0069       return *(beginData<uint64_t>(column) + row);
0070     case ColumnType::Bool:
0071       return *(beginData<bool>(column) + row);
0072     case ColumnType::Float:
0073       return *(beginData<float>(column) + row);
0074     case ColumnType::Double:
0075       return *(beginData<double>(column) + row);
0076   }
0077   throw cms::Exception("LogicError", "Unsupported type");
0078 }
0079 
0080 void nanoaod::FlatTable::RowView::throwUnknownColumn(const std::string& column) {
0081   throw cms::Exception("LogicError") << "Invalid column name '" << column << "'";
0082 }