CMS 3D CMS Logo

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