Skip to content

Commit

Permalink
Merge pull request #41916 from CTPPS/fo_nt2_PRs_backport130
Browse files Browse the repository at this point in the history
Backport for Totem T2, to be used in the special run at 25.6, consisting of #41472 , #41777 and #41859
  • Loading branch information
cmsbuild authored Jun 13, 2023
2 parents d78de1b + ae1d0c8 commit d77e58b
Show file tree
Hide file tree
Showing 38 changed files with 1,192 additions and 244 deletions.
91 changes: 88 additions & 3 deletions CalibPPS/ESProducers/plugins/TotemDAQMappingESSourceXML.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
#include "FWCore/Framework/interface/ESProducts.h"
Expand Down Expand Up @@ -85,6 +87,8 @@ class TotemDAQMappingESSourceXML : public edm::ESProducer, public edm::EventSetu
TotemDAQMappingESSourceXML(const edm::ParameterSet &);
~TotemDAQMappingESSourceXML() override;

static void fillDescriptions(edm::ConfigurationDescriptions &);

edm::ESProducts<std::unique_ptr<TotemDAQMapping>, std::unique_ptr<TotemAnalysisMask>> produce(const TotemReadoutRcd &);

private:
Expand All @@ -96,6 +100,9 @@ class TotemDAQMappingESSourceXML : public edm::ESProducer, public edm::EventSetu
//subdetector id for sampic
unsigned int sampicSubDetId;

//Unpack multiple channels per payload for T2
bool packedPayload;

/// the mapping files
std::vector<std::string> mappingFileNames;

Expand Down Expand Up @@ -201,6 +208,9 @@ class TotemDAQMappingESSourceXML : public edm::ESProducer, public edm::EventSetu
/// extracts VFAT's DAQ channel from XML attributes
TotemFramePosition ChipFramePosition(xercesc::DOMNode *chipnode);

/// extracts VFAT's DAQ channel from XML attributes for packed T2 payload
TotemT2FramePosition ChipT2FramePosition(xercesc::DOMNode *chipnode);

void GetChannels(xercesc::DOMNode *n, std::set<unsigned char> &channels);

