CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
HGCalSlinkEmulator Class Reference
Inheritance diagram for HGCalSlinkEmulator:
edm::stream::EDProducer<>

Public Member Functions

 HGCalSlinkEmulator (const edm::ParameterSet &)
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 

Private Member Functions

void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::unique_ptr< hgcal::econd::Emulatoremulator_
 
const unsigned int fed_id_
 
edm::EDPutTokenT< HGCalSlinkEmulatorInfofedEmulInfoToken_
 
const edm::EDPutTokenT< FEDRawDataCollectionfedRawToken_
 
hgcal::HGCalFrameGenerator frame_gen_
 
edm::Service< edm::RandomNumberGeneratorrng_
 
const bool store_emul_info_
 
const bool store_fed_header_trailer_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 31 of file HGCalSlinkEmulator.cc.

Constructor & Destructor Documentation

◆ HGCalSlinkEmulator()

HGCalSlinkEmulator::HGCalSlinkEmulator ( const edm::ParameterSet iConfig)
explicit

Definition at line 53 of file HGCalSlinkEmulator.cc.

References hgcal::HGCalFrameGenerator::econdParams(), emulator_, Exception, fedEmulInfoToken_, frame_gen_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), edm::Service< T >::isAvailable(), rng_, hgcal::HGCalFrameGenerator::setEmulator(), store_emul_info_, and AlCaHLTBitMon_QueryRunRegistry::string.

54  : fed_id_(iConfig.getParameter<unsigned int>("fedId")),
55  store_emul_info_(iConfig.getParameter<bool>("storeEmulatorInfo")),
56  store_fed_header_trailer_(iConfig.getParameter<bool>("fedHeaderTrailer")),
57  fedRawToken_(produces<FEDRawDataCollection>()),
58  frame_gen_(iConfig) {
59  // figure out which emulator is to be used
60  const auto& emul_type = iConfig.getParameter<std::string>("emulatorType");
61  if (frame_gen_.econdParams().empty())
62  throw cms::Exception("HGCalSlinkEmulator")
63  << "No ECON-D parameters were retrieved from the configuration. Please add at least one.";
64  const auto& econd_params = frame_gen_.econdParams().begin()->second;
65  if (emul_type == "trivial")
66  emulator_ = std::make_unique<hgcal::econd::TrivialEmulator>(econd_params);
67  else if (emul_type == "hgcmodule")
68  emulator_ = std::make_unique<hgcal::econd::HGCalModuleTreeReader>(
69  econd_params,
70  iConfig.getUntrackedParameter<std::string>("treeName"),
71  iConfig.getUntrackedParameter<std::vector<std::string>>("inputs"));
72  else
73  throw cms::Exception("HGCalSlinkEmulator") << "Invalid emulator type chosen: '" << emul_type << "'.";
74 
76 
77  // ensure the random number generator service is present in configuration
78  if (!rng_.isAvailable())
79  throw cms::Exception("HGCalSlinkEmulator") << "The HGCalSlinkEmulator module requires the "
80  "RandomNumberGeneratorService,\n"
81  "which appears to be absent. Please add that service to your "
82  "configuration\n"
83  "or remove the modules that require it.";
84 
85  if (store_emul_info_)
86  fedEmulInfoToken_ = produces<HGCalSlinkEmulatorInfo>();
87 }
const bool store_fed_header_trailer_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const std::map< unsigned int, econd::EmulatorParameters > & econdParams() const
List of ECON-D operational parameters for emulation.
void setEmulator(econd::Emulator &)
Set the emulation source for ECON-D frames.
const edm::EDPutTokenT< FEDRawDataCollection > fedRawToken_
T getUntrackedParameter(std::string const &, T const &) const
std::unique_ptr< hgcal::econd::Emulator > emulator_
edm::EDPutTokenT< HGCalSlinkEmulatorInfo > fedEmulInfoToken_
hgcal::HGCalFrameGenerator frame_gen_
edm::Service< edm::RandomNumberGenerator > rng_
bool isAvailable() const
Definition: Service.h:40
const unsigned int fed_id_

