Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CondCore/MTDPlugins/BuildFile.xml
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"/>
12 changes: 12 additions & 0 deletions CondCore/MTDPlugins/src/plugin.cc
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);
14 changes: 14 additions & 0 deletions CondFormats/DataRecord/interface/BTLReadoutMapRcd.h
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
4 changes: 4 additions & 0 deletions CondFormats/DataRecord/src/BTLReadoutMapRcd.cc
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);
6 changes: 6 additions & 0 deletions CondFormats/MTDObjects/BuildFile.xml
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>
60 changes: 60 additions & 0 deletions CondFormats/MTDObjects/interface/BTLElectronicsId.h
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
63 changes: 63 additions & 0 deletions CondFormats/MTDObjects/interface/BTLReadoutMap.h
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
35 changes: 35 additions & 0 deletions CondFormats/MTDObjects/src/BTLElectronicsId.cc
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;
}
100 changes: 100 additions & 0 deletions CondFormats/MTDObjects/src/BTLReadoutMap.cc

Copy link
Copy Markdown
Contributor

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.cc instead of BTLReadouMap.cc?

Copy link
Copy Markdown
Contributor Author

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.

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();
}
4 changes: 4 additions & 0 deletions CondFormats/MTDObjects/src/T_EventSetup_BTLReadoutMap.cc
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);
11 changes: 11 additions & 0 deletions CondFormats/MTDObjects/src/classes.h
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
8 changes: 8 additions & 0 deletions CondFormats/MTDObjects/src/classes_def.xml
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>
2 changes: 2 additions & 0 deletions CondFormats/MTDObjects/src/headers.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my understanding what is purpose of this file ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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"
11 changes: 11 additions & 0 deletions EventFilter/MTDRawToDigi/BuildFile.xml
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>
Loading