bool RPNode(NodeType type) {
Expand Down Expand Up @@ -270,6 +280,7 @@ TotemDAQMappingESSourceXML::TotemDAQMappingESSourceXML(const edm::ParameterSet &
: verbosity(conf.getUntrackedParameter<unsigned int>("verbosity", 0)),
subSystemName(conf.getUntrackedParameter<string>("subSystem")),
sampicSubDetId(conf.getParameter<unsigned int>("sampicSubDetId")),
packedPayload(conf.getParameter<bool>("multipleChannelsPerPayload")),
currentBlock(0),
currentBlockValid(false) {
for (const auto &it : conf.getParameter<vector<ParameterSet>>("configuration")) {
Expand Down Expand Up @@ -861,14 +872,20 @@ void TotemDAQMappingESSourceXML::ParseTreeTotemT2(ParseType pType,
// parse tag attributes
unsigned int hw_id = 0;
bool hw_id_set = false;
unsigned int channel_in_payload = 0;
bool payload_set = false;
DOMNamedNodeMap *attr = child->getAttributes();

for (unsigned int j = 0; j < attr->getLength(); j++) {
DOMNode *a = attr->item(j);
if (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "hwId")) {
sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &hw_id);
sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%x", &hw_id);
hw_id_set = true;
}
if (packedPayload && (!strcmp(cms::xerces::toString(a->getNodeName()).c_str(), "pay"))) {
sscanf(cms::xerces::toString(a->getNodeValue()).c_str(), "%u", &channel_in_payload);
payload_set = true;
}
}

// content control
Expand All @@ -878,14 +895,28 @@ void TotemDAQMappingESSourceXML::ParseTreeTotemT2(ParseType pType,
if (!hw_id_set)
throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeTotemT2")
<< "hwId not given for element `" << cms::xerces::toString(child->getNodeName()) << "'";
if (packedPayload && (!payload_set))
throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeTotemT2")
<< "Payload position in fibre not given for element `" << cms::xerces::toString(child->getNodeName())
<< "'";

// store mapping data
const TotemFramePosition &framepos = ChipFramePosition(child);
const TotemT2FramePosition &framepos = (packedPayload ? ChipT2FramePosition(child) : TotemT2FramePosition());
const TotemFramePosition &frameposSingle = (packedPayload ? TotemFramePosition() : ChipFramePosition(child));
TotemVFATInfo vfatInfo;
vfatInfo.hwID = hw_id;
unsigned int arm = parentID / 10, plane = parentID % 10;
vfatInfo.symbolicID.symbolicID = TotemT2DetId(arm, plane, id);
if (verbosity > 2) {
edm::LogWarning("Totem") << "Print T2 frame pos (payload):" << framepos << " ("
<< (packedPayload ? "true" : "false") << ") hw_id / T2 DetID" << hw_id << "/"
<< TotemT2DetId(arm, plane, id) << endl;
}

mapping->insert(framepos, vfatInfo);
if (packedPayload)
mapping->insert(framepos, vfatInfo);
else
mapping->insert(frameposSingle, vfatInfo);

continue;
}
Expand Down Expand Up @@ -921,6 +952,30 @@ TotemFramePosition TotemDAQMappingESSourceXML::ChipFramePosition(xercesc::DOMNod

//----------------------------------------------------------------------------------------------------

TotemT2FramePosition TotemDAQMappingESSourceXML::ChipT2FramePosition(xercesc::DOMNode *chipnode) {
TotemT2FramePosition fp;
unsigned char attributeFlag = 0;

DOMNamedNodeMap *attr = chipnode->getAttributes();
for (unsigned int j = 0; j < attr->getLength(); j++) {
DOMNode *a = attr->item(j);
if (fp.setXMLAttribute(
cms::xerces::toString(a->getNodeName()), cms::xerces::toString(a->getNodeValue()), attributeFlag) > 1) {
throw cms::Exception("TotemDAQMappingESSourceXML")
<< "Unrecognized T2 tag `" << cms::xerces::toString(a->getNodeName()) << "' or incompatible value `"
<< cms::xerces::toString(a->getNodeValue()) << "'.";
}
}

if (!fp.checkXMLAttributeFlag(attributeFlag)) {
throw cms::Exception("TotemDAQMappingESSourceXML")
<< "Wrong/incomplete T2 DAQ channel specification (attributeFlag = " << attributeFlag << ").";
}

return fp;
}
//----------------------------------------------------------------------------------------------------

TotemDAQMappingESSourceXML::NodeType TotemDAQMappingESSourceXML::GetNodeType(xercesc::DOMNode *n) {
// common node types
if (Test(n, tagArm))
Expand Down Expand Up @@ -999,4 +1054,34 @@ void TotemDAQMappingESSourceXML::GetChannels(xercesc::DOMNode *n, set<unsigned c

//----------------------------------------------------------------------------------------------------

void TotemDAQMappingESSourceXML::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
// totemDAQMappingESSourceXML
edm::ParameterSetDescription desc;
desc.addUntracked<unsigned int>("verbosity", 0);
desc.addUntracked<std::string>("subSystem", "")->setComment("set it to: TrackingStrip, ...");
desc.add<unsigned int>("sampicSubDetId");
desc.add<bool>("multipleChannelsPerPayload", false);
{
edm::ParameterSetDescription vpsd1;
vpsd1.add<edm::EventRange>("validityRange", edm::EventRange(1, 0, 1, 1, 0, 0));
vpsd1.add<std::vector<std::string>>("mappingFileNames", {});
vpsd1.add<std::vector<std::string>>("maskFileNames", {});
std::vector<edm::ParameterSet> temp1;
temp1.reserve(1);
{
edm::ParameterSet temp2;
temp2.addParameter<edm::EventRange>("validityRange", edm::EventRange(1, 0, 1, 1, 0, 0));
temp2.addParameter<std::vector<std::string>>("mappingFileNames", {});
temp2.addParameter<std::vector<std::string>>("maskFileNames", {});
temp1.push_back(temp2);
}
desc.addVPSet("configuration", vpsd1, temp1)->setComment("validityRange, mappingFileNames and maskFileNames");
}
descriptions.add("totemDAQMappingESSourceXML", desc);
// or use the following to generate the label from the module's C++ type
//descriptions.addWithDefaultLabel(desc);
}

//----------------------------------------------------------------------------------------------------

DEFINE_FWK_EVENTSETUP_SOURCE(TotemDAQMappingESSourceXML);
17 changes: 0 additions & 17 deletions CalibPPS/ESProducers/python/totemDAQMappingESSourceXML_cfi.py

This file was deleted.

12 changes: 10 additions & 2 deletions CalibPPS/ESProducers/python/totemT2DAQMapping_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
totemDAQMappingESSourceXML = _xml.clone(
subSystem = "TotemT2",
configuration = cms.VPSet(
#old v2.1 T2 firmware test file
cms.PSet(
validityRange = cms.EventRange("1:min - 999999999:max"),
mappingFileNames = cms.vstring("CondFormats/PPSObjects/xml/mapping_totem_nt2_2021.xml"),
validityRange = cms.EventRange("1:min - 368022:max"),
mappingFileNames = cms.vstring("CondFormats/PPSObjects/xml/mapping_totem_nt2_2023.xml"),
maskFileNames = cms.vstring()
),
#final T2 mapping test files
cms.PSet(
validityRange = cms.EventRange("368023:min - 999999999:max"),
mappingFileNames = cms.vstring("CondFormats/PPSObjects/xml/mapping_totem_nt2_2023_final.xml"),
maskFileNames = cms.vstring()
)
),
sampicSubDetId = cms.uint32(6),
multipleChannelsPerPayload = True,
)
2 changes: 2 additions & 0 deletions CondFormats/PPSObjects/interface/TotemDAQMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define CondFormats_PPSObjects_TotemDAQMapping

#include "CondFormats/PPSObjects/interface/TotemFramePosition.h"
#include "CondFormats/PPSObjects/interface/TotemT2FramePosition.h"

#include "CondFormats/PPSObjects/interface/TotemSymbId.h"

Expand Down Expand Up @@ -51,6 +52,7 @@ class TotemDAQMapping {
std::map<uint8_t, TotemTimingPlaneChannelPair> totemTimingChannelMap;

void insert(const TotemFramePosition& fp, const TotemVFATInfo& vi);
void insert(const TotemT2FramePosition& fp2, const TotemVFATInfo& vi);

/// Given the hardware ID, returns the corresponding Plane, Channel pair (TotemTimingPlaneChannelPair)
const TotemTimingPlaneChannelPair getTimingChannel(const uint8_t hwId) const;
Expand Down
109 changes: 109 additions & 0 deletions CondFormats/PPSObjects/interface/TotemT2FramePosition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/****************************************************************************
*
* This is a part of the TOTEM offline software.
* Authors:
* Jan Kašpar ([email protected])
*
****************************************************************************/

#ifndef CondFormats_PPSObjects_TotemT2FramePosition
#define CondFormats_PPSObjects_TotemT2FramePosition
#include "CondFormats/PPSObjects/interface/TotemFramePosition.h"

#include <iostream>
#include <string>

/**
* Uniquely identifies the DAQ channel through which a VFAT frame has been received.
*
* The internal representation has the following structure:
* \verbatim
* | 32 bits raw position |
* | 12 bits | 2 bits | 10 bits | 4 bits | 4 bits |
* | empty | T2 payload | FED ID | GOH ID | index within fiber |
* \endverbatim
*
**/
class TotemT2FramePosition : public TotemFramePosition {
public:
static const unsigned int offsetPayload = 18, maskPayload = 0x3;

/// the preferred constructor
TotemT2FramePosition(unsigned short SubSystemId,
unsigned short TOTFEDId,
unsigned short OptoRxId,
unsigned short GOHId,
unsigned short IdxInFiber,
unsigned short payload)
: rawPosition(IdxInFiber << offsetIdxInFiber | GOHId << offsetGOHId | OptoRxId << offsetOptoRxId |
TOTFEDId << offsetTOTFEDId | SubSystemId << offsetSubSystemId | (payload + 1) << offsetPayload) {}

/// don't use this constructor unless you have a good reason
TotemT2FramePosition(unsigned int pos = 0) : rawPosition(pos) {}

~TotemT2FramePosition() {}

/// recomended getters and setters

unsigned short getFEDId() const { return (rawPosition >> offsetFEDId) & maskFEDId; }
unsigned short getPayload() const { return (((rawPosition >> offsetPayload) & maskPayload) - 1); }

void setFEDId(unsigned short v) {
v &= maskFEDId;
rawPosition &= 0xFFFFFFFF - (maskFEDId << offsetFEDId);
rawPosition |= (v << offsetFEDId);
}
void setPayload(unsigned short v) {
unsigned short av = (v + 1) & maskPayload;
rawPosition &= 0xFFFFFFFF - (maskPayload << offsetPayload);
rawPosition |= (av << offsetPayload);
}

unsigned short getGOHId() const { return (rawPosition >> offsetGOHId) & maskGOHId; }

void setGOHId(unsigned short v) {
v &= maskGOHId;
rawPosition &= 0xFFFFFFFF - (maskGOHId << offsetGOHId);
rawPosition |= (v << offsetGOHId);
}

unsigned short getIdxInFiber() const { return (rawPosition >> offsetIdxInFiber) & maskIdxInFiber; }

void setIdxInFiber(unsigned short v) {
v &= maskIdxInFiber;
rawPosition &= 0xFFFFFFFF - (maskIdxInFiber << offsetIdxInFiber);
rawPosition |= (v << offsetIdxInFiber);
}

/// the getters and setters below are deprecated

/// don't use this method unless you have a good reason
unsigned int getRawPosition() const { return rawPosition; }

bool operator<(const TotemT2FramePosition &pos) const { return (rawPosition < pos.rawPosition); }
bool operator<(const TotemFramePosition &pos) const { return (rawPosition < pos.getRawPosition()); }

bool operator==(const TotemT2FramePosition &pos) const { return (rawPosition == pos.rawPosition); }
bool operator==(const TotemFramePosition &pos) const { return (rawPosition == pos.getRawPosition()); }

/// Condensed representation of the DAQ channel.
/// prints 5-digit hex number, the digits correspond to SubSystem, TOTFED ID, OptoRx ID,
/// GOH ID, index within fiber in this order
friend std::ostream &operator<<(std::ostream &s, const TotemT2FramePosition &fp);

/// prints XML formatted DAQ channel to stdout
void printXML();

/// Sets attribute with XML name 'attribute' and value 'value'.
/// Also turns on attribute presents bit in the flag parameter
/// returns 0 if the attribute is known, non-zero value else
unsigned char setXMLAttribute(const std::string &attribute, const std::string &value, unsigned char &flag);

/// returns true if all attributes have been set
static bool checkXMLAttributeFlag(unsigned char flag) { return (flag == 0x3f); }

protected:
unsigned int rawPosition;
};

#endif
23 changes: 19 additions & 4 deletions CondFormats/PPSObjects/src/TotemDAQMapping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
****************************************************************************/

#include "FWCore/Utilities/interface/typelookup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "CondFormats/PPSObjects/interface/TotemDAQMapping.h"

Expand All @@ -25,15 +26,29 @@ std::ostream &operator<<(std::ostream &s, const TotemVFATInfo &vi) {
void TotemDAQMapping::insert(const TotemFramePosition &fp, const TotemVFATInfo &vi) {
auto it = VFATMapping.find(fp);
if (it != VFATMapping.end()) {
cerr << "WARNING in DAQMapping::insert > Overwriting entry at " << fp << ". Previous: " << endl
<< " " << VFATMapping[fp] << "," << endl
<< " new: " << endl
<< " " << vi << ". " << endl;
edm::LogWarning("Totem") << "WARNING in DAQMapping::insert > Overwriting entry at " << fp << ". Previous: "
<< " " << VFATMapping[fp] << ","
<< " new: "
<< " " << vi << ". " << endl;
}

VFATMapping[fp] = vi;
}

//----------------------------------------------------------------------------------------------------
void TotemDAQMapping::insert(const TotemT2FramePosition &fp2, const TotemVFATInfo &vi) {
const TotemFramePosition fp1(fp2.getRawPosition());
auto it = VFATMapping.find(fp1);
if (it != VFATMapping.end()) {
edm::LogWarning("Totem") << "WARNING in DAQMapping::insert > Overwriting T2 entry at " << fp2 << ". Previous: "
<< " " << VFATMapping[fp1] << ","
<< " new: "
<< " " << vi << ". " << endl;
}

VFATMapping[fp1] = vi;
}

//----------------------------------------------------------------------------------------------------

const TotemDAQMapping::TotemTimingPlaneChannelPair TotemDAQMapping::getTimingChannel(const uint8_t hwId) const {
Expand Down
Loading

0 comments on commit d77e58b

Please sign in to comment.