CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
38 template <class T>
40 {
41 
42  public:
43  // con- and destructors
44 
46 }
47  CrossingFrame(int minb, int maxb, int bunchsp, std::string subdet ,unsigned int maxNbSources);
48 
50 
51  void swap(CrossingFrame& other);
52 
54 
55  //standard version
56  void addSignals(const std::vector<T> * vec,edm::EventID id);
57  // version for HepMCProduct
58  void addSignals(const T * vec,edm::EventID id);
59 
60  // standard version
61  void addPileups(std::vector<T> const& vec);
62  // version for HepMCProduct
63  void addPileups(T const& product);
64 
65  void setTof( );
66 
67  // we keep the shared pointer in the object that will be only destroyed at the end of the event (transient object!)
68  // because of HepMCProduct, we need 2 versions...
69 /* void setPileupPtr(std::shared_ptr<edm::Wrapper<std::vector<T> > const> shPtr) {shPtrPileups_=shPtr;} */
70 /* void setPileupPtr(std::shared_ptr<edm::Wrapper<T> const> shPtr) {shPtrPileups2_=shPtr;} */
71  void setPileupPtr(std::shared_ptr<edm::Wrapper<std::vector<T> > const> shPtr) {shPtrPileups_.push_back( shPtr );}
72  void setPileupPtr(std::shared_ptr<edm::Wrapper<T> const> shPtr) {shPtrPileups2_.push_back( shPtr );}
73  // used in the Step2 to set the PCrossingFrame
74  void setPileupPtr(std::shared_ptr<edm::Wrapper<PCrossingFrame<T> > const> shPtr);
75 
76  void print(int level=0) const ;
77 
78  void setBcrOffset() {
79  pileupOffsetsBcr_.push_back(pileups_.size());
80  }
81 
82  void setSourceOffset(const unsigned int s) {
83  pileupOffsetsSource_[s].push_back(pileups_.size());
84  }
85 
86  //getters
87  edm::EventID getEventID() const {return id_;}
88  std::pair<int,int> getBunchRange() const {return std::pair<int,int>(firstCrossing_,lastCrossing_);}
89  int getBunchSpace() const {return bunchSpace_;}
90  unsigned int getMaxNbSources() const {return maxNbSources_; }
91  std::string getSubDet() const { return subdet_;}
92  unsigned int getPileupFileNr() const {return pileupFileNr_;}
94  std::vector<unsigned int> getPileupOffsetsBcr() const {return pileupOffsetsBcr_;}
95  std::vector< std::vector<unsigned int> > getPileupOffsetsSource() const {return pileupOffsetsSource_;} //one per source
96  std::vector<const T *> getPileups() const {return pileups_;}
97  std::vector<const T *> getSignal() const {return signals_;}
98 
99 
100  void getSignal(typename std::vector<const T *>::const_iterator &first,typename std::vector<const T*>::const_iterator &last) const {
101  first=signals_.begin();
102  last=signals_.end();
103  }
104  void getPileups(typename std::vector<const T*>::const_iterator &first, typename std::vector<const T*>::const_iterator &last) const;
105  unsigned int getNrSignals() const {return signals_.size();}
106  unsigned int getNrPileups() const {return pileups_.size();}
107  unsigned int getNrPileups(int bcr) const {
109 
110  // get pileup information in dependency from internal pointer
111  int getBunchCrossing(unsigned int ip) const;
112 
113  int getSourceType(unsigned int ip) const;
114 
115  // get object in pileup when position in the vector is known (for DigiSimLink typically)
116 
117  const T & getObject(unsigned int ip) const {
118  //ip is position in the MixCollection (i.e. signal + pileup)
119  if (ip>getNrSignals()+getNrPileups()) throw cms::Exception("BadIndex")<<"CrossingFrame::getObject called with an invalid index- index was "<<ip<<"!"; // ip >=0, since ip is unsigned
120  if (ip<getNrSignals()) {
121  return *(signals_[ip]);
122  }
123  else {
124  return *(pileups_[ip-getNrSignals()]);
125  }
126  }
127 
128 
129  // setters needed for step2 when using mixed secondary source
130  void setEventID(edm::EventID evId) { id_ = evId; }
131  void setPileups(const std::vector<const T *>& p) { pileups_ = p; }
132  void setBunchSpace(int bSpace) { bunchSpace_ = bSpace; }
133  void setMaxNbSources(unsigned int mNbS) { maxNbSources_ = mNbS; }
134  void setSubDet(std::string det) { subdet_ = det; }
135  void setPileupFileNr(unsigned int pFileNr) { pileupFileNr_ = pFileNr;}
137  void setPileupOffsetsBcr(const std::vector<unsigned int>& pOffsetsBcr) { pileupOffsetsBcr_ = pOffsetsBcr;}
138  void setPileupOffsetsSource(const std::vector< std::vector<unsigned int> >& pOffsetsS) { pileupOffsetsSource_ = pOffsetsS;} //one per source
139  void setBunchRange(std::pair<int,int> bunchRange) { firstCrossing_ = bunchRange.first;
140  lastCrossing_ = bunchRange.second;}
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 //==============================================================================
177 // implementations
178 //==============================================================================
179 
180 template <class T>
181 CrossingFrame<T>::CrossingFrame(int minb, int maxb, int bunchsp, std::string subdet ,unsigned int
182 maxNbSources):firstCrossing_(minb), lastCrossing_(maxb),
183 bunchSpace_(bunchsp),subdet_(subdet),maxNbSources_(maxNbSources) {
185  for (unsigned int i=0;i<maxNbSources_;++i)
187 
188 //FIXME: should we force around 0 or so??
190 }
191 
192 template <typename T>
193 inline
194 void
196  std::swap(firstCrossing_, other.firstCrossing_);
197  std::swap(lastCrossing_, other.lastCrossing_);
198  std::swap(bunchSpace_, other.bunchSpace_);
199  subdet_.swap(other.subdet_);
200  std::swap(id_, other.id_);
201  std::swap(idFirstPileup_, other.idFirstPileup_);
202  std::swap(pileupFileNr_, other.pileupFileNr_);
203  std::swap(maxNbSources_, other.maxNbSources_);
204  signals_.swap(other.signals_);
205  pileups_.swap(other.pileups_);
206  shPtrPileups_.swap(other.shPtrPileups_);
207  shPtrPileups2_.swap(other.shPtrPileups2_);
208  shPtrPileupsPCF_.swap(other.shPtrPileupsPCF_);
209  pileupOffsetsBcr_.swap(other.pileupOffsetsBcr_);
210  pileupOffsetsSource_.resize(maxNbSources_);
211  for (unsigned int i=0;i<pileupOffsetsSource_.size();++i) {
212  pileupOffsetsSource_[i].swap(other.pileupOffsetsSource_[i]);
213  }
214 }
215 
216 template <typename T>
217 inline
220  CrossingFrame<T> temp(rhs);
221  this->swap(temp);
222  return *this;
223 }
224 
225 
226 template <class T>
227 void CrossingFrame<T>::getPileups(typename std::vector<const T *>::const_iterator &first,typename std::vector<const T *>::const_iterator &last) const {
228  first=pileups_.begin();
229  last=pileups_.end();
230 }
231 
232 template <class T>
234 }
235 
236 template <class T>
237 int CrossingFrame<T>::getSourceType(unsigned int ip) const {
238  // ip is position in the pileup vector
239  // decide to which source belongs object with index ip in the pileup vector
240  // pileup=0, cosmics=1, beam halo+ =2, beam halo- =3 forward =4
241  unsigned int bcr= getBunchCrossing(ip)-firstCrossing_; //starts at 0
242  for (unsigned int i=0;i<pileupOffsetsSource_.size()-1;++i) {
243  if (ip>=(pileupOffsetsSource_[i])[bcr] && ip <(pileupOffsetsSource_[i+1])[bcr]) return i;
244  }
245  return pileupOffsetsSource_.size()-1;
246 }
247 
248 template <class T>
249 int CrossingFrame<T>::getBunchCrossing(unsigned int ip) const {
250  // return the bcr for a certain position in the pileup vector
251  for (unsigned int ii=1;ii<pileupOffsetsBcr_.size();ii++){
252  if (ip>=pileupOffsetsBcr_[ii-1] && ip<pileupOffsetsBcr_[ii]) return ii+firstCrossing_-1;
253  }
254  if (ip<pileups_.size()) return lastCrossing_;
255  else return 999;
256 }
257 
258 // Free swap function
259 template <typename T>
260 inline
261 void
263  lhs.swap(rhs);
264 }
265 
266 #include<iosfwd>
267 #include<iostream>
268 
269 template <class T>
270 std::ostream &operator<<(std::ostream& o, const CrossingFrame<T>& cf)
271 {
272  std::pair<int,int> range=cf.getBunchRange();
273  o <<"\nCrossingFrame for subdet "<<cf.getEventID()<<", bunchrange = "<<range.first<<","<<range.second
274  <<", bunchSpace "<<cf.getBunchSpace();
275 
276  return o;
277 }
278 
280 template <class T>
281 void CrossingFrame<T>::setPileupPtr(std::shared_ptr<edm::Wrapper<PCrossingFrame<T> > const> shPtr) {shPtrPileupsPCF_=shPtr;}
282 
283 
284 template <class T>
285 void CrossingFrame<T>::addPileups(T const& product) {
286  // default, valid for HepMCProduct
287  pileups_.push_back(&product);
288 }
289 
290 #ifndef __GCCXML__
291 template <class T>
292 void CrossingFrame<T>::addPileups(std::vector<T> const& product){
293  for (auto const& item : product) {
294  pileups_.push_back(&item);
295  }
296 }
297 #endif
298 
299 template <class T>
300 void CrossingFrame<T>::addSignals(const std::vector<T> * vec,edm::EventID id){
301  // valid (called) for all except HepMCProduct
302  id_=id;
303  for (unsigned int i=0;i<vec->size();++i) {
304  signals_.push_back(&((*vec)[i]));
305  }
306 }
307 
308 template <class T>
309 void CrossingFrame<T>::addSignals(const T * product,edm::EventID id){
310  // valid (called) for all except HepMCProduct
311  id_=id;
312  signals_.push_back(product);
313 }
314 
315 template <class T>
317 
318 #endif
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:70
void addSignals(const std::vector< T > *vec, edm::EventID id)
void addPileups(std::vector< T > const &vec)
int i
Definition: DBlmapReader.cc:9
void setEventID(edm::EventID evId)
std::pair< int, int > getBunchRange() const
Definition: CrossingFrame.h:88
std::vector< std::shared_ptr< edm::Wrapper< T > const > > shPtrPileups2_
void print(int level=0) const
unsigned int getMaxNbSources() const
Definition: CrossingFrame.h:90
void setPileups(const std::vector< const T * > &p)
unsigned int getNrPileups(int bcr) const
void setPileupPtr(std::shared_ptr< edm::Wrapper< std::vector< T > > const > shPtr)
Definition: CrossingFrame.h:71
int getSourceType(unsigned int ip) const
void setMaxNbSources(unsigned int mNbS)
void setPileupFileNr(unsigned int pFileNr)
void setIdFirstPileup(edm::EventID idFP)
std::vector< std::vector< unsigned int > > getPileupOffsetsSource() const
Definition: CrossingFrame.h:95
std::vector< const T * > signals_
int ii
Definition: cuy.py:588
void setPileupPtr(std::shared_ptr< edm::Wrapper< T > const > shPtr)
Definition: CrossingFrame.h:72
void setSubDet(std::string det)
edm::EventID id_
unsigned int maxNbSources_
std::string getSubDet() const
Definition: CrossingFrame.h:91
edm::EventID getEventID() const
Definition: CrossingFrame.h:87
const T & getObject(unsigned int ip) const
std::vector< const T * > getSignal() const
Definition: CrossingFrame.h:97
edm::EventID idFirstPileup_
void setBunchRange(std::pair< int, int > bunchRange)
std::vector< unsigned int > pileupOffsetsBcr_
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::vector< const T * > getPileups() const
Definition: CrossingFrame.h:96
void setPileupOffsetsBcr(const std::vector< unsigned int > &pOffsetsBcr)
std::shared_ptr< edm::Wrapper< PCrossingFrame< T > > const > shPtrPileupsPCF_
void setBunchSpace(int bSpace)
int getBunchCrossing(unsigned int ip) const
void setPileupOffsetsSource(const std::vector< std::vector< unsigned int > > &pOffsetsS)
unsigned int getPileupFileNr() const
Definition: CrossingFrame.h:92
std::vector< std::shared_ptr< edm::Wrapper< std::vector< T > > const > > shPtrPileups_
void setBcrOffset()
Definition: CrossingFrame.h:78
std::vector< std::vector< unsigned int > > pileupOffsetsSource_
std::string subdet_
std::vector< const T * > pileups_
void swap(CrossingFrame &other)
tuple level
Definition: testEve_cfg.py:34
std::vector< unsigned int > getPileupOffsetsBcr() const
Definition: CrossingFrame.h:94
unsigned int getNrSignals() const
unsigned int pileupFileNr_
edm::EventID getIdFirstPileup() const
Definition: CrossingFrame.h:93
long double T
void setSourceOffset(const unsigned int s)
Definition: CrossingFrame.h:82
void getSignal(typename std::vector< const T * >::const_iterator &first, typename std::vector< const T * >::const_iterator &last) const
CrossingFrame & operator=(CrossingFrame const &rhs)
int getBunchSpace() const
Definition: CrossingFrame.h:89
unsigned int getNrPileups() const