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