CMS 3D CMS Logo

L1TExtCondProducer.cc
Go to the documentation of this file.
1 
10 // system include files
11 
12 // user include files
13 
24 
28 
31 
32 //#include <vector>
34 
36 
38 
39 using namespace std;
40 using namespace edm;
41 using namespace l1t;
42 
43 //
44 // class declaration
45 //
46 
48 public:
49  explicit L1TExtCondProducer(const ParameterSet&);
50  ~L1TExtCondProducer() override;
51 
52  static void fillDescriptions(ConfigurationDescriptions& descriptions);
53 
54 private:
55  void produce(edm::Event&, const edm::EventSetup&) override;
56 
57  // ----------member data ---------------------------
58  // unsigned long long m_paramsCacheId; // Cache-ID from current parameters, to check if needs to be updated.
59  //std::shared_ptr<const CaloParams> m_dbpars; // Database parameters for the trigger, to be updated as needed.
60  //std::shared_ptr<const FirmwareVersion> m_fwv;
61  //std::shared_ptr<FirmwareVersion> m_fwv; //not const during testing.
62 
63  // BX parameters
64  int bxFirst_;
65  int bxLast_;
66 
70  bool setBptxOR_;
71 
72  unsigned long long m_l1GtMenuCacheID;
73  std::map<std::string, unsigned int> m_extBitMap;
74 
76 
80 };
81 
82 //
83 // constructors and destructor
84 //
86  : bxFirst_(iConfig.getParameter<int>("bxFirst")),
87  bxLast_(iConfig.getParameter<int>("bxLast")),
88  setBptxAND_(iConfig.getParameter<bool>("setBptxAND")),
89  setBptxPlus_(iConfig.getParameter<bool>("setBptxPlus")),
90  setBptxMinus_(iConfig.getParameter<bool>("setBptxMinus")),
91  setBptxOR_(iConfig.getParameter<bool>("setBptxOR")),
92  tcdsInputTag_(iConfig.getParameter<edm::InputTag>("tcdsRecordLabel")) {
94 
98  edm::LogWarning("L1TExtCondProducer")
99  << "Default trigger rule prefire veto bit number too large. Resetting to " << m_triggerRulePrefireVetoBit;
100  }
101 
102  if (!(tcdsInputTag_ == edm::InputTag(""))) {
103  tcdsRecordToken_ = consumes<TCDSRecord>(tcdsInputTag_);
105  }
106 
107  // register what you produce
108  produces<GlobalExtBlkBxCollection>();
109 
110  // Initialize parameters
111  m_l1GtMenuCacheID = 0ULL;
112 }
113 
115 
116 //
117 // member functions
118 //
119 
120 // ------------ method called to produce the data ------------
122  LogDebug("L1TExtCondProducer") << "L1TExtCondProducer::produce function called...\n";
123 
124  // get / update the trigger menu from the EventSetup
125  // local cache & check on cacheIdentifier
126  unsigned long long l1GtMenuCacheID = iSetup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
127 
128  if (m_l1GtMenuCacheID != l1GtMenuCacheID) {
130  iSetup.get<L1TUtmTriggerMenuRcd>().get(l1GtMenu);
131  const L1TUtmTriggerMenu* utml1GtMenu = l1GtMenu.product();
132 
133  // Instantiate Parser
135 
136  std::map<std::string, unsigned int> extBitMap = gtParser.getExternalSignals(utml1GtMenu);
137 
138  m_l1GtMenuCacheID = l1GtMenuCacheID;
139  m_extBitMap = extBitMap;
140  }
141 
142  bool TriggerRulePrefireVetoBit(false);
143  if (makeTriggerRulePrefireVetoBit_) {
144  // code taken from Nick Smith's EventFilter/L1TRawToDigi/plugins/TriggerRulePrefireVetoFilter.cc
145 
146  edm::Handle<TCDSRecord> tcdsRecordH;
147  iEvent.getByToken(tcdsRecordToken_, tcdsRecordH);
148  const auto& tcdsRecord = *tcdsRecordH.product();
149 
150  uint64_t thisEvent = (tcdsRecord.getBXID() - 1) + tcdsRecord.getOrbitNr() * 3564ull;
151 
152  std::vector<uint64_t> eventHistory;
153  for (auto&& l1a : tcdsRecord.getFullL1aHistory()) {
154  eventHistory.push_back(thisEvent - ((l1a.getBXID() - 1) + l1a.getOrbitNr() * 3564ull));
155  }
156 
157  // should be 16 according to TCDSRecord.h, we only care about the last 4
158  if (eventHistory.size() < 4) {
159  edm::LogError("L1TExtCondProducer") << "Unexpectedly small L1A history from TCDSRecord";
160  }
161 
162  // No more than 1 L1A in 3 BX
163  if (eventHistory[0] < 3ull) {
164  edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (1 in 3)";
165  }
166 
167  if (eventHistory[0] == 3ull)
168  TriggerRulePrefireVetoBit = true;
169 
170  // No more than 2 L1As in 25 BX
171  if (eventHistory[0] < 25ull and eventHistory[1] < 25ull) {
172  edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (2 in 25)";
173  }
174  if (eventHistory[0] < 25ull and eventHistory[1] == 25ull)
175  TriggerRulePrefireVetoBit = true;
176 
177  // No more than 3 L1As in 100 BX
178  if (eventHistory[0] < 100ull and eventHistory[1] < 100ull and eventHistory[2] < 100ull) {
179  edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (3 in 100)";
180  }
181  if (eventHistory[0] < 100ull and eventHistory[1] < 100ull and eventHistory[2] == 100ull)
182  TriggerRulePrefireVetoBit = true;
183 
184  // No more than 4 L1As in 240 BX
185  if (eventHistory[0] < 240ull and eventHistory[1] < 240ull and eventHistory[2] < 240ull and
186  eventHistory[3] < 240ull) {
187  edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (4 in 240)";
188  }
189  if (eventHistory[0] < 240ull and eventHistory[1] < 240ull and eventHistory[2] < 240ull and
190  eventHistory[3] == 240ull)
191  TriggerRulePrefireVetoBit = true;
192  }
193 
194  // Setup vectors
195  GlobalExtBlk extCond_bx;
196 
197  //outputs
198  std::unique_ptr<GlobalExtBlkBxCollection> extCond(new GlobalExtBlkBxCollection(0, bxFirst_, bxLast_));
199 
200  bool foundBptxAND = (m_extBitMap.find("BPTX_plus_AND_minus.v0") != m_extBitMap.end());
201  bool foundBptxPlus = (m_extBitMap.find("BPTX_plus.v0") != m_extBitMap.end());
202  bool foundBptxMinus = (m_extBitMap.find("BPTX_minus.v0") != m_extBitMap.end());
203  bool foundBptxOR = (m_extBitMap.find("BPTX_plus_OR_minus.v0") != m_extBitMap.end());
204 
205  // Fill in some external conditions for testing
206  if (setBptxAND_ && foundBptxAND)
207  extCond_bx.setExternalDecision(m_extBitMap["BPTX_plus_AND_minus.v0"], true);
208  if (setBptxPlus_ && foundBptxPlus)
209  extCond_bx.setExternalDecision(m_extBitMap["BPTX_plus.v0"], true);
210  if (setBptxMinus_ && foundBptxMinus)
211  extCond_bx.setExternalDecision(m_extBitMap["BPTX_minus.v0"], true);
212  if (setBptxOR_ && foundBptxOR)
213  extCond_bx.setExternalDecision(m_extBitMap["BPTX_plus_OR_minus.v0"], true);
214 
215  //check for updated Bptx names as well
216  foundBptxAND = (m_extBitMap.find("ZeroBias_BPTX_AND_VME") != m_extBitMap.end());
217  foundBptxPlus = (m_extBitMap.find("BPTX_B1_VME") != m_extBitMap.end());
218  foundBptxMinus = (m_extBitMap.find("BPTX_B2_VME") != m_extBitMap.end());
219  foundBptxOR = (m_extBitMap.find("BPTX_OR_VME") != m_extBitMap.end());
220 
221  // Fill in some external conditions for testing
222  if (setBptxAND_ && foundBptxAND)
223  extCond_bx.setExternalDecision(m_extBitMap["ZeroBias_BPTX_AND_VME"], true);
224  if (setBptxPlus_ && foundBptxPlus)
225  extCond_bx.setExternalDecision(m_extBitMap["BPTX_B1_VME"], true);
226  if (setBptxMinus_ && foundBptxMinus)
227  extCond_bx.setExternalDecision(m_extBitMap["BPTX_B2_VME"], true);
228  if (setBptxOR_ && foundBptxOR)
229  extCond_bx.setExternalDecision(m_extBitMap["BPTX_OR_VME"], true);
230 
231  // set the bit for the TriggerRulePrefireVeto if true
232  if (TriggerRulePrefireVetoBit)
233  extCond_bx.setExternalDecision(m_triggerRulePrefireVetoBit, true);
234 
235  // Fill Externals
236  for (int iBx = bxFirst_; iBx <= bxLast_; iBx++) {
237  extCond->push_back(iBx, extCond_bx);
238  }
239 
240  iEvent.put(std::move(extCond));
241 }
242 
243 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
245  // simGtExtFakeProd
247  desc.add<bool>("setBptxMinus", true);
248  desc.add<bool>("setBptxAND", true);
249  desc.add<int>("bxFirst", -2);
250  desc.add<bool>("setBptxOR", true);
251  desc.add<int>("bxLast", 2);
252  desc.add<bool>("setBptxPlus", true);
253  desc.add<edm::InputTag>("tcdsRecordLabel", edm::InputTag(""));
254  descriptions.add("simGtExtFakeProd", desc);
255 }
256 
257 //define this as a plug-in
ConfigurationDescriptions.h
L1TExtCondProducer::L1TExtCondProducer
L1TExtCondProducer(const ParameterSet &)
Definition: L1TExtCondProducer.cc:85
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
electrons_cff.bool
bool
Definition: electrons_cff.py:372
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
l1t::TriggerMenuParser::getExternalSignals
std::map< std::string, unsigned int > getExternalSignals(const L1TUtmTriggerMenu *utmMenu)
Definition: TriggerMenuParser.cc:155
L1TUtmTriggerMenuRcd.h
MessageLogger.h
L1TExtCondProducer::tcdsInputTag_
edm::InputTag tcdsInputTag_
Definition: L1TExtCondProducer.cc:79
L1TExtCondProducer::m_l1GtMenuCacheID
unsigned long long m_l1GtMenuCacheID
Definition: L1TExtCondProducer.cc:72
BXVector.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
L1TExtCondProducer::setBptxAND_
bool setBptxAND_
Definition: L1TExtCondProducer.cc:67
ESHandle.h
L1TUtmTriggerMenuRcd
Definition: L1TUtmTriggerMenuRcd.h:11
edm::EDGetTokenT< TCDSRecord >
GlobalExtBlk::maxExternalConditions
const static unsigned int maxExternalConditions
Definition: GlobalExtBlk.h:43
edm
HLT enums.
Definition: AlignableModifier.h:19
GlobalExtBlk.h
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
L1TExtCondProducer::~L1TExtCondProducer
~L1TExtCondProducer() override
Definition: L1TExtCondProducer.cc:114
L1TExtCondProducer::bxFirst_
int bxFirst_
Definition: L1TExtCondProducer.cc:64
EDProducer.h
L1TExtCondProducer::tcdsRecordToken_
edm::EDGetTokenT< TCDSRecord > tcdsRecordToken_
Definition: L1TExtCondProducer.cc:78
L1TExtCondProducer::m_triggerRulePrefireVetoBit
unsigned int m_triggerRulePrefireVetoBit
Definition: L1TExtCondProducer.cc:75
GlobalExtBlkBxCollection
BXVector< GlobalExtBlk > GlobalExtBlkBxCollection
Definition: GlobalExtBlk.h:29
edm::Handle
Definition: AssociativeIterator.h:50
L1TUtmTriggerMenu
Definition: L1TUtmTriggerMenu.h:36
L1TExtCondProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: L1TExtCondProducer.cc:121
MakerMacros.h
L1TExtCondProducer::makeTriggerRulePrefireVetoBit_
bool makeTriggerRulePrefireVetoBit_
Definition: L1TExtCondProducer.cc:77
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TCDSRecord.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::ESHandle
Definition: DTSurvey.h:22
ParameterSetDescription.h
EDGetToken.h
L1TExtCondProducer::setBptxPlus_
bool setBptxPlus_
Definition: L1TExtCondProducer.cc:68
L1TExtCondProducer::fillDescriptions
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Definition: L1TExtCondProducer.cc:244
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
L1TExtCondProducer::bxLast_
int bxLast_
Definition: L1TExtCondProducer.cc:65
edm::LogWarning
Definition: MessageLogger.h:141
L1TUtmTriggerMenu.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
L1TExtCondProducer::setBptxMinus_
bool setBptxMinus_
Definition: L1TExtCondProducer.cc:69
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
Event.h
l1t
delete x;
Definition: CaloConfig.h:22
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
GlobalExtBlk
Definition: GlobalExtBlk.h:34
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
InputTag.h
L1TExtCondProducer::m_extBitMap
std::map< std::string, unsigned int > m_extBitMap
Definition: L1TExtCondProducer.cc:73
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
TriggerMenuParser.h
Frameworkfwd.h
EventSetup.h
L1TExtCondProducer::setBptxOR_
bool setBptxOR_
Definition: L1TExtCondProducer.cc:70
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
ParameterSet.h
l1t::TriggerMenuParser
Definition: TriggerMenuParser.h:57
L1TExtCondProducer
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
GlobalExtBlk::setExternalDecision
void setExternalDecision(unsigned int bit, bool val)
Set decision bits.
Definition: GlobalExtBlk.cc:40