Member Function Documentation

◆ fillDescriptions()

void HGCalSlinkEmulator::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 150 of file HGCalSlinkEmulator.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, hgcal::HGCalFrameGenerator::description(), and or.

150  {
152  desc.ifValue(
153  edm::ParameterDescription<std::string>("emulatorType", "trivial", true),
154  // trivial emulator
155  "trivial" >> edm::EmptyGroupDescription() or
156  // test beam tree content
157  "hgcmodule" >> (edm::ParameterDescription<std::string>("treeName", "hgcroc_rawdata/eventdata", false) and
158  edm::ParameterDescription<std::vector<std::string>>("inputs", {}, false)))
159  ->setComment("emulator mode (trivial, or hgcmodule)");
160  desc.add<unsigned int>("fedId", 0)->setComment("FED number delivering the emulated frames");
161  desc.add<bool>("fedHeaderTrailer", false)->setComment("also add FED header/trailer info");
162  desc.add<bool>("storeEmulatorInfo", false)
163  ->setComment("also append a 'truth' auxiliary info to the output event content");
164  descriptions.add("hgcalEmulatedSlinkRawData", desc);
165 }
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
static edm::ParameterSetDescription description()
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ produce()

void HGCalSlinkEmulator::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 89 of file HGCalSlinkEmulator.cc.

References FEDHeader::bxID(), evf::compute_crc(), FEDTrailer::crc(), TauDecayModes::dec, FEDTrailer::evtStatus(), fed_id_, FEDRawDataCollection::FEDData(), fedEmulInfoToken_, fedRawToken_, FEDTrailer::fragmentLength(), frame_gen_, edm::RandomNumberGenerator::getEngine(), iEvent, hgcal::HGCalFrameGenerator::lastECONDEmulatedInput(), hgcal::HGCalFrameGenerator::lastSlinkEmulatedInfo(), FEDHeader::length, FEDTrailer::length, dqm-mbProfile::log, LogDebug, FEDHeader::lvl1ID(), eostools::move(), hgcal::HGCalFrameGenerator::produceSlinkEvent(), FEDRawData::resize(), rng_, FEDHeader::set(), FEDTrailer::set(), hgcal::HGCalFrameGenerator::setRandomEngine(), FEDHeader::sourceID(), store_emul_info_, and store_fed_header_trailer_.

