CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MixingWorker.h
Go to the documentation of this file.
1 #ifndef MixingWorker_h
2 #define MixingWorker_h
3 
19 
24 
25 #include <vector>
26 #include <string>
27 #include <typeinfo>
28 #include "MixingWorkerBase.h"
29 
30 class SimTrack;
31 class SimVertex;
32 namespace edm
33 {
34  template <class T>
36  {
37  public:
38 
40  explicit MixingWorker() {;}
41 
42  /*Normal constructor*/
43  MixingWorker(int minBunch,int maxBunch, int bunchSpace,std::string subdet,std::string label, std::string labelCF,int maxNbSources, InputTag& tag, InputTag& tagCF, bool mixProdStep2):
44  MixingWorkerBase(minBunch,maxBunch,bunchSpace,subdet,label,labelCF,maxNbSources,tag,tagCF,mixProdStep2)
45  {
46  mixProdStep2_ = mixProdStep2;
47  }
48 
50  virtual ~MixingWorker() {;}
51 
52  public:
53 
54  void setTof();
55 
56  virtual void put(edm::Event &e) {
57  std::auto_ptr<CrossingFrame<T> > pOut(crFrame_);
58  if (!mixProdStep2_){
59  e.put(pOut,label_);
60  LogDebug("MixingModule") <<" CF was put for type "<<typeid(T).name()<<" with "<<label_;
61  }
62  else {
63  e.put(pOut,labelCF_);
64  LogDebug("MixingModule") <<" CF was put for type "<<typeid(T).name()<<" with "<<labelCF_;
65  }
66  }
67 
68 
69  virtual bool checkSignal(const edm::Event &e){
70  bool got;
71  InputTag t;
72  edm::Handle<std::vector<T> > result_t;
73  if (mixProdStep2_){
74  got = e.getByLabel(tagSignal_,result_t);
76  }
77  else{
78  got = e.getByLabel(tag_,result_t);
79  t = InputTag(tag_.label(),tag_.instance());
80  }
81 
82  if (got)
83  LogInfo("MixingModule") <<" Will create a CrossingFrame for "<< typeid(T).name()
84  << " with InputTag= "<< t.encode();
85 
86  return got;
87  }
88 
89 
90  virtual void createnewEDProduct(){
92  }
93 
94  virtual void setBcrOffset() {crFrame_->setBcrOffset();}
95  virtual void setSourceOffset(const unsigned int s) {crFrame_->setSourceOffset(s);}
96 
97 
98  virtual void addSignals(const edm::Event &e){
99  if (mixProdStep2_){
100  edm::Handle<std::vector<T> > result_t;
101  bool got = e.getByLabel(tagSignal_,result_t);
102  if (got) {
103  LogDebug("MixingModule") <<" adding " << result_t.product()->size()<<" signal objects for "<<typeid(T).name()<<" with "<<tagSignal_;
104  crFrame_->addSignals(result_t.product(),e.id());
105  }
106  else LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for "<<typeid(T).name()<<", with "<<tagSignal_;
107  }
108  else{
109  // Default version
110  edm::Handle<std::vector<T> > result_t;
111  bool got = e.getByLabel(tag_,result_t);
112  if (got) {
113  LogDebug("MixingModule") <<" adding " << result_t.product()->size()<<" signal objects for "<<typeid(T).name()<<" with "<<tag_;
114  crFrame_->addSignals(result_t.product(),e.id());
115  }
116  else LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for "<<typeid(T).name()<<", with "<<tag_;
117 
118  }
119 
120  }
121 
122  virtual void addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset);
123  // When using mixed secondary source
124  // Copy the data from the PCrossingFrame to the CrossingFrame
125  virtual void copyPCrossingFrame(const PCrossingFrame<T> *PCF);
126 
127  private:
130 
132  };
133 
134 //=============== template specializations ====================================================================================
135  template <class T>
136  void MixingWorker<T>::addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset)
137  {
138  if (!mixProdStep2_){
139  // default version
140  // valid for CaloHits
141  boost::shared_ptr<Wrapper<std::vector<T> > const> shPtr =
142  edm::getProductByTag<std::vector<T> >(*ep, tag_);
143 
144  if (shPtr) {
145  LogDebug("MixingModule") <<shPtr->product()->size()<<" pileup objects added, eventNr "<<eventNr;
146  crFrame_->addPileups(bcr,const_cast< std::vector<T> * >(shPtr->product()),eventNr);
147  }
148 
149  }
150  else
151  {
152  boost::shared_ptr<Wrapper<PCrossingFrame<T> > const> shPtr = getProductByTag<PCrossingFrame<T> >(*ep, tag_);
153 
154  if (shPtr){
155  secSourceCF_ = const_cast<PCrossingFrame<T> * >(shPtr->product());
156  LogDebug("MixingModule") << "Add PCrossingFrame<T> eventNr " << secSourceCF_->getEventID();
157 
158  copyPCrossingFrame(secSourceCF_);
159 
160  }
161  else
162  LogDebug("MixingModule") << "Could not get the PCrossingFrame<T>!";
163  }
164  }
165 
166 
167 template <>
168  void MixingWorker<PSimHit>::addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset);
169 
170 template <>
171  void MixingWorker<SimTrack>::addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset);
172 
173 template <>
174  void MixingWorker<SimVertex>::addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset);
175 
176 template <>
177  void MixingWorker<HepMCProduct>::addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset);
178 
179 template <class T>
181 
182 template <class T>
184  {
185  crFrame_->setBunchRange(PCF->getBunchRange());
186  crFrame_->setBunchSpace(PCF->getBunchSpace());
187  crFrame_->setMaxNbSources(PCF->getMaxNbSources());
188  crFrame_->setSubDet(PCF->getSubDet());
189  crFrame_->setPileupOffsetsBcr(PCF->getPileupOffsetsBcr());
190  crFrame_->setPileupOffsetsSource(PCF->getPileupOffsetsSource());
191  crFrame_->setPileups(PCF->getPileups());
192 
193  // For playback option
194  crFrame_->setPileupFileNr(PCF->getPileupFileNr());
195  crFrame_->setIdFirstPileup(PCF->getIdFirstPileup());
196  }
197 
198 }//edm
199 
200 #endif
#define LogDebug(id)
std::string const subdet_
virtual void setBcrOffset()
Definition: MixingWorker.h:94
std::string const labelCF_
const std::string & label
Definition: MVAComputer.cc:186
virtual void createnewEDProduct()
Definition: MixingWorker.h:90
int getBunchSpace() const
unsigned int getPileupFileNr() const
virtual void addSignals(const edm::Event &e)
Definition: MixingWorker.h:98
std::string encode() const
Definition: InputTag.cc:72
edm::EventID getIdFirstPileup() const
virtual bool checkSignal(const edm::Event &e)
Definition: MixingWorker.h:69
virtual void copyPCrossingFrame(const PCrossingFrame< T > *PCF)
Definition: MixingWorker.h:183
virtual ~MixingWorker()
Definition: MixingWorker.h:50
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
virtual void addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr, int vertexoffset)
Definition: MixingWorker.h:136
CrossingFrame< T > * crFrame_
Definition: MixingWorker.h:128
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
virtual void put(edm::Event &e)
Definition: MixingWorker.h:56
std::string getSubDet() const
unsigned int getMaxNbSources() const
std::pair< int, int > getBunchRange() const
T const * product() const
Definition: Handle.h:74
std::vector< unsigned int > getPileupOffsetsBcr() const
std::string const & label() const
Definition: InputTag.h:25
edm::EventID id() const
Definition: EventBase.h:56
PCrossingFrame< T > * secSourceCF_
Definition: MixingWorker.h:129
MixingWorker(int minBunch, int maxBunch, int bunchSpace, std::string subdet, std::string label, std::string labelCF, int maxNbSources, InputTag &tag, InputTag &tagCF, bool mixProdStep2)
Definition: MixingWorker.h:43
std::vector< const T * > getPileups() const
unsigned int const maxNbSources_
string s
Definition: asciidump.py:422
std::string const label_
long double T
std::string const & instance() const
Definition: InputTag.h:26
virtual void setSourceOffset(const unsigned int s)
Definition: MixingWorker.h:95
std::vector< std::vector< unsigned int > > getPileupOffsetsSource() const