Project
Loading...
Searching...
No Matches
TrapConfig.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_TRAPCONFIG_H
13#define O2_TRAPCONFIG_H
14
15#include <string>
16#include <vector>
17#include <memory>
18#include <iostream>
19#include <ostream>
20#include <fstream>
21#include <sstream>
22#include "Rtypes.h"
23#include <fairlogger/Logger.h>
24// Configuration of the TRD Tracklet Processor
25// (TRD Front-End Electronics)
26// There is a manual to describe all the internals of the electronics.
27// A very detailed manual, will try put it in the source code.
28// TRAP registers
29// TRAP data memory (DMEM)
30//
31namespace o2
32{
33namespace trd
34{
35
38 public:
39 TrapConfig();
41
42 // allocation
54 // common to registers and DMEM
55
56 // registers
491 kLastReg }; // enum of all TRAP registers, to be used for access to them
492
493 static const int mlastAlloc = kAllocLast;
494 bool setTrapRegAlloc(TrapReg_t reg, Alloc_t mode) { return mRegisterValue[reg].allocate(mode); }
495 bool setTrapReg(TrapReg_t reg, int value, int det);
496 bool setTrapReg(TrapReg_t reg, int value, int det, int rob, int mcm);
497
498 int getTrapReg(TrapReg_t reg, int det = -1, int rob = -1, int mcm = -1);
499
500 void resetRegs();
501 std::string getConfigVersion() { return mTrapConfigVersion; }
502 std::string getConfigName() { return mTrapConfigName; }
504 void setConfigName(std::string name) { mTrapConfigName = name; }
505 // data memory (DMEM)
506 bool setDmemAlloc(int addr, Alloc_t mode);
507 bool setDmem(int addr, unsigned int value, int det);
508 bool setDmem(int addr, unsigned int value, int det, int rob, int mcm);
509 bool setDmem(int addr, int value) { return setDmem(addr, (unsigned int)value); }
510 bool setDmem(int addr, int value, int det, int rob, int mcm) { return setDmem(addr, (unsigned int)value, det, rob, mcm); }
511
512 unsigned int getDmemUnsigned(int addr, int det, int rob, int mcm);
513
514 void resetDmem();
516 // not implemented due to not doing online gains
517 // double getFGANrm(int det, int rob, int mcm, int ch){return mGainTable.getFGANrm(det,rob,mcm,ch);};
518 // double getFGFNrm(int det, int rob,int mcm, int ch){return mGainTable.getFGFNrm(det,rob,mcm,ch);};
519 // double getAdcdacrm(int det, int rob, int mcm){return mGainTable.getAdcdacrm(det,rob,mcm);};
520
521 // access by 16-bit address
522 unsigned int peek(int addr, int det, int rob, int mcm);
523 bool poke(int addr, unsigned int value, int det, int rob, int mcm);
524
525 // helper methods
526 std::string getRegName(TrapReg_t reg) { return ((reg >= 0) && (reg < kLastReg)) ? mRegisterValue[reg].getName() : ""; }
527 unsigned short getRegAddress(TrapReg_t reg) { return ((reg >= 0) && (reg < kLastReg)) ? mRegisterValue[reg].getAddr() : 0; }
528 unsigned short getRegNBits(TrapReg_t reg) { return ((reg >= 0) && (reg < kLastReg)) ? mRegisterValue[reg].getNbits() : 0; }
529 unsigned int getRegResetValue(TrapReg_t reg) { return ((reg >= 0) && (reg < kLastReg)) ? mRegisterValue[reg].getResetValue() : 0; }
530
532
533 bool printTrapReg(TrapReg_t reg, int det = -1, int rob = -1, int mcm = -1);
534 bool printTrapAddr(int addr, int det = -1, int rob = -1, int mcm = -1);
535
536 void printMemDatx(std::ostream& os, int addr);
537 void printMemDatx(std::ostream& os, int addr, int det, int rob, int mcm);
538 void printMemDatx(std::ostream& os, TrapReg_t reg);
539 void printMemDatx(std::ostream& os, TrapReg_t reg, int det, int rob, int mcm);
540 void printDatx(std::ostream& os, unsigned int addr, unsigned int data, int rob, int mcm);
541
542 void printVerify(std::ostream& os, int det, int rob, int mcm);
543
544 static const int mgkDmemStartAddress = 0xc000; // start address in TRAP GIO
545 static const int mgkDmemWords = 0x400; // number of words in DMEM
546
547 static const int mgkImemStartAddress = 0xe000; // start address in TRAP GIO
548 static const int mgkImemWords = 0x1000; // number of words in IMEM
549
550 static const int mgkDbankStartAddress = 0xf000; // start address in TRAP GIO
551 static const int mgkDbankWords = 0x0100; // number of words in DBANK
552
554 {
555 public:
556 TrapValue();
557 ~TrapValue() = default;
558
559 bool allocate(Alloc_t mode);
560 bool allocatei(int mode);
561 static const std::array<int, TrapConfig::mlastAlloc> mgkSize; //= {0, 1, 540, 1080, 8 * 18 * 540, 4, 6, 8 * 18 * 30};
562 //static const std::array<int,TrapConfig::mlastAlloc> mgkSize; // required array dimension for different allocation modes
563 //this is used purely for copying data from run2 ocdb to run3 ccdb.
564 void setDataFromRun2(int value, int valid, unsigned int index)
565 {
566 if (index < mData.size()) {
567 mData[index] = value;
568 mValid[index] = valid;
569 } else {
570 LOG(debug) << "attempt to write data outside array with size : " << mData.size() << "and index of :" << index;
571 }
572 }
573 //next 3 functions are putrely for back ref cross checks to run2.
574 int getAllocMode() { return (int)mAllocMode; }
575 unsigned int getDataRaw(int i) { return mData[i]; }
576 unsigned int getValidRaw(int i) { return mValid[i]; }
577 unsigned int getDataSize() { return mData.size(); }
578
579 protected:
580 bool setData(unsigned int value);
581 bool setData(unsigned int value, int det);
582 bool setData(unsigned int value, int det, int rob, int mcm);
583
584 unsigned int getData(int det, int rob, int mcm);
585
586 int getIdx(int det, int rob, int mcm);
587
588 private:
589 TrapValue(const TrapValue& rhs); // not implemented
590 TrapValue& operator=(const TrapValue& rhs); // not implemented
591
592 Alloc_t mAllocMode; // allocation mode
593 std::vector<unsigned int> mData; //[mSize] data array
594 std::vector<bool> mValid; //[mSize] valid flag
595 ClassDefNV(TrapValue, 1);
596 };
597
598 class TrapRegister : public TrapValue
599 {
600 public:
601 TrapRegister();
603
604 void init(const char* name, int addr, int nBits, int resetValue);
605 void initfromrun2(const char* name, int addr, int nBits, int resetValue);
607
608 bool setValue(int value, int det) { return setData(value, det); }
609 bool setValue(int value, int det, int rob, int mcm) { return setData(value, det, rob, mcm); }
610
611 int getValue(int det, int rob, int mcm) { return getData(det, rob, mcm); }
612 std::string getName() { return mName; }
613 unsigned short getAddr() { return mAddr; }
614 unsigned short getNbits() { return mNbits; }
615 unsigned int getResetValue() { return mResetValue; }
616
617 protected:
620
621 // fixed properties of the register
622 // which do not need to be stored
623 std::string mName;
624 unsigned short mAddr;
625 unsigned short mNbits;
626 unsigned int mResetValue;
628 };
629
630 class TrapDmemWord : public TrapValue
631 {
632 public:
634 ~TrapDmemWord() = default;
635
636 void reset() { setData(0); }
637
638 bool setValue(unsigned int value, int det) { return setData(value, det); }
639 bool setValue(unsigned int value, int det, int rob, int mcm) { return setData(value, det, rob, mcm); }
640
641 unsigned int getValue(int det, int rob, int mcm) { return getData(det, rob, mcm); }
642
643 void setAddress(unsigned short addr)
644 {
645 mAddr = addr;
646 std::stringstream mNamestream;
647 mNamestream << "DMEM 0x" << std::hex << mAddr;
648 mName = mNamestream.str();
649 }
650 std::string getName() { return mName; }
651 unsigned short getAddress() { return mAddr; }
652
653 protected:
654 TrapDmemWord(const TrapDmemWord& rhs); // not implemented
655 TrapDmemWord& operator=(const TrapDmemWord& rhs); // not implemented
656
657 std::string mName;
658 unsigned short mAddr;
660 };
661
662 // protected:
663 void initRegs();
664
665 // configuration registers
666 std::array<TrapRegister, kLastReg> mRegisterValue{}; // array of TRAP register values in use
667
668 // DMEM
669 std::array<TrapDmemWord, mgkDmemWords> mDmem{}; // TRAP data memory
670
671 static const int mgkMcmlistSize = 256; // list of MCMs to which a value has to be written
672
674 std::array<TrapReg_t, 0x400 + 0x200 + 0x4> mgRegAddressMap{};
675
676 const std::array<int, 3> mgkRegisterAddressBlockStart = {0x0a00, 0x3000, 0xd000};
677 const std::array<int, 3> mgkRegisterAddressBlockSize = {0x0400, 0x0200, 0x0004};
678 std::string mTrapConfigName;
680 void PrintDmemValue3(TrapConfig::TrapDmemWord* trapval, std::ofstream& output);
681 void PrintRegisterValue3(TrapConfig::TrapRegister* trapval, std::ofstream& output);
682 void DumpTrapConfig2File(std::string filename);
683
684 private:
685 // TrapConfig& operator=(const TrapConfig& rhs); // not implemented
686 // TrapConfig(const TrapConfig& cfg); // not implemented
687
688 ClassDefNV(TrapConfig, 1);
689};
690} //namespace trd
691} //namespace o2
692#endif
uint16_t mcm
uint16_t rob
int32_t i
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
uint32_t version
Definition RawData.h:8
std::ostringstream debug
const auto & getData()
ClassDefNV(TrapDmemWord, 1)
address
TrapDmemWord & operator=(const TrapDmemWord &rhs)
TrapDmemWord(const TrapDmemWord &rhs)
unsigned int getValue(int det, int rob, int mcm)
Definition TrapConfig.h:641
void setAddress(unsigned short addr)
Definition TrapConfig.h:643
bool setValue(unsigned int value, int det)
Definition TrapConfig.h:638
bool setValue(unsigned int value, int det, int rob, int mcm)
Definition TrapConfig.h:639
unsigned int mResetValue
Number of bits, from 1 to 32.
Definition TrapConfig.h:626
void initfromrun2(const char *name, int addr, int nBits, int resetValue)
bool setValue(int value, int det, int rob, int mcm)
Definition TrapConfig.h:609
int getValue(int det, int rob, int mcm)
Definition TrapConfig.h:611
ClassDefNV(TrapRegister, 1)
reset value
void init(const char *name, int addr, int nBits, int resetValue)
TrapRegister(const TrapRegister &rhs)
bool setValue(int value, int det)
Definition TrapConfig.h:608
TrapRegister & operator=(const TrapRegister &rhs)
unsigned short mAddr
Name of the register.
Definition TrapConfig.h:624
unsigned short mNbits
Address in GIO of TRAP.
Definition TrapConfig.h:625
unsigned int getValidRaw(int i)
Definition TrapConfig.h:576
static const std::array< int, TrapConfig::mlastAlloc > mgkSize
Definition TrapConfig.h:37
unsigned int getDataRaw(int i)
Definition TrapConfig.h:575
bool setData(unsigned int value)
void setDataFromRun2(int value, int valid, unsigned int index)
Definition TrapConfig.h:564
int getIdx(int det, int rob, int mcm)
static const int mgkDbankStartAddress
Definition TrapConfig.h:550
std::array< TrapDmemWord, mgkDmemWords > mDmem
Definition TrapConfig.h:669
void PrintDmemValue3(TrapConfig::TrapDmemWord *trapval, std::ofstream &output)
bool printTrapAddr(int addr, int det=-1, int rob=-1, int mcm=-1)
unsigned int peek(int addr, int det, int rob, int mcm)
bool setDmem(int addr, int value, int det, int rob, int mcm)
Definition TrapConfig.h:510
unsigned short getRegNBits(TrapReg_t reg)
Definition TrapConfig.h:528
void setConfigName(std::string name)
Definition TrapConfig.h:504
void printDatx(std::ostream &os, unsigned int addr, unsigned int data, int rob, int mcm)
unsigned short getRegAddress(TrapReg_t reg)
Definition TrapConfig.h:527
bool poke(int addr, unsigned int value, int det, int rob, int mcm)
bool setDmem(int addr, unsigned int value, int det)
void setConfigVersion(std::string version)
Definition TrapConfig.h:503
static const int mgkDmemStartAddress
Definition TrapConfig.h:544
std::string mTrapConfigName
Definition TrapConfig.h:678
unsigned int getDmemUnsigned(int addr, int det, int rob, int mcm)
std::string getRegName(TrapReg_t reg)
Definition TrapConfig.h:526
const std::array< int, 3 > mgkRegisterAddressBlockSize
Definition TrapConfig.h:677
void PrintRegisterValue3(TrapConfig::TrapRegister *trapval, std::ofstream &output)
unsigned int getRegResetValue(TrapReg_t reg)
Definition TrapConfig.h:529
static const int mgkImemStartAddress
Definition TrapConfig.h:547
bool setTrapReg(TrapReg_t reg, int value, int det)
const std::array< int, 3 > mgkRegisterAddressBlockStart
Definition TrapConfig.h:676
bool setDmemAlloc(int addr, Alloc_t mode)
std::array< TrapRegister, kLastReg > mRegisterValue
Definition TrapConfig.h:666
int getTrapReg(TrapReg_t reg, int det=-1, int rob=-1, int mcm=-1)
void printMemDatx(std::ostream &os, int addr)
std::array< TrapReg_t, 0x400+0x200+0x4 > mgRegAddressMap
Definition TrapConfig.h:674
static const int mgkDbankWords
Definition TrapConfig.h:551
void printVerify(std::ostream &os, int det, int rob, int mcm)
static const int mlastAlloc
Definition TrapConfig.h:493
static const int mgkImemWords
Definition TrapConfig.h:548
static const int mgkMcmlistSize
Definition TrapConfig.h:671
std::string getConfigVersion()
Definition TrapConfig.h:501
std::string mTrapConfigVersion
Definition TrapConfig.h:679
bool setTrapRegAlloc(TrapReg_t reg, Alloc_t mode)
Definition TrapConfig.h:494
std::string getConfigName()
Definition TrapConfig.h:502
TrapReg_t getRegByAddress(int address)
static const int mgkDmemWords
Definition TrapConfig.h:545
bool setDmem(int addr, int value)
Definition TrapConfig.h:509
bool printTrapReg(TrapReg_t reg, int det=-1, int rob=-1, int mcm=-1)
static bool mgRegAddressMapInitialized
Definition TrapConfig.h:673
void DumpTrapConfig2File(std::string filename)
GLenum mode
Definition glcorearb.h:266
GLuint GLuint64EXT address
Definition glcorearb.h:5846
GLuint index
Definition glcorearb.h:781
GLuint const GLchar * name
Definition glcorearb.h:781
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLboolean * data
Definition glcorearb.h:298
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"