Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#include "DataFormats/SiPixelDigi/interface/PixelDigiCollection.h"
#include <iostream>
#include <algorithm>

void PixelDigiCollection::put(Range input, unsigned int detID) {
  // put in Digis of detID

  // store size of vector before put
  IndexRange inputRange;

  // put in PixelDigis from input
  bool first = true;

  // fill input in temporary vector for sorting
  std::vector<PixelDigi> temporary;
  PixelDigiCollection::ContainerIterator sort_begin = input.first;
  PixelDigiCollection::ContainerIterator sort_end = input.second;
  for (; sort_begin != sort_end; ++sort_begin) {
    temporary.push_back(*sort_begin);
  }
  std::sort(temporary.begin(), temporary.end());

  // iterators over input
  PixelDigiCollection::ContainerIterator begin = temporary.begin();
  PixelDigiCollection::ContainerIterator end = temporary.end();
  for (; begin != end; ++begin) {
    container_.push_back(*begin);
    if (first) {
      inputRange.first = container_.size() - 1;
      first = false;
    }
  }
  inputRange.second = container_.size() - 1;

  // fill map
  map_[detID] = inputRange;
}

const PixelDigiCollection::Range PixelDigiCollection::get(unsigned int detID) const {
  // get Digis of detID

  auto found = map_.find(detID);
  PixelDigiCollection::IndexRange returnIndexRange{};
  if (found != map_.end()) {
    returnIndexRange = found->second;
  }

  PixelDigiCollection::Range returnRange;
  returnRange.first = container_.begin() + returnIndexRange.first;
  returnRange.second = container_.begin() + returnIndexRange.second + 1;

  return returnRange;
}

const std::vector<unsigned int> PixelDigiCollection::detIDs() const {
  // returns vector of detIDs in map

  PixelDigiCollection::RegistryIterator begin = map_.begin();
  PixelDigiCollection::RegistryIterator end = map_.end();

  std::vector<unsigned int> output;

  for (; begin != end; ++begin) {
    output.push_back(begin->first);
  }

  return output;
}