diff --git a/EventFilter/L1TRawToDigi/interface/AMC13Spec.h b/EventFilter/L1TRawToDigi/interface/AMC13Spec.h new file mode 100644 index 0000000000000..23e5eb593bd94 --- /dev/null +++ b/EventFilter/L1TRawToDigi/interface/AMC13Spec.h @@ -0,0 +1,88 @@ +#ifndef AMC13_SPEC__h +#define AMC13_SPEC__h + +#include +#include +#include + +#include "AMCSpec.h" + +namespace edm { + class Event; +} + +namespace amc13 { + class Header { + public: + Header() : data_(0) {}; + Header(const uint64_t *data) : data_(data[0]) {}; + Header(unsigned int namc, unsigned int orbit); + + inline uint64_t raw() const { return data_; }; + bool check() const; + + inline unsigned int getFormatVersion() const { return (data_ >> uFOV_shift) & uFOV_mask; }; + inline unsigned int getNumberOfAMCs() const { return (data_ >> nAMC_shift) & nAMC_mask; }; + inline unsigned int getOrbitNumber() const { return (data_ >> OrN_shift) & OrN_mask; }; + + private: + static const unsigned int uFOV_shift = 60; + static const unsigned int uFOV_mask = 0xf; + static const unsigned int nAMC_shift = 52; + static const unsigned int nAMC_mask = 0xf; + static const unsigned int OrN_shift = 4; + static const unsigned int OrN_mask = 0xffffffff; + + static const unsigned int fov = 1; + static const unsigned int max_amc = 12; + + uint64_t data_; + }; + + class Trailer { + public: + Trailer(const uint64_t *data) : data_(data[0]) {}; + Trailer(unsigned int blk, unsigned int lv1, unsigned int bx); + + inline unsigned int getCRC() const { return (data_ >> CRC_shift) & CRC_mask; }; + inline unsigned int getBlock() const { return (data_ >> BlkNo_shift) & BlkNo_mask; }; + inline unsigned int getLV1ID() const { return (data_ >> LV1_shift) & LV1_mask; }; + inline unsigned int getBX() const { return (data_ >> BX_shift) & BX_mask; }; + + uint64_t raw() const { return data_; }; + bool check(unsigned int crc, unsigned int block, unsigned int lv1_id, unsigned int bx) const; + static void writeCRC(const uint64_t *start, uint64_t *end); + + private: + static const unsigned int CRC_shift = 32; + static const unsigned int CRC_mask = 0xffffffff; + static const unsigned int BlkNo_shift = 20; + static const unsigned int BlkNo_mask = 0xff; + static const unsigned int LV1_shift = 12; + static const unsigned int LV1_mask = 0xff; + static const unsigned int BX_shift = 0; + static const unsigned int BX_mask = 0xfff; + + uint64_t data_; + }; + + class Packet { + public: + Packet() {}; + + unsigned int blocks() const; + unsigned int size() const; + + void add(unsigned int amc_no, unsigned int board, unsigned int lv1id, unsigned int orbit, unsigned int bx, const std::vector& load); + bool parse(const uint64_t *start, const uint64_t *data, unsigned int size, unsigned int lv1, unsigned int bx, bool legacy_mc=false); + bool write(const edm::Event& ev, unsigned char * ptr, unsigned int skip, unsigned int size) const; + + inline std::vector payload() const { return payload_; }; + + private: + Header header_; + std::vector payload_; + }; +} + +#endif diff --git a/EventFilter/L1TRawToDigi/interface/AMCSpec.h b/EventFilter/L1TRawToDigi/interface/AMCSpec.h index e37e7ad1a3006..b2b3868123aff 100644 --- a/EventFilter/L1TRawToDigi/interface/AMCSpec.h +++ b/EventFilter/L1TRawToDigi/interface/AMCSpec.h @@ -5,20 +5,18 @@ #include #include -namespace edm { - class Event; -} - namespace amc { static const unsigned int split_block_size = 0x1000; - class Header { + // The AMC header within an AMC13 payload block. Should optimally only + // be used when packing/unpacking AMC payloads into AMC13 blocks. + class BlockHeader { public: - Header() : data_(0) {}; - Header(const uint64_t *data) : data_(data[0]) {}; + BlockHeader() : data_(0) {}; + BlockHeader(const uint64_t *data) : data_(data[0]) {}; // size is the total size of the AMC payload, not just of the // block - Header(unsigned int amc_no, unsigned int board_id, unsigned int size, unsigned int block=0); + BlockHeader(unsigned int amc_no, unsigned int board_id, unsigned int size, unsigned int block=0); operator uint64_t() const { return data_; }; @@ -33,6 +31,8 @@ namespace amc { inline unsigned int getMore() const { return (data_ >> More_bit_shift) & 1; }; inline unsigned int getSegmented() const { return (data_ >> Segmented_bit_shift) & 1; }; + inline unsigned int validCRC() const { return (data_ >> CRC_bit_shift) & 1; }; + private: static const unsigned int Size_shift = 32; static const unsigned int Size_mask = 0xffffff; @@ -54,96 +54,100 @@ namespace amc { uint64_t data_; }; - class Packet { - public: - Packet(const uint64_t* d) : header_(d) {}; - Packet(unsigned int amc, unsigned int board, const std::vector& load); - - void addPayload(const uint64_t*, unsigned int); - - std::vector block(unsigned int id) const; - std::unique_ptr data(); - Header header(unsigned int block=0) const { return header_; }; - - inline unsigned int blocks() const { return header_.getBlocks(); }; - inline unsigned int size() const { return header_.getSize(); }; - - private: - Header header_; - std::vector payload_; - }; -} - -namespace amc13 { + // The actual header attached to the AMC payload, also contained in the + // AMC payload of an AMC13 packet/block. class Header { public: - Header() : data_(0) {}; - Header(const uint64_t *data) : data_(data[0]) {}; - Header(unsigned int namc, unsigned int orbit); - - bool valid(); + Header() : data0_(0), data1_(0) {}; + Header(const uint64_t *data) : data0_(data[0]), data1_(data[1]) {}; + Header(unsigned int amc_no, unsigned int lv1_id, unsigned int bx_id, unsigned int size, + unsigned int or_n, unsigned int board_id, unsigned int user); - inline uint64_t raw() const { return data_; }; + inline unsigned int getAMCNumber() const { return (data0_ >> AmcNo_shift) & AmcNo_mask; }; + inline unsigned int getBoardID() const { return (data1_ >> BoardID_shift) & BoardID_mask; }; + inline unsigned int getLV1ID() const { return (data0_ >> LV1ID_shift) & LV1ID_mask; }; + inline unsigned int getBX() const { return (data0_ >> BX_shift) & BX_mask; }; + inline unsigned int getOrbitNumber() const { return (data1_ >> OrN_shift) & OrN_mask; }; + inline unsigned int getSize() const { return (data0_ >> Size_shift) & Size_mask; }; + inline unsigned int getUserData() const { return (data1_ >> User_shift) & User_mask; }; - inline unsigned int getFormatVersion() const { return (data_ >> uFOV_shift) & uFOV_mask; }; - inline unsigned int getNumberOfAMCs() const { return (data_ >> nAMC_shift) & nAMC_mask; }; - inline unsigned int getOrbitNumber() const { return (data_ >> OrN_shift) & OrN_mask; }; + std::vector raw() const { return {data0_, data1_}; }; private: - static const unsigned int uFOV_shift = 60; - static const unsigned int uFOV_mask = 0xf; - static const unsigned int nAMC_shift = 52; - static const unsigned int nAMC_mask = 0xf; - static const unsigned int OrN_shift = 4; - static const unsigned int OrN_mask = 0xffffffff; + static const unsigned int Size_shift = 0; + static const unsigned int Size_mask = 0xfffff; + static const unsigned int BX_shift = 20; + static const unsigned int BX_mask = 0xfff; + static const unsigned int LV1ID_shift = 32; + static const unsigned int LV1ID_mask = 0xffffff; + static const unsigned int AmcNo_shift = 56; + static const unsigned int AmcNo_mask = 0xf; - static const unsigned int fov = 1; - static const unsigned int max_amc = 12; + static const unsigned int BoardID_shift = 0; + static const unsigned int BoardID_mask = 0xffff; + static const unsigned int OrN_shift = 16; + static const unsigned int OrN_mask = 0xffff; + static const unsigned int User_shift = 32; + static const unsigned int User_mask = 0xffffffff; - uint64_t data_; + uint64_t data0_; + uint64_t data1_; }; class Trailer { public: + Trailer() : data_(0) {}; Trailer(const uint64_t *data) : data_(data[0]) {}; - Trailer(unsigned int crc, unsigned int blk, unsigned int lv1, unsigned int bx); + Trailer(unsigned int crc, unsigned int lv1_id, unsigned int size); inline unsigned int getCRC() const { return (data_ >> CRC_shift) & CRC_mask; }; - inline unsigned int getBlock() const { return (data_ >> BlkNo_shift) & BlkNo_mask; }; - inline unsigned int getLV1ID() const { return (data_ >> LV1_shift) & LV1_mask; }; - inline unsigned int getBX() const { return (data_ >> BX_shift) & BX_mask; }; + inline unsigned int getLV1ID() const { return (data_ >> LV1ID_shift) & LV1ID_mask; }; + inline unsigned int getSize() const { return (data_ >> Size_shift) & Size_mask; }; - uint64_t raw() const { return data_; }; + uint64_t raw() const { return data_; } + bool check(unsigned int crc, unsigned int lv1_id, unsigned int size) const; + + static void writeCRC(const uint64_t *start, uint64_t *end); private: + static const unsigned int Size_shift = 0; + static const unsigned int Size_mask = 0xfffff; + static const unsigned int LV1ID_shift = 24; + static const unsigned int LV1ID_mask = 0xff; static const unsigned int CRC_shift = 32; static const unsigned int CRC_mask = 0xffffffff; - static const unsigned int BlkNo_shift = 20; - static const unsigned int BlkNo_mask = 0xff; - static const unsigned int LV1_shift = 12; - static const unsigned int LV1_mask = 0xff; - static const unsigned int BX_shift = 0; - static const unsigned int BX_mask = 0xfff; uint64_t data_; }; class Packet { public: - Packet() {}; + Packet(const uint64_t* d) : block_header_(d) {}; + Packet(unsigned int amc, unsigned int board, unsigned int lv1id, unsigned int orbit, unsigned int bx, const std::vector& load); - unsigned int blocks() const; - unsigned int size() const; + // Add payload fragment from an AMC13 block to the AMC packet + void addPayload(const uint64_t*, unsigned int); + // To be called after the last payload addition. Removes header + // and trailer from the actual paylod. Also performs + // cross-checks for data consistency. + void finalize(unsigned int lv1, unsigned int bx, bool legacy_mc=false); - void add(unsigned int amc_no, unsigned int board, const std::vector& load); - bool parse(const uint64_t*, unsigned int); - bool write(const edm::Event& ev, unsigned char * ptr, unsigned int size) const; + std::vector block(unsigned int id) const; + std::unique_ptr data(); + BlockHeader blockHeader(unsigned int block=0) const { return block_header_; }; + Header header() const { return header_; }; + Trailer trailer() const { return trailer_; }; - inline std::vector payload() const { return payload_; }; + inline unsigned int blocks() const { return block_header_.getBlocks(); }; + // Returns the size of the payload _without_ the headers + inline unsigned int size() const { return payload_.size() - 3; }; private: + BlockHeader block_header_; Header header_; - std::vector payload_; + Trailer trailer_; + + std::vector payload_; }; } diff --git a/EventFilter/L1TRawToDigi/interface/Block.h b/EventFilter/L1TRawToDigi/interface/Block.h index bf23e9f9f9e21..63c89487573ab 100644 --- a/EventFilter/L1TRawToDigi/interface/Block.h +++ b/EventFilter/L1TRawToDigi/interface/Block.h @@ -11,16 +11,17 @@ namespace l1t { class BlockHeader { public: - BlockHeader(unsigned int id, unsigned int size, block_t type=MP7) : id_(id), size_(size), type_(type) {}; + BlockHeader(unsigned int id, unsigned int size, unsigned int capID=0, block_t type=MP7) : id_(id), size_(size), capID_(capID), type_(type) {}; // Create a MP7 block header: everything is contained in the raw uint32 - BlockHeader(const uint32_t *data) : id_((data[0] >> ID_shift) & ID_mask), size_((data[0] >> size_shift) & size_mask), type_(MP7) {}; + BlockHeader(const uint32_t *data) : id_((data[0] >> ID_shift) & ID_mask), size_((data[0] >> size_shift) & size_mask), capID_((data[0] >> capID_shift) & capID_mask), type_(MP7) {}; // Create a CTP7 block header: size is contained in the general CTP7 header - BlockHeader(const uint32_t *data, unsigned int size) : id_((data[0] >> CTP7_shift) & CTP7_mask), size_(size), type_(CTP7) {}; + BlockHeader(const uint32_t *data, unsigned int size) : id_((data[0] >> CTP7_shift) & CTP7_mask), size_(size), capID_(0), type_(CTP7) {}; bool operator<(const BlockHeader& o) const { return getID() < o.getID(); }; unsigned int getID() const { return id_; }; unsigned int getSize() const { return size_; }; + unsigned int getCapID() const { return capID_; }; block_t getType() const { return type_; }; uint32_t raw(block_t type=MP7) const; @@ -32,9 +33,12 @@ namespace l1t { static const unsigned int ID_mask = 0xff; static const unsigned int size_shift = 16; static const unsigned int size_mask = 0xff; + static const unsigned int capID_shift = 8; + static const unsigned int capID_mask = 0xff; unsigned int id_; unsigned int size_; + unsigned int capID_; block_t type_; }; @@ -42,8 +46,8 @@ namespace l1t { public: Block(const BlockHeader& h, const uint32_t * payload_start, const uint32_t * payload_end) : header_(h), payload_(payload_start, payload_end) {}; - Block(unsigned int id, const std::vector& payload, block_t type=MP7) : - header_(id, payload.size(), type), payload_(payload) {}; + Block(unsigned int id, const std::vector& payload, unsigned int capID=0, block_t type=MP7) : + header_(id, payload.size(), capID, type), payload_(payload) {}; bool operator<(const Block& o) const { return header() < o.header(); }; @@ -65,9 +69,10 @@ namespace l1t { class Payload { public: - Payload(const uint32_t * data, const uint32_t * end) : data_(data), end_(end), fw_(0) {}; + Payload(const uint32_t * data, const uint32_t * end) : data_(data), end_(end), algo_(0), infra_(0) {}; - unsigned getFirmwareId() const { return fw_; }; + virtual unsigned getAlgorithmFWVersion() const { return algo_; }; + virtual unsigned getInfrastructureFWVersion() const { return infra_; }; virtual unsigned getHeaderSize() const = 0; // Read header from data_ and advance data_ to point behind the // header. Called by getBlock(), which also checks that data_ != @@ -78,12 +83,13 @@ namespace l1t { const uint32_t * data_; const uint32_t * end_; - unsigned fw_; + unsigned algo_; + unsigned infra_; }; class MP7Payload : public Payload { public: - MP7Payload(const uint32_t * data, const uint32_t * end); + MP7Payload(const uint32_t * data, const uint32_t * end, bool legacy_mc=false); virtual unsigned getHeaderSize() const override { return 1; }; virtual BlockHeader getHeader() override; }; diff --git a/EventFilter/L1TRawToDigi/interface/PackingSetup.h b/EventFilter/L1TRawToDigi/interface/PackingSetup.h index 0c47b25ea6512..6fc0bcb9e7007 100644 --- a/EventFilter/L1TRawToDigi/interface/PackingSetup.h +++ b/EventFilter/L1TRawToDigi/interface/PackingSetup.h @@ -3,6 +3,8 @@ #include +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" + #include "EventFilter/L1TRawToDigi/interface/Packer.h" #include "EventFilter/L1TRawToDigi/interface/PackerTokens.h" @@ -13,7 +15,7 @@ namespace edm { class ConsumesCollector; class Event; class ParameterSet; - namespace one { + namespace stream { class EDProducerBase; } } @@ -28,14 +30,18 @@ namespace l1t { public: PackingSetup() {}; virtual std::unique_ptr registerConsumes(const edm::ParameterSet&, edm::ConsumesCollector&) = 0; - virtual void registerProducts(edm::one::EDProducerBase&) = 0; + virtual void registerProducts(edm::stream::EDProducerBase&) = 0; // Get a map of (amc #, board id) ↔ list of packing functions for a specific FED, FW combination - virtual PackerMap getPackers(int fed, int fw) = 0; + virtual PackerMap getPackers(int fed, unsigned int fw) = 0; // Get a map of Block IDs ↔ unpacker for a specific FED, board, AMC, FW combination - virtual UnpackerMap getUnpackers(int fed, int board , int amc, int fw) = 0; + virtual UnpackerMap getUnpackers(int fed, int board , int amc, unsigned int fw) = 0; virtual std::unique_ptr getCollections(edm::Event&) = 0; + + // Fill description with needed parameters for the setup, i.e., + // special input tags + virtual void fillDescription(edm::ParameterSetDescription&) = 0; }; typedef PackingSetup*(prov_fct)(); @@ -45,6 +51,7 @@ namespace l1t { public: static const PackingSetupFactory* get() { return &instance_; }; std::auto_ptr make(const std::string&) const; + void fillDescription(edm::ParameterSetDescription&) const; private: PackingSetupFactory() {}; static const PackingSetupFactory instance_; diff --git a/EventFilter/L1TRawToDigi/interface/Unpacker.h b/EventFilter/L1TRawToDigi/interface/Unpacker.h index 706b5f7ae5eda..44f39fc533004 100644 --- a/EventFilter/L1TRawToDigi/interface/Unpacker.h +++ b/EventFilter/L1TRawToDigi/interface/Unpacker.h @@ -8,6 +8,8 @@ namespace l1t { class UnpackerCollections; + void getBXRange(int nbx, int& first, int& last); + class Unpacker { public: virtual bool unpack(const Block& block, UnpackerCollections *coll) = 0; diff --git a/EventFilter/L1TRawToDigi/plugins/AMC13DumpToRaw.cc b/EventFilter/L1TRawToDigi/plugins/AMC13DumpToRaw.cc new file mode 100644 index 0000000000000..869466ee3ec14 --- /dev/null +++ b/EventFilter/L1TRawToDigi/plugins/AMC13DumpToRaw.cc @@ -0,0 +1,311 @@ +// -*- C++ -*- +// +// Package: EventFilter/L1TRawToDigi +// Class: AMC13DumpToRaw +// +/**\class AMC13DumpToRaw AMC13DumpToRaw.cc L1Trigger/L1TCalorimeter/plugins/AMC13DumpToRaw.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: James Brooke +// Created: Tue, 11 Mar 2014 14:55:45 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Utilities/interface/Exception.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "DataFormats/FEDRawData/interface/FEDRawData.h" +#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" +#include "DataFormats/FEDRawData/interface/FEDHeader.h" +#include "DataFormats/FEDRawData/interface/FEDTrailer.h" + +#include "FWCore/Utilities/interface/CRC16.h" + +#include +#include +#include +#include +#include +#include + +#include "EventFilter/L1TRawToDigi/interface/AMCSpec.h" + + +namespace l1t { + +class AMC13DumpToRaw : public edm::EDProducer { +public: + explicit AMC13DumpToRaw(const edm::ParameterSet&); + ~AMC13DumpToRaw(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + +private: + virtual void beginJob() override; + virtual void produce(edm::Event&, const edm::EventSetup&) override; + virtual void endJob() override; + + void readEvent(std::vector& load32); + + // void formatAMC(amc13::Packet& amc13, const std::vector& load32); + + // void formatRaw(edm::Event& iEvent, amc13::Packet& amc13, FEDRawData& fed_data); + + //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + + // ----------member data --------------------------- + std::ifstream file_; + std::string filename_; + + // DAQ params + int fedId_; + int iAmc_; + int boardId_; + int evType_; + int fwVer_; + int slinkHeaderSize_; // in 8-bit words + int slinkTrailerSize_; + +}; + +// +// constants, enums and typedefs +// + +// +// static data member definitions +// + +// +// constructors and destructor +// + AMC13DumpToRaw::AMC13DumpToRaw(const edm::ParameterSet& iConfig) : + filename_(iConfig.getUntrackedParameter("filename", "data.txt")), + fedId_(iConfig.getUntrackedParameter("fedId", 1)), + iAmc_(iConfig.getUntrackedParameter("iAmc", 1)), + boardId_(iConfig.getUntrackedParameter("boardId", 1)), + evType_(iConfig.getUntrackedParameter("eventType", 1)), + fwVer_(iConfig.getUntrackedParameter("fwVersion", 1)), + slinkHeaderSize_(iConfig.getUntrackedParameter("lenSlinkHeader", 8)), + slinkTrailerSize_(iConfig.getUntrackedParameter("lenSlinkTrailer", 8)) +{ + + produces(); + +} + + +AMC13DumpToRaw::~AMC13DumpToRaw() +{ + + // do anything here that needs to be done at desctruction time + // (e.g. close files, deallocate resources etc.) + +} + + +// +// member functions +// + +// ------------ method called for each event ------------ +void +AMC13DumpToRaw::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + + // create AMC 13 packet + // amc13::Packet amc13; + + std::vector load32; + + readEvent(load32); + + // formatAMC(amc13, load32); + + int size = load32.size() * 4; + + LogDebug("L1T") << "AMC13 size " << size << " bytes"; + + // prepare the raw data collection + std::auto_ptr raw_coll(new FEDRawDataCollection()); + FEDRawData& fed_data = raw_coll->FEDData(fedId_); + + fed_data.resize(size); + + // fill FEDRawData object + for (unsigned i=0; i>(8*j)) & 0xff; + } + } + + // formatRaw(iEvent, amc13, fed_data); + + LogDebug("L1T") << "Packing FED ID " << fedId_ << " size " << fed_data.size(); + + // put the collection in the event + iEvent.put(raw_coll); + +} + + +void +AMC13DumpToRaw::readEvent(std::vector& load32) { + + // read file + std::string line; + + // while not encountering dumb errors + while (getline(file_, line) && !line.empty() ) { + + std::istringstream iss(line); + unsigned long d; + iss >> std::hex >> d; + + load32.push_back( d ) ; + + } + +} + + +// void +// AMC13DumpToRaw::formatAMC(amc13::Packet& amc13, const std::vector& load32) { + +// // TODO this is an empty word to be replaced with a proper MP7 +// // header containing at least the firmware version + +// std::vector load64; +// for (unsigned int i = 0; i < load32.size(); i += 2) { +// uint64_t word = load32[i]; +// if (i + 1 < load32.size()) +// word |= static_cast(load32[i + 1]) << 32; +// load64.push_back(word); +// } + +// LogDebug("L1T") << "Creating AMC packet " << iAmc_; + +// amc13.add(iAmc_, boardId_, load64); + +// } + + + +// void +// AMC13DumpToRaw::formatRaw(edm::Event& iEvent, amc13::Packet& amc13, FEDRawData& fed_data) +// { + +// unsigned int size = slinkHeaderSize_ + slinkTrailerSize_ + amc13.size() * 8; +// fed_data.resize(size); +// unsigned char * payload = fed_data.data(); +// unsigned char * payload_start = payload; + +// auto bxId = iEvent.bunchCrossing(); +// auto evtId = iEvent.id().event(); + +// LogDebug("L1T") << "Creating FEDRawData ID " << fedId_ << ", size " << size; + +// FEDHeader header(payload); +// header.set(payload, evType_, evtId, bxId, fedId_); + +// payload += slinkHeaderSize_; + +// amc13.write(iEvent, payload, size - slinkHeaderSize_ - slinkTrailerSize_); + +// payload += amc13.size() * 8; + +// FEDTrailer trailer(payload); +// trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0); + +// } + + +// ------------ method called once each job just before starting event loop ------------ +void +AMC13DumpToRaw::beginJob() +{ + + // open VME file + file_.open(filename_.c_str(), std::ios::in); + if(!file_.good()) { edm::LogInfo("TextToDigi") << "Failed to open ASCII file " << filename_ << std::endl; } + + +} + + +// ------------ method called once each job just after ending the event loop ------------ +void +AMC13DumpToRaw::endJob() +{ + + file_.close(); + +} + +// ------------ method called when starting to processes a run ------------ +/* +void +AMC13DumpToRaw::beginRun(edm::Run const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method called when ending the processing of a run ------------ +/* +void +AMC13DumpToRaw::endRun(edm::Run const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method called when starting to processes a luminosity block ------------ +/* +vvoid +AMC13DumpToRaw::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method called when ending the processing of a luminosity block ------------ +/* +void +AMC13DumpToRaw::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +AMC13DumpToRaw::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + +} + +using namespace l1t; +//define this as a plug-in +DEFINE_FWK_MODULE(AMC13DumpToRaw); diff --git a/EventFilter/L1TRawToDigi/plugins/AMCDumpToRaw.cc b/EventFilter/L1TRawToDigi/plugins/AMCDumpToRaw.cc new file mode 100644 index 0000000000000..93ef5e51d7845 --- /dev/null +++ b/EventFilter/L1TRawToDigi/plugins/AMCDumpToRaw.cc @@ -0,0 +1,299 @@ +// -*- C++ -*- +// +// Package: EventFilter/L1TRawToDigi +// Class: AMCDumpToRaw +// +/**\class AMCDumpToRaw AMCDumpToRaw.cc L1Trigger/L1TCalorimeter/plugins/AMCDumpToRaw.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: James Brooke +// Created: Tue, 11 Mar 2014 14:55:45 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Utilities/interface/Exception.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "DataFormats/FEDRawData/interface/FEDRawData.h" +#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" +#include "DataFormats/FEDRawData/interface/FEDHeader.h" +#include "DataFormats/FEDRawData/interface/FEDTrailer.h" + +#include "FWCore/Utilities/interface/CRC16.h" + +#include +#include +#include +#include +#include +#include + +#include "EventFilter/L1TRawToDigi/interface/AMC13Spec.h" + + +namespace l1t { + +class AMCDumpToRaw : public edm::EDProducer { +public: + explicit AMCDumpToRaw(const edm::ParameterSet&); + ~AMCDumpToRaw(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + +private: + virtual void beginJob() override; + virtual void produce(edm::Event&, const edm::EventSetup&) override; + virtual void endJob() override; + + void readEvent(std::vector& load32); + + void formatAMC(amc13::Packet& amc13, const std::vector& load32); + + void formatRaw(edm::Event& iEvent, amc13::Packet& amc13, FEDRawData& fed_data); + + //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + + // ----------member data --------------------------- + std::ifstream file_; + std::string filename_; + + // DAQ params + int fedId_; + int iAmc_; + int boardId_; + int evType_; + int fwVer_; + int slinkHeaderSize_; // in 8-bit words + int slinkTrailerSize_; + +}; + +// +// constants, enums and typedefs +// + +// +// static data member definitions +// + +// +// constructors and destructor +// + AMCDumpToRaw::AMCDumpToRaw(const edm::ParameterSet& iConfig) : + filename_(iConfig.getUntrackedParameter("filename", "data.txt")), + fedId_(iConfig.getUntrackedParameter("fedId", 1)), + iAmc_(iConfig.getUntrackedParameter("iAmc", 1)), + boardId_(iConfig.getUntrackedParameter("boardId", 1)), + evType_(iConfig.getUntrackedParameter("eventType", 1)), + fwVer_(iConfig.getUntrackedParameter("fwVersion", 1)), + slinkHeaderSize_(iConfig.getUntrackedParameter("lenSlinkHeader", 8)), + slinkTrailerSize_(iConfig.getUntrackedParameter("lenSlinkTrailer", 8)) +{ + + produces(); + +} + + +AMCDumpToRaw::~AMCDumpToRaw() +{ + + // do anything here that needs to be done at desctruction time + // (e.g. close files, deallocate resources etc.) + +} + + +// +// member functions +// + +// ------------ method called for each event ------------ +void +AMCDumpToRaw::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + + // create AMC 13 packet + amc13::Packet amc13; + + std::vector load32; + + readEvent(load32); + + formatAMC(amc13, load32); + + LogDebug("L1T") << "AMC13 size " << amc13.size(); + + // prepare the raw data collection + std::auto_ptr raw_coll(new FEDRawDataCollection()); + FEDRawData& fed_data = raw_coll->FEDData(fedId_); + + formatRaw(iEvent, amc13, fed_data); + + LogDebug("L1T") << "Packing FED ID " << fedId_ << " size " << fed_data.size(); + + // put the collection in the event + iEvent.put(raw_coll); + +} + + +void +AMCDumpToRaw::readEvent(std::vector& load32) { + + // read file + std::string line; + + // while not encountering dumb errors + while (getline(file_, line) && !line.empty() ) { + + std::istringstream iss(line); + unsigned long d; + iss >> std::hex >> d; + + load32.push_back( d ) ; + + } + +} + + +void +AMCDumpToRaw::formatAMC(amc13::Packet& amc13, const std::vector& load32) { + + // TODO this is an empty word to be replaced with a proper MP7 + // header containing at least the firmware version + + std::vector load64; + for (unsigned int i = 0; i < load32.size(); i += 2) { + uint64_t word = load32[i]; + if (i + 1 < load32.size()) + word |= static_cast(load32[i + 1]) << 32; + load64.push_back(word); + } + + LogDebug("L1T") << "Creating AMC packet " << iAmc_; + + amc13.add(iAmc_, boardId_, 0, 0, 0, load64); + +} + + + +void +AMCDumpToRaw::formatRaw(edm::Event& iEvent, amc13::Packet& amc13, FEDRawData& fed_data) +{ + + unsigned int size = slinkHeaderSize_ + slinkTrailerSize_ + amc13.size() * 8; + fed_data.resize(size); + unsigned char * payload = fed_data.data(); + unsigned char * payload_start = payload; + + auto bxId = iEvent.bunchCrossing(); + auto evtId = iEvent.id().event(); + + LogDebug("L1T") << "Creating FEDRawData ID " << fedId_ << ", size " << size; + + FEDHeader header(payload); + header.set(payload, evType_, evtId, bxId, fedId_); + + amc13.write(iEvent, payload, slinkHeaderSize_, size - slinkHeaderSize_ - slinkTrailerSize_); + + payload += slinkHeaderSize_; + payload += amc13.size() * 8; + + FEDTrailer trailer(payload); + trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0); + +} + + +// ------------ method called once each job just before starting event loop ------------ +void +AMCDumpToRaw::beginJob() +{ + + // open VME file + file_.open(filename_.c_str(), std::ios::in); + if(!file_.good()) { edm::LogInfo("TextToDigi") << "Failed to open ASCII file " << filename_ << std::endl; } + + +} + + +// ------------ method called once each job just after ending the event loop ------------ +void +AMCDumpToRaw::endJob() +{ + + file_.close(); + +} + +// ------------ method called when starting to processes a run ------------ +/* +void +AMCDumpToRaw::beginRun(edm::Run const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method called when ending the processing of a run ------------ +/* +void +AMCDumpToRaw::endRun(edm::Run const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method called when starting to processes a luminosity block ------------ +/* +vvoid +AMCDumpToRaw::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method called when ending the processing of a luminosity block ------------ +/* +void +AMCDumpToRaw::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +AMCDumpToRaw::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + +} + +using namespace l1t; +//define this as a plug-in +DEFINE_FWK_MODULE(AMCDumpToRaw); diff --git a/EventFilter/L1TRawToDigi/plugins/L1TDigiToRaw.cc b/EventFilter/L1TRawToDigi/plugins/L1TDigiToRaw.cc index d3bb95a383f94..1309c77a9f8ae 100644 --- a/EventFilter/L1TRawToDigi/plugins/L1TDigiToRaw.cc +++ b/EventFilter/L1TRawToDigi/plugins/L1TDigiToRaw.cc @@ -30,7 +30,7 @@ #include "FWCore/Framework/interface/ConsumesCollector.h" #include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/one/EDProducer.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/Utilities/interface/CRC16.h" @@ -39,23 +39,21 @@ #include "FWCore/Utilities/interface/InputTag.h" -#include "EventFilter/L1TRawToDigi/interface/AMCSpec.h" +#include "EventFilter/L1TRawToDigi/interface/AMC13Spec.h" #include "EventFilter/L1TRawToDigi/interface/PackingSetup.h" namespace l1t { - class L1TDigiToRaw : public edm::one::EDProducer { + class L1TDigiToRaw : public edm::stream::EDProducer<> { public: explicit L1TDigiToRaw(const edm::ParameterSet&); ~L1TDigiToRaw(); static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - using edm::one::EDProducer::consumes; + using edm::stream::EDProducer<>::consumes; private: - virtual void beginJob() override; virtual void produce(edm::Event&, const edm::EventSetup&) override; - virtual void endJob() override; virtual void beginRun(edm::Run const&, edm::EventSetup const&) override {}; virtual void endRun(edm::Run const&, edm::EventSetup const&) override {}; @@ -110,6 +108,10 @@ namespace l1t { amc13::Packet amc13; + auto bxId = event.bunchCrossing(); + auto evtId = event.id().event(); + auto orbit = event.eventAuxiliary().orbitNumber(); + // Create all the AMC payloads to pack into the AMC13 for (const auto& item: setup_->getPackers(fedId_, fwId_)) { auto amc_no = item.first.first; @@ -128,9 +130,10 @@ namespace l1t { LogDebug("L1T") << "Concatenating blocks"; std::vector load32; - // TODO this is an empty word to be replaced with a proper MP7 - // header containing at least the firmware version + // TODO Infrastructure firmware version. Currently not used. + // Would change the way the payload has to be unpacked. load32.push_back(0); + load32.push_back(fwId_); for (const auto& block: block_load) { LogDebug("L1T") << "Adding block " << block.header().getID() << " with size " << block.payload().size(); auto load = block.payload(); @@ -152,14 +155,17 @@ namespace l1t { std::vector load64; for (unsigned int i = 0; i < load32.size(); i += 2) { uint64_t word = load32[i]; - if (i + 1 < load32.size()) + if (i + 1 < load32.size()) { word |= static_cast(load32[i + 1]) << 32; + } else { + word |= static_cast(0xffffffff) << 32; + } load64.push_back(word); } LogDebug("L1T") << "Creating AMC packet"; - amc13.add(amc_no, board, load64); + amc13.add(amc_no, board, evtId, orbit, bxId, load64); } std::auto_ptr raw_coll(new FEDRawDataCollection()); @@ -170,16 +176,12 @@ namespace l1t { unsigned char * payload = fed_data.data(); unsigned char * payload_start = payload; - auto bxId = event.bunchCrossing(); - auto evtId = event.id().event(); - FEDHeader header(payload); header.set(payload, evtType_, evtId, bxId, fedId_); - payload += slinkHeaderSize_; - - amc13.write(event, payload, size - slinkHeaderSize_ - slinkTrailerSize_); + amc13.write(event, payload, slinkHeaderSize_, size - slinkHeaderSize_ - slinkTrailerSize_); + payload += slinkHeaderSize_; payload += amc13.size() * 8; FEDTrailer trailer(payload); @@ -188,17 +190,6 @@ namespace l1t { event.put(raw_coll); } - // ------------ method called once each job just before starashtting event loop ------------ - void - L1TDigiToRaw::beginJob() - { - } - - // ------------ method called once each job just after ending the event loop ------------ - void - L1TDigiToRaw::endJob() { - } - // ------------ method called when starting to processes a run ------------ /* void @@ -234,11 +225,18 @@ namespace l1t { // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ void L1TDigiToRaw::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); + desc.add("FWId", -1); + desc.add("FedId"); + desc.addUntracked("eventType", 1); + desc.add("Setup"); + desc.addOptional("InputLabel"); + desc.addUntracked("lenSlinkHeader", 8); + desc.addUntracked("lenSlinkTrailer", 8); + + PackingSetupFactory::get()->fillDescription(desc); + + descriptions.add("l1tDigiToRaw", desc); } } diff --git a/EventFilter/L1TRawToDigi/plugins/L1TRawToDigi.cc b/EventFilter/L1TRawToDigi/plugins/L1TRawToDigi.cc index 903987df9c69e..5c1f51b9db7f0 100644 --- a/EventFilter/L1TRawToDigi/plugins/L1TRawToDigi.cc +++ b/EventFilter/L1TRawToDigi/plugins/L1TRawToDigi.cc @@ -17,13 +17,15 @@ // // system include files +#include +#include #include #define EDM_ML_DEBUG 1 // user include files #include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/one/EDProducer.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -34,12 +36,12 @@ #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" #include "DataFormats/FEDRawData/interface/FEDTrailer.h" -#include "EventFilter/L1TRawToDigi/interface/AMCSpec.h" +#include "EventFilter/L1TRawToDigi/interface/AMC13Spec.h" #include "EventFilter/L1TRawToDigi/interface/Block.h" #include "EventFilter/L1TRawToDigi/interface/PackingSetup.h" namespace l1t { - class L1TRawToDigi : public edm::one::EDProducer { + class L1TRawToDigi : public edm::stream::EDProducer<> { public: explicit L1TRawToDigi(const edm::ParameterSet&); ~L1TRawToDigi(); @@ -57,7 +59,8 @@ namespace l1t { // ----------member data --------------------------- edm::EDGetTokenT fedData_; std::vector fedIds_; - int fwId_; + unsigned int fwId_; + bool fwOverride_; std::auto_ptr prov_; @@ -70,6 +73,7 @@ namespace l1t { int amc13TrailerSize_; bool ctp7_mode_; + bool debug_; }; } @@ -80,18 +84,16 @@ std::ostream & operator<<(std::ostream& o, const l1t::BlockHeader& h) { namespace l1t { L1TRawToDigi::L1TRawToDigi(const edm::ParameterSet& config) : - fwId_(config.getUntrackedParameter("FWId", -1)), + fedIds_(config.getParameter>("FedIds")), + fwId_(-1), + fwOverride_(false), ctp7_mode_(config.getUntrackedParameter("CTP7", false)) { fedData_ = consumes(config.getParameter("InputLabel")); - if (config.exists("FedId") and config.exists("FedIds")) { - throw edm::Exception(edm::errors::Configuration, "PSet") - << "Cannot have FedId and FedIds as parameter at the same time"; - } else if (config.exists("FedId")) { - fedIds_ = {config.getParameter("FedId")}; - } else { - fedIds_ = config.getParameter>("FedIds"); + if (config.exists("FWId")) { + fwId_ = config.getParameter("FWId"); + fwOverride_ = true; } prov_ = PackingSetupFactory::get()->make(config.getParameter("Setup")); @@ -103,6 +105,8 @@ namespace l1t { amcTrailerSize_ = config.getUntrackedParameter("lenAMCTrailer", 0); amc13HeaderSize_ = config.getUntrackedParameter("lenAMC13Header", 8); amc13TrailerSize_ = config.getUntrackedParameter("lenAMC13Trailer", 8); + + debug_ = config.getUntrackedParameter("debug", false); } @@ -127,7 +131,7 @@ namespace l1t { event.getByToken(fedData_, feds); if (!feds.isValid()) { - LogError("L1T") << "Cannot unpack: no collection found"; + LogError("L1T") << "Cannot unpack: no FEDRawDataCollection found"; return; } @@ -139,8 +143,7 @@ namespace l1t { if ((int) l1tRcd.size() < slinkHeaderSize_ + slinkTrailerSize_ + amc13HeaderSize_ + amc13TrailerSize_ + amcHeaderSize_ + amcTrailerSize_) { LogError("L1T") << "Cannot unpack: empty/invalid L1T raw data (size = " << l1tRcd.size() << ") for ID " << fedId << ". Returning empty collections!"; - continue; - //return; + continue; } const unsigned char *data = l1tRcd.data(); @@ -169,10 +172,19 @@ namespace l1t { LogWarning("L1T") << "Did not find a SLink trailer!"; } + // FIXME Hard-coded firmware version for first 74x MC campaigns. + // Will account for differences in the AMC payload, MP7 payload, + // and unpacker setup. + bool legacy_mc = fwOverride_ && ((fwId_ >> 24) == 0xff); + amc13::Packet packet; if (!packet.parse( + (const uint64_t*) data, (const uint64_t*) (data + slinkHeaderSize_), - (l1tRcd.size() - slinkHeaderSize_ - slinkTrailerSize_) / 8)) { + (l1tRcd.size() - slinkHeaderSize_ - slinkTrailerSize_) / 8, + header.lvl1ID(), + header.bxID(), + legacy_mc)) { LogError("L1T") << "Could not extract AMC13 Packet."; return; @@ -181,6 +193,8 @@ namespace l1t { for (auto& amc: packet.payload()) { auto payload64 = amc.data(); const uint32_t * start = (const uint32_t*) payload64.get(); + // Want to have payload size in 32 bit words, but AMC measures + // it in 64 bit words → factor 2. const uint32_t * end = start + (amc.size() * 2); std::auto_ptr payload; @@ -188,36 +202,43 @@ namespace l1t { LogDebug("L1T") << "Using CTP7 mode"; payload.reset(new CTP7Payload(start, end)); } else { - LogDebug("L1T") << "Using MP7 mode"; - payload.reset(new MP7Payload(start, end)); + LogDebug("L1T") << "Using MP7 mode; legacy MC bit: " << legacy_mc; + payload.reset(new MP7Payload(start, end, legacy_mc)); } - unsigned fw = payload->getFirmwareId(); + unsigned fw = payload->getAlgorithmFWVersion(); // Let parameterset value override FW version - if (fwId_ > 0) + if (fwOverride_) fw = fwId_; - unsigned board = amc.header().getBoardID(); - unsigned amc_no = amc.header().getAMCNumber(); + unsigned board = amc.blockHeader().getBoardID(); + unsigned amc_no = amc.blockHeader().getAMCNumber(); auto unpackers = prov_->getUnpackers(fedId, board, amc_no, fw); // getBlock() returns a non-null auto_ptr on success std::auto_ptr block; while ((block = payload->getBlock()).get()) { - // skip empty filler blocks - if (block->header().getID() == 0 and block->header().getSize() == 0) - continue; + if (debug_) { + std::cout << ">>> block to unpack <<<" << std::endl + << "hdr: " << std::hex << std::setw(8) << std::setfill('0') << block->header().raw() << std::dec + << " (ID " << block->header().getID() << ", size " << block->header().getSize() + << ", CapID 0x" << std::hex << std::setw(2) << std::setfill('0') << block->header().getCapID() + << ")" << std::dec << std::endl; + for (const auto& word: block->payload()) { + std::cout << "data: " << std::hex << std::setw(8) << std::setfill('0') << word << std::dec << std::endl; + } + } auto unpacker = unpackers.find(block->header().getID()); block->amc(amc.header()); if (unpacker == unpackers.end()) { - LogDebug("L1T") << "Cannot find an unpacker for block ID " - << block->header().getID() << ", AMC # " << amc_no - << ", board ID " << board << ", FED ID " << fedId - << ", and FW ID " << fw << "!"; + LogDebug("L1T") << "Cannot find an unpacker for" + << "\n\tblock: ID " << block->header().getID() << ", size " << block->header().getSize() + << "\n\tAMC: # " << amc_no << ", board ID 0x" << std::hex << board << std::dec + << "\n\tFED ID " << fedId << ", and FW ID " << fw; // TODO Handle error } else if (!unpacker->second->unpack(*block, coll.get())) { LogDebug("L1T") << "Error unpacking data for block ID " @@ -234,11 +255,20 @@ namespace l1t { // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ void L1TRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); + desc.addOptional("FWId")->setComment("32 bits: if the first eight bits are 0xff, will read the 74x MC format"); + desc.addUntracked("CTP7", false); + desc.add("InputLabel"); + desc.add>("FedIds", {}); + desc.add("Setup", ""); + desc.addUntracked("lenSlinkHeader", 8); + desc.addUntracked("lenSlinkTrailer", 8); + desc.addUntracked("lenAMCHeader", 8); + desc.addUntracked("lenAMCTrailer", 0); + desc.addUntracked("lenAMC13Header", 8); + desc.addUntracked("lenAMC13Trailer", 8); + desc.addUntracked("debug", false)->setComment("turn on verbose output"); + descriptions.add("l1tRawToDigi", desc); } } diff --git a/EventFilter/L1TRawToDigi/plugins/L1TValidationEventFilter.cc b/EventFilter/L1TRawToDigi/plugins/L1TValidationEventFilter.cc new file mode 100644 index 0000000000000..48cb1f6463e64 --- /dev/null +++ b/EventFilter/L1TRawToDigi/plugins/L1TValidationEventFilter.cc @@ -0,0 +1,110 @@ +// -*- C++ -*- +// +// Package: L1TValidationEventFilter +// Class: L1TValidationEventFilter +// +/**\class L1TValidationEventFilter L1TValidationEventFilter.cc EventFilter/L1TRawToDigi/src/L1TValidationEventFilter.cc + +Description: +Implementation: + +*/ +// +// Original Author: Jim Brooke +// Created: +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" + +#include "FWCore/Framework/interface/EDFilter.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include +#include + +#include "DataFormats/FEDRawData/interface/FEDRawData.h" +#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" +#include "DataFormats/FEDRawData/interface/FEDNumbering.h" + + +// +// class declaration +// + +class L1TValidationEventFilter : public edm::EDFilter { +public: + explicit L1TValidationEventFilter(const edm::ParameterSet&); + virtual ~L1TValidationEventFilter(); + +private: + virtual void beginJob() override ; + virtual bool filter(edm::Event&, const edm::EventSetup&) override; + virtual void endJob() override ; + + // ----------member data --------------------------- + + int period_; + + // edm::EDGetTokenT token_; + +}; + + +// +// constructors and destructor +// +L1TValidationEventFilter::L1TValidationEventFilter(const edm::ParameterSet& iConfig) : + period_( iConfig.getUntrackedParameter("period", 107) ) +{ + //now do what ever initialization is needed + +} + + +L1TValidationEventFilter::~L1TValidationEventFilter() +{ + + // do anything here that needs to be done at desctruction time + // (e.g. close files, deallocate resources etc.) + +} + + +// +// member functions +// + +// ------------ method called on each new Event ------------ +bool +L1TValidationEventFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + + return ((iEvent.id().event() % period_)==0); + +} + +// ------------ method called once each job just before starting event loop ------------ +void +L1TValidationEventFilter::beginJob() +{ + +} + +// ------------ method called once each job just after ending the event loop ------------ +void +L1TValidationEventFilter::endJob() { + +} + +//define this as a plug-in +DEFINE_FWK_MODULE(L1TValidationEventFilter); diff --git a/EventFilter/L1TRawToDigi/plugins/MP7BufferDumpToRaw.cc b/EventFilter/L1TRawToDigi/plugins/MP7BufferDumpToRaw.cc index 5cb21c2031f88..7bbec011b53d3 100644 --- a/EventFilter/L1TRawToDigi/plugins/MP7BufferDumpToRaw.cc +++ b/EventFilter/L1TRawToDigi/plugins/MP7BufferDumpToRaw.cc @@ -46,7 +46,7 @@ #include "EventFilter/L1TRawToDigi/interface/MP7FileReader.h" #include "EventFilter/L1TRawToDigi/interface/MP7PacketReader.h" #include "EventFilter/L1TRawToDigi/interface/Block.h" -#include "EventFilter/L1TRawToDigi/interface/AMCSpec.h" +#include "EventFilter/L1TRawToDigi/interface/AMC13Spec.h" //#include "EventFilter/L1TRawToDigi/interface/PackingSetup.h" // // class declaration @@ -135,7 +135,7 @@ class MP7BufferDumpToRaw : public edm::EDProducer { rxFileReader_(iConfig.getUntrackedParameter("rxFile", "rx_summary.txt")), txFileReader_(iConfig.getUntrackedParameter("txFile", "tx_summary.txt")), rxPacketReader_(iConfig.getUntrackedParameter("rxFile", "rx_summary.txt"), 1, 0), - txPacketReader_(iConfig.getUntrackedParameter("txFile", "tx_summary.txt"), 1, 0), + txPacketReader_(iConfig.getUntrackedParameter("txFile", "tx_summary.txt"), iConfig.getUntrackedParameter("nHeaderFrames", 0), 0), packetisedData_(iConfig.getUntrackedParameter("packetisedData", true)), nFramesPerEvent_(iConfig.getUntrackedParameter("nFramesPerEvent", 6)), iBoard_(iConfig.getUntrackedParameter("boardOffset", 0)), @@ -424,7 +424,7 @@ MP7BufferDumpToRaw::formatAMC(amc13::Packet& amc13, const std::vector& bl LogDebug("L1T") << "Creating AMC packet " << iBoard; // LogDebug("L1T") << iBoard << ", " << boardId_.at(iBoard) << ", " << load64.size(); - amc13.add(iBoard, boardId_.at(iBoard), load64); + amc13.add(iBoard, boardId_.at(iBoard), 0, 0, 0, load64); } @@ -447,10 +447,9 @@ MP7BufferDumpToRaw::formatRaw(edm::Event& iEvent, amc13::Packet& amc13, FEDRawDa FEDHeader header(payload); header.set(payload, evType_, evtId, bxId, fedId_); - payload += slinkHeaderSize_; - - amc13.write(iEvent, payload, size - slinkHeaderSize_ - slinkTrailerSize_); + amc13.write(iEvent, payload, slinkHeaderSize_, size - slinkHeaderSize_ - slinkTrailerSize_); + payload += slinkHeaderSize_; payload += amc13.size() * 8; FEDTrailer trailer(payload); diff --git a/EventFilter/L1TRawToDigi/python/amc13DumpToRaw_cfi.py b/EventFilter/L1TRawToDigi/python/amc13DumpToRaw_cfi.py new file mode 100644 index 0000000000000..1195263c7c400 --- /dev/null +++ b/EventFilter/L1TRawToDigi/python/amc13DumpToRaw_cfi.py @@ -0,0 +1,9 @@ +import FWCore.ParameterSet.Config as cms + +amc13DumpToRaw = cms.EDProducer( + "AMC13DumpToRaw", + + filename = cms.untracked.string("data.txt"), + fedId = cms.untracked.int32(1352) + +) diff --git a/EventFilter/L1TRawToDigi/python/amcDumpToRaw_cfi.py b/EventFilter/L1TRawToDigi/python/amcDumpToRaw_cfi.py new file mode 100644 index 0000000000000..5ffd4b4adf1f0 --- /dev/null +++ b/EventFilter/L1TRawToDigi/python/amcDumpToRaw_cfi.py @@ -0,0 +1,15 @@ +import FWCore.ParameterSet.Config as cms + +amcDumpToRaw = cms.EDProducer( + "AMCDumpToRaw", + + filename = cms.untracked.string("data_nohdr.txt"), + fedId = cms.untracked.int32(1352), + iAmc = cms.untracked.int32(1), + boardId = cms.untracked.int32(4109), + eventType = cms.untracked.int32(238), + fwVersion = cms.untracked.int32(255), + lenSlinkHeader = cms.untracked.int32(8), + lenSlinkTrailer = cms.untracked.int32(8) + +) diff --git a/EventFilter/L1TRawToDigi/python/caloStage1Digis_cfi.py b/EventFilter/L1TRawToDigi/python/caloStage1Digis_cfi.py index f104d7b153375..48333a371d696 100644 --- a/EventFilter/L1TRawToDigi/python/caloStage1Digis_cfi.py +++ b/EventFilter/L1TRawToDigi/python/caloStage1Digis_cfi.py @@ -5,8 +5,9 @@ Setup = cms.string("stage1::CaloSetup"), #InputLabel = cms.InputTag("l1tDigiToRaw"), InputLabel = cms.InputTag("rawDataCollector"), - FedId = cms.int32(1352), - FWId = cms.untracked.int32(2), + FedIds = cms.vint32(1352), + # Uncomment the following for 74x legacy MC + # FWId = cms.uint32(0xff000000), lenSlinkHeader = cms.untracked.int32(8), lenSlinkTrailer = cms.untracked.int32(8), lenAMCHeader = cms.untracked.int32(8), diff --git a/EventFilter/L1TRawToDigi/python/caloStage1Raw_cfi.py b/EventFilter/L1TRawToDigi/python/caloStage1Raw_cfi.py new file mode 100644 index 0000000000000..4cbc2ba3990b2 --- /dev/null +++ b/EventFilter/L1TRawToDigi/python/caloStage1Raw_cfi.py @@ -0,0 +1,17 @@ +import FWCore.ParameterSet.Config as cms + +caloStage1Raw = cms.EDProducer( + "L1TDigiToRaw", + Setup = cms.string("stage1::CaloSetup"), + InputLabel = cms.InputTag("caloStage1Digis"), + TauInputLabel = cms.InputTag("caloStage1Digis", "rlxTaus"), + IsoTauInputLabel = cms.InputTag("caloStage1Digis", "isoTaus"), + HFBitCountsInputLabel = cms.InputTag("caloStage1Digis", "HFBitCounts"), + HFRingSumsInputLabel = cms.InputTag("caloStage1Digis", "HFRingSums"), + RegionInputLabel = cms.InputTag("caloStage1Digis", ""), + EmCandInputLabel = cms.InputTag("caloStage1Digis", ""), + FedId = cms.int32(1352), + FWId = cms.uint32(1), + lenSlinkHeader = cms.untracked.int32(8), + lenSlinkTrailer = cms.untracked.int32(8) +) diff --git a/EventFilter/L1TRawToDigi/python/stage1MP7BufferRaw_cfi.py b/EventFilter/L1TRawToDigi/python/stage1MP7BufferRaw_cfi.py index 9d086680bbd58..bdf8ba7bab722 100644 --- a/EventFilter/L1TRawToDigi/python/stage1MP7BufferRaw_cfi.py +++ b/EventFilter/L1TRawToDigi/python/stage1MP7BufferRaw_cfi.py @@ -10,24 +10,24 @@ # parameters for non-packetised data nFramesPerEvent = cms.untracked.int32(6), - nFramesOffset = cms.untracked.vint32(0,0), + nFramesOffset = cms.untracked.vint32(0,9), nFramesLatency = cms.untracked.vint32(0,0), # DAQ parameters - boardId = cms.untracked.int32( 0x100D, 0x100E ), + boardId = cms.untracked.vint32( 0x100D, 0x100E ), # jet ID, EG ID fedId = cms.untracked.int32(1352), eventType = cms.untracked.int32(238), fwVersion = cms.untracked.int32(255), lenSlinkHeader = cms.untracked.int32(8), # length in 8 bit words ! lenSlinkTrailer = cms.untracked.int32(8), - mux = cms.untracked.bool(True), + #mux = cms.untracked.bool(True), # these parameters specify the amount of data from each link to be # recorded in the FEDRawData object # if insufficient data is read from any channel to produce the # record, module will pad with zeros blocks = cms.untracked.VPSet( - cms.untracked.PSet( + cms.untracked.PSet( # region board setup rxBlockLength = cms.untracked.vint32(6,6,6,6, # quad 0 6,6,6,6, # quad 1 6,6,6,6, # quad 2 @@ -52,13 +52,13 @@ 0,0,0,0, # quad 6 0,0,0,0, # quad 7 0,0,0,0, # quad 8 - 0,0,0,0, # quad 9 - 0,0,0,0, # quad 10 - 0,0,0,0, # quad 11 - 0,0,0,0, # quad 12 - 6,6,0,0) # quad 13 + 0,0,2,2, # quad 9 + 2,2,2,2, # quad 10 + 2,2,2,2, # quad 11 + 2,2,2,2, # quad 12 + 2,2,0,0) # quad 13 ), - cms.untracked.PSet( + cms.untracked.PSet( # EG board setup rxBlockLength = cms.untracked.vint32(6,6,6,6, # quad 0 6,6,6,6, # quad 1 6,6,6,6, # quad 2 @@ -87,7 +87,7 @@ 0,0,0,0, # quad 10 0,0,0,0, # quad 11 0,0,0,0, # quad 12 - 6,6,0,0) # quad 13 + 0,0,0,0) # quad 13 ) ) ) diff --git a/EventFilter/L1TRawToDigi/python/stage2DemuxMP7BufferRaw_cfi.py b/EventFilter/L1TRawToDigi/python/stage2DemuxMP7BufferRaw_cfi.py index 61e19d47bb8f4..6ca09e1b24e63 100644 --- a/EventFilter/L1TRawToDigi/python/stage2DemuxMP7BufferRaw_cfi.py +++ b/EventFilter/L1TRawToDigi/python/stage2DemuxMP7BufferRaw_cfi.py @@ -1,3 +1,4 @@ + import FWCore.ParameterSet.Config as cms stage2DemuxRaw = cms.EDProducer( @@ -21,7 +22,7 @@ lenSlinkTrailer = cms.untracked.int32(8), # readout parameters - boardId = cms.untracked.vint32( 1 ), + boardId = cms.untracked.vint32( 0 ), mux = cms.untracked.bool(False), muxOffset = cms.untracked.int32(0), @@ -51,10 +52,10 @@ 0,0,0,0), # q17 68-71 txBlockLength = cms.untracked.vint32(0,0,0,0, # q0 0-3 - 0,0,0,0, # q1 4-7 - 0,0,0,0, # q2 8-11 - 6,0,0,0, # q3 12-15 - 0,0,6,0, # q4 16-19 + 0,0,6,6, # q1 4-7 + 0,0,6,0, # q2 8-11 + 0,0,0,0, # q3 12-15 + 0,0,0,0, # q4 16-19 0,0,0,0, # q5 20-23 0,0,0,0, # q6 24-27 0,0,0,0, # q7 28-31 diff --git a/EventFilter/L1TRawToDigi/python/stage2MP7BufferRaw_cfi.py b/EventFilter/L1TRawToDigi/python/stage2MP7BufferRaw_cfi.py index 7d3c6f0c55b28..a025e374dfe0c 100644 --- a/EventFilter/L1TRawToDigi/python/stage2MP7BufferRaw_cfi.py +++ b/EventFilter/L1TRawToDigi/python/stage2MP7BufferRaw_cfi.py @@ -2,27 +2,27 @@ mpblocks = cms.untracked.PSet( - rxBlockLength = cms.untracked.vint32(41,41,41,41, # q0 0-3 - 41,41,41,41, # q1 4-7 - 41,41,41,41, # q2 8-11 - 41,41,41,41, # q3 12-15 - 41,41,41,41, # q4 16-19 - 41,41,41,41, # q5 20-23 - 41,41,41,41, # q6 24-27 - 41,41,41,41, # q7 28-31 - 41,41,41,41, # q8 32-35 - 41,41,41,41, # q9 36-39 - 41,41,41,41, # q10 40-43 - 41,41,41,41, # q11 44-47 - 41,41,41,41, # q12 48-51 - 41,41,41,41, # q13 52-55 - 41,41,41,41, # q14 56-59 - 41,41,41,41, # q15 60-63 - 41,41,41,41, # q16 64-67 - 41,41,41,41), # q17 68-71 + rxBlockLength = cms.untracked.vint32(40,40,40,40, # q0 0-3 + 40,40,40,40, # q1 4-7 + 40,40,40,40, # q2 8-11 + 40,40,40,40, # q3 12-15 + 40,40,40,40, # q4 16-19 + 40,40,40,40, # q5 20-23 + 40,40,40,40, # q6 24-27 + 40,40,40,40, # q7 28-31 + 40,40,40,40, # q8 32-35 + 40,40,40,40, # q9 36-39 + 40,40,40,40, # q10 40-43 + 40,40,40,40, # q11 44-47 + 40,40,40,40, # q12 48-51 + 40,40,40,40, # q13 52-55 + 40,40,40,40, # q14 56-59 + 40,40,40,40, # q15 60-63 + 40,40,40,40, # q16 64-67 + 40,40,40,40), # q17 68-71 - txBlockLength = cms.untracked.vint32(39,39,39,39, # q0 0-3 - 39,39,0,0, # q1 4-7 + txBlockLength = cms.untracked.vint32(40,40,40,40, # q0 0-3 + 40,40,0,0, # q1 4-7 0,0,0,0, # q2 8-11 0,0,0,0, # q3 12-15 0,0,0,0, # q4 16-19 @@ -50,9 +50,9 @@ packetisedData = cms.untracked.bool(True), # parameters for non-packetised data - nFramesPerEvent = cms.untracked.int32(41), - nFramesOffset = cms.untracked.vuint32(0,0,0,0,0,0,0,0,0,0,0,0), - nFramesLatency = cms.untracked.vuint32(0,0,0,0,0,0,0,0,0,0,0,0), + nFramesPerEvent = cms.untracked.int32(40), + nFramesOffset = cms.untracked.vuint32(0,0,0,0,0,0,0,0,0,0,0), + nFramesLatency = cms.untracked.vuint32(0,0,0,0,0,0,0,0,0,0,0), # DAQ parameters fedId = cms.untracked.int32(1360), @@ -62,7 +62,7 @@ lenSlinkTrailer = cms.untracked.int32(8), # HW parameters - boardId = cms.untracked.vint32( 1,2,3,4,5,6,7,8,9,10,11,12 ), + boardId = cms.untracked.vint32( 0,1,2,3,4,5,6,7,8,9,10 ), mux = cms.untracked.bool(True), muxOffset = cms.untracked.int32(0), @@ -82,7 +82,6 @@ mpblocks, mpblocks, mpblocks, - mpblocks, ) ) diff --git a/EventFilter/L1TRawToDigi/python/validationEventFilter_cfi.py b/EventFilter/L1TRawToDigi/python/validationEventFilter_cfi.py new file mode 100644 index 0000000000000..b0a75875b5b52 --- /dev/null +++ b/EventFilter/L1TRawToDigi/python/validationEventFilter_cfi.py @@ -0,0 +1,7 @@ + +import FWCore.ParameterSet.Config as cms + +validationEventFilter = cms.EDFilter( + "L1TValidationEventFilter", + period = cms.untracked.int32(107) +) diff --git a/EventFilter/L1TRawToDigi/src/AMC13Spec.cc b/EventFilter/L1TRawToDigi/src/AMC13Spec.cc new file mode 100644 index 0000000000000..4c626b2173d3f --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/AMC13Spec.cc @@ -0,0 +1,268 @@ +#include +#include + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/CRC32Calculator.h" + +#include "EventFilter/L1TRawToDigi/interface/AMC13Spec.h" + +#define EDM_ML_DEBUG 1 + +namespace amc13 { + Header::Header(unsigned int namc, unsigned int orbit) + { + data_ = + (static_cast(namc & nAMC_mask) << nAMC_shift) | + (static_cast(orbit & OrN_mask) << OrN_shift) | + (static_cast(fov & uFOV_mask) << uFOV_shift); + } + + bool + Header::check() const + { + return (getNumberOfAMCs() <= max_amc) && (getFormatVersion() == fov); + } + + Trailer::Trailer(unsigned int blk, unsigned int lv1, unsigned int bx) + { + data_ = + (static_cast(blk & BlkNo_mask) << BlkNo_shift) | + (static_cast(lv1 & LV1_mask) << LV1_shift) | + (static_cast(bx & BX_mask) << BX_shift); + } + + bool + Trailer::check(unsigned int crc, unsigned int block, unsigned int lv1_id, unsigned int bx) const + { + if ((crc != 0 && crc != getCRC()) || block != getBlock() || (lv1_id & LV1_mask) != getLV1ID() || (bx & BX_mask) != getBX()) { + edm::LogWarning("L1T") + << "Found AMC13 trailer with:" + << "\n\tBX " << getBX() << ", LV1 ID " << getLV1ID() << ", block # " << getBlock() + << ", CRC " << std::hex << std::setw(8) << std::setfill('0') << getCRC() << std::dec + << "\nBut expected:" + << "\n\tBX " << (bx & BX_mask) << ", LV1 ID " << (lv1_id & LV1_mask) << ", block # " << block + << ", CRC " << std::hex << std::setw(8) << std::setfill('0') << crc; + return false; + } + return true; + } + + void + Trailer::writeCRC(const uint64_t *start, uint64_t *end) + { + std::string dstring(reinterpret_cast(start), reinterpret_cast(end) + 4); + auto crc = cms::CRC32Calculator(dstring).checksum(); + + *end = ((*end) & ~(uint64_t(CRC_mask) << CRC_shift)) | (static_cast(crc & CRC_mask) << CRC_shift); + } + + void + Packet::add(unsigned int amc_no, unsigned int board, unsigned int lv1id, unsigned int orbit, unsigned int bx, const std::vector& load) + { + edm::LogInfo("AMC") << "Adding board " << board << " with payload size " << load.size() + << " as payload #" << amc_no; + // Start by indexing with 1 + payload_.push_back(amc::Packet(amc_no, board, lv1id, orbit, bx, load)); + } + + bool + Packet::parse(const uint64_t *start, const uint64_t *data, unsigned int size, unsigned int lv1, unsigned int bx, bool legacy_mc) + { + // Need at least a header and trailer + // TODO check if this can be removed + if (size < 2) { + edm::LogError("AMC") << "AMC13 packet size too small"; + return false; + } + + std::map amc_index; + + header_ = Header(data++); + + if (!header_.check()) { + edm::LogError("AMC") + << "Invalid header for AMC13 packet: " + << "format version " << header_.getFormatVersion() + << ", " << header_.getNumberOfAMCs() + << " AMC packets"; + return false; + } + + if (size < 2 + header_.getNumberOfAMCs()) + return false; + + // Initial filling of AMC payloads. First, get the headers. The + // first payload follows afterwards. + for (unsigned int i = 0; i < header_.getNumberOfAMCs(); ++i) { + payload_.push_back(amc::Packet(data++)); + amc_index[payload_.back().blockHeader().getAMCNumber()] = i; + } + + unsigned int tot_size = 0; // total payload size + unsigned int tot_nblocks = 0; // total blocks of payload + unsigned int maxblocks = 0; // counting the # of amc13 header/trailers (1 ea per block) + + bool check_crc = false; + for (const auto& amc: payload_) { + tot_size += amc.blockHeader().getSize(); + tot_nblocks += amc.blockHeader().getBlocks(); + maxblocks = std::max(maxblocks, amc.blockHeader().getBlocks()); + + if (amc.blockHeader().validCRC()) + check_crc = true; + } + + unsigned int words = tot_size + // payload size + tot_nblocks + // AMC headers + 2 * maxblocks; // AMC13 headers + + if (size < words) { + edm::LogError("L1T") + << "Encountered AMC 13 packet with " + << size << " words, " + << "but expected " + << words << " words: " + << tot_size << " payload words, " + << tot_nblocks << " AMC header words, and 2 AMC 13 header words."; + return false; + } + + // Read in the first AMC block and append the payload to the + // corresponding AMC packet. + for (auto& amc: payload_) { + amc.addPayload(data, amc.blockHeader().getBlockSize()); + data += amc.blockHeader().getBlockSize(); + } + + Trailer t(data++); + + int crc = 0; + if (check_crc) { + std::string check(reinterpret_cast(start), reinterpret_cast(data) - 4); + crc = cms::CRC32Calculator(check).checksum(); + + LogDebug("L1T") << "checking data checksum of " << std::hex << crc << std::dec; + } + + t.check(crc, 0, lv1, bx); + + // Read in remaining AMC blocks + for (unsigned int b = 1; b < maxblocks; ++b) { + Header block_h(data++); + std::vector headers; + + for (unsigned int i = 0; i < block_h.getNumberOfAMCs(); ++i) + headers.push_back(amc::BlockHeader(data++)); + + check_crc = false; + for (const auto& amc: headers) { + payload_[amc_index[amc.getAMCNumber()]].addPayload(data, amc.getBlockSize()); + data += amc.getBlockSize(); + + if (amc.validCRC()) + check_crc = true; + } + + t = Trailer(data++); + + if (check_crc) { + std::string check(reinterpret_cast(start), reinterpret_cast(data) - 4); + crc = cms::CRC32Calculator(check).checksum(); + + LogDebug("L1T") << "checking data checksum of " << std::hex << crc << std::dec; + } else { + crc = 0; + } + + t.check(crc, b, lv1, bx); + } + + for (auto& amc: payload_) { + amc.finalize(lv1, bx, legacy_mc); + } + + return true; + } + + unsigned int + Packet::blocks() const + { + unsigned int maxblocks = 0; + + for (const auto& amc: payload_) + maxblocks = std::max(maxblocks, amc.blocks()); + + return maxblocks; + } + + unsigned int + Packet::size() const + { + unsigned int words = 0; + unsigned int blocks = 0; + unsigned int maxblocks = 0; + + for (const auto& amc: payload_) { + words += amc.header().getSize(); + blocks += amc.blocks(); + maxblocks = std::max(maxblocks, amc.blocks()); + } + + // Size is total amount of words + # of blocks for AMC headers + # of + // maxblocks for AMC13 block header, trailer + return words + blocks + maxblocks * 2; + } + + bool + Packet::write(const edm::Event& ev, unsigned char * ptr, unsigned int skip, unsigned int size) const + { + if (size < this->size() * 8) + return false; + + if (size % 8 != 0) + return false; + + uint64_t * data = reinterpret_cast(ptr + skip); + + for (unsigned int b = 0; b < blocks(); ++b) { + // uint64_t * block_start = data; + + std::vector block_headers; + std::vector block_load; + for (const auto& amc: payload_) { + edm::LogInfo("AMC") + << "Considering block " << b + << " for payload " << amc.blockHeader().getBoardID() + << " with size " << amc.size() + << " and " << amc.blocks() << " blocks"; + if (amc.blocks() < b + 1) + continue; + + block_headers.push_back(amc.blockHeader(b)); + auto words = amc.block(b); + block_load.insert(block_load.end(), words.begin(), words.end()); + } + + if (b == 0) { + amc13::Header h(block_headers.size(), ev.orbitNumber()); + edm::LogInfo("AMC") + << "Writing header for AMC13 packet: " + << "format version " << h.getFormatVersion() + << ", " << h.getNumberOfAMCs() + << " AMC packets, orbit " << h.getOrbitNumber(); + } + + *(data++) = amc13::Header(block_headers.size(), ev.orbitNumber()).raw(); + + block_headers.insert(block_headers.end(), block_load.begin(), block_load.end()); + for (const auto& word: block_headers) + *(data++) = word; + + *data = Trailer(b, ev.id().event(), ev.bunchCrossing()).raw(); + Trailer::writeCRC(reinterpret_cast(ptr), data); + } + + return true; + } +} diff --git a/EventFilter/L1TRawToDigi/src/AMCSpec.cc b/EventFilter/L1TRawToDigi/src/AMCSpec.cc index 4dfdf88e0ca6c..c9671e200dd35 100644 --- a/EventFilter/L1TRawToDigi/src/AMCSpec.cc +++ b/EventFilter/L1TRawToDigi/src/AMCSpec.cc @@ -1,12 +1,14 @@ -#include "FWCore/Framework/interface/Event.h" +#include + #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/CRC32Calculator.h" + #include "EventFilter/L1TRawToDigi/interface/AMCSpec.h" #define EDM_ML_DEBUG 1 namespace amc { - Header::Header(unsigned int amc_no, unsigned int board_id, unsigned int size, unsigned int block) + BlockHeader::BlockHeader(unsigned int amc_no, unsigned int board_id, unsigned int size, unsigned int block) { // Determine size unsigned int max_block_no = 0; @@ -49,7 +51,7 @@ namespace amc { } unsigned int - Header::getBlocks() const + BlockHeader::getBlocks() const { // The first block of a segmented event has a size of 1023, all // following have a max size of 4096. Segmentation only happens @@ -61,7 +63,7 @@ namespace amc { } unsigned int - Header::getBlockSize() const + BlockHeader::getBlockSize() const { // More and not Segmented means the first of multiple blocks. For // these, getSize() returns the total size of the AMC packet, not the @@ -71,269 +73,115 @@ namespace amc { return getSize(); } - Packet::Packet(unsigned int amc, unsigned int board, const std::vector& load) : - header_(amc, board, load.size()), - payload_(load) + Header::Header(unsigned int amc_no, unsigned int lv1_id, unsigned int bx_id, unsigned int size, + unsigned int or_n, unsigned int board_id, unsigned int user) : + data0_( + (uint64_t(amc_no & AmcNo_mask) << AmcNo_shift) | + (uint64_t(lv1_id & LV1ID_mask) << LV1ID_shift) | + (uint64_t(bx_id & BX_mask) << BX_shift) | + (uint64_t(size & Size_mask) << Size_shift) + ), + data1_( + (uint64_t(or_n & OrN_mask) << OrN_shift) | + (uint64_t(board_id & BoardID_mask) << BoardID_shift) | + (uint64_t(user & User_mask) << User_shift) + ) { } - void - Packet::addPayload(const uint64_t * data, unsigned int size) + Trailer::Trailer(unsigned int crc, unsigned int lv1_id, unsigned int size) : + data_( + (uint64_t(crc & CRC_mask) << CRC_shift) | + (uint64_t(lv1_id & LV1ID_mask) << LV1ID_shift) | + (uint64_t(size & Size_mask) << Size_shift) + ) { - payload_.insert(payload_.end(), data, data + size); } - std::vector - Packet::block(unsigned int id) const + bool + Trailer::check(unsigned int crc, unsigned int lv1_id, unsigned int size) const { - if (id == 0 and id == header_.getBlocks() - 1) { - return payload_; - } else if (id == header_.getBlocks() - 1) { - return std::vector(payload_.begin() + id * split_block_size, payload_.end()); - } else { - return std::vector(payload_.begin() + id * split_block_size, payload_.begin() + (id + 1) * split_block_size); + if (crc != getCRC() || size != getSize() || (lv1_id & LV1ID_mask) != getLV1ID()) { + edm::LogWarning("L1T") + << "Found AMC trailer with:" + << "\n\tLV1 ID " << getLV1ID() << ", size " << getSize() + << ", CRC " << std::hex << std::setw(8) << std::setfill('0') << getCRC() << std::dec + << "\nBut expected:" + << "\n\tLV1 ID " << (lv1_id & LV1ID_mask) << ", size " << size + << ", CRC " << std::hex << std::setw(8) << std::setfill('0') << crc; + return false; } + return true; } - std::unique_ptr - Packet::data() - { - std::unique_ptr res(new uint64_t[payload_.size()]); - for (unsigned int i = 0; i < payload_.size(); ++i) - res.get()[i] = payload_[i]; - return res; - } -} - -namespace amc13 { - Header::Header(unsigned int namc, unsigned int orbit) + void + Trailer::writeCRC(const uint64_t *start, uint64_t *end) { - data_ = - (static_cast(namc & nAMC_mask) << nAMC_shift) | - (static_cast(orbit & OrN_mask) << OrN_shift) | - (static_cast(fov & uFOV_mask) << uFOV_shift); - } + std::string dstring(reinterpret_cast(start), reinterpret_cast(end) + 4); + auto crc = cms::CRC32Calculator(dstring).checksum(); - bool - Header::valid() - { - return (getNumberOfAMCs() <= max_amc) && (getFormatVersion() == fov); + *end = ((*end) & ~(uint64_t(CRC_mask) << CRC_shift)) | (static_cast(crc & CRC_mask) << CRC_shift); } - Trailer::Trailer(unsigned int crc, unsigned int blk, unsigned int lv1, unsigned int bx) + Packet::Packet(unsigned int amc, unsigned int board, unsigned int lv1id, unsigned int orbit, unsigned int bx, const std::vector& load) : + block_header_(amc, board, load.size() + 3), // add 3 words for header (2) and trailer (1) + header_(amc, lv1id, bx, load.size() + 3, orbit, board, 0), + trailer_(0, lv1id, load.size() + 3) { - data_ = - (static_cast(crc & CRC_mask) << CRC_shift) | - (static_cast(blk & BlkNo_mask) << BlkNo_shift) | - (static_cast(lv1 & LV1_mask) << LV1_shift) | - (static_cast(bx & BX_mask) << BX_shift); + auto hdata = header_.raw(); + payload_.reserve(load.size() + 3); + payload_.insert(payload_.end(), hdata.begin(), hdata.end()); + payload_.insert(payload_.end(), load.begin(), load.end()); + payload_.insert(payload_.end(), trailer_.raw()); + + auto ptr = payload_.data(); + Trailer::writeCRC(ptr, ptr + payload_.size() - 1); } void - Packet::add(unsigned int amc_no, unsigned int board, const std::vector& load) + Packet::addPayload(const uint64_t * data, unsigned int size) { - edm::LogInfo("AMC") << "Adding board " << board << " with payload size " << load.size() - << " as payload #" << amc_no; - // Start by indexing with 1 - payload_.push_back(amc::Packet(amc_no, board, load)); + payload_.insert(payload_.end(), data, data + size); } - bool - Packet::parse(const uint64_t *data, unsigned int size) + void + Packet::finalize(unsigned int lv1, unsigned int bx, bool legacy_mc) { - // Need at least a header and trailer - // TODO check if this can be removed - if (size < 2) { - edm::LogError("AMC") << "AMC13 packet size too small"; - return false; - } - - auto block_start = data; - header_ = Header(data++); - - if (!header_.valid()) { - edm::LogError("AMC") - << "Invalid header for AMC13 packet: " - << "format version " << header_.getFormatVersion() - << ", " << header_.getNumberOfAMCs() - << " AMC packets, orbit " << header_.getOrbitNumber(); - return false; - } - - if (size < 2 + header_.getNumberOfAMCs()) - return false; - - // Initial filling of AMC payloads. First, get the headers. The - // first payload follows afterwards. - for (unsigned int i = 0; i < header_.getNumberOfAMCs(); ++i) { - payload_.push_back(amc::Packet(data++)); - } - - unsigned int tot_size = 0; // total payload size - unsigned int tot_nblocks = 0; // total blocks of payload - unsigned int maxblocks = 0; // counting the # of amc13 header/trailers (1 ea per block) - - for (const auto& amc: payload_) { - tot_size += amc.header().getSize(); - tot_nblocks += amc.header().getBlocks(); - maxblocks = std::max(maxblocks, amc.header().getBlocks()); - } - - unsigned int words = tot_size + // payload size - tot_nblocks + // AMC headers - 2 * maxblocks; // AMC13 headers - - if (size < words) { - edm::LogError("L1T") - << "Encountered AMC 13 packet with " - << size << " words, " - << "but expected " - << words << " words: " - << tot_size << " payload words, " - << tot_nblocks << " AMC header words, and 2 AMC 13 header words."; - return false; - } - - // Read in the first AMC block and append the payload to the - // corresponding AMC packet. - for (auto& amc: payload_) { - amc.addPayload(data, amc.header().getBlockSize()); - data += amc.header().getBlockSize(); - } - auto block_end = data; - - Trailer t(data++); - - std::string check(reinterpret_cast(block_start), reinterpret_cast(block_end)); - cms::CRC32Calculator crc(check); - - if (crc.checksum() != t.getCRC()) { - edm::LogWarning("L1T") << "Mismatch in checksums for block 0"; - } - - if (t.getBlock() != 0 ) { - edm::LogWarning("L1T") - << "Block trailer mismatch: " - << "expected block 0, but trailer is for block " - << t.getBlock(); - } - - // Read in remaining AMC blocks - for (unsigned int b = 1; b < maxblocks; ++b) { - block_start = data; - - Header block_h(data++); - std::vector headers; - - for (unsigned int i = 0; i < block_h.getNumberOfAMCs(); ++i) - headers.push_back(amc::Header(data++)); - - for (const auto& amc: headers) { - payload_[amc.getAMCNumber() - 1].addPayload(data, amc.getBlockSize()); - data += amc.getBlockSize(); - } - - block_end = data; + if (legacy_mc) { + header_ = Header(block_header_.getAMCNumber(), lv1, bx, block_header_.getSize(), 0, block_header_.getBoardID(), 0); - t = Trailer(data++); - - check = std::string(reinterpret_cast(block_start), reinterpret_cast(block_end)); - crc = cms::CRC32Calculator(check); + payload_.insert(payload_.begin(), {0, 0}); + payload_.insert(payload_.end(), {0}); + } else { + header_ = Header(payload_.data()); + trailer_ = Trailer(&payload_.back()); - if (crc.checksum() != t.getCRC()) { - edm::LogWarning("L1T") << "Mismatch in checksums for block " << b; - } + std::string check(reinterpret_cast(payload_.data()), payload_.size() * 8 - 4); + auto crc = cms::CRC32Calculator(check).checksum(); - if (t.getBlock() != 0 ) { - edm::LogWarning("L1T") - << "Block trailer mismatch: " - << "expected block " << b - << ", but trailer is for block " << t.getBlock(); - } + trailer_.check(crc, lv1, header_.getSize()); } - - return true; - } - - unsigned int - Packet::blocks() const - { - unsigned int maxblocks = 0; - - for (const auto& amc: payload_) - maxblocks = std::max(maxblocks, amc.blocks()); - - return maxblocks; } - unsigned int - Packet::size() const + std::vector + Packet::block(unsigned int id) const { - unsigned int words = 0; - unsigned int blocks = 0; - unsigned int maxblocks = 0; - - for (const auto& amc: payload_) { - words += amc.size(); - blocks += amc.blocks(); - maxblocks = std::max(maxblocks, amc.blocks()); + if (id == 0 and id == block_header_.getBlocks() - 1) { + return payload_; + } else if (id == block_header_.getBlocks() - 1) { + return std::vector(payload_.begin() + id * split_block_size, payload_.end()); + } else { + return std::vector(payload_.begin() + id * split_block_size, payload_.begin() + (id + 1) * split_block_size); } - - // Size is total amount of words + # of blocks for AMC headers + # of - // maxblocks for AMC13 block header, trailer - return words + blocks + maxblocks * 2; } - bool - Packet::write(const edm::Event& ev, unsigned char * ptr, unsigned int size) const + std::unique_ptr + Packet::data() { - if (size < this->size() * 8) - return false; - - if (size % 8 != 0) - return false; - - uint64_t * data = reinterpret_cast(ptr); - - for (unsigned int b = 0; b < blocks(); ++b) { - uint64_t * block_start = data; - - std::vector block_headers; - std::vector block_load; - for (const auto& amc: payload_) { - edm::LogInfo("AMC") - << "Considering block " << b - << " for payload " << amc.header().getBoardID() - << " with size " << amc.size() - << " and " << amc.blocks() << " blocks"; - if (amc.blocks() < b + 1) - continue; - - block_headers.push_back(amc.header(b)); - auto words = amc.block(b); - block_load.insert(block_load.end(), words.begin(), words.end()); - } - - if (b == 0) { - amc13::Header h(block_headers.size(), ev.orbitNumber()); - edm::LogInfo("AMC") - << "Writing header for AMC13 packet: " - << "format version " << h.getFormatVersion() - << ", " << h.getNumberOfAMCs() - << " AMC packets, orbit " << h.getOrbitNumber(); - } - - *(data++) = amc13::Header(block_headers.size(), ev.orbitNumber()).raw(); - - block_headers.insert(block_headers.end(), block_load.begin(), block_load.end()); - for (const auto& word: block_headers) - *(data++) = word; - - std::string dstring(reinterpret_cast(block_start), reinterpret_cast(data)); - cms::CRC32Calculator crc(dstring); - *(data++) = Trailer(crc.checksum(), b, ev.id().event(), ev.bunchCrossing()).raw(); - } - - return true; + // Remove 3 words: 2 for the header, 1 for the trailer + std::unique_ptr res(new uint64_t[payload_.size() - 3]); + for (unsigned int i = 0; i < payload_.size() - 3; ++i) + res.get()[i] = payload_[i + 2]; + return res; } } diff --git a/EventFilter/L1TRawToDigi/src/Block.cc b/EventFilter/L1TRawToDigi/src/Block.cc index 8ffa7f152f75b..a6c77f3c02d6a 100644 --- a/EventFilter/L1TRawToDigi/src/Block.cc +++ b/EventFilter/L1TRawToDigi/src/Block.cc @@ -1,3 +1,5 @@ +#include + #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "EventFilter/L1TRawToDigi/interface/Block.h" @@ -10,7 +12,7 @@ namespace l1t { { if (type_ == MP7) { LogTrace("L1T") << "Writing MP7 link header"; - return ((id_ & ID_mask) << ID_shift) | ((size_ & size_mask) << size_shift); + return ((id_ & ID_mask) << ID_shift) | ((size_ & size_mask) << size_shift) | ((capID_ & capID_mask) << capID_shift); } LogTrace("L1T") << "Writing CTP7 link header"; return ((id_ & CTP7_mask) << CTP7_shift); @@ -19,8 +21,17 @@ namespace l1t { std::auto_ptr Payload::getBlock() { - if (end_ - data_ < getHeaderSize()) + if (end_ - data_ < getHeaderSize()) { + LogDebug("L1T") << "Reached end of payload"; return std::auto_ptr(); + } + + if (data_[0] == 0xffffffff) { + LogDebug("L1T") << "Skipping padding word"; + ++data_; + return getBlock(); + } + auto header = getHeader(); if (end_ - data_ < header.getSize()) { @@ -37,18 +48,25 @@ namespace l1t { return res; } - MP7Payload::MP7Payload(const uint32_t * data, const uint32_t * end) : Payload(data, end) + MP7Payload::MP7Payload(const uint32_t * data, const uint32_t * end, bool legacy_mc) : Payload(data, end) { - // FIXME extract firmware version here - // skip header for now - LogTrace("L1T") << "Skipping " << std::hex << *data_; - ++data_; + // For legacy MC (74 first MC campaigns) skip one empty word that was + // reserved for the header. With data, read out infrastructure + // version and algorithm version. + if (legacy_mc) { + LogTrace("L1T") << "Skipping " << std::hex << *data_; + ++data_; + } else { + infra_ = data_[0]; + algo_ = data_[1]; + data_ += 2; + } } BlockHeader MP7Payload::getHeader() { - LogTrace("L1T") << "Getting header from " << std::hex << *data_; + LogTrace("L1T") << "Getting header from " << std::hex << std::setw(8) << *data_; return BlockHeader(data_++); } diff --git a/EventFilter/L1TRawToDigi/src/MP7PacketReader.cc b/EventFilter/L1TRawToDigi/src/MP7PacketReader.cc index cb7d9fb1ced7a..0949b03690c16 100644 --- a/EventFilter/L1TRawToDigi/src/MP7PacketReader.cc +++ b/EventFilter/L1TRawToDigi/src/MP7PacketReader.cc @@ -68,7 +68,7 @@ MP7PacketReader::load() { // Here the 64 bit uint is converted into a 32 bit uint, the data valid bit is stripped in the 64->32 bit conversion. pkt.links_[lIt->first] = std::vector( lIt->second.begin() + p.first + header_, - lIt->second.begin() + p.second - footer_ + lIt->second.begin() + p.second - footer_ + 1 ); } pkt.first_ = p.first + header_; diff --git a/EventFilter/L1TRawToDigi/src/PackingSetup.cc b/EventFilter/L1TRawToDigi/src/PackingSetup.cc index 02cdb9f6a716b..14400d809a84f 100644 --- a/EventFilter/L1TRawToDigi/src/PackingSetup.cc +++ b/EventFilter/L1TRawToDigi/src/PackingSetup.cc @@ -18,4 +18,12 @@ namespace l1t { return helper; } + + void + PackingSetupFactory::fillDescription(edm::ParameterSetDescription& desc) const + { + for (const auto& info: PackingSetupFactoryT::get()->available()) { + PackingSetupFactoryT::get()->create(info.name_)->fillDescription(desc); + } + } } diff --git a/EventFilter/L1TRawToDigi/src/Unpacker.cc b/EventFilter/L1TRawToDigi/src/Unpacker.cc index 341ff210f7372..2b7fe257e1c80 100644 --- a/EventFilter/L1TRawToDigi/src/Unpacker.cc +++ b/EventFilter/L1TRawToDigi/src/Unpacker.cc @@ -8,6 +8,13 @@ EDM_REGISTER_PLUGINFACTORY(l1t::UnpackerFactoryT,"UnpackerFactory"); namespace l1t { const UnpackerFactory UnpackerFactory::instance_; + void + getBXRange(int nbx, int& first, int& last) + { + last = floor(nbx / 2.); + first = std::min(0, -last + (1 - nbx % 2)); + } + std::shared_ptr UnpackerFactory::make(const std::string& name) const { diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloCollections.h b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloCollections.h index a704d8f0a8718..f2a595803aa84 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloCollections.h +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloCollections.h @@ -10,6 +10,13 @@ #include "DataFormats/L1Trigger/interface/Tau.h" #include "DataFormats/L1Trigger/interface/CaloSpare.h" + +#include "DataFormats/L1CaloTrigger/interface/L1CaloEmCand.h" +#include "DataFormats/L1CaloTrigger/interface/L1CaloRegion.h" +#include "DataFormats/L1CaloTrigger/interface/L1CaloRegionDetId.h" +#include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h" + + #include "EventFilter/L1TRawToDigi/interface/UnpackerCollections.h" namespace l1t { @@ -26,8 +33,8 @@ namespace l1t { isotaus_(new TauBxCollection()), calospareHFBitCounts_(new CaloSpareBxCollection()), calospareHFRingSums_(new CaloSpareBxCollection()), - caloEmCands_(new CaloEmCandBxCollection()), - caloRegions_(new CaloRegionBxCollection()) {}; + caloEmCands_(new L1CaloEmCollection()), + caloRegions_(new L1CaloRegionCollection()) {}; virtual ~CaloCollections(); @@ -39,8 +46,8 @@ namespace l1t { inline TauBxCollection* getIsoTaus() { return isotaus_.get(); }; inline CaloSpareBxCollection* getCaloSpareHFBitCounts() { return calospareHFBitCounts_.get(); }; inline CaloSpareBxCollection* getCaloSpareHFRingSums() { return calospareHFRingSums_.get(); }; - inline CaloEmCandBxCollection* getCaloEmCands() { return caloEmCands_.get(); }; - inline CaloRegionBxCollection* getCaloRegions() { return caloRegions_.get(); }; + inline L1CaloEmCollection* getCaloEmCands() { return caloEmCands_.get(); }; + inline L1CaloRegionCollection* getCaloRegions() { return caloRegions_.get(); }; private: std::auto_ptr towers_; @@ -51,8 +58,8 @@ namespace l1t { std::auto_ptr isotaus_; std::auto_ptr calospareHFBitCounts_; std::auto_ptr calospareHFRingSums_; - std::auto_ptr caloEmCands_; - std::auto_ptr caloRegions_; + std::auto_ptr caloEmCands_; + std::auto_ptr caloRegions_; }; } } diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloSetup.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloSetup.cc index 1bb9c57ae4318..56555af43589d 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloSetup.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloSetup.cc @@ -1,4 +1,5 @@ -#include "FWCore/Framework/interface/one/EDProducerBase.h" +#include "FWCore/Framework/interface/stream/EDProducerBase.h" +#include "FWCore/Utilities/interface/InputTag.h" #include "EventFilter/L1TRawToDigi/interface/Packer.h" #include "EventFilter/L1TRawToDigi/interface/Unpacker.h" @@ -16,10 +17,19 @@ namespace l1t { return std::unique_ptr(new CaloTokens(cfg, cc)); }; - virtual PackerMap getPackers(int fed, int fw) override { + virtual void fillDescription(edm::ParameterSetDescription& desc) override { + desc.addOptional("TauInputLabel")->setComment("for stage1"); + desc.addOptional("IsoTauInputLabel")->setComment("for stage1"); + desc.addOptional("HFBitCountsInputLabel")->setComment("for stage1"); + desc.addOptional("HFRingSumsInputLabel")->setComment("for stage1"); + desc.addOptional("RegionInputLabel")->setComment("for stage1"); + desc.addOptional("EmCandInputLabel")->setComment("for stage1"); + }; + + virtual PackerMap getPackers(int fed, unsigned int fw) override { PackerMap res; - res[{1, 0x200D}] = { + res[{1, 0x2300}] = { PackerFactory::get()->make("stage1::IsoEGammaPacker"), PackerFactory::get()->make("stage1::NonIsoEGammaPacker"), PackerFactory::get()->make("stage1::CentralJetPacker"), @@ -27,17 +37,20 @@ namespace l1t { PackerFactory::get()->make("stage1::TauPacker"), PackerFactory::get()->make("stage1::IsoTauPacker"), PackerFactory::get()->make("stage1::EtSumPacker"), - PackerFactory::get()->make("stage1::HFRingPacker"), + PackerFactory::get()->make("stage1::MissEtPacker"), + PackerFactory::get()->make("stage1::CaloSpareHFPacker"), + PackerFactory::get()->make("stage1::MissHtPacker"), + PackerFactory::get()->make("stage1::RCTEmRegionPacker"), }; return res; }; - virtual void registerProducts(edm::one::EDProducerBase& prod) override { - prod.produces(); + virtual void registerProducts(edm::stream::EDProducerBase& prod) override { + prod.produces(); prod.produces("HFBitCounts"); prod.produces("HFRingSums"); - prod.produces(); + prod.produces(); prod.produces(); prod.produces(); prod.produces(); @@ -50,45 +63,79 @@ namespace l1t { return std::unique_ptr(new CaloCollections(e)); }; - virtual UnpackerMap getUnpackers(int fed, int board, int amc, int fw) override { + virtual UnpackerMap getUnpackers(int fed, int board, int amc, unsigned int fw) override { UnpackerMap res; - auto cjet_unp = UnpackerFactory::get()->make("stage1::CentralJetUnpacker"); - auto fjet_unp = UnpackerFactory::get()->make("stage1::ForwardJetUnpacker"); - - if (fed == 1352) { - if (board == 0x200D) { - auto iegamma_unp = UnpackerFactory::get()->make("stage1::IsoEGammaUnpacker"); - auto niegamma_unp = UnpackerFactory::get()->make("stage1::NonIsoEGammaUnpacker"); - auto tau_unp = UnpackerFactory::get()->make("stage1::TauUnpacker"); - auto isotau_unp = UnpackerFactory::get()->make("stage1::IsoTauUnpacker"); - auto etsum_unp = UnpackerFactory::get()->make("stage1::EtSumUnpacker"); - auto ring_unp = UnpackerFactory::get()->make("stage1::HFRingUnpacker"); - - res[1] = iegamma_unp; - res[2] = niegamma_unp; - res[3] = cjet_unp; - res[4] = fjet_unp; - res[5] = tau_unp; - res[6] = etsum_unp; - res[7] = ring_unp; - res[8] = isotau_unp; + // FIXME Hard-coded firmware version for first 74x MC campaigns. + // Will account for differences in the AMC payload, MP7 payload, + // and unpacker setup. + if ((fw >> 24) == 0xff) { + auto cjet_unp = UnpackerFactory::get()->make("stage1::legacy::CentralJetUnpacker"); + auto fjet_unp = UnpackerFactory::get()->make("stage1::legacy::ForwardJetUnpacker"); + + if (fed == 1352) { + if (board == 0x200D) { + auto iegamma_unp = UnpackerFactory::get()->make("stage1::legacy::IsoEGammaUnpacker"); + auto niegamma_unp = UnpackerFactory::get()->make("stage1::legacy::NonIsoEGammaUnpacker"); + auto tau_unp = UnpackerFactory::get()->make("stage1::legacy::TauUnpacker"); + auto isotau_unp = UnpackerFactory::get()->make("stage1::legacy::IsoTauUnpacker"); + auto etsum_unp = UnpackerFactory::get()->make("stage1::legacy::EtSumUnpacker"); + auto ring_unp = UnpackerFactory::get()->make("stage1::legacy::HFRingUnpacker"); + + res[1] = iegamma_unp; + res[2] = niegamma_unp; + res[3] = cjet_unp; + res[4] = fjet_unp; + res[5] = tau_unp; + res[6] = etsum_unp; + res[7] = ring_unp; + res[8] = isotau_unp; + } } } else { - auto rctRegion_unp = UnpackerFactory::get()->make("stage1::RCTRegionUnpacker"); - auto rctEm_unp = UnpackerFactory::get()->make("stage1::RCTEmUnpacker"); - - for (int m=0;m<36;m++) { - if (board == 4109) { - res[m*2] = rctRegion_unp; - } - else if (board == 4110) { - res[m*2] = rctEm_unp; - } - } - if (board == 4109) { - res[105] = cjet_unp; - res[107] = fjet_unp; + auto cjet_unp_Left = UnpackerFactory::get()->make("stage1::CentralJetUnpackerLeft"); + auto fjet_unp_Left = UnpackerFactory::get()->make("stage1::ForwardJetUnpackerLeft"); + auto iegamma_unp_Left = UnpackerFactory::get()->make("stage1::IsoEGammaUnpackerLeft"); + auto niegamma_unp_Left = UnpackerFactory::get()->make("stage1::NonIsoEGammaUnpackerLeft"); + auto tau_unp_Left = UnpackerFactory::get()->make("stage1::TauUnpackerLeft"); + auto isotau_unp_Left = UnpackerFactory::get()->make("stage1::IsoTauUnpackerLeft"); + auto cjet_unp_Right = UnpackerFactory::get()->make("stage1::CentralJetUnpackerRight"); + auto fjet_unp_Right = UnpackerFactory::get()->make("stage1::ForwardJetUnpackerRight"); + auto iegamma_unp_Right = UnpackerFactory::get()->make("stage1::IsoEGammaUnpackerRight"); + auto niegamma_unp_Right = UnpackerFactory::get()->make("stage1::NonIsoEGammaUnpackerRight"); + auto tau_unp_Right = UnpackerFactory::get()->make("stage1::TauUnpackerRight"); + auto isotau_unp_Right = UnpackerFactory::get()->make("stage1::IsoTauUnpackerRight"); + auto etsum_unp = UnpackerFactory::get()->make("stage1::EtSumUnpacker"); + auto missetsum_unp = UnpackerFactory::get()->make("stage1::MissEtUnpacker"); + auto calospare_unp = UnpackerFactory::get()->make("stage1::CaloSpareHFUnpacker"); + auto misshtsum_unp = UnpackerFactory::get()->make("stage1::MissHtUnpacker"); + + if (fed == 1352) { + auto rct_unp = UnpackerFactory::get()->make("stage1::RCTEmRegionUnpacker"); + + // 4109 == 0x100D + if(board == 0x2300){ + res[77] = cjet_unp_Left; + res[79] = cjet_unp_Right; + res[81] = fjet_unp_Left; + res[83] = fjet_unp_Right; + res[85] = iegamma_unp_Left; + res[87] = iegamma_unp_Right; + res[89] = niegamma_unp_Left; + res[91] = niegamma_unp_Right; + res[93] = etsum_unp; + res[95] = missetsum_unp; + res[97] = calospare_unp; + res[99] = misshtsum_unp; + res[101] = tau_unp_Left; + res[103] = tau_unp_Right; + res[105] = isotau_unp_Left; + res[107] = isotau_unp_Right; + + for (int m=0;m<36;m++) { + res[m*2] = rct_unp; + } + } } } return res; diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloSpareHFPacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloSpareHFPacker.cc new file mode 100644 index 0000000000000..1b09cd792d376 --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloSpareHFPacker.cc @@ -0,0 +1,67 @@ +#include "FWCore/Framework/interface/Event.h" + +#include "EventFilter/L1TRawToDigi/interface/Packer.h" + +#include "CaloTokens.h" + +namespace l1t { + namespace stage1 { + class CaloSpareHFPacker : public Packer { + public: + virtual Blocks pack(const edm::Event&, const PackerTokens*) override; + }; + } +} + +// Implementation + +namespace l1t { + namespace stage1 { + Blocks + CaloSpareHFPacker::pack(const edm::Event& event, const PackerTokens* toks) + { + edm::Handle calosparesHFBitCounts; + event.getByToken(static_cast(toks)->getCaloSpareHFBitCountsToken(), calosparesHFBitCounts); + + edm::Handle calosparesHFRingSums; + event.getByToken(static_cast(toks)->getCaloSpareHFRingSumsToken(), calosparesHFRingSums); + + std::vector load; + + for (int i = calosparesHFBitCounts->getFirstBX(); i <= calosparesHFBitCounts->getLastBX(); ++i) { + int n = 0; + + int hfbitcount=0; + int hfringsum=0; + + for (auto j = calosparesHFBitCounts->begin(i); j != calosparesHFBitCounts->end(i) && n < 2; ++j, ++n) { + hfbitcount=std::min(j->hwPt(),0xFFF); + } + + n=0; + + for (auto j = calosparesHFRingSums->begin(i); j != calosparesHFRingSums->end(i) && n < 2; ++j, ++n) { + hfringsum=std::min(j->hwPt(),0xFFF); + } + + uint16_t object[2]={0,0}; + + object[0]=hfbitcount|((hfringsum & 0x7) << 12); + object[1]=((hfringsum>>3) & 0x1FF) |(0x1)<<10 | (0x1)<<12 | (0x1)<<14; + + uint32_t word0=(object[0] & 0xFFFF); + uint32_t word1=(object[1] & 0xFFFF); + + word0 |= (1 << 15); + word1 |= ((i == 0) << 15); + + load.push_back(word0); + load.push_back(word1); + } + + return {Block(97, load)}; + } + } +} + +DEFINE_L1T_PACKER(l1t::stage1::CaloSpareHFPacker); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloSpareHFUnpacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloSpareHFUnpacker.cc new file mode 100644 index 0000000000000..7f4cbfe081f7c --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloSpareHFUnpacker.cc @@ -0,0 +1,75 @@ +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "EventFilter/L1TRawToDigi/interface/Unpacker.h" + +#include "CaloCollections.h" + +namespace l1t { + namespace stage1 { + class CaloSpareHFUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + } +} + +// Implementation + +namespace l1t { + namespace stage1 { + bool + CaloSpareHFUnpacker::unpack(const Block& block, UnpackerCollections *coll) + { + + LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize(); + + int nBX, firstBX, lastBX; + nBX = int(ceil(block.header().getSize() / 2.)); + getBXRange(nBX, firstBX, lastBX); + + auto resHFBitCounts_ = static_cast(coll)->getCaloSpareHFBitCounts(); + resHFBitCounts_->setBXRange(firstBX, lastBX); + + auto resHFRingSums_ = static_cast(coll)->getCaloSpareHFRingSums(); + resHFRingSums_->setBXRange(firstBX, lastBX); + + LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX; + + // Initialise index + int unsigned i = 0; + + // Loop over multiple BX and then number of jets filling jet collection + for (int bx=firstBX; bx<=lastBX; bx++){ + uint32_t raw_data0 = block.payload()[i++]; + uint32_t raw_data1 = block.payload()[i++]; + + /* if (raw_data0 == 0 || raw_data1==0) continue; */ + + uint16_t candbit[2]; + candbit[0] = raw_data0 & 0xFFFF; + candbit[1] = raw_data1 & 0xFFFF; + + int hfbitcount=candbit[0] & 0xFFF; + int hfringsum=((candbit[0]>>12) & 0x7) | ((candbit[1] & 0x1FF) << 3); + + l1t::CaloSpare hfbc= l1t::CaloSpare(); + hfbc.setHwPt(hfbitcount); + hfbc.setType(l1t::CaloSpare::HFBitCount); + LogDebug("L1T") << "hfbc pT " << hfbc.hwPt(); + resHFBitCounts_->push_back(bx,hfbc); + + l1t::CaloSpare hfrs= l1t::CaloSpare(); + hfrs.setHwPt(hfringsum); + hfrs.setType(l1t::CaloSpare::HFRingSum); + LogDebug("L1T") << "hfrs pT " << hfrs.hwPt(); + resHFRingSums_->push_back(bx,hfrs); + + } + + return true; + + } + } +} + +DEFINE_L1T_UNPACKER(l1t::stage1::CaloSpareHFUnpacker); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloTokens.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloTokens.cc index 87299b15b88ce..61ce9411b8a31 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloTokens.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloTokens.cc @@ -13,6 +13,8 @@ namespace l1t { auto isotautag = cfg.getParameter("IsoTauInputLabel"); auto tagHFBitCounts = cfg.getParameter("HFBitCountsInputLabel"); auto tagHFRingSums = cfg.getParameter("HFRingSumsInputLabel"); + auto tagRegion = cfg.getParameter("RegionInputLabel"); + auto tagEmCand = cfg.getParameter("EmCandInputLabel"); towerToken_ = cc.consumes(tag); egammaToken_ = cc.consumes(tag); @@ -22,6 +24,10 @@ namespace l1t { isotauToken_ = cc.consumes(isotautag); calospareHFBitCountsToken_ = cc.consumes(tagHFBitCounts); calospareHFRingSumsToken_ = cc.consumes(tagHFRingSums); + caloregionToken_ = cc.consumes(tagRegion); + caloemCandToken_ = cc.consumes(tagEmCand); + + } } } diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloTokens.h b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloTokens.h index 0201857187fd3..2097d08e10d56 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloTokens.h +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/CaloTokens.h @@ -8,12 +8,20 @@ #include "DataFormats/L1Trigger/interface/Tau.h" #include "DataFormats/L1Trigger/interface/CaloSpare.h" +#include "DataFormats/L1CaloTrigger/interface/L1CaloEmCand.h" +#include "DataFormats/L1TCalorimeter/interface/CaloEmCand.h" +#include "DataFormats/L1CaloTrigger/interface/L1CaloRegion.h" +#include "DataFormats/L1TCalorimeter/interface/CaloRegion.h" +#include "DataFormats/L1CaloTrigger/interface/L1CaloRegionDetId.h" +#include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h" + + #include "EventFilter/L1TRawToDigi/interface/PackerTokens.h" namespace l1t { namespace stage1 { - class CaloTokens : public PackerTokens { + class CaloTokens : public PackerTokens {//getCaloRegions, getCaloEmCands public: CaloTokens(const edm::ParameterSet&, edm::ConsumesCollector&); @@ -25,6 +33,8 @@ namespace l1t { inline const edm::EDGetTokenT& getIsoTauToken() const { return isotauToken_; }; inline const edm::EDGetTokenT& getCaloSpareHFBitCountsToken() const { return calospareHFBitCountsToken_; }; inline const edm::EDGetTokenT& getCaloSpareHFRingSumsToken() const { return calospareHFRingSumsToken_; }; + inline const edm::EDGetTokenT& getCaloRegionToken() const { return caloregionToken_; }; + inline const edm::EDGetTokenT& getCaloEmCandToken() const { return caloemCandToken_; }; private: edm::EDGetTokenT towerToken_; @@ -35,6 +45,9 @@ namespace l1t { edm::EDGetTokenT isotauToken_; edm::EDGetTokenT calospareHFBitCountsToken_; edm::EDGetTokenT calospareHFRingSumsToken_; + edm::EDGetTokenT caloregionToken_; + edm::EDGetTokenT caloemCandToken_; + }; } } diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/EtSumPacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/EtSumPacker.cc index 1fe079f9b9016..b1d2fe57ed253 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage1/EtSumPacker.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/EtSumPacker.cc @@ -29,13 +29,9 @@ namespace stage1 { int n = 0; uint16_t objectTotalEt=0; - uint16_t objectTotalHt=0; - uint16_t objectMissingEt=0; - uint16_t objectMissingEtPhi=0; - + uint16_t objectTotalHt=0; int flagTotalEt=0; int flagTotalHt=0; - int flagMissingEt=0; for (auto j = etSums->begin(i); j != etSums->end(i) && n < 4; ++j, ++n) { @@ -48,19 +44,14 @@ namespace stage1 { flagTotalHt=j->hwQual() & 0x1; objectTotalHt=std::min(j->hwPt(), 0xFFF)|(flagTotalHt<<12); } - - else if (j->getType()==l1t::EtSum::kMissingEt){ - flagMissingEt=j->hwQual() & 0x1; - objectMissingEt=std::min(j->hwPt(), 0xFFF)|(flagMissingEt<<12); - objectMissingEtPhi=std::min(j->hwPhi(), 0x7F); - } } - uint32_t word0=(objectTotalEt & 0xFFFF) | ((objectMissingEt & 0xFFFF) << 16); - uint32_t word1=(objectTotalHt & 0xFFFF) | ((objectMissingEtPhi & 0xFFFF) << 16); - - word0 |= (1 << 31) | (1 << 15); - word1 |= ((i == 0) << 31) | ((i == 0) << 15); + uint32_t word0=(objectTotalEt & 0xFFFF); + uint32_t word1=(objectTotalHt & 0xFFFF); + + word0 |= (1 << 15); + word1 |= ((i == 0) << 15); + load.push_back(word0); load.push_back(word1); @@ -68,7 +59,7 @@ namespace stage1 { - return {Block(6, load)}; + return {Block(93, load)}; } } } diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/EtSumUnpacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/EtSumUnpacker.cc index 36abf629d5a28..afef1fcfd9b28 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage1/EtSumUnpacker.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/EtSumUnpacker.cc @@ -23,16 +23,9 @@ namespace l1t { LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize(); - int nBX = int(ceil(block.header().getSize() / 2.)); - - // Find the first and last BXs - int firstBX = -(ceil((double)nBX/2.)-1); - int lastBX; - if (nBX % 2 == 0) { - lastBX = ceil((double)nBX/2.)+1; - } else { - lastBX = ceil((double)nBX/2.); - } + int nBX, firstBX, lastBX; + nBX = int(ceil(block.header().getSize() / 2.)); + getBXRange(nBX, firstBX, lastBX); auto res_ = static_cast(coll)->getEtSums(); res_->setBXRange(firstBX, lastBX); @@ -43,25 +36,23 @@ namespace l1t { int unsigned i = 0; // Loop over multiple BX and then number of jets filling jet collection - for (int bx=firstBX; bxresize(bx,4); + uint32_t raw_data0 = block.payload()[i++]; uint32_t raw_data1 = block.payload()[i++]; /* if (raw_data0 == 0 || raw_data1==0) continue; */ - uint16_t candbit[4]; + uint16_t candbit[2]; candbit[0] = raw_data0 & 0xFFFF; - candbit[1] = (raw_data0 >> 16) & 0xFFFF; - candbit[2] = raw_data1 & 0xFFFF; - candbit[3] = (raw_data1 >> 16) & 0xFFFF; + candbit[1] = raw_data1 & 0xFFFF; int totet=candbit[0] & 0xFFF; int overflowtotet=(candbit[0]>>12) & 0x1; - int etmiss=candbit[1] & 0xFFF; - int overflowetmiss=(candbit[1]>>12) & 0x1; - int totht=candbit[2] & 0xFFF; - int overflowtotht=(candbit[2]>>12) & 0x1; - int etmissphi=candbit[3] & 0x7F; + int totht=candbit[1] & 0xFFF; + int overflowtotht=(candbit[1]>>12) & 0x1; l1t::EtSum et = l1t::EtSum(); et.setHwPt(totet); @@ -70,7 +61,7 @@ namespace l1t { flagtotet|= overflowtotet; et.setHwQual(flagtotet); LogDebug("L1T") << "ET: pT " << et.hwPt()<<"is overflow "<push_back(bx,et); + res_->set(bx, 2,et); l1t::EtSum ht = l1t::EtSum(); ht.setHwPt(totht); @@ -79,17 +70,7 @@ namespace l1t { flagtotht|= overflowtotht; ht.setHwQual(flagtotht); LogDebug("L1T") << "HT: pT " << ht.hwPt()<<"is overflow "<push_back(bx,ht); - - l1t::EtSum met = l1t::EtSum(); - met.setHwPt(etmiss); - met.setHwPhi(etmissphi); - met.setType(l1t::EtSum::kMissingEt); - int flagetmiss=met.hwQual(); - flagetmiss|= overflowetmiss; - met.setHwQual(flagetmiss); - LogDebug("L1T") << "MET: pT " << met.hwPt()<<"is overflow "<push_back(bx,met); + res_->set(bx, 3,ht); } diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/LegacyEtSumUnpacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/LegacyEtSumUnpacker.cc new file mode 100644 index 0000000000000..d4a9693df9eda --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/LegacyEtSumUnpacker.cc @@ -0,0 +1,99 @@ +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "EventFilter/L1TRawToDigi/interface/Unpacker.h" + +#include "CaloCollections.h" + +namespace l1t { + namespace stage1 { + namespace legacy { + class EtSumUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + } + } +} + +// Implementation + +namespace l1t { + namespace stage1 { + namespace legacy { + bool + EtSumUnpacker::unpack(const Block& block, UnpackerCollections *coll) + { + + LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize(); + + int nBX, firstBX, lastBX; + nBX = int(ceil(block.header().getSize() / 2.)); + getBXRange(nBX, firstBX, lastBX); + + auto res_ = static_cast(coll)->getEtSums(); + res_->setBXRange(firstBX, lastBX); + + LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX; + + // Initialise index + int unsigned i = 0; + + // Loop over multiple BX and then number of jets filling jet collection + for (int bx=firstBX; bx<=lastBX; bx++){ + uint32_t raw_data0 = block.payload()[i++]; + uint32_t raw_data1 = block.payload()[i++]; + + /* if (raw_data0 == 0 || raw_data1==0) continue; */ + + uint16_t candbit[4]; + candbit[0] = raw_data0 & 0xFFFF; + candbit[1] = (raw_data0 >> 16) & 0xFFFF; + candbit[2] = raw_data1 & 0xFFFF; + candbit[3] = (raw_data1 >> 16) & 0xFFFF; + + int totet=candbit[0] & 0xFFF; + int overflowtotet=(candbit[0]>>12) & 0x1; + int etmiss=candbit[1] & 0xFFF; + int overflowetmiss=(candbit[1]>>12) & 0x1; + int totht=candbit[2] & 0xFFF; + int overflowtotht=(candbit[2]>>12) & 0x1; + int etmissphi=candbit[3] & 0x7F; + + l1t::EtSum et = l1t::EtSum(); + et.setHwPt(totet); + et.setType(l1t::EtSum::kTotalEt); + int flagtotet=et.hwQual(); + flagtotet|= overflowtotet; + et.setHwQual(flagtotet); + LogDebug("L1T") << "ET: pT " << et.hwPt()<<"is overflow "<push_back(bx,et); + + l1t::EtSum ht = l1t::EtSum(); + ht.setHwPt(totht); + ht.setType(l1t::EtSum::kTotalHt); + int flagtotht=ht.hwQual(); + flagtotht|= overflowtotht; + ht.setHwQual(flagtotht); + LogDebug("L1T") << "HT: pT " << ht.hwPt()<<"is overflow "<push_back(bx,ht); + + l1t::EtSum met = l1t::EtSum(); + met.setHwPt(etmiss); + met.setHwPhi(etmissphi); + met.setType(l1t::EtSum::kMissingEt); + int flagetmiss=met.hwQual(); + flagetmiss|= overflowetmiss; + met.setHwQual(flagetmiss); + LogDebug("L1T") << "MET: pT " << met.hwPt()<<"is overflow "<push_back(bx,met); + + } + + return true; + + } + } + } +} + +DEFINE_L1T_UNPACKER(l1t::stage1::legacy::EtSumUnpacker); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/LegacyHFRingUnpacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/LegacyHFRingUnpacker.cc new file mode 100644 index 0000000000000..4718a54382286 --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/LegacyHFRingUnpacker.cc @@ -0,0 +1,97 @@ +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "EventFilter/L1TRawToDigi/interface/Unpacker.h" + +#include "CaloCollections.h" + +namespace l1t { + namespace stage1 { + namespace legacy { + class HFRingUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + } + } +} + +// Implementation + +namespace l1t { + namespace stage1 { + namespace legacy { + bool + HFRingUnpacker::unpack(const Block& block, UnpackerCollections *coll) + { + + LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize(); + + int nBX, firstBX, lastBX; + nBX = int(ceil(block.header().getSize() / 2.)); + getBXRange(nBX, firstBX, lastBX); + + auto resHFBitCounts_ = static_cast(coll)->getCaloSpareHFBitCounts(); + resHFBitCounts_->setBXRange(firstBX, lastBX); + + auto resHFRingSums_ = static_cast(coll)->getCaloSpareHFRingSums(); + resHFRingSums_->setBXRange(firstBX, lastBX); + + auto reset_ = static_cast(coll)->getEtSums(); + reset_->setBXRange(firstBX, lastBX); + + LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX; + + // Initialise index + int unsigned i = 0; + + // Loop over multiple BX and then number of jets filling jet collection + for (int bx=firstBX; bx<=lastBX; bx++){ + uint32_t raw_data0 = block.payload()[i++]; + uint32_t raw_data1 = block.payload()[i++]; + + /* if (raw_data0 == 0 || raw_data1==0) continue; */ + + uint16_t candbit[4]; + candbit[0] = raw_data0 & 0xFFFF; + candbit[1] = (raw_data0 >> 16) & 0xFFFF; + candbit[2] = raw_data1 & 0xFFFF; + candbit[3] = (raw_data1 >> 16) & 0xFFFF; + + int hfbitcount=candbit[0] & 0xFFF; + int hfringsum=((candbit[0]>>12) & 0x7) | ((candbit[2] & 0x1FF) << 3); + int htmissphi=candbit[1] & 0x1F; + int htmiss=(candbit[1]>>5) & 0x7F; + int overflowhtmiss=(candbit[1]>>12) & 0x1; + + l1t::CaloSpare hfbc= l1t::CaloSpare(); + hfbc.setHwPt(hfbitcount); + hfbc.setType(l1t::CaloSpare::HFBitCount); + LogDebug("L1T") << "hfbc pT " << hfbc.hwPt(); + resHFBitCounts_->push_back(bx,hfbc); + + l1t::CaloSpare hfrs= l1t::CaloSpare(); + hfrs.setHwPt(hfringsum); + hfrs.setType(l1t::CaloSpare::HFRingSum); + LogDebug("L1T") << "hfrs pT " << hfrs.hwPt(); + resHFRingSums_->push_back(bx,hfrs); + + l1t::EtSum mht = l1t::EtSum(); + mht.setHwPt(htmiss); + mht.setHwPhi(htmissphi); + mht.setType(l1t::EtSum::kMissingHt); + int flaghtmiss=mht.hwQual(); + flaghtmiss|= overflowhtmiss; + mht.setHwQual(flaghtmiss); + LogDebug("L1T") << "MHT: pT " << mht.hwPt()<<"is overflow "<push_back(bx,mht); + + } + + return true; + + } + } + } +} + +DEFINE_L1T_UNPACKER(l1t::stage1::legacy::HFRingUnpacker); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/LegacyPhysCandUnpacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/LegacyPhysCandUnpacker.cc new file mode 100644 index 0000000000000..a23db14ebbedc --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/LegacyPhysCandUnpacker.cc @@ -0,0 +1,157 @@ +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "EventFilter/L1TRawToDigi/interface/Unpacker.h" + +#include "CaloCollections.h" + +template +bool +process(const l1t::Block& block, BXVector * coll, F modify) { + LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize(); + + int nBX, firstBX, lastBX; + nBX = int(ceil(block.header().getSize() / 2.)); + l1t::getBXRange(nBX, firstBX, lastBX); + + coll->setBXRange(firstBX, lastBX); + + LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX; + + // Initialise index + int unsigned i = 0; + + // Loop over multiple BX and then number of jets filling jet collection + for (int bx=firstBX; bx<=lastBX; bx++){ + uint32_t raw_data0 = block.payload()[i++]; + uint32_t raw_data1 = block.payload()[i++]; + + uint16_t candbit[4]; + candbit[0] = raw_data0 & 0xFFFF; + candbit[1] = (raw_data0 >> 16) & 0xFFFF; + candbit[2] = raw_data1 & 0xFFFF; + candbit[3] = (raw_data1 >> 16) & 0xFFFF; + + for (int icand=0;icand<4;icand++){ + + int candPt=candbit[icand] & 0x3F; + int candEta=(candbit[icand]>>6 ) & 0x7; + int candEtasign=(candbit[icand]>>9) & 0x1; + int candPhi=(candbit[icand]>>10) & 0x1F; + + T cand; + cand.setHwPt(candPt); + cand.setHwEta((candEtasign << 3) | candEta); + cand.setHwPhi(candPhi); + //int qualflag=cand.hwQual(); + //qualflag|= (candPt == 0x3F); + //cand.setHwQual(qualflag); + + /* std::cout << "cand: eta " << cand.hwEta() << " phi " << cand.hwPhi() << " pT " << cand.hwPt() << " qual " << cand.hwQual() << std::endl; */ + //std::cout << cand.hwPt() << " @ " << cand.hwEta() << ", " << cand.hwPhi() << " > " << cand.hwQual() << " > " << cand.hwIso() << std::endl; + coll->push_back(bx, modify(cand)); + } + } + + return true; +} + +namespace l1t { + namespace stage1 { + namespace legacy { + class IsoEGammaUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + + class NonIsoEGammaUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + + class CentralJetUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + + class ForwardJetUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + + class TauUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + + class IsoTauUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + } + } +} + +// Implementation + +namespace l1t { + namespace stage1 { + namespace legacy { + bool + IsoEGammaUnpacker::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getEGammas(); + return process(block, res, [](l1t::EGamma eg) { eg.setHwIso(1); return eg; }); + } + + bool + NonIsoEGammaUnpacker::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getEGammas(); + return process(block, res, [](const l1t::EGamma& eg) { return eg; }); + } + + bool + CentralJetUnpacker::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getJets(); + + if (res->size(0) != 0) + edm::LogWarning("L1T") << "Need to unpack central jets before forward ones"; + + return process(block, res, [](const l1t::Jet& j) { return j; }); + } + + bool + ForwardJetUnpacker::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getJets(); + + if (res->size(0) != 4) + edm::LogWarning("L1T") << "Need to unpack central jets before forward ones"; + + return process(block, res, [](l1t::Jet j) { j.setHwQual(j.hwQual() | 2); return j; }); + } + + bool + TauUnpacker::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getTaus(); + return process(block, res, [](const l1t::Tau& t) { return t; }); + } + + bool + IsoTauUnpacker::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getIsoTaus(); + return process(block, res, [](const l1t::Tau& t) { return t; }); + } + } + } +} + +DEFINE_L1T_UNPACKER(l1t::stage1::legacy::IsoEGammaUnpacker); +DEFINE_L1T_UNPACKER(l1t::stage1::legacy::NonIsoEGammaUnpacker); +DEFINE_L1T_UNPACKER(l1t::stage1::legacy::CentralJetUnpacker); +DEFINE_L1T_UNPACKER(l1t::stage1::legacy::ForwardJetUnpacker); +DEFINE_L1T_UNPACKER(l1t::stage1::legacy::TauUnpacker); +DEFINE_L1T_UNPACKER(l1t::stage1::legacy::IsoTauUnpacker); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/MissEtPacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/MissEtPacker.cc new file mode 100644 index 0000000000000..8dc9fdae9b691 --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/MissEtPacker.cc @@ -0,0 +1,60 @@ +#include "FWCore/Framework/interface/Event.h" + +#include "EventFilter/L1TRawToDigi/interface/Packer.h" + +#include "CaloTokens.h" + +namespace l1t { + namespace stage1 { + class MissEtPacker : public Packer { + public: + virtual Blocks pack(const edm::Event&, const PackerTokens*) override; + }; + } +} + +// Implementation + +namespace l1t { +namespace stage1 { + Blocks + MissEtPacker::pack(const edm::Event& event, const PackerTokens* toks) + { + edm::Handle etSums; + event.getByToken(static_cast(toks)->getEtSumToken(), etSums); + + std::vector load; + + for (int i = etSums->getFirstBX(); i <= etSums->getLastBX(); ++i) { + int n = 0; + + uint16_t objectMissingEt=0; + uint16_t objectMissingEtPhi=0; + + int flagMissingEt=0; + + for (auto j = etSums->begin(i); j != etSums->end(i) && n < 4; ++j, ++n) { + if (j->getType()==l1t::EtSum::kMissingEt){ + flagMissingEt=j->hwQual() & 0x1; + objectMissingEt=std::min(j->hwPt(), 0xFFF)|(flagMissingEt<<12); + objectMissingEtPhi=std::min(j->hwPhi(), 0x7F); + } + } + + uint32_t word0= (objectMissingEt & 0xFFFF); + uint32_t word1= (objectMissingEtPhi & 0xFFFF); + + word0 |= (1 << 15); + word1 |= ((i == 0) << 15); + + + load.push_back(word0); + load.push_back(word1); + } + + return {Block(95, load)}; + } +} +} + +DEFINE_L1T_PACKER(l1t::stage1::MissEtPacker); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/MissEtUnpacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/MissEtUnpacker.cc new file mode 100644 index 0000000000000..5b5d1d7be2081 --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/MissEtUnpacker.cc @@ -0,0 +1,74 @@ +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "EventFilter/L1TRawToDigi/interface/Unpacker.h" + +#include "CaloCollections.h" + +namespace l1t { + namespace stage1 { + class MissEtUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + } +} + +// Implementation + +namespace l1t { + namespace stage1 { + bool + MissEtUnpacker::unpack(const Block& block, UnpackerCollections *coll) + { + + LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize(); + + int nBX, firstBX, lastBX; + nBX = int(ceil(block.header().getSize() / 2.)); + getBXRange(nBX, firstBX, lastBX); + + auto res_ = static_cast(coll)->getEtSums(); + res_->setBXRange(firstBX, lastBX); + + LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX; + + // Initialise index + int unsigned i = 0; + + // Loop over multiple BX and then number of jets filling jet collection + for (int bx=firstBX; bx<=lastBX; bx++){ + + res_->resize(bx,4); + + uint32_t raw_data0 = block.payload()[i++]; + uint32_t raw_data1 = block.payload()[i++]; + + /* if (raw_data0 == 0 || raw_data1==0) continue; */ + + uint16_t candbit[2]; + candbit[0] = raw_data0 & 0xFFFF; + candbit[1] = raw_data1 & 0xFFFF; + + int etmiss=candbit[0] & 0xFFF; + int overflowetmiss=(candbit[0]>>12) & 0x1; + int etmissphi=candbit[1] & 0x7F; + + l1t::EtSum met = l1t::EtSum(); + met.setHwPt(etmiss); + met.setHwPhi(etmissphi); + met.setType(l1t::EtSum::kMissingEt); + int flagetmiss=met.hwQual(); + flagetmiss|= overflowetmiss; + met.setHwQual(flagetmiss); + LogDebug("L1T") << "MET: pT " << met.hwPt()<<"is overflow "<set(bx, 0,met); + + } + + return true; + + } + } +} + +DEFINE_L1T_UNPACKER(l1t::stage1::MissEtUnpacker); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/MissHtPacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/MissHtPacker.cc new file mode 100644 index 0000000000000..d169ba741a30c --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/MissHtPacker.cc @@ -0,0 +1,65 @@ +#include "FWCore/Framework/interface/Event.h" + +#include "EventFilter/L1TRawToDigi/interface/Packer.h" + +#include "CaloTokens.h" + +namespace l1t { + namespace stage1 { + class MissHtPacker : public Packer { + public: + virtual Blocks pack(const edm::Event&, const PackerTokens*) override; + }; + } +} + +// Implementation + +namespace l1t { + namespace stage1 { + Blocks + MissHtPacker::pack(const edm::Event& event, const PackerTokens* toks) + { + edm::Handle etSums; + event.getByToken(static_cast(toks)->getEtSumToken(), etSums); + + std::vector load; + + for (int i = etSums->getFirstBX(); i <= etSums->getLastBX(); ++i) { + int n = 0; + + int htmissphi=0; + int htmiss=0; + + int flaghtmiss=0; + + for (auto j = etSums->begin(i); j != etSums->end(i) && n < 4; ++j, ++n) { + if (j->getType()==l1t::EtSum::kMissingHt){ + + flaghtmiss=j->hwQual() & 0x1; + htmiss=std::min(j->hwPt(),0x7F); + htmissphi=std::min(j->hwPhi(),0x1F); + } + } + + uint16_t object[2]={0,0}; + + object[0]=htmissphi|((htmiss & 0x7F) << 5 ) |(flaghtmiss<<12)|(0x1 << 14); + object[1]= 0x1 | (0x1 << 2) | (0x1 << 4) | (0x1 << 6) |(0x1 << 8) | (0x1 << 10) | (0x1 << 12) | (0x1 << 14); + + uint32_t word0=(object[0] & 0xFFFF); + uint32_t word1=(object[1] & 0xFFFF); + + word0 |= (1 << 15); + word1 |= ((i == 0) << 15); + + load.push_back(word0); + load.push_back(word1); + } + + return {Block(99, load)}; + } + } +} + +DEFINE_L1T_PACKER(l1t::stage1::MissHtPacker); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/MissHtUnpacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/MissHtUnpacker.cc new file mode 100644 index 0000000000000..d4f61b474dfb7 --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/MissHtUnpacker.cc @@ -0,0 +1,74 @@ +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "EventFilter/L1TRawToDigi/interface/Unpacker.h" + +#include "CaloCollections.h" + +namespace l1t { + namespace stage1 { + class MissHtUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + } +} + +// Implementation + +namespace l1t { + namespace stage1 { + bool + MissHtUnpacker::unpack(const Block& block, UnpackerCollections *coll) + { + + LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize(); + + int nBX, firstBX, lastBX; + nBX = int(ceil(block.header().getSize() / 2.)); + getBXRange(nBX, firstBX, lastBX); + + auto reset_ = static_cast(coll)->getEtSums(); + reset_->setBXRange(firstBX, lastBX); + + LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX; + + // Initialise index + int unsigned i = 0; + + // Loop over multiple BX and then number of jets filling jet collection + for (int bx=firstBX; bx<=lastBX; bx++){ + + reset_->resize(bx,4); + + uint32_t raw_data0 = block.payload()[i++]; + uint32_t raw_data1 = block.payload()[i++]; + + /* if (raw_data0 == 0 || raw_data1==0) continue; */ + + uint16_t candbit[2]; + candbit[0] = raw_data0 & 0xFFFF; + candbit[1] = raw_data1 & 0xFFFF; + + int htmissphi=candbit[0] & 0x1F; + int htmiss=(candbit[0]>>5) & 0x7F; + int overflowhtmiss=(candbit[0]>>12) & 0x1; + + l1t::EtSum mht = l1t::EtSum(); + mht.setHwPt(htmiss); + mht.setHwPhi(htmissphi); + mht.setType(l1t::EtSum::kMissingHt); + int flaghtmiss=mht.hwQual(); + flaghtmiss|= overflowhtmiss; + mht.setHwQual(flaghtmiss); + LogDebug("L1T") << "MHT: pT " << mht.hwPt()<<"is overflow "<set(bx, 1,mht); + + } + + return true; + + } + } +} + +DEFINE_L1T_UNPACKER(l1t::stage1::MissHtUnpacker); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysCandPacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysCandPacker.cc index 229d7aeb6c03b..34779eceb5f63 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysCandPacker.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysCandPacker.cc @@ -6,9 +6,9 @@ template l1t::Blocks -process(unsigned int id, const BXVector& coll, F filter) +process(unsigned int id1, unsigned int id2, const BXVector& coll, F filter) { - std::vector load; + std::vector load[2]; for (int i = coll.getFirstBX(); i <= coll.getLastBX(); ++i) { uint16_t jetbit[4] = {0, 0, 0, 0}; @@ -22,17 +22,20 @@ process(unsigned int id, const BXVector& coll, F filter) ((j->hwEta() >> 3) & 0x1) << 9 | (j->hwPhi() & 0x1F) << 10; } - uint32_t word0=(jetbit[0] & 0xFFFF) | ((jetbit[1] & 0xFFFF) << 16); - uint32_t word1=(jetbit[2] & 0xFFFF) | ((jetbit[3] & 0xFFFF) << 16); - - word0 |= (1 << 31) | (1 << 15); - word1 |= ((i == 0) << 31) | ((i == 0) << 15); - - load.push_back(word0); - load.push_back(word1); + uint32_t word0=(jetbit[0] & 0xFFFF); + uint32_t word1=(jetbit[1] & 0xFFFF); + uint32_t word2=(jetbit[2] & 0xFFFF); + uint32_t word3=(jetbit[3] & 0xFFFF); + + load[0].push_back(word0); + load[0].push_back(word2); + + load[1].push_back(word1); + load[1].push_back(word3); + } - return {l1t::Block(id, load)}; + return {l1t::Block(id1, load[0]),l1t::Block(id2, load[1])}; } namespace l1t { @@ -79,7 +82,7 @@ namespace l1t { edm::Handle egammas; event.getByToken(static_cast(toks)->getEGammaToken(), egammas); - return process(1, *egammas, [](const l1t::EGamma& eg) -> bool { return eg.hwIso() == 1; }); + return process(85,87, *egammas, [](const l1t::EGamma& eg) -> bool { return eg.hwIso() == 1; }); } Blocks @@ -88,7 +91,7 @@ namespace l1t { edm::Handle egammas; event.getByToken(static_cast(toks)->getEGammaToken(), egammas); - return process(2, *egammas, [](const l1t::EGamma& eg) -> bool { return eg.hwIso() == 0; }); + return process(89,91, *egammas, [](const l1t::EGamma& eg) -> bool { return eg.hwIso() == 0; }); } Blocks @@ -97,7 +100,7 @@ namespace l1t { edm::Handle jets; event.getByToken(static_cast(toks)->getJetToken(), jets); - return process(3, *jets, [](const l1t::Jet& jet) -> bool { return !(jet.hwQual() & 2); }); + return process(77,79, *jets, [](const l1t::Jet& jet) -> bool { return !(jet.hwQual() & 2); }); } Blocks @@ -106,7 +109,7 @@ namespace l1t { edm::Handle jets; event.getByToken(static_cast(toks)->getJetToken(), jets); - return process(4, *jets, [](const l1t::Jet& jet) -> bool { return jet.hwQual() & 2; }); + return process(81,83, *jets, [](const l1t::Jet& jet) -> bool { return jet.hwQual() & 2; }); } Blocks @@ -115,7 +118,7 @@ namespace l1t { edm::Handle taus; event.getByToken(static_cast(toks)->getTauToken(), taus); - return process(5, *taus, [](const l1t::Tau& tau) -> bool { return true; }); + return process(101,103, *taus, [](const l1t::Tau& tau) -> bool { return true; }); } Blocks @@ -124,7 +127,7 @@ namespace l1t { edm::Handle taus; event.getByToken(static_cast(toks)->getIsoTauToken(), taus); - return process(8, *taus, [](const l1t::Tau& tau) -> bool { return true; }); + return process(105,107, *taus, [](const l1t::Tau& tau) -> bool { return true; }); } } } diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysCandUnpacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysCandUnpacker.cc index f90d62a6d471e..688a99b197000 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysCandUnpacker.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysCandUnpacker.cc @@ -6,39 +6,34 @@ template bool -process(const l1t::Block& block, BXVector * coll, F modify) { +process(const l1t::Block& block, BXVector * coll, F modify, bool isleft, bool isfirst,bool istau) { LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize(); - int nBX = int(ceil(block.header().getSize() / 2.)); - - // Find the first and last BXs - int firstBX = -(ceil((double)nBX/2.)-1); - int lastBX; - if (nBX % 2 == 0) { - lastBX = ceil((double)nBX/2.)+1; - } else { - lastBX = ceil((double)nBX/2.); - } + int nBX, firstBX, lastBX; + nBX = int(ceil(block.header().getSize() / 2.)); + l1t::getBXRange(nBX, firstBX, lastBX); coll->setBXRange(firstBX, lastBX); - LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX; + LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX; // Initialise index int unsigned i = 0; // Loop over multiple BX and then number of jets filling jet collection - for (int bx=firstBX; bxresize(bx,8); + else coll->resize(bx,4); + uint32_t raw_data0 = block.payload()[i++]; uint32_t raw_data1 = block.payload()[i++]; - uint16_t candbit[4]; + uint16_t candbit[2]; candbit[0] = raw_data0 & 0xFFFF; - candbit[1] = (raw_data0 >> 16) & 0xFFFF; - candbit[2] = raw_data1 & 0xFFFF; - candbit[3] = (raw_data1 >> 16) & 0xFFFF; + candbit[1] = raw_data1 & 0xFFFF; - for (int icand=0;icand<4;icand++){ + for (int icand=0;icand<2;icand++){ int candPt=candbit[icand] & 0x3F; int candEta=(candbit[icand]>>6 ) & 0x7; @@ -55,7 +50,23 @@ process(const l1t::Block& block, BXVector * coll, F modify) { /* std::cout << "cand: eta " << cand.hwEta() << " phi " << cand.hwPhi() << " pT " << cand.hwPt() << " qual " << cand.hwQual() << std::endl; */ //std::cout << cand.hwPt() << " @ " << cand.hwEta() << ", " << cand.hwPhi() << " > " << cand.hwQual() << " > " << cand.hwIso() << std::endl; - coll->push_back(bx, modify(cand)); + + if(isfirst){ + if(isleft){ + coll->set(bx, 2*icand,modify(cand)); + } + else if (!isleft){ + coll->set(bx, 2*icand+1,modify(cand)); + } + } + else if (!isfirst){ + if(isleft){ + coll->set(bx, 2*icand+4,modify(cand)); + } + else if (!isleft){ + coll->set(bx, 2*icand+5,modify(cand)); + } + } } } @@ -64,35 +75,66 @@ process(const l1t::Block& block, BXVector * coll, F modify) { namespace l1t { namespace stage1 { - class IsoEGammaUnpacker : public Unpacker { + class IsoEGammaUnpackerLeft : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + + class NonIsoEGammaUnpackerLeft : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + + class CentralJetUnpackerLeft : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + + class ForwardJetUnpackerLeft : public Unpacker { public: virtual bool unpack(const Block& block, UnpackerCollections *coll) override; }; - class NonIsoEGammaUnpacker : public Unpacker { + class TauUnpackerLeft : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + + class IsoTauUnpackerLeft : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + + class IsoEGammaUnpackerRight : public Unpacker { public: virtual bool unpack(const Block& block, UnpackerCollections *coll) override; }; - class CentralJetUnpacker : public Unpacker { + class NonIsoEGammaUnpackerRight : public Unpacker { public: virtual bool unpack(const Block& block, UnpackerCollections *coll) override; }; - class ForwardJetUnpacker : public Unpacker { + class CentralJetUnpackerRight : public Unpacker { public: virtual bool unpack(const Block& block, UnpackerCollections *coll) override; }; - class TauUnpacker : public Unpacker { + class ForwardJetUnpackerRight : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + + class TauUnpackerRight : public Unpacker { public: virtual bool unpack(const Block& block, UnpackerCollections *coll) override; }; - class IsoTauUnpacker : public Unpacker { + class IsoTauUnpackerRight : public Unpacker { public: virtual bool unpack(const Block& block, UnpackerCollections *coll) override; }; + } } @@ -101,60 +143,100 @@ namespace l1t { namespace l1t { namespace stage1 { bool - IsoEGammaUnpacker::unpack(const Block& block, UnpackerCollections *coll) + IsoEGammaUnpackerLeft::unpack(const Block& block, UnpackerCollections *coll) { auto res = static_cast(coll)->getEGammas(); - return process(block, res, [](l1t::EGamma eg) { eg.setHwIso(1); return eg; }); + return process(block, res, [](l1t::EGamma eg) { eg.setHwIso(1); return eg; },true,true,false); } bool - NonIsoEGammaUnpacker::unpack(const Block& block, UnpackerCollections *coll) + NonIsoEGammaUnpackerLeft::unpack(const Block& block, UnpackerCollections *coll) { auto res = static_cast(coll)->getEGammas(); - return process(block, res, [](const l1t::EGamma& eg) { return eg; }); + return process(block, res, [](const l1t::EGamma& eg) { return eg; },true,false,false); } bool - CentralJetUnpacker::unpack(const Block& block, UnpackerCollections *coll) + CentralJetUnpackerLeft::unpack(const Block& block, UnpackerCollections *coll) { auto res = static_cast(coll)->getJets(); + return process(block, res, [](const l1t::Jet& j) { return j; },true,true,false); + } - if (res->size(0) != 0) - edm::LogWarning("L1T") << "Need to unpack central jets before forward ones"; + bool + ForwardJetUnpackerLeft::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getJets(); + return process(block, res, [](l1t::Jet j) { j.setHwQual(j.hwQual() | 2); return j; },true,false,false); + } - return process(block, res, [](const l1t::Jet& j) { return j; }); + bool + TauUnpackerLeft::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getTaus(); + return process(block, res, [](const l1t::Tau& t) { return t; },true,true,true); } bool - ForwardJetUnpacker::unpack(const Block& block, UnpackerCollections *coll) + IsoTauUnpackerLeft::unpack(const Block& block, UnpackerCollections *coll) { - auto res = static_cast(coll)->getJets(); + auto res = static_cast(coll)->getIsoTaus(); + return process(block, res, [](const l1t::Tau& t) { return t; },true,true,true); + } - if (res->size(0) != 4) - edm::LogWarning("L1T") << "Need to unpack central jets before forward ones"; + bool + IsoEGammaUnpackerRight::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getEGammas(); + return process(block, res, [](l1t::EGamma eg) { eg.setHwIso(1); return eg; },false,true,false); + } - return process(block, res, [](l1t::Jet j) { j.setHwQual(j.hwQual() | 2); return j; }); + bool + NonIsoEGammaUnpackerRight::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getEGammas(); + return process(block, res, [](const l1t::EGamma& eg) { return eg; },false,false,false); + } + + bool + CentralJetUnpackerRight::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getJets(); + return process(block, res, [](const l1t::Jet& j) { return j; },false,true,false); + } + + bool + ForwardJetUnpackerRight::unpack(const Block& block, UnpackerCollections *coll) + { + auto res = static_cast(coll)->getJets(); + return process(block, res, [](l1t::Jet j) { j.setHwQual(j.hwQual() | 2); return j; },false,false,false); } bool - TauUnpacker::unpack(const Block& block, UnpackerCollections *coll) + TauUnpackerRight::unpack(const Block& block, UnpackerCollections *coll) { auto res = static_cast(coll)->getTaus(); - return process(block, res, [](const l1t::Tau& t) { return t; }); + return process(block, res, [](const l1t::Tau& t) { return t; },false,true,true); } bool - IsoTauUnpacker::unpack(const Block& block, UnpackerCollections *coll) + IsoTauUnpackerRight::unpack(const Block& block, UnpackerCollections *coll) { auto res = static_cast(coll)->getIsoTaus(); - return process(block, res, [](const l1t::Tau& t) { return t; }); + return process(block, res, [](const l1t::Tau& t) { return t; },false,true,true); } } } -DEFINE_L1T_UNPACKER(l1t::stage1::IsoEGammaUnpacker); -DEFINE_L1T_UNPACKER(l1t::stage1::NonIsoEGammaUnpacker); -DEFINE_L1T_UNPACKER(l1t::stage1::CentralJetUnpacker); -DEFINE_L1T_UNPACKER(l1t::stage1::ForwardJetUnpacker); -DEFINE_L1T_UNPACKER(l1t::stage1::TauUnpacker); -DEFINE_L1T_UNPACKER(l1t::stage1::IsoTauUnpacker); +DEFINE_L1T_UNPACKER(l1t::stage1::IsoEGammaUnpackerLeft); +DEFINE_L1T_UNPACKER(l1t::stage1::NonIsoEGammaUnpackerLeft); +DEFINE_L1T_UNPACKER(l1t::stage1::CentralJetUnpackerLeft); +DEFINE_L1T_UNPACKER(l1t::stage1::ForwardJetUnpackerLeft); +DEFINE_L1T_UNPACKER(l1t::stage1::TauUnpackerLeft); +DEFINE_L1T_UNPACKER(l1t::stage1::IsoTauUnpackerLeft); +DEFINE_L1T_UNPACKER(l1t::stage1::IsoEGammaUnpackerRight); +DEFINE_L1T_UNPACKER(l1t::stage1::NonIsoEGammaUnpackerRight); +DEFINE_L1T_UNPACKER(l1t::stage1::CentralJetUnpackerRight); +DEFINE_L1T_UNPACKER(l1t::stage1::ForwardJetUnpackerRight); +DEFINE_L1T_UNPACKER(l1t::stage1::TauUnpackerRight); +DEFINE_L1T_UNPACKER(l1t::stage1::IsoTauUnpackerRight); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysicsToBitConverter.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysicsToBitConverter.cc index 814a648269612..a66221f72ce30 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysicsToBitConverter.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage1/PhysicsToBitConverter.cc @@ -1,46 +1,81 @@ -#include "PhysicsToBitConverter.h" - - -namespace l1t{ - PhysicsToBitConverter::PhysicsToBitConverter() { - - } - - void PhysicsToBitConverter::Convert() { - - for (int iword=0;iword<6;iword++){ - for (int ibit=0;ibit<32;ibit++){ - bitsLink[0].push_back(ReadBitInInt(ibit,words32bitLink[0][iword])); - bitsLink[1].push_back(ReadBitInInt(ibit,words32bitLink[1][iword])); - } - } - } - - int PhysicsToBitConverter::GetObject(rctDataBase::rctObjectType t, int firstindex, int secondindex) - { - int mystart = databaseobject.GetIndices(t,firstindex,secondindex); - int mylength = databaseobject.GetLength(t); - int mylink = databaseobject.GetLink(t); - - return BuildPhysicsValue(mystart, mylength, mylink); - } - - int PhysicsToBitConverter::ReadBitInInt(int bit,int value){ - - std::bitset<32> foo(value); - return foo[bit]; - - } - - int PhysicsToBitConverter::BuildPhysicsValue(int firstbit,int bitlength,int linkid){ - - int myvalue=0; - int counter=0; - - for (int m=firstbit;m(pow(2,mylength)-1)) std::cout<<"The value you are trying to set has more bins than expected "<>i)&0x1; + + } + + + int PhysicsToBitConverter::ReadBitInInt(int bit,int value){ + + std::bitset<32> foo(value); + return foo[bit]; + + } + + int PhysicsToBitConverter::BuildDecimalValue(int firstbit,int bitlength,int linkid){ + + int myvalue=0; + int counter=0; + + for (int m=firstbit;m -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "rctDataBase.h" - -namespace l1t{ - class PhysicsToBitConverter { - - - int words32bitLink[2][6]; //[link][word] - - std::vector bitsLink[2]; - rctDataBase databaseobject; - - - public: - - PhysicsToBitConverter(); - ~PhysicsToBitConverter() { } - void Set32bitWordLinkEven(int index,uint32_t value){words32bitLink[0][index]=value;}; - void Set32bitWordLinkOdd(int index,uint32_t value){words32bitLink[1][index]=value;}; - void Convert(); - - int GetObject(rctDataBase::rctObjectType t, int firstindex, int secondindex = -1); - - int ReadBitInInt(int bit,int value); - int BuildPhysicsValue(int firstbit,int bitlength,int linkid); - - int GetRCEt(int card,int region) {return GetObject(rctDataBase::RCEt,card,region);} - int GetHFEt(int region) {return GetObject(rctDataBase::HFEt,region);} - int GetRCTau(int card,int region){return GetObject(rctDataBase::RCTau,card,region);} - int GetRCOf(int card,int region) {return GetObject(rctDataBase::RCOf,card,region);} - int GetHFFg(int region) {return GetObject(rctDataBase::HFFg,region);} - int GetNEReg(int cand) {return GetObject(rctDataBase::NEReg,cand);} - int GetNECard(int cand) {return GetObject(rctDataBase::NECard,cand);} - int GetNEEt(int cand) {return GetObject(rctDataBase::NEEt,cand);} - int GetIEReg(int cand) {return GetObject(rctDataBase::IEReg,cand);} - int GetIECard(int cand) {return GetObject(rctDataBase::IECard,cand);} - int GetIEEt(int cand) {return GetObject(rctDataBase::IEEt,cand);} - int GetRCHad(int card,int region){return GetObject(rctDataBase::RCHad,card,region);} - - - }; -} -#endif +#ifndef _PHYSICSTOBITCONVERTER_h +#define _PHYSICSTOBITCONVERTER_h + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "rctDataBase.h" + +namespace l1t{ + class PhysicsToBitConverter { + + + int words32bitLink[2][6]; //[link][word] + + int bitsLink[2][192]; + rctDataBase databaseobject; + + + public: + + PhysicsToBitConverter(); + ~PhysicsToBitConverter() { } + void Set32bitWordLinkEven(int index,uint32_t value){words32bitLink[0][index]=value;}; + void Set32bitWordLinkOdd(int index,uint32_t value){words32bitLink[1][index]=value;}; + + int Get32bitWordLinkEven(int index){return words32bitLink[0][index];}; + int Get32bitWordLinkOdd(int index) {return words32bitLink[1][index];}; + + void Convert(); + void Extract32bitwords(); + + int GetObject(rctDataBase::rctObjectType t, int firstindex, int secondindex = -1); + void SetObject(rctDataBase::rctObjectType t, int value, int firstindex, int secondindex = -1); + + int ReadBitInInt(int bit,int value); + int BuildDecimalValue(int firstbit,int bitlength,int linkid); + + int GetRCEt(int card,int region) {return GetObject(rctDataBase::RCEt,card,region);} + int GetHFEt(int region) {return GetObject(rctDataBase::HFEt,region);} + int GetRCTau(int card,int region){return GetObject(rctDataBase::RCTau,card,region);} + int GetRCOf(int card,int region) {return GetObject(rctDataBase::RCOf,card,region);} + int GetHFFg(int region) {return GetObject(rctDataBase::HFFg,region);} + int GetNEReg(int cand) {return GetObject(rctDataBase::NEReg,cand);} + int GetNECard(int cand) {return GetObject(rctDataBase::NECard,cand);} + int GetNEEt(int cand) {return GetObject(rctDataBase::NEEt,cand);} + int GetIEReg(int cand) {return GetObject(rctDataBase::IEReg,cand);} + int GetIECard(int cand) {return GetObject(rctDataBase::IECard,cand);} + int GetIEEt(int cand) {return GetObject(rctDataBase::IEEt,cand);} + int GetRCHad(int card,int region){return GetObject(rctDataBase::RCHad,card,region);} + + void SetRCEt(int value,int card,int region) {SetObject(rctDataBase::RCEt,value,card,region);} + void SetHFEt(int value,int region) {SetObject(rctDataBase::HFEt,value,region);} + void SetRCTau(int value,int card,int region){SetObject(rctDataBase::RCTau,value,card,region);} + void SetRCOf(int value,int card,int region) {SetObject(rctDataBase::RCOf,value,card,region);} + void SetHFFg(int value,int region) {SetObject(rctDataBase::HFFg,value,region);} + void SetNEReg(int value,int cand) {SetObject(rctDataBase::NEReg,value,cand);} + void SetNECard(int value,int cand) {SetObject(rctDataBase::NECard,value,cand);} + void SetNEEt(int value,int cand) {SetObject(rctDataBase::NEEt,value,cand);} + void SetIEReg(int value,int cand) {SetObject(rctDataBase::IEReg,value,cand);} + void SetIECard(int value,int cand) {SetObject(rctDataBase::IECard,value,cand);} + void SetIEEt(int value,int cand) {SetObject(rctDataBase::IEEt,value,cand);} + void SetRCHad(int value,int card,int region){SetObject(rctDataBase::RCHad,value,card,region);} + + }; +} +#endif diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage1/RCTEMUnpacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage1/RCTEMUnpacker.cc deleted file mode 100644 index 41ad9f04c28f1..0000000000000 --- a/EventFilter/L1TRawToDigi/src/implementations_stage1/RCTEMUnpacker.cc +++ /dev/null @@ -1,118 +0,0 @@ -#include "FWCore/Framework/interface/MakerMacros.h" -#include "EventFilter/L1TRawToDigi/interface/Unpacker.h" -#include "PhysicsToBitConverter.h" -#include "rctDataBase.h" - - -#include "DataFormats/L1CaloTrigger/interface/L1CaloEmCand.h" -#include "DataFormats/L1TCalorimeter/interface/CaloEmCand.h" -#include "DataFormats/L1CaloTrigger/interface/L1CaloRegion.h" -#include "DataFormats/L1TCalorimeter/interface/CaloRegion.h" -#include "DataFormats/L1CaloTrigger/interface/L1CaloRegionDetId.h" -#include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h" - - -#include -#include - -#include "CaloCollections.h" - -namespace l1t { - namespace stage1 { - class RCTEmUnpacker : public Unpacker { - public: - virtual bool unpack(const Block& block, UnpackerCollections *coll) override; - private: - unsigned int counter_ = 0; - }; - } -} - -// Implementation - -namespace l1t { - namespace stage1 { - bool RCTEmUnpacker::unpack(const Block& block, UnpackerCollections *coll){ - - int nBX = int(ceil(block.header().getSize() / 6.)); - - // Find the first and last BXs - int firstBX = -(ceil((double)nBX/2.)-1); - int lastBX; - if (nBX % 2 == 0) { - lastBX = ceil((double)nBX/2.)+1; - } else { - lastBX = ceil((double)nBX/2.); - } - - auto resRCTEMCands_ = static_cast(coll)->getCaloEmCands(); - resRCTEMCands_->setBXRange(std::min(firstBX, resRCTEMCands_->getFirstBX()), std::max(lastBX, resRCTEMCands_->getLastBX())); - - // Initialise index - int unsigned i = 0; - - for (int bx=firstBX; bx uint; - uint.reserve(6); - - PhysicsToBitConverter converter; - rctDataBase database; - int mp7link=(int)(block.header().getID()/2); - database.GetLinkRCT(mp7link,crate,even); - - uint.push_back(block.payload()[i++]); - uint.push_back(block.payload()[i++]); - uint.push_back(block.payload()[i++]); - uint.push_back(block.payload()[i++]); - uint.push_back(block.payload()[i++]); - uint.push_back(block.payload()[i++]); - - LogDebug("L1T")<<"--------------- mp7 link ="< caloregion; + event.getByToken(static_cast(toks)->getCaloRegionToken(), caloregion); + + edm::Handle caloemcand; + event.getByToken(static_cast(toks)->getCaloEmCandToken(), caloemcand); + + std::vector load[36]; + + for (int i = 0; i <= 0; ++i) { + int n = 0; + PhysicsToBitConverter converter[18]; + for (auto j = caloregion->begin(); j != caloregion->end(); ++j, ++n) { + + int et=(int)j->et(); + int overFlow=(int)j->overFlow(); + int fineGrain=(int)j->fineGrain(); + int mip=(int)j->mip(); + //int quiet=(int)j->quiet(); + int rctCrate=(int)j->rctCrate(); + int rctCard=(int)j->rctCard(); + int rctRegion=(int)j->rctRegionIndex(); + bool isHf=(bool)j->isHf(); + + if(!isHf){ + converter[rctCrate].SetRCEt(et,rctCard,rctRegion); + converter[rctCrate].SetRCOf(overFlow,rctCard,rctRegion); + converter[rctCrate].SetRCTau(fineGrain,rctCard,rctRegion); + converter[rctCrate].SetRCHad(mip,rctCard,rctRegion); + LogDebug("L1T")<<"CRATE"< +#include + +#include "CaloCollections.h" + +namespace l1t { + namespace stage1 { + class RCTEmRegionUnpacker : public Unpacker { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + private: + unsigned int counter_ = 0; + }; + } +} + +// Implementation + +namespace l1t { + namespace stage1 { + void + unpack_em(const Block& block, UnpackerCollections *coll) + { + int nBX, firstBX, lastBX; + nBX = int(ceil(block.header().getSize() / 6.)); + getBXRange(nBX, firstBX, lastBX); + + auto resRCTEMCands_ = static_cast(coll)->getCaloEmCands(); + + // Initialise index + int unsigned i = 0; + + for (int bx=firstBX; bx<=lastBX; bx++){ + + unsigned int crate; + bool even=0; + + std::vector uint; + uint.reserve(6); + + PhysicsToBitConverter converter; + rctDataBase database; + int mp7link=(int)(block.header().getID()/2); + database.GetLinkRCT(mp7link,crate,even); + + uint.push_back(block.payload()[i++]); + uint.push_back(block.payload()[i++]); + uint.push_back(block.payload()[i++]); + uint.push_back(block.payload()[i++]); + uint.push_back(block.payload()[i++]); + uint.push_back(block.payload()[i++]); + + LogDebug("L1T")<<"--------------- mp7 link ="< -#include - -#include "CaloCollections.h" - -namespace l1t { - namespace stage1 { - class RCTRegionUnpacker : public Unpacker { - public: - virtual bool unpack(const Block& block, UnpackerCollections *coll) override; - private: - unsigned int counter_ = 0; - }; - } -} - -// Implementation - -namespace l1t { - namespace stage1 { - bool RCTRegionUnpacker::unpack(const Block& block, UnpackerCollections *coll){ - - int nBX = int(ceil(block.header().getSize() / 6.)); - - // Find the first and last BXs - int firstBX = -(ceil((double)nBX/2.)-1); - int lastBX; - if (nBX % 2 == 0) { - lastBX = ceil((double)nBX/2.)+1; - } else { - lastBX = ceil((double)nBX/2.); - } - - auto resRCTRegions_ = static_cast(coll)->getCaloRegions(); - resRCTRegions_->setBXRange(std::min(firstBX, resRCTRegions_->getFirstBX()), std::max(lastBX, resRCTRegions_->getLastBX())); - - // Initialise index - int unsigned i = 0; - std::vector uint; - uint.reserve(6); - - for (int bx=firstBX; bx > *p4 =new ROOT::Math::LorentzVector >(); - CaloRegion region(*p4,0.,0.,(int) rgn.et(),(int) rgn.id().ieta(),(int) rgn.id().iphi(),0.,0.); - resRCTRegions_->push_back(bx,region); - } - }// end if odd - - - else{ - - for(int i=0;i<6;i++) converter.Set32bitWordLinkEven(i,uint[i]); - converter.Convert(); - - for(int j = 0; j < 7; j++) { - for(int k = 0; k < 2; k++) { - - unsigned int RCet=(unsigned int)converter.GetRCEt(j,k); - bool overflow=(bool)converter.GetRCOf(j,k); - bool tauveto=(bool)converter.GetRCTau(j,k); - bool hadveto=(bool)converter.GetRCHad(j,k); - bool quiet=false; //to be fixed - - LogDebug("L1T") <<"region="<(new CaloTokens(cfg, cc)); }; - virtual PackerMap getPackers(int fed, int fw) override { + virtual void fillDescription(edm::ParameterSetDescription& desc) override {}; + + virtual PackerMap getPackers(int fed, unsigned int fw) override { PackerMap res; if (fed == 1366) { @@ -33,7 +35,7 @@ namespace l1t { return res; }; - virtual void registerProducts(edm::one::EDProducerBase& prod) override { + virtual void registerProducts(edm::stream::EDProducerBase& prod) override { prod.produces(); prod.produces(); prod.produces(); @@ -48,7 +50,7 @@ namespace l1t { return std::unique_ptr(new CaloCollections(e)); }; - virtual UnpackerMap getUnpackers(int fed, int board, int amc, int fw) override { + virtual UnpackerMap getUnpackers(int fed, int board, int amc, unsigned int fw) override { auto tower_unp = UnpackerFactory::get()->make("stage2::CaloTowerUnpacker"); auto egamma_unp = UnpackerFactory::get()->make("stage2::EGammaUnpacker"); auto etsum_unp = UnpackerFactory::get()->make("stage2::EtSumUnpacker"); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/EtSumUnpacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage2/EtSumUnpacker.cc index 784dcfba27fb8..18f9c3201dd57 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage2/EtSumUnpacker.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/EtSumUnpacker.cc @@ -60,33 +60,33 @@ namespace stage2 { res_->push_back(bx,et); - // MET + // HT raw_data = block.payload()[i++]; - l1t::EtSum met = l1t::EtSum(); + l1t::EtSum ht = l1t::EtSum(); - met.setHwPt(raw_data & 0xFFF); - met.setHwPhi((raw_data >> 20) & 0xFFF);//12) & 0xFF); - met.setType(l1t::EtSum::kMissingEt); + ht.setHwPt(raw_data & 0xFFF); + ht.setType(l1t::EtSum::kTotalHt); - LogDebug("L1T") << "MET: phi " << met.hwPhi() << " pT " << met.hwPt() << " bx " << bx; + LogDebug("L1T") << "HT: pT " << ht.hwPt(); - res_->push_back(bx,met); + res_->push_back(bx,ht); - // HT + // MET raw_data = block.payload()[i++]; - l1t::EtSum ht = l1t::EtSum(); + l1t::EtSum met = l1t::EtSum(); - ht.setHwPt(raw_data & 0xFFF); - ht.setType(l1t::EtSum::kTotalHt); + met.setHwPt(raw_data & 0xFFF); + met.setHwPhi((raw_data >> 12) & 0xFF); + met.setType(l1t::EtSum::kMissingEt); - LogDebug("L1T") << "HT: pT " << ht.hwPt(); + LogDebug("L1T") << "MET: phi " << met.hwPhi() << " pT " << met.hwPt() << " bx " << bx; - res_->push_back(bx,ht); + res_->push_back(bx,met); // MHT @@ -96,7 +96,7 @@ namespace stage2 { l1t::EtSum mht = l1t::EtSum(); mht.setHwPt(raw_data & 0xFFF); - mht.setHwPhi((raw_data >> 20) & 0xFFF);//12) & 0xFF); + mht.setHwPhi((raw_data >> 12) & 0xFF); mht.setType(l1t::EtSum::kMissingHt); LogDebug("L1T") << "MHT: phi " << mht.hwPhi() << " pT " << mht.hwPt() << " bx " << bx; diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/GTSetup.cc b/EventFilter/L1TRawToDigi/src/implementations_stage2/GTSetup.cc index d44b2f4c1b976..7418c7c1a871f 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage2/GTSetup.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/GTSetup.cc @@ -1,4 +1,4 @@ -#include "FWCore/Framework/interface/one/EDProducerBase.h" +#include "FWCore/Framework/interface/stream/EDProducerBase.h" #include "EventFilter/L1TRawToDigi/interface/Packer.h" #include "EventFilter/L1TRawToDigi/interface/Unpacker.h" @@ -16,7 +16,9 @@ namespace l1t { return std::unique_ptr(new GTTokens(cfg, cc)); }; - virtual PackerMap getPackers(int fed, int fw) override { + virtual void fillDescription(edm::ParameterSetDescription& desc) override {}; + + virtual PackerMap getPackers(int fed, unsigned int fw) override { PackerMap res; if (fed == 1404) { @@ -35,7 +37,7 @@ namespace l1t { return res; }; - virtual void registerProducts(edm::one::EDProducerBase& prod) override { + virtual void registerProducts(edm::stream::EDProducerBase& prod) override { prod.produces("GT"); prod.produces("GT"); @@ -50,7 +52,7 @@ namespace l1t { return std::unique_ptr(new GTCollections(e)); }; - virtual UnpackerMap getUnpackers(int fed, int board, int amc, int fw) override { + virtual UnpackerMap getUnpackers(int fed, int board, int amc, unsigned int fw) override { auto egamma_unp = UnpackerFactory::get()->make("stage2::EGammaUnpacker"); auto etsum_unp = UnpackerFactory::get()->make("stage2::EtSumUnpacker"); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/MPUnpacker.cc b/EventFilter/L1TRawToDigi/src/implementations_stage2/MPUnpacker.cc index 98977e52ac97e..d022c2628499f 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage2/MPUnpacker.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/MPUnpacker.cc @@ -32,17 +32,27 @@ namespace stage2 { // Initialise frame indices for each data type int unsigned fet = 0; - int unsigned fht = 12; - int unsigned fjet = 37; + int unsigned fht = 1; + int unsigned fjet = 2; // ET / MET(x) / MET (y) uint32_t raw_data = block.payload()[fet]; l1t::EtSum et = l1t::EtSum(); - - et.setHwPt(raw_data & 0xFFFFF); - et.setType(l1t::EtSum::kTotalEt); + + et.setHwPt( static_cast( uint32_t(raw_data & 0xFFFFFF) << 16 ) >> 16 ); + //et.setHwPt(raw_data & 0xFFFFF); + switch(block.header().getID()){ + case 1: et.setType(l1t::EtSum::kTotalEt); break; + case 3: et.setType(l1t::EtSum::kTotalEtx); break; + case 5: et.setType(l1t::EtSum::kTotalEty); break; + case 7: et.setType(l1t::EtSum::kTotalEt); break; + case 9: et.setType(l1t::EtSum::kTotalEtx); break; + case 11: et.setType(l1t::EtSum::kTotalEty); break; + default: break; + } + LogDebug("L1T") << "ET/METx/METy: pT " << et.hwPt(); @@ -53,10 +63,19 @@ namespace stage2 { raw_data = block.payload()[fht]; - l1t::EtSum ht = l1t::EtSum(); - - ht.setHwPt(raw_data & 0xFFFFF); - ht.setType(l1t::EtSum::kTotalHt); + l1t::EtSum ht = l1t::EtSum(); + + //ht.setHwPt(raw_data & 0xFFFFF); + ht.setHwPt( static_cast( uint32_t(raw_data & 0xFFFFFF) << 16 ) >> 16 ); + switch(block.header().getID()){ + case 1: ht.setType(l1t::EtSum::kTotalHt); break; + case 3: ht.setType(l1t::EtSum::kTotalHtx); break; + case 5: ht.setType(l1t::EtSum::kTotalHty); break; + case 7: ht.setType(l1t::EtSum::kTotalHt); break; + case 9: ht.setType(l1t::EtSum::kTotalHtx); break; + case 11: ht.setType(l1t::EtSum::kTotalHty); break; + default: break; + } LogDebug("L1T") << "HT/MHTx/MHTy: pT " << ht.hwPt(); @@ -87,7 +106,41 @@ namespace stage2 { LogDebug("L1T") << "Jet: eta " << jet.hwEta() << " phi " << jet.hwPhi() << " pT " << jet.hwPt() << " qual " << jet.hwQual(); - res1_->push_back(0,jet); + //res1_->push_back(0,jet); + + // Push them back in the right place (for checking sorting) + + int blockID = block.header().getID(); + int nPos=0, nNeg=0; + for (unsigned i=0; isize(0); i++) + res1_->at(0,i).hwEta()>0 ? nPos++ : nNeg++; + + if (nJet==1) res1_->push_back(0,jet); + else if (nJet==0) { + if (blockID==1) { + res1_->push_back(0,jet); + } + if (blockID==3) { + if (nPos==1) res1_->push_back(0,jet); + else if (nPos==2) res1_->insert(0,1,jet); + } + if (blockID==5) { + if (nPos==2) res1_->push_back(0,jet); + else if (nPos>2) res1_->insert(0,2,jet); + } + if (blockID==7) { + res1_->push_back(0,jet); + } + if (blockID==9) { + if (nNeg==1) res1_->push_back(0,jet); + else if (nNeg==2) res1_->insert(0,nPos+1,jet); + } + if (blockID==11) { + if (nNeg==2) res1_->push_back(0,jet); + else if (nNeg>2) res1_->insert(0,nPos+2,jet); + } + } + } return true; diff --git a/EventFilter/L1TRawToDigi/test/test_AMC13DumpToRaw_cfg.py b/EventFilter/L1TRawToDigi/test/test_AMC13DumpToRaw_cfg.py new file mode 100644 index 0000000000000..f5374ffb2d992 --- /dev/null +++ b/EventFilter/L1TRawToDigi/test/test_AMC13DumpToRaw_cfg.py @@ -0,0 +1,102 @@ +# Auto generated configuration file +# using: +# Revision: 1.19 +# Source: /local/reps/CMSSW/CMSSW/Configuration/Applications/python/ConfigBuilder.py,v +# with command line options: SingleElectronPt10_cfi.py -s GEN,SIM,DIGI,L1 --pileup=NoPileUp --geometry DB --conditions=auto:startup -n 1 --no_exec +import FWCore.ParameterSet.Config as cms + +process = cms.Process('L1') + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.StandardSequences.GeometryRecoDB_cff') +process.load('Configuration.Geometry.GeometryDB_cff') +process.load('Configuration.StandardSequences.MagneticField_38T_cff') +process.load('Configuration.StandardSequences.SimL1Emulator_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(1) +) + +# Input source +process.source = cms.Source("EmptySource") + +process.options = cms.untracked.PSet( + SkipEvent = cms.untracked.vstring('ProductNotFound') +) + + +# Output definition + +process.output = cms.OutputModule( + "PoolOutputModule", + splitLevel = cms.untracked.int32(0), + eventAutoFlushCompressedSize = cms.untracked.int32(5242880), + outputCommands = cms.untracked.vstring("keep *", + "drop *_mix_*_*"), + fileName = cms.untracked.string('L1T_EDM.root'), + dataset = cms.untracked.PSet( + filterName = cms.untracked.string(''), + dataTier = cms.untracked.string('') + ) +) + +# Additional output definition + +# Other statements +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:startup', '') + +# enable debug message logging for our modules +process.MessageLogger = cms.Service( + "MessageLogger", + threshold = cms.untracked.string('DEBUG'), + categories = cms.untracked.vstring('L1T'), +# l1t = cms.untracked.PSet( +# threshold = cms.untracked.string('DEBUG') +# ), + debugModules = cms.untracked.vstring('*'), +# 'stage1Raw', +# 'caloStage1Digis' +# ), +# cout = cms.untracked.PSet( +# ) +) + +# TTree output file +process.load("CommonTools.UtilAlgos.TFileService_cfi") +process.TFileService.fileName = cms.string('l1t.root') + + +# user stuff + +# raw data from MP card +process.load('EventFilter.L1TRawToDigi.amc13DumpToRaw_cfi') +process.amc13DumpToRaw.filename = cms.untracked.string("../data/stage1_amc13_example.txt") +process.amc13DumpToRaw.fedId = cms.untracked.int32(1352) + +# dump raw data +process.dumpRaw = cms.EDAnalyzer( + "DumpFEDRawDataProduct", + label = cms.untracked.string("amc13DumpToRaw"), + feds = cms.untracked.vint32 ( 1352 ), + dumpPayload = cms.untracked.bool ( True ) +) + +# raw to digi +process.load('EventFilter.L1TRawToDigi.caloStage1Digis_cfi') +process.caloStage1Digis.InputLabel = cms.InputTag('amc13DumpToRaw') + +# Path and EndPath definitions +process.path = cms.Path( + process.amc13DumpToRaw + +process.dumpRaw + +process.caloStage1Digis +) + +process.out = cms.EndPath( + process.output +) diff --git a/EventFilter/L1TRawToDigi/test/test_AMCDumpToRaw_cfg.py b/EventFilter/L1TRawToDigi/test/test_AMCDumpToRaw_cfg.py new file mode 100644 index 0000000000000..adbb62ff2e4ed --- /dev/null +++ b/EventFilter/L1TRawToDigi/test/test_AMCDumpToRaw_cfg.py @@ -0,0 +1,100 @@ +# Auto generated configuration file +# using: +# Revision: 1.19 +# Source: /local/reps/CMSSW/CMSSW/Configuration/Applications/python/ConfigBuilder.py,v +# with command line options: SingleElectronPt10_cfi.py -s GEN,SIM,DIGI,L1 --pileup=NoPileUp --geometry DB --conditions=auto:startup -n 1 --no_exec +import FWCore.ParameterSet.Config as cms + +process = cms.Process('L1') + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.StandardSequences.GeometryRecoDB_cff') +process.load('Configuration.Geometry.GeometryDB_cff') +process.load('Configuration.StandardSequences.MagneticField_38T_cff') +process.load('Configuration.StandardSequences.SimL1Emulator_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(1) +) + +# Input source +process.source = cms.Source("EmptySource") + +process.options = cms.untracked.PSet( + SkipEvent = cms.untracked.vstring('ProductNotFound') +) + + +# Output definition + +process.output = cms.OutputModule( + "PoolOutputModule", + splitLevel = cms.untracked.int32(0), + eventAutoFlushCompressedSize = cms.untracked.int32(5242880), + outputCommands = cms.untracked.vstring("keep *", + "drop *_mix_*_*"), + fileName = cms.untracked.string('L1T_EDM.root'), + dataset = cms.untracked.PSet( + filterName = cms.untracked.string(''), + dataTier = cms.untracked.string('') + ) +) + +# Additional output definition + +# Other statements +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:startup', '') + +# enable debug message logging for our modules +process.MessageLogger = cms.Service( + "MessageLogger", + threshold = cms.untracked.string('DEBUG'), + categories = cms.untracked.vstring('L1T'), +# l1t = cms.untracked.PSet( +# threshold = cms.untracked.string('DEBUG') +# ), + debugModules = cms.untracked.vstring('*'), +# 'stage1Raw', +# 'caloStage1Digis' +# ), +# cout = cms.untracked.PSet( +# ) +) + +# TTree output file +process.load("CommonTools.UtilAlgos.TFileService_cfi") +process.TFileService.fileName = cms.string('l1t.root') + + +# user stuff + +# raw data from MP card +process.load('EventFilter.L1TRawToDigi.amcDumpToRaw_cfi') + +# dump raw data +process.dumpRaw = cms.EDAnalyzer( + "DumpFEDRawDataProduct", + label = cms.untracked.string("amcDumpToRaw"), + feds = cms.untracked.vint32 ( 1352 ), + dumpPayload = cms.untracked.bool ( True ) +) + +# raw to digi +process.load('EventFilter.L1TRawToDigi.caloStage1Digis_cfi') +process.caloStage1Digis.InputLabel = cms.InputTag('amcDumpToRaw') + +# Path and EndPath definitions +process.path = cms.Path( + process.amcDumpToRaw + +process.dumpRaw + +process.caloStage1Digis +) + +process.out = cms.EndPath( + process.output +) diff --git a/EventFilter/L1TRawToDigi/test/test_DigiToRawToDigi.py b/EventFilter/L1TRawToDigi/test/test_DigiToRawToDigi.py index 4187fd03f2f5b..19cd407f77374 100644 --- a/EventFilter/L1TRawToDigi/test/test_DigiToRawToDigi.py +++ b/EventFilter/L1TRawToDigi/test/test_DigiToRawToDigi.py @@ -5,7 +5,41 @@ # with command line options: SingleElectronPt10_cfi.py -s GEN,SIM,DIGI,L1 --pileup=NoPileUp --geometry DB --conditions=auto:startup -n 1 --no_exec import FWCore.ParameterSet.Config as cms -process = cms.Process('DIGI2RAW2DIGI') +import FWCore.ParameterSet.VarParsing as VarParsing +options = VarParsing.VarParsing('analysis') +options.register('skipEvents', + 0, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.int, + "Number of events to skip") +options.register('dumpRaw', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Print RAW data") +options.register('dumpDigis', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Print digis") +options.register('histos', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Produce standard histograms") +options.register('debug', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "More verbose output") +options.register('edm', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Produce EDM file") +options.parseArguments() + +process = cms.Process('Digi2Raw2Digi') # import of standard configurations process.load('Configuration.StandardSequences.Services_cff') @@ -17,16 +51,14 @@ process.load('Configuration.StandardSequences.EndOfProcess_cff') process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') -process.maxEvents = cms.untracked.PSet( - input = cms.untracked.int32(-1) +process.source = cms.Source ( + "PoolSource", + fileNames = cms.untracked.vstring (options.inputFiles), + skipEvents=cms.untracked.uint32(options.skipEvents) ) -# Input source -process.source = cms.Source( - "PoolSource", - # fileNames = cms.untracked.vstring("file:L1T_EDM.root") - # fileNames = cms.untracked.vstring("file:SimL1Emulator_Stage1_SimpleHW.root") - fileNames = cms.untracked.vstring("file:SimL1Emulator_Stage1_PP.root") +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(options.maxEvents) ) @@ -50,37 +82,38 @@ from Configuration.AlCa.GlobalTag import GlobalTag process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:startup', '') +process.dumpRaw = cms.EDAnalyzer( + "DumpFEDRawDataProduct", + label = cms.untracked.string("caloStage1Raw"), + feds = cms.untracked.vint32 ( 1352 ), + dumpPayload = cms.untracked.bool ( options.dumpRaw ) +) + # enable debug message logging for our modules process.MessageLogger = cms.Service( "MessageLogger", - destinations = cms.untracked.vstring( - 'detailedInfo', - 'critical' - ), - detailedInfo = cms.untracked.PSet( - threshold = cms.untracked.string('DEBUG') - ), - debugModules = cms.untracked.vstring( - 'l1tDigiToRaw', 'l1tRawToDigi' - ) + threshold = cms.untracked.string('INFO'), + categories = cms.untracked.vstring('L1T', 'L1TCaloEvents'), +# debugModules = cms.untracked.vstring( +# 'mp7BufferDumpToRaw', +# 'l1tDigis', +# 'caloStage1Digis' +# ) ) # user stuff -process.load("EventFilter.L1TRawToDigi.l1tDigiToRaw_cfi") -process.l1tDigiToRaw.Setup = cms.string("stage1::CaloSetup") -process.l1tDigiToRaw.InputLabel = cms.InputTag("simCaloStage1FinalDigis", "") -process.l1tDigiToRaw.TauInputLabel = cms.InputTag("simCaloStage1FinalDigis", "rlxTaus") -process.l1tDigiToRaw.IsoTauInputLabel = cms.InputTag("simCaloStage1FinalDigis", "isoTaus") -process.l1tDigiToRaw.HFBitCountsInputLabel = cms.InputTag("simCaloStage1FinalDigis", "HFBitCounts") -process.l1tDigiToRaw.HFRingSumsInputLabel = cms.InputTag("simCaloStage1FinalDigis", "HFRingSums") -process.load("EventFilter.L1TRawToDigi.l1tRawToDigi_cfi") -process.l1tRawToDigi.Setup = cms.string("stage1::CaloSetup") +process.load('EventFilter.L1TRawToDigi.caloStage1Raw_cfi') +process.load('EventFilter.L1TRawToDigi.caloStage1Digis_cfi') +process.newCaloStage1Digis = process.caloStage1Digis.clone() +process.newCaloStage1Digis.InputLabel = cms.InputTag('caloStage1Raw') +process.newCaloStage1Digis.debug = cms.untracked.bool(options.debug) # Path and EndPath definitions process.path = cms.Path( - process.l1tDigiToRaw - +process.l1tRawToDigi + process.caloStage1Raw + +process.dumpRaw + +process.newCaloStage1Digis ) process.out = cms.EndPath( diff --git a/EventFilter/L1TRawToDigi/test/test_MP7BufferDumpToRaw_Stage1.py b/EventFilter/L1TRawToDigi/test/test_MP7BufferDumpToRaw_Stage1.py index 9bde45c8061f9..ebe8b0b0d9715 100644 --- a/EventFilter/L1TRawToDigi/test/test_MP7BufferDumpToRaw_Stage1.py +++ b/EventFilter/L1TRawToDigi/test/test_MP7BufferDumpToRaw_Stage1.py @@ -75,8 +75,8 @@ # raw data from MP card process.load('EventFilter.L1TRawToDigi.stage1MP7BufferRaw_cfi') -process.stage1Raw.nFramesOffset = cms.untracked.vuint32(0,0) -process.stage1Raw.nFramesLatency = cms.untracked.vuint32(96,96) +process.stage1Raw.nFramesOffset = cms.untracked.vuint32(0) +process.stage1Raw.nFramesLatency = cms.untracked.vuint32(96) process.stage1Raw.rxFile = cms.untracked.string("stage1_rx_summary.txt") process.stage1Raw.txFile = cms.untracked.string("stage1_tx_summary.txt") diff --git a/EventFilter/L1TRawToDigi/test/test_MP7BufferDumpToRaw_Stage1_RCT.py b/EventFilter/L1TRawToDigi/test/test_MP7BufferDumpToRaw_Stage1_RCT.py index 6ed1c7da47022..4edce55d8d3f7 100644 --- a/EventFilter/L1TRawToDigi/test/test_MP7BufferDumpToRaw_Stage1_RCT.py +++ b/EventFilter/L1TRawToDigi/test/test_MP7BufferDumpToRaw_Stage1_RCT.py @@ -76,16 +76,16 @@ # raw data from MP card process.load('EventFilter.L1TRawToDigi.stage1MP7BufferRaw_cfi') process.stage1Raw.fedId = cms.untracked.int32(1300) -process.stage1Raw.amcId = cms.untracked.int32(0x100D) -process.stage1Raw.nFramesOffset = cms.untracked.int32(0) -process.stage1Raw.nFramesLatency = cms.untracked.int32(90) +process.stage1Raw.boardId = cms.untracked.vint32(0x100D) +process.stage1Raw.nFramesOffset = cms.untracked.vuint32(0) +process.stage1Raw.nFramesLatency = cms.untracked.vuint32(90) process.stage1Raw.rxFile = cms.untracked.string("stage1_rx_summary.txt") process.stage1Raw.txFile = cms.untracked.string("stage1_tx_summary.txt") process.stage1RawDelayed = process.stage1Raw.clone() -process.stage1RawDelayed.amcId = cms.untracked.int32(0x100E) +process.stage1RawDelayed.boardId = cms.untracked.vint32(0x100E) process.stage1RawDelayed.fedId = cms.untracked.int32(1301) -process.stage1RawDelayed.nFramesOffset = cms.untracked.int32(0) +process.stage1RawDelayed.nFramesOffset = cms.untracked.vuint32(0) process.load("EventFilter.RawDataCollector.rawDataCollector_cfi") process.rawDataCollector.RawCollectionList = cms.VInputTag( diff --git a/EventFilter/L1TRawToDigi/test/test_RawToDigi.py b/EventFilter/L1TRawToDigi/test/test_RawToDigi.py new file mode 100644 index 0000000000000..56751f05eb7af --- /dev/null +++ b/EventFilter/L1TRawToDigi/test/test_RawToDigi.py @@ -0,0 +1,113 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process('L1') + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.StandardSequences.GeometryRecoDB_cff') +process.load('Configuration.Geometry.GeometryDB_cff') +process.load('Configuration.StandardSequences.MagneticField_38T_cff') +process.load('Configuration.StandardSequences.SimL1Emulator_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(1) +) + +# Input source +process.source = cms.Source( + "PoolSource", + fileNames = cms.untracked.vstring([ + "/store/data/Run2015A/MinimumBias/RAW/v1/000/247/215/00000/04D76DE1-3C0C-E511-9821-02163E011DD9.root", + "/store/data/Run2015A/MinimumBias/RAW/v1/000/247/215/00000/2E9F5DD9-2B0C-E511-A51D-02163E01467B.root", + "/store/data/Run2015A/MinimumBias/RAW/v1/000/247/215/00000/30634843-2F0C-E511-9AB3-02163E0144C3.root", + "/store/data/Run2015A/MinimumBias/RAW/v1/000/247/215/00000/4825AFD3-2B0C-E511-93A8-02163E013496.root", + "/store/data/Run2015A/MinimumBias/RAW/v1/000/247/215/00000/9ED5038A-2E0C-E511-B66B-02163E0144F1.root", + "/store/data/Run2015A/MinimumBias/RAW/v1/000/247/215/00000/A826FAC5-3C0C-E511-A4CA-02163E013653.root", + "/store/data/Run2015A/MinimumBias/RAW/v1/000/247/215/00000/AE2CA338-3D0C-E511-9547-02163E0143EB.root", + "/store/data/Run2015A/MinimumBias/RAW/v1/000/247/215/00000/C81E3707-240C-E511-97CA-02163E01207D.root", + "/store/data/Run2015A/MinimumBias/RAW/v1/000/247/215/00000/E66FC716-3D0C-E511-8F99-02163E014204.root" + ]), + eventsToProcess = cms.untracked.VEventRange('247215:1-247215:MAX') +) + +process.options = cms.untracked.PSet( + SkipEvent = cms.untracked.vstring('ProductNotFound') +) + + +# Output definition + +process.output = cms.OutputModule( + "PoolOutputModule", + splitLevel = cms.untracked.int32(0), + eventAutoFlushCompressedSize = cms.untracked.int32(5242880), + outputCommands = cms.untracked.vstring("keep *", + "drop *_mix_*_*"), + fileName = cms.untracked.string('L1T_EDM.root'), + dataset = cms.untracked.PSet( + filterName = cms.untracked.string(''), + dataTier = cms.untracked.string('') + ) +) + +# Additional output definition + +# Other statements +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:startup', '') + +# enable debug message logging for our modules +process.MessageLogger = cms.Service( + "MessageLogger", + threshold = cms.untracked.string('DEBUG'), + categories = cms.untracked.vstring('L1T'), +# l1t = cms.untracked.PSet( +# threshold = cms.untracked.string('DEBUG') +# ), + debugModules = cms.untracked.vstring('*'), +# 'stage1Raw', +# 'caloStage1Digis' +# ), +# cout = cms.untracked.PSet( +# ) +) + +# TTree output file +process.load("CommonTools.UtilAlgos.TFileService_cfi") +process.TFileService.fileName = cms.string('l1t.root') + + +# user stuff + +# raw data from MP card +# process.load('EventFilter.L1TRawToDigi.amc13DumpToRaw_cfi') +# process.amc13DumpToRaw.filename = cms.untracked.string("../data/stage1_amc13_example.txt") +# process.amc13DumpToRaw.fedId = cms.untracked.int32(1352) + +# dump raw data +process.dumpRaw = cms.EDAnalyzer( + "DumpFEDRawDataProduct", + label = cms.untracked.string("rawDataCollector"), + feds = cms.untracked.vint32 ( 1352 ), + dumpPayload = cms.untracked.bool ( True ) +) + +# raw to digi +process.load('EventFilter.L1TRawToDigi.caloStage1Digis_cfi') +process.caloStage1Digis.InputLabel = cms.InputTag('rawDataCollector') +process.caloStage1Digis.debug = cms.untracked.bool(True) + +# Path and EndPath definitions +process.path = cms.Path( + # process.amc13DumpToRaw + # +process.dumpRaw + process.dumpRaw + +process.caloStage1Digis +) + +process.out = cms.EndPath( + process.output +) diff --git a/EventFilter/L1TRawToDigi/utils/unpackBuffers-CaloStage1.py b/EventFilter/L1TRawToDigi/utils/unpackBuffers-CaloStage1.py new file mode 100644 index 0000000000000..39cf8fb33f177 --- /dev/null +++ b/EventFilter/L1TRawToDigi/utils/unpackBuffers-CaloStage1.py @@ -0,0 +1,157 @@ +# Auto generated configuration file +# using: +# Revision: 1.19 +# Source: /local/reps/CMSSW/CMSSW/Configuration/Applications/python/ConfigBuilder.py,v +# with command line options: SingleElectronPt10_cfi.py -s GEN,SIM,DIGI,L1 --pileup=NoPileUp --geometry DB --conditions=auto:startup -n 1 --no_exec +import FWCore.ParameterSet.Config as cms + + +# options +import FWCore.ParameterSet.VarParsing as VarParsing +options = VarParsing.VarParsing('analysis') +options.register('skipEvents', + 0, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.int, + "Number of events to skip") +options.register('framesPerEvent', + 6, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.int, + "N frames per event") +options.register('offset', + 0, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.int, + "Jet board offset (frames)") +options.register('egLatency', + 0, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.int, + "EG board latency (frames)") +options.register('jetLatency', + 40, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.int, + "Jet board latency (frames)") +options.register('egDelay', + 54, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.int, + "EG input delay wrt regions (frames)") +options.register('dump', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Print RAW data") + + +options.parseArguments() + +if (options.maxEvents == -1): + options.maxEvents = 1 + + +process = cms.Process('Raw2Digi') + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.StandardSequences.GeometryRecoDB_cff') +process.load('Configuration.Geometry.GeometryDB_cff') +process.load('Configuration.StandardSequences.MagneticField_38T_cff') +process.load('Configuration.StandardSequences.SimL1Emulator_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(options.maxEvents) +) + +# Input source +process.source = cms.Source("EmptySource") + +process.options = cms.untracked.PSet( + SkipEvent = cms.untracked.vstring('ProductNotFound') +) + + +# Output definition +process.output = cms.OutputModule( + "PoolOutputModule", + outputCommands = cms.untracked.vstring("keep *"), + fileName = cms.untracked.string('l1tCalo_2015_EDM.root') +) + +# Additional output definition +# TTree output file +process.load("CommonTools.UtilAlgos.TFileService_cfi") +process.TFileService.fileName = cms.string('l1tCalo_2015_histos.root') + + +# enable debug message logging for our modules +process.MessageLogger = cms.Service( + "MessageLogger", + threshold = cms.untracked.string('DEBUG'), + categories = cms.untracked.vstring('L1T'), + debugModules = cms.untracked.vstring('*') +# 'mp7BufferDumpToRaw', +# 'l1tDigis', +# 'caloStage1Digis' +# ) +) + + +# Other statements +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:startup', '') + + +# buffer dump to RAW +process.load('EventFilter.L1TRawToDigi.stage1MP7BufferRaw_cfi') + +# skip events +jetOffset = options.offset + (options.skipEvents * options.framesPerEvent) +egOffset = jetOffset + options.egDelay + + +# print some debug info +print "egOffset = ", egOffset +print "jetOffset = ", jetOffset +print " " + + +# pack into arrays +latencies = [ options.jetLatency, options.egLatency ] +offsets = [ jetOffset, egOffset ] + +process.stage1Raw.nFramesPerEvent = cms.untracked.int32(options.framesPerEvent) +process.stage1Raw.nFramesOffset = cms.untracked.vuint32(offsets) +process.stage1Raw.nFramesLatency = cms.untracked.vuint32(latencies) +process.stage1Raw.rxFile = cms.untracked.string("rx_summary.txt") +process.stage1Raw.txFile = cms.untracked.string("tx_summary.txt") + +# dump raw data +process.dumpRaw = cms.EDAnalyzer( + "DumpFEDRawDataProduct", + label = cms.untracked.string("stage1Raw"), + feds = cms.untracked.vint32 ( 1352 ), + dumpPayload = cms.untracked.bool ( options.dump ) +) + +# raw to digi +process.load('EventFilter.L1TRawToDigi.caloStage1Digis_cfi') +process.caloStage1Digis.InputLabel = cms.InputTag('stage1Raw') + +# Path and EndPath definitions +process.path = cms.Path( + process.stage1Raw + +process.dumpRaw + +process.caloStage1Digis + +) + +process.out = cms.EndPath( + process.output +) + diff --git a/EventFilter/L1TRawToDigi/test/unpackBuffers-CaloStage2.py b/EventFilter/L1TRawToDigi/utils/unpackBuffers-CaloStage2.py similarity index 88% rename from EventFilter/L1TRawToDigi/test/unpackBuffers-CaloStage2.py rename to EventFilter/L1TRawToDigi/utils/unpackBuffers-CaloStage2.py index 68df2a65fecda..68cf9bf69e769 100644 --- a/EventFilter/L1TRawToDigi/test/unpackBuffers-CaloStage2.py +++ b/EventFilter/L1TRawToDigi/utils/unpackBuffers-CaloStage2.py @@ -29,13 +29,23 @@ VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "MP offset (frames)") +options.register('mpHeaderFrames', + 0, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.int, + "MP header frames in tx") +options.register('dmFramesPerEvent', + 6, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.int, + "Demux frames per event") options.register('dmLatency', 0, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "Demux latency (frames)") options.register('dmOffset', - 0, + 28, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "Demux offset (frames)") @@ -60,7 +70,7 @@ VarParsing.VarParsing.varType.bool, "Print RAW data") options.register('debug', - False, + True, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "Enable debug data") @@ -75,7 +85,7 @@ VarParsing.VarParsing.varType.bool, "Read demux data") options.register('doGT', - True, + False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "Read GT data") @@ -156,8 +166,10 @@ # buffer dump to RAW process.load('EventFilter.L1TRawToDigi.stage2MP7BufferRaw_cff') -mpOffsets = cms.untracked.vint32() +# skip events +dmOffset = options.dmOffset + (options.skipEvents * options.dmFramesPerEvent) +mpOffsets = cms.untracked.vint32() for i in range (0,options.nMP): offset = options.mpOffset + (options.skipEvents / options.nMP) if (i < options.skipEvents % options.nMP): @@ -186,8 +198,9 @@ process.stage2MPRaw.nFramesOffset = cms.untracked.vuint32(mpOffsets) process.stage2MPRaw.boardOffset = cms.untracked.int32(boardOffset) #process.stage2MPRaw.nFramesLatency = cms.untracked.vuint32(mpLatencies) -process.stage2MPRaw.rxFile = cms.untracked.string("merge/rx_summary.txt") -process.stage2MPRaw.txFile = cms.untracked.string("merge/tx_summary.txt") +process.stage2MPRaw.nHeaderFrames = cms.untracked.int32(options.mpHeaderFrames) +process.stage2MPRaw.rxFile = cms.untracked.string("mp_rx_summary.txt") +process.stage2MPRaw.txFile = cms.untracked.string("mp_tx_summary.txt") # Demux config if (options.doDemux): @@ -196,10 +209,11 @@ print "dmLatency = ", options.dmLatency print " " -process.stage2DemuxRaw.nFramesOffset = cms.untracked.vuint32(options.dmOffset) +process.stage2DemuxRaw.nFramesPerEvent = cms.untracked.int32(options.dmFramesPerEvent) +process.stage2DemuxRaw.nFramesOffset = cms.untracked.vuint32(dmOffset) process.stage2DemuxRaw.nFramesLatency = cms.untracked.vuint32(options.dmLatency) -process.stage2DemuxRaw.rxFile = cms.untracked.string("good/demux/rx_summary.txt") -process.stage2DemuxRaw.txFile = cms.untracked.string("good/demux/tx_summary.txt") +process.stage2DemuxRaw.rxFile = cms.untracked.string("demux_rx_summary.txt") +process.stage2DemuxRaw.txFile = cms.untracked.string("demux_tx_summary.txt") # GT config if (options.doGT): @@ -235,11 +249,9 @@ # object analyser process.load('L1Trigger.L1TCalorimeter.l1tStage2CaloAnalyzer_cfi') process.l1tStage2CaloAnalyzer.towerToken = cms.InputTag("caloStage2Digis") -process.l1tStage2CaloAnalyzer.clusterToken = cms.InputTag("caloStage2Digis") -process.l1tStage2CaloAnalyzer.egToken = cms.InputTag("caloStage2Digis") -process.l1tStage2CaloAnalyzer.tauToken = cms.InputTag("caloStage2Digis") -process.l1tStage2CaloAnalyzer.jetToken = cms.InputTag("caloStage2Digis") -process.l1tStage2CaloAnalyzer.etSumToken = cms.InputTag("caloStage2Digis") +process.l1tStage2CaloAnalyzer.clusterToken = cms.InputTag("None") +process.l1tStage2CaloAnalyzer.mpEGToken = cms.InputTag("None") +process.l1tStage2CaloAnalyzer.mpTauToken = cms.InputTag("None") # Path and EndPath definitions process.path = cms.Path( diff --git a/EventFilter/L1TRawToDigi/utils/unpackData-CaloStage1.py b/EventFilter/L1TRawToDigi/utils/unpackData-CaloStage1.py new file mode 100644 index 0000000000000..38206ab2a2c24 --- /dev/null +++ b/EventFilter/L1TRawToDigi/utils/unpackData-CaloStage1.py @@ -0,0 +1,201 @@ +# Auto generated configuration file +# using: +# Revision: 1.19 +# Source: /local/reps/CMSSW/CMSSW/Configuration/Applications/python/ConfigBuilder.py,v +# with command line options: SingleElectronPt10_cfi.py -s GEN,SIM,DIGI,L1 --pileup=NoPileUp --geometry DB --conditions=auto:startup -n 1 --no_exec +import FWCore.ParameterSet.Config as cms + + +# options +import FWCore.ParameterSet.VarParsing as VarParsing +options = VarParsing.VarParsing('analysis') +options.register('skipEvents', + 0, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.int, + "Number of events to skip") +options.register('streamer', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Use streamer file as input") +options.register('debug', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Print debug messages") +options.register('dumpRaw', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Print RAW data") +options.register('dumpDigis', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Print digis") +options.register('histos', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Produce standard histograms") +options.register('edm', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Produce EDM file") +options.register('valEvents', + False, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Filter on validation events") + + +options.parseArguments() + +process = cms.Process('Raw2Digi') + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.StandardSequences.GeometryRecoDB_cff') +process.load('Configuration.Geometry.GeometryDB_cff') +process.load('Configuration.StandardSequences.MagneticField_38T_cff') +process.load('Configuration.StandardSequences.SimL1Emulator_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +# Input source +if (options.streamer) : + process.source = cms.Source( + "NewEventStreamFileReader", + fileNames = cms.untracked.vstring (options.inputFiles), + skipEvents=cms.untracked.uint32(options.skipEvents) + ) +else : + process.source = cms.Source ( + "PoolSource", + fileNames = cms.untracked.vstring (options.inputFiles), + skipEvents=cms.untracked.uint32(options.skipEvents) + ) + +# N events +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(options.maxEvents) +) + + +process.options = cms.untracked.PSet( + SkipEvent = cms.untracked.vstring('ProductNotFound') +) + + +# enable debug message logging for our modules +process.load('FWCore.MessageService.MessageLogger_cfi') +process.MessageLogger.categories.append('L1TCaloEvents') +process.MessageLogger.suppressInfo = cms.untracked.vstring('Geometry', 'AfterSource') +if (options.dumpRaw or options.dumpDigis): + process.MessageLogger.infos.placeholder = cms.untracked.bool(False) + process.MessageLogger.infos.INFO = cms.untracked.PSet(limit = cms.untracked.int32(0)) + process.MessageLogger.infos.L1TCaloEvents = cms.untracked.PSet( + optionalPSet = cms.untracked.bool(True), + limit = cms.untracked.int32(10000) + ) + +if (options.debug): +# process.MessageLogger.debugModules = cms.untracked.vstring('L1TRawToDigi:caloStage2Digis', 'MP7BufferDumpToRaw:stage2MPRaw', 'MP7BufferDumpToRaw:stage2DemuxRaw') + process.MessageLogger.debugModules = cms.untracked.vstring('*') + process.MessageLogger.cerr.threshold = cms.untracked.string('DEBUG') + + + +# Other statements +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:startup', '') + + +# dump raw data +process.dumpRaw = cms.EDAnalyzer( + "DumpFEDRawDataProduct", + label = cms.untracked.string("rawDataCollector"), + feds = cms.untracked.vint32 ( 1352 ), + dumpPayload = cms.untracked.bool ( options.dumpRaw ) +) + +# validation event filter +process.load('EventFilter.L1TRawToDigi.validationEventFilter_cfi') + +# raw to digi +process.load('EventFilter.L1TRawToDigi.caloStage1Digis_cfi') +process.caloStage1Digis.InputLabel = cms.InputTag('rawDataCollector') + +# analyzer/dumper +process.load('L1Trigger.L1TCalorimeter.l1tStage2CaloAnalyzer_cfi') +process.load('L1Trigger.L1GctAnalyzer.dumpGctDigis_cfi') +process.load('L1Trigger.RegionalCaloTrigger.L1RCTTestAnalyzer_cfi') + +# Path and EndPath definitions +process.path = cms.Path( + process.validationEventFilter + +process.dumpRaw + +process.caloStage1Digis + +process.l1tStage2CaloAnalyzer + +process.L1RCTTestAnalyzer + +process.dumpGctDigis +) + +# enable validation event filtering +if (not options.valEvents): + process.path.remove(process.validationEventFilter) + +# optional histograms & text dump +if (options.dumpDigis or options.histos): + process.load("CommonTools.UtilAlgos.TFileService_cfi") + process.TFileService.fileName = cms.string('l1tCalo_histos.root') + + process.l1tStage2CaloAnalyzer.towerToken = cms.InputTag("None") + process.l1tStage2CaloAnalyzer.clusterToken = cms.InputTag("None") + process.l1tStage2CaloAnalyzer.mpEGToken = cms.InputTag("None") + process.l1tStage2CaloAnalyzer.mpJetToken = cms.InputTag("None") + process.l1tStage2CaloAnalyzer.mpTauToken = cms.InputTag("None") + process.l1tStage2CaloAnalyzer.mpEtSumToken = cms.InputTag("None") + process.l1tStage2CaloAnalyzer.egToken = cms.InputTag("caloStage1Digis") + process.l1tStage2CaloAnalyzer.jetToken = cms.InputTag("caloStage1Digis") + process.l1tStage2CaloAnalyzer.tauToken = cms.InputTag("caloStage1Digis","rlxTaus") + process.l1tStage2CaloAnalyzer.etSumToken = cms.InputTag("caloStage1Digis") + process.l1tStage2CaloAnalyzer.doText = cms.untracked.bool(options.dumpDigis) + process.l1tStage2CaloAnalyzer.doHistos = cms.untracked.bool(options.histos) + process.L1RCTTestAnalyzer.rctDigisLabel = cms.InputTag("caloStage1Digis") +else: + process.path.remove(process.l1tStage2CaloAnalyzer) + process.path.remove(process.L1RCTTestAnalyzer) + +if (options.dumpDigis): + process.dumpGctDigis.doRctEm = cms.untracked.bool(True) + process.dumpGctDigis.doRegions = cms.untracked.bool(True) + process.dumpGctDigis.doInternEm = cms.untracked.bool(False) + process.dumpGctDigis.doEm = cms.untracked.bool(False) + process.dumpGctDigis.doJets = cms.untracked.bool(False) + process.dumpGctDigis.doEnergySums = cms.untracked.bool(False) + process.dumpGctDigis.doFibres = cms.untracked.bool(False) + process.dumpGctDigis.doEmulated = cms.untracked.bool(False) + process.dumpGctDigis.doHardware = cms.untracked.bool(True) + process.dumpGctDigis.outFile = cms.untracked.string('') + process.dumpGctDigis.rawInput = cms.untracked.InputTag("caloStage1Digis") +else: + process.path.remove(process.dumpGctDigis) + + +# optional EDM file +if (options.edm): + process.output = cms.OutputModule( + "PoolOutputModule", + outputCommands = cms.untracked.vstring("keep *"), + fileName = cms.untracked.string('l1tCalo_EDM.root') + ) + + process.out = cms.EndPath( + process.output + ) + + diff --git a/HLTrigger/Configuration/python/customizeHLTforCMSSW.py b/HLTrigger/Configuration/python/customizeHLTforCMSSW.py index 0cc84e0029bab..d1a55cd607e33 100644 --- a/HLTrigger/Configuration/python/customizeHLTforCMSSW.py +++ b/HLTrigger/Configuration/python/customizeHLTforCMSSW.py @@ -95,6 +95,15 @@ def customiseFor7794(process): return process +# Removal of L1 Stage 1 unpacker configuration from config (PR #10087) +def customiseFor10087(process): + if hasattr(process, 'hltCaloStage1Digis'): + if hasattr(process.hltCaloStage1Digis, 'FWId'): + delattr(process.hltCaloStage1Digis, 'FWId') + if hasattr(process.hltCaloStage1Digis, 'FedId'): + delattr(process.hltCaloStage1Digis, 'FedId') + return process + # CMSSW version specific customizations def customiseHLTforCMSSW(process,menuType="GRun",fastSim=False): import os @@ -106,6 +115,7 @@ def customiseHLTforCMSSW(process,menuType="GRun",fastSim=False): process = customiseFor8356(process) process = customiseFor7966(process) process = customiseFor7794(process) + process = customiseFor10087(process) process = customizeHLTforNewJetCorrectors(process) return process diff --git a/L1Trigger/L1TCommon/python/customsPostLS1.py b/L1Trigger/L1TCommon/python/customsPostLS1.py index adbb2cbe59b3f..7e3558f7a8369 100644 --- a/L1Trigger/L1TCommon/python/customsPostLS1.py +++ b/L1Trigger/L1TCommon/python/customsPostLS1.py @@ -10,7 +10,8 @@ def customiseSimL1EmulatorForStage1(process): process.load("L1Trigger.L1TCommon.l1tDigiToRaw_cfi") - process.load("L1Trigger.L1TCommon.l1tRawToDigi_cfi") + process.load("EventFilter.L1TRawToDigi.caloStage1Digis_cfi") + process.load("L1Trigger.L1TCommon.caloStage1LegacyFormatDigis_cfi") process.load('L1Trigger.L1TCalorimeter.caloStage1Params_cfi') @@ -120,3 +121,11 @@ def customiseSimL1EmulatorForPostLS1_HI(process): # move to the heavy ions draft L1 menu once the HLT has been updated accordingly process = L1Menu_CollisionsHeavyIons2015_v0(process) return process + +# This (UNTESTED/UNUSED) should allow for unpacking RAW data created with legacy 74X MC. +def customiseL1RawToDigiFor74XMC(process): + if hasattr(process,'caloStage1Digis'): + process.caloStage1Digis.FWId = cms.uint32(0xff000000) + if hasattr(process,'hltCaloStage1Digis'): + process.hltCaloStage1Digis.FWId = cms.uint32(0xff000000) + return process diff --git a/L1Trigger/L1TCommon/python/l1tDigiToRaw_cfi.py b/L1Trigger/L1TCommon/python/l1tDigiToRaw_cfi.py index 2e5791427367f..0041003de8a7a 100644 --- a/L1Trigger/L1TCommon/python/l1tDigiToRaw_cfi.py +++ b/L1Trigger/L1TCommon/python/l1tDigiToRaw_cfi.py @@ -3,19 +3,16 @@ l1tDigiToRaw = cms.EDProducer( "L1TDigiToRaw", Setup = cms.string("stage1::CaloSetup"), - InputLabel = cms.InputTag("caloStage2FinalDigis"), + InputLabel = cms.InputTag("simCaloStage1FinalDigis"), + TauInputLabel = cms.InputTag("simCaloStage1FinalDigis", "rlxTaus"), + IsoTauInputLabel = cms.InputTag("simCaloStage1FinalDigis", "isoTaus"), + HFBitCountsInputLabel = cms.InputTag("simCaloStage1FinalDigis", "HFBitCounts"), + HFRingSumsInputLabel = cms.InputTag("simCaloStage1FinalDigis", "HFRingSums"), + RegionInputLabel = cms.InputTag("simRctDigis", ""), + EmCandInputLabel = cms.InputTag("simRctDigis", ""), FedId = cms.int32(1352), - FWId = cms.uint32(2) + FWId = cms.uint32(1), + lenSlinkHeader = cms.untracked.int32(8), + lenSlinkTrailer = cms.untracked.int32(8) ) -# -# Make some changes if running with the Stage 1 trigger -# -from Configuration.StandardSequences.Eras import eras -eras.stage1L1Trigger.toModify( l1tDigiToRaw, InputLabel = cms.InputTag("simCaloStage1FinalDigis", "") ) -eras.stage1L1Trigger.toModify( l1tDigiToRaw, TauInputLabel = cms.InputTag("simCaloStage1FinalDigis", "rlxTaus") ) -eras.stage1L1Trigger.toModify( l1tDigiToRaw, IsoTauInputLabel = cms.InputTag("simCaloStage1FinalDigis", "isoTaus") ) -eras.stage1L1Trigger.toModify( l1tDigiToRaw, HFBitCountsInputLabel = cms.InputTag("simCaloStage1FinalDigis", "HFBitCounts") ) -eras.stage1L1Trigger.toModify( l1tDigiToRaw, HFRingSumsInputLabel = cms.InputTag("simCaloStage1FinalDigis", "HFRingSums") ) -eras.stage1L1Trigger.toModify( l1tDigiToRaw, RegionInputLabel = cms.InputTag("simRctDigis", "") ) -eras.stage1L1Trigger.toModify( l1tDigiToRaw, EMCandInputLabel = cms.InputTag("simRctDigis", "") ) diff --git a/L1Trigger/L1TCommon/python/l1tRawToDigi_cfi.py b/L1Trigger/L1TCommon/python/l1tRawToDigi_cfi.py index e43661a11c2ac..64f26dda14e9f 100644 --- a/L1Trigger/L1TCommon/python/l1tRawToDigi_cfi.py +++ b/L1Trigger/L1TCommon/python/l1tRawToDigi_cfi.py @@ -1,10 +1,3 @@ -import FWCore.ParameterSet.Config as cms -caloStage1Digis = cms.EDProducer( - "L1TRawToDigi", - Setup = cms.string("stage1::CaloSetup"), - #InputLabel = cms.InputTag("l1tDigiToRaw"), - InputLabel = cms.InputTag("rawDataCollector"), - FedId = cms.int32(1352), - FWId = cms.untracked.int32(2) -) + +from EventFilter.L1TRawToDigi.caloStage1Digis_cfi import caloStage1Digis