From 7bb6fed9f0d1fd922dc84bc8f51d8ea1eacdd425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ka=C5=A1par?= Date: Thu, 24 Mar 2016 14:31:34 +0100 Subject: [PATCH 1/2] Import from CTPPS repository: conditions formats needed for TOTEM RP raw-to-digi. --- .../DataRecord/interface/TotemReadoutRcd.h | 19 + CondFormats/DataRecord/src/TotemReadoutRcd.cc | 12 + CondFormats/TotemReadoutObjects/BuildFile.xml | 6 + .../interface/TotemAnalysisMask.h | 48 + .../interface/TotemDAQMapping.h | 52 + .../interface/TotemSymbId.h | 41 + .../TotemReadoutObjects/plugins/BuildFile.xml | 7 + .../plugins/PrintTotemDAQMapping.cc | 60 + .../plugins/TotemDAQMappingESSourceXML.cc | 1069 +++++++++++ .../python/TotemDAQMappingESSourceXML_cfi.py | 8 + .../src/TotemAnalysisMask.cc | 23 + .../src/TotemDAQMapping.cc | 45 + .../TotemReadoutObjects/src/TotemSymbId.cc | 29 + .../xml/totem_rp_210_mapping.xml | 789 +++++++++ .../xml/totem_rp_210far_220_mapping.xml | 1576 +++++++++++++++++ .../xml/totem_rp_220_mapping.xml | 790 +++++++++ .../xml/totem_rp_mask_example.xml | 533 ++++++ 17 files changed, 5107 insertions(+) create mode 100644 CondFormats/DataRecord/interface/TotemReadoutRcd.h create mode 100644 CondFormats/DataRecord/src/TotemReadoutRcd.cc create mode 100644 CondFormats/TotemReadoutObjects/BuildFile.xml create mode 100644 CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h create mode 100644 CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h create mode 100644 CondFormats/TotemReadoutObjects/interface/TotemSymbId.h create mode 100644 CondFormats/TotemReadoutObjects/plugins/BuildFile.xml create mode 100644 CondFormats/TotemReadoutObjects/plugins/PrintTotemDAQMapping.cc create mode 100644 CondFormats/TotemReadoutObjects/plugins/TotemDAQMappingESSourceXML.cc create mode 100644 CondFormats/TotemReadoutObjects/python/TotemDAQMappingESSourceXML_cfi.py create mode 100644 CondFormats/TotemReadoutObjects/src/TotemAnalysisMask.cc create mode 100644 CondFormats/TotemReadoutObjects/src/TotemDAQMapping.cc create mode 100644 CondFormats/TotemReadoutObjects/src/TotemSymbId.cc create mode 100644 CondFormats/TotemReadoutObjects/xml/totem_rp_210_mapping.xml create mode 100644 CondFormats/TotemReadoutObjects/xml/totem_rp_210far_220_mapping.xml create mode 100644 CondFormats/TotemReadoutObjects/xml/totem_rp_220_mapping.xml create mode 100644 CondFormats/TotemReadoutObjects/xml/totem_rp_mask_example.xml diff --git a/CondFormats/DataRecord/interface/TotemReadoutRcd.h b/CondFormats/DataRecord/interface/TotemReadoutRcd.h new file mode 100644 index 0000000000000..d23cb39524bec --- /dev/null +++ b/CondFormats/DataRecord/interface/TotemReadoutRcd.h @@ -0,0 +1,19 @@ +/**************************************************************************** +* +* This is a part of TOTEM offline software. +* Authors: +* Jan Kaspar (jan.kaspar@gmail.com) +* +****************************************************************************/ + +#ifndef TotemCondFormatsDataRecordTotemDAQMappingRecord_h +#define TotemCondFormatsDataRecordTotemDAQMappingRecord_h + +#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" + +/** + *\brief EventSetup record for TOTEM readout-related information. + **/ +class TotemReadoutRcd : public edm::eventsetup::EventSetupRecordImplementation {}; + +#endif diff --git a/CondFormats/DataRecord/src/TotemReadoutRcd.cc b/CondFormats/DataRecord/src/TotemReadoutRcd.cc new file mode 100644 index 0000000000000..1aaa4c4e96b0b --- /dev/null +++ b/CondFormats/DataRecord/src/TotemReadoutRcd.cc @@ -0,0 +1,12 @@ +/**************************************************************************** +* +* This is a part of TOTEM offline software. +* Authors: +* Jan Kaspar (jan.kaspar@gmail.com) +* +****************************************************************************/ + +#include "CondFormats/DataRecord/interface/TotemReadoutRcd.h" +#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" + +EVENTSETUP_RECORD_REG(TotemReadoutRcd); diff --git a/CondFormats/TotemReadoutObjects/BuildFile.xml b/CondFormats/TotemReadoutObjects/BuildFile.xml new file mode 100644 index 0000000000000..c9809e9492415 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/BuildFile.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h b/CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h new file mode 100644 index 0000000000000..edcc3d40c3402 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h @@ -0,0 +1,48 @@ +/**************************************************************************** +* +* This is a part of TOTEM offline software. +* Authors: +* Maciej Wróbel (wroblisko@gmail.com) +* Jan Kašpar (jan.kaspar@cern.ch) +* +****************************************************************************/ + +#ifndef _TotemAnalysisMask_h_ +#define _TotemAnalysisMask_h_ + +#include "CondFormats/TotemReadoutObjects/interface/TotemSymbId.h" + +#include +#include + +//---------------------------------------------------------------------------------------------------- + +/** + *\brief Contains data on masked channels of a VFAT. + */ +class TotemVFATAnalysisMask +{ + public: + TotemVFATAnalysisMask() : fullMask(false) {} + + /// whether all channels of the VFAT shall be masked + bool fullMask; + + /// list of channels to be masked + std::set maskedChannels; +}; + +//---------------------------------------------------------------------------------------------------- + +/** + *\brief Channel-mask mapping. + **/ +class TotemAnalysisMask +{ + public: + std::map analysisMask; + + void Insert(const TotemSymbID &sid, const TotemVFATAnalysisMask &vam); +}; + +#endif diff --git a/CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h b/CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h new file mode 100644 index 0000000000000..e35322fbd88a8 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h @@ -0,0 +1,52 @@ +/**************************************************************************** +* +* This is a part of TOTEM offline software. +* Authors: +* Maciej Wróbel (wroblisko@gmail.com) +* Jan Kašpar (jan.kaspar@cern.ch) +* +****************************************************************************/ + +#ifndef _TotemDAQMapping_h_ +#define _TotemDAQMapping_h_ + +#include "DataFormats/TotemRawData/interface/TotemFramePosition.h" + +#include "CondFormats/TotemReadoutObjects/interface/TotemSymbId.h" + +#include + +//---------------------------------------------------------------------------------------------------- + +/** + *\brief Contains mappind data related to a VFAT. + */ +class TotemVFATInfo +{ + public: + /// is data of coincidence-chip VFAT + enum {data, CC} type; + + /// the symbolic id + TotemSymbID symbolicID; + + /// the hardware ID (16 bit) + unsigned int hwID; + + friend std::ostream& operator << (std::ostream& s, const TotemVFATInfo &fp); +}; + +//---------------------------------------------------------------------------------------------------- + +/** + *\brief The mapping between FramePosition and VFATInfo. + */ +class TotemDAQMapping +{ + public: + std::map VFATMapping; + + void Insert(const TotemFramePosition &fp, const TotemVFATInfo &vi); +}; + +#endif diff --git a/CondFormats/TotemReadoutObjects/interface/TotemSymbId.h b/CondFormats/TotemReadoutObjects/interface/TotemSymbId.h new file mode 100644 index 0000000000000..f186c93daec35 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/interface/TotemSymbId.h @@ -0,0 +1,41 @@ +/**************************************************************************** +* +* This is a part of TOTEM offline software. +* Authors: +* Jan Kašpar (jan.kaspar@cern.ch) +* +****************************************************************************/ + +#ifndef _TotemSymbId_h_ +#define _TotemSymbId_h_ + +#include + +/** + *\brief Symbolic ID describing an entity of a TOTEM subdetector. + **/ +class TotemSymbID +{ + public: + /// identifies the TOTEM subsystem + enum {RP, T1, T2} subSystem; + + /// integer-encoded symbolic ID + unsigned int symbolicID; + + bool operator < (const TotemSymbID &sid) const + { + if (subSystem == sid.subSystem) + return (symbolicID < sid.symbolicID); + return (subSystem < sid.subSystem); + } + + bool operator == (const TotemSymbID &sid) const + { + return ((subSystem==sid.subSystem) && (symbolicID==sid.symbolicID)); + } + + friend std::ostream& operator << (std::ostream& s, const TotemSymbID &sid); +}; + +#endif diff --git a/CondFormats/TotemReadoutObjects/plugins/BuildFile.xml b/CondFormats/TotemReadoutObjects/plugins/BuildFile.xml new file mode 100644 index 0000000000000..653b699f384a9 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/plugins/BuildFile.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/CondFormats/TotemReadoutObjects/plugins/PrintTotemDAQMapping.cc b/CondFormats/TotemReadoutObjects/plugins/PrintTotemDAQMapping.cc new file mode 100644 index 0000000000000..bc9d928fbcb32 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/plugins/PrintTotemDAQMapping.cc @@ -0,0 +1,60 @@ +/**************************************************************************** +* +* This is a part of TOTEM offline software. +* Authors: +* Jan Kašpar (jan.kaspar@gmail.com) +* +****************************************************************************/ + +#include "FWCore/Framework/interface/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/ESHandle.h" + +#include "CondFormats/DataRecord/interface/TotemReadoutRcd.h" +#include "CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h" +#include "CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h" + +//---------------------------------------------------------------------------------------------------- + +/** + *\brief Prints the DAQ mapping loaded by DAQMappingSourceXML. + **/ +class PrintTotemDAQMapping : public edm::EDAnalyzer +{ + public: + PrintTotemDAQMapping(const edm::ParameterSet &ps) {} + ~PrintTotemDAQMapping() {} + + private: + virtual void beginRun(edm::Run const&, edm::EventSetup const&); + virtual void analyze(const edm::Event &e, const edm::EventSetup &es) {} + virtual void endJob() {} +}; + +using namespace std; +using namespace edm; + +//---------------------------------------------------------------------------------------------------- + +void PrintTotemDAQMapping::beginRun(edm::Run const&, edm::EventSetup const& es) +{ + // get mapping + ESHandle mapping; + es.get().get(mapping); + + // get analysis mask to mask channels + ESHandle analysisMask; + es.get().get(analysisMask); + + for (const auto &p : mapping->VFATMapping) + { + cout << p.first << " -> " << p.second << endl; + } +} + +//---------------------------------------------------------------------------------------------------- + +DEFINE_FWK_MODULE(PrintTotemDAQMapping); diff --git a/CondFormats/TotemReadoutObjects/plugins/TotemDAQMappingESSourceXML.cc b/CondFormats/TotemReadoutObjects/plugins/TotemDAQMappingESSourceXML.cc new file mode 100644 index 0000000000000..15365e0e83503 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/plugins/TotemDAQMappingESSourceXML.cc @@ -0,0 +1,1069 @@ +/**************************************************************************** +* +* This is a part of TOTEM offline software. +* Authors: +* Maciej Wróbel (wroblisko@gmail.com) +* Jan Kašpar (jan.kaspar@cern.ch) +* Marcin Borratynski (mborratynski@gmail.com) +* +****************************************************************************/ + +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/SourceFactory.h" +#include "FWCore/Framework/interface/ModuleFactory.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/ESProducer.h" +#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h" +#include "FWCore/Framework/interface/ESProducts.h" +#include "FWCore/Framework/interface/SourceFactory.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include "DataFormats/TotemRawData/interface/TotemFramePosition.h" + +#include "CondFormats/DataRecord/interface/TotemReadoutRcd.h" +#include "CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h" +#include "CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h" + +#include +#include +#include +#include +#include + +#include +#include + +//#define DEBUG 1 + +//---------------------------------------------------------------------------------------------------- + +using namespace std; + +/** + * \brief Loads TotemDAQMapping and TotemAnalysisMask from two XML files. + **/ +class TotemDAQMappingESSourceXML: public edm::ESProducer, public edm::EventSetupRecordIntervalFinder +{ +public: + static const std::string tagVFAT; + static const std::string tagChannel; + static const std::string tagAnalysisMask; + + /// Common position tags + static const std::string tagArm; + + /// RP XML tags + static const std::string tagRPStation; + static const std::string tagRPPot; + static const std::string tagRPPlane; + + /// T2 XML tags + static const std::string tagT2; + static const std::string tagT2Half; + static const std::string tagT2detector; + + /// T1 XML tags + static const std::string tagT1; + static const std::string tagT1Arm; + static const std::string tagT1Plane; + static const std::string tagT1CSC; + static const std::string tagT1ChannelType; + + /// COMMON Chip XML tags + static const std::string tagChip1; + static const std::string tagChip2; + static const std::string tagTriggerVFAT1; + + TotemDAQMappingESSourceXML(const edm::ParameterSet &); + ~TotemDAQMappingESSourceXML(); + + edm::ESProducts< boost::shared_ptr, boost::shared_ptr > produce( const TotemReadoutRcd & ); + +private: + unsigned int verbosity; + + /// the mapping files + std::vector mappingFileNames; + + /// the mask files + std::vector maskFileNames; + + /// enumeration of XML node types + enum NodeType { nUnknown, nTop, nArm, nRPStation, nRPPot, nRPPlane, nChip, nTriggerVFAT, + nT2, nT2Half, nT2Det, nT1, nT1Arm, nT1Plane, nT1CSC, nT1ChannelType, nChannel }; + + /// whether to parse a mapping of a mask XML + enum ParseType { pMapping, pMask }; + + /// parses XML file + void ParseXML(ParseType, const string &file, const boost::shared_ptr&, const boost::shared_ptr&); + + /// recursive method to extract RP-related information from the DOM tree + void ParseTreeRP(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, + const boost::shared_ptr&, const boost::shared_ptr&); + + /// recursive method to extract RP-related information from the DOM tree + void ParseTreeT1(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, + const boost::shared_ptr&, const boost::shared_ptr&, + unsigned int T1Arm, unsigned int T1Plane, unsigned int T1CSC); + + /// recursive method to extract RP-related information from the DOM tree + void ParseTreeT2(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, + const boost::shared_ptr&, const boost::shared_ptr&); + +private: + /// adds the path prefix, if needed + string CompleteFileName(const string &fn); + + /// returns the top element from an XML file + xercesc::DOMDocument* GetDOMDocument(string file); + + /// returns true iff the node is of the given name + bool Test(xercesc::DOMNode *node, const std::string &name) + { + return !(name.compare(xercesc::XMLString::transcode(node->getNodeName()))); + } + + /// determines node type + NodeType GetNodeType(xercesc::DOMNode *); + + /// returns the content of the node + string GetNodeContent(xercesc::DOMNode *parent) + { + return string(xercesc::XMLString::transcode(parent->getTextContent())); + } + + /// returns the value of the node + string GetNodeValue(xercesc::DOMNode *node) + { + return string(xercesc::XMLString::transcode(node->getNodeValue())); + } + + /// extracts VFAT's DAQ channel from XML attributes + TotemFramePosition ChipFramePosition(xercesc::DOMNode *chipnode); + + void GetChannels(xercesc::DOMNode *n, std::set &channels); + + bool RPNode(NodeType type) + { + return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nRPPlane)||(type == nChip)||(type == nTriggerVFAT)); + } + + bool T2Node(NodeType type) + { + return ((type==nT2)||(type==nT2Det)|| (type==nT2Half)); + } + + bool T1Node(NodeType type) + { + return ((type==nT1)||(type==nT1Arm)|| (type==nT1Plane) || (type==nT1CSC) || (type==nT1ChannelType)); + } + + bool CommonNode(NodeType type) + { + return ((type==nChip)||(type==nArm)); + } + +protected: + /// sets infinite validity of this data + virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&, const edm::IOVSyncValue&, edm::ValidityInterval&); +}; + +//---------------------------------------------------------------------------------------------------- + +using namespace std; +using namespace edm; +using namespace xercesc; + +const string TotemDAQMappingESSourceXML::tagVFAT="vfat"; +const string TotemDAQMappingESSourceXML::tagChannel="channel"; +const string TotemDAQMappingESSourceXML::tagAnalysisMask="analysisMask"; + +// common XML position tags +const string TotemDAQMappingESSourceXML::tagArm = "arm"; + +// common XML Chip tags +const string TotemDAQMappingESSourceXML::tagChip1 = "vfat"; +const string TotemDAQMappingESSourceXML::tagChip2 = "test_vfat"; +const string TotemDAQMappingESSourceXML::tagTriggerVFAT1 = "trigger_vfat"; + +// specific RP XML tags +const string TotemDAQMappingESSourceXML::tagRPStation = "station"; +const string TotemDAQMappingESSourceXML::tagRPPot = "rp_detector_set"; +const string TotemDAQMappingESSourceXML::tagRPPlane = "rp_plane"; + +// specific T2 XML tags +const string TotemDAQMappingESSourceXML::tagT2="t2_detector_set"; +const string TotemDAQMappingESSourceXML::tagT2detector="t2_detector"; +const string TotemDAQMappingESSourceXML::tagT2Half="t2_half"; + +// specific T1 XML tags +const string TotemDAQMappingESSourceXML::tagT1="t1_detector_set"; +const string TotemDAQMappingESSourceXML::tagT1Arm="t1_arm"; +const string TotemDAQMappingESSourceXML::tagT1Plane="t1_plane"; +const string TotemDAQMappingESSourceXML::tagT1CSC="t1_csc"; +const string TotemDAQMappingESSourceXML::tagT1ChannelType="t1_channel_type"; + +//---------------------------------------------------------------------------------------------------- + +TotemDAQMappingESSourceXML::TotemDAQMappingESSourceXML(const edm::ParameterSet& conf) : + verbosity(conf.getUntrackedParameter("verbosity", 0)), + mappingFileNames(conf.getUntrackedParameter< vector >("mappingFileNames")), + maskFileNames(conf.getUntrackedParameter< vector >("maskFileNames")) +{ + setWhatProduced(this); + findingRecord(); +} + +//---------------------------------------------------------------------------------------------------- + +string TotemDAQMappingESSourceXML::CompleteFileName(const string &fn) +{ + char *cmsswPath = getenv("CMSSW_BASE"); + if (cmsswPath && fn[0] != '/' && fn[0] != '.') + return string(cmsswPath) + string("/src/") + fn; + else + return fn; +} + +//---------------------------------------------------------------------------------------------------- + +void TotemDAQMappingESSourceXML::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&, + const edm::IOVSyncValue& iosv, edm::ValidityInterval& oValidity) +{ + ValidityInterval infinity(iosv.beginOfTime(), iosv.endOfTime()); + oValidity = infinity; +} + +//---------------------------------------------------------------------------------------------------- + +DOMDocument* TotemDAQMappingESSourceXML::GetDOMDocument(string file) +{ + XercesDOMParser* parser = new XercesDOMParser(); + //parser->setValidationScheme(XercesDOMParser::Val_Always); + //parser->setDoNamespaces(true); + + try { + parser->parse(file.c_str()); + } + catch (...) { + throw cms::Exception("TotemDAQMappingESSourceXML::GetDOMDocument") << "Cannot parse file `" << file + << "' (exception)." << endl; + } + + if (!parser) + throw cms::Exception("TotemDAQMappingESSourceXML::GetDOMDocument") << "Cannot parse file `" << file + << "' (parser = NULL)." << endl; + + DOMDocument* xmlDoc = parser->getDocument(); + + if (!xmlDoc) + throw cms::Exception("TotemDAQMappingESSourceXML::GetDOMDocument") << "Cannot parse file `" << file + << "' (xmlDoc = NULL)." << endl; + + return xmlDoc; +} + +//---------------------------------------------------------------------------------------------------- + +TotemDAQMappingESSourceXML::~TotemDAQMappingESSourceXML() +{ +} + +//---------------------------------------------------------------------------------------------------- + +edm::ESProducts< boost::shared_ptr, boost::shared_ptr > + TotemDAQMappingESSourceXML::produce( const TotemReadoutRcd & ) +{ + boost::shared_ptr mapping(new TotemDAQMapping()); + boost::shared_ptr mask(new TotemAnalysisMask()); + + // initialize Xerces + try + { + XMLPlatformUtils::Initialize(); + } + catch (const XMLException& toCatch) + { + char* message = XMLString::transcode(toCatch.getMessage()); + throw cms::Exception("TotemDAQMappingESSourceXML") << "An XMLException caught with message: " << message << ".\n"; + XMLString::release(&message); + } + + // load mapping files + for (unsigned int i = 0; i < mappingFileNames.size(); ++i) + ParseXML(pMapping, CompleteFileName(mappingFileNames[i]), mapping, mask); + + // load mask files + for (unsigned int i = 0; i < maskFileNames.size(); ++i) + ParseXML(pMask, CompleteFileName(maskFileNames[i]), mapping, mask); + + // release Xerces + XMLPlatformUtils::Terminate(); + + // commit the products + return edm::es::products(mapping, mask); +} + +//---------------------------------------------------------------------------------------------------- + +void TotemDAQMappingESSourceXML::ParseXML(ParseType pType, const string &file, + const boost::shared_ptr &mapping, const boost::shared_ptr &mask) +{ + DOMDocument* domDoc = GetDOMDocument(file); + DOMElement* elementRoot = domDoc->getDocumentElement(); + + if (!elementRoot) + throw cms::Exception("TotemDAQMappingESSourceXML::ParseMappingXML") << "File `" << + file << "' is empty." << endl; + + ParseTreeRP(pType, elementRoot, nTop, 0, mapping, mask); + ParseTreeT2(pType, elementRoot, nTop, 0, mapping, mask); + ParseTreeT1(pType, elementRoot, nTop, 0, mapping, mask, 0,0,0); +} + +//----------------------------------------------------------------------------------------------------------- + +void TotemDAQMappingESSourceXML::ParseTreeRP(ParseType pType, xercesc::DOMNode * parent, NodeType parentType, + unsigned int parentID, const boost::shared_ptr& mapping, + const boost::shared_ptr& mask) +{ +#ifdef DEBUG + printf(">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n", XMLString::transcode(parent->getNodeName()), + parentType, parentID); +#endif + + DOMNodeList *children = parent->getChildNodes(); + + for (unsigned int i = 0; i < children->getLength(); i++) + { + DOMNode *n = children->item(i); + if (n->getNodeType() != DOMNode::ELEMENT_NODE) + continue; + + NodeType type = GetNodeType(n); + +#ifdef DEBUG + printf("\tname = %s, type = %u\n", XMLString::transcode(n->getNodeName()), type); +#endif + + // structure control + if (!RPNode(type)) + continue; + + if ((type != parentType + 1)&&(parentType != nRPPot || type != nTriggerVFAT)) + { + if (parentType == nTop && type == nRPPot) + { + LogPrint("TotemDAQMappingESSourceXML") << ">> TotemDAQMappingESSourceXML::ParseTreeRP > Warning: tag `" << tagRPPot + << "' found in global scope, assuming station ID = 12."; + parentID = 12; + } else { + throw cms::Exception("TotemDAQMappingESSourceXML") << "Node " << XMLString::transcode(n->getNodeName()) + << " not allowed within " << XMLString::transcode(parent->getNodeName()) << " block.\n"; + } + } + + // parse tag attributes + unsigned int id = 0, hw_id = 0; + bool id_set = false, hw_id_set = false; + bool fullMask = false; + DOMNamedNodeMap* attr = n->getAttributes(); + + for (unsigned int j = 0; j < attr->getLength(); j++) + { + DOMNode *a = attr->item(j); + + if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) + { + sscanf(XMLString::transcode(a->getNodeValue()), "%u", &id); + id_set = true; + } + + if (!strcmp(XMLString::transcode(a->getNodeName()), "hw_id")) + { + sscanf(XMLString::transcode(a->getNodeValue()), "%x", &hw_id); + hw_id_set = true; + } + + if (!strcmp(XMLString::transcode(a->getNodeName()), "full_mask")) + fullMask = (strcmp(XMLString::transcode(a->getNodeValue()), "no") != 0); + } + + // content control + if (!id_set && type != nTriggerVFAT) + throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP") << "id not given for element `" + << XMLString::transcode(n->getNodeName()) << "'" << endl; + + if (!hw_id_set && type == nChip && pType == pMapping) + throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP") << "hw_id not given for element `" + << XMLString::transcode(n->getNodeName()) << "'" << endl; + + if (type == nRPPlane && id > 9) + throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeRP") << + "Plane IDs range from 0 to 9. id = " << id << " is invalid." << endl; + +#ifdef DEBUG + printf("\tID found: 0x%x\n", id); +#endif + + // store mapping data + if (pType == pMapping && (type == nChip || type == nTriggerVFAT)) + { + const TotemFramePosition &framepos = ChipFramePosition(n); + TotemVFATInfo vfatInfo; + vfatInfo.hwID = hw_id; + vfatInfo.symbolicID.subSystem = TotemSymbID::RP; + + if (type == nChip) + { + vfatInfo.symbolicID.symbolicID = parentID * 10 + id; + vfatInfo.type = TotemVFATInfo::data; + } + + if (type == nTriggerVFAT) + { + vfatInfo.symbolicID.symbolicID = parentID; + vfatInfo.type = TotemVFATInfo::CC; + } + + mapping->Insert(framepos, vfatInfo); + + continue; + } + + // store mask data + if (pType == pMask && type == nChip) + { + TotemSymbID symbId; + symbId.subSystem = TotemSymbID::RP; + symbId.symbolicID = parentID * 10 + id; + + TotemVFATAnalysisMask am; + am.fullMask = fullMask; + GetChannels(n, am.maskedChannels); + + mask->Insert(symbId, am); + + continue; + } + + // recursion (deeper in the tree) + ParseTreeRP(pType, n, type, parentID * 10 + id, mapping, mask); + } +} + +//---------------------------------------------------------------------------------------------------- + +void TotemDAQMappingESSourceXML::ParseTreeT2(ParseType pType, xercesc::DOMNode * parent, NodeType parentType, + unsigned int parentID, const boost::shared_ptr& data, + const boost::shared_ptr& mask) +{ + DOMNodeList *children = parent->getChildNodes(); + +#ifdef DEBUG + printf(">> ParseTreeT2(parent,parentType,parentID)=(%p, %i, %u)\n", parent, parentType, parentID); + printf("\tchildren: Numero children: %li\n", children->getLength()); +#endif + + for (unsigned int i = 0; i < children->getLength(); i++) + { + DOMNode *n = children->item(i); + + if (n->getNodeType() != DOMNode::ELEMENT_NODE) + continue; + + // get node type for RP or T2 + NodeType type = GetNodeType(n); + +#ifdef DEBUG + printf("\t\tchildren #%i: is a %s, (of type %i) \n", i, XMLString::transcode(n->getNodeName()), type); +#endif + + if ((type == nUnknown)) { +#ifdef DEBUG + printf("Found Unknown tag during T2 reading.. EXIT "); +#endif + continue; + } + + if ((T2Node(type)==false)&&(CommonNode(type)==false)) { +#ifdef DEBUG + printf("Found Non-T2 tag during T2 reading.. EXIT "); + printf("\t The tag is: %s \n", XMLString::transcode(n->getNodeName())); +#endif + continue; + } + + // get ID_t2 and position + + // id for T2 plane goes from 0..9; for chip is the 16 bit ID + // position_t2 was the S-link for chip and for the plane should be a number compatible with arm,ht,pl,pls or HS position + int ID_t2 = 0; + + unsigned int position_t2 = 0; + + unsigned int arm=0,ht=0,pl=0,pls=0; + + bool idSet_t2 = false; + //position_t2Set = false; + int attribcounter_t2planedescript=0; + unsigned int toaddForParentID=0; + + unsigned hw_id = 0; + bool hw_id_set = false; + + DOMNamedNodeMap* attr = n->getAttributes(); + + // Begin loop for save T2 element attriute + for (unsigned int j = 0; j < attr->getLength(); j++) { + DOMNode *a = attr->item(j); + if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) { + sscanf(XMLString::transcode(a->getNodeValue()), "%i", &ID_t2); + idSet_t2 = true; + } + + if (!strcmp(XMLString::transcode(a->getNodeName()), "hw_id")) { + sscanf(XMLString::transcode(a->getNodeValue()), "%x", &hw_id); + hw_id_set = true; + } + + if (!strcmp(XMLString::transcode(a->getNodeName()), "position")) { + position_t2 = atoi(XMLString::transcode(a->getNodeValue())); + if (pType == pMask) + toaddForParentID = position_t2; +// position_t2Set = true; + } + + if (type == nArm) { + // arm is the top node and should be reset to 0. + if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) { + parentID=0; + unsigned int id_arm = atoi(XMLString::transcode(a->getNodeValue())); + toaddForParentID=20*id_arm; + } + } + + if (type == nT2Half) { + if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) { + unsigned int id_half = atoi(XMLString::transcode(a->getNodeValue())); + toaddForParentID=10*id_half; + } + } + + // This is needed in principle only for the old formats + if(type == nT2Det) { + if (!strcmp(XMLString::transcode(a->getNodeName()), "arm")) { + sscanf(XMLString::transcode(a->getNodeValue()), "%u", &arm); + attribcounter_t2planedescript++; + } + + if (!strcmp(XMLString::transcode(a->getNodeName()), "ht")) { + sscanf(XMLString::transcode(a->getNodeValue()), "%u", &ht); + attribcounter_t2planedescript++; + } + + if (!strcmp(XMLString::transcode(a->getNodeName()), "pl")) { + sscanf(XMLString::transcode(a->getNodeValue()), "%u", &pl); + attribcounter_t2planedescript++; + } + + if (!strcmp(XMLString::transcode(a->getNodeName()), "pls")) { + sscanf(XMLString::transcode(a->getNodeValue()), "%u", &pls); + attribcounter_t2planedescript++; + } + + // remember id in monitor goes from 0 -- 39 + if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) { + // Id saved another time ... just to increment attribcounter + sscanf(XMLString::transcode(a->getNodeValue()), "%i", &ID_t2); + attribcounter_t2planedescript++; + } + + if (!strcmp(XMLString::transcode(a->getNodeName()), "position")) { + sscanf(XMLString::transcode(a->getNodeValue()), "%u", &position_t2); + attribcounter_t2planedescript++; + // Just another indication for further checking. This attribute was not compulsory in monitor. + attribcounter_t2planedescript=attribcounter_t2planedescript+20; + // 20 is just a "big number" + } + } + } + + // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + // When a plane tag is found, calculate Parent-Id and allows different xml formats: + // Provide compatibility with old monitor formats. + + // Note: + // plane position and id foreseen in final ip5 mapping. + // plane position NOT foreseen in Monitor. + + if (pType == pMapping) { + if (type == nT2Det) { + // Calculate the parent-id from attributes or xml STRUCTURE +// position_t2Set = true; + if (attribcounter_t2planedescript>=(21)) { + // there is already in xml plane the "position" attribute + other attributes. It is assumed to utilize the parent info + +#ifdef DEBUG + printf("TotemDAQMappingESSourceXML: attribcounter_t2planedescript: %i \n",attribcounter_t2planedescript); +#endif + + if (attribcounter_t2planedescript>=25) { + edm::LogVerbatim("TotemDAQMappingESSourceXML") << "T2-Plane attribute utilezed for parentID: position+info from parent "; + //Plane Seems fully specified + //all T2 plane attribute read correctly. Check if it is consitent + unsigned int test_position_t2=arm*20+ht*10+pl*2+pls; + unsigned int testHS=pl*2+pls; + if(testHS!=position_t2) { + edm::LogPrint("TotemDAQMappingESSourceXML") <<"T2 Xml inconsistence in pl-pls attributes and position. Only 'position attribute' taken "; + testHS=position_t2; + } + + // For plane, ID_t2 should go from 0..39 position_t2 from 0..9 + ID_t2=parentID+position_t2; + cout << "attribcounter_t2planedescript>=(25), ID_t2: " << ID_t2 << endl; + toaddForParentID=position_t2; + if (ID_t2!=(int)test_position_t2) + edm::LogPrint("TotemDAQMappingESSourceXML") <<"T2 Xml inconsistence in plane attributes and xml parents structure. Plane attributes ignored"; + + } else { + // Case where arm-ht-pl-pls are NOT specified + edm::LogVerbatim("TotemDAQMappingESSourceXML")<<"T2 Plane have parentID: "<=(21), ID_t2: " << ID_t2 << endl; + toaddForParentID=position_t2; + idSet_t2=true; + } + } + } else { + // Construct plane position from other attributes cause "position" is not inserted; + // Ex- monitor: + + if (attribcounter_t2planedescript>=1) { + // Remember, Z attribute is not counted + + if(attribcounter_t2planedescript>=5) { + int test_position_t2=arm*20+ht*10+pl*2+pls; + + // case for xml from monitor + ID_t2=test_position_t2; + cout << "ID_t2=test_position_t2: " << ID_t2 << endl; + toaddForParentID=test_position_t2; + + if ((int)parentID!=ID_t2) { + edm::LogPrint("TotemDAQMappingESSourceXML") <<"T2 Inconsistence between plane 'id' and position from attributes. Id ignored"; + edm::LogPrint("TotemDAQMappingESSourceXML") <<" T2-Parent = "<getNodeName()) << "'" << endl; + edm::LogProblem ("TotemDAQMappingESSourceXML") <<"ID_t2 not given for element `"<getNodeName()) << "'"; + } + + if (type == nChip && !hw_id_set) + throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "hw_id not given for VFAT id `" << + ID_t2 << "'" << endl; + + if (type == nT2Det && position_t2 > 39) { + throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "Plane position_t2 range from 0 to 39. position_t2 = " << position_t2 << " is invalid." << endl; + edm::LogProblem ("TotemDAQMappingESSourceXML") <<"Plane position_t2 range from 0 to 39. position_t2 = "<getParentNode()->getNodeName())))) + symId = parentID * 100 + ID_t2; // same conv = symbplaneNumber*100 +iid used in DQM + else { + // It is a special VFAT and the special number is set directly in the XML file + symId = ID_t2; //17,18,19,20 +#ifdef DEBUG + printf("TotemDAQMappingESSourceXML Found T2 special Vfat ChId-SLink-Symb 0x%x - %i - %i \n", + ID_t2,position_t2,symId ); +#endif + } + + TotemFramePosition framepos = ChipFramePosition(n); + TotemVFATInfo vfatInfo; + vfatInfo.symbolicID.symbolicID = symId; + vfatInfo.hwID = hw_id; + vfatInfo.symbolicID.subSystem = TotemSymbID::T2; + vfatInfo.type = TotemVFATInfo::data; + data->Insert(framepos, vfatInfo); + } + + // save mask data + if (pType == pMask) { + TotemVFATAnalysisMask vfatMask; + TotemSymbID symbId; + symbId.subSystem = TotemSymbID::T2; + symbId.symbolicID = 100*parentID+ID_t2; + + DOMNode *fullMaskNode = attr->getNamedItem(XMLString::transcode("full_mask")); + if (fullMaskNode && !GetNodeValue(fullMaskNode).compare("yes")) + vfatMask.fullMask = true; + else + GetChannels(n, vfatMask.maskedChannels); + + mask->Insert(symbId, vfatMask); + //cout << "saved mask, ID = " << symbId.symbolicID << ", full mask: " << vfatMask.fullMask << endl; + } + } else { + // Look for the children of n (recursion) + // 3° argument=parentId is needed for calculate VFAT-id startintg from the parent plane + ParseTreeT2(pType, n, type, parentID+toaddForParentID, data, mask); + } + } // Go to the next children +} + +//---------------------------------------------------------------------------------------------------- + +void TotemDAQMappingESSourceXML::ParseTreeT1(ParseType pType, xercesc::DOMNode * parent, NodeType parentType, + unsigned int parentID, const boost::shared_ptr& mapping, + const boost::shared_ptr& mask, unsigned int T1Arm, unsigned int T1Plane, unsigned int T1CSC) +{ + const int ArmMask = 0x0200; + const int PlaneMask = 0x01c0; + const int CSCMask = 0x0038; + const int GenderMask = 0x0004; + const int VFnMask = 0x0003; + + int ArmMask_ = 0; + int PlaneMask_ = 0; + int CSCMask_ = 0; + int GenderMask_ = 0; + int VFnMask_ = 0; + + unsigned int T1ChannelType = 0; + + DOMNodeList *children = parent->getChildNodes(); + +#ifdef DEBUG + printf(">> ParseTreeT1(parent,parentType,parentID)=(%p, %i, %u)\n", parent, parentType, parentID); + printf("\tchildren: Numero children: %li\n", children->getLength()); +#endif + + for (unsigned int i = 0; i < children->getLength(); i++) { + DOMNode *n = children->item(i); + + if (n->getNodeType() != DOMNode::ELEMENT_NODE) + continue; + + // get node type for RP or T2 or T1 + NodeType type = GetNodeType(n); + +#ifdef DEBUG + printf("\t\tchildren #%i: is a %s, (of type %i) \n", i, XMLString::transcode(n->getNodeName()), type); +#endif + + if ((type == nUnknown)) { +#ifdef DEBUG + printf("Found Unknown tag during T1 reading.. EXIT "); +#endif + continue; + } + + if ((T1Node(type)==false)&&(CommonNode(type)==false)) { +#ifdef DEBUG + printf("Found Non-T1 tag during T1 reading.. EXIT "); + printf("\t The tag is: %s \n", XMLString::transcode(n->getNodeName())); +#endif + continue; + } + + // id for T2 plane goes from 0..9; for chip is the 16 bit ID + // for VFATs: (0 or 1 for anodes A0 and A1; 0, 1 or 2 for Cathodes C0,C1,C2) + unsigned int ID_t1 = 0; +#ifdef DEBUG + unsigned int VFPOS = 0; +#endif + unsigned int Gender =0; + + // hardware of an id + unsigned int hw_id = 0; + bool hw_id_set = false; + + bool idSet_t1 = false;//bool position_t2Set = false; + + DOMNamedNodeMap* attr = n->getAttributes(); + + bool fullMask = false; + + // Begin loop for save T1 element attriute ------------------------------------------------------------------ + for (unsigned int j = 0; j < attr->getLength(); j++) { + + DOMNode *a = attr->item(j); + if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) { + sscanf(XMLString::transcode(a->getNodeValue()), "%u", &ID_t1); + idSet_t1 = true; + } + + if (type == nT1Arm) { + if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) { + // arm is the top node and parent ID should be reset to 0. + parentID=0; + unsigned int id_arm = atoi(XMLString::transcode(a->getNodeValue())); + T1Arm = id_arm; + if (id_arm != 0 && id_arm != 1) { + throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "T1 id_arm neither 0 nor 1. Problem parsing XML file." << XMLString::transcode(n->getNodeName()) << endl; + edm::LogProblem ("TotemDAQMappingESSourceXML") <<"T1 id_arm neither 0 nor 1. Problem parsing XML file."<getNodeName()) ; + } + + id_arm = id_arm << 9; + ArmMask_ = ~ArmMask; + parentID &= ArmMask_; + parentID |= id_arm; + } + } + + if (type == nT1Plane) { + if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) { + unsigned int id_plane = atoi(XMLString::transcode(a->getNodeValue())); + T1Plane = id_plane; + id_plane = id_plane << 6; + PlaneMask_ = ~PlaneMask; + parentID &= PlaneMask_; + parentID |= id_plane; + } + } + + if (type == nT1CSC) { + if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) { + unsigned int id_csc = atoi(XMLString::transcode(a->getNodeValue())); + T1CSC = id_csc; + id_csc = id_csc << 3; + CSCMask_ = ~CSCMask; + parentID &= CSCMask_; + parentID |= id_csc; + } + } + + if (type == nT1ChannelType) { + if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) { + T1ChannelType = atoi(XMLString::transcode(a->getNodeValue())); + } + if (!strcmp(XMLString::transcode(a->getNodeName()), "full_mask")) { + fullMask = (strcmp(XMLString::transcode(a->getNodeValue()), "no") != 0); + } + } + + if(type == nChip) { +#ifdef DEBUG + if (!strcmp(XMLString::transcode(a->getNodeName()), "position")){ + VFPOS = atoi(XMLString::transcode(a->getNodeValue())); + } +#endif + if (!strcmp(XMLString::transcode(a->getNodeName()), "polarity")) { + if (!strcmp(XMLString::transcode(a->getNodeValue()),"a")) { + Gender = 0; + } else + if (!strcmp(XMLString::transcode(a->getNodeValue()),"c")) { + Gender = 1; + } else { + throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "T1: Neither anode nor cathode vfat : " << XMLString::transcode(n->getNodeName()) << endl; + edm::LogProblem ("TotemDAQMappingESSourceXML") <<"T1: Neither anode nor cathode vfat : "<getNodeName()); + } + } + + if (!strcmp(XMLString::transcode(a->getNodeName()), "hw_id")) + sscanf(XMLString::transcode(a->getNodeValue()), "%x", &hw_id); + hw_id_set = true; + } + } + + // content control + // Note: each element has an id!! However if the element is a plane, it could be enough to use position 0..9 + + if (idSet_t1==false){ + throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "ID_t1 not given for element `" << XMLString::transcode(n->getNodeName()) << "'" << endl; + edm::LogProblem ("TotemDAQMappingESSourceXML") <<"ID_t1 not given for element `"<getNodeName()) << "'"; + } + + if (type == nChip && !hw_id_set) + throw cms::Exception("TotemDAQMappingESSourceXML::ParseTreeT1") << + "hw_id not set for T1 VFAT id " << ID_t1 << "." << endl; + + + + // save mask data + if (type == nT1ChannelType && pType == pMask) { + TotemSymbID symbId; + symbId.subSystem = TotemSymbID::T1; + symbId.symbolicID = T1ChannelType + 10 * T1CSC + 100 * T1Plane + 1000 * T1Arm; + //cout << "mask: " << T1Arm << " " << T1Plane << " " << T1CSC << " " <Insert(symbId, am); + //cout << "saved mask, ID = " << symbId.symbolicID << ", full mask: " << am.fullMask << endl; + } + + // save data + if (type == nChip) { +#ifdef DEBUG + printf("T1 Vfat in detector (parentID): %x || Position %i \n", parentID, VFPOS); + printf("\t\t\tID_t1 = 0x%x\n", ID_t1); +#endif + + unsigned int symId=0; + + // Check if it is a special chip + if (!tagT1CSC.compare(XMLString::transcode((n->getParentNode()->getNodeName())))) { + symId = parentID; + Gender = Gender << 2; + GenderMask_ = ~GenderMask; + + symId &= GenderMask_; + symId |= Gender; + + VFnMask_ = ~VFnMask; + symId &= VFnMask_; + symId |= ID_t1; + } else { + // It is a special VFAT ... + throw cms::Exception("TotemDAQMappingESSourceXML::ParseTree") << "T1 has no special vfat `" << XMLString::transcode(n->getNodeName()) << "'" << endl; + edm::LogProblem ("TotemDAQMappingESSourceXML") <<"T1 has no special vfat `"<getNodeName()) << "'"; + } + + // Assign a contanaier for the register of that VFAT with ChipId (Hex) + TotemFramePosition framepos = ChipFramePosition(n); + TotemVFATInfo vfatInfo; + vfatInfo.symbolicID.symbolicID = symId; + vfatInfo.hwID = hw_id; + vfatInfo.symbolicID.subSystem = TotemSymbID::T1; + vfatInfo.type = TotemVFATInfo::data; + mapping->Insert(framepos, vfatInfo); + } else { + // Look for the children of n (recursion) + // 3° argument=parentId is needed for calculate VFAT-id startintg from the parent plane + ParseTreeT1(pType, n, type, parentID, mapping, mask, T1Arm, T1Plane, T1CSC); + } + } // Go to the next children +} + +//---------------------------------------------------------------------------------------------------- +//---------------------------------------------------------------------------------------------------- + +TotemFramePosition TotemDAQMappingESSourceXML::ChipFramePosition(xercesc::DOMNode *chipnode) +{ + TotemFramePosition 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(XMLString::transcode(a->getNodeName()), XMLString::transcode(a->getNodeValue()), attributeFlag) > 1) + { + throw cms::Exception("TotemDAQMappingESSourceXML") << + "Unrecognized tag `" << XMLString::transcode(a->getNodeName()) << + "' or incompatible value `" << XMLString::transcode(a->getNodeValue()) << + "'." << endl; + } + } + + if (!fp.CheckXMLAttributeFlag(attributeFlag)) + { + throw cms::Exception("TotemDAQMappingESSourceXML") << + "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag << ")." << endl; + } + + return fp; +} + +//---------------------------------------------------------------------------------------------------- + +TotemDAQMappingESSourceXML::NodeType TotemDAQMappingESSourceXML::GetNodeType(xercesc::DOMNode *n) +{ + // common node types + if (Test(n, tagArm)) return nArm; + if (Test(n, tagChip1)) return nChip; + if (Test(n, tagChip2)) return nChip; + if (Test(n, tagTriggerVFAT1)) return nTriggerVFAT; + + // RP node types + if (Test(n, tagRPStation)) return nRPStation; + if (Test(n, tagRPPot)) return nRPPot; + if (Test(n, tagRPPlane)) return nRPPlane; + + // T2 node types + if (Test(n, tagT2)) return nT2; + if (Test(n, tagT2detector)) return nT2Det; + if (Test(n, tagT2Half)) return nT2Half; + + // T1 node types + if (Test(n, tagT1)) return nT1; + if (Test(n, tagT1Arm)) return nT1Arm; + if (Test(n, tagT1Plane)) return nT1Plane; + if (Test(n, tagT1CSC)) return nT1CSC; + if (Test(n, tagT1ChannelType)) return nT1ChannelType; + if (Test(n, tagChannel)) return nChannel; + + + throw cms::Exception("TotemDAQMappingESSourceXML::GetNodeType") << "Unknown tag `" + << XMLString::transcode(n->getNodeName()) << "'.\n"; +} + +//---------------------------------------------------------------------------------------------------- + +void TotemDAQMappingESSourceXML::GetChannels(xercesc::DOMNode *n, set &channels) +{ + DOMNodeList *children = n->getChildNodes(); + for (unsigned int i = 0; i < children->getLength(); i++) + { + DOMNode *n = children->item(i); + if (n->getNodeType() != DOMNode::ELEMENT_NODE || !Test(n, "channel")) + continue; + + DOMNamedNodeMap* attr = n->getAttributes(); + bool idSet = false; + for (unsigned int j = 0; j < attr->getLength(); j++) + { + DOMNode *a = attr->item(j); + + if (!strcmp(XMLString::transcode(a->getNodeName()), "id")) + { + unsigned int id = 0; + sscanf(XMLString::transcode(a->getNodeValue()), "%u", &id); + channels.insert(id); + idSet = true; + break; + } + } + + if (!idSet) + { + throw cms::Exception("TotemDAQMappingESSourceXML::GetChannels") << + "Channel tags must have an `id' attribute."; + } + } +} + +//---------------------------------------------------------------------------------------------------- + +DEFINE_FWK_EVENTSETUP_SOURCE(TotemDAQMappingESSourceXML); diff --git a/CondFormats/TotemReadoutObjects/python/TotemDAQMappingESSourceXML_cfi.py b/CondFormats/TotemReadoutObjects/python/TotemDAQMappingESSourceXML_cfi.py new file mode 100644 index 0000000000000..72eb628b317ae --- /dev/null +++ b/CondFormats/TotemReadoutObjects/python/TotemDAQMappingESSourceXML_cfi.py @@ -0,0 +1,8 @@ +import FWCore.ParameterSet.Config as cms + +TotemDAQMappingESSourceXML = cms.ESSource("TotemDAQMappingESSourceXML", + verbosity = cms.untracked.uint32(0), + + mappingFileNames = cms.untracked.vstring(), + maskFileNames = cms.untracked.vstring() +) diff --git a/CondFormats/TotemReadoutObjects/src/TotemAnalysisMask.cc b/CondFormats/TotemReadoutObjects/src/TotemAnalysisMask.cc new file mode 100644 index 0000000000000..fead0056fe7a0 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/src/TotemAnalysisMask.cc @@ -0,0 +1,23 @@ +/**************************************************************************** +* +* This is a part of TOTEM offline software. +* Authors: +* Maciej Wróbel (wroblisko@gmail.com) +* Jan Kašpar (jan.kaspar@cern.ch) +* +****************************************************************************/ + +#include "FWCore/Utilities/interface/typelookup.h" + +#include "CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h" + +//---------------------------------------------------------------------------------------------------- + +void TotemAnalysisMask::Insert(const TotemSymbID &sid, const TotemVFATAnalysisMask &vam) +{ + analysisMask[sid] = vam; +} + +//---------------------------------------------------------------------------------------------------- + +TYPELOOKUP_DATA_REG(TotemAnalysisMask); diff --git a/CondFormats/TotemReadoutObjects/src/TotemDAQMapping.cc b/CondFormats/TotemReadoutObjects/src/TotemDAQMapping.cc new file mode 100644 index 0000000000000..90c9d03fccfd1 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/src/TotemDAQMapping.cc @@ -0,0 +1,45 @@ +/**************************************************************************** +* +* This is a part of TOTEM offline software. +* Authors: +* Maciej Wróbel (wroblisko@gmail.com) +* +****************************************************************************/ + +#include "FWCore/Utilities/interface/typelookup.h" + +#include "CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h" + +using namespace std; + +//---------------------------------------------------------------------------------------------------- + +std::ostream& operator << (std::ostream& s, const TotemVFATInfo &vi) +{ + if (vi.type == TotemVFATInfo::data) + s << "type=data, "; + else + s << "type= CC, "; + + s << vi.symbolicID << ", hw id=0x" << hex << vi.hwID << dec; + + return s; +} + +//---------------------------------------------------------------------------------------------------- + +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; + } + + VFATMapping[fp] = vi; +} + +//---------------------------------------------------------------------------------------------------- + +TYPELOOKUP_DATA_REG(TotemDAQMapping); diff --git a/CondFormats/TotemReadoutObjects/src/TotemSymbId.cc b/CondFormats/TotemReadoutObjects/src/TotemSymbId.cc new file mode 100644 index 0000000000000..eb4b54bea5a95 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/src/TotemSymbId.cc @@ -0,0 +1,29 @@ +/**************************************************************************** +* +* This is a part of TOTEM offline software. +* Authors: +* Jan Kašpar (jan.kaspar@cern.ch) +* +****************************************************************************/ + +#include "CondFormats/TotemReadoutObjects/interface/TotemSymbId.h" + +std::ostream& operator << (std::ostream& s, const TotemSymbID &sid) +{ + switch (sid.subSystem) { + case TotemSymbID::RP: + s << "sub-system=RP, "; + break; + case TotemSymbID::T1: + s << "sub-system=T1, "; + break; + case TotemSymbID::T2: + s << "sub-system=T2, "; + break; + } + + s << "symb. id=" << sid.symbolicID; + + return s; +} + diff --git a/CondFormats/TotemReadoutObjects/xml/totem_rp_210_mapping.xml b/CondFormats/TotemReadoutObjects/xml/totem_rp_210_mapping.xml new file mode 100644 index 0000000000000..a4b9775355e87 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/xml/totem_rp_210_mapping.xml @@ -0,0 +1,789 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CondFormats/TotemReadoutObjects/xml/totem_rp_210far_220_mapping.xml b/CondFormats/TotemReadoutObjects/xml/totem_rp_210far_220_mapping.xml new file mode 100644 index 0000000000000..06ba1d0f14617 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/xml/totem_rp_210far_220_mapping.xml @@ -0,0 +1,1576 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CondFormats/TotemReadoutObjects/xml/totem_rp_220_mapping.xml b/CondFormats/TotemReadoutObjects/xml/totem_rp_220_mapping.xml new file mode 100644 index 0000000000000..0fdd8d284b026 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/xml/totem_rp_220_mapping.xml @@ -0,0 +1,790 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CondFormats/TotemReadoutObjects/xml/totem_rp_mask_example.xml b/CondFormats/TotemReadoutObjects/xml/totem_rp_mask_example.xml new file mode 100644 index 0000000000000..9f9b08fb5417b --- /dev/null +++ b/CondFormats/TotemReadoutObjects/xml/totem_rp_mask_example.xml @@ -0,0 +1,533 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 57c8b94a138c9852e438f94d4e0c34a1421d3a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ka=C5=A1par?= Date: Tue, 12 Apr 2016 12:05:04 +0200 Subject: [PATCH 2/2] Update after modifying raw-data DataFormats. --- .../DataRecord/interface/TotemReadoutRcd.h | 4 +- CondFormats/TotemReadoutObjects/BuildFile.xml | 1 - .../interface/TotemAnalysisMask.h | 6 +- .../interface/TotemDAQMapping.h | 8 +- .../interface/TotemFramePosition.h | 135 +++ .../interface/TotemSymbId.h | 4 +- .../plugins/PrintTotemDAQMapping.cc | 4 +- .../plugins/TotemDAQMappingESSourceXML.cc | 35 +- .../src/TotemAnalysisMask.cc | 2 +- .../src/TotemDAQMapping.cc | 2 +- .../src/TotemFramePosition.cc | 137 +++ .../xml/ctpps_210_mapping.xml | 789 ++++++++++++++++++ 12 files changed, 1086 insertions(+), 41 deletions(-) create mode 100644 CondFormats/TotemReadoutObjects/interface/TotemFramePosition.h create mode 100644 CondFormats/TotemReadoutObjects/src/TotemFramePosition.cc create mode 100644 CondFormats/TotemReadoutObjects/xml/ctpps_210_mapping.xml diff --git a/CondFormats/DataRecord/interface/TotemReadoutRcd.h b/CondFormats/DataRecord/interface/TotemReadoutRcd.h index d23cb39524bec..27f83d9fc5c43 100644 --- a/CondFormats/DataRecord/interface/TotemReadoutRcd.h +++ b/CondFormats/DataRecord/interface/TotemReadoutRcd.h @@ -6,8 +6,8 @@ * ****************************************************************************/ -#ifndef TotemCondFormatsDataRecordTotemDAQMappingRecord_h -#define TotemCondFormatsDataRecordTotemDAQMappingRecord_h +#ifndef CondFormats_DataRecord_TotemReadoutRcd +#define CondFormats_DataRecord_TotemReadoutRcd #include "FWCore/Framework/interface/EventSetupRecordImplementation.h" diff --git a/CondFormats/TotemReadoutObjects/BuildFile.xml b/CondFormats/TotemReadoutObjects/BuildFile.xml index c9809e9492415..193dfc68b5059 100644 --- a/CondFormats/TotemReadoutObjects/BuildFile.xml +++ b/CondFormats/TotemReadoutObjects/BuildFile.xml @@ -1,5 +1,4 @@ - diff --git a/CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h b/CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h index edcc3d40c3402..3c1b4f7884cc1 100644 --- a/CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h +++ b/CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h @@ -7,8 +7,8 @@ * ****************************************************************************/ -#ifndef _TotemAnalysisMask_h_ -#define _TotemAnalysisMask_h_ +#ifndef CondFormats_TotemReadoutObjects_TotemAnalysisMask +#define CondFormats_TotemReadoutObjects_TotemAnalysisMask #include "CondFormats/TotemReadoutObjects/interface/TotemSymbId.h" @@ -42,7 +42,7 @@ class TotemAnalysisMask public: std::map analysisMask; - void Insert(const TotemSymbID &sid, const TotemVFATAnalysisMask &vam); + void insert(const TotemSymbID &sid, const TotemVFATAnalysisMask &vam); }; #endif diff --git a/CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h b/CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h index e35322fbd88a8..6d0df6270648c 100644 --- a/CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h +++ b/CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h @@ -7,10 +7,10 @@ * ****************************************************************************/ -#ifndef _TotemDAQMapping_h_ -#define _TotemDAQMapping_h_ +#ifndef CondFormats_TotemReadoutObjects_TotemDAQMapping +#define CondFormats_TotemReadoutObjects_TotemDAQMapping -#include "DataFormats/TotemRawData/interface/TotemFramePosition.h" +#include "CondFormats/TotemReadoutObjects/interface/TotemFramePosition.h" #include "CondFormats/TotemReadoutObjects/interface/TotemSymbId.h" @@ -46,7 +46,7 @@ class TotemDAQMapping public: std::map VFATMapping; - void Insert(const TotemFramePosition &fp, const TotemVFATInfo &vi); + void insert(const TotemFramePosition &fp, const TotemVFATInfo &vi); }; #endif diff --git a/CondFormats/TotemReadoutObjects/interface/TotemFramePosition.h b/CondFormats/TotemReadoutObjects/interface/TotemFramePosition.h new file mode 100644 index 0000000000000..6749301be8d69 --- /dev/null +++ b/CondFormats/TotemReadoutObjects/interface/TotemFramePosition.h @@ -0,0 +1,135 @@ +/**************************************************************************** +* +* This is a part of the TOTEM offline software. +* Authors: +* Jan Kašpar (jan.kaspar@gmail.com) +* +****************************************************************************/ + +#ifndef CondFormats_TotemReadoutObjects_TotemFramePosition +#define CondFormats_TotemReadoutObjects_TotemFramePosition + +#include +#include + +/** + * 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 | 3 bits | 5 bits | 2 bits | 4 bits | 4 bits | + * | empty | empty | SubSystem | TOTFED ID | OptoRx ID | GOH ID | index within fiber | + * | | (this part is encoded in OptoRx header) | | + * \endverbatim + * According to the convention SubSystemId goes from 1 to 6, TOTFEDId from 1 to 21 and OptoRx from 1 to 3. + **/ +class TotemFramePosition +{ + public: + /// the official enumeration of DAQ subsystems + enum SubSystemType {ssNone=0, ssT1=1, ssT2=2, ssRP=3, ssTrigger=4, ssTTC=5, ssFEC=6}; + + static const unsigned int offsetIdxInFiber = 0, maskIdxInFiber = 0xF; + static const unsigned int offsetGOHId = 4, maskGOHId = 0xF; + static const unsigned int offsetOptoRxId = 8, maskOptoRxId = 0x3; + static const unsigned int offsetTOTFEDId = 10, maskTOTFEDId = 0x1F; + static const unsigned int offsetSubSystemId = 15, maskSubSystemId = 0x7; + + /// the preferred constructor + TotemFramePosition(unsigned short SubSystemId, unsigned short TOTFEDId, unsigned short OptoRxId, unsigned short GOHId, unsigned short IdxInFiber) : + rawPosition(IdxInFiber<> offsetSubSystemId) & maskSubSystemId; } + unsigned short getTOTFEDId() const { return (rawPosition >> offsetTOTFEDId) & maskTOTFEDId;} + unsigned short getOptoRxId() const { return (rawPosition >> offsetOptoRxId) & maskOptoRxId; } + unsigned short getGOHId() const { return (rawPosition >> offsetGOHId) & maskGOHId; } + unsigned short getIdxInFiber() const { return (rawPosition >> offsetIdxInFiber) & maskIdxInFiber; } + + void setSubSystemId(unsigned short v) + { v &= maskSubSystemId; rawPosition &= 0xFFFFFFFF - (maskSubSystemId << offsetSubSystemId); rawPosition |= (v << offsetSubSystemId); } + + void setTOTFEDId(unsigned short v) + { v &= maskTOTFEDId; rawPosition &= 0xFFFFFFFF - (maskTOTFEDId << offsetTOTFEDId); rawPosition |= (v << offsetTOTFEDId); } + + void setOptoRxId(unsigned short v) + { v &= maskOptoRxId; rawPosition &= 0xFFFFFFFF - (maskOptoRxId << offsetOptoRxId); rawPosition |= (v << offsetOptoRxId); } + + void setGOHId(unsigned short v) + { v &= maskGOHId; rawPosition &= 0xFFFFFFFF - (maskGOHId << offsetGOHId); rawPosition |= (v << offsetGOHId); } + + void setIdxInFiber(unsigned short v) + { v &= maskIdxInFiber; rawPosition &= 0xFFFFFFFF - (maskIdxInFiber << offsetIdxInFiber); rawPosition |= (v << offsetIdxInFiber); } + + void setAllIDs(unsigned short SubSystemId, unsigned short TOTFEDId, unsigned short OptoRxId, unsigned short GOHId, unsigned short IdxInFiber) + { + rawPosition = (IdxInFiber<> 8) & 0xFFF; + } + + protected: + unsigned int rawPosition; +}; + +#endif diff --git a/CondFormats/TotemReadoutObjects/interface/TotemSymbId.h b/CondFormats/TotemReadoutObjects/interface/TotemSymbId.h index f186c93daec35..99fc50058629e 100644 --- a/CondFormats/TotemReadoutObjects/interface/TotemSymbId.h +++ b/CondFormats/TotemReadoutObjects/interface/TotemSymbId.h @@ -6,8 +6,8 @@ * ****************************************************************************/ -#ifndef _TotemSymbId_h_ -#define _TotemSymbId_h_ +#ifndef CondFormats_TotemReadoutObjects_TotemSymbId +#define CondFormats_TotemReadoutObjects_TotemSymbId #include diff --git a/CondFormats/TotemReadoutObjects/plugins/PrintTotemDAQMapping.cc b/CondFormats/TotemReadoutObjects/plugins/PrintTotemDAQMapping.cc index bc9d928fbcb32..1117bcc052cf8 100644 --- a/CondFormats/TotemReadoutObjects/plugins/PrintTotemDAQMapping.cc +++ b/CondFormats/TotemReadoutObjects/plugins/PrintTotemDAQMapping.cc @@ -6,7 +6,7 @@ * ****************************************************************************/ -#include "FWCore/Framework/interface/EDAnalyzer.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Framework/interface/EventSetup.h" @@ -22,7 +22,7 @@ /** *\brief Prints the DAQ mapping loaded by DAQMappingSourceXML. **/ -class PrintTotemDAQMapping : public edm::EDAnalyzer +class PrintTotemDAQMapping : public edm::one::EDAnalyzer<> { public: PrintTotemDAQMapping(const edm::ParameterSet &ps) {} diff --git a/CondFormats/TotemReadoutObjects/plugins/TotemDAQMappingESSourceXML.cc b/CondFormats/TotemReadoutObjects/plugins/TotemDAQMappingESSourceXML.cc index 15365e0e83503..7ff5d8d932ac1 100644 --- a/CondFormats/TotemReadoutObjects/plugins/TotemDAQMappingESSourceXML.cc +++ b/CondFormats/TotemReadoutObjects/plugins/TotemDAQMappingESSourceXML.cc @@ -19,11 +19,10 @@ #include "FWCore/Framework/interface/SourceFactory.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "DataFormats/TotemRawData/interface/TotemFramePosition.h" - #include "CondFormats/DataRecord/interface/TotemReadoutRcd.h" #include "CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h" #include "CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h" +#include "CondFormats/TotemReadoutObjects/interface/TotemFramePosition.h" #include #include @@ -241,20 +240,7 @@ void TotemDAQMappingESSourceXML::setIntervalFor(const edm::eventsetup::EventSetu DOMDocument* TotemDAQMappingESSourceXML::GetDOMDocument(string file) { XercesDOMParser* parser = new XercesDOMParser(); - //parser->setValidationScheme(XercesDOMParser::Val_Always); - //parser->setDoNamespaces(true); - - try { - parser->parse(file.c_str()); - } - catch (...) { - throw cms::Exception("TotemDAQMappingESSourceXML::GetDOMDocument") << "Cannot parse file `" << file - << "' (exception)." << endl; - } - - if (!parser) - throw cms::Exception("TotemDAQMappingESSourceXML::GetDOMDocument") << "Cannot parse file `" << file - << "' (parser = NULL)." << endl; + parser->parse(file.c_str()); DOMDocument* xmlDoc = parser->getDocument(); @@ -428,7 +414,7 @@ void TotemDAQMappingESSourceXML::ParseTreeRP(ParseType pType, xercesc::DOMNode * vfatInfo.type = TotemVFATInfo::CC; } - mapping->Insert(framepos, vfatInfo); + mapping->insert(framepos, vfatInfo); continue; } @@ -444,7 +430,7 @@ void TotemDAQMappingESSourceXML::ParseTreeRP(ParseType pType, xercesc::DOMNode * am.fullMask = fullMask; GetChannels(n, am.maskedChannels); - mask->Insert(symbId, am); + mask->insert(symbId, am); continue; } @@ -618,7 +604,6 @@ void TotemDAQMappingESSourceXML::ParseTreeT2(ParseType pType, xercesc::DOMNode * unsigned int testHS=pl*2+pls; if(testHS!=position_t2) { edm::LogPrint("TotemDAQMappingESSourceXML") <<"T2 Xml inconsistence in pl-pls attributes and position. Only 'position attribute' taken "; - testHS=position_t2; } // For plane, ID_t2 should go from 0..39 position_t2 from 0..9 @@ -714,7 +699,7 @@ void TotemDAQMappingESSourceXML::ParseTreeT2(ParseType pType, xercesc::DOMNode * vfatInfo.hwID = hw_id; vfatInfo.symbolicID.subSystem = TotemSymbID::T2; vfatInfo.type = TotemVFATInfo::data; - data->Insert(framepos, vfatInfo); + data->insert(framepos, vfatInfo); } // save mask data @@ -730,7 +715,7 @@ void TotemDAQMappingESSourceXML::ParseTreeT2(ParseType pType, xercesc::DOMNode * else GetChannels(n, vfatMask.maskedChannels); - mask->Insert(symbId, vfatMask); + mask->insert(symbId, vfatMask); //cout << "saved mask, ID = " << symbId.symbolicID << ", full mask: " << vfatMask.fullMask << endl; } } else { @@ -919,7 +904,7 @@ void TotemDAQMappingESSourceXML::ParseTreeT1(ParseType pType, xercesc::DOMNode * TotemVFATAnalysisMask am; am.fullMask = fullMask; GetChannels(n, am.maskedChannels); - mask->Insert(symbId, am); + mask->insert(symbId, am); //cout << "saved mask, ID = " << symbId.symbolicID << ", full mask: " << am.fullMask << endl; } @@ -957,7 +942,7 @@ void TotemDAQMappingESSourceXML::ParseTreeT1(ParseType pType, xercesc::DOMNode * vfatInfo.hwID = hw_id; vfatInfo.symbolicID.subSystem = TotemSymbID::T1; vfatInfo.type = TotemVFATInfo::data; - mapping->Insert(framepos, vfatInfo); + mapping->insert(framepos, vfatInfo); } else { // Look for the children of n (recursion) // 3° argument=parentId is needed for calculate VFAT-id startintg from the parent plane @@ -978,7 +963,7 @@ TotemFramePosition TotemDAQMappingESSourceXML::ChipFramePosition(xercesc::DOMNod for (unsigned int j = 0; j < attr->getLength(); j++) { DOMNode *a = attr->item(j); - if (fp.SetXMLAttribute(XMLString::transcode(a->getNodeName()), XMLString::transcode(a->getNodeValue()), attributeFlag) > 1) + if (fp.setXMLAttribute(XMLString::transcode(a->getNodeName()), XMLString::transcode(a->getNodeValue()), attributeFlag) > 1) { throw cms::Exception("TotemDAQMappingESSourceXML") << "Unrecognized tag `" << XMLString::transcode(a->getNodeName()) << @@ -987,7 +972,7 @@ TotemFramePosition TotemDAQMappingESSourceXML::ChipFramePosition(xercesc::DOMNod } } - if (!fp.CheckXMLAttributeFlag(attributeFlag)) + if (!fp.checkXMLAttributeFlag(attributeFlag)) { throw cms::Exception("TotemDAQMappingESSourceXML") << "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag << ")." << endl; diff --git a/CondFormats/TotemReadoutObjects/src/TotemAnalysisMask.cc b/CondFormats/TotemReadoutObjects/src/TotemAnalysisMask.cc index fead0056fe7a0..cf8eb46f1d834 100644 --- a/CondFormats/TotemReadoutObjects/src/TotemAnalysisMask.cc +++ b/CondFormats/TotemReadoutObjects/src/TotemAnalysisMask.cc @@ -13,7 +13,7 @@ //---------------------------------------------------------------------------------------------------- -void TotemAnalysisMask::Insert(const TotemSymbID &sid, const TotemVFATAnalysisMask &vam) +void TotemAnalysisMask::insert(const TotemSymbID &sid, const TotemVFATAnalysisMask &vam) { analysisMask[sid] = vam; } diff --git a/CondFormats/TotemReadoutObjects/src/TotemDAQMapping.cc b/CondFormats/TotemReadoutObjects/src/TotemDAQMapping.cc index 90c9d03fccfd1..729fff9dbc3bf 100644 --- a/CondFormats/TotemReadoutObjects/src/TotemDAQMapping.cc +++ b/CondFormats/TotemReadoutObjects/src/TotemDAQMapping.cc @@ -28,7 +28,7 @@ std::ostream& operator << (std::ostream& s, const TotemVFATInfo &vi) //---------------------------------------------------------------------------------------------------- -void TotemDAQMapping::Insert(const TotemFramePosition &fp, const TotemVFATInfo &vi) +void TotemDAQMapping::insert(const TotemFramePosition &fp, const TotemVFATInfo &vi) { auto it = VFATMapping.find(fp); if (it != VFATMapping.end()) diff --git a/CondFormats/TotemReadoutObjects/src/TotemFramePosition.cc b/CondFormats/TotemReadoutObjects/src/TotemFramePosition.cc new file mode 100644 index 0000000000000..8051a7720cb5a --- /dev/null +++ b/CondFormats/TotemReadoutObjects/src/TotemFramePosition.cc @@ -0,0 +1,137 @@ +/**************************************************************************** +* +* This is a part of the TOTEM offline software. +* Authors: +* Jan Kašpar (jan.kaspar@gmail.com) +* +****************************************************************************/ + +#include "CondFormats/TotemReadoutObjects/interface/TotemFramePosition.h" + +#include +#include + +using namespace std; + +const string TotemFramePosition::tagSSNone = "None"; +const string TotemFramePosition::tagSST1 = "T1"; +const string TotemFramePosition::tagSST2 = "T2"; +const string TotemFramePosition::tagSSRP = "RP"; +const string TotemFramePosition::tagSSTrigger = "Trigger"; +const string TotemFramePosition::tagSSTTC = "TTC"; +const string TotemFramePosition::tagSSFEC = "FEC"; + +//---------------------------------------------------------------------------------------------------- + +std::ostream& operator << (std::ostream& s, const TotemFramePosition &fp) +{ + return s << std::hex + << fp.getSubSystemId() << ":" + << std::setw(2) << std::setfill('0') + << fp.getTOTFEDId() << ":" + << fp.getOptoRxId() << ":" + << fp.getGOHId() << ":" + << fp.getIdxInFiber() + << std::dec; +} + +//---------------------------------------------------------------------------------------------------- + +void TotemFramePosition::printXML() +{ + cout << dec << "SubSystemId=\""; + + const unsigned char &ss = getSubSystemId(); + switch (ss) + { + case ssT1: cout << "T1"; break; + case ssT2: cout << "T2"; break; + case ssRP: cout << "RP"; break; + case ssTrigger: cout << "Trigger"; break; + case ssTTC: cout << "TTC"; break; + case ssFEC: cout << "FEC"; break; + default: cout << "None"; + } + + cout << "\" TOTFEDId=\"" << getTOTFEDId() + << "\" OptoRxId=\"" << getOptoRxId() + << "\" GOHId=\"" << getGOHId() + << "\" IdxInFiber=\"" << getIdxInFiber() + << "\""; +} + +//---------------------------------------------------------------------------------------------------- + +unsigned char TotemFramePosition::setXMLAttribute(const std::string &attribute, const std::string &value, + unsigned char &flag) +{ + if (attribute == "DAQPosition") + { + size_t dd1 = value.find(':', 0); + size_t dd2 = value.find(':', dd1+1); + size_t dd3 = value.find(':', dd2+1); + size_t dd4 = value.find(':', dd3+1); + size_t dd5 = value.find(':', dd4+1); + + if (dd1 == string::npos || dd2 == string::npos || dd3 == string::npos || dd4 == string::npos || + dd5 != string::npos) + return 3; + + unsigned short ss = strtol(value.substr(0, dd1).c_str(), NULL, 16); + unsigned short ti = strtol(value.substr(dd1+1, dd2-dd1).c_str(), NULL, 16); + unsigned short oi = strtol(value.substr(dd2+1, dd3-dd2).c_str(), NULL, 16); + unsigned short gi = strtol(value.substr(dd3+1, dd4-dd3).c_str(), NULL, 16); + unsigned short fi = strtol(value.substr(dd4+1).c_str(), NULL, 16); + + setAllIDs(ss, ti, oi, gi, fi); + flag |= 0x40; + return 0; + } + + unsigned int v = atoi(value.c_str()); + + if (attribute == "SubSystemId") + { + if (value == tagSSNone) setSubSystemId(ssNone); + else if (value == tagSST1) setSubSystemId(ssT1); + else if (value == tagSST2) setSubSystemId(ssT2); + else if (value == tagSSRP) setSubSystemId(ssRP); + else if (value == tagSSTrigger) setSubSystemId(ssTrigger); + else if (value == tagSSTTC) setSubSystemId(ssTTC); + else if (value == tagSSFEC) setSubSystemId(ssFEC); + else setSubSystemId(v); + + flag |= 0x10; + return 0; + } + + if (attribute == "TOTFEDId") + { + setTOTFEDId(v); + flag |= 0x8; + return 0; + } + + if (attribute == "OptoRxId") + { + setOptoRxId(v); + flag |= 0x4; + return 0; + } + + if (attribute == "GOHId") + { + setGOHId(v); + flag |= 0x2; + return 0; + } + + if (attribute == "IdxInFiber") + { + setIdxInFiber(v); + flag |= 0x1; + return 0; + } + + return 1; +} diff --git a/CondFormats/TotemReadoutObjects/xml/ctpps_210_mapping.xml b/CondFormats/TotemReadoutObjects/xml/ctpps_210_mapping.xml new file mode 100644 index 0000000000000..bba2fa4b20edb --- /dev/null +++ b/CondFormats/TotemReadoutObjects/xml/ctpps_210_mapping.xml @@ -0,0 +1,789 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +