CMS 3D CMS Logo

L1TExtCondProducer.cc
Go to the documentation of this file.
1 
10 // System include files
11 // User include files
23 
27 
30 
34 
35 #include <vector>
36 
37 using namespace std;
38 using namespace edm;
39 using namespace l1t;
40 
41 //
42 // Class declaration
43 //
44 
46 public:
47  explicit L1TExtCondProducer(const ParameterSet&);
48  ~L1TExtCondProducer() override;
49 
50  static void fillDescriptions(ConfigurationDescriptions& descriptions);
51 
52 private:
53  void produce(edm::Event&, const edm::EventSetup&) override;
54 
55  // ---------- Member data ---------------------------
56  // unsigned long long m_paramsCacheId; // Cache-ID from current parameters, to check if needs to be updated.
57  //std::shared_ptr<const CaloParams> m_dbpars; // Database parameters for the trigger, to be updated as needed.
58  //std::shared_ptr<const FirmwareVersion> m_fwv;
59  //std::shared_ptr<FirmwareVersion> m_fwv; //not const during testing.
60 
61  // BX parameters
62  int bxFirst_;
63  int bxLast_;
64 
68  bool setBptxOR_;
69 
70  unsigned long long m_l1GtMenuCacheID;
71  std::map<std::string, unsigned int> m_extBitMap;
72 
74 
79 };
80 
81 //
82 // Constructors and destructor
83 //
85  : bxFirst_(iConfig.getParameter<int>("bxFirst")),
86  bxLast_(iConfig.getParameter<int>("bxLast")),
87  setBptxAND_(iConfig.getParameter<bool>("setBptxAND")),
88  setBptxPlus_(iConfig.getParameter<bool>("setBptxPlus")),
89  setBptxMinus_(iConfig.getParameter<bool>("setBptxMinus")),
90  setBptxOR_(iConfig.getParameter<bool>("setBptxOR")),
91  tcdsInputTag_(iConfig.getParameter<edm::InputTag>("tcdsRecordLabel")),
94 
96 
97  tcdsRecordToken_ = consumes<TCDSRecord>(tcdsInputTag_);
98  // Note that the tcdsRecord input tag should be used as InputTag("unpackTcds","tcdsRecord") only for data
99  if (!(tcdsInputTag_ == edm::InputTag(""))) {
101  }
102 
103  // Register what you produce
104  produces<GlobalExtBlkBxCollection>();
105 
106  // Initialize parameters
107  m_l1GtMenuCacheID = 0ULL;
108 }
109 
111 
112 //
113 // Member functions
114 //
115 
116 // ------------ method called to produce the data ------------
118  LogDebug("L1TExtCondProducer") << "L1TExtCondProducer::produce function called...\n";
119 
120  // Get / update the trigger menu from the EventSetup
121  // local cache & check on cacheIdentifier
122  unsigned long long l1GtMenuCacheID = iSetup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
123 
124  if (m_l1GtMenuCacheID != l1GtMenuCacheID) {
125  edm::ESHandle<L1TUtmTriggerMenu> l1GtMenu = iSetup.getHandle(l1GtMenuToken_);
126  const L1TUtmTriggerMenu* utml1GtMenu = l1GtMenu.product();
127 
128  // Instantiate Parser
130 
131  std::map<std::string, unsigned int> extBitMap = gtParser.getExternalSignals(utml1GtMenu);
132 
133  m_l1GtMenuCacheID = l1GtMenuCacheID;
134  m_extBitMap = extBitMap;
135  }
136 
137  edm::Handle<TCDSRecord> tcdsRecordH;
138  iEvent.getByToken(tcdsRecordToken_, tcdsRecordH);
139  makeTriggerRulePrefireVetoBit_ = makeTriggerRulePrefireVetoBit_ && tcdsRecordH.isValid();
140 
141  bool TriggerRulePrefireVetoBit(false);
142  // The following list of checks on the tcdsRecord is relevant only for data;
143  // code taken from Nick Smith's EventFilter/L1TRawToDigi/plugins/TriggerRulePrefireVetoFilter.cc
144  if (iEvent.isRealData() && makeTriggerRulePrefireVetoBit_) {
145  const auto& tcdsRecord = *tcdsRecordH.product();
146 
147  uint64_t thisEvent = (tcdsRecord.getBXID() - 1) + tcdsRecord.getOrbitNr() * 3564ull;
148 
149  std::vector<uint64_t> eventHistory;
150  for (auto&& l1a : tcdsRecord.getFullL1aHistory()) {
151  eventHistory.push_back(thisEvent - ((l1a.getBXID() - 1) + l1a.getOrbitNr() * 3564ull));
152  }
153 
154  // It should be 16 according to TCDSRecord.h, we only care about the last 4
155  if (eventHistory.size() >= 4) {
156  // No more than 1 L1A in 3 BX
157  if (eventHistory[0] < 3ull) {
158  edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (1 in 3)";
159  }
160 
161  if (eventHistory[0] == 3ull)
162  TriggerRulePrefireVetoBit = true;
163 
164  // No more than 2 L1As in 25 BX
165  if (eventHistory[0] < 25ull and eventHistory[1] < 25ull) {
166  edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (2 in 25)";
167  }
168  if (eventHistory[0] < 25ull and eventHistory[1] == 25ull)
169  TriggerRulePrefireVetoBit = true;
170 
171  // No more than 3 L1As in 100 BX
172  if (eventHistory[0] < 100ull and eventHistory[1] < 100ull and eventHistory[2] <= 100ull) {
173  if (eventHistory[2] == 100ull)
174  TriggerRulePrefireVetoBit = true;
175  else
176  edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (3 in 100)";
177  }
178 
179  // No more than 4 L1As in 240 BX
180  if (eventHistory[0] < 240ull and eventHistory[1] < 240ull and eventHistory[2] < 240ull and
181  eventHistory[3] <= 240ull) {
182  if (eventHistory[3] == 240ull)
183  TriggerRulePrefireVetoBit = true;
184  else
185  edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (4 in 240)";
186  }
187  }
188  }
189  // Setup vectors
190  GlobalExtBlk extCond_bx;
191 
192  // Outputs
193  std::unique_ptr<GlobalExtBlkBxCollection> extCond(new GlobalExtBlkBxCollection(0, bxFirst_, bxLast_));
194 
195  bool foundBptxAND = (m_extBitMap.find("BPTX_plus_AND_minus.v0") != m_extBitMap.end());
196  bool foundBptxPlus = (m_extBitMap.find("BPTX_plus.v0") != m_extBitMap.end());
197  bool foundBptxMinus = (m_extBitMap.find("BPTX_minus.v0") != m_extBitMap.end());
198  bool foundBptxOR = (m_extBitMap.find("BPTX_plus_OR_minus.v0") != m_extBitMap.end());
199 
200  // Fill in some external conditions for testing
201  if (setBptxAND_ && foundBptxAND)
202  extCond_bx.setExternalDecision(m_extBitMap["BPTX_plus_AND_minus.v0"], true);
203  if (setBptxPlus_ && foundBptxPlus)
204  extCond_bx.setExternalDecision(m_extBitMap["BPTX_plus.v0"], true);
205  if (setBptxMinus_ && foundBptxMinus)
206  extCond_bx.setExternalDecision(m_extBitMap["BPTX_minus.v0"], true);
207  if (setBptxOR_ && foundBptxOR)
208  extCond_bx.setExternalDecision(m_extBitMap["BPTX_plus_OR_minus.v0"], true);
209 
210  // Check for updated Bptx names as well
211  foundBptxAND = (m_extBitMap.find("ZeroBias_BPTX_AND_VME") != m_extBitMap.end());
212  foundBptxPlus = (m_extBitMap.find("BPTX_B1_VME") != m_extBitMap.end());
213  foundBptxMinus = (m_extBitMap.find("BPTX_B2_VME") != m_extBitMap.end());
214  foundBptxOR = (m_extBitMap.find("BPTX_OR_VME") != m_extBitMap.end());
215 
216  // Fill in some external conditions for testing
217  if (setBptxAND_ && foundBptxAND)
218  extCond_bx.setExternalDecision(m_extBitMap["ZeroBias_BPTX_AND_VME"], true);
219  if (setBptxPlus_ && foundBptxPlus)
220  extCond_bx.setExternalDecision(m_extBitMap["BPTX_B1_VME"], true);
221  if (setBptxMinus_ && foundBptxMinus)
222  extCond_bx.setExternalDecision(m_extBitMap["BPTX_B2_VME"], true);
223  if (setBptxOR_ && foundBptxOR)
224  extCond_bx.setExternalDecision(m_extBitMap["BPTX_OR_VME"], true);
225 
226  // Set the bit for the TriggerRulePrefireVeto if true
227  if (TriggerRulePrefireVetoBit)
228  extCond_bx.setExternalDecision(m_triggerRulePrefireVetoBit, true);
229 
230  // Fill Externals
231  for (int iBx = bxFirst_; iBx <= bxLast_; iBx++) {
232  extCond->push_back(iBx, extCond_bx);
233  }
234 
235  iEvent.put(std::move(extCond));
236 }
237 
238 // ------------ Method fills 'descriptions' with the allowed parameters for the module ------------
240  // simGtExtFakeProd
242  desc.add<bool>("setBptxMinus", true);
243  desc.add<bool>("setBptxAND", true);
244  desc.add<int>("bxFirst", -2);
245  desc.add<bool>("setBptxOR", true);
246  desc.add<int>("bxLast", 2);
247  desc.add<bool>("setBptxPlus", true);
248  desc.add<edm::InputTag>("tcdsRecordLabel", edm::InputTag(""));
249  descriptions.add("simGtExtFakeProd", desc);
250 }
251 
252 // Define this as a plug-in
edm::ESGetToken< L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd > l1GtMenuToken_
BXVector< GlobalExtBlk > GlobalExtBlkBxCollection
Definition: GlobalExtBlk.h:29
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::EDGetTokenT< TCDSRecord > tcdsRecordToken_
static const unsigned int maxExternalConditions
Definition: GlobalExtBlk.h:43
T const * product() const
Definition: Handle.h:70
delete x;
Definition: CaloConfig.h:22
std::map< std::string, unsigned int > getExternalSignals(const L1TUtmTriggerMenu *utmMenu)
Log< level::Error, false > LogError
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
unsigned int m_triggerRulePrefireVetoBit
T get() const
Definition: EventSetup.h:79
edm::InputTag tcdsInputTag_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(ConfigurationDescriptions &descriptions)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
L1TExtCondProducer(const ParameterSet &)
void setExternalDecision(unsigned int bit, bool val)
Set decision bits.
Definition: GlobalExtBlk.cc:40
unsigned long long m_l1GtMenuCacheID
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
unsigned long long uint64_t
Definition: Time.h:13
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
std::map< std::string, unsigned int > m_extBitMap
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)