17#include <FairParAsciiFileIo.h>
18#include <FairParGenericSet.h>
19#include <FairParamList.h>
20#include <FairRuntimeDb.h>
25#include <RtypesCore.h>
27#include <boost/format.hpp>
45 Int_t nModules(0), nAsics(0);
46 if (strcmp(parset->ClassName(),
"CbmTrdParSetAsic") == 0) {
50 if (!setDet)
continue;
54 nAsics += setDet->GetNofAsicsOnModule();
58 LOG(info) << GetName() <<
"::initParSet - for container " << parset->ClassName() <<
" modules " << nModules
59 <<
" asics " << nAsics;
61 else if (strcmp(parset->ClassName(),
"CbmTrdParSetDigi") == 0) {
64 for (
auto digi : digiPar) {
69 LOG(info) << GetName() <<
"::initParSet - for container " << parset->ClassName() <<
" modules " <<
fModuleId.size();
71 else if (strcmp(parset->ClassName(),
"CbmTrdParSetGas") == 0) {
73 setPar->printParams();
76 else if (strcmp(parset->ClassName(),
"CbmTrdParSetGain") == 0) {
78 setPar->printParams();
82 LOG(error) <<
"Parameter set " << parset->ClassName() <<
" not known. Skip.";
89std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>*
92 LOG(info) << GetName() <<
"::GetParContainerRequest - for container " << geoTag.data() <<
" run " << runId <<
" "
93 << fParFilesBasePath.data();
96 std::string basepath = Form(
"%s/trd_%s", fParFilesBasePath.data(), geoTag.data());
97 std::string temppath =
"";
100 std::string runpath =
"";
102 runpath =
".run" + std::to_string(runId);
105 temppath = basepath + runpath +
".digi" +
".par";
106 fParContVec.emplace_back(std::make_pair(temppath, std::make_shared<CbmTrdParSetDigi>()));
107 temppath = basepath + runpath +
".asic" +
".par";
108 fParContVec.emplace_back(std::make_pair(temppath, std::make_shared<CbmTrdParSetAsic>()));
120 const UChar_t lFasp = messes[0].getFaspIdMod();
127 LOG(error) << GetName() <<
"::pushDigis - Par for FASP " << (int) lFasp <<
" in module " << mod_id
128 <<
" missing. Skip.";
132 LOG(error) << GetName() <<
"::pushDigis - DIGI par for module " << mod_id <<
" missing. Skip.";
136 ULong64_t tdaqOffset(0);
143 for (
auto imess : messes) {
147 LOG(warn) << GetName() <<
"::pushDigis - FASP par " << mod_id * 1000 + lFasp <<
" ch " << int(imess.ch)
148 <<
" masked but have data. Masks need attention.";
150 const ULong64_t lTime =
fTime + tdaqOffset + imess.tlab;
151 const UShort_t lchR = chCalib->
HasPairingR() ? imess.data : 0;
152 const UShort_t lchT = chCalib->
HasPairingR() ? 0 : imess.data;
153 std::vector<CbmTrdDigi>& digiBuffer =
fDigiBuffer[pad];
158 printf(
"fasp[%2d] ch[%4d / %2d] pad[%4d] row[%2d] col[%2d] %c[%4d]\n", lFasp, ch, imess.ch, pad,
160 lchT > 0 ? lchT : lchR);
163 if (digiBuffer.size() == 0) {
164 digiBuffer.emplace_back(pad, lchT, lchR, lTime);
165 digiBuffer.back().SetAddressModule(mod_id);
170 auto id = digiBuffer.rbegin();
174 const Int_t dtime = (*id).GetTimeDAQ() - lTime;
177 if (TMath::Abs(dtime) < 5) {
178 r = (*id).GetCharge(t, dt);
179 if (lchR && r < 0.1) {
180 (*id).SetCharge(t, lchR, -dtime);
183 else if (lchT && t < 0.1) {
184 (*id).SetCharge(lchT, r, +dtime);
185 (*id).SetTimeDAQ(ULong64_t((*id).GetTimeDAQ() - dtime));
192 digiBuffer.emplace_back(pad, lchT, lchR, lTime);
193 digiBuffer.back().SetAddressModule(mod_id);
194 id = digiBuffer.rbegin();
201 for (++
id;
id != digiBuffer.rend(); ++id) {
202 r = (*id).GetCharge(t, dt);
203 if (lchR &&
int(r)) {
204 (*id).SetCharge(t, lchR, dt);
208 else if (lchT &&
int(t)) {
209 (*id).SetCharge(lchT, r, dt);
223 uint32_t uNbLostDigis = 0;
230 LOG(warn) << fName <<
"::ResetTimeslice - buffered digi pad=" << pad_id <<
" store " <<
fDigiBuffer[pad_id].size()
231 <<
" unprocessed digi.";
248 r = (*id).GetCharge(t, dt);
253 if (((t > 0) != (*id).IsFlagged(0)) || ((r > 0) != (*id).IsFlagged(1))) {
260 (*id).SetFlag(0,
false);
261 (*id).SetFlag(1,
false);
262 fOutputVec.emplace_back(std::move((*
id)));
266 if (nIncomplete > 2) {
267 LOG(warn) << fName <<
"FinalizeComponent() skip " << nIncomplete <<
" incomplete digi at pad " << ipad <<
".\n";
275 if (
VERBOSE) printf(
"CbmTrdUnpackFaspAlgo::unpack 0x%04x %d\n", icomp, imslice);
276 LOG(debug2) <<
"Component " << icomp <<
" connected to config CbmTrdUnpackConfig2D. Slice " << imslice;
278 bool unpackOk =
true;
281 auto msdesc = ts->descriptor(icomp, imslice);
285 printf(
"time start %lu system[0x%x] version[0x%x]\n",
static_cast<size_t>(msdesc.idx), msdesc.sys_id,
290 switch (msdesc.sys_ver) {
292 LOG(info) <<
"CbmTrdUnpackFaspAlgo::unpack : Legacy version.";
296 LOG(info) <<
"CbmTrdUnpackFaspAlgo::unpack : 06.2024 version.";
299 default: LOG(fatal) <<
"CbmTrdUnpackFaspAlgo::unpack : Un-registered version " << msdesc.sys_ver;
break;
303 fTime = ULong64_t((msdesc.idx - fTsStartTime - fSystemTimeOffset) / 12.5);
309 auto mssize = msdesc.size;
312 std::uint32_t nwords = mssize / 4;
314 const auto mspointer = ts->content(icomp, imslice);
317 const auto mscontent =
reinterpret_cast<const size_t*
>(mspointer);
319 const uint32_t* wd =
reinterpret_cast<const uint32_t*
>(mscontent);
322 uint8_t lFaspOld(0xff);
323 vector<CbmTrdFaspMessage> vMess;
324 for (uint64_t j = 0; j < nwords; j++, wd++) {
353 LOG(error) <<
"CbmTrdUnpackFaspAlgo::unpack : Epoch message with wrong signature. Ask an expert.";
365 vMess.emplace_back(*
fMess);
373 uint8_t t, uint16_t d, uint8_t lnk)
397 type = (w >> shift) & 0x1;
399 tlab = (w >> shift) & 0x7f;
401 data = (w >> shift) & 0x3fff;
404 fasp = ((w >> shift) & 0x3f);
407 printf(
"legacyMess_readDW[%x]\n", w);
418 type = (w >> shift) & 0x1;
420 epoch = (w >> shift) & 0x1fffff;
422 fasp = (w >> shift) & 0x3f;
425 printf(
"legacyMess_readEW[%x]\n", w);
434 cout << Form(
" DATA : rob=%d%c fasp_id=%02d [%03d] ch_id=%02d tclk=%03d data=%4d\n", rob, (elink ?
'u' :
'd'),
435 fasp, getFaspIdMod(), ch, tlab, data);
437 cout << Form(
" EPOCH: eq_id=%d%c ch_id=%02d epoch=%05d\n", rob, (elink ?
'u' :
'd'), ch, epoch);
439 cout <<
" MTYPE: unknown";
460 uint16_t adc_data = (w >> shift) & 0x3fff;
464 uint16_t sign = adc_data >> 13;
469 value_i = (-1) * ((adc_data ^ 0xffff) & 0x1fff);
471 data = (value_i + 0x1fff) >> 2;
473 tlab = (w >> shift) & 0x7f;
475 ch = (w >> shift) & 0xf;
477 fasp = ((w >> shift) & 0x3f);
479 type = (w >> shift) & 0x1;
483 printf(
"v06.24Mess_readDW[%x] signed charge = %+d\n", w, value_i);
492 epoch = (w >> shift) & 0x1fffff;
494 ch = (w >> shift) & 0xf;
496 fasp = (w >> shift) & 0x3f;
498 type = (w >> shift) & 0x1;
502 printf(
"v06.24Mess_readEW[%x]\n", w);
ClassImp(CbmConverterManager)
Trd FASP unpacking algorithm.
static constexpr size_t size()
Definition of FASP channel calibration container.
Bool_t HasPairingR() const
Query pad pairing type.
Bool_t HasPairingT() const
Definition of FASP parameters.
virtual void Print(Option_t *opt="") const
const CbmTrdParFaspChannel * GetChannel(Int_t pad_address, UChar_t pair) const
Query the calibration for one FASP RO channel.
int GetPadAddress(Int_t ich) const
Describe TRD module ASIC settings (electronic gain, delays, etc)
virtual const CbmTrdParAsic * GetAsicPar(Int_t address) const
Look for the ASIC parameters of a given DAQ id It applies to the list of ASICs.
Definition of chamber gain conversion for one TRD module.
Int_t GetPadRow(const Int_t channelNumber) const
Int_t GetPadColumn(const Int_t channelNumber) const
Describe TRD module ASIC settings (electronic gain, delays, etc)
virtual int FindModuleByEqId(uint16_t eqid, uint8_t &rob_id, uint8_t &lnk_id) const
Search for the module in the setup parameters by equipement id.
Describe TRD module working settings (HV, etc)
virtual Int_t GetNrOfModules() const
virtual const CbmTrdParMod * GetModulePar(Int_t detId) const
std::map< Int_t, CbmTrdParMod * > GetModuleMap()
virtual void addParam(CbmTrdParMod *mod)
virtual void readEW(uint32_t w)
virtual eMessageType getType(uint32_t w) const
virtual void readDW(uint32_t w)
Data structure for unpacking the FASP word.
uint8_t elink
optical link for read-out unit (up or down, starting with v2024)
eMessageVersion version
format version
virtual int getFaspIdMod() const
uint8_t type
message type 0 = data, 1 = epoch
virtual void print() const
uint8_t rob
Read-Out unit id in the module.
virtual eMessageType getType(uint32_t w) const
uint32_t mod
full module address according to CbmTrdAddress
virtual void readDW(uint32_t w)
virtual void readEW(uint32_t w)
uint8_t ch
ch id in the FASP
CbmTrdFaspMessage()=default
std::array< std::vector< CbmTrdDigi >, NFASPMOD *NFASPCH > fDigiBuffer
CbmTrdParSetAsic fAsicSet
uint32_t ResetTimeslice()
Check and assure there are no data left-overs.
virtual std::vector< std::pair< std::string, std::shared_ptr< FairParGenericSet > > > * GetParContainerRequest(std::string geoTag, std::uint32_t runId)
Get the requested parameter containers. Return the required parameter containers together with the pa...
bool unpack(const fles::Timeslice *ts, std::uint16_t icomp, UInt_t imslice)
Unpack a given microslice.
@ kMess24
unpacker version for 2-board FASPRO+GETS HW
CbmTrdUnpackFaspAlgo()
Create the Cbm Trd Unpack AlgoBase object.
std::vector< uint16_t > fModuleId
CbmTrdFaspMessage * fMess
Bool_t initParSet(FairParGenericSet *parset)
Handles the distribution of the hidden derived classes to their explicit functions.
void FinalizeComponent()
Finalize component (e.g. copy from temp buffers)
std::shared_ptr< CbmTrdUnpackFaspMonitor > fMonitor
Potential (online) monitor for the unpacking process.
bool pushDigis(std::vector< CbmTrdUnpackFaspAlgo::CbmTrdFaspMessage > messages, const uint16_t mod_id)
CbmTrdParSetDigi * fDigiSet
virtual ~CbmTrdUnpackFaspAlgo()
Destroy the Cbm Trd Unpack Task object.
ULong64_t fTime
Time offset for digi wrt the TS start, expressed in 80 MHz clks. It contains:
#define FASP_EPOCH_LENGTH