-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[MTD]: BTL readout mapping - first implementation in CondFormats #51279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <use name="CondCore/ESSources"/> | ||
| <use name="FWCore/Utilities"/> | ||
| <use name="CondFormats/DataRecord"/> | ||
| <use name="CondFormats/MTDObjects"/> | ||
| <use name="rootrflx"/> | ||
| <flags EDM_PLUGIN="1"/> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #include "CondCore/ESSources/interface/registration_macros.h" | ||
|
|
||
| #include "CondFormats/MTDObjects/interface/BTLReadoutMap.h" | ||
| #include "CondFormats/DataRecord/interface/BTLReadoutMapRcd.h" | ||
|
|
||
| namespace { | ||
| struct initializeBtlReadoutMap { | ||
| void operator()(BTLReadoutMap& m) { m.initialize(); } | ||
| }; | ||
| } // namespace | ||
|
|
||
| REGISTER_PLUGIN_INIT(BTLReadoutMapRcd, BTLReadoutMap, initializeBtlReadoutMap); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #ifndef CondFormats_DataRecord_BTLReadoutMapRcd_h | ||
| #define CondFormats_DataRecord_BTLReadoutMapRcd_h | ||
|
|
||
| #include "FWCore/Framework/interface/EventSetupRecordImplementation.h" | ||
| #include "Geometry/Records/interface/MTDGeometryRecord.h" | ||
| #include "Geometry/Records/interface/MTDTopologyRcd.h" | ||
|
|
||
| #include "FWCore/Utilities/interface/mplVector.h" | ||
|
|
||
| class BTLReadoutMapRcd | ||
| : public edm::eventsetup::DependentRecordImplementation<BTLReadoutMapRcd, | ||
| edm::mpl::Vector<MTDDigiGeometryRecord, MTDTopologyRcd> > { | ||
| }; | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" | ||
| #include "CondFormats/DataRecord/interface/BTLReadoutMapRcd.h" | ||
|
|
||
| EVENTSETUP_RECORD_REG(BTLReadoutMapRcd); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <use name="FWCore/Utilities"/> | ||
| <use name="CondFormats/Serialization"/> | ||
| <use name="DataFormats/ForwardDetId"/> | ||
| <export> | ||
| <lib name="1"/> | ||
| </export> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #ifndef CondFormats_MTDObjects_BTLElectronicsId_h | ||
| #define CondFormats_MTDObjects_BTLElectronicsId_h | ||
|
|
||
| #include "CondFormats/Serialization/interface/Serializable.h" | ||
|
|
||
| #include <cstdint> | ||
| #include <iosfwd> | ||
|
|
||
| class BTLElectronicsId { | ||
| public: | ||
| // Bit layout: | ||
| // | ||
| // 0 - 4 : channelId 0..31 (5 bits) | ||
| // 5 - 9 : eLinkId 0..23 (5 bits) | ||
| // 10 - 16 : hsLinkId 0..127 (7 bits) | ||
| // 17 - 29 : fedId ? (13 bits) | ||
| // 30 - 31 : free for now | ||
|
|
||
| static constexpr uint32_t kChannelMask = 0x1F; // 5 bits | ||
| static constexpr uint32_t kELinkMask = 0x1F; // 5 bits | ||
| static constexpr uint32_t kHSLinkMask = 0x7F; // 7 bits | ||
| static constexpr uint32_t kFEDMask = 0x1FFF; // 13 bits | ||
|
|
||
| static constexpr unsigned kChannelShift = 0; | ||
| static constexpr unsigned kELinkShift = 5; | ||
| static constexpr unsigned kHSLinkShift = 10; | ||
| static constexpr unsigned kFEDShift = 17; | ||
|
|
||
| /** Default constructor **/ | ||
| BTLElectronicsId(); | ||
|
|
||
| /** Constructor from rawId **/ | ||
| explicit BTLElectronicsId(uint32_t rawid); | ||
|
|
||
| /** Constructor from (FED id, HS-link id, e-link id, tofhir channel id) **/ | ||
| BTLElectronicsId(int fedId, // sLinkId | ||
| int hsLinkId, | ||
| int eLinkId, | ||
| int channelId); | ||
|
|
||
| /// Accessors | ||
| int fedId() const { return (rawid_ >> kFEDShift) & kFEDMask; }; | ||
| int hsLinkId() const { return (rawid_ >> kHSLinkShift) & kHSLinkMask; }; | ||
| int eLinkId() const { return (rawid_ >> kELinkShift) & kELinkMask; }; | ||
| int channelId() const { return (rawid_ >> kChannelShift) & kChannelMask; } | ||
|
|
||
| uint32_t rawId() const { return rawid_; }; | ||
|
|
||
| bool operator==(const BTLElectronicsId&) const; | ||
| bool operator!=(const BTLElectronicsId&) const; | ||
|
|
||
| private: | ||
| uint32_t rawid_ = 0; | ||
|
|
||
| COND_SERIALIZABLE; | ||
| }; | ||
|
|
||
| std::ostream& operator<<(std::ostream&, const BTLElectronicsId&); | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #ifndef CondFormats_MTDObjects_BTLReadoutMap_h | ||
| #define CondFormats_MTDObjects_BTLReadoutMap_h | ||
|
|
||
| #include <cstdint> | ||
| #include <unordered_map> | ||
|
|
||
| #include "DataFormats/ForwardDetId/interface/BTLDetId.h" | ||
| #include "CondFormats/MTDObjects/interface/BTLElectronicsId.h" | ||
| #include "CondFormats/Serialization/interface/Serializable.h" | ||
|
|
||
| //------------------------------------------------------------ | ||
| // Electronics IDs corresponding to the two sides of one crystal | ||
| //------------------------------------------------------------ | ||
| struct BTLElectronicsIdPair { | ||
| BTLElectronicsId minus; | ||
| BTLElectronicsId plus; | ||
|
|
||
| COND_SERIALIZABLE; | ||
| }; | ||
|
|
||
| // ------------------------------------------------------------ | ||
| // Readout map: BTLDetId <-> BTLElectronicsId | ||
| // ------------------------------------------------------------ | ||
| class BTLReadoutMap { | ||
| public: | ||
| BTLReadoutMap(); | ||
| virtual ~BTLReadoutMap(); | ||
|
|
||
| // ---------------------------- | ||
| // Fill interface - inserts a new record in the readout map | ||
| // ---------------------------- | ||
| void add(const BTLDetId& detId, const BTLElectronicsIdPair& elecIds); | ||
|
|
||
| // ---------------------------- | ||
| // Forward lookup: DetId -> electronics | ||
| // ---------------------------- | ||
| BTLElectronicsIdPair getElectronicsId(const BTLDetId& detId) const; | ||
|
|
||
| // ---------------------------- | ||
| // Reverse lookup: electronics -> DetId | ||
| // ---------------------------- | ||
| BTLDetId getDetId(const BTLElectronicsId& elecId) const; | ||
|
|
||
| // ---------------------------- | ||
| // Utilities | ||
| // ---------------------------- | ||
| void initialize(); | ||
|
|
||
| void clear(); | ||
|
|
||
| int size() const { return detToElec_.size(); }; | ||
|
|
||
| private: | ||
| // forward mapping | ||
| std::unordered_map<uint32_t, BTLElectronicsIdPair> detToElec_; | ||
|
|
||
| // reverse mapping (packed electronics key -> detid) | ||
| std::unordered_map<uint32_t, uint32_t> elecToDet_ COND_TRANSIENT; | ||
|
|
||
| COND_SERIALIZABLE; | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include "CondFormats/MTDObjects/interface/BTLElectronicsId.h" | ||
|
|
||
| #include <ostream> | ||
|
|
||
| // ------------------------------------------------------------ | ||
| // Constructors | ||
| // ------------------------------------------------------------ | ||
| BTLElectronicsId::BTLElectronicsId() : rawid_(0) {} | ||
|
|
||
| BTLElectronicsId::BTLElectronicsId(uint32_t rawid) : rawid_(rawid) {} | ||
|
|
||
| BTLElectronicsId::BTLElectronicsId(int fed, int hsLink, int eLink, int channel) { | ||
| rawid_ = (static_cast<uint32_t>(fed) << kFEDShift) | (static_cast<uint32_t>(hsLink) << kHSLinkShift) | | ||
| (static_cast<uint32_t>(eLink) << kELinkShift) | (static_cast<uint32_t>(channel) << kChannelShift); | ||
| } | ||
|
|
||
| // ------------------------------------------------------------ | ||
| // Comparison operators | ||
| // ------------------------------------------------------------ | ||
|
|
||
| bool BTLElectronicsId::operator==(const BTLElectronicsId& other) const { return rawid_ == other.rawid_; } | ||
|
|
||
| bool BTLElectronicsId::operator!=(const BTLElectronicsId& other) const { return rawid_ != other.rawid_; } | ||
|
|
||
| // ------------------------------------------------------------ | ||
| // Stream operator | ||
| // ------------------------------------------------------------ | ||
|
|
||
| std::ostream& operator<<(std::ostream& os, const BTLElectronicsId& id) { | ||
| os << "BTLElectronicsId: " | ||
| << "rawId = " << static_cast<int>(id.rawId()) << ", FED Id = " << id.fedId() << ", HS-link = " << id.hsLinkId() | ||
| << ", e-link = " << id.eLinkId() << ", TOFHIR channel Id = " << id.channelId(); | ||
|
|
||
| return os; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| #include "FWCore/Utilities/interface/Exception.h" | ||
| #include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
| #include "CondFormats/MTDObjects/interface/BTLReadoutMap.h" | ||
|
|
||
| #include <stdexcept> | ||
| #include <ostream> | ||
|
|
||
| BTLReadoutMap::BTLReadoutMap() {} | ||
|
|
||
| BTLReadoutMap::~BTLReadoutMap() {} | ||
|
|
||
| // ------------------------------------------------------------------ | ||
| // Initialize - to build inverse map which is not stored persistently | ||
| // ------------------------------------------------------------------ | ||
| void BTLReadoutMap::initialize() { | ||
| elecToDet_.clear(); | ||
|
|
||
| for (const auto& entry : detToElec_) { | ||
| const uint32_t detId = entry.first; | ||
| const BTLElectronicsIdPair& elecIds = entry.second; | ||
|
|
||
| auto ret = elecToDet_.emplace(elecIds.minus.rawId(), detId); | ||
| if (!ret.second) { | ||
| throw cms::Exception("BTLReadoutMap::initialize()") << "Duplicate BTLElectronicsId (minus side)" << std::endl; | ||
| } | ||
|
|
||
| ret = elecToDet_.emplace(elecIds.plus.rawId(), detId); | ||
| if (!ret.second) { | ||
| throw cms::Exception("BTLReadoutMap::initialize()") << "Duplicate BTLElectronicsId (plus side)" << std::endl; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // ------------------------------------------------------------ | ||
| // Add full 2-channel mapping | ||
| // ------------------------------------------------------------ | ||
| void BTLReadoutMap::add(const BTLDetId& detId, const BTLElectronicsIdPair& elecIds) { | ||
| const uint32_t detKey = detId.rawId(); | ||
|
|
||
| // ---------------------------- | ||
| // Forward: det -> 2 channels | ||
| // ---------------------------- | ||
| if (detToElec_.find(detKey) != detToElec_.end()) { | ||
| throw cms::Exception("BTLReadoutMap::add()") << "Duplicate BTLDetId entry" << std::endl; | ||
| } | ||
|
|
||
| detToElec_[detKey] = elecIds; | ||
|
|
||
| // ---------------------------- | ||
| // Reverse: each channel -> det | ||
| // ---------------------------- | ||
|
|
||
| // -- minus side | ||
| const uint32_t minusKey = elecIds.minus.rawId(); | ||
| if (elecToDet_.find(minusKey) != elecToDet_.end()) { | ||
| throw cms::Exception("BTLReadoutMap::add()") << "Duplicate BTLElectronicsId entry (minus side): " << elecIds.minus; | ||
| } | ||
| elecToDet_[minusKey] = detKey; | ||
|
|
||
| // -- plus side | ||
| const uint32_t plusKey = elecIds.plus.rawId(); | ||
| if (elecToDet_.find(plusKey) != elecToDet_.end()) { | ||
| throw cms::Exception("BTLReadoutMap::add()") << "Duplicate BTLElectronicsId entry (plus side): " << elecIds.plus; | ||
| } | ||
| elecToDet_[plusKey] = detKey; | ||
| } | ||
|
|
||
| // ------------------------------------------------------------ | ||
| // Forward lookup | ||
| // ------------------------------------------------------------ | ||
| BTLElectronicsIdPair BTLReadoutMap::getElectronicsId(const BTLDetId& detId) const { | ||
| const auto it = detToElec_.find(detId.rawId()); | ||
|
|
||
| if (it == detToElec_.end()) { | ||
| throw cms::Exception("BTLReadoutMap::getElectronicsId") << "BTLDetId " << detId.rawId() << " not found! "; | ||
| } | ||
|
|
||
| return it->second; | ||
| } | ||
|
|
||
| // ------------------------------------------------------------ | ||
| // Reverse lookup | ||
| // ------------------------------------------------------------ | ||
| BTLDetId BTLReadoutMap::getDetId(const BTLElectronicsId& elecId) const { | ||
| const auto it = elecToDet_.find(elecId.rawId()); | ||
|
|
||
| if (it == elecToDet_.end()) { | ||
| throw cms::Exception("BTLReadoutMap::getElectronicsId") << "BTLElectronicsId " << elecId.rawId() << " not found! "; | ||
| } | ||
|
|
||
| return BTLDetId(it->second); | ||
| } | ||
|
|
||
| // ------------------------------------------------------------ | ||
| // clear | ||
| // ------------------------------------------------------------ | ||
| void BTLReadoutMap::clear() { | ||
| detToElec_.clear(); | ||
| elecToDet_.clear(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #include "CondFormats/MTDObjects/interface/BTLReadoutMap.h" | ||
| #include "FWCore/Utilities/interface/typelookup.h" | ||
|
|
||
| TYPELOOKUP_DATA_REG(BTLReadoutMap); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #include "CondFormats/MTDObjects/interface/BTLElectronicsId.h" | ||
| #include "CondFormats/MTDObjects/interface/BTLReadoutMap.h" | ||
|
|
||
| namespace CondFormats_MTDObjects { | ||
| struct dictionary { | ||
| BTLElectronicsId electronicsId; | ||
| BTLElectronicsIdPair electronicsIdPair; | ||
| BTLReadoutMap readoutMap; | ||
| std::unordered_map<unsigned int, BTLElectronicsIdPair> detToElec; | ||
| }; | ||
| } // namespace CondFormats_MTDObjects |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <lcgdict> | ||
| <class name="BTLElectronicsId"/> | ||
| <class name="BTLElectronicsIdPair"/> | ||
| <class name="BTLReadoutMap" class_version="0"> | ||
| <field name="detToElec_" mapping="blob" /> | ||
| </class> | ||
| <class name="std::unordered_map<uint32_t, BTLElectronicsIdPair>"/> | ||
| </lcgdict> |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for my understanding what is purpose of this file ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to this tutorial: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideCondObjectsTutorial the src/headers.h file is read by the serialization system to find the serializable classes and generate serialization code for them.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, thanks |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #include "CondFormats/MTDObjects/interface/BTLElectronicsId.h" | ||
| #include "CondFormats/MTDObjects/interface/BTLReadoutMap.h" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <use name="FWCore/Framework"/> | ||
| <use name="FWCore/MessageLogger"/> | ||
| <use name="FWCore/ParameterSet"/> | ||
| <use name="CondFormats/DataRecord"/> | ||
| <use name="DataFormats/ForwardDetId"/> | ||
| <use name="CondFormats/MTDObjects"/> | ||
| <use name="Geometry/MTDCommonData"/> | ||
| <use name="Geometry/MTDGeometryBuilder"/> | ||
| <export> | ||
| <lib name="1"/> | ||
| </export> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, just for my own understanding, shouldn't the file be named
BTLReadoutMap.ccinstead ofBTLReadouMap.cc?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Moanwar Yes, indeed. Thanks for spotting it.