Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-12 09:07:27

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::Float:
0017         addColumn<float>(other.columnName(i), other.columnData<float>(i), other.columnDoc(i));
0018         break;
0019       case ColumnType::Int:
0020         addColumn<int>(other.columnName(i), other.columnData<int>(i), other.columnDoc(i));
0021         break;
0022       case ColumnType::Int8:
0023         addColumn<int8_t>(other.columnName(i), other.columnData<int>(i), other.columnDoc(i));
0024         break;
0025       case ColumnType::Bool:
0026         addColumn<bool>(other.columnName(i), other.columnData<bool>(i), other.columnDoc(i));
0027         break;
0028       case ColumnType::UInt8:
0029         addColumn<uint8_t>(other.columnName(i), other.columnData<uint8_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::Double:
0035         addColumn<double>(other.columnName(i), other.columnData<double>(i), other.columnDoc(i));
0036         break;
0037       default:
0038         throw cms::Exception("LogicError", "Unsupported type");
0039     }
0040   }
0041 }
0042 
0043 double nanoaod::FlatTable::getAnyValue(unsigned int row, unsigned int column) const {
0044   if (column >= nColumns())
0045     throw cms::Exception("LogicError", "Invalid column");
0046   switch (columnType(column)) {
0047     case ColumnType::Float:
0048       return *(beginData<float>(column) + row);
0049     case ColumnType::Int:
0050       return *(beginData<int>(column) + row);
0051     case ColumnType::Int8:
0052       return *(beginData<int8_t>(column) + row);
0053     case ColumnType::Bool:
0054       return *(beginData<bool>(column) + row);
0055     case ColumnType::UInt8:
0056       return *(beginData<uint8_t>(column) + row);
0057     case ColumnType::UInt32:
0058       return *(beginData<uint32_t>(column) + row);
0059     case ColumnType::Double:
0060       return *(beginData<double>(column) + row);
0061   }
0062   throw cms::Exception("LogicError", "Unsupported type");
0063 }