CMS 3D CMS Logo

CrossingFrame.h
Go to the documentation of this file.
1 #ifndef CROSSING_FRAME_H
2 #define CROSSING_FRAME_H
3 
21 
25 
26 template <class T>
28 
29 #include <vector>
30 #include <string>
31 #include <iostream>
32 #include <utility>
33 #include <algorithm>
34 #include <memory>
35 
36 template <class T>
38 public:
39  // con- and destructors
40 
42  CrossingFrame(int minb, int maxb, int bunchsp, std::string subdet, unsigned int maxNbSources);
43 
45 
46  void swap(CrossingFrame& other);
47 
49 
50  //standard version
51  void addSignals(const std::vector<T>* vec, edm::EventID id);
52  // version for HepMCProduct
53  void addSignals(const T* vec, edm::EventID id);
54 
55  // standard version
56  void addPileups(std::vector<T> const& vec);
57  // version for HepMCProduct
58  void addPileups(T const& product);
59 
60  void setTof();
61 
62  // we keep the shared pointer in the object that will be only destroyed at the end of the event (transient object!)
63  // because of HepMCProduct, we need 2 versions...
64  /* void setPileupPtr(std::shared_ptr<edm::Wrapper<std::vector<T> > const> shPtr) {shPtrPileups_=shPtr;} */
65  /* void setPileupPtr(std::shared_ptr<edm::Wrapper<T> const> shPtr) {shPtrPileups2_=shPtr;} */
66  void setPileupPtr(std::shared_ptr<edm::Wrapper<std::vector<T> > const> shPtr) { shPtrPileups_.push_back(shPtr); }
67  void setPileupPtr(std::shared_ptr<edm::Wrapper<T> const> shPtr) { shPtrPileups2_.push_back(shPtr); }
68  // used in the Step2 to set the PCrossingFrame
69  void setPileupPtr(std::shared_ptr<edm::Wrapper<PCrossingFrame<T> > const> shPtr);
70 
71  void print(int level = 0) const;
72 
73  void setBcrOffset() { pileupOffsetsBcr_.push_back(pileups_.size()); }
74 
75  void setSourceOffset(const unsigned int s) { pileupOffsetsSource_[s].push_back(pileups_.size()); }
76 
77  //getters
78  edm::EventID getEventID() const { return id_; }
79  std::pair<int, int> getBunchRange() const { return std::pair<int, int>(firstCrossing_, lastCrossing_); }
80  int getBunchSpace() const { return bunchSpace_; }
81  unsigned int getMaxNbSources() const { return maxNbSources_; }
82  std::string getSubDet() const { return subdet_; }
83  unsigned int getPileupFileNr() const { return pileupFileNr_; }
85  const std::vector<unsigned int>& getPileupOffsetsBcr() const { return pileupOffsetsBcr_; }
86  const std::vector<std::vector<unsigned int> >& getPileupOffsetsSource() const {
87  return pileupOffsetsSource_;
88  } //one per source
89  const std::vector<const T*>& getPileups() const { return pileups_; }
90  const std::vector<const T*>& getSignal() const { return signals_; }
91 
92  void getSignal(typename std::vector<const T*>::const_iterator& first,
93  typename std::vector<const T*>::const_iterator& last) const {
94  first = signals_.begin();
95  last = signals_.end();
96  }
97  void getPileups(typename std::vector<const T*>::const_iterator& first,
98  typename std::vector<const T*>::const_iterator& last) const;
99  unsigned int getNrSignals() const { return signals_.size(); }
100  unsigned int getNrPileups() const { return pileups_.size(); }
101  unsigned int getNrPileups(int bcr) const {
104  }
105 
106  // get pileup information in dependency from internal pointer
107  int getBunchCrossing(unsigned int ip) const;
108 
109  int getSourceType(unsigned int ip) const;
110 
111  // get object in pileup when position in the vector is known (for DigiSimLink typically)
112 
113  const T& getObject(unsigned int ip) const {
114  //ip is position in the MixCollection (i.e. signal + pileup)
115  if (ip > getNrSignals() + getNrPileups())
116  throw cms::Exception("BadIndex") << "CrossingFrame::getObject called with an invalid index- index was " << ip
117  << "!"; // ip >=0, since ip is unsigned
118  if (ip < getNrSignals()) {
119  return *(signals_[ip]);
120  } else {
121  return *(pileups_[ip - getNrSignals()]);
122  }
123  }
124 
125  // setters needed for step2 when using mixed secondary source
126  void setEventID(edm::EventID evId) { id_ = evId; }
127  void setPileups(const std::vector<const T*>& p) { pileups_ = p; }
128  void setBunchSpace(int bSpace) { bunchSpace_ = bSpace; }
129  void setMaxNbSources(unsigned int mNbS) { maxNbSources_ = mNbS; }
130  void setSubDet(std::string det) { subdet_ = det; }
131  void setPileupFileNr(unsigned int pFileNr) { pileupFileNr_ = pFileNr; }
133  void setPileupOffsetsBcr(const std::vector<unsigned int>& pOffsetsBcr) { pileupOffsetsBcr_ = pOffsetsBcr; }
134  void setPileupOffsetsSource(const std::vector<std::vector<unsigned int> >& pOffsetsS) {
135  pileupOffsetsSource_ = pOffsetsS;
136  } //one per source
137  void setBunchRange(std::pair<int, int> bunchRange) {
138  firstCrossing_ = bunchRange.first;
139  lastCrossing_ = bunchRange.second;
140  }
141 
142 private:
143  // please update the swap() function below if any data members are added.
144  // general information
147  int bunchSpace_; //in nsec
148  std::string subdet_; // for PSimHits/PCaloHits
149  edm::EventID id_; // event id of the signal event
150 
151  // for playback option
152  edm::EventID idFirstPileup_; // EventId fof the first pileup event used for this signal event
153  unsigned int pileupFileNr_; // ordinal number of the pileup file this event was in
154 
155  unsigned int maxNbSources_;
156 
157  // signal
158  std::vector<const T*> signals_;
159 
160  //pileup
161  std::vector<const T*> pileups_;
162  std::vector<std::shared_ptr<edm::Wrapper<std::vector<T> > const> > shPtrPileups_;
163  std::vector<std::shared_ptr<edm::Wrapper<T> const> > shPtrPileups2_; // fore HepMCProduct
164  /* std::shared_ptr<edm::Wrapper<std::vector<T> > const> shPtrPileups_; */
165  /* std::shared_ptr<edm::Wrapper<T> const> shPtrPileups2_; // fore HepMCProduct */
166  std::shared_ptr<edm::Wrapper<PCrossingFrame<T> > const> shPtrPileupsPCF_;
167  // std::shared_ptr<edm::Wrapper<PCrossingFrame<edm::HepMCProduct> const> shPtrPileupsHepMCProductPCF_;
168 
169  // these are informations stored in order to be able to have information
170  // as a function of the position of an object in the pileups_ vector
171  std::vector<unsigned int> pileupOffsetsBcr_;
172  std::vector<std::vector<unsigned int> > pileupOffsetsSource_; //one per source
173 };
174 
175 //==============================================================================
176 // implementations
177 //==============================================================================
178 
179 template <class T>
180 CrossingFrame<T>::CrossingFrame(int minb, int maxb, int bunchsp, std::string subdet, unsigned int maxNbSources)
181  : firstCrossing_(minb), lastCrossing_(maxb), bunchSpace_(bunchsp), subdet_(subdet), maxNbSources_(maxNbSources) {
183  for (unsigned int i = 0; i < maxNbSources_; ++i)
185 
186  //FIXME: should we force around 0 or so??
188 }
189 
190 template <typename T>
192  std::swap(firstCrossing_, other.firstCrossing_);
193  std::swap(lastCrossing_, other.lastCrossing_);
194  std::swap(bunchSpace_, other.bunchSpace_);
195  subdet_.swap(other.subdet_);
196  std::swap(id_, other.id_);
197  std::swap(idFirstPileup_, other.idFirstPileup_);
198  std::swap(pileupFileNr_, other.pileupFileNr_);
199  std::swap(maxNbSources_, other.maxNbSources_);
200  signals_.swap(other.signals_);
201  pileups_.swap(other.pileups_);
202  shPtrPileups_.swap(other.shPtrPileups_);
203  shPtrPileups2_.swap(other.shPtrPileups2_);
204  shPtrPileupsPCF_.swap(other.shPtrPileupsPCF_);
205  pileupOffsetsBcr_.swap(other.pileupOffsetsBcr_);
206  pileupOffsetsSource_.resize(maxNbSources_);
207  for (unsigned int i = 0; i < pileupOffsetsSource_.size(); ++i) {
208  pileupOffsetsSource_[i].swap(other.pileupOffsetsSource_[i]);
209  }
210 }
211 
212 template <typename T>
214  CrossingFrame<T> temp(rhs);
215  this->swap(temp);
216  return *this;
217 }
218 
219 template <class T>
220 void CrossingFrame<T>::getPileups(typename std::vector<const T*>::const_iterator& first,
221  typename std::vector<const T*>::const_iterator& last) const {
222  first = pileups_.begin();
223  last = pileups_.end();
224 }
225 
226 template <class T>
227 void CrossingFrame<T>::print(int level) const {}
228 
229 template <class T>
230 int CrossingFrame<T>::getSourceType(unsigned int ip) const {
231  // ip is position in the pileup vector
232  // decide to which source belongs object with index ip in the pileup vector
233  // pileup=0, cosmics=1, beam halo+ =2, beam halo- =3 forward =4
234  unsigned int bcr = getBunchCrossing(ip) - firstCrossing_; //starts at 0
235  for (unsigned int i = 0; i < pileupOffsetsSource_.size() - 1; ++i) {
236  if (ip >= (pileupOffsetsSource_[i])[bcr] && ip < (pileupOffsetsSource_[i + 1])[bcr])
237  return i;
238  }
239  return pileupOffsetsSource_.size() - 1;
240 }
241 
242 template <class T>
243 int CrossingFrame<T>::getBunchCrossing(unsigned int ip) const {
244  // return the bcr for a certain position in the pileup vector
245  for (unsigned int ii = 1; ii < pileupOffsetsBcr_.size(); ii++) {
246  if (ip >= pileupOffsetsBcr_[ii - 1] && ip < pileupOffsetsBcr_[ii])
247  return ii + firstCrossing_ - 1;
248  }
249  if (ip < pileups_.size())
250  return lastCrossing_;
251  else
252  return 999;
253 }
254 
255 // Free swap function
256 template <typename T>
257 inline void swap(CrossingFrame<T>& lhs, CrossingFrame<T>& rhs) {
258  lhs.swap(rhs);
259 }
260 
261 #include <iosfwd>
262 #include <iostream>
263 
264 template <class T>
265 std::ostream& operator<<(std::ostream& o, const CrossingFrame<T>& cf) {
266  std::pair<int, int> range = cf.getBunchRange();
267  o << "\nCrossingFrame for subdet " << cf.getEventID() << ", bunchrange = " << range.first << "," << range.second
268  << ", bunchSpace " << cf.getBunchSpace();
269 
270  return o;
271 }
272 
274 template <class T>
275 void CrossingFrame<T>::setPileupPtr(std::shared_ptr<edm::Wrapper<PCrossingFrame<T> > const> shPtr) {
276  shPtrPileupsPCF_ = shPtr;
277 }
278 
279 template <class T>
280 void CrossingFrame<T>::addPileups(T const& product) {
281  // default, valid for HepMCProduct
282  pileups_.push_back(&product);
283 }
284 
285 #ifndef __GCCXML__
286 template <class T>
287 void CrossingFrame<T>::addPileups(std::vector<T> const& product) {
288  for (auto const& item : product) {
289  pileups_.push_back(&item);
290  }
291 }
292 #endif
293 
294 template <class T>
295 void CrossingFrame<T>::addSignals(const std::vector<T>* vec, edm::EventID id) {
296  // valid (called) for all except HepMCProduct
297  id_ = id;
298  for (unsigned int i = 0; i < vec->size(); ++i) {
299  signals_.push_back(&((*vec)[i]));
300  }
301 }
302 
303 template <class T>
304 void CrossingFrame<T>::addSignals(const T* product, edm::EventID id) {
305  // valid (called) for all except HepMCProduct
306  id_ = id;
307  signals_.push_back(product);
308 }
309 
310 template <class T>
312  ;
313 }
314 
315 #endif
personalPlayback.level
level
Definition: personalPlayback.py:22
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
CrossingFrame::CrossingFrame
CrossingFrame()
Definition: CrossingFrame.h:41
mps_fire.i
i
Definition: mps_fire.py:428
CrossingFrame::getPileups
const std::vector< const T * > & getPileups() const
Definition: CrossingFrame.h:89
CrossingFrame::maxNbSources_
unsigned int maxNbSources_
Definition: CrossingFrame.h:155
CrossingFrame::addPileups
void addPileups(std::vector< T > const &vec)
Definition: CrossingFrame.h:287
CrossingFrame::getSubDet
std::string getSubDet() const
Definition: CrossingFrame.h:82
CrossingFrame::idFirstPileup_
edm::EventID idFirstPileup_
Definition: CrossingFrame.h:152
CrossingFrame::print
void print(int level=0) const
Definition: CrossingFrame.h:227
CrossingFrame::setBunchRange
void setBunchRange(std::pair< int, int > bunchRange)
Definition: CrossingFrame.h:137
CrossingFrame::addSignals
void addSignals(const std::vector< T > *vec, edm::EventID id)
Definition: CrossingFrame.h:295
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
PSimHitContainer.h
CrossingFrame::setPileups
void setPileups(const std::vector< const T * > &p)
Definition: CrossingFrame.h:127
PCrossingFrame
Definition: CrossingFrame.h:27
CrossingFrame::setMaxNbSources
void setMaxNbSources(unsigned int mNbS)
Definition: CrossingFrame.h:129
CrossingFrame::getPileupFileNr
unsigned int getPileupFileNr() const
Definition: CrossingFrame.h:83
CrossingFrame::getSourceType
int getSourceType(unsigned int ip) const
Definition: CrossingFrame.h:230
CrossingFrame::setPileupOffsetsSource
void setPileupOffsetsSource(const std::vector< std::vector< unsigned int > > &pOffsetsS)
Definition: CrossingFrame.h:134
CrossingFrame::setSubDet
void setSubDet(std::string det)
Definition: CrossingFrame.h:130
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
CrossingFrame::setIdFirstPileup
void setIdFirstPileup(edm::EventID idFP)
Definition: CrossingFrame.h:132
edm::Wrapper
Definition: Product.h:10
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
CrossingFrame
Definition: CrossingFrame.h:37
alignCSCRings.s
s
Definition: alignCSCRings.py:92
CrossingFrame::getNrSignals
unsigned int getNrSignals() const
Definition: CrossingFrame.h:99
dqmdumpme.last
last
Definition: dqmdumpme.py:56
CrossingFrame::setEventID
void setEventID(edm::EventID evId)
Definition: CrossingFrame.h:126
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
CrossingFrame::shPtrPileups2_
std::vector< std::shared_ptr< edm::Wrapper< T > const > > shPtrPileups2_
Definition: CrossingFrame.h:163
EventID.h
CrossingFrame::lastCrossing_
int lastCrossing_
Definition: CrossingFrame.h:146
CrossingFrame::setSourceOffset
void setSourceOffset(const unsigned int s)
Definition: CrossingFrame.h:75
CrossingFrame::getNrPileups
unsigned int getNrPileups(int bcr) const
Definition: CrossingFrame.h:101
CrossingFrame::getEventID
edm::EventID getEventID() const
Definition: CrossingFrame.h:78
trackingPlots.other
other
Definition: trackingPlots.py:1460
CrossingFrame::getPileupOffsetsBcr
const std::vector< unsigned int > & getPileupOffsetsBcr() const
Definition: CrossingFrame.h:85
CrossingFrame::subdet_
std::string subdet_
Definition: CrossingFrame.h:148
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
CrossingFrame::getSignal
void getSignal(typename std::vector< const T * >::const_iterator &first, typename std::vector< const T * >::const_iterator &last) const
Definition: CrossingFrame.h:92
CrossingFrame::getBunchSpace
int getBunchSpace() const
Definition: CrossingFrame.h:80
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CrossingFrame::setPileupPtr
void setPileupPtr(std::shared_ptr< edm::Wrapper< std::vector< T > > const > shPtr)
Definition: CrossingFrame.h:66
CrossingFrame::firstCrossing_
int firstCrossing_
Definition: CrossingFrame.h:145
CrossingFrame::getSignal
const std::vector< const T * > & getSignal() const
Definition: CrossingFrame.h:90
CrossingFrame::setPileupFileNr
void setPileupFileNr(unsigned int pFileNr)
Definition: CrossingFrame.h:131
CrossingFrame::getMaxNbSources
unsigned int getMaxNbSources() const
Definition: CrossingFrame.h:81
CrossingFrame::setTof
void setTof()
Definition: CrossingFrame.h:311
CrossingFrame::getBunchCrossing
int getBunchCrossing(unsigned int ip) const
Definition: CrossingFrame.h:243
PCrossingFrame.h
CrossingFrame::bunchSpace_
int bunchSpace_
Definition: CrossingFrame.h:147
CrossingFrame::setBcrOffset
void setBcrOffset()
Definition: CrossingFrame.h:73
CrossingFrame::pileupOffsetsSource_
std::vector< std::vector< unsigned int > > pileupOffsetsSource_
Definition: CrossingFrame.h:172
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
CrossingFrame::shPtrPileups_
std::vector< std::shared_ptr< edm::Wrapper< std::vector< T > > const > > shPtrPileups_
Definition: CrossingFrame.h:162
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
CrossingFrame::getObject
const T & getObject(unsigned int ip) const
Definition: CrossingFrame.h:113
CrossingFrame::shPtrPileupsPCF_
std::shared_ptr< edm::Wrapper< PCrossingFrame< T > > const > shPtrPileupsPCF_
Definition: CrossingFrame.h:166
CrossingFrame::setBunchSpace
void setBunchSpace(int bSpace)
Definition: CrossingFrame.h:128
Wrapper.h
CrossingFrame::signals_
std::vector< const T * > signals_
Definition: CrossingFrame.h:158
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
T
long double T
Definition: Basic3DVectorLD.h:48
swap
void swap(CrossingFrame< T > &lhs, CrossingFrame< T > &rhs)
Definition: CrossingFrame.h:257
CrossingFrame::getNrPileups
unsigned int getNrPileups() const
Definition: CrossingFrame.h:100
Exception
Definition: hltDiff.cc:245
CrossingFrame::setPileupOffsetsBcr
void setPileupOffsetsBcr(const std::vector< unsigned int > &pOffsetsBcr)
Definition: CrossingFrame.h:133
CrossingFrame::setPileupPtr
void setPileupPtr(std::shared_ptr< edm::Wrapper< T > const > shPtr)
Definition: CrossingFrame.h:67
CrossingFrame::getBunchRange
std::pair< int, int > getBunchRange() const
Definition: CrossingFrame.h:79
PCaloHitContainer.h
CrossingFrame::pileupFileNr_
unsigned int pileupFileNr_
Definition: CrossingFrame.h:153
CrossingFrame::pileups_
std::vector< const T * > pileups_
Definition: CrossingFrame.h:161
operator<<
std::ostream & operator<<(std::ostream &o, const CrossingFrame< T > &cf)
Definition: CrossingFrame.h:265
CrossingFrame::swap
void swap(CrossingFrame &other)
Definition: CrossingFrame.h:191
CrossingFrame::getIdFirstPileup
edm::EventID getIdFirstPileup() const
Definition: CrossingFrame.h:84
CrossingFrame::operator=
CrossingFrame & operator=(CrossingFrame const &rhs)
Definition: CrossingFrame.h:213
HepMCProduct.h
edm::EventID
Definition: EventID.h:31
CrossingFrame::~CrossingFrame
~CrossingFrame()
Definition: CrossingFrame.h:44
SimTrackContainer.h
cuy.ii
ii
Definition: cuy.py:590
CrossingFrame::pileupOffsetsBcr_
std::vector< unsigned int > pileupOffsetsBcr_
Definition: CrossingFrame.h:171
SimVertexContainer.h
CrossingFrame::getPileupOffsetsSource
const std::vector< std::vector< unsigned int > > & getPileupOffsetsSource() const
Definition: CrossingFrame.h:86
CrossingFrame::id_
edm::EventID id_
Definition: CrossingFrame.h:149
EncodedEventId.h