Skip to content

Commit

Permalink
Merge pull request #14600 from CTPPS/ctpps_raw_cond_formats_backport
Browse files Browse the repository at this point in the history
CTPPS: new CondFormats related to TOTEM RP raw data and digi - backport of #13838
  • Loading branch information
davidlange6 committed May 27, 2016
2 parents 136b0a7 + 57c8b94 commit a7a5e87
Show file tree
Hide file tree
Showing 20 changed files with 6,152 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CondFormats/DataRecord/interface/TotemReadoutRcd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/****************************************************************************
*
* This is a part of TOTEM offline software.
* Authors:
* Jan Kaspar (jan.kaspar@gmail.com)
*
****************************************************************************/

#ifndef CondFormats_DataRecord_TotemReadoutRcd
#define CondFormats_DataRecord_TotemReadoutRcd

#include "FWCore/Framework/interface/EventSetupRecordImplementation.h"

/**
*\brief EventSetup record for TOTEM readout-related information.
**/
class TotemReadoutRcd : public edm::eventsetup::EventSetupRecordImplementation<TotemReadoutRcd> {};

#endif
12 changes: 12 additions & 0 deletions CondFormats/DataRecord/src/TotemReadoutRcd.cc
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 5 additions & 0 deletions CondFormats/TotemReadoutObjects/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<use name="FWCore/Framework"/>

<export>
<lib name="1"/>
</export>
48 changes: 48 additions & 0 deletions CondFormats/TotemReadoutObjects/interface/TotemAnalysisMask.h
Original file line number Diff line number Diff line change
@@ -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 CondFormats_TotemReadoutObjects_TotemAnalysisMask
#define CondFormats_TotemReadoutObjects_TotemAnalysisMask

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

#include <set>
#include <map>

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

/**
*\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<unsigned char> maskedChannels;
};

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

/**
*\brief Channel-mask mapping.
**/
class TotemAnalysisMask
{
public:
std::map<TotemSymbID, TotemVFATAnalysisMask> analysisMask;

void insert(const TotemSymbID &sid, const TotemVFATAnalysisMask &vam);
};

#endif
52 changes: 52 additions & 0 deletions CondFormats/TotemReadoutObjects/interface/TotemDAQMapping.h
Original file line number Diff line number Diff line change
@@ -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 CondFormats_TotemReadoutObjects_TotemDAQMapping
#define CondFormats_TotemReadoutObjects_TotemDAQMapping

#include "CondFormats/TotemReadoutObjects/interface/TotemFramePosition.h"

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

#include <map>

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

/**
*\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<TotemFramePosition, TotemVFATInfo> VFATMapping;

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

#endif
135 changes: 135 additions & 0 deletions CondFormats/TotemReadoutObjects/interface/TotemFramePosition.h
Original file line number Diff line number Diff line change
@@ -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 <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 | 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<<offsetIdxInFiber | GOHId<<offsetGOHId | OptoRxId<<offsetOptoRxId | TOTFEDId<<offsetTOTFEDId | SubSystemId<<offsetSubSystemId)
{
}

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

~TotemFramePosition()
{
}

unsigned short getSubSystemId() const { return (rawPosition >> 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<<offsetIdxInFiber | GOHId<<offsetGOHId | OptoRxId<<offsetOptoRxId
| TOTFEDId<<offsetTOTFEDId | SubSystemId<<offsetSubSystemId);
}

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

public:
bool operator < (const TotemFramePosition &pos) const
{
return (rawPosition < pos.rawPosition);
}

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

/// 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 TotemFramePosition &fp);

/// XML sub-system tags
static const std::string tagSSNone;
static const std::string tagSSTrigger;
static const std::string tagSST1;
static const std::string tagSST2;
static const std::string tagSSRP;
static const std::string tagSSTTC;
static const std::string tagSSFEC;

/// 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 == 0x1f) | (flag == 0x20) | (flag == 0x40));
}

unsigned short getFullOptoRxId() const
{
return (rawPosition >> 8) & 0xFFF;
}

protected:
unsigned int rawPosition;
};

#endif
41 changes: 41 additions & 0 deletions CondFormats/TotemReadoutObjects/interface/TotemSymbId.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/****************************************************************************
*
* This is a part of TOTEM offline software.
* Authors:
* Jan Kašpar (jan.kaspar@cern.ch)
*
****************************************************************************/

#ifndef CondFormats_TotemReadoutObjects_TotemSymbId
#define CondFormats_TotemReadoutObjects_TotemSymbId

#include <iostream>

/**
*\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
7 changes: 7 additions & 0 deletions CondFormats/TotemReadoutObjects/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<library name="CondFormatsTotemReadoutObjectsPlugins" file="*.cc">
<flags EDM_PLUGIN="1"/>
<use name="FWCore/Framework"/>
<use name="CondFormats/DataRecord"/>
<use name="CondFormats/TotemReadoutObjects"/>
<use name="xerces-c"/>
</library>
60 changes: 60 additions & 0 deletions CondFormats/TotemReadoutObjects/plugins/PrintTotemDAQMapping.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/****************************************************************************
*
* This is a part of TOTEM offline software.
* Authors:
* Jan Kašpar (jan.kaspar@gmail.com)
*
****************************************************************************/

#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"
#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::one::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<TotemDAQMapping> mapping;
es.get<TotemReadoutRcd>().get(mapping);

// get analysis mask to mask channels
ESHandle<TotemAnalysisMask> analysisMask;
es.get<TotemReadoutRcd>().get(analysisMask);

for (const auto &p : mapping->VFATMapping)
{
cout << p.first << " -> " << p.second << endl;
}
}

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

DEFINE_FWK_MODULE(PrintTotemDAQMapping);
Loading

0 comments on commit a7a5e87

Please sign in to comment.