89  {
91 
92  // build the S-link payload
93  auto slink_event = frame_gen_.produceSlinkEvent(fed_id_);
94  const auto slink_event_size = slink_event.size() * sizeof(slink_event.at(0));
95 
96  // compute the total S-link payload size
97  size_t total_event_size = slink_event_size;
99  total_event_size += FEDHeader::length + FEDTrailer::length;
100 
101  // fill the output FED raw data collection
102  FEDRawDataCollection raw_data;
103  auto& fed_data = raw_data.FEDData(fed_id_);
104  fed_data.resize(total_event_size);
105  auto* ptr = fed_data.data();
106 
108  const auto& last_event = frame_gen_.lastECONDEmulatedInput();
109  const auto event_id = std::get<0>(last_event.first), bx_id = std::get<1>(last_event.first);
110  int trg_type = 0;
111  // compose 2*32-bit FED header word
112  FEDHeader::set(ptr, trg_type, event_id, bx_id, fed_id_);
113  LogDebug("HGCalSlinkEmulator").log([&](auto& log) {
114  const FEDHeader hdr(ptr);
115  log << "FED header: lvl1ID=" << hdr.lvl1ID() << ", bxID=" << hdr.bxID() << ", source ID=" << hdr.sourceID()
116  << ".";
117  });
118  ptr += FEDHeader::length;
119  }
120 
121  // insert ECON-D payload
122  std::memcpy(ptr, slink_event.data(), slink_event_size);
123  ptr += slink_event_size;
124  LogDebug("HGCalSlinkEmulator") << "Wrote " << slink_event.size() << " 64-bit words = " << slink_event_size
125  << " 8-bit words.";
126 
128  // compose 2*32-bit FED trailer word
129  FEDTrailer::set(ptr,
130  slink_event.size() + 2,
131  evf::compute_crc(reinterpret_cast<uint8_t*>(slink_event.data()), slink_event_size),
132  0,
133  0);
134  LogDebug("HGCalSlinkEmulator").log([&](auto& log) {
135  const FEDTrailer trl(ptr);
136  log << "FED trailer: fragment length: " << trl.fragmentLength() << ", CRC=0x" << std::hex << trl.crc() << std::dec
137  << ", status: " << trl.evtStatus() << ".";
138  });
139  ptr += FEDTrailer::length;
140  }
141 
142  iEvent.emplace(fedRawToken_, std::move(raw_data));
143 
144  // store the emulation information if requested
145  if (store_emul_info_)
147 }
const bool store_fed_header_trailer_
static const uint32_t length
Definition: FEDTrailer.h:57
const econd::ECONDInput & lastECONDEmulatedInput() const
Retrieve the last ECON-D event emulated.
static const uint32_t length
Definition: FEDHeader.h:54
const edm::EDPutTokenT< FEDRawDataCollection > fedRawToken_
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
std::vector< uint64_t > produceSlinkEvent(unsigned int fed_id) const
Produce a S-link event from an emulated event.
int iEvent
Definition: GenABIO.cc:224
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:31
void resize(size_t newsize)
Definition: FEDRawData.cc:28
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
const HGCalSlinkEmulatorInfo & lastSlinkEmulatedInfo() const
Retrieve the metadata generated along with the last S-link emulated payload.
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
edm::EDPutTokenT< HGCalSlinkEmulatorInfo > fedEmulInfoToken_
hgcal::HGCalFrameGenerator frame_gen_
void setRandomEngine(CLHEP::HepRandomEngine &rng)
Set the random number generator engine.
edm::Service< edm::RandomNumberGenerator > rng_
static void set(unsigned char *header, uint8_t triggerType, uint32_t lvl1ID, uint16_t bxID, uint16_t sourceID, uint8_t version=0, bool moreHeaders=false)
Set all fields in the header.
Definition: FEDHeader.cc:25
const unsigned int fed_id_
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)

Member Data Documentation

◆ emulator_

std::unique_ptr<hgcal::econd::Emulator> HGCalSlinkEmulator::emulator_
private

Definition at line 46 of file HGCalSlinkEmulator.cc.

Referenced by HGCalSlinkEmulator().

◆ fed_id_

const unsigned int HGCalSlinkEmulator::fed_id_
private

Definition at line 40 of file HGCalSlinkEmulator.cc.

Referenced by produce().

◆ fedEmulInfoToken_

edm::EDPutTokenT<HGCalSlinkEmulatorInfo> HGCalSlinkEmulator::fedEmulInfoToken_
private

Definition at line 49 of file HGCalSlinkEmulator.cc.

Referenced by HGCalSlinkEmulator(), and produce().

◆ fedRawToken_

const edm::EDPutTokenT<FEDRawDataCollection> HGCalSlinkEmulator::fedRawToken_
private

Definition at line 45 of file HGCalSlinkEmulator.cc.

Referenced by produce().

◆ frame_gen_

hgcal::HGCalFrameGenerator HGCalSlinkEmulator::frame_gen_
private

Definition at line 50 of file HGCalSlinkEmulator.cc.

Referenced by HGCalSlinkEmulator(), and produce().

◆ rng_

edm::Service<edm::RandomNumberGenerator> HGCalSlinkEmulator::rng_
private

Definition at line 48 of file HGCalSlinkEmulator.cc.

Referenced by HGCalSlinkEmulator(), and produce().

◆ store_emul_info_

const bool HGCalSlinkEmulator::store_emul_info_
private

Definition at line 42 of file HGCalSlinkEmulator.cc.

Referenced by HGCalSlinkEmulator(), and produce().

◆ store_fed_header_trailer_

const bool HGCalSlinkEmulator::store_fed_header_trailer_
private

Definition at line 43 of file HGCalSlinkEmulator.cc.

Referenced by produce().