Skip to content
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
21 changes: 20 additions & 1 deletion DataFormats/Detectors/ZDC/include/DataFormatsZDC/BCData.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ namespace zdc
{
class ChannelData;

struct __attribute__((__packed__)) ModuleTriggerMap {
unsigned Alice_0 : 1;
unsigned Alice_1 : 1;
unsigned Alice_2 : 1;
unsigned Alice_3 : 1;
unsigned Auto_m : 1;
unsigned Auto_0 : 1;
unsigned Auto_1 : 1;
unsigned Auto_2 : 1;
unsigned Auto_3 : 1;
unsigned empty : 7;
};

union ModuleTriggerMapData {
uint16_t w;
struct ModuleTriggerMap f;
void reset();
};

struct BCData {
/// we are going to refer to at most 26 channels, so 5 bits for the NChannels and 27 for the reference
o2::dataformats::RangeRefComp<5> ref;
Expand All @@ -48,7 +67,7 @@ struct BCData {
}

gsl::span<const ChannelData> getBunchChannelData(const gsl::span<const ChannelData> tfdata) const;
void print() const;
void print(uint32_t triggerMask = 0) const;

ClassDefNV(BCData, 2);
};
Expand Down
39 changes: 25 additions & 14 deletions DataFormats/Detectors/ZDC/src/BCData.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

using namespace o2::zdc;

void BCData::print() const
void BCData::print(uint32_t triggerMask) const
{
printf("Orbit %9u bc %4u nch %2d pos %d\n", ir.orbit, ir.bc, ref.getEntries(), ref.getFirstEntry());
printf("Read:");
Expand All @@ -32,15 +32,6 @@ void BCData::print() const
printf(" ");
}
}
printf("]\nTrigs:");
for (int i = 0; i < NChannels; i++) {
std::bitset<10> bb(moduleTriggers[i]);
printf("[%2d: %s]", i, bb.to_string().c_str());
if (i % (NChannels / 3) == 0 && i) {
printf("\n");
}
}

printf("]\nHits:");
for (int ic = 0; ic < NDigiChannels; ic++) {
if (ic % NChPerModule == 0) {
Expand All @@ -50,13 +41,33 @@ void BCData::print() const
printf("] %d[", ic / NChPerModule);
}
}
if (triggers & (0x1 << ic)) {
printf("H");
bool is_hit = triggers & (0x1 << ic);
bool is_trig = triggerMask & (0x1 << ic);
if (is_trig) {
if (is_hit) {
printf("T");
} else {
printf(".");
}
} else {
printf(" ");
if (is_hit) {
printf("H");
} else {
printf(" ");
}
}
}
printf("]\n");
printf("]\nAUTO:");
for (int i = 0; i < NModules; i++) {
std::bitset<10> bb(moduleTriggers[i]);
printf(" %d %s%s%s%s%s", i, bb[8] ? "3" : "-", bb[7] ? "2" : "-", bb[6] ? "1" : "-", bb[5] ? "0" : "-", bb[4] ? "M" : "-");
}
printf("\nALIT:");
for (int i = 0; i < NModules; i++) {
std::bitset<10> bb(moduleTriggers[i]);
printf(" %d %s%s%s%s ", i, bb[3] ? "3" : "-", bb[2] ? "2" : "-", bb[1] ? "1" : "-", bb[0] ? "0" : "-");
}
printf("\n");
}

gsl::span<const ChannelData> BCData::getBunchChannelData(const gsl::span<const ChannelData> tfdata) const
Expand Down
6 changes: 3 additions & 3 deletions Detectors/ZDC/base/include/ZDCBase/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class Geometry
static constexpr double ZEMPOSITION[3] = {9.69, 0., 760.};

private:
static Int_t getDetector(const Int_t det);
static Int_t getSector(const Int_t tow);
static Int_t getVolumeId(const Int_t* vol);
static int32_t getDetector(const int32_t det);
static int32_t getSector(const int32_t tow);
static int32_t getVolumeId(const int32_t* vol);

ClassDefNV(Geometry, 1);
};
Expand Down
3 changes: 1 addition & 2 deletions Detectors/ZDC/raw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# submit itself to any jurisdiction.

o2_add_library(ZDCRaw
SOURCES src/DumpRaw.cxx src/raw-parser.cxx
SOURCES src/DumpRaw.cxx src/raw-parser.cxx src/RawReaderZDCBase.cxx src/RawReaderBase.cxx
PUBLIC_LINK_LIBRARIES O2::SimulationDataFormat O2::ZDCBase O2::ZDCSimulation
O2::DataFormatsZDC O2::CCDB O2::SimConfig O2::DPLUtils
O2::DetectorsRaw O2::Headers)
Expand All @@ -28,4 +28,3 @@ o2_add_executable(raw-parser
O2::DetectorsRaw
O2::DetectorsCommonDataFormats
O2::CommonUtils)

