Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please consider the following formatting changes to #11886 #63

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion DataFormats/Detectors/TRD/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ o2_add_library(DataFormatsTRD
src/Digit.cxx
src/KrCluster.cxx
src/NoiseCalibration.cxx
src/TrapRegisters.cxx
src/TrapRegInfo.cxx
src/MCMEvent.cxx
src/TrapConfigEvent.cxx
PUBLIC_LINK_LIBRARIES O2::CommonDataFormat O2::SimulationDataFormat)

o2_target_root_dictionary(DataFormatsTRD
Expand Down Expand Up @@ -53,7 +57,13 @@ o2_target_root_dictionary(DataFormatsTRD
include/DataFormatsTRD/CalT0.h
include/DataFormatsTRD/SignalArray.h
include/DataFormatsTRD/CompressedDigit.h
include/DataFormatsTRD/CompressedHeader.h)
include/DataFormatsTRD/CompressedHeader.h
include/DataFormatsTRD/TrapConfigEvent.h
include/DataFormatsTRD/MCMEvent.h
include/DataFormatsTRD/TrapRegInfo.h
include/DataFormatsTRD/TrapRegisters.h
include/DataFormatsTRD/TrapConfigEventQC.h
include/DataFormatsTRD/TrapConfigEvent.h)

o2_add_test(Digit
COMPONENT_NAME trd
Expand All @@ -70,3 +80,11 @@ o2_add_test(RawData
ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage
LABELS trd
)

o2_add_test(TrapConfigEvent
COMPONENT_NAME trd
PUBLIC_LINK_LIBRARIES O2::DataFormatsTRD
SOURCES test/testTrapConfigEvent.cxx
ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage
LABELS trd
)
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ constexpr unsigned int ETYPEPHYSICSTRIGGER = 0x2; ///< CRU Half Chamber head
constexpr unsigned int ETYPECALIBRATIONTRIGGER = 0x3; ///< CRU Half Chamber header eventtype definition
constexpr int MAXCRUERRORVALUE = 0x2; ///< Max possible value for a CRU Halfchamber link error. As of may 2022, can only be 0x0, 0x1, and 0x2, at least that is all so far(may2022).
constexpr int INVALIDPRETRIGGERPHASE = 0xf; ///< Invalid value for phase, used to signify there is no hcheader.
constexpr int CONFIGEVENTNUMBER = 0x47; ///< Major version number in Digit HC Header defining a configuration "digit" event
constexpr int CONFIGEVENTENDA = 0x42424242; ///< End of packed config event in message to be passed on for processing
constexpr int CONFIGEVENTENDB = 0xedededed; ///< End of packed config event in message to be passed on for processing
constexpr int CONFIGEVENTBLOCKENDMARKER = 0x7fff00fe; ///< End marker for a configuration event block.

} // namespace constants
} // namespace trd
Expand Down
1 change: 1 addition & 0 deletions DataFormats/Detectors/TRD/include/DataFormatsTRD/Digit.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Digit
void setMCM(int row, int col) { mMCM = HelperMethods::getMCMfromPad(row, col); } // set MCM from pad row, column
void setChannel(int channel) { mChannel = channel; }
void setDetector(int det) { mDetector = ((mDetector & 0xf000) | (det & 0xfff)); }
void setPhase(unsigned int phase) { mDetector &= phase << 12; }
void setADC(ArrayADC const& adc) { mADC = adc; }
void setADC(const gsl::span<ADC_t>& adc) { std::copy(adc.begin(), adc.end(), mADC.begin()); }
void setPreTrigPhase(int phase) { mDetector = (((phase & 0xf) << 12) | (mDetector & 0xfff)); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define ALICEO2_TRD_HELPERMETHODS_HH

#include "DataFormatsTRD/Constants.h"
#include "DataFormatsTRD/RawData.h"
#include <iostream>
#include <string>
#include <fmt/format.h>
Expand Down Expand Up @@ -211,6 +212,30 @@ struct HelperMethods {
mcm = (row % constants::NMCMROBINROW) * constants::NMCMROBINCOL + (mcmCol % constants::NMCMROBINCOL);
channel = constants::NADCMCM - 1 - ((chamberIndex % constants::NCHANNELSPERROW) % constants::NADCMCM);
}

static int getMCMId(int sector, int stack, int layer, int rob, int mcm)
{
// return the mcmid of the indexed mcm
int mcmid = (sector * constants::NSTACK * constants::NLAYER + stack * constants::NLAYER + layer) * constants::NROBC1 * constants::NMCMROB + rob * constants::NMCMROB + mcm;
return mcmid;
}

static int getMCMId(int det, int rob, int mcm)
{
// return the mcmid of the indexed mcm
int mcmid = det * constants::NROBC1 * constants::NMCMROB + rob * constants::NMCMROB + mcm;
return mcmid;
}

static int getHCIDFromMCMId(int mcmid)
{
return mcmid / (constants::NROBC1 * constants::NMCMROB);
}

static int getHCIDFromDigitHCHeader(DigitHCHeader header)
{
return header.supermodule * constants::NHCPERSEC + header.stack * constants::NLAYER * 2 + header.layer * 2 + header.side;
}
};

} // namespace trd
Expand Down
68 changes: 68 additions & 0 deletions DataFormats/Detectors/TRD/include/DataFormatsTRD/MCMEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef O2_TRDMCMEVENT_H
#define O2_TRDMCMEVENT_H

