File indexing completed on 2021-02-14 23:31:14
0001 #ifndef CROSSING_FRAME_H
0002 #define CROSSING_FRAME_H
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0017 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0018 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
0019 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
0020 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0021
0022 #include "DataFormats/Provenance/interface/EventID.h"
0023 #include "DataFormats/Common/interface/Wrapper.h"
0024 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
0025
0026 template <class T>
0027 class PCrossingFrame;
0028
0029 #include <vector>
0030 #include <string>
0031 #include <iostream>
0032 #include <utility>
0033 #include <algorithm>
0034 #include <memory>
0035
0036 template <class T>
0037 class CrossingFrame {
0038 public:
0039
0040
0041 CrossingFrame() : firstCrossing_(0), lastCrossing_(0), bunchSpace_(75), subdet_(""), maxNbSources_(0) {}
0042 CrossingFrame(int minb, int maxb, int bunchsp, std::string subdet, unsigned int maxNbSources);
0043
0044 ~CrossingFrame() { ; }
0045
0046 void swap(CrossingFrame& other);
0047
0048 CrossingFrame& operator=(CrossingFrame const& rhs);
0049
0050
0051 void addSignals(const std::vector<T>* vec, edm::EventID id);
0052
0053 void addSignals(const T* vec, edm::EventID id);
0054
0055
0056 void addPileups(std::vector<T> const& vec);
0057
0058 void addPileups(T const& product);
0059
0060 void setTof();
0061
0062
0063
0064
0065
0066 void setPileupPtr(std::shared_ptr<edm::Wrapper<std::vector<T> > const> shPtr) { shPtrPileups_.push_back(shPtr); }
0067 void setPileupPtr(std::shared_ptr<edm::Wrapper<T> const> shPtr) { shPtrPileups2_.push_back(shPtr); }
0068
0069 void setPileupPtr(std::shared_ptr<edm::Wrapper<PCrossingFrame<T> > const> shPtr);
0070
0071 void print(int level = 0) const;
0072
0073 void setBcrOffset() { pileupOffsetsBcr_.push_back(pileups_.size()); }
0074
0075 void setSourceOffset(const unsigned int s) { pileupOffsetsSource_[s].push_back(pileups_.size()); }
0076
0077
0078 edm::EventID getEventID() const { return id_; }
0079 std::pair<int, int> getBunchRange() const { return std::pair<int, int>(firstCrossing_, lastCrossing_); }
0080 int getBunchSpace() const { return bunchSpace_; }
0081 unsigned int getMaxNbSources() const { return maxNbSources_; }
0082 std::string getSubDet() const { return subdet_; }
0083 unsigned int getPileupFileNr() const { return pileupFileNr_; }
0084 edm::EventID getIdFirstPileup() const { return idFirstPileup_; }
0085 const std::vector<unsigned int>& getPileupOffsetsBcr() const { return pileupOffsetsBcr_; }
0086 const std::vector<std::vector<unsigned int> >& getPileupOffsetsSource() const {
0087 return pileupOffsetsSource_;
0088 }
0089 const std::vector<const T*>& getPileups() const { return pileups_; }
0090 const std::vector<const T*>& getSignal() const { return signals_; }
0091
0092 void getSignal(typename std::vector<const T*>::const_iterator& first,
0093 typename std::vector<const T*>::const_iterator& last) const {
0094 first = signals_.begin();
0095 last = signals_.end();
0096 }
0097 void getPileups(typename std::vector<const T*>::const_iterator& first,
0098 typename std::vector<const T*>::const_iterator& last) const;
0099 unsigned int getNrSignals() const { return signals_.size(); }
0100 unsigned int getNrPileups() const { return pileups_.size(); }
0101 unsigned int getNrPileups(int bcr) const {
0102 return bcr == lastCrossing_ ? pileups_.size() - pileupOffsetsBcr_[lastCrossing_ - firstCrossing_]
0103 : pileupOffsetsBcr_[bcr - firstCrossing_ + 1] - pileupOffsetsBcr_[bcr - firstCrossing_];
0104 }
0105
0106
0107 int getBunchCrossing(unsigned int ip) const;
0108
0109 int getSourceType(unsigned int ip) const;
0110
0111
0112
0113 const T& getObject(unsigned int ip) const {
0114
0115 if (ip > getNrSignals() + getNrPileups())
0116 throw cms::Exception("BadIndex") << "CrossingFrame::getObject called with an invalid index- index was " << ip
0117 << "!";
0118 if (ip < getNrSignals()) {
0119 return *(signals_[ip]);
0120 } else {
0121 return *(pileups_[ip - getNrSignals()]);
0122 }
0123 }
0124
0125
0126 void setEventID(edm::EventID evId) { id_ = evId; }
0127 void setPileups(const std::vector<const T*>& p) { pileups_ = p; }
0128 void setBunchSpace(int bSpace) { bunchSpace_ = bSpace; }
0129 void setMaxNbSources(unsigned int mNbS) { maxNbSources_ = mNbS; }
0130 void setSubDet(std::string det) { subdet_ = det; }
0131 void setPileupFileNr(unsigned int pFileNr) { pileupFileNr_ = pFileNr; }
0132 void setIdFirstPileup(edm::EventID idFP) { idFirstPileup_ = idFP; }
0133 void setPileupOffsetsBcr(const std::vector<unsigned int>& pOffsetsBcr) { pileupOffsetsBcr_ = pOffsetsBcr; }
0134 void setPileupOffsetsSource(const std::vector<std::vector<unsigned int> >& pOffsetsS) {
0135 pileupOffsetsSource_ = pOffsetsS;
0136 }
0137 void setBunchRange(std::pair<int, int> bunchRange) {
0138 firstCrossing_ = bunchRange.first;
0139 lastCrossing_ = bunchRange.second;
0140 }
0141
0142 private:
0143
0144
0145 int firstCrossing_;
0146 int lastCrossing_;
0147 int bunchSpace_;
0148 std::string subdet_;
0149 edm::EventID id_;
0150
0151
0152 edm::EventID idFirstPileup_;
0153 unsigned int pileupFileNr_;
0154
0155 unsigned int maxNbSources_;
0156
0157
0158 std::vector<const T*> signals_;
0159
0160
0161 std::vector<const T*> pileups_;
0162 std::vector<std::shared_ptr<edm::Wrapper<std::vector<T> > const> > shPtrPileups_;
0163 std::vector<std::shared_ptr<edm::Wrapper<T> const> > shPtrPileups2_;
0164
0165
0166 std::shared_ptr<edm::Wrapper<PCrossingFrame<T> > const> shPtrPileupsPCF_;
0167
0168
0169
0170
0171 std::vector<unsigned int> pileupOffsetsBcr_;
0172 std::vector<std::vector<unsigned int> > pileupOffsetsSource_;
0173 };
0174
0175
0176
0177
0178
0179 template <class T>
0180 CrossingFrame<T>::CrossingFrame(int minb, int maxb, int bunchsp, std::string subdet, unsigned int maxNbSources)
0181 : firstCrossing_(minb), lastCrossing_(maxb), bunchSpace_(bunchsp), subdet_(subdet), maxNbSources_(maxNbSources) {
0182 pileupOffsetsSource_.resize(maxNbSources_);
0183 for (unsigned int i = 0; i < maxNbSources_; ++i)
0184 pileupOffsetsSource_[i].reserve(-firstCrossing_ + lastCrossing_ + 1);
0185
0186
0187 pileupOffsetsBcr_.reserve(-firstCrossing_ + lastCrossing_ + 1);
0188 }
0189
0190 template <typename T>
0191 inline void CrossingFrame<T>::swap(CrossingFrame<T>& other) {
0192 std::swap(firstCrossing_, other.firstCrossing_);
0193 std::swap(lastCrossing_, other.lastCrossing_);
0194 std::swap(bunchSpace_, other.bunchSpace_);
0195 subdet_.swap(other.subdet_);
0196 std::swap(id_, other.id_);
0197 std::swap(idFirstPileup_, other.idFirstPileup_);
0198 std::swap(pileupFileNr_, other.pileupFileNr_);
0199 std::swap(maxNbSources_, other.maxNbSources_);
0200 signals_.swap(other.signals_);
0201 pileups_.swap(other.pileups_);
0202 shPtrPileups_.swap(other.shPtrPileups_);
0203 shPtrPileups2_.swap(other.shPtrPileups2_);
0204 shPtrPileupsPCF_.swap(other.shPtrPileupsPCF_);
0205 pileupOffsetsBcr_.swap(other.pileupOffsetsBcr_);
0206 pileupOffsetsSource_.resize(maxNbSources_);
0207 for (unsigned int i = 0; i < pileupOffsetsSource_.size(); ++i) {
0208 pileupOffsetsSource_[i].swap(other.pileupOffsetsSource_[i]);
0209 }
0210 }
0211
0212 template <typename T>
0213 inline CrossingFrame<T>& CrossingFrame<T>::operator=(CrossingFrame<T> const& rhs) {
0214 CrossingFrame<T> temp(rhs);
0215 this->swap(temp);
0216 return *this;
0217 }
0218
0219 template <class T>
0220 void CrossingFrame<T>::getPileups(typename std::vector<const T*>::const_iterator& first,
0221 typename std::vector<const T*>::const_iterator& last) const {
0222 first = pileups_.begin();
0223 last = pileups_.end();
0224 }
0225
0226 template <class T>
0227 void CrossingFrame<T>::print(int level) const {}
0228
0229 template <class T>
0230 int CrossingFrame<T>::getSourceType(unsigned int ip) const {
0231
0232
0233
0234 unsigned int bcr = getBunchCrossing(ip) - firstCrossing_;
0235 for (unsigned int i = 0; i < pileupOffsetsSource_.size() - 1; ++i) {
0236 if (ip >= (pileupOffsetsSource_[i])[bcr] && ip < (pileupOffsetsSource_[i + 1])[bcr])
0237 return i;
0238 }
0239 return pileupOffsetsSource_.size() - 1;
0240 }
0241
0242 template <class T>
0243 int CrossingFrame<T>::getBunchCrossing(unsigned int ip) const {
0244
0245 for (unsigned int ii = 1; ii < pileupOffsetsBcr_.size(); ii++) {
0246 if (ip >= pileupOffsetsBcr_[ii - 1] && ip < pileupOffsetsBcr_[ii])
0247 return ii + firstCrossing_ - 1;
0248 }
0249 if (ip < pileups_.size())
0250 return lastCrossing_;
0251 else
0252 return 999;
0253 }
0254
0255
0256 template <typename T>
0257 inline void swap(CrossingFrame<T>& lhs, CrossingFrame<T>& rhs) {
0258 lhs.swap(rhs);
0259 }
0260
0261 #include <iosfwd>
0262 #include <iostream>
0263
0264 template <class T>
0265 std::ostream& operator<<(std::ostream& o, const CrossingFrame<T>& cf) {
0266 std::pair<int, int> range = cf.getBunchRange();
0267 o << "\nCrossingFrame for subdet " << cf.getEventID() << ", bunchrange = " << range.first << "," << range.second
0268 << ", bunchSpace " << cf.getBunchSpace();
0269
0270 return o;
0271 }
0272
0273 #include "SimDataFormats/CrossingFrame/interface/PCrossingFrame.h"
0274 template <class T>
0275 void CrossingFrame<T>::setPileupPtr(std::shared_ptr<edm::Wrapper<PCrossingFrame<T> > const> shPtr) {
0276 shPtrPileupsPCF_ = shPtr;
0277 }
0278
0279 template <class T>
0280 void CrossingFrame<T>::addPileups(T const& product) {
0281
0282 pileups_.push_back(&product);
0283 }
0284
0285 #ifndef __GCCXML__
0286 template <class T>
0287 void CrossingFrame<T>::addPileups(std::vector<T> const& product) {
0288 for (auto const& item : product) {
0289 pileups_.push_back(&item);
0290 }
0291 }
0292 #endif
0293
0294 template <class T>
0295 void CrossingFrame<T>::addSignals(const std::vector<T>* vec, edm::EventID id) {
0296
0297 id_ = id;
0298 for (unsigned int i = 0; i < vec->size(); ++i) {
0299 signals_.push_back(&((*vec)[i]));
0300 }
0301 }
0302
0303 template <class T>
0304 void CrossingFrame<T>::addSignals(const T* product, edm::EventID id) {
0305
0306 id_ = id;
0307 signals_.push_back(product);
0308 }
0309
0310 template <class T>
0311 void CrossingFrame<T>::setTof() {
0312 ;
0313 }
0314
0315 #endif