2 changes: 1 addition & 1 deletion Detectors/ZDC/raw/include/ZDCRaw/DumpRaw.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DumpRaw
void init();
int process(const EventData& ev);
int process(const EventChData& ch);
int processWord(const UInt_t* word);
int processWord(const uint32_t* word);
int getHPos(uint32_t board, uint32_t ch);
void write();
void setVerbosity(int v)
Expand Down
245 changes: 245 additions & 0 deletions Detectors/ZDC/raw/include/ZDCRaw/RawReaderBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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.
//
//file RawReaderBase.h base class for RAW data reading
//
// Artur.Furs
// afurs@cern.ch
//
//Main purpuse is to decode ZDC data blocks and push them to DigitBlockFT0 for process

#ifndef ALICEO2_ZDC_RAWREADERBASE_H_
#define ALICEO2_ZDC_RAWREADERBASE_H_
#include <iostream>
#include <vector>
#include <map>

#include <Rtypes.h>
#include <CommonDataFormat/InteractionRecord.h>
#include "Headers/RAWDataHeader.h"
#include <Framework/Logger.h>
#include "DataFormatsZDC/RawEventData.h"
#include "ZDCSimulation/Digits2Raw.h"
#include "ZDCSimulation/SimCondition.h"

#include <gsl/span>
namespace o2
{
namespace zdc
{

class RawReaderBase
{
public:
RawReaderBase() = default;
~RawReaderBase() = default;

std::map<InteractionRecord, EventData> mMapData; /// Raw data cache
const ModuleConfig* mModuleConfig = nullptr; /// Trigger/readout configuration object
void setModuleConfig(const ModuleConfig* moduleConfig) { mModuleConfig = moduleConfig; };
const ModuleConfig* getModuleConfig() { return mModuleConfig; };

//decoding binary data into data blocks
EventChData mCh; // Channel data to be decoded
int processWord(const uint32_t* word)
{
if (word == nullptr) {
LOG(ERROR) << "NULL pointer";
return 1;
}
if ((word[0] & 0x3) == Id_w0) {
for (int32_t iw = 0; iw < NWPerGBTW; iw++) {
mCh.w[0][iw] = word[iw];
}
} else if ((word[0] & 0x3) == Id_w1) {
if (mCh.f.fixed_0 == Id_w0) {
for (int32_t iw = 0; iw < NWPerGBTW; iw++) {
mCh.w[1][iw] = word[iw];
}
} else {
LOG(ERROR) << "Wrong word sequence";
mCh.f.fixed_0 = Id_wn;
mCh.f.fixed_1 = Id_wn;
mCh.f.fixed_2 = Id_wn;
}
} else if ((word[0] & 0x3) == Id_w2) {
if (mCh.f.fixed_0 == Id_w0 && mCh.f.fixed_1 == Id_w1) {
for (int32_t iw = 0; iw < NWPerGBTW; iw++) {
mCh.w[2][iw] = word[iw];
}
process(mCh);
} else {
LOG(ERROR) << "Wrong word sequence";
}
mCh.f.fixed_0 = Id_wn;
mCh.f.fixed_1 = Id_wn;
mCh.f.fixed_2 = Id_wn;
} else {
// Word not present in payload
LOG(FATAL) << "Event format error";
return 1;
}
return 0;
}

void process(const EventChData& ch)
{
InteractionRecord ir(ch.f.bc, ch.f.orbit);
auto& mydata = mMapData[ir];
int32_t im = ch.f.board;
int32_t ic = ch.f.ch;
for (int32_t iwb = 0; iwb < NWPerBc; iwb++) {
for (int32_t iwg = 0; iwg < NWPerGBTW; iwg++) {
mydata.data[im][ic].w[iwb][iwg] = mCh.w[iwb][iwg];
}
}
}

//processing data blocks into digits
void processBinaryData(gsl::span<const uint8_t> payload, int linkID)
{
size_t payloadSize = payload.size();
for (int32_t ip = 0; ip < payloadSize; ip += 16) {
//o2::zdc::Digits2Raw::print_gbt_word((const uint32_t*)&payload[ip]);
processWord((const uint32_t*)&payload[ip]);
}
}
/*
void process(int linkID, gsl::span<const uint8_t> payload)
{
static_cast<RawReader*>(this)->processDigits(linkID,payload);
}
*/
//pop digits
int getDigits(std::vector<BCData>& digitsBC, std::vector<ChannelData>& digitsCh, std::vector<PedestalData>& pedestalData)
{
if (mModuleConfig == nullptr) {
LOG(FATAL) << "Missing ModuleConfig";
return 0;
}
int bcCounter = mMapData.size();
LOG(INFO) << "Processing #bc " << bcCounter;
for (auto& [ir, ev] : mMapData) {
// TODO: Error check
// Pedestal data
if (ir.bc == 3563) {
auto& pdata = pedestalData.emplace_back();
pdata.ir = ir;
for (int32_t im = 0; im < NModules; im++) {
for (int32_t ic = 0; ic < NChPerModule; ic++) {
if (ev.data[im][ic].f.fixed_0 == Id_w0 && ev.data[im][ic].f.fixed_1 == Id_w1 && ev.data[im][ic].f.fixed_2 == Id_w2) {
// Identify connected channel
auto id = mModuleConfig->modules[im].channelID[ic];
int offset = ev.data[im][ic].f.offset - 32768;
pdata.data[id] = offset;
} else if (ev.data[im][ic].f.fixed_0 == 0 && ev.data[im][ic].f.fixed_1 == 0 && ev.data[im][ic].f.fixed_2 == 0) {
// Empty channel
} else {
LOG(ERROR) << "Data format error";
}
}
}
}
// BC data
auto& bcdata = digitsBC.emplace_back();
bcdata.ir = ir;
// Channel data
bool inconsistent_event = false;
bool filled_event = false;
for (int32_t im = 0; im < NModules; im++) {
ModuleTriggerMapData mt;
mt.w = 0;
bool filled_module = false;
bool inconsistent_module = false;
for (int32_t ic = 0; ic < NChPerModule; ic++) {
if (ev.data[im][ic].f.fixed_0 == Id_w0 && ev.data[im][ic].f.fixed_1 == Id_w1 && ev.data[im][ic].f.fixed_2 == Id_w2) {
auto& ch = ev.data[im][ic];
uint16_t us[12];
us[0] = ch.f.s00;
us[1] = ch.f.s01;
us[2] = ch.f.s02;
us[3] = ch.f.s03;
us[4] = ch.f.s04;
us[5] = ch.f.s05;
us[6] = ch.f.s06;
us[7] = ch.f.s07;
us[8] = ch.f.s08;
us[9] = ch.f.s09;
us[10] = ch.f.s10;
us[11] = ch.f.s11;
// Identify connected channel
auto& chd = digitsCh.emplace_back();
auto id = mModuleConfig->modules[im].channelID[ic];
chd.id = id;
for (int32_t is = 0; is < NTimeBinsPerBC; is++) {
if (us[is] > ADCMax) {
chd.data[is] = us[is] - ADCRange;
} else {
chd.data[is] = us[is];
}
}
// Trigger bits
if (ch.f.Hit) {
bcdata.triggers |= (0x1 << ((im - 1) * NChPerModule + ic));
}
// TODO: Alice trigger bits
// TODO: consistency checks
if (filled_event == false) {
mt.f.Alice_0 = ch.f.Alice_0;
mt.f.Alice_1 = ch.f.Alice_1;
mt.f.Alice_2 = ch.f.Alice_2;
mt.f.Alice_3 = ch.f.Alice_3;
filled_event = true;
} else if (mt.f.Alice_0 != ch.f.Alice_0 || mt.f.Alice_1 != ch.f.Alice_1 || mt.f.Alice_2 != ch.f.Alice_2 || mt.f.Alice_3 != ch.f.Alice_3) {
inconsistent_event = true;
}
if (filled_module == false) {
mt.f.Auto_m = ch.f.Auto_m;
mt.f.Auto_0 = ch.f.Auto_0;
mt.f.Auto_1 = ch.f.Auto_1;
mt.f.Auto_2 = ch.f.Auto_2;
mt.f.Auto_3 = ch.f.Auto_3;
filled_module = true;
} else if (mt.f.Auto_m != ch.f.Auto_m || mt.f.Auto_0 != ch.f.Auto_0 || mt.f.Auto_1 != ch.f.Auto_1 || mt.f.Auto_2 != ch.f.Auto_2 || mt.f.Auto_3 != ch.f.Auto_3) {
inconsistent_module = true;
}
} else if (ev.data[im][ic].f.fixed_0 == 0 && ev.data[im][ic].f.fixed_1 == 0 && ev.data[im][ic].f.fixed_2 == 0) {
// Empty channel
} else {
LOG(ERROR) << "Data format error";
}
}
bcdata.moduleTriggers[im] = mt.w;
if (inconsistent_module == true) {
inconsistent_event = true;
}
}
if (inconsistent_event) {
LOG(ERROR) << "Inconsistent event";
for (int32_t im = 0; im < NModules; im++) {
for (int32_t ic = 0; ic < NChPerModule; ic++) {
if (ev.data[im][ic].f.fixed_0 == Id_w0 && ev.data[im][ic].f.fixed_1 == Id_w1 && ev.data[im][ic].f.fixed_2 == Id_w2) {
for (int32_t iw = 0; iw < NWPerBc; iw++) {
o2::zdc::Digits2Raw::print_gbt_word((const uint32_t*)&ev.data[im][ic].w[iw][0]);
}
}
}
}
}
}
mMapData.clear();
return bcCounter;
}
};

} // namespace zdc
} // namespace o2

#endif
Loading