Skip to content

Commit

Permalink
LogError related to the tcdsRecord changed to throw an exception and …
Browse files Browse the repository at this point in the history
…avoid segmentation fault
  • Loading branch information
elfontan committed Jan 31, 2022
1 parent bb42398 commit 0f7b567
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions L1Trigger/L1TGlobal/plugins/L1TExtCondProducer.cc
Expand Up @@ -7,10 +7,8 @@
/// \author: D. Puigh OSU
///

// system include files

// user include files

// System include files
// User include files
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
Expand All @@ -30,19 +28,16 @@
#include <FWCore/ParameterSet/interface/ConfigurationDescriptions.h>
#include <FWCore/ParameterSet/interface/ParameterSetDescription.h>

//#include <vector>
#include "DataFormats/L1Trigger/interface/BXVector.h"

#include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"

#include "DataFormats/TCDS/interface/TCDSRecord.h"

using namespace std;
using namespace edm;
using namespace l1t;

//
// class declaration
// Class declaration
//

class L1TExtCondProducer : public stream::EDProducer<> {
Expand All @@ -55,7 +50,7 @@ class L1TExtCondProducer : public stream::EDProducer<> {
private:
void produce(edm::Event&, const edm::EventSetup&) override;

// ----------member data ---------------------------
// ---------- Member data ---------------------------
// unsigned long long m_paramsCacheId; // Cache-ID from current parameters, to check if needs to be updated.
//std::shared_ptr<const CaloParams> m_dbpars; // Database parameters for the trigger, to be updated as needed.
//std::shared_ptr<const FirmwareVersion> m_fwv;
Expand All @@ -82,7 +77,7 @@ class L1TExtCondProducer : public stream::EDProducer<> {
};

//
// constructors and destructor
// Constructors and destructor
//
L1TExtCondProducer::L1TExtCondProducer(const ParameterSet& iConfig)
: bxFirst_(iConfig.getParameter<int>("bxFirst")),
Expand All @@ -97,12 +92,13 @@ L1TExtCondProducer::L1TExtCondProducer(const ParameterSet& iConfig)

m_triggerRulePrefireVetoBit = GlobalExtBlk::maxExternalConditions - 1;

// Note that the tcdsRecord input tag should be used as InputTag("unpackTcds","tcdsRecord") only for data
if (!(tcdsInputTag_ == edm::InputTag(""))) {
tcdsRecordToken_ = consumes<TCDSRecord>(tcdsInputTag_);
makeTriggerRulePrefireVetoBit_ = true;
}

// register what you produce
// Register what you produce
produces<GlobalExtBlkBxCollection>();

// Initialize parameters
Expand All @@ -112,14 +108,14 @@ L1TExtCondProducer::L1TExtCondProducer(const ParameterSet& iConfig)
L1TExtCondProducer::~L1TExtCondProducer() {}

//
// member functions
// Member functions
//

// ------------ method called to produce the data ------------
void L1TExtCondProducer::produce(Event& iEvent, const EventSetup& iSetup) {
LogDebug("L1TExtCondProducer") << "L1TExtCondProducer::produce function called...\n";

// get / update the trigger menu from the EventSetup
// Get / update the trigger menu from the EventSetup
// local cache & check on cacheIdentifier
unsigned long long l1GtMenuCacheID = iSetup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();

Expand All @@ -137,9 +133,9 @@ void L1TExtCondProducer::produce(Event& iEvent, const EventSetup& iSetup) {
}

bool TriggerRulePrefireVetoBit(false);
// The following list of checks on the tcdsRecord is relevant only for data;
// code taken from Nick Smith's EventFilter/L1TRawToDigi/plugins/TriggerRulePrefireVetoFilter.cc
if (iEvent.isRealData() && makeTriggerRulePrefireVetoBit_) {
// code taken from Nick Smith's EventFilter/L1TRawToDigi/plugins/TriggerRulePrefireVetoFilter.cc

edm::Handle<TCDSRecord> tcdsRecordH;
iEvent.getByToken(tcdsRecordToken_, tcdsRecordH);
const auto& tcdsRecord = *tcdsRecordH.product();
Expand All @@ -151,9 +147,10 @@ void L1TExtCondProducer::produce(Event& iEvent, const EventSetup& iSetup) {
eventHistory.push_back(thisEvent - ((l1a.getBXID() - 1) + l1a.getOrbitNr() * 3564ull));
}

// should be 16 according to TCDSRecord.h, we only care about the last 4
// It should be 16 according to TCDSRecord.h, we only care about the last 4
if (eventHistory.size() < 4) {
edm::LogError("L1TExtCondProducer") << "Unexpectedly small L1A history from TCDSRecord";
throw cms::Exception("L1TExtCondProducer")
<< "Unexpectedly small L1A history from TCDSRecord: (size = " << eventHistory.size() << " < 4)";
}

// No more than 1 L1A in 3 BX
Expand Down Expand Up @@ -191,7 +188,7 @@ void L1TExtCondProducer::produce(Event& iEvent, const EventSetup& iSetup) {
// Setup vectors
GlobalExtBlk extCond_bx;

//outputs
// Outputs
std::unique_ptr<GlobalExtBlkBxCollection> extCond(new GlobalExtBlkBxCollection(0, bxFirst_, bxLast_));

bool foundBptxAND = (m_extBitMap.find("BPTX_plus_AND_minus.v0") != m_extBitMap.end());
Expand All @@ -209,7 +206,7 @@ void L1TExtCondProducer::produce(Event& iEvent, const EventSetup& iSetup) {
if (setBptxOR_ && foundBptxOR)
extCond_bx.setExternalDecision(m_extBitMap["BPTX_plus_OR_minus.v0"], true);

//check for updated Bptx names as well
// Check for updated Bptx names as well
foundBptxAND = (m_extBitMap.find("ZeroBias_BPTX_AND_VME") != m_extBitMap.end());
foundBptxPlus = (m_extBitMap.find("BPTX_B1_VME") != m_extBitMap.end());
foundBptxMinus = (m_extBitMap.find("BPTX_B2_VME") != m_extBitMap.end());
Expand All @@ -225,7 +222,7 @@ void L1TExtCondProducer::produce(Event& iEvent, const EventSetup& iSetup) {
if (setBptxOR_ && foundBptxOR)
extCond_bx.setExternalDecision(m_extBitMap["BPTX_OR_VME"], true);

// set the bit for the TriggerRulePrefireVeto if true
// Set the bit for the TriggerRulePrefireVeto if true
if (TriggerRulePrefireVetoBit)
extCond_bx.setExternalDecision(m_triggerRulePrefireVetoBit, true);

Expand All @@ -237,7 +234,7 @@ void L1TExtCondProducer::produce(Event& iEvent, const EventSetup& iSetup) {
iEvent.put(std::move(extCond));
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
// ------------ Method fills 'descriptions' with the allowed parameters for the module ------------
void L1TExtCondProducer::fillDescriptions(ConfigurationDescriptions& descriptions) {
// simGtExtFakeProd
edm::ParameterSetDescription desc;
Expand All @@ -251,5 +248,5 @@ void L1TExtCondProducer::fillDescriptions(ConfigurationDescriptions& description
descriptions.add("simGtExtFakeProd", desc);
}

//define this as a plug-in
// Define this as a plug-in
DEFINE_FWK_MODULE(L1TExtCondProducer);

0 comments on commit 0f7b567

Please sign in to comment.