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