CMS 3D CMS Logo

SiStripDetSetVectorFiller.h
Go to the documentation of this file.
1 #ifndef EventFilter_SiStripRawToDigi_SiStripDetSetVectorFiller_H
2 #define EventFilter_SiStripRawToDigi_SiStripDetSetVectorFiller_H
3 
5 #include <vector>
6 #include <algorithm>
7 #include <memory>
8 #include <cstdint>
9 class SiStripRawDigi;
10 class SiStripDigi;
11 
12 namespace sistrip {
13 
14  //A class to fill a DetSetVector from data from different channels only sorting once
15 
16  //T is type of object in DetSetVector (SiStripRawDigi, SiStripDigi), dsvIsSparse should be false for raw digis so null digis are inserted
17  template <typename T, bool dsvIsSparse>
19  public:
20  DetSetVectorFiller(const size_t registrySize, const size_t dataSize);
22 
23  void newChannel(const uint32_t key, const uint16_t firstItem = 0);
24  void addItem(const T& item);
25  std::unique_ptr<edm::DetSetVector<T> > createDetSetVector();
26 
27  private:
29  ChannelRegistryItem(const uint32_t theKey,
30  const uint32_t theStartIndex,
31  const uint16_t theLength,
32  const uint16_t theFirstItem)
33  : key(theKey), startIndex(theStartIndex), length(theLength), firstItem(theFirstItem) {}
34  bool operator<(const ChannelRegistryItem& other) const {
35  return ((this->key != other.key) ? (this->key < other.key) : (this->firstItem < other.firstItem));
36  }
37  uint32_t key; //ID of DetSet in DetSetVector
38  uint32_t startIndex; //index of first item in data container
39  uint16_t length; //number of items
40  uint16_t firstItem; //index of first item in final DetSet
41  };
42  typedef std::vector<ChannelRegistryItem> Registry;
43  typedef std::vector<T> Data;
44 
47  };
48 
49  template <typename T, bool dsvIsSparse>
50  inline DetSetVectorFiller<T, dsvIsSparse>::DetSetVectorFiller(const size_t registrySize, const size_t dataSize) {
51  registry_.reserve(registrySize);
52  data_.reserve(dataSize);
53  }
54 
55  template <typename T, bool dsvIsSparse>
57 
58  template <typename T, bool dsvIsSparse>
59  inline void DetSetVectorFiller<T, dsvIsSparse>::newChannel(const uint32_t key, const uint16_t firstItem) {
60  registry_.push_back(ChannelRegistryItem(key, data_.size(), 0, firstItem));
61  }
62 
63  template <typename T, bool dsvIsSparse>
65  data_.push_back(item);
66  registry_.back().length++;
67  }
68 
69  template <typename T, bool dsvIsSparse>
70  std::unique_ptr<edm::DetSetVector<T> > DetSetVectorFiller<T, dsvIsSparse>::createDetSetVector() {
71  std::sort(registry_.begin(), registry_.end());
72  std::vector<edm::DetSet<T> > sorted_and_merged;
73  sorted_and_merged.reserve(registry_.size());
74  typename Registry::const_iterator iReg = registry_.begin();
75  const typename Registry::const_iterator endReg = registry_.end();
76  while (iReg != endReg) {
77  sorted_and_merged.push_back(edm::DetSet<T>(iReg->key));
78  std::vector<T>& detSetData = sorted_and_merged.back().data;
79  typename Registry::const_iterator jReg;
80  if (dsvIsSparse) {
81  uint16_t length = 0;
82  for (jReg = iReg; (jReg != endReg) && (jReg->key == iReg->key); ++jReg)
83  length += jReg->length;
84  detSetData.reserve(length);
85  for (jReg = iReg; (jReg != endReg) && (jReg->key == iReg->key); ++jReg) {
86  detSetData.insert(
87  detSetData.end(), data_.begin() + jReg->startIndex, data_.begin() + jReg->startIndex + jReg->length);
88  }
89  } else {
90  uint16_t detLength = 0;
91  uint16_t firstItemOfLastChannel = 0;
92  for (jReg = iReg; (jReg != endReg) && (jReg->key == iReg->key); ++jReg) {
93  if (!detLength)
94  detLength = jReg->length;
95  else if (detLength != jReg->length)
96  throw cms::Exception("DetSetVectorFiller")
97  << "Cannot fill non-sparse DetSet if channels are not unformly sized.";
98  firstItemOfLastChannel = jReg->firstItem;
99  }
100  detSetData.resize(firstItemOfLastChannel + detLength);
101  for (jReg = iReg; (jReg != endReg) && (jReg->key == iReg->key); ++jReg) {
102  std::copy(data_.begin() + jReg->startIndex,
103  data_.begin() + jReg->startIndex + jReg->length,
104  detSetData.begin() + jReg->firstItem);
105  }
106  }
107  iReg = jReg;
108  }
109  return typename std::unique_ptr<edm::DetSetVector<T> >(new edm::DetSetVector<T>(sorted_and_merged, true));
110  }
111 
114 } // namespace sistrip
115 
116 #endif // EventFilter_SiStripRawToDigi_SiStripDetSetVectorFiller_H
edm::DetSetVector
Definition: DetSetVector.h:61
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
sistrip::DetSetVectorFiller::registry_
Registry registry_
Definition: SiStripDetSetVectorFiller.h:45
edm::DetSet
Definition: DetSet.h:23
sistrip::DetSetVectorFiller::data_
Data data_
Definition: SiStripDetSetVectorFiller.h:46
sistrip::DetSetVectorFiller::ChannelRegistryItem::startIndex
uint32_t startIndex
Definition: SiStripDetSetVectorFiller.h:38
sistrip::DetSetVectorFiller::newChannel
void newChannel(const uint32_t key, const uint16_t firstItem=0)
Definition: SiStripDetSetVectorFiller.h:59
sistrip::DetSetVectorFiller::DetSetVectorFiller
DetSetVectorFiller(const size_t registrySize, const size_t dataSize)
Definition: SiStripDetSetVectorFiller.h:50
sistrip::ZSDigiDetSetVectorFiller
DetSetVectorFiller< SiStripDigi, true > ZSDigiDetSetVectorFiller
Definition: SiStripDetSetVectorFiller.h:113
SiStripRawDigi
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
Definition: SiStripRawDigi.h:15
sistrip::DetSetVectorFiller::ChannelRegistryItem::length
uint16_t length
Definition: SiStripDetSetVectorFiller.h:39
sistrip::DetSetVectorFiller::Data
std::vector< T > Data
Definition: SiStripDetSetVectorFiller.h:43
trackingPlots.other
other
Definition: trackingPlots.py:1464
sistrip::RawDigiDetSetVectorFiller
DetSetVectorFiller< SiStripRawDigi, false > RawDigiDetSetVectorFiller
Definition: SiStripDetSetVectorFiller.h:112
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
sistrip::DetSetVectorFiller::Registry
std::vector< ChannelRegistryItem > Registry
Definition: SiStripDetSetVectorFiller.h:42
sistrip::DetSetVectorFiller::createDetSetVector
std::unique_ptr< edm::DetSetVector< T > > createDetSetVector()
Definition: SiStripDetSetVectorFiller.h:70
sistrip::DetSetVectorFiller::ChannelRegistryItem::operator<
bool operator<(const ChannelRegistryItem &other) const
Definition: SiStripDetSetVectorFiller.h:34
sistrip::DetSetVectorFiller::addItem
void addItem(const T &item)
Definition: SiStripDetSetVectorFiller.h:64
sistrip::DetSetVectorFiller::~DetSetVectorFiller
~DetSetVectorFiller()
Definition: SiStripDetSetVectorFiller.h:56
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
DetSetVector.h
sistrip::DetSetVectorFiller::ChannelRegistryItem::ChannelRegistryItem
ChannelRegistryItem(const uint32_t theKey, const uint32_t theStartIndex, const uint16_t theLength, const uint16_t theFirstItem)
Definition: SiStripDetSetVectorFiller.h:29
T
long double T
Definition: Basic3DVectorLD.h:48
sistrip::DetSetVectorFiller
Definition: SiStripDetSetVectorFiller.h:18
Exception
Definition: hltDiff.cc:245
SiStripDigi
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
sistrip
sistrip classes
Definition: EnsembleCalibrationLA.cc:10
sistrip::DetSetVectorFiller::ChannelRegistryItem::key
uint32_t key
Definition: SiStripDetSetVectorFiller.h:37
crabWrapper.key
key
Definition: crabWrapper.py:19
sistrip::DetSetVectorFiller::ChannelRegistryItem::firstItem
uint16_t firstItem
Definition: SiStripDetSetVectorFiller.h:40
sistrip::DetSetVectorFiller::ChannelRegistryItem
Definition: SiStripDetSetVectorFiller.h:28