#include "CommonDataFormat/InteractionRecord.h"
#include <fairlogger/Logger.h>

#include "DataFormatsTRD/Constants.h"
#include "DataFormatsTRD/RawData.h"
#include "DataFormatsTRD/TrapRegInfo.h"
#include "DataFormatsTRD/TrapRegisters.h"
#include "DataFormatsTRD/Digit.h"

#include <string>
#include <map>
#include <unordered_map>
#include <array>
#include <vector>
#include <bitset>
#include <gsl/span>

namespace o2::trd
{

/*!
A class to hold a configuration event from a single mcm.
All packed registers are simply stored in an array.
Unpacking and packing is internal to this class.
*/

class MCMEvent
{

public:
MCMEvent() = default;
MCMEvent(int mcmid) { setMCMId(mcmid); }
~MCMEvent() = default;
// get and set the mcmid, this could be extracted from the location of this class in other objects. Its just easier to have it handy here.
int32_t const getMCMId() { return mMCMId; }
void setMCMId(const int32_t mcmid) { mMCMId = mcmid; }

// get and set a specific register. Get/Set the value from its internal compressed format.
bool setRegister(const uint32_t data, const uint32_t regidx, const TrapRegInfo& trapreg);

// bool setRegister(const uint32_t data, const uint32_t regidx, const uint32_t base, const uint32_t wordnumber, const uint32_t shift, const uint32_t mask);
const uint32_t getRegister(const uint32_t regidx, const TrapRegInfo& trapreg) const;

const uint32_t getvalue(const uint32_t index) { return mRegisterData[index]; };

private:
std::array<uint32_t, o2::trd::kTrapRegistersSize> mRegisterData{0}; // a block of mcm register data.
int32_t mMCMId{-1}; // the id of this mcm. -1 to know when it has not been set yet.
ClassDefNV(MCMEvent, 1);
};

} // namespace o2::trd

#endif
50 changes: 50 additions & 0 deletions DataFormats/Detectors/TRD/include/DataFormatsTRD/RawData.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <map>
#include <cstdint>
#include <ostream>
#include <bitset>
#include "DataFormatsTRD/Constants.h"
#include "Rtypes.h"

Expand Down Expand Up @@ -429,6 +430,55 @@ struct LinkToHCIDMapping {
ClassDefNV(LinkToHCIDMapping, 1);
};

struct DigitHCHeaderAll {
// store all the digit hcheaders for carrying them around all together.
// all 4 of them are 32 bit integers and its simpler to just store them like that.
std::array<uint32_t, 4> mHeaders;
std::bitset<4> mHasHeader;
bool isSet(int header) { return mHasHeader.test(header); }
void setHeader(uint32_t header, uint32_t value)
{
mHasHeader.set(header);
mHeaders[header] = value;
}
uint32_t getHeader(uint32_t header)
{
if (isSet(header))
return mHeaders[header];
else
return 0;
}
uint32_t getHeader()
{
if (isSet(0)) {
return mHeaders[0];
} else
return 0;
}
uint32_t getHeader1()
{
if (isSet(1)) {
return mHeaders[1];
} else
return 0;
}
uint32_t getHeader2()
{
if (isSet(2)) {
return mHeaders[2];
} else
return 0;
}
uint32_t getHeader3()
{
if (isSet(3)) {
return mHeaders[3];
} else
return 0;
}
void reset() { mHeaders.fill(0); } ///< reset the headers to zero
};

uint32_t setHalfCRUHeader(HalfCRUHeader& cruhead, int crurdhversion, int bunchcrossing, int stopbits, int endpoint, int eventtype, int feeid, int cruid);
uint32_t setHalfCRUHeaderLinkData(HalfCRUHeader& cruhead, int link, int size, int errors);
uint32_t getlinkerrorflag(const HalfCRUHeader& cruhead, const uint32_t link);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ enum OptionBits {
TRDGenerateStats,
TRDOnlyCalibrationTriggerBit,
TRDSortDigits,
TRDLinkStats
TRDLinkStats,
TRDEnableConfigEvents
}; // this is currently 16 options, the array is 16, if you add here you need to change the 16;

struct DataCountersPerTrigger {
Expand Down
134 changes: 134 additions & 0 deletions DataFormats/Detectors/TRD/include/DataFormatsTRD/TrapConfigEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef O2_TRDTRAPCONFIGEVENT_H
#define O2_TRDTRAPCONFIGEVENT_H

#include "CommonDataFormat/InteractionRecord.h"
#include <fairlogger/Logger.h>

#include "DataFormatsTRD/Constants.h"
#include "DataFormatsTRD/RawData.h"
#include "DataFormatsTRD/MCMEvent.h"
#include "DataFormatsTRD/Digit.h"
#include "DataFormatsTRD/TrapRegisters.h"
#include "DataFormatsTRD/TrapRegInfo.h"

#include <string>
#include <map>
#include <unordered_map>
#include <array>
#include <vector>
#include <bitset>
#include <gsl/span>

namespace o2::trd
{

class TrapConfigEvent
{
// class that is actually stored in ccdb.
// it holds a compressed version of what comes in the config events

public:
TrapConfigEvent();
~TrapConfigEvent() = default;

TrapConfigEvent(const TrapConfigEvent& A);

// get a config register value by index, addr, and name, via mcm index
uint32_t getRegisterValue(const uint32_t regidx, const int mcmidx);
bool setRegisterValue(const uint32_t data, const uint32_t regidx, const int mcmidx);

// get a registers index (enum value) by address or name
// due to the speed, it is never used in normal operations, only debugging.
int32_t getRegIndexByName(const std::string& name);

// get a registers address by index or name
int32_t getRegAddrByIdx(const unsigned int regidx);
int32_t getRegAddrByName(const std::string& name);

// move to parser bool isValidAddress(const uint32_t addr);
const std::string getRegisterName(const unsigned int regidx) { return mTrapRegisters[regidx].getName(); }
const uint32_t getRegisterMax(const unsigned int regidx) { return mTrapRegisters[regidx].getMax(); }
const uint32_t getRegisterNBits(const unsigned int regidx) { return mTrapRegisters[regidx].getNbits(); }
const TrapRegInfo& getRegisterInfo(const uint32_t regidx) { return mTrapRegisters[regidx]; }
const uint16_t getRegisterAddress(const uint32_t regidx) { return mTrapRegisters[regidx].getAddr(); }

// return all the registers for a particular mcm
void getAllRegisters(const int mcmidx, std::array<uint32_t, o2::trd::TrapRegisters::kLastReg>& registers);

// return all the mcm values for a particular register index
void getAllMCMByIndex(const int regindex, std::array<uint32_t, o2::trd::constants::MAXMCMCOUNT>& registers);

// return all the mcm values for a particular register name
void getAllMCMByName(const std::string& registername, std::array<uint32_t, o2::trd::constants::MAXMCMCOUNT>& mcms);

// return all the config data in an unpacked array.
void getAll(std::array<uint32_t, o2::trd::TrapRegisters::kLastReg * o2::trd::constants::MAXMCMCOUNT>& configdata);

// population pending
uint32_t getConfigVersion(const int mcmid = 0) { return getRegisterValue(TrapRegisters::kQ2VINFO, mcmid); } // these must some how be gotten from git or wingdb.
uint32_t getConfigName(const int mcmid = 0) { return getRegisterValue(TrapRegisters::kQ2VINFO, mcmid); } // these must be gotten from git or wingdb.
uint16_t getConfigSavedVersion(const int mcmid = 0) { return getRegisterValue(TrapRegisters::kVINFO, mcmid); } // the version that is saved, for the ability to later save the config differently.

bool isConfigDifferent(const TrapConfigEvent& trapconfigevent) const;

// for compliance with the same interface to o2::trd::TrapConfig and its run1/2 inherited interface:
// only these 2 are used in the simulations.
uint32_t getDmemUnsigned(uint32_t address, int detector, int rob, int mcm);
uint32_t getTrapReg(const uint32_t index, const int detector, const int rob, const int mcm);

bool isHCIDPresent(const int hcid) const { return mHCIDPresent.test(hcid); }
void HCIDIsPresent(const int hcid) { mHCIDPresent.set(hcid); }
uint32_t countHCIDPresent() { return mHCIDPresent.count(); }
const std::bitset<constants::MAXHALFCHAMBER>& getHCIDPresent() const { return mHCIDPresent; }
bool isMCMPresent(const int mcmid) const { return (mConfigDataIndex[mcmid] != -1) ? true : false; }
// const std::bitset<constants::MAXMCMCOUNT>& getMCMPresent() const { return mMCMPresent; }
uint32_t countMCMPresent() { return constants::MAXMCMCOUNT - std::count(mConfigDataIndex.begin(), mConfigDataIndex.end(), -1); } // count those indices not set and subtract from the total number of mcm
// void clearMCMPresent() { mMCMPresent.reset(); }
void clearMCMEvent() { mConfigData.clear(); }
void clear()
{
// clearMCMPresent();
clearMCMEvent();
}
bool ignoreWord(const int offset) const { return mWordNumberIgnore.test(offset); }

// required for a container for calibration
void fill(const TrapConfigEvent& input);
void fill(const gsl::span<const TrapConfigEvent> input); // dummy!
void merge(const TrapConfigEvent* prev);
void print();
int getRegisterBase(const int regidx) { return mTrapRegisters[regidx].getBase(); }
const MCMEvent& getMCMEvent(const int mcmidx) { return mConfigData[mcmidx]; }
int getMCMEventSize() { return mConfigDataIndex.size(); }
uint32_t getrawdata(uint32_t idx) { return mConfigData[0].getvalue(idx); }
// TODO put into QC
void buildAverage();
void buildDefaults();
void setDefaultRegisterValue(const int regidx, const uint32_t registervalue) { mDefaultRegisters.setRegister(regidx, registervalue, mTrapRegisters[regidx]); }
uint32_t getDefaultRegisterValue(const int regidx) { return mDefaultRegisters.getRegister(regidx, mTrapRegisters[regidx]); }

private:
TrapRegisters mTrapRegisters;
MCMEvent mDefaultRegisters; // default values for registers
std::bitset<constants::MAXHALFCHAMBER> mHCIDPresent{0}; // did the link actually receive data.
std::vector<MCMEvent> mConfigData; // vector of register data blocks
std::array<int32_t, constants::MAXMCMCOUNT> mConfigDataIndex{-1}; // one block of data per mcm, array as one wants to query if an mcm is present with having to walk the whole index.
// std::map<uint16_t, uint16_t> mTrapRegistersAddressIndexMap; moved to parser //!< map of address into mTrapRegisters, populated at the end of initialiseRegisters
std::bitset<kTrapRegistersSize> mWordNumberIgnore; // whether to ignore a register or not. Here to speed lookups up.
ClassDefNV(TrapConfigEvent, 3);
};

} // namespace o2::trd

#endif
Loading