Project
Loading...
Searching...
No Matches
TOFFEElightReader.cxx
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
13#include "Framework/Logger.h"
14#include "TSystem.h"
15#include <fstream>
16
17using namespace o2::tof;
18
19void TOFFEElightReader::loadFEElightConfig(const char* fileName)
20{
21 // load FEElight config
22
23 char* expandedFileName = gSystem->ExpandPathName(fileName);
24 std::ifstream is;
25 is.open(expandedFileName, std::ios::binary);
26 mFileLoadBuff.reset(new char[sizeof(o2::tof::TOFFEElightConfig)]);
27 is.read(mFileLoadBuff.get(), sizeof(o2::tof::TOFFEElightConfig));
28 is.close();
29 mFEElightConfig = reinterpret_cast<const TOFFEElightConfig*>(mFileLoadBuff.get());
30}
31
32//_______________________________________________________________
33void TOFFEElightReader::loadFEElightConfig(gsl::span<const char> configBuf)
34{
35 // load FEElight config from buffer
36
37 if (configBuf.size() != sizeof(o2::tof::TOFFEElightConfig)) {
38 LOG(fatal) << "Incoming message with TOFFEE configuration does not match expected size: " << configBuf.size() << " received, " << sizeof(*mFEElightConfig) << " expected";
39 }
40 mFEElightConfig = reinterpret_cast<const TOFFEElightConfig*>(configBuf.data());
41}
42
43//_______________________________________________________________
44
46{
47 // parse FEElight config
48 // loops over all FEE channels, checks whether they are enabled
49 // and sets channel enabled
50
51 mFEElightInfo.resetAll();
52
53 int version = mFEElightConfig->mVersion;
54 int runNumber = mFEElightConfig->mRunNumber;
55 int runType = mFEElightConfig->mRunType;
56
57 mFEElightInfo.mVersion = version;
58 mFEElightInfo.mRunNumber = runNumber;
59 mFEElightInfo.mRunType = runType;
60
61 int nEnabled = 0, index;
62 const TOFFEEchannelConfig* channelConfig = nullptr;
63 for (int crateId = 0; crateId < Geo::kNCrate; crateId++) {
64 for (int trmId = 0; trmId < Geo::kNTRM - 2; trmId++) { // in O2, the number of TRMs is 12, but in the FEE world it is 10
65 for (int chainId = 0; chainId < Geo::kNChain; chainId++) {
66 for (int tdcId = 0; tdcId < Geo::kNTdc; tdcId++) {
67 for (int channelId = 0; channelId < Geo::kNCh; channelId++) {
68 channelConfig = mFEElightConfig->getChannelConfig(crateId, trmId, chainId, tdcId, channelId);
69 if (verbose) {
70 LOG(info) << "Processing electronic channel with indices: crate = " << crateId << ", trm = " << trmId << ", chain = "
71 << chainId << ", tdc = " << tdcId << ", tdcChannel = " << channelId << " -> " << channelConfig;
72 }
73 if (channelConfig) {
74 if (!channelConfig->isEnabled()) {
75 continue;
76 }
77 // get index DO from crate, trm, chain, tdc, tdcchannel
78 index = Geo::getCHFromECH(Geo::getECHFromIndexes(crateId, trmId + 3, chainId, tdcId, channelId)); // in O2, the TRM index is shifted by 3 because it corresponds to the VME slot
79 if (index == -1) {
80 continue;
81 }
82 nEnabled++;
83 if (verbose) {
84 LOG(info) << "Enabling channel " << index;
85 }
86 mFEElightInfo.mChannelEnabled[index] = channelConfig->isEnabled();
87 mFEElightInfo.mMatchingWindow[index] = channelConfig->mMatchingWindow;
88 mFEElightInfo.mLatencyWindow[index] = channelConfig->mLatencyWindow;
89 }
90 }
91 }
92 }
93 }
94 }
95
97 const int channelInSector = Geo::NPADS * Geo::NSTRIPXSECTOR;
98 for (int isector = 0; isector < Geo::NSECTORS; isector++) {
99 int nstripInPrevPlates = 0;
100 for (int iplate = 0; iplate < Geo::NPLATES; iplate++) {
101 unsigned int mask = mFEElightConfig->getHVConfig(isector, iplate);
102 for (int istrip = 0; istrip < istripInPlate[iplate]; istrip++) {
103 bool isActive = mask & 1; // check first bit/current_strip
104 mask /= 2; // move to the next bit/strip
105
106 if (!isActive) { // switch off all channels in this strip
107 int index0 = isector * channelInSector + (nstripInPrevPlates + istrip) * Geo::NPADS;
108 int indexF = index0 + Geo::NPADS;
109 for (int index = index0; index < indexF; index++) {
110 mFEElightInfo.mChannelEnabled[index] = 0;
111 }
112 }
113 }
114 nstripInPrevPlates += istripInPlate[iplate];
115 }
116 }
117
118 const TOFFEEtriggerConfig* triggerConfig = nullptr;
119 for (Int_t iddl = 0; iddl < TOFFEElightConfig::NTRIGGERMAPS; iddl++) {
120 triggerConfig = mFEElightConfig->getTriggerConfig(iddl);
121 if (verbose) {
122 LOG(info) << "Processing trigger config " << iddl << ": " << triggerConfig;
123 }
124 if (triggerConfig) {
125 mFEElightInfo.mTriggerMask[iddl] = triggerConfig->mStatusMap;
126 }
127 }
128
129 return nEnabled;
130}
uint32_t version
Definition RawData.h:8
static constexpr Int_t NSECTORS
Definition Geo.h:120
static constexpr Int_t NSTRIPXSECTOR
Definition Geo.h:116
static constexpr Int_t NPADS
Definition Geo.h:110
static constexpr Int_t NSTRIPB
Definition Geo.h:113
static constexpr Int_t NSTRIPC
Definition Geo.h:114
static constexpr Int_t NSTRIPA
Definition Geo.h:112
static Int_t getCHFromECH(int echan)
Definition Geo.h:352
@ kNTRM
Definition Geo.h:92
@ kNCrate
Definition Geo.h:95
@ kNTdc
Definition Geo.h:93
@ kNChain
Definition Geo.h:94
static constexpr Int_t NPLATES
Definition Geo.h:122
static Int_t getECHFromIndexes(int crate, int trm, int chain, int tdc, int chan)
Definition Geo.h:350
void loadFEElightConfig(const char *fileName)
int parseFEElightConfig(bool verbose=false)
GLuint index
Definition glcorearb.h:781
GLint GLuint mask
Definition glcorearb.h:291
const TOFFEEchannelConfig * getChannelConfig(int icrate, int itrm, int ichain, int itdc, int ich) const
const TOFFEEmapHVConfig * getHVConfig(int isector) const
static constexpr int NTRIGGERMAPS
const TOFFEEtriggerConfig * getTriggerConfig(int idx) const
std::array< bool, NCHANNELS > mChannelEnabled
std::array< int, NCHANNELS > mMatchingWindow
std::array< uint64_t, NTRIGGERMAPS > mTriggerMask
std::array< int, NCHANNELS > mLatencyWindow
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"