Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-04 04:04:15

0001 #include "CondFormats/HGCalObjects/interface/HGCalDenseIndexerBase.h"
0002 #include <iostream>
0003 #include <iterator>
0004 #include <set>
0005 #include <cassert>
0006 
0007 int main() {
0008   //init an indexer for a MH (HD) module
0009   //which has 6 ROCs, each with 2 halfs, each with 37 channels
0010   std::vector<uint32_t> rans{{6, 2, 37}};
0011   HGCalDenseIndexerBase di(rans);
0012 
0013   //a lambda to print arrays
0014   auto parray = [](auto v) { std::copy(std::begin(v), std::end(v), std::ostream_iterator<uint32_t>(std::cout, " ")); };
0015 
0016   //test coding/decoding different values
0017   std::set<uint32_t> allidx;
0018   for (uint32_t i = 0; i < rans[0]; i++) {
0019     for (uint32_t j = 0; j < rans[1]; j++) {
0020       for (uint32_t k = 0; k < rans[2]; k++) {
0021         std::vector<uint32_t> vals{{i, j, k}};
0022         uint32_t rtn = di.denseIndex(vals);
0023         allidx.insert(rtn);
0024         auto decoded_vals = di.unpackDenseIndex(rtn);
0025 
0026         if (vals == decoded_vals)
0027           continue;
0028         std::cout << "Dense indexing failed @ ";
0029         parray(vals);
0030         std::cout << " -> " << rtn << " -> ";
0031         parray(decoded_vals);
0032         std::cout << std::endl;
0033       }
0034     }
0035   }
0036 
0037   //check that all values were unique
0038   assert(allidx.size() == di.getMaxIndex());
0039 
0040   //check that values were sequential (last value==size)
0041   assert((*allidx.end()) == di.getMaxIndex());
0042 
0043   return 0;
0044 }