|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | +#include "FairLogger.h" |
| 11 | + |
| 12 | +#include "DataFormatsEMCAL/EMCALBlockHeader.h" |
| 13 | +#include "DataFormatsEMCAL/TriggerRecord.h" |
| 14 | +#include "EMCALWorkflow/RawToCellConverterSpec.h" |
| 15 | +#include "Framework/ControlService.h" |
| 16 | +#include "SimulationDataFormat/MCCompLabel.h" |
| 17 | +#include "SimulationDataFormat/MCTruthContainer.h" |
| 18 | +#include "EMCALBase/Geometry.h" |
| 19 | +#include "EMCALBase/Mapper.h" |
| 20 | +#include "EMCALReconstruction/CaloFitResults.h" |
| 21 | +#include "EMCALReconstruction/Bunch.h" |
| 22 | +#include "EMCALReconstruction/CaloRawFitterStandard.h" |
| 23 | +#include "EMCALReconstruction/AltroDecoder.h" |
| 24 | +#include "CommonDataFormat/InteractionRecord.h" |
| 25 | + |
| 26 | +using namespace o2::emcal::reco_workflow; |
| 27 | + |
| 28 | +void RawToCellConverterSpec::init(framework::InitContext& ctx) |
| 29 | +{ |
| 30 | + LOG(DEBUG) << "[EMCALRawToCellConverter - init] Initialize converter "; |
| 31 | + if (!mGeometry) { |
| 32 | + mGeometry = o2::emcal::Geometry::GetInstanceFromRunNumber(223409); |
| 33 | + } |
| 34 | + if (!mGeometry) |
| 35 | + LOG(ERROR) << "Failure accessing geometry"; |
| 36 | + |
| 37 | + if (!mMapper) { |
| 38 | + mMapper = std::unique_ptr<o2::emcal::MappingHandler>(new o2::emcal::MappingHandler); |
| 39 | + } |
| 40 | + if (!mMapper) |
| 41 | + LOG(ERROR) << "Failed to initialize mapper"; |
| 42 | + |
| 43 | + mRawFitter.setAmpCut(mNoiseThreshold); |
| 44 | + mRawFitter.setL1Phase(0.); |
| 45 | +} |
| 46 | + |
| 47 | +void RawToCellConverterSpec::run(framework::ProcessingContext& ctx) |
| 48 | +{ |
| 49 | + LOG(DEBUG) << "[EMCALRawToCellConverter - run] called"; |
| 50 | + |
| 51 | + mOutputCells.clear(); |
| 52 | + mOutputTriggerRecords.clear(); |
| 53 | + |
| 54 | + int firstEntry = 0; |
| 55 | + for (const auto& rawData : ctx.inputs()) { |
| 56 | + |
| 57 | + //o2::emcal::RawReaderMemory<o2::header::RAWDataHeaderV4> rawreader(gsl::span(rawData.payload, o2::framework::DataRefUtils::getPayloadSize(rawData))); |
| 58 | + |
| 59 | + o2::emcal::RawReaderMemory<o2::header::RAWDataHeaderV4> rawreader(o2::framework::DataRefUtils::as<const char>(rawData)); |
| 60 | + |
| 61 | + bool first = true; |
| 62 | + uint16_t currentTrigger = 0; |
| 63 | + uint32_t currentorbit = 0; |
| 64 | + |
| 65 | + // loop over all the DMA pages |
| 66 | + while (rawreader.hasNext()) { |
| 67 | + |
| 68 | + rawreader.next(); |
| 69 | + |
| 70 | + auto header = rawreader.getRawHeader(); |
| 71 | + |
| 72 | + if (!first) { // check if it is the first event in the payload |
| 73 | + std::cout << " triggerBC " << header.triggerBC << " current Trigger " << currentTrigger << std::endl; |
| 74 | + if (header.triggerBC > currentTrigger) { //new event |
| 75 | + mOutputTriggerRecords.emplace_back(o2::InteractionRecord(currentTrigger, currentorbit), firstEntry, mOutputCells.size() - 1); |
| 76 | + firstEntry = mOutputCells.size(); |
| 77 | + |
| 78 | + currentTrigger = header.triggerBC; |
| 79 | + currentorbit = header.triggerOrbit; |
| 80 | + } //new event |
| 81 | + } else { //first |
| 82 | + currentTrigger = header.triggerBC; |
| 83 | + std::cout << " first is true and I set triggerBC to currentTrigger " << currentTrigger << std::endl; |
| 84 | + currentorbit = header.triggerOrbit; |
| 85 | + std::cout << " and set first to false " << std::endl; |
| 86 | + first = false; |
| 87 | + } |
| 88 | + |
| 89 | + if (header.feeId > 40) |
| 90 | + continue; //skip STU ddl |
| 91 | + |
| 92 | + //std::cout<<rawreader.getRawHeader()<<std::endl; |
| 93 | + |
| 94 | + // use the altro decoder to decode the raw data, and extract the RCU trailer |
| 95 | + o2::emcal::AltroDecoder<decltype(rawreader)> decoder(rawreader); |
| 96 | + decoder.decode(); |
| 97 | + |
| 98 | + std::cout << decoder.getRCUTrailer() << std::endl; |
| 99 | + |
| 100 | + o2::emcal::Mapper map = mMapper->getMappingForDDL(header.feeId); |
| 101 | + |
| 102 | + // Loop over all the channels |
| 103 | + for (auto& chan : decoder.getChannels()) { |
| 104 | + |
| 105 | + int iRow = map.getRow(chan.getHardwareAddress()); |
| 106 | + int iCol = map.getColumn(chan.getHardwareAddress()); |
| 107 | + ChannelType_t chantype = map.getChannelType(chan.getHardwareAddress()); |
| 108 | + int iSM = header.feeId / 2; |
| 109 | + |
| 110 | + int CellID = mGeometry->GetAbsCellIdFromCellIndexes(iSM, iRow, iCol); |
| 111 | + |
| 112 | + // define the conatiner for the fit results, and perform the raw fitting using the stadnard raw fitter |
| 113 | + o2::emcal::CaloFitResults fitResults = mRawFitter.evaluate(chan.getBunches(), 0, 0); |
| 114 | + |
| 115 | + if (fitResults.getAmp() < 0 && fitResults.getTime() < 0) { |
| 116 | + fitResults.setAmp(0.); |
| 117 | + fitResults.setTime(0.); |
| 118 | + } |
| 119 | + mOutputCells.emplace_back(CellID, fitResults.getAmp(), fitResults.getTime(), chantype); |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + LOG(DEBUG) << "[EMCALRawToCellConverter - run] Writing " << mOutputCells.size() << " cells ..."; |
| 125 | + ctx.outputs().snapshot(o2::framework::Output{"EMC", "CELLS", 0, o2::framework::Lifetime::Timeframe}, mOutputCells); |
| 126 | + ctx.outputs().snapshot(o2::framework::Output{"EMC", "CELLSTRGR", 0, o2::framework::Lifetime::Timeframe}, mOutputTriggerRecords); |
| 127 | +} |
| 128 | + |
| 129 | +o2::framework::DataProcessorSpec o2::emcal::reco_workflow::getRawToCellConverterSpec() |
| 130 | +{ |
| 131 | + std::vector<o2::framework::InputSpec> inputs; |
| 132 | + std::vector<o2::framework::OutputSpec> outputs; |
| 133 | + |
| 134 | + inputs.emplace_back("readout-proxy", "FLP", "RAWDATA", 0, o2::framework::Lifetime::Timeframe); |
| 135 | + outputs.emplace_back("EMC", "CELLS", 0, o2::framework::Lifetime::Timeframe); |
| 136 | + outputs.emplace_back("EMC", "CELLSTRGR", 0, o2::framework::Lifetime::Timeframe); |
| 137 | + |
| 138 | + return o2::framework::DataProcessorSpec{"EMCALRawToCellConverterSpec", |
| 139 | + inputs, |
| 140 | + outputs, |
| 141 | + o2::framework::adaptFromTask<o2::emcal::reco_workflow::RawToCellConverterSpec>()}; |
| 142 | +} |
0 commit comments