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
void newChannel(const uint32_t key, const uint16_t firstItem=0)
DetSetVectorFiller(const size_t registrySize, const size_t dataSize)
sistrip classes
DetSetVectorFiller< SiStripDigi, true > ZSDigiDetSetVectorFiller
std::unique_ptr< edm::DetSetVector< T > > createDetSetVector()
key
prepare the HTCondor submission files and eventually submit them
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
std::vector< ChannelRegistryItem > Registry
DetSetVectorFiller< SiStripRawDigi, false > RawDigiDetSetVectorFiller
bool operator<(const ChannelRegistryItem &other) const
ChannelRegistryItem(const uint32_t theKey, const uint32_t theStartIndex, const uint16_t theLength, const uint16_t theFirstItem)
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
long double T