CMS 3D CMS Logo

MixingWorker.h
Go to the documentation of this file.
1 #ifndef MixingWorker_h
2 #define MixingWorker_h
3 
19 
24 
29 
30 #include <memory>
31 #include <vector>
32 #include <string>
33 #include <typeinfo>
34 #include "MixingWorkerBase.h"
35 
36 class SimTrack;
37 class SimVertex;
38 namespace edm
39 {
40  template <class T>
42  {
43  public:
44 
46  explicit MixingWorker() :
47  minBunch_(-5),
48  maxBunch_(3),
49  bunchSpace_(75),
50  subdet_(std::string(" ")),
51  label_(std::string(" ")),
52  labelCF_(std::string(" ")),
53  maxNbSources_(5),
54  tag_(),
55  tagSignal_(),
56  allTags_(),
59  {
60  }
61 
62  /*Normal constructor*/
63  MixingWorker(int minBunch,int maxBunch, int bunchSpace,
65  std::string labelCF,int maxNbSources, InputTag& tag,
66  InputTag& tagCF):
68  minBunch_(minBunch),
69  maxBunch_(maxBunch),
70  bunchSpace_(bunchSpace),
71  subdet_(subdet),
72  label_(label),
73  labelCF_(labelCF),
74  maxNbSources_(maxNbSources),
75  tag_(tag),
76  tagSignal_(tagCF),
77  allTags_(),
80  {
81  }
82 
83  /*constructor for HepMCproduct case*/
84  MixingWorker(int minBunch,int maxBunch, int bunchSpace,
86  std::string labelCF,int maxNbSources, InputTag& tag,
87  InputTag& tagCF,
88  std::vector<InputTag> const& tags) :
90  minBunch_(minBunch),
91  maxBunch_(maxBunch),
92  bunchSpace_(bunchSpace),
93  subdet_(subdet),
94  label_(label),
95  labelCF_(labelCF),
96  maxNbSources_(maxNbSources),
97  tag_(tag),
98  tagSignal_(tagCF),
99  allTags_(tags),
100  crFrame_(nullptr),
102  {
103  }
104 
106  ~MixingWorker() override {;}
107 
108  public:
109 
110  void reload(const edm::EventSetup & setup) override{
111  //get the required parameters from DB.
112  // watch the label/tag
114  setup.get<MixingRcd>().get(config);
115  minBunch_=config->minBunch();
116  maxBunch_=config->maxBunch();
117  bunchSpace_=config->bunchSpace();
118  }
119 
120  bool checkSignal(const edm::Event &e) override{
121  bool got;
122  InputTag t;
123  edm::Handle<std::vector<T> > result_t;
124  got = e.getByLabel(tag_,result_t);
125  t = InputTag(tag_.label(),tag_.instance());
126 
127  if (got)
128  LogInfo("MixingModule") <<" Will create a CrossingFrame for "<< typeid(T).name()
129  << " with InputTag= "<< t.encode();
130 
131  return got;
132  }
133 
134 
135  void createnewEDProduct() override{
137  }
138 
139  void addSignals(const edm::Event &e) override{
140  edm::Handle<std::vector<T> > result_t;
141  bool got = e.getByLabel(tag_,result_t);
142  if (got) {
143  LogDebug("MixingModule") <<" adding " << result_t.product()->size()<<" signal objects for "<<typeid(T).name()<<" with "<<tag_;
144  crFrame_->addSignals(result_t.product(),e.id());
145  } else {
146  LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for "<<typeid(T).name()<<", with "<<tag_;
147  }
148  }
149 
150  void addPileups(const EventPrincipal &ep, ModuleCallingContext const*, unsigned int eventNr) override;
151 
152  void setBcrOffset() override {crFrame_->setBcrOffset();}
153  void setSourceOffset(const unsigned int s) override {crFrame_->setSourceOffset(s);}
154 
155  void setTof() override;
156 
157  void put(edm::Event &e) override {
158  std::unique_ptr<CrossingFrame<T> > pOut(crFrame_);
159  e.put(std::move(pOut),label_);
160  LogDebug("MixingModule") <<" CF was put for type "<<typeid(T).name()<<" with "<<label_;
161  }
162 
163  // When using mixed secondary source
164  // Copy the data from the PCrossingFrame to the CrossingFrame
165  virtual void copyPCrossingFrame(const PCrossingFrame<T> *PCF);
166 
167  private:
174  unsigned int const maxNbSources_;
177  std::vector<InputTag> allTags_; // for HepMCProduct
178 
181  };
182 
183  template <typename T>
184  void MixingWorker<T>::addPileups(const EventPrincipal &ep, ModuleCallingContext const* mcc, unsigned int eventNr) {
185  std::shared_ptr<Wrapper<std::vector<T> > const> shPtr = getProductByTag<std::vector<T> >(ep, tag_, mcc);
186  if (shPtr) {
187  LogDebug("MixingModule") << shPtr->product()->size() << " pileup objects added, eventNr " << eventNr;
188  crFrame_->setPileupPtr(shPtr);
189  crFrame_->addPileups(*shPtr->product());
190  }
191  }
192 //=============== template specializations ====================================================================================
193 
194 template <>
195  void MixingWorker<HepMCProduct>::addPileups(const EventPrincipal &ep, ModuleCallingContext const*, unsigned int eventNr);
196 
197 template <class T>
199 
200 template <class T>
202  {
203  crFrame_->setBunchRange(PCF->getBunchRange());
204  crFrame_->setBunchSpace(PCF->getBunchSpace());
205  crFrame_->setMaxNbSources(PCF->getMaxNbSources());
206  crFrame_->setSubDet(PCF->getSubDet());
207  crFrame_->setPileupOffsetsBcr(PCF->getPileupOffsetsBcr());
208  crFrame_->setPileupOffsetsSource(PCF->getPileupOffsetsSource());
209  crFrame_->setPileups(PCF->getPileups());
210 
211  // For playback option
212  crFrame_->setPileupFileNr(PCF->getPileupFileNr());
213  crFrame_->setIdFirstPileup(PCF->getIdFirstPileup());
214  }
215 
216 }//edm
217 
218 #endif
#define LogDebug(id)
void addSignals(const edm::Event &e) override
Definition: MixingWorker.h:139
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
const int & bunchSpace() const
void setTof() override
Definition: MixingWorker.h:198
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
int getBunchSpace() const
unsigned int getPileupFileNr() const
std::string const labelCF_
Definition: MixingWorker.h:173
#define nullptr
std::string encode() const
Definition: InputTag.cc:166
bool checkSignal(const edm::Event &e) override
Definition: MixingWorker.h:120
void setSourceOffset(const unsigned int s) override
Definition: MixingWorker.h:153
const int & maxBunch() const
config
Definition: looper.py:287
edm::EventID getIdFirstPileup() const
void put(edm::Event &e) override
Definition: MixingWorker.h:157
void addPileups(const EventPrincipal &ep, ModuleCallingContext const *, unsigned int eventNr) override
Definition: MixingWorker.h:184
virtual void copyPCrossingFrame(const PCrossingFrame< T > *PCF)
Definition: MixingWorker.h:201
~MixingWorker() override
Definition: MixingWorker.h:106
MixingWorker(int minBunch, int maxBunch, int bunchSpace, std::string subdet, std::string label, std::string labelCF, int maxNbSources, InputTag &tag, InputTag &tagCF, std::vector< InputTag > const &tags)
Definition: MixingWorker.h:84
CrossingFrame< T > * crFrame_
Definition: MixingWorker.h:179
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:475
MixingWorker(int minBunch, int maxBunch, int bunchSpace, std::string subdet, std::string label, std::string labelCF, int maxNbSources, InputTag &tag, InputTag &tagCF)
Definition: MixingWorker.h:63
std::vector< InputTag > allTags_
Definition: MixingWorker.h:177
std::string getSubDet() const
T const * product() const
Definition: Handle.h:81
unsigned int getMaxNbSources() const
const T & get() const
Definition: EventSetup.h:59
void setBcrOffset() override
Definition: MixingWorker.h:152
std::pair< int, int > getBunchRange() const
std::vector< unsigned int > getPileupOffsetsBcr() const
std::string const & label() const
Definition: InputTag.h:36
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
PCrossingFrame< T > * secSourceCF_
Definition: MixingWorker.h:180
std::string const label_
Definition: MixingWorker.h:172
void reload(const edm::EventSetup &setup) override
Definition: MixingWorker.h:110
std::vector< const T * > getPileups() const
const int & minBunch() const
long double T
std::string const subdet_
Definition: MixingWorker.h:171
void createnewEDProduct() override
Definition: MixingWorker.h:135
std::string const & instance() const
Definition: InputTag.h:37
def move(src, dest)
Definition: eostools.py:510
unsigned int const maxNbSources_
Definition: MixingWorker.h:174
std::vector< std::vector< unsigned int > > getPileupOffsetsSource() const