CMS 3D CMS Logo

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