File indexing completed on 2023-03-17 10:50:46
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::Int8:
0017 addColumn<int8_t>(other.columnName(i), other.columnData<int8_t>(i), other.columnDoc(i));
0018 break;
0019 case ColumnType::UInt8:
0020 addColumn<uint8_t>(other.columnName(i), other.columnData<uint8_t>(i), other.columnDoc(i));
0021 break;
0022 case ColumnType::Int16:
0023 addColumn<int16_t>(other.columnName(i), other.columnData<int16_t>(i), other.columnDoc(i));
0024 break;
0025 case ColumnType::UInt16:
0026 addColumn<uint16_t>(other.columnName(i), other.columnData<uint16_t>(i), other.columnDoc(i));
0027 break;
0028 case ColumnType::Int32:
0029 addColumn<int32_t>(other.columnName(i), other.columnData<int32_t>(i), other.columnDoc(i));
0030 break;
0031 case ColumnType::UInt32:
0032 addColumn<uint32_t>(other.columnName(i), other.columnData<uint32_t>(i), other.columnDoc(i));
0033 break;
0034 case ColumnType::Bool:
0035 addColumn<bool>(other.columnName(i), other.columnData<bool>(i), other.columnDoc(i));
0036 break;
0037 case ColumnType::Float:
0038 addColumn<float>(other.columnName(i), other.columnData<float>(i), other.columnDoc(i));
0039 break;
0040 case ColumnType::Double:
0041 addColumn<double>(other.columnName(i), other.columnData<double>(i), other.columnDoc(i));
0042 break;
0043 default:
0044 throw cms::Exception("LogicError", "Unsupported type");
0045 }
0046 }
0047 }
0048
0049 double nanoaod::FlatTable::getAnyValue(unsigned int row, unsigned int column) const {
0050 if (column >= nColumns())
0051 throw cms::Exception("LogicError", "Invalid column");
0052 switch (columnType(column)) {
0053 case ColumnType::Int8:
0054 return *(beginData<int8_t>(column) + row);
0055 case ColumnType::UInt8:
0056 return *(beginData<uint8_t>(column) + row);
0057 case ColumnType::Int16:
0058 return *(beginData<int16_t>(column) + row);
0059 case ColumnType::UInt16:
0060 return *(beginData<uint16_t>(column) + row);
0061 case ColumnType::Int32:
0062 return *(beginData<int32_t>(column) + row);
0063 case ColumnType::UInt32:
0064 return *(beginData<uint32_t>(column) + row);
0065 case ColumnType::Bool:
0066 return *(beginData<bool>(column) + row);
0067 case ColumnType::Float:
0068 return *(beginData<float>(column) + row);
0069 case ColumnType::Double:
0070 return *(beginData<double>(column) + row);
0071 }
0072 throw cms::Exception("LogicError", "Unsupported type");
0073 }