From e95f4f3e22225ff0b16c2ae5680a93b820a93d7b Mon Sep 17 00:00:00 2001 From: Giacomo Volpe Date: Thu, 8 Aug 2019 15:41:42 +0200 Subject: [PATCH 001/208] WIP: clusterizer workflow --- Detectors/HMPID/CMakeLists.txt | 2 + Detectors/HMPID/base/CMakeLists.txt | 5 +- .../HMPID/base/include/HMPIDBase/Cluster.h | 33 ++++++ Detectors/HMPID/base/src/Cluster.cxx | 18 +++ Detectors/HMPID/reconstruction/CMakeLists.txt | 18 +++ .../include/HMPIDReconstruction/Clusterer.h | 59 ++++++++++ .../include/HMPIDReconstruction/DataReader.h | 12 ++ .../HMPID/reconstruction/src/Clusterer.cxx | 63 ++++++++++ .../HMPID/reconstruction/src/DataReader.cxx | 12 ++ .../src/HMPIDReconstructionLinkDef.h | 20 ++++ Detectors/HMPID/workflow/CMakeLists.txt | 23 ++++ .../include/HMPIDWorkflow/ClusterizerSpec.h | 26 ++++ .../include/HMPIDWorkflow/DigitReaderSpec.h | 52 ++++++++ .../HMPID/workflow/src/ClusterizerSpec.cxx | 111 ++++++++++++++++++ .../HMPID/workflow/src/DigitReaderSpec.cxx | 90 ++++++++++++++ .../HMPID/workflow/src/HMPIDRecoWorkflow.cxx | 35 ++++++ 16 files changed, 577 insertions(+), 2 deletions(-) create mode 100644 Detectors/HMPID/base/include/HMPIDBase/Cluster.h create mode 100644 Detectors/HMPID/base/src/Cluster.cxx create mode 100644 Detectors/HMPID/reconstruction/CMakeLists.txt create mode 100644 Detectors/HMPID/reconstruction/include/HMPIDReconstruction/Clusterer.h create mode 100644 Detectors/HMPID/reconstruction/include/HMPIDReconstruction/DataReader.h create mode 100644 Detectors/HMPID/reconstruction/src/Clusterer.cxx create mode 100644 Detectors/HMPID/reconstruction/src/DataReader.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h create mode 100644 Detectors/HMPID/workflow/CMakeLists.txt create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/ClusterizerSpec.h create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/DigitReaderSpec.h create mode 100644 Detectors/HMPID/workflow/src/ClusterizerSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/DigitReaderSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/HMPIDRecoWorkflow.cxx diff --git a/Detectors/HMPID/CMakeLists.txt b/Detectors/HMPID/CMakeLists.txt index 46b43743c005e..f9ecc0c9f62be 100644 --- a/Detectors/HMPID/CMakeLists.txt +++ b/Detectors/HMPID/CMakeLists.txt @@ -10,3 +10,5 @@ add_subdirectory(base) add_subdirectory(simulation) +add_subdirectory(reconstruction) +add_subdirectory(workflow) diff --git a/Detectors/HMPID/base/CMakeLists.txt b/Detectors/HMPID/base/CMakeLists.txt index 5f1940e8a6597..424f49648c968 100644 --- a/Detectors/HMPID/base/CMakeLists.txt +++ b/Detectors/HMPID/base/CMakeLists.txt @@ -9,10 +9,11 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDBase - SOURCES src/Param.cxx src/Digit.cxx + SOURCES src/Param.cxx src/Digit.cxx src/Cluster.cxx PUBLIC_LINK_LIBRARIES O2::CommonDataFormat O2::SimulationDataFormat ROOT::Physics) o2_target_root_dictionary(HMPIDBase HEADERS include/HMPIDBase/Param.h - include/HMPIDBase/Digit.h) + include/HMPIDBase/Digit.h + include/HMPIDBase/Cluster.h) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Cluster.h b/Detectors/HMPID/base/include/HMPIDBase/Cluster.h new file mode 100644 index 0000000000000..764dcfcf9c602 --- /dev/null +++ b/Detectors/HMPID/base/include/HMPIDBase/Cluster.h @@ -0,0 +1,33 @@ +// 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. + +#ifndef DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_CLUSTER_H_ +#define DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_CLUSTER_H_ + +#include "CommonDataFormat/TimeStamp.h" +//#include "HMPIDBase/Hit.h" // for hit +#include "HMPIDBase/Param.h" // for param +#include "TMath.h" + +namespace o2 +{ +namespace hmpid +{ + +/// \class Claster +/// \brief HMPID cluster implementation +class Cluster +{ +}; + +} // namespace hmpid +} // namespace o2 + +#endif /* DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_CLUSTER_H_ */ diff --git a/Detectors/HMPID/base/src/Cluster.cxx b/Detectors/HMPID/base/src/Cluster.cxx new file mode 100644 index 0000000000000..6c5dec851a0ad --- /dev/null +++ b/Detectors/HMPID/base/src/Cluster.cxx @@ -0,0 +1,18 @@ +// 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. + +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Param.h" +#include "TRandom.h" +#include "TMath.h" + +using namespace o2::hmpid; + +ClassImp(o2::hmpid::Digit); diff --git a/Detectors/HMPID/reconstruction/CMakeLists.txt b/Detectors/HMPID/reconstruction/CMakeLists.txt new file mode 100644 index 0000000000000..a9e882fa411b7 --- /dev/null +++ b/Detectors/HMPID/reconstruction/CMakeLists.txt @@ -0,0 +1,18 @@ +# 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. + +o2_add_library(HMPIDReconstruction + SOURCES src/Clusterer.cxx src/DataReader.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDBase + O2::HMPIDSimulation) + +o2_target_root_dictionary(HMPIDReconstruction + HEADERS include/HMPIDReconstruction/Clusterer.h + include/HMPIDReconstruction/DataReader.h) diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/Clusterer.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/Clusterer.h new file mode 100644 index 0000000000000..461729f2704e5 --- /dev/null +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/Clusterer.h @@ -0,0 +1,59 @@ +// 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 Clusterer.h +/// \brief Definition of the HMPID cluster finder +#ifndef ALICEO2_HMPID_CLUSTERER_H +#define ALICEO2_HMPID_CLUSTERER_H + +#include +#include +#include "HMPIDBase/Cluster.h" +#include "HMPIDBase/Digit.h" +#include "SimulationDataFormat/MCTruthContainer.h" +#include "SimulationDataFormat/MCCompLabel.h" + +namespace o2 +{ + +namespace hmpid +{ +class Clusterer +{ + using MCLabelContainer = o2::dataformats::MCTruthContainer; + using Cluster = o2::hmpid::Cluster; + using Digit = o2::hmpid::Digit; + + public: + Clusterer() = default; + ~Clusterer() = default; + + Clusterer(const Clusterer&) = delete; + Clusterer& operator=(const Clusterer&) = delete; + + void process(std::vector const& digits, std::vector& clusters, MCLabelContainer const* digitMCTruth); + + void setMCTruthContainer(o2::dataformats::MCTruthContainer* truth) { mClsLabels = truth; } + + private: + //void processChamber(std::vector& clusters, MCLabelContainer const* digitMCTruth); + //void fetchMCLabels(const Digit* dig, std::array& labels, int& nfilled) const; + + o2::dataformats::MCTruthContainer* mClsLabels = nullptr; // Cluster MC labels + + Digit* mContributingDigit[6]; //! array of digits contributing to the cluster; this will not be stored, it is temporary to build the final cluster + int mNumberOfContributingDigits; //! number of digits contributing to the cluster; this will not be stored, it is temporary to build the final cluster + void addContributingDigit(Digit* dig); + void buildCluster(Cluster& c, MCLabelContainer const* digitMCTruth); +}; + +} // namespace hmpid +} // namespace o2 +#endif /* ALICEO2_TOF_CLUSTERER_H */ diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/DataReader.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/DataReader.h new file mode 100644 index 0000000000000..e0cfd8791af4a --- /dev/null +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/DataReader.h @@ -0,0 +1,12 @@ +// 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 DataReader.h +/// \brief Definition of the TOF hit reader diff --git a/Detectors/HMPID/reconstruction/src/Clusterer.cxx b/Detectors/HMPID/reconstruction/src/Clusterer.cxx new file mode 100644 index 0000000000000..089b63787cde8 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/Clusterer.cxx @@ -0,0 +1,63 @@ +// 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 Clusterer.cxx +/// \brief Implementation of the HMPID cluster finder +#include +#include "FairLogger.h" // for LOG +#include "HMPIDBase/Cluster.h" +#include "HMPIDReconstruction/Clusterer.h" +#include "SimulationDataFormat/MCCompLabel.h" +#include "SimulationDataFormat/MCTruthContainer.h" +#include + +using namespace o2::hmpid; + +//__________________________________________________ +void Clusterer::process(std::vector const& digits, std::vector& clusters, MCLabelContainer const* digitMCTruth) +{ + TStopwatch timerProcess; + timerProcess.Start(); + + // reader.init(); + // int totNumDigits = 0; + // + // while (reader.getNextStripData(mStripData)) { + // LOG(DEBUG) << "HMPIDClusterer got Strip " << mStripData.stripID << " with Ndigits " + // << mStripData.digits.size(); + // totNumDigits += mStripData.digits.size(); + // + // processStrip(clusters, digitMCTruth); + // } + + // LOG(DEBUG) << "We had " << totNumDigits << " digits in this event"; + timerProcess.Stop(); + printf("Timing:\n"); + printf("Clusterer::process: "); + timerProcess.Print(); +} + +////__________________________________________________ +//void Clusterer::dig2Clu(std::vector& clusters, MCLabelContainer const* digitMCTruth) +//{ +// // method to clusterize +// +// // to be implemented +// +//} +////______________________________________________________________________ +//void Clusterer::formClu(Cluster& c, Digit* dig, o2::hmpid::Digit>& digits, MCLabelContainer const* digitMCTruth) +//{ +// // method to clusterize +// +// // to be implemented +// +//} +//______________________________________________________________________ diff --git a/Detectors/HMPID/reconstruction/src/DataReader.cxx b/Detectors/HMPID/reconstruction/src/DataReader.cxx new file mode 100644 index 0000000000000..b2306eab0eb09 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/DataReader.cxx @@ -0,0 +1,12 @@ +// 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 Clusterer.cxx +/// \brief Implementation of the HMPID data reader class diff --git a/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h b/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h new file mode 100644 index 0000000000000..23608c4bc6a4c --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h @@ -0,0 +1,20 @@ +// 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. + +#ifdef __CLING__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ class o2::hmpid::DataReader + ; +#pragma link C++ class o2::hmpid::Clusterer + ; + +#endif diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt new file mode 100644 index 0000000000000..78a7a79e3c9ea --- /dev/null +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -0,0 +1,23 @@ +# 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. + +o2_add_library(HMPIDWorkflow + SOURCES src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDBase + O2::HMPIDSimulation + O2::HMPIDReconstruction + O2::Framework) + +o2_add_executable(recoworkflow + COMPONENT_NAME hmpid + SOURCES src/HMPIDRecoWorkflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + + diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/ClusterizerSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ClusterizerSpec.h new file mode 100644 index 0000000000000..bf5f5bdbb5313 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ClusterizerSpec.h @@ -0,0 +1,26 @@ +// 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. + +#ifndef STEER_DIGITIZERWORKFLOW_HMPIDCLUSTERIZER_H_ +#define STEER_DIGITIZERWORKFLOW_HMPIDCLUSTERIZER_H_ + +#include "Framework/DataProcessorSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +o2::framework::DataProcessorSpec getHMPIDClusterizerSpec(bool useMC); + +} // end namespace hmpid +} // end namespace o2 + +#endif /* STEER_DIGITIZERWORKFLOW_HMPIDCLUSTERIZERSPEC_H_ */ diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DigitReaderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DigitReaderSpec.h new file mode 100644 index 0000000000000..147c7f22976c5 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DigitReaderSpec.h @@ -0,0 +1,52 @@ +// 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 DigitReader.h + +#ifndef O2_HMPID_DIGITREADER +#define O2_HMPID_DIGITREADER + +#include "TFile.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" +#include "HMPIDBase/Digit.h" +#include "SimulationDataFormat/MCCompLabel.h" +#include "SimulationDataFormat/MCTruthContainer.h" + +namespace o2 +{ +namespace hmpid +{ + +class DigitReader : public o2::framework::Task +{ + public: + DigitReader(bool useMC) : mUseMC(useMC) {} + ~DigitReader() override = default; + void init(o2::framework::InitContext& ic) final; + void run(o2::framework::ProcessingContext& pc) final; + + private: + int mState = 0; + bool mUseMC = true; + std::unique_ptr mFile = nullptr; + + std::vector mDigits, *mPdigits = &mDigits; + + o2::dataformats::MCTruthContainer mLabels, *mPlabels = &mLabels; +}; + +/// read simulated HMPID digits from a root file +framework::DataProcessorSpec getDigitReaderSpec(bool useMC); + +} // namespace hmpid +} // namespace o2 + +#endif /* O2_HMPID_DIGITREADER */ diff --git a/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx b/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx new file mode 100644 index 0000000000000..463a3f97753ee --- /dev/null +++ b/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx @@ -0,0 +1,111 @@ +// 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. + +#include "HMPIDWorkflow/ClusterizerSpec.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/DataRefUtils.h" +#include "Framework/Lifetime.h" +#include "Framework/Task.h" +#include "Headers/DataHeader.h" +#include "HMPIDReconstruction/Clusterer.h" +#include "HMPIDBase/Cluster.h" +#include "SimulationDataFormat/MCTruthContainer.h" +#include "SimulationDataFormat/MCCompLabel.h" +#include // for make_shared, make_unique, unique_ptr +#include + +using namespace o2::framework; + +namespace o2 +{ +namespace hmpid +{ + +// use the tasking system of DPL +// just need to implement 2 special methods init + run (there is no need to inherit from anything) +class HMPIDDPLClustererTask +{ + using MCLabelContainer = o2::dataformats::MCTruthContainer; + bool mUseMC = true; + + public: + explicit HMPIDDPLClustererTask(bool useMC) : mUseMC(useMC) {} + void init(framework::InitContext& ic) + { + // nothing special to be set up + } + + void run(framework::ProcessingContext& pc) + { + static bool finished = false; + if (finished) { + return; + } + // get digit data + auto digits = pc.inputs().get*>("hmpiddigits"); + LOG(INFO) << "RECEIVED " << digits->size() << " DIGITS"; + auto labelvector = std::make_shared>(); + if (mUseMC) { + auto digitlabels = pc.inputs().get*>("hmpiddigitlabels"); + *labelvector.get() = std::move(*digitlabels); + mClusterer.setMCTruthContainer(&mClsLabels); + mClsLabels.clear(); + } + // call actual clustering routine + mClustersArray.clear(); + + if (mUseMC) { + mClusterer.process(*digits.get(), mClustersArray, labelvector.get()); + } else { + mClusterer.process(*digits.get(), mClustersArray, nullptr); + } + + LOG(INFO) << "HMPID CLUSTERER : TRANSFORMED " << digits->size() + << " DIGITS TO " << mClustersArray.size() << " CLUSTERS"; + + // send clusters + //pc.outputs().snapshot(Output{"HMP", "CLUSTERS", 0, Lifetime::Timeframe}, mClustersArray); + // send labels + if (mUseMC) { + //pc.outputs().snapshot(Output{"HMP", "CLUSTERSMCTR", 0, Lifetime::Timeframe}, mClsLabels); + } + + // declare done + finished = true; + pc.services().get().readyToQuit(false); + } + + private: + Clusterer mClusterer; ///< Cluster finder + + std::vector mClustersArray; ///< Array of clusters + MCLabelContainer mClsLabels; +}; + +o2::framework::DataProcessorSpec getHMPIDClusterizerSpec(bool useMC) +{ + std::vector inputs; + inputs.emplace_back("hmpiddigits", "HMP", "DIGITS", 0, Lifetime::Timeframe); + if (useMC) + inputs.emplace_back("hmpiddigitlabels", "HMP", "DIGITSMCTR", 0, Lifetime::Timeframe); + + return DataProcessorSpec{ + "HMPClusterer", + inputs, + // Outputs{OutputSpec{"HMP", "CLUSTERS", 0, Lifetime::Timeframe}, + // OutputSpec{"HMP", "CLUSTERSMCTR", 0, Lifetime::Timeframe}}, + Outputs{}, + AlgorithmSpec{adaptFromTask(useMC)}, + Options{/* for the moment no options */}}; +} + +} // end namespace hmpid +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx b/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx new file mode 100644 index 0000000000000..007a5343c5b71 --- /dev/null +++ b/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx @@ -0,0 +1,90 @@ +// 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 DigitReader.cxx + +#include + +#include "../include/HMPIDWorkflow/DigitReaderSpec.h" +#include "TTree.h" + +#include "Framework/ControlService.h" +#include "DataFormatsParameters/GRPObject.h" +using namespace o2::framework; +using namespace o2::hmpid; + +namespace o2 +{ +namespace hmpid +{ + +void DigitReader::init(InitContext& ic) +{ + LOG(INFO) << "Init Digit reader!"; + auto filename = ic.options().get("hmpid-digit-infile"); + mFile = std::make_unique(filename.c_str(), "OLD"); + if (!mFile->IsOpen()) { + LOG(ERROR) << "Cannot open the " << filename.c_str() << " file !"; + mState = 0; + return; + } + mState = 1; +} + +void DigitReader::run(ProcessingContext& pc) +{ + if (mState != 1) { + return; + } + + std::unique_ptr treeDig((TTree*)mFile->Get("o2sim")); + + if (treeDig) { + treeDig->SetBranchAddress("HMPDigit", &mPdigits); + + if (mUseMC) { + treeDig->SetBranchAddress("HMPDigitLabels", &mPlabels); + } + + treeDig->GetEntry(0); + + // add digits loaded in the output snapshot + pc.outputs().snapshot(Output{"HMP", "DIGITS", 0, Lifetime::Timeframe}, mDigits); + if (mUseMC) { + pc.outputs().snapshot(Output{"HMP", "DIGITSMCTR", 0, Lifetime::Timeframe}, mLabels); + } + } else { + LOG(ERROR) << "Cannot read the HMPID digits !"; + return; + } + + mState = 2; + pc.services().get().readyToQuit(false); +} + +DataProcessorSpec getDigitReaderSpec(bool useMC) +{ + std::vector outputs; + outputs.emplace_back("HMP", "DIGITS", 0, Lifetime::Timeframe); + if (useMC) { + outputs.emplace_back("HMP", "DIGITSMCTR", 0, Lifetime::Timeframe); + } + + return DataProcessorSpec{ + "hmpid-digit-reader", + Inputs{}, + outputs, + AlgorithmSpec{adaptFromTask(useMC)}, + Options{ + {"hmpid-digit-infile", VariantType::String, "hmpiddigits.root", {"Name of the input file"}}}}; +} + +} // namespace hmpid +} // namespace o2 diff --git a/Detectors/HMPID/workflow/src/HMPIDRecoWorkflow.cxx b/Detectors/HMPID/workflow/src/HMPIDRecoWorkflow.cxx new file mode 100644 index 0000000000000..a8f392b86481e --- /dev/null +++ b/Detectors/HMPID/workflow/src/HMPIDRecoWorkflow.cxx @@ -0,0 +1,35 @@ +// 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. + +#include "HMPIDWorkflow/DigitReaderSpec.h" +#include "HMPIDWorkflow/ClusterizerSpec.h" + +#include "Framework/WorkflowSpec.h" +#include "Framework/ConfigParamSpec.h" + +#include "Framework/runDataProcessing.h" // the main driver + +using namespace o2::framework; + +/// The standalone workflow executable for HMPID reconstruction workflow +/// - digit reader +/// - clusterer + +/// This function hooks up the the workflow specifications into the DPL driver. +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + WorkflowSpec specs; + + bool useMC = true; + specs.emplace_back(o2::hmpid::getDigitReaderSpec(useMC)); + specs.emplace_back(o2::hmpid::getHMPIDClusterizerSpec(useMC)); + + return std::move(specs); +} From 207a85975a69e48fccd3bb3d235e46cc58815401 Mon Sep 17 00:00:00 2001 From: Giacomo Volpe Date: Fri, 30 Aug 2019 19:02:33 +0200 Subject: [PATCH 002/208] Preliminary HMPID cluster implementation --- .../HMPID/base/include/HMPIDBase/Cluster.h | 38 +++++++++++++++++++ Detectors/HMPID/base/src/Cluster.cxx | 9 ++++- Detectors/HMPID/base/src/HMPIDBaseLinkDef.h | 2 + .../HMPID/reconstruction/src/Clusterer.cxx | 17 --------- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Cluster.h b/Detectors/HMPID/base/include/HMPIDBase/Cluster.h index 764dcfcf9c602..836f804136e14 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Cluster.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Cluster.h @@ -25,6 +25,44 @@ namespace hmpid /// \brief HMPID cluster implementation class Cluster { + public: + Cluster() = default; + + Cluster(Int_t chamber, Int_t size, Int_t NlocMax, Double_t QRaw, Double_t Q, Double_t X, Double_t Y); + ~Cluster() = default; + + + Int_t getCh() const { return mChamber; } + void setCh(Int_t chamber) { mChamber = chamber; } + + Int_t getSize() const { return mSize; } + void setSize(Int_t size) { mSize = size; } + + Int_t getQRaw() const { return mQRaw; } + void setQRaw(Int_t QRaw) { mQRaw = QRaw; } + + Int_t getQ() const { return mQ; } + void setQ(Int_t Q) { mQ = Q; } + + Int_t getX() const { return mX; } + void setX(Int_t X) { mX = X; } + + Int_t getY() const { return mY; } + void setY(Int_t Y) { mY = Y; } + + + protected: + + Int_t mChamber; /// chamber number + Int_t mSize; /// size of the formed cluster from which this cluster deduced + Int_t mNlocMax; /// number of local maxima in formed cluster + Double_t mQRaw; /// QDC value of the raw cluster + Double_t mQ; /// QDC value of the actual cluster + Double_t mX; /// local x postion, [cm] + Double_t mY; /// local y postion, [cm] + + + ClassDefNV(Cluster, 1); }; } // namespace hmpid diff --git a/Detectors/HMPID/base/src/Cluster.cxx b/Detectors/HMPID/base/src/Cluster.cxx index 6c5dec851a0ad..05770b85e1ffd 100644 --- a/Detectors/HMPID/base/src/Cluster.cxx +++ b/Detectors/HMPID/base/src/Cluster.cxx @@ -8,11 +8,16 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Cluster.h" #include "HMPIDBase/Param.h" #include "TRandom.h" #include "TMath.h" using namespace o2::hmpid; -ClassImp(o2::hmpid::Digit); +ClassImp(o2::hmpid::Cluster); + +Cluster::Cluster(Int_t chamber, Int_t size, Int_t NlocMax, Double_t QRaw, Double_t Q, Double_t X, Double_t Y) + : mChamber(chamber), mSize(size), mNlocMax(NlocMax), mQRaw(QRaw), mQ(Q), mX(X), mY(Y) +{ +} diff --git a/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h b/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h index 179ba16791750..fc5aa9c380584 100644 --- a/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h +++ b/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h @@ -14,6 +14,8 @@ #pragma link off all classes; #pragma link off all functions; +#pragma link C++ class o2::hmpid::Cluster + ; +#pragma link C++ class vector < o2::hmpid::Cluster> + ; #pragma link C++ class o2::hmpid::Param + ; #pragma link C++ class o2::hmpid::Digit + ; #pragma link C++ class vector < o2::hmpid::Digit> + ; diff --git a/Detectors/HMPID/reconstruction/src/Clusterer.cxx b/Detectors/HMPID/reconstruction/src/Clusterer.cxx index 089b63787cde8..e3d026c3479ac 100644 --- a/Detectors/HMPID/reconstruction/src/Clusterer.cxx +++ b/Detectors/HMPID/reconstruction/src/Clusterer.cxx @@ -44,20 +44,3 @@ void Clusterer::process(std::vector const& digits, std::vector timerProcess.Print(); } -////__________________________________________________ -//void Clusterer::dig2Clu(std::vector& clusters, MCLabelContainer const* digitMCTruth) -//{ -// // method to clusterize -// -// // to be implemented -// -//} -////______________________________________________________________________ -//void Clusterer::formClu(Cluster& c, Digit* dig, o2::hmpid::Digit>& digits, MCLabelContainer const* digitMCTruth) -//{ -// // method to clusterize -// -// // to be implemented -// -//} -//______________________________________________________________________ From 857d150eeb9ae7b12b94da9bec51813406caed6f Mon Sep 17 00:00:00 2001 From: Giacomo Volpe Date: Thu, 7 Jan 2021 16:34:39 +0100 Subject: [PATCH 003/208] First data decoder workflow implementation --- Detectors/HMPID/reconstruction/CMakeLists.txt | 9 +- .../HMPID/reconstruction/src/Clusterer.cxx | 1 + .../src/HMPIDReconstructionLinkDef.h | 5 +- Detectors/HMPID/simulation/data/simcuts.dat | 18 ++ Detectors/HMPID/simulation/src/Detector.cxx | 2 + .../HMPID/simulation/src/HMPIDDigitizer.cxx | 2 + Detectors/HMPID/workflow/CMakeLists.txt | 14 +- .../include/HMPIDWorkflow/DataDecoderSpec.h | 33 +++ .../HMPID/workflow/src/ClusterizerSpec.cxx | 1 + .../HMPID/workflow/src/DataDecoderSpec.cxx | 188 ++++++++++++++++++ .../HMPID/workflow/src/DigitReaderSpec.cxx | 5 +- .../workflow/src/raw-to-digits-workflow.cxx | 40 ++++ 12 files changed, 309 insertions(+), 9 deletions(-) create mode 100644 Detectors/HMPID/simulation/data/simcuts.dat create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h create mode 100644 Detectors/HMPID/workflow/src/DataDecoderSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx diff --git a/Detectors/HMPID/reconstruction/CMakeLists.txt b/Detectors/HMPID/reconstruction/CMakeLists.txt index a9e882fa411b7..346cad9e40c7f 100644 --- a/Detectors/HMPID/reconstruction/CMakeLists.txt +++ b/Detectors/HMPID/reconstruction/CMakeLists.txt @@ -9,10 +9,13 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDReconstruction - SOURCES src/Clusterer.cxx src/DataReader.cxx + SOURCES src/Clusterer.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDBase O2::HMPIDSimulation) o2_target_root_dictionary(HMPIDReconstruction - HEADERS include/HMPIDReconstruction/Clusterer.h - include/HMPIDReconstruction/DataReader.h) + HEADERS include/HMPIDReconstruction/Clusterer.h) + #include/HMPIDReconstruction/HmpidDecodeRawMem.h + #include/HMPIDReconstruction/HmpidDecoder.h + #include/HMPIDReconstruction/HmpidEquipment.h) + #include/HMPIDReconstruction/DataReader.h) diff --git a/Detectors/HMPID/reconstruction/src/Clusterer.cxx b/Detectors/HMPID/reconstruction/src/Clusterer.cxx index e3d026c3479ac..e543d99193290 100644 --- a/Detectors/HMPID/reconstruction/src/Clusterer.cxx +++ b/Detectors/HMPID/reconstruction/src/Clusterer.cxx @@ -12,6 +12,7 @@ /// \brief Implementation of the HMPID cluster finder #include #include "FairLogger.h" // for LOG +#include "Framework/Logger.h" #include "HMPIDBase/Cluster.h" #include "HMPIDReconstruction/Clusterer.h" #include "SimulationDataFormat/MCCompLabel.h" diff --git a/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h b/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h index 23608c4bc6a4c..26b789b661b47 100644 --- a/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h +++ b/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h @@ -14,7 +14,10 @@ #pragma link off all classes; #pragma link off all functions; -#pragma link C++ class o2::hmpid::DataReader + ; +//#pragma link C++ class o2::hmpid::DataReader + ; #pragma link C++ class o2::hmpid::Clusterer + ; +//#pragma link C++ class o2::hmpid::HmpidDecodeRawMem + ; +//#pragma link C++ class o2::hmpid::HmpidDecoder + ; +//#pragma link C++ class o2::hmpid::HmpidEquipment + ; #endif diff --git a/Detectors/HMPID/simulation/data/simcuts.dat b/Detectors/HMPID/simulation/data/simcuts.dat new file mode 100644 index 0000000000000..6235a9db8a564 --- /dev/null +++ b/Detectors/HMPID/simulation/data/simcuts.dat @@ -0,0 +1,18 @@ +* HMPID +* ==== +* +* Med GAM ELEC NHAD CHAD MUON EBREM MUHAB EDEL MUDEL MUPA ANNI BREM COMP DCAY DRAY HADR LOSS MULS PAIR PHOT RAYL +* SiO2 Window (>1000 keV delta-electrons) +HMPID 3 1.e-4 1.e-4 1.e-4 -1. 1.e-4 -1. -1. 1.e-3 1.e-3 -1. -1 -1 -1 -1 1 -1 1 -1 -1 -1 -1 +* C6F14 Radiator (> 500 keV delta-electrons) +HMPID 4 1.e-4 1.e-4 1.e-4 -1. 1.e-4 -1. -1. 5.e-4 5.e-4 -1. -1 -1 -1 -1 1 -1 1 -1 -1 -1 -1 +* Methane Gap (> 100 keV delta-electrons) +HMPID 5 5.e-5 1.e-5 1.e-4 -1. 1.e-4 -1. -1. 1.e-4 1.e-4 -1. -1 -1 -1 -1 1 -1 1 -1 -1 -1 -1 +* CSI (> 50 keV delta-electrons) +HMPID 6 1.e-5 1.e-5 1.e-4 -1. 1.e-4 -1. -1. 5.e-5 5.e-5 -1. -1 -1 -1 -1 1 -1 1 -1 -1 -1 -1 +* Al (> 50 keV delta-electrons) +HMPID 7 1.e-5 1.e-5 1.e-4 -1. 1.e-4 -1. -1. 5.e-5 5.e-5 -1. -1 -1 -1 -1 1 -1 1 -1 -1 -1 -1 +* Cu (> 50 keV delta-electrons) +HMPID 8 1.e-5 1.e-5 1.e-4 -1. 1.e-4 -1. -1. 5.e-5 5.e-5 -1. -1 -1 -1 -1 1 -1 1 -1 -1 -1 -1 +* W (> 50 keV delta-electrons) +HMPID 9 1.e-5 1.e-5 1.e-4 -1. 1.e-4 -1. -1. 5.e-5 5.e-5 -1. -1 -1 -1 -1 1 -1 1 -1 -1 -1 -1 diff --git a/Detectors/HMPID/simulation/src/Detector.cxx b/Detectors/HMPID/simulation/src/Detector.cxx index acec57c665d6d..247f56a43149a 100644 --- a/Detectors/HMPID/simulation/src/Detector.cxx +++ b/Detectors/HMPID/simulation/src/Detector.cxx @@ -32,6 +32,8 @@ #include "DetectorsBase/MaterialManager.h" +#include "Framework/Logger.h" + namespace o2 { namespace hmpid diff --git a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx index 155e2a8ae4455..d9b8dfe5f9c48 100644 --- a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx +++ b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx @@ -11,6 +11,8 @@ #include "HMPIDSimulation/HMPIDDigitizer.h" #include "HMPIDBase/Digit.h" +#include "Framework/Logger.h" + using namespace o2::hmpid; ClassImp(HMPIDDigitizer); diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index 78a7a79e3c9ea..6bd41689209b6 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -9,11 +9,13 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDWorkflow - SOURCES src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx - PUBLIC_LINK_LIBRARIES O2::HMPIDBase + SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx + PUBLIC_LINK_LIBRARIES O2::Framework + O2::DPLUtils + O2::DetectorsRaw + O2::HMPIDBase O2::HMPIDSimulation - O2::HMPIDReconstruction - O2::Framework) + O2::HMPIDReconstruction) o2_add_executable(recoworkflow COMPONENT_NAME hmpid @@ -21,3 +23,7 @@ o2_add_executable(recoworkflow PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) +o2_add_executable(raw-to-digits-workflow + COMPONENT_NAME hmpid + SOURCES src/raw-to-digits-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h new file mode 100644 index 0000000000000..fc1da045c6742 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -0,0 +1,33 @@ +// 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 DatDecoderSpec.h +/// \author Andrea Ferrero +/// +/// \brief Definition of a data processor to run the raw decoding +/// + +#ifndef O2_MCH_DATADECODERSPEC_H_ +#define O2_MCH_DATADECODERSPEC_H_ + +#include "Framework/DataProcessorSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec = "TF:HMP/RAWDATA"); +//o2::framework::DataProcessorSpec getDecodingSpec(); +} // end namespace hmpid +} // end namespace o2 + +#endif diff --git a/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx b/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx index 463a3f97753ee..3e39b04b16cba 100644 --- a/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx +++ b/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx @@ -14,6 +14,7 @@ #include "Framework/DataRefUtils.h" #include "Framework/Lifetime.h" #include "Framework/Task.h" +#include "Framework/Logger.h" #include "Headers/DataHeader.h" #include "HMPIDReconstruction/Clusterer.h" #include "HMPIDBase/Cluster.h" diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx new file mode 100644 index 0000000000000..d0be3a60eb70e --- /dev/null +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -0,0 +1,188 @@ +// draft +// 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 DatDecoderSpec.cxx +/// \author +/// +/// \brief Implementation of a data processor to run the HMPID raw decoding +/// + +#include +#include +#include +#include +#include +#include + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" + +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" +#include "DPLUtils/DPLRawParser.h" + +#include "HMPIDBase/Digit.h" +#include "HMPIDWorkflow/DataDecoderSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using namespace o2; +using namespace o2::framework; +using RDH = o2::header::RDHAny; + +//======================= +// Data decoder +class DataDecoderTask +{ + public: + //_________________________________________________________________________________________________ + void init(framework::InitContext& ic) + { + /* SampaChannelHandler channelHandler; + RdhHandler rdhHandler; + + auto ds2manu = ic.options().get("ds2manu"); + mPrint = ic.options().get("print"); + auto mapCRUfile = ic.options().get("cru-map"); + auto mapFECfile = ic.options().get("fec-map"); + + mDecoder = new DataDecoder(channelHandler, rdhHandler, mapCRUfile, mapFECfile, ds2manu, mPrint); + */ + } + + //_________________________________________________________________________________________________ + // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder + void decodeTF(framework::ProcessingContext& pc) + { + Printf("*********** In decodeTF **************"); + + // get the input buffer + auto& inputs = pc.inputs(); + DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); + + for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { + auto const* rdh = it.get_if(); + auto const* raw = it.raw(); + size_t payloadSize = it.size(); + // stampare solo payload + std::cout << " ***** payloadSize = " << payloadSize << std::endl; + + /* if (payloadSize == 0) { + continue; + } + + gsl::span buffer(reinterpret_cast(raw), sizeof(RDH) + payloadSize); + mDecoder->decodeBuffer(buffer); + */ + } + } + + //_________________________________________________________________________________________________ + // the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow +/* void decodeReadout(const o2::framework::DataRef& input) + { + static int nFrame = 1; + // get the input buffer + if (input.spec->binding != "readout") { + return; + } + + const auto* header = o2::header::get(input.header); + if (!header) { + return; + } + + auto const* raw = input.payload; + // cout size of payload + std::cout << " payloadSize " << header->payloadSize << std::endl; + //size_t payloadSize = header->payloadSize; + + if (mPrint) { + std::cout << nFrame << " payloadSize=" << payloadSize << std::endl; + } + nFrame += 1; + if (payloadSize == 0) { + return; + } + + gsl::span buffer(reinterpret_cast(raw), payloadSize); + mDecoder->decodeBuffer(buffer); + } +*/ + //_________________________________________________________________________________________________ + void run(framework::ProcessingContext& pc) + { + + decodeTF(pc); + for (auto&& input : pc.inputs()) { + + std::cout << " ******* input " << input.spec->binding << std::endl; + // if (input.spec->binding == "readout") { // solo cout + // decodeReadout(input); + // } + } + +/* auto& digits = mDecoder->getOutputDigits(); + auto& orbits = mDecoder->getOrbits(); + + if (mPrint) { + for (auto d : digits) { + std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; + } + } + // send the output buffer via DPL + size_t digitsSize, orbitsSize; + char* digitsBuffer = createBuffer(digits, digitsSize); + char* orbitsBuffer = createBuffer(orbits, orbitsSize); + + // create the output message + auto freefct = [](void* data, void*) { free(data); }; + // pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); + // pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); + */ + } + + private: + bool mPrint = {false}; +// DataDecoder* mDecoder = {nullptr}; +}; + +//_________________________________________________________________________________________________ +o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) +//o2::framework::DataPrecessorSpec getDecodingSpec() +{ + + std::vector inputs; + inputs.emplace_back("RAWDATA", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + + return DataProcessorSpec{ + "HMP-DataDecoder", + o2::framework::select(inputSpec.c_str()), + Outputs{OutputSpec{"HMP", "DIGITS", 0, Lifetime::Timeframe}, OutputSpec{"HMP", "ORBITS", 0, Lifetime::Timeframe}}, + AlgorithmSpec{adaptFromTask()}, + Options{{"print", VariantType::Bool, false, {"print digits"}}, + {"cru-map", VariantType::String, "", {"custom CRU mapping"}}, + {"fec-map", VariantType::String, "", {"custom FEC mapping"}}, + {"ds2manu", VariantType::Bool, false, {"convert channel numbering from Run3 to Run1-2 order"}}}}; +} + +} // namespace hmpid +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx b/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx index 007a5343c5b71..9d67bd722c1fe 100644 --- a/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx @@ -12,11 +12,14 @@ #include -#include "../include/HMPIDWorkflow/DigitReaderSpec.h" +#include "HMPIDWorkflow/DigitReaderSpec.h" #include "TTree.h" #include "Framework/ControlService.h" +#include "Framework/ConfigParamRegistry.h" #include "DataFormatsParameters/GRPObject.h" +#include "Framework/Logger.h" + using namespace o2::framework; using namespace o2::hmpid; diff --git a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx new file mode 100644 index 0000000000000..462ee37e15521 --- /dev/null +++ b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx @@ -0,0 +1,40 @@ +// 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 raw-to-digits-workflow.cxx +/// \author Andrea Ferrero +/// +/// \brief This is an executable that runs the decoding via DPL. +/// +/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. +/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow +/// + +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/Task.h" +#include "Framework/runDataProcessing.h" +#include "HMPIDWorkflow/DataDecoderSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + DataProcessorSpec producer = o2::hmpid::getDecodingSpec(); + specs.push_back(producer); + + return specs; +} From 92f0f83c472fd77beb6c0e5da6d0bdb683bc3fb5 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 8 Jan 2021 12:03:23 +0100 Subject: [PATCH 004/208] Add Decoder Class --- DataFormats/Detectors/HMPID/CMakeLists.txt | 17 + .../HMPID/include/DataFormatsHMP/DataFormat.h | 46 + .../HMPID/src/DataFormatsHMPLinkDef.h | 18 + Detectors/HMPID/base/include/HMPIDBase/Geo.h | 86 ++ Detectors/HMPID/base/src/Geo.cxx | 74 ++ .../reconstruction/src/HmpidDecodeRawFile.cxx | 157 +++ .../reconstruction/src/HmpidDecodeRawFile.h | 62 + .../reconstruction/src/HmpidDecodeRawMem.cxx | 134 +++ .../reconstruction/src/HmpidDecodeRawMem.h | 55 + .../HMPID/reconstruction/src/HmpidDecoder.cxx | 1065 +++++++++++++++++ .../HMPID/reconstruction/src/HmpidDecoder.h | 167 +++ .../reconstruction/src/HmpidEquipment.cxx | 139 +++ .../HMPID/reconstruction/src/HmpidEquipment.h | 135 +++ GPU/GPUTracking/Standalone/Common | 2 +- GPU/GPUTracking/Standalone/Global | 2 +- GPU/GPUTracking/Standalone/HLTHeaders | 2 +- GPU/GPUTracking/Standalone/ITS | 2 +- GPU/GPUTracking/Standalone/Merger | 2 +- GPU/GPUTracking/Standalone/SliceTracker | 2 +- .../Standalone/TPCFastTransformation | 2 +- GPU/GPUTracking/Standalone/TRDTracking | 2 +- GPU/GPUTracking/Standalone/dependencies | 2 +- 22 files changed, 2164 insertions(+), 9 deletions(-) create mode 100644 DataFormats/Detectors/HMPID/CMakeLists.txt create mode 100644 DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h create mode 100644 DataFormats/Detectors/HMPID/src/DataFormatsHMPLinkDef.h create mode 100644 Detectors/HMPID/base/include/HMPIDBase/Geo.h create mode 100644 Detectors/HMPID/base/src/Geo.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.h create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecoder.h create mode 100644 Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HmpidEquipment.h diff --git a/DataFormats/Detectors/HMPID/CMakeLists.txt b/DataFormats/Detectors/HMPID/CMakeLists.txt new file mode 100644 index 0000000000000..7c5851c1560cb --- /dev/null +++ b/DataFormats/Detectors/HMPID/CMakeLists.txt @@ -0,0 +1,17 @@ +# 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. + +# o2_add_library(DataFormatsHMP +# SOURCES src/Cluster.cxx +# PUBLIC_LINK_LIBRARIES O2::ReconstructionDataFormats +# Boost::serialization) + +# o2_target_root_dictionary(DataFormatsHMP +# HEADERS include/DataFormatsHMP/DataFormat.h diff --git a/DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h b/DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h new file mode 100644 index 0000000000000..ac6f3397e2829 --- /dev/null +++ b/DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h @@ -0,0 +1,46 @@ +// 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 DataFormat.h +/// \brief Definition of the HMPID raw data format + +#ifndef ALICEO2_HMP_DATAFORMAT_H +#define ALICEO2_HMP_DATAFORMAT_H + +#include + +namespace o2 +{ +namespace hmpid +{ + +namespace raw +{ + + /** generic word * + + struct Word_t { + uint32_t undefined : 31; + uint32_t wordType : 1; + }; + + union Union_t { + uint32_t data; + Word_t word; + CrateHeader_t crateHeader; + FrameHeader_t frameHeader; + PackedHit_t packedHit; + CrateTrailer_t crateTrailer; + }; +*/ +} // namespace raw +} // namespace tof +} // namespace o2 +#endif diff --git a/DataFormats/Detectors/HMPID/src/DataFormatsHMPLinkDef.h b/DataFormats/Detectors/HMPID/src/DataFormatsHMPLinkDef.h new file mode 100644 index 0000000000000..027b310bd7b29 --- /dev/null +++ b/DataFormats/Detectors/HMPID/src/DataFormatsHMPLinkDef.h @@ -0,0 +1,18 @@ +// 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. + +#ifdef __CLING__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; +//#pragma link C++ class o2::hmpid::Cluster + ; + +#endif diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h new file mode 100644 index 0000000000000..469c32a5cba26 --- /dev/null +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -0,0 +1,86 @@ +// 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. + +#ifndef ALICEO2_HMPID_GEO_H +#define ALICEO2_HMPID_GEO_H + +//#include "Rtypes.h" + +namespace o2 +{ +namespace hmpid +{ +/// \class Geo +/// \brief HMPID detector geometry (only statics) +class Geo +{ + public: + // From AliTOFGeometry +// static void translate(Float_t* xyz, Float_t translationVector[3]); +// enum { +// // DAQ characteristics +// kNDDL = 4, // Number of DDL (Detector Data Link) per sector +// kNTRM = 12, // Number of TRM ( Readout Module) per DDL +// kNTdc = 15, // Number of Tdc (Time to Digital Converter) per TRM +// kNChain = 2, // Number of chains per TRM +// kNCrate = 72, // Number of Crates +// kNCh = 8 // Number of channels per Tdc +// }; + + + // ---- HMPID geometry ------- + static constexpr int MAXEQUIPMENTS = 14; + static constexpr int N_SEGMENTS = 3; + static constexpr int N_COLXSEGMENT = 8; + static constexpr int N_COLUMNS = 24; + static constexpr int N_DILOGICS = 10; + static constexpr int N_CHANNELS = 48; + static constexpr int N_DILOCHANNELS = 64; + + static constexpr int N_MODULES = 7; + static constexpr int N_XROWS = 160; + static constexpr int N_YCOLS = 144; + + static constexpr int MAXYCOLS = 143; + static constexpr int MAXHALFXROWS = 79; + static constexpr int HALFXROWS = 80; + + static constexpr int DILOPADSCOLS = 6; + static constexpr int DILOPADSROWS = 8; + + static constexpr int EQUIPMENTSPERMODULE = 2; + + + static constexpr int N_EQUIPMENTTOTALPADS = N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; + static constexpr int N_HMPIDTOTALPADS = MAXEQUIPMENTS * N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; + + + void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); + void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); + + // from + //static constexpr Bool_t FEAWITHMASKS[NSECTORS] = + // // TOF sectors with Nino masks: 0, 8, 9, 10, 16 + // {kTRUE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, + // kTRUE, kTRUE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, kFALSE}; + //; // Selecting TOF sectors containing FEA cooling masks + + +// static Float_t getCableLength(Int_t icrate, Int_t islot, Int_t ichain, Int_t itdc) { return CABLELENGTH[icrate][islot - 3][ichain][itdc / 3]; } + + private: + static void Init(); + + ClassDefNV(Geo, 1); +}; +} // namespace hmpid +} // namespace o2 + +#endif diff --git a/Detectors/HMPID/base/src/Geo.cxx b/Detectors/HMPID/base/src/Geo.cxx new file mode 100644 index 0000000000000..ef6f4a1da7858 --- /dev/null +++ b/Detectors/HMPID/base/src/Geo.cxx @@ -0,0 +1,74 @@ +// 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. + +#include "HMPIDBase/Geo.h" +#include "TGeoManager.h" +#include "TMath.h" +#include "FairLogger.h" +#include "DetectorsBase/GeometryManager.h" + +ClassImp(o2::hmpid::Geo); + +using namespace o2::hmpid; + +//constexpr Bool_t Geo::FEAWITHMASKS[NSECTORS]; + +void Geo::Init() +{ + LOG(INFO) << "hmpid::Geo: Initialization of HMPID parameters"; + +} +// =================== General Purposes HMPID Functions ======================= +/// Functions to translate coordinates : from Module,Col,Row to Equipment,Col,Dilogic,Channel +/// Digit coordinates " Mod,Row,Col := Mod = {0..6} Row = {0..159} Col = {0..143} +/// (0,0) Left Bottom +/// +/// Hardware coordinates Equ,Col,Dil,Cha := Equ = {0..13} Col = {0..23} Dil = {0..9} Cha = {0..47} +/// +/// (0,0,0,0) Right Top (1,0,0,0) Left Bottom +/// +void Geo::Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan) +{ + if (Row > MAXHALFXROWS) { + *Equi = Mod * EQUIPMENTSPERMODULE + 1; + Row = Row - HALFXROWS; + } else { + *Equi = Mod * EQUIPMENTSPERMODULE; + Row = MAXHALFXROWS - Row; + Col = MAXYCOLS - Col; + } + *Dilo = Row / DILOPADSROWS; + *Colu = Col / DILOPADSCOLS; + *Chan = (Row % DILOPADSROWS) * DILOPADSCOLS + (Col % DILOPADSCOLS); + return; +} + +/// Functions to translate coordinates : from Equipment,Col,Dilogic,Channel to Module,Col,Row +/// Digit coordinates " Mod,Row,Col := Mod = {0..6} Row = {0..159} Col = {0..143} +/// (0,0) Left Bottom +/// +/// Hardware coordinates Equ,Col,Dil,Cha := Equ = {0..13} Col = {0..23} Dil = {0..9} Cha = {0..47} +/// +/// (0,0,0,0) Right Top (1,0,0,0) Left Bottom +/// +void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row) +{ + *Mod = Equi / EQUIPMENTSPERMODULE; + *Row = Dilo * DILOPADSROWS + Chan / DILOPADSROWS; + *Col = (Colu * DILOPADSCOLS) + Chan % DILOPADSCOLS; + + if (Equi % EQUIPMENTSPERMODULE == 1) { + *Row += HALFXROWS; + } else { + *Row = MAXHALFXROWS - *Row; + *Col = MAXYCOLS - *Col; + } + return; +} diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx new file mode 100644 index 0000000000000..3c1c30b592fd0 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx @@ -0,0 +1,157 @@ +// 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 HmpidDecodeRawFile.cxx +/// \author Antonio Franco - INFN Bari +/// \brief Derived Class for decoding Raw Data File stream +/// \version 1.0 +/// \date 24 set 2020 + +/* ------ HISTORY --------- +*/ + +#include "HmpidDecodeRawFile.h" + +using namespace o2::hmpid; + +/// Constructor with the default HMPID equipments map at P2 +/// @param[in] numOfEquipments : number of defined equipments [0..13] +HmpidDecodeRawFile::HmpidDecodeRawFile(int numOfEquipments) + : + HmpidDecoder(numOfEquipments) +{ + fh = 0; +} + +/// Constructor with the HMPID address map +/// @param[in] numOfEquipments : the number of equipments to define [1..14] +/// @param[in] *EqIds : the pointer to the Equipments ID array +/// @param[in] *CruIds : the pointer to the CRU ID array +/// @param[in] *LinkIds : the pointer to the Link ID array +HmpidDecodeRawFile::HmpidDecodeRawFile(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) + : + HmpidDecoder(EqIds, CruIds, LinkIds, numOfEquipments) +{ + fh = 0; +} + +/// Destructor +HmpidDecodeRawFile::~HmpidDecodeRawFile() +{ +} + +/// Setup the Input Stream with a File Handle +/// verify the existence and try to open it +/// @param[in] *FileName : the string that contains the File Name +/// @param[in] Size : not used +/// @returns True if the file is opened +/// @throws TH_FILENOTEXISTS Thrown if the file doesn't exists +/// @throws TH_OPENFILE Thrown if Fails to open the file +bool HmpidDecodeRawFile::setUpStream(void *FileName, long Size) +{ + strcpy(mInputFile, (const char*) FileName); + // files section ---- + if (!fileExists(mInputFile)) { + ILOG(ERROR) << "The input file " << mInputFile << " does not exist at this time." << FairLogger::endl; + throw TH_FILENOTEXISTS; + } + // open the file + fh = fopen(mInputFile, "rb"); + if (fh == 0) { + ILOG(ERROR) << "ERROR to open Input file ! [" << mInputFile << "]" << FairLogger::endl; + throw TH_OPENFILE; + } + + mActualStreamPtr = 0; // sets the pointer to the Buffer + mEndStreamPtr = 0; //sets the End of buffer + mStartStreamPtr = 0; + + return (true); +} + +/// Gets a sized chunk from the stream. Read from the file and update the pointers +/// ATTENTION : in order to optimize the disk accesses the block read pre-load a +/// complete Header+Payload block, the Size parameter is recalculated with the +/// dimension of the pack extract from the header field 'Offeset' +/// +/// verify the existence and try to open it +/// @param[in] **streamPtr : the pointer to the memory buffer +/// @param[in] Size : not used +/// @returns True if the file is opened +/// @throws TH_WRONGFILELEN Thrown if the file doesn't contains enough words +bool HmpidDecodeRawFile::getBlockFromStream(int32_t **streamPtr, uint32_t Size) +{ + if (Size > MAXRAWFILEBUFFER) + return (false); + int nr = fread(mFileBuffer, sizeof(int32_t), HEADERDIMENSION_W, fh); + if (nr != HEADERDIMENSION_W) { + throw TH_WRONGFILELEN; + } + Size = ((mFileBuffer[2] & 0x0000FFFF) / sizeof(int32_t)) - HEADERDIMENSION_W; + nr = fread(mFileBuffer+HEADERDIMENSION_W, sizeof(int32_t), Size, fh); + ILOG(DEBUG) << " getBlockFromStream read " << nr << " of " << Size+HEADERDIMENSION_W << " words !" << FairLogger::endl; + if (nr != Size) { + throw TH_WRONGFILELEN; + } + *streamPtr = mFileBuffer; + mStartStreamPtr = mFileBuffer; + mActualStreamPtr = mFileBuffer; + mEndStreamPtr = mFileBuffer + Size; + return (true); +} + +/// Reads the Header from the file +/// @param[in] **streamPtr : the pointer to the memory buffer +/// @returns True if the header is read +bool HmpidDecodeRawFile::getHeaderFromStream(int32_t **streamPtr) +{ + bool flag = getBlockFromStream(streamPtr, RAWBLOCKDIMENSION_W); // reads the 8k block + mActualStreamPtr += HEADERDIMENSION_W; // Move forward for the first word + return (flag); +} + +/// Read one word from the pre-load buffer +/// @param[in] *word : the buffer for the read word +/// @returns True every time +bool HmpidDecodeRawFile::getWordFromStream(int32_t *word) +{ + *word = *mActualStreamPtr; + mActualStreamPtr++; + return (true); +} + +/// ----- Sets the Pad ! ------ +/// this is an overloaded method. In this version the value of the charge +/// is used to update the statistical matrix of the base class +/// +/// @param[in] *eq : the pointer to the Equipment object +/// @param[in] col : the column [0..23] +/// @param[in] dil : the dilogic [0..9] +/// @param[in] ch : the channel [0..47] +/// @param[in] charge : the value of the charge +void HmpidDecodeRawFile::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) +{ + eq->setPad(col, dil, ch, charge); + return; +} + +/// Checks if the file exists ! +/// @param[in] *filewithpath : the File Name to check +/// @returns True if the file exists +int HmpidDecodeRawFile::fileExists(char *filewithpath) +{ + if (access(filewithpath, F_OK) != -1) { + return (true); + } else { + return (false); + } +} + diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h new file mode 100644 index 0000000000000..38bebe8d31d77 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h @@ -0,0 +1,62 @@ +// 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 HmpidDecodeRawFile.h +/// \author Antonio Franco - INFN Bari +/// \brief Derived Class for decoding Raw Data File stream +/// \version 1.0 +/// \date 24 set 2020 + +#ifndef COMMON_HMPIDDECODERAWFILE_H_ +#define COMMON_HMPIDDECODERAWFILE_H_ + +#include +#include +#include +#include +#include +#include + +#include "HmpidDecoder.h" + +#define MAXFILENAMEBUFFER 512 +#define MAXRAWFILEBUFFER RAWBLOCKDIMENSION_W * 4 + 8 + +namespace o2 { + namespace hmpid { + + +class HmpidDecodeRawFile: public HmpidDecoder +{ + public: + HmpidDecodeRawFile(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); + HmpidDecodeRawFile(int numOfEquipments); + ~HmpidDecodeRawFile(); + + bool setUpStream(void *InpuFileName, long Size); + + private: + bool getBlockFromStream(int32_t **streamPtr, uint32_t Size); + bool getHeaderFromStream(int32_t **streamPtr); + bool getWordFromStream(int32_t *word); + int fileExists(char *filewithpath); + void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + + private: + FILE *fh; + char mInputFile[MAXFILENAMEBUFFER]; + int32_t mFileBuffer[MAXRAWFILEBUFFER]; + +}; + + } +} +#endif /* COMMON_HMPIDDECODERAWFILE_H_ */ diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx new file mode 100644 index 0000000000000..c9d39361d9536 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -0,0 +1,134 @@ +// 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 HmpidDecodeRawMem.cxx +/// \author Antonio Franco - INFN Bari +/// \brief Derived Class for decoding Raw Data Memory stream +/// \version 1.0 +/// \date 24 set 2020 + +/* ------ HISTORY --------- +*/ + +#include "HmpidDecodeRawMem.h" + +using namespace o2::hmpid; + +/// Constructor : accepts the number of equipments to define +/// The mapping is the default at P2 +/// Allocates instances for all defined equipments +/// normally it is equal to 14 +/// @param[in] numOfEquipments : the number of equipments to define [1..14] +HmpidDecodeRawMem::HmpidDecodeRawMem(int numOfEquipments) + : + HmpidDecoder(numOfEquipments) +{ +} + +/// Constructor : accepts the number of equipments to define +/// and their complete address map +/// Allocates instances for all defined equipments +/// +/// The Address map is build from three array +/// @param[in] numOfEquipments : the number of equipments to define [1..14] +/// @param[in] *EqIds : the pointer to the Equipments ID array +/// @param[in] *CruIds : the pointer to the CRU ID array +/// @param[in] *LinkIds : the pointer to the Link ID array +HmpidDecodeRawMem::HmpidDecodeRawMem(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) + : + HmpidDecoder(EqIds, CruIds, LinkIds, numOfEquipments) +{ +} + +/// Destructor +HmpidDecodeRawMem::~HmpidDecodeRawMem() +{ +} + +/// Setup the Input Stream with a Memory Pointer +/// the buffer length is in byte, some controls are done +/// +/// @param[in] *Buffer : the pointer to Memory buffer +/// @param[in] BufferLen : the length of the buffer (bytes) +/// @returns True if the stream is set +/// @throws TH_NULLBUFFERPOINTER Thrown if the pointer to the buffer is NULL +/// @throws TH_BUFFEREMPTY Thrown if the buffer is empty +/// @throws TH_WRONGBUFFERDIM Thrown if the buffer len is less then one header +bool HmpidDecodeRawMem::setUpStream(void *Buffer, long BufferLen) +{ + long wordsBufferLen = BufferLen / (sizeof(int32_t) / sizeof(char)); // Converts the len in words + if (Buffer == nullptr) { + ILOG(ERROR) << "Raw data buffer null Pointer ! " << FairLogger::endl; + throw TH_NULLBUFFERPOINTER; + } + if (wordsBufferLen == 0) { + ILOG(Error) << "Raw data buffer Empty ! " < +#include +#include +#include +#include +#include + +#include "HmpidDecoder.h" + +namespace o2{ + namespace hmpid { + + +class HmpidDecodeRawMem: public HmpidDecoder +{ + public: + HmpidDecodeRawMem(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); + HmpidDecodeRawMem(int numOfEquipments); + ~HmpidDecodeRawMem(); + + bool setUpStream(void *Buffer, long BufferLen); + + private: + bool getBlockFromStream(int32_t **streamPtr, uint32_t Size); + bool getHeaderFromStream(int32_t **streamPtr); + bool getWordFromStream(int32_t *word); + void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + + private: + +}; + +} +} +#endif /* COMMON_HMPIDDECODERAWFILE_H_ */ diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx new file mode 100644 index 0000000000000..d2350216140be --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -0,0 +1,1065 @@ +// 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 HmpidDecoder.cxx +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to decode HMPID Raw Data stream +/// \version 1.0 +/// \date 17/11/2020 + +/* ------ HISTORY --------- +*/ + +#include "FairLogger.h" +#include "HmpidDecoder.h" + +using namespace o2::hmpid; + +// ============= HmpidDecoder Class implementation ======= + + +/// Decoding Error Messages Definitions +char HmpidDecoder::sErrorDescription[MAXERRORS][MAXDESCRIPTIONLENGHT] = { "Word that I don't known !", + "Row Marker Word with 0 words", "Duplicated Pad Word !", "Row Marker Wrong/Lost -> to EoE", + "Row Marker Wrong/Lost -> to EoE", "Row Marker reports an ERROR !", "Lost EoE Marker !", "Double EoE marker", + "Wrong size definition in EoE Marker", "Double Mark Word", "Wrong Size in Segment Marker", "Lost EoS Marker !", + "HMPID Header Errors" }; + +/// HMPID Firmware Error Messages Definitions +char HmpidDecoder::sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT] = { "L0 Missing," + "L1 is received without L0", "L1A signal arrived before the L1 Latency", "L1A signal arrived after the L1 Latency", + "L1A is missing or L1 timeout", "L1A Message is missing or L1 Message" }; + +/// Constructor : accepts the number of equipments to define +/// The mapping is the default at P2 +/// Allocates instances for all defined equipments +/// normally it is equal to 14 +/// @param[in] numOfEquipments : the number of equipments to define [1..14] +HmpidDecoder::HmpidDecoder(int numOfEquipments) +{ + // The standard definition of HMPID equipments at P2 + int EqIds[] = { 0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13 }; + int CruIds[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3 }; + int LinkIds[] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2 }; + + mNumberOfEquipments = numOfEquipments; + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i] = new HmpidEquipment(EqIds[i], CruIds[i], LinkIds[i]); + } +} + +/// Constructor : accepts the number of equipments to define +/// and their complete address map +/// Allocates instances for all defined equipments +/// +/// The Address map is build from three array +/// @param[in] numOfEquipments : the number of equipments to define [1..14] +/// @param[in] *EqIds : the pointer to the Equipments ID array +/// @param[in] *CruIds : the pointer to the CRU ID array +/// @param[in] *LinkIds : the pointer to the Link ID array +HmpidDecoder::HmpidDecoder(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) +{ + mNumberOfEquipments = numOfEquipments; + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i] = new HmpidEquipment(EqIds[i], CruIds[i], LinkIds[i]); + } +} + +/// Destructor : remove the Equipments instances +HmpidDecoder::~HmpidDecoder() +{ + for (int i = 0; i < mNumberOfEquipments; i++) { + delete mTheEquipments[i]; + } +} + +/// Resets to 0 all the class members +void HmpidDecoder::init() +{ + mVerbose = 0; + mHeEvent = 0; + mHeBusy = 0; + mNumberWordToRead = 0; + mPayloadTail = 0; + + mHeFEEID = 0; + mHeSize = 0; + mHeVer = 0; + mHePrior = 0; + mHeStop = 0; + mHePages = 0; + mEquipment = 0; + + mHeOffsetNewPack = 0; + mHeMemorySize = 0; + + mHeDetectorID = 0; + mHeDW = 0; + mHeCruID = 0; + mHePackNum = 0; + mHePAR = 0; + mHePageNum = 0; + mHeLinkNum = 0; + mHeFirmwareVersion = 0; + mHeHmpidError = 0; + mHeBCDI = 0; + mHeORBIT = 0; + mHeTType = 0; + + mActualStreamPtr = 0; + mEndStreamPtr = 0; + mStartStreamPtr = 0; + +} + +/// Returns the Equipment Index (Pointer of the array) converting +/// the FLP hardware coords (CRU_Id and Link_Id) +/// @param[in] CruId : the CRU ID [0..3] -> FLP 160 = [0,1] FLP 161 = [2,3] +/// @param[in] LinkId : the Link ID [0..3] +/// @returns EquipmentIndex : the index in the Equipment array [0..13] (-1 := error) +int HmpidDecoder::getEquipmentIndex(int CruId, int LinkId) +{ + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->getEquipmentId(CruId, LinkId) != -1) { + return (i); + } + } + return (-1); +} + +/// Returns the Equipment Index (Pointer of the array) converting +/// the Equipment_ID (Firmaware defined Id AKA FFEID) +/// @param[in] EquipmentId : the Equipment ID [0..13] +/// @returns EquipmentIndex : the index in the Equipment array [0..13] (-1 := error) +int HmpidDecoder::getEquipmentIndex(int EquipmentId) +{ + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->getEquipmentId() == EquipmentId) { + return (i); + } + } + return (-1); +} + +/// Returns the Equipment_ID converting the FLP hardware coords +/// @param[in] CruId : the CRU ID [0..3] -> FLP 160 = [0,1] FLP 161 = [2,3] +/// @param[in] LinkId : the Link ID [0..3] +/// @returns EquipmentID : the ID of the Equipment [0..13] (-1 := error) +int HmpidDecoder::getEquipmentID(int CruId, int LinkId) +{ + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->getEquipmentId(CruId, LinkId) != -1) { + return (mTheEquipments[i]->getEquipmentId()); + } + } + return (-1); +} + +/// Scans the BitMap of Raw Data File word and detect the type +/// and the parameters +/// @param[in] wp : the word to analyze +/// @param[out] *p1 : first parameter extract (if it exists) +/// @param[out] *p2 : second parameter extract (if it exists) +/// @param[out] *p3 : third parameter extract (if it exists) +/// @param[out] *p4 : fourth parameter extract (if it exists) +/// @returns Type of Word : the type of word [0..4] (0 := undetect) +int HmpidDecoder::checkType(int32_t wp, int *p1, int *p2, int *p3, int *p4) +{ + if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 + || (wp & 0x0800ffff) == 0x080010A0) { + *p2 = (wp & 0x03ff0000) >> 16; // Number of words of row + *p1 = wp & 0x0000ffff; + return (WTYPE_ROW); + } + if ((wp & 0xfff00000) >> 20 == 0xAB0) { + *p2 = (wp & 0x000fff00) >> 8; // Number of words of Segment + *p1 = (wp & 0xfff00000) >> 20; + *p3 = wp & 0x0000000F; + if (*p3 < 4 && *p3 > 0) { + return (WTYPE_EOS); + } + } + // #EX MASK Raul 0x3803FF80 # ex mask 0xF803FF80 - this is EoE marker 0586800B0 + if ((wp & 0x0803FF80) == 0x08000080) { + *p1 = (wp & 0x07c00000) >> 22; + *p2 = (wp & 0x003C0000) >> 18; + *p3 = (wp & 0x0000007F); + if (*p1 < 25 && *p2 < 11) { + return (WTYPE_EOE); + } + } + if ((wp & 0x08000000) == 0) { // # this is a pad + // PAD:0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value + *p1 = (wp & 0x07c00000) >> 22; + *p2 = (wp & 0x003C0000) >> 18; + *p3 = (wp & 0x0003F000) >> 12; + *p4 = (wp & 0x00000FFF); + if (*p1 > 0 && *p1 < 25 && *p2 > 0 && *p2 < 11 && *p3 < 48) { + return (WTYPE_PAD); + } + } else { + return (WTYPE_NONE); + } + return (WTYPE_NONE); +} + +/// Checks if is a Raw Marker and extract the Row Size +/// @param[in] wp : the word to check +/// @param[out] *Err : true if an error is detected +/// @param[out] *rowSize : the number of words of the row +/// @param[out] *mark : the row marker +/// @returns True if Row Marker is detected +bool HmpidDecoder::isRowMarker(int32_t wp, int *Err, int *rowSize, int *mark) +{ + if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 + || (wp & 0x0800ffff) == 0x080010A0) { + *rowSize = (wp & 0x03ff0000) >> 16; // # Number of words of row + *mark = wp & 0x0000ffff; + *Err = false; + return (true); + } else { + *Err = true; + return (false); + } +} + +/// Checks if is a Segment Marker and extracts the Segment number and the size +/// @param[in] wp : the word to check +/// @param[out] *Err : true if an error is detected +/// @param[out] *segSize : the number of words of the segment +/// @param[out] *Seg : the Segment number [1..3] +/// @param[out] *mark : the Segment Marker +/// @returns True if Segment Marker is detected +bool HmpidDecoder::isSegmentMarker(int32_t wp, int *Err, int *segSize, int *Seg, int *mark) +{ + *Err = false; + if ((wp & 0xfff00000) >> 20 == 0xAB0) { + *segSize = (wp & 0x000fff00) >> 8; // # Number of words of Segment + *mark = (wp & 0xfff00000) >> 20; + *Seg = wp & 0x0000000F; + + if (*Seg > 3 || *Seg < 1) { + ILOG(INFO) << " Wrong segment Marker Word, bad Number of segment" << *Seg << "!" << FairLogger::endl; + *Err = true; + } + return (true); + } else { + return (false); + } +} + +/// Checks if is a PAD Word and extracts all the parameters +/// PAD map : 0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value +/// @param[in] wp : the word to check +/// @param[out] *Err : true if an error is detected +/// @param[out] *Col : the column number [1..24] +/// @param[out] *Dilogic : the dilogic number [1..10] +/// @param[out] *Channel : the channel number [0..47] +/// @param[out] *Charge : the value of Charge [0..4095] +/// @returns True if PAD Word is detected +bool HmpidDecoder::isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge) +{ + *Err = false; + if ((wp & 0x08000000) == 0) { // # this is a pad + *Col = (wp & 0x07c00000) >> 22; + *Dilogic = (wp & 0x003C0000) >> 18; + *Channel = (wp & 0x0003F000) >> 12; + *Charge = (wp & 0x00000FFF); + if (*Dilogic > 10 || *Channel > 47 || *Dilogic < 1 || *Col > 24 || *Col < 1) { + ILOG(WARNING) << " Wrong Pad values Col=" << *Col << " Dilogic="<< *Dilogic << \ + " Channel=" << *Channel << " Charge=" << *Charge << FairLogger::endl; + *Err = true; + } + return (true); + } else { + return (false); + } +} + +/// Checks if is a EoE Marker and extracts the Column, Dilogic and the size +/// @param[in] wp : the word to check +/// @param[out] *Err : true if an error is detected +/// @param[out] *Col : the column number [1..24] +/// @param[out] *Dilogic : the dilogic number [1..10] +/// @param[out] *Eoesize : the number of words for dilogic +/// @returns True if EoE marker is detected +bool HmpidDecoder::isEoEmarker(int32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize) +{ + *Err = false; + // #EX MASK Raul 0x3803FF80 # ex mask 0xF803FF80 - this is EoE marker 0586800B0 + if ((wp & 0x0803FF80) == 0x08000080) { + *Col = (wp & 0x07c00000) >> 22; + *Dilogic = (wp & 0x003C0000) >> 18; + *Eoesize = (wp & 0x0000007F); + if (*Col > 24 || *Dilogic > 10) { + ILOG(INFO) << " EoE size wrong definition. Col=" << *Col << " Dilogic=" << *Dilogic << FairLogger::endl; + *Err = true; + } + return (true); + } else { + return (false); + } +} + +/// Decode the HMPID error BitMap field (5 bits) and returns true if there are +/// errors and in addition the concat string that contains the error messages +/// ATTENTION : the char * outbuf MUST point to a 250 bytes buffer +/// @param[in] ErrorField : the HMPID Error field +/// @param[out] *outbuf : the output buffer that contains the error description +/// @returns True if EoE marker is detected +bool HmpidDecoder::decodeHmpidError(int ErrorField, char *outbuf) +{ + int res = false; + outbuf[0] = '\0'; + for (int i = 0; i < MAXHMPIDERRORS; i++) { + if ((ErrorField & (0x01 << i)) != 0) { + res = true; + strcat(outbuf, sHmpidErrorDescription[i]); + } + } + return (res); +} + +/// This Decode the Raw Data Header, returns the EquipmentIndex +/// that is obtained with the FLP hardware coords +/// +/// ATTENTION : the 'EquipIndex' parameter and the mEquipment member +/// are different data: the first is the pointer in the Equipments instances +/// array, the second is the FEE_ID number +/// +/// The EVENT_NUMBER : actually is calculated from the ORBIT number +/// +/// @param[in] *streamPtrAdr : the pointer to the Header buffer +/// @param[out] *EquipIndex : the Index to the Equipment Object Array [0..13] +/// @returns True every time +/// @throws TH_WRONGEQUIPINDEX Thrown if the Equipment Index is out of boundary (Equipment not recognized) +int HmpidDecoder::decodeHeader(int32_t *streamPtrAdr, int *EquipIndex) +{ + int32_t *buffer = streamPtrAdr; // Sets the pointer to buffer + + mHeFEEID = (buffer[0] & 0x000f0000) >> 16; + mHeSize = (buffer[0] & 0x0000ff00) >> 8; + mHeVer = (buffer[0] & 0x000000ff); + mHePrior = (buffer[1] & 0x000000FF); + mHeDetectorID = (buffer[1] & 0x0000FF00) >> 8; + mHeOffsetNewPack = (buffer[2] & 0x0000FFFF); + mHeMemorySize = (buffer[2] & 0xffff0000) >> 16; + mHeDW = (buffer[3] & 0xF0000000) >> 24; + mHeCruID = (buffer[3] & 0x0FF0000) >> 16; + mHePackNum = (buffer[3] & 0x0000FF00) >> 8; + mHeLinkNum = (buffer[3] & 0x000000FF); + mHeBCDI = (buffer[4] & 0x00000FFF); + mHeORBIT = buffer[5]; + mHeTType = buffer[8]; + mHePageNum = (buffer[9] & 0x0000FFFF); + mHeStop = (buffer[9] & 0x00ff0000) >> 16; + mHeBusy = (buffer[12] & 0xfffffe00) >> 9; + mHeFirmwareVersion = buffer[12] & 0x0000000f; + mHeHmpidError = (buffer[12] & 0x000001F0) >> 4; + mHePAR = buffer[13] & 0x0000FFFF; + + *EquipIndex = getEquipmentIndex(mHeCruID, mHeLinkNum); + // mEquipment = (*EquipIndex != -1) ? mTheEquipments[*EquipIndex]->getEquipmentId() : -1; + mEquipment = mHeFEEID; + mNumberWordToRead = ((mHeMemorySize - mHeSize) / sizeof(uint32_t)); + mPayloadTail = ((mHeOffsetNewPack - mHeMemorySize) / sizeof(uint32_t)); + + // ---- Event ID : Actualy based on ORBIT NUMBER ... + mHeEvent = mHeORBIT; + + ILOG(INFO) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID <<\ + " HeMemorySize=" << mHeMemorySize << " HeOffsetNewPack=" << mHeOffsetNewPack << FairLogger::endl; + ILOG(INFO) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << \ + mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT << FairLogger::endl; + ILOG(INFO) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ + mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR << FairLogger::endl; + ILOG(INFO) << " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail << FairLogger::endl; + + if (*EquipIndex == -1) { + ILOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment << FairLogger::endl; + throw TH_WRONGEQUIPINDEX; + } + return (true); +} + +/// Updates some information related to the Event +/// this function is called at the end of the event +/// @param[in] *eq : the pointer to the Equipment Object +void HmpidDecoder::updateStatistics(HmpidEquipment *eq) +{ + eq->mPadsPerEventAverage = ((eq->mPadsPerEventAverage * (eq->mNumberOfEvents - 1)) + eq->mSampleNumber) + / (eq->mNumberOfEvents); + eq->mEventSizeAverage = ((eq->mEventSizeAverage * (eq->mNumberOfEvents - 1)) + eq->mEventSize) + / (eq->mNumberOfEvents); + eq->mBusyTimeAverage = ((eq->mBusyTimeAverage * eq->mBusyTimeSamples) + eq->mBusyTimeValue) + / (++(eq->mBusyTimeSamples)); + if (eq->mSampleNumber == 0) + eq->mNumberOfEmptyEvents += 1; + if (eq->mErrorsCounter > 0) + eq->mNumberOfWrongEvents += 1; + eq->mTotalPads += eq->mSampleNumber; + eq->mTotalErrors += eq->mErrorsCounter; + return; +} + +/// Evaluates the content of the header and detect the change of the event +/// with the relevant updates... +/// @param[in] EquipmentIndex : the pointer to the Array of Equipments Array +/// @returns the Pointer to the modified Equipment object +HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) +{ + HmpidEquipment *eq = mTheEquipments[EquipmentIndex]; + if (mHeEvent != eq->mEventNumber) { // Is a new event + if (eq->mEventNumber != -1) { // skip the first + updateStatistics(eq); // update previous statistics + } + eq->mNumberOfEvents++; + eq->mEventNumber = mHeEvent; + eq->mBusyTimeValue = mHeBusy * 0.00000005; + eq->mEventSize = 0; // reset the event + eq->mSampleNumber = 0; + eq->mErrorsCounter = 0; + } + eq->mEventSize += mNumberWordToRead * sizeof(uint32_t); // Calculate the size in bytes + if (mHeHmpidError != 0) { + ILOG(ERROR) << "HMPID Header reports an error : " << mHeHmpidError << FairLogger::endl; + dumpHmpidError(mHeHmpidError); + eq->setError(ERR_HMPID); + } + return (eq); +} + +/// --------------- Read Raw Data Buffer --------------- +/// Read the stream, decode the contents and store resuls. +/// ATTENTION : Assumes that the input stream was set +/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header +bool HmpidDecoder::decodeBuffer() +{ + // ---------resets the PAdMap----------- + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i]->init(); + mTheEquipments[i]->resetPadMap(); + mTheEquipments[i]->resetErrors(); + } + + int type; + int equipmentIndex = -1; + int isIt; + HmpidEquipment *eq; + int32_t *streamBuf; + ILOG(DEBUG) << "Enter decoding !" << FairLogger::endl; + + // Input Stream Main Loop + while (true) { + try { + getHeaderFromStream(&streamBuf); + } + catch (int e) { + // The stream end ! + ILOG(DEBUG) << "End main decoding loop !" << FairLogger::endl; + break; + } + try { + decodeHeader(streamBuf, &equipmentIndex); + } + catch (int e) { + ILOG(ERROR) << "Failed to decode the Header !" << FairLogger::endl; + throw TH_WRONGHEADER; + } + + eq = evaluateHeaderContents(equipmentIndex); + + int wpprev = 0; + int wp = 0; + int newOne = true; + int p1, p2, p3, p4; + int error; + + int payIndex = 0; + while (payIndex < mNumberWordToRead) { //start the payload loop word by word + if (newOne == true) { + wpprev = wp; + if (!getWordFromStream(&wp)) { // end the stream + break; + } + + type = checkType(wp, &p1, &p2, &p3, &p4); + if (type == WTYPE_NONE) { + if (eq->mWillBePad == true) { // try to recover the first pad ! + type = checkType((wp & 0xF7FFFFFF), &p1, &p2, &p3, &p4); + if (type == WTYPE_PAD && p3 == 0 && eq->mWordsPerDilogicCounter == 0) { + newOne = false; // # reprocess as pad + continue; + } + } + eq->setError(ERR_NOTKNOWN); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_NOTKNOWN] << " [" << wp << "]" << FairLogger::endl; + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; + payIndex++; + continue; + } + } + + if (eq->mWillBeRowMarker == true) { // #shoud be a Row Marker + if (type == WTYPE_ROW) { + eq->mColumnCounter++; + eq->mWordsPerSegCounter++; + eq->mRowSize = p2; + switch (p2) { + case 0: // Empty column + eq->setError(ERR_ROWMARKEMPTY); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKEMPTY] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = true; + break; + case 0x3FF: // Error in column + eq->setError(ERR_ROWMARKERROR); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKERROR] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = true; + break; + case 0x3FE: // Masked column + ILOG(INFO) << "Equip=" << mEquipment << "The column=" << (eq->mSegment) * 8 + eq->mColumnCounter << " is Masked !" << FairLogger::endl; + eq->mWillBeRowMarker = true; + break; + default: + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + break; + } + newOne = true; + } else { + if (wp == wpprev) { + eq->setError(ERR_DUPLICATEPAD); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + newOne = true; + } else if (type == WTYPE_EOE) { // # Could be a EoE + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKWRONG); + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } else if (type == WTYPE_PAD) { //# Could be a PAD + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKLOST); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } else if (type == WTYPE_EOS) { // # Could be a EoS + eq->mWillBeRowMarker = false; + eq->mWillBeSegmentMarker = true; + newOne = false; + } else { + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKLOST); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } + } + } else if (eq->mWillBePad == true) { // # We expect a pad + //# PAD:0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value + // c = 1..24 d = 1..10 n = 0..47 + if (type == WTYPE_PAD) { + newOne = true; + if (wp == wpprev) { + eq->setError(ERR_DUPLICATEPAD); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + } else if (p1 != (eq->mSegment * 8 + eq->mColumnCounter)) { // # Manage + // We try to recover the RowMarker misunderstanding + isIt = isRowMarker(wp, &error, &p2, &p1); + if (isIt == true && error == false) { + type = WTYPE_ROW; + newOne = false; + eq->mWillBeEoE = true; + eq->mWillBePad = false; + } else { + ILOG(DEBUG) << "Equip=" << mEquipment << " Mismatch in column" << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mColumnCounter = p1 % 8; + } + } else { + setPad(eq, p1 - 1, p2 - 1, p3, p4); + eq->mWordsPerDilogicCounter++; + eq->mSampleNumber++; + if (p3 == 47) { + eq->mWillBeEoE = true; + eq->mWillBePad = false; + } + } + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; + } else if (type == WTYPE_EOE) { //# the pads are end ok + eq->mWillBeEoE = true; + eq->mWillBePad = false; + newOne = false; + } else if (type == WTYPE_ROW) { // # We Lost the EoE ! + // We try to recover the PAD misunderstanding + isIt = isPadWord(wp, &error, &p1, &p2, &p3, &p4); + if (isIt == true && error == false) { + type = WTYPE_PAD; + newOne = false; // # reprocess as pad + } else { + eq->setError(ERR_LOSTEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = true; + eq->mWillBePad = false; + newOne = false; + } + } else if (type == WTYPE_EOS) { // # We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeSegmentMarker = true; + eq->mWillBePad = false; + newOne = false; + } + } else if (eq->mWillBeEoE == true) { // # We expect a EoE + if (type == WTYPE_EOE) { + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; + if (wpprev == wp) { + eq->setError(ERR_DOUBLEEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEEOEMARK] << " col=" << p1 << FairLogger::endl; + } else if (p3 != eq->mWordsPerDilogicCounter) { + eq->setError(ERR_WRONGSIZEINEOE); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZEINEOE] << " col=" << p1 << FairLogger::endl; + } + eq->mWordsPerDilogicCounter = 0; + if (p2 == 10) { + if (p1 % 8 != 0) { // # we expect the Row Marker + eq->mWillBeRowMarker = true; + } else { + eq->mWillBeSegmentMarker = true; + } + } else { + eq->mWillBePad = true; + } + eq->mWillBeEoE = false; + newOne = true; + } else if (type == WTYPE_EOS) { // We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeSegmentMarker = true; + eq->mWillBeEoE = false; + newOne = false; + } else if (type == WTYPE_ROW) { //# We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = true; + eq->mWillBeEoE = false; + newOne = false; + } else if (type == WTYPE_PAD) { // # We Lost the EoE ! + int typb, p1b, p2b, p3b, p4b; + typb = checkType((wp | 0x08000000), &p1b, &p2b, &p3b, &p4b); + if (typb == WTYPE_EOE && p3b == 48) { + type = typb; + p1 = p1b; + p2 = p2b; + p3 = p3b; + p4 = p4b; + newOne = false; // # reprocess as EoE + } else { + eq->setError(ERR_LOSTEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBePad = true; + eq->mWillBeEoE = false; + newOne = false; + } + } + } else if (eq->mWillBeSegmentMarker == true) { // # We expect a EoSegment + if (wpprev == wp) { + eq->setError(ERR_DOUBLEMARKWORD); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEMARKWORD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + newOne = true; + } else if (type == 2) { + if (abs(eq->mWordsPerSegCounter - p2) > 5) { + eq->setError(ERR_WRONGSIZESEGMENTMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZESEGMENTMARK] << " Seg=" << p2 << FairLogger::endl; + } + eq->mWordsPerSegCounter = 0; + eq->mWordsPerRowCounter = 0; + eq->mColumnCounter = 0; + eq->mSegment = p3 % 3; + eq->mWillBeRowMarker = true; + eq->mWillBeSegmentMarker = false; + newOne = true; + } else { + eq->setError(ERR_LOSTEOSMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOSMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeSegmentMarker = false; + eq->mWillBeRowMarker = true; + newOne = false; + } + } + if (newOne) { + payIndex += 1; + } + } + for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail + getWordFromStream(&wp); + } + } // this is the end of stream + + // cycle in order to update info for the last event + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->mNumberOfEvents > 0) { + updateStatistics(mTheEquipments[i]); + } + } + return (true); +} + +/// ---------- Read Raw Data Buffer with Fast Decoding ---------- +/// Read the stream, decode the contents and store resuls. +/// Fast alghoritm : no parsing of control words ! +/// ATTENTION : Assumes that the input stream was set +/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header +bool HmpidDecoder::decodeBufferFast() +{ + // ---------resets the PAdMap----------- + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i]->init(); + mTheEquipments[i]->resetPadMap(); + } + + int type; + int equipmentIndex = -1; + int isIt; + HmpidEquipment *eq; + int32_t *streamBuf; + ILOG(DEBUG) << "Enter FAST decoding !" << FairLogger::endl; + + // Input Stream Main Loop + while (true) { + try { + getHeaderFromStream(&streamBuf); + } + catch (int e) { + // The stream end ! + ILOG(DEBUG) << "End main decoding loop !" << FairLogger::endl; + break; + } + try { + decodeHeader(streamBuf, &equipmentIndex); + } + catch (int e) { + ILOG(ERROR) << "Failed to decode the Header !" << FairLogger::endl; + throw TH_WRONGHEADER; + } + + eq = evaluateHeaderContents(equipmentIndex); + + int wpprev = 0; + int wp = 0; + int newOne = true; + int p1, p2, p3, p4; + int error; + + int payIndex = 0; + while (payIndex < mNumberWordToRead) { //start the payload loop word by word + wpprev = wp; + if (!getWordFromStream(&wp)) { // end the stream + break; + } + if (wp == wpprev) { + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + } else { + if( isPadWord(wp, &error, &p1, &p2, &p3, &p4) == true) { + if( error != false) { + setPad(eq, p1 - 1, p2 - 1, p3, p4); + eq->mSampleNumber++; + } + } + } + payIndex += 1; + } + for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail + getWordFromStream(&wp); + } + } // this is the end of stream + + // cycle in order to update info for the last event + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->mNumberOfEvents > 0) { + updateStatistics(mTheEquipments[i]); + } + } + return (true); +} + + + +// ========================================================= + +/// Getter method to extract Statistic Data in Digit Coords +/// @param[in] Module : the HMPID Module number [0..6] +/// @param[in] Column : the HMPID Module Column number [0..143] +/// @param[in] Row : the HMPID Module Row number [0..159] +/// @returns The Number of entries for specified pad +uint16_t HmpidDecoder::getPadSamples(int Module, int Column, int Row) +{ + int e, c, d, h; + Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + int EqInd = getEquipmentIndex(e); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSamples[c][d][h]); +} + +/// Getter method to extract Statistic Data in Digit Coords +/// @param[in] Module : the HMPID Module number [0..6] +/// @param[in] Column : the HMPID Module Column number [0..143] +/// @param[in] Row : the HMPID Module Row number [0..159] +/// @returns The Sum of Charges for specified pad +double HmpidDecoder::getPadSum(int Module, int Column, int Row) +{ + int e, c, d, h; + Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + int EqInd = getEquipmentIndex(e); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSum[c][d][h]); +} + +/// Getter method to extract Statistic Data in Digit Coords +/// @param[in] Module : the HMPID Module number [0..6] +/// @param[in] Column : the HMPID Module Column number [0..143] +/// @param[in] Row : the HMPID Module Row number [0..159] +/// @returns The Sum of Square Charges for specified pad +double HmpidDecoder::getPadSquares(int Module, int Column, int Row) +{ + int e, c, d, h; + Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + int EqInd = getEquipmentIndex(e); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSquares[c][d][h]); +} + +/// Getter method to extract Statistic Data in Hardware Coords +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @param[in] Column : the HMPID Module Column number [0..23] +/// @param[in] Dilogic : the HMPID Module Row number [0..9] +/// @param[in] Channel : the HMPID Module Row number [0..47] +/// @returns The Number of Entries for specified pad +uint16_t HmpidDecoder::getChannelSamples(int EquipmId, int Column, int Dilogic, int Channel) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSamples[Column][Dilogic][Channel]); +} + +/// Getter method to extract Statistic Data in Hardware Coords +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @param[in] Column : the HMPID Module Column number [0..23] +/// @param[in] Dilogic : the HMPID Module Row number [0..9] +/// @param[in] Channel : the HMPID Module Row number [0..47] +/// @returns The Sum of Charges for specified pad +double HmpidDecoder::getChannelSum(int EquipmId, int Column, int Dilogic, int Channel) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSum[Column][Dilogic][Channel]); +} + +/// Getter method to extract Statistic Data in Hardware Coords +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @param[in] Column : the HMPID Module Column number [0..23] +/// @param[in] Dilogic : the HMPID Module Row number [0..9] +/// @param[in] Channel : the HMPID Module Row number [0..47] +/// @returns The Sum of Square Charges for specified pad +double HmpidDecoder::getChannelSquare(int EquipmId, int Column, int Dilogic, int Channel) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSquares[Column][Dilogic][Channel]); +} + +/// Gets the Average Event Size value +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @returns The Average Event Size value ( 0 for wrong Equipment Id) +float HmpidDecoder::getAverageEventSize(int EquipmId) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return (0.0); + return (mTheEquipments[EqInd]->mEventSizeAverage); +} + +/// Gets the Average Busy Time value +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @returns The Average Busy Time value ( 0 for wrong Equipment Id) +float HmpidDecoder::getAverageBusyTime(int EquipmId) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return (0.0); + return (mTheEquipments[EqInd]->mBusyTimeAverage); +} + +// =================================================== +// Methods to dump info + + +/// Prints on the standard output the table of decoding +/// errors for one equipment +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +void HmpidDecoder::dumpErrors(int EquipmId) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return; + + std::cout << "Dump Errors for the Equipment = " << EquipmId << std::endl; + for (int i = 0; i < MAXERRORS; i++) { + std::cout << sErrorDescription[i] << " = " << mTheEquipments[EqInd]->mErrors[i] << std::endl; + } + std::cout << " -------- " << std::endl; + return; +} + +/// Prints on the standard output a Table of statistical +/// decoding information for one equipment +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @type[in] The type of info. 0 = Entries, 1 = Sum, 2 = Sum of squares +void HmpidDecoder::dumpPads(int EquipmId, int type) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return; + + int Module = EquipmId / 2; + int StartRow = (EquipmId % 2 == 1) ? 80 : 0; + int EndRow = (EquipmId % 2 == 1) ? 160 : 80; + std::cout << "Dump Pads for the Equipment = " << EquipmId << std::endl; + for (int c = 0; c < 144; c++) { + for (int r = StartRow; r < EndRow; r++) { + switch (type) { + case 0: + std::cout << getPadSamples(Module, c, r) << ","; + break; + case 1: + std::cout << getPadSum(Module, c, r) << ","; + break; + case 2: + std::cout << getPadSquares(Module, c, r) << ","; + break; + } + } + std::cout << std::endl; + } + std::cout << " -------- " << std::endl; + return; +} + +/// Prints on the standard output the decoded HMPID error field +/// @param[in] ErrorField : the HMPID readout error field +void HmpidDecoder::dumpHmpidError(int ErrorField) +{ + char printbuf[MAXHMPIDERRORS * MAXDESCRIPTIONLENGHT]; + if (decodeHmpidError(ErrorField, printbuf) == true) { + ILOG(ERROR) << "HMPID Error field = " << ErrorField << " : " << printbuf << FairLogger::endl; + } + return; +} + +/// Writes in a ASCCI File the complete report of the decoding +/// procedure +/// @param[in] *summaryFileName : the name of the output file +/// @throws TH_CREATEFILE Thrown if was not able to create the file +void HmpidDecoder::writeSummaryFile(char *summaryFileName) +{ + FILE *fs = fopen(summaryFileName, "w"); + if (fs == 0) { + printf("Error opening the file %s !\n", summaryFileName); + throw TH_CREATEFILE; + } + + fprintf(fs, "HMPID Readout Raw Data Decoding Summary File\n"); + fprintf(fs, "Equipment Id\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->getEquipmentId()); + fprintf(fs, "\n"); + + fprintf(fs, "Number of events\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mNumberOfEvents); + fprintf(fs, "\n"); + + fprintf(fs, "Average Event Size\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%f\t", mTheEquipments[i]->mEventSizeAverage); + fprintf(fs, "\n"); + + fprintf(fs, "Total pads\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mTotalPads); + fprintf(fs, "\n"); + + fprintf(fs, "Average pads per event\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%f\t", mTheEquipments[i]->mPadsPerEventAverage); + fprintf(fs, "\n"); + + fprintf(fs, "Busy Time average\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%e\t", mTheEquipments[i]->mBusyTimeAverage); + fprintf(fs, "\n"); + + fprintf(fs, "Event rate\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%e\t", 1 / mTheEquipments[i]->mBusyTimeAverage); + fprintf(fs, "\n"); + + fprintf(fs, "Number of Empty Events\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mNumberOfEmptyEvents); + fprintf(fs, "\n"); + + fprintf(fs, "-------------Errors--------------------\n"); + fprintf(fs, "Wrong events\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mNumberOfWrongEvents); + fprintf(fs, "\n"); + + for (int j = 0; j < MAXERRORS; j++) { + fprintf(fs, "%s\t", sErrorDescription[j]); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mErrors[j]); + fprintf(fs, "\n"); + } + + fprintf(fs, "Total errors\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mTotalErrors); + fprintf(fs, "\n"); + + fclose(fs); + return; +} diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.h b/Detectors/HMPID/reconstruction/src/HmpidDecoder.h new file mode 100644 index 0000000000000..f01a58962d54a --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.h @@ -0,0 +1,167 @@ +// 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 HmpidDecoder.h +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to decode HMPID Raw Data stream +/// + +#ifndef COMMON_HMPIDDECODER_H_ +#define COMMON_HMPIDDECODER_H_ + +#include +#include +#include +#include + +#include "FairLogger.h" + +#include "HmpidEquipment.h" + +#define MAXDESCRIPTIONLENGHT 50 + +// ---- RDH 6 standard dimension ------- +#define RAWBLOCKDIMENSION_W 2048 +#define HEADERDIMENSION_W 16 +#define PAYLOADDIMENSION_W 2032 + +// ---- Defines for the decoding +#define WTYPE_ROW 1 +#define WTYPE_EOS 2 +#define WTYPE_PAD 3 +#define WTYPE_EOE 4 +#define WTYPE_NONE 0 + + +// Hmpid Equipment class +namespace o2 { + +namespace hmpid { + +class HmpidDecoder +{ + + // Members + public: + int mVerbose; + HmpidEquipment *mTheEquipments[Geo::MAXEQUIPMENTS]; + int mNumberOfEquipments; + + static char sErrorDescription[MAXERRORS][MAXDESCRIPTIONLENGHT]; + static char sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT]; + + public: + int mHeEvent; + int mHeBusy; + int mNumberWordToRead; + int mPayloadTail; + + int mHeFEEID; + int mHeSize; + int mHeVer; + int mHePrior; + int mHeStop; + int mHePages; + int mEquipment; + + int mHeOffsetNewPack; + int mHeMemorySize; + + int mHeDetectorID; + int mHeDW; + int mHeCruID; + int mHePackNum; + int mHePAR; + + int mHePageNum; + int mHeLinkNum; + int mHeFirmwareVersion; + int mHeHmpidError; + int mHeBCDI; + int mHeORBIT; + int mHeTType; + + int32_t *mActualStreamPtr; + int32_t *mEndStreamPtr; + int32_t *mStartStreamPtr; + + // Methods + public: + HmpidDecoder(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); + HmpidDecoder(int numOfEquipments); + ~HmpidDecoder(); + + void init(); + virtual bool setUpStream(void *Buffer, long BufferLen) = 0; + void setVerbosity(int Level) + { + mVerbose = Level; + } + ; + int getVerbosity() + { + return (mVerbose); + } + ; + + int getNumberOfEquipments() + { + return (mNumberOfEquipments); + } + ; + int getEquipmentIndex(int EquipmentId); + int getEquipmentIndex(int CruID, int LinkId); + int getEquipmentID(int CruId, int LinkId); + + bool decodeBuffer(); + bool decodeBufferFast(); + + uint16_t getChannelSamples(int Equipment, int Column, int Dilogic, int Channel); + double getChannelSum(int Equipment, int Column, int Dilogic, int Channel); + double getChannelSquare(int Equipment, int Column, int Dilogic, int Channel); + uint16_t getPadSamples(int Module, int Column, int Row); + double getPadSum(int Module, int Column, int Row); + double getPadSquares(int Module, int Column, int Row); + + void dumpErrors(int Equipment); + void dumpPads(int Equipment, int type = 0); + void writeSummaryFile(char *summaryFileName); + + float getAverageEventSize(int Equipment); + float getAverageBusyTime(int Equipment); + + protected: + int checkType(int32_t wp, int *p1, int *p2, int *p3, int *p4); + bool isRowMarker(int32_t wp, int *Err, int *rowSize, int *mark); + bool isSegmentMarker(int32_t wp, int *Err, int *segSize, int *Seg, int *mark); + bool isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge); + bool isEoEmarker(int32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize); + int decodeHeader(int32_t *streamPtrAdr, int *EquipIndex); + bool decodeHmpidError(int ErrorField, char *outbuf); + void dumpHmpidError(int ErrorField); + HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); + void updateStatistics(HmpidEquipment *eq); + + virtual void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) = 0; + + virtual bool getBlockFromStream(int32_t **streamPtr, uint32_t Size) = 0; + virtual bool getHeaderFromStream(int32_t **streamPtr) = 0; + virtual bool getWordFromStream(int32_t *word) = 0; + int32_t* getActualStreamPtr() + { + return (mActualStreamPtr); + } + ; + +}; +} +} +#endif /* COMMON_HMPIDDECODER_H_ */ diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx new file mode 100644 index 0000000000000..fc442cc92be1b --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx @@ -0,0 +1,139 @@ +// 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 HmpidEquipments.h +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to describe HMPID Equipment +/// \version 1.0 +/// \date 24 set 2020 + +/* ------ HISTORY --------- +*/ + +#include "HmpidEquipment.h" + +using namespace o2::hmpid; + +// ============= HmpidEquipment Class implementation ======= + +/// Constructor : map the Equipment_ID with the CRU_Id and Link_Id +/// +/// @param[in] Equipment : the HMPID EquipmentId [0..13] +/// @param[in] Cru : the HMPID Cru [0..3] (FLP160 = 0,1 FLP161 = 2,3) +/// @param[in] Link : the FLP Link [0..3] +HmpidEquipment::HmpidEquipment(int Equipment, int Cru, int Link) +{ + mEquipmentId = Equipment; + mCruId = Cru; + mLinkId = Link; + return; +} + +/// Destructor : do nothing +HmpidEquipment::~HmpidEquipment() +{ + return; +} + +/// Inits the members for the decoding +void HmpidEquipment::init() +{ + mWillBeRowMarker = true; + mWillBeSegmentMarker = false; + mWillBeEoE = false; + mWillBePad = false; + mRowSize = 0; + mSegment = 0; + mColumnCounter = 0; + mWordsPerRowCounter = 0; + mWordsPerSegCounter = 0; + mWordsPerDilogicCounter = 0; + mSampleNumber = 0; + mErrorsCounter = 0; + mErrorPadsPerEvent = 0; + + mEventNumber = -1; + mNumberOfEvents = 0; + + mBusyTimeValue = 0.0; + mBusyTimeAverage = 0.0; + mBusyTimeSamples = 0; + + mEventSizeAverage = 0.0; + mEventSize = 0; + + mPadsPerEventAverage = 0.0; + + mNumberOfEmptyEvents = 0; + mNumberOfWrongEvents = 0; + mTotalPads = 0; + mTotalErrors = 0; + + return; +} + +/// Resets the matrix that contains the results of the decoding +void HmpidEquipment::resetPadMap() +{ + for (int r = 0; r < Geo::N_COLUMNS; r++) + for (int d = 0; d < Geo::N_DILOGICS; d++) + for (int c = 0; c < Geo::N_CHANNELS; c++) { + mPadSamples[r][d][c] = 0; + mPadSum[r][d][c] = 0.0; + mPadSquares[r][d][c] = 0.0; + } + return; +} + +/// Resets the decoding errors statistics +void HmpidEquipment::resetErrors() +{ + for (int i = 0; i < MAXERRORS; i++) + mErrors[i] = 0; + return; +} + +/// Setup an error by type +/// TODO : control of array boundary +/// @param[in] ErrType : the Decoding error type [0..MAXERRORS] +void HmpidEquipment::setError(int ErrType) +{ + mErrors[ErrType]++; + mErrorsCounter++; + return; +} + +/// Set the charge value of a pad into the three statistics +/// matrix : Entries, Sum of charge, Sum of Charge squares +/// @param[in] col : column [0..23] +/// @param[in] dil : dilogic [0..9] +/// @param[in] cha : channel [0..47] +/// @param[in] charge : the value of the charge +void HmpidEquipment::setPad(int col, int dil, int cha, int charge) +{ + mPadSamples[col][dil][cha]++; + mPadSum[col][dil][cha] += (double) charge; + mPadSquares[col][dil][cha] += (double) charge * (double) charge; + return; +} + +/// Return the EquipmentId with the check of CRU_Id and Link_Id +/// @param[in] cru : FLP CRU Id [0..3] +/// @param[in] link : CRU Link Id [0..3] +/// @returns the Equipment Id +int HmpidEquipment::getEquipmentId(int cru, int link) +{ + if (cru == mCruId && link == mLinkId) + return (mEquipmentId); + else + return (-1); +} + diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.h b/Detectors/HMPID/reconstruction/src/HmpidEquipment.h new file mode 100644 index 0000000000000..aa324ea9c2fa9 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.h @@ -0,0 +1,135 @@ +// 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 HmpidEquipments.h +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to describe HMPID Equipment for the decoding of RawData stream +/// \version 1.0 +/// \date 24 set 2020 + +#ifndef COMMON_HMPIDEQUIPMENT_H_ +#define COMMON_HMPIDEQUIPMENT_H_ + +#include +#include +#include + +#include "HMPIDBase/Geo.h" + +namespace o2 +{ +namespace hmpid +{ + +const int MAXERRORS = 13; +const int MAXHMPIDERRORS = 5; + +const int ERR_NOTKNOWN = 0; +const int ERR_ROWMARKEMPTY = 1; +const int ERR_DUPLICATEPAD = 2; +const int ERR_ROWMARKWRONG = 3; +const int ERR_ROWMARKLOST = 4; +const int ERR_ROWMARKERROR = 5; +const int ERR_LOSTEOEMARK = 6; +const int ERR_DOUBLEEOEMARK = 7; +const int ERR_WRONGSIZEINEOE = 8; +const int ERR_DOUBLEMARKWORD = 9; +const int ERR_WRONGSIZESEGMENTMARK = 10; +const int ERR_LOSTEOSMARK = 11; +const int ERR_HMPID = 12; + +// ---- HMPID error def ------- +const int TH_FILENOTEXISTS = 9; +const int TH_OPENFILE = 8; +const int TH_CREATEFILE = 7; +const int TH_READFILE = 6; +const int TH_WRITEFILE = 5; +const int TH_WRONGEQUIPINDEX = 19; +const int TH_WRONGHEADER = 15; +const int TH_WRONGFILELEN = 14; +const int TH_NULLBUFFERPOINTER = 13; +const int TH_BUFFEREMPTY = 12; +const int TH_WRONGBUFFERDIM = 11; + + + + +class HmpidEquipment +{ + + private: + + uint32_t mEquipmentId; + uint32_t mCruId; + uint32_t mLinkId; + + public: + + uint32_t mPadSamples[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; + double mPadSum[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; + double mPadSquares[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; + + int mErrors[MAXERRORS]; + + int mWillBeRowMarker; + int mWillBeSegmentMarker; + int mWillBeEoE; + int mWillBePad; + int mRowSize; + int mSegment; + int mColumnCounter; + int mWordsPerRowCounter; + int mWordsPerSegCounter; + int mWordsPerDilogicCounter; + + int mErrorsCounter; + int mErrorPadsPerEvent; + + int mEventNumber; + int mNumberOfEvents; + float mEventSizeAverage; + int mEventSize; + + int mSampleNumber; + float mPadsPerEventAverage; + + float mBusyTimeValue; + float mBusyTimeAverage; + int mBusyTimeSamples; + int mNumberOfEmptyEvents; + int mNumberOfWrongEvents; + int mTotalPads; + int mTotalErrors; + + public: + HmpidEquipment(int Equipment, int Cru, int Link); + ~HmpidEquipment(); + + int getEquipmentId() + { + return (mEquipmentId); + } + ; + int getEquipmentId(int cru, int link); + + void init(); + void resetPadMap(); + void resetErrors(); + void setError(int ErrType); + void setPad(int col, int dil, int cha, int charge); + +}; + +} // namespace hmpid +} // namespace o2 + + +#endif /* COMMON_HMPIDEQUIPMENT_H_ */ diff --git a/GPU/GPUTracking/Standalone/Common b/GPU/GPUTracking/Standalone/Common index a66ad39d9318c..8267556b4adf4 120000 --- a/GPU/GPUTracking/Standalone/Common +++ b/GPU/GPUTracking/Standalone/Common @@ -1 +1 @@ -../../Common/ \ No newline at end of file +../../Common \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/Global b/GPU/GPUTracking/Standalone/Global index 7bfca6e01147e..f0aa85e860967 120000 --- a/GPU/GPUTracking/Standalone/Global +++ b/GPU/GPUTracking/Standalone/Global @@ -1 +1 @@ -../Global/ \ No newline at end of file +../Global \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/HLTHeaders b/GPU/GPUTracking/Standalone/HLTHeaders index 3f271033d8eeb..04ee42150c2fa 120000 --- a/GPU/GPUTracking/Standalone/HLTHeaders +++ b/GPU/GPUTracking/Standalone/HLTHeaders @@ -1 +1 @@ -../HLTHeaders/ \ No newline at end of file +../HLTHeaders \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/ITS b/GPU/GPUTracking/Standalone/ITS index 3ed25d6858b1e..d8e5c8b49d528 120000 --- a/GPU/GPUTracking/Standalone/ITS +++ b/GPU/GPUTracking/Standalone/ITS @@ -1 +1 @@ -../ITS/ \ No newline at end of file +../ITS \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/Merger b/GPU/GPUTracking/Standalone/Merger index ddb7c2e13a8d9..8bb6fe6d7b583 120000 --- a/GPU/GPUTracking/Standalone/Merger +++ b/GPU/GPUTracking/Standalone/Merger @@ -1 +1 @@ -../Merger/ \ No newline at end of file +../Merger \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/SliceTracker b/GPU/GPUTracking/Standalone/SliceTracker index b2ff0a64ab1a7..c34e64b9edf11 120000 --- a/GPU/GPUTracking/Standalone/SliceTracker +++ b/GPU/GPUTracking/Standalone/SliceTracker @@ -1 +1 @@ -../SliceTracker/ \ No newline at end of file +../SliceTracker \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/TPCFastTransformation b/GPU/GPUTracking/Standalone/TPCFastTransformation index a8c5e0a2ebd0c..d631da4216cd7 120000 --- a/GPU/GPUTracking/Standalone/TPCFastTransformation +++ b/GPU/GPUTracking/Standalone/TPCFastTransformation @@ -1 +1 @@ -../../TPCFastTransformation/ \ No newline at end of file +../../TPCFastTransformation \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/TRDTracking b/GPU/GPUTracking/Standalone/TRDTracking index db0ce36effe8b..8fb1cffa1420c 120000 --- a/GPU/GPUTracking/Standalone/TRDTracking +++ b/GPU/GPUTracking/Standalone/TRDTracking @@ -1 +1 @@ -../TRDTracking/ \ No newline at end of file +../TRDTracking \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/dependencies b/GPU/GPUTracking/Standalone/dependencies index 90273dd71ef60..c2e0ef0135d70 120000 --- a/GPU/GPUTracking/Standalone/dependencies +++ b/GPU/GPUTracking/Standalone/dependencies @@ -1 +1 @@ -../../../dependencies/ \ No newline at end of file +../../../dependencies \ No newline at end of file From 7a638ccea62c28c6a61d1c0078df170b3d227d7a Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 18 Jan 2021 10:03:04 +0100 Subject: [PATCH 005/208] Prima versione --- .../HMPID/base/include/HMPIDBase/Digit.h | 127 +--- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 7 +- Detectors/HMPID/base/src/Digit.cxx | 64 ++ Detectors/HMPID/base/src/Geo.cxx | 26 + .../HMPIDReconstruction}/HmpidDecodeRawFile.h | 8 +- .../HMPIDReconstruction}/HmpidDecodeRawMem.h | 24 +- .../HMPIDReconstruction}/HmpidDecoder.h | 37 +- .../HMPIDReconstruction}/HmpidEquipment.h | 2 +- .../reconstruction/src/HmpidDecodeRawFile.cxx | 14 +- .../reconstruction/src/HmpidDecodeRawMem.cxx | 78 +- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 689 ++++++++++-------- .../reconstruction/src/HmpidEquipment.cxx | 2 +- .../HMPID/simulation/src/HMPIDDigitizer.cxx | 7 +- .../include/HMPIDWorkflow/DataDecoderSpec.h | 16 + .../HMPID/workflow/src/DataDecoderSpec.cxx | 187 +++-- 15 files changed, 764 insertions(+), 524 deletions(-) rename Detectors/HMPID/reconstruction/{src => include/HMPIDReconstruction}/HmpidDecodeRawFile.h (87%) rename Detectors/HMPID/reconstruction/{src => include/HMPIDReconstruction}/HmpidDecodeRawMem.h (69%) rename Detectors/HMPID/reconstruction/{src => include/HMPIDReconstruction}/HmpidDecoder.h (78%) rename Detectors/HMPID/reconstruction/{src => include/HMPIDReconstruction}/HmpidEquipment.h (99%) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 27f43af50cedb..be5116f0da64e 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -23,96 +23,45 @@ namespace hmpid /// \class Digit /// \brief HMPID digit implementation -using DigitBase = o2::dataformats::TimeStamp; -class Digit : public DigitBase +//using DigitBase = o2::dataformats::TimeStamp; +class Digit { - public: - Digit() = default; - Digit(double time, int pad, float charge) : DigitBase(time), mPad(pad), mQ(charge) {} - - float getCharge() const { return mQ; } - int getPadID() const { return mPad; } - // convenience conversion to x-y pad coordinates - int getPx() const { return Param::A2X(mPad); } - int getPy() const { return Param::A2Y(mPad); } - - static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge) - { - float localX; - float localY; - chamber = hit.GetDetectorID(); - double tmp[3] = {hit.GetX(), hit.GetY(), hit.GetZ()}; - Param::Instance()->Mars2Lors(chamber, tmp, localX, localY); - Param::Lors2Pad(localX, localY, pc, px, py); - - totalcharge = Digit::QdcTot(hit.GetEnergyLoss(), hit.GetTime(), pc, px, py, localX, localY); - } - - static float getFractionalContributionForPad(HitType const& hit, int somepad) - { - float localX; - float localY; - - // chamber number is in detID - const auto chamber = hit.GetDetectorID(); - double tmp[3] = {hit.GetX(), hit.GetY(), hit.GetZ()}; - // converting chamber id and hit coordiates to local coordinates - Param::Instance()->Mars2Lors(chamber, tmp, localX, localY); - // calculate charge fraction in given pad - return Digit::InMathieson(localX, localY, somepad); - } - - // add charge to existing digit - void addCharge(float q) { mQ += q; } - - private: - float mQ = 0.; - int mPad = 0.; // -1 indicates invalid digit - - static float LorsX(int pad) { return Param::LorsX(Param::A2P(pad), Param::A2X(pad)); } //center of the pad x, [cm] - static float LorsY(int pad) { return Param::LorsY(Param::A2P(pad), Param::A2Y(pad)); } //center of the pad y, [cm] - - // determines the total charge created by a hit - // might modify the localX, localY coordiates associated to the hit - static float QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY); - - static float IntPartMathiX(float x, int pad) - { - // Integration of Mathieson. - // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603) - // Arguments: x,y- position of the center of Mathieson distribution - // Returns: a charge fraction [0-1] imposed into the pad - auto shift1 = -LorsX(pad) + 0.5 * Param::SizePadX(); - auto shift2 = -LorsX(pad) - 0.5 * Param::SizePadX(); - - auto ux1 = Param::SqrtK3x() * TMath::TanH(Param::K2x() * (x + shift1) / Param::PitchAnodeCathode()); - auto ux2 = Param::SqrtK3x() * TMath::TanH(Param::K2x() * (x + shift2) / o2::hmpid::Param::PitchAnodeCathode()); - - return o2::hmpid::Param::K4x() * (TMath::ATan(ux2) - TMath::ATan(ux1)); - } - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - static Double_t IntPartMathiY(Double_t y, int pad) - { - // Integration of Mathieson. - // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603) - // Arguments: x,y- position of the center of Mathieson distribution - // Returns: a charge fraction [0-1] imposed into the pad - Double_t shift1 = -LorsY(pad) + 0.5 * o2::hmpid::Param::SizePadY(); - Double_t shift2 = -LorsY(pad) - 0.5 * o2::hmpid::Param::SizePadY(); - - Double_t uy1 = Param::SqrtK3y() * TMath::TanH(Param::K2y() * (y + shift1) / Param::PitchAnodeCathode()); - Double_t uy2 = Param::SqrtK3y() * TMath::TanH(Param::K2y() * (y + shift2) / Param::PitchAnodeCathode()); - - return Param::K4y() * (TMath::ATan(uy2) - TMath::ATan(uy1)); - } - - static float InMathieson(float localX, float localY, int pad) - { - return 4. * Digit::IntPartMathiX(localX, pad) * Digit::IntPartMathiY(localY, pad); - } - - ClassDefNV(Digit, 2); + public: + Digit() = default; + Digit(int bc, int orbit, int pad, float charge) : mBc(bc), mOrbit(orbit), mPad(pad), mQ(charge) {}; + + float getCharge() const { return mQ; } + int getPadID() const { return mPad; } + int getOrbit() const { return mOrbit; } + int getBC() const { return mBc; } + + // convenience conversion to x-y pad coordinates + int getPx() const { return Param::A2X(mPad); } + int getPy() const { return Param::A2Y(mPad); } + + static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); + static float getFractionalContributionForPad(HitType const& hit, int somepad); + + // add charge to existing digit + void addCharge(float q) { mQ += q; } + + private: + float mQ = 0.; + int mPad = 0.; // -1 indicates invalid digit + int mBc = 0.; + int mOrbit = 0; + + static float LorsX(int pad) { return Param::LorsX(Param::A2P(pad), Param::A2X(pad)); } //center of the pad x, [cm] + static float LorsY(int pad) { return Param::LorsY(Param::A2P(pad), Param::A2Y(pad)); } //center of the pad y, [cm] + + // determines the total charge created by a hit + // might modify the localX, localY coordiates associated to the hit + static float QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY); + static float IntPartMathiX(float x, int pad); + static Double_t IntPartMathiY(Double_t y, int pad); + static float InMathieson(float localX, float localY, int pad); + + ClassDefNV(Digit, 2); }; } // namespace hmpid diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 469c32a5cba26..92c543fdeb2d2 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -11,7 +11,7 @@ #ifndef ALICEO2_HMPID_GEO_H #define ALICEO2_HMPID_GEO_H -//#include "Rtypes.h" +#include namespace o2 { @@ -62,8 +62,9 @@ class Geo static constexpr int N_HMPIDTOTALPADS = MAXEQUIPMENTS * N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; - void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); - void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); + static void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); + static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); + static Int_t GetPad(int Equi, int Colu, int Dilo, int Chan); // from //static constexpr Bool_t FEAWITHMASKS[NSECTORS] = diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index de4c9cea63ff4..e82d63fa5f5b9 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -17,6 +17,33 @@ using namespace o2::hmpid; ClassImp(o2::hmpid::Digit); +void Digit::getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge) +{ + float localX; + float localY; + chamber = hit.GetDetectorID(); + double tmp[3] = {hit.GetX(), hit.GetY(), hit.GetZ()}; + Param::Instance()->Mars2Lors(chamber, tmp, localX, localY); + Param::Lors2Pad(localX, localY, pc, px, py); + + totalcharge = Digit::QdcTot(hit.GetEnergyLoss(), hit.GetTime(), pc, px, py, localX, localY); +} + +float Digit::getFractionalContributionForPad(HitType const& hit, int somepad) +{ + float localX; + float localY; + + // chamber number is in detID + const auto chamber = hit.GetDetectorID(); + double tmp[3] = {hit.GetX(), hit.GetY(), hit.GetZ()}; + // converting chamber id and hit coordiates to local coordinates + Param::Instance()->Mars2Lors(chamber, tmp, localX, localY); + // calculate charge fraction in given pad + return Digit::InMathieson(localX, localY, somepad); +} + + float Digit::QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY) { // Samples total charge associated to a hit @@ -49,3 +76,40 @@ float Digit::QdcTot(float e, float time, int pc, int px, int py, float& localX, } return Q; } + +float Digit::IntPartMathiX(float x, int pad) +{ + // Integration of Mathieson. + // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603) + // Arguments: x,y- position of the center of Mathieson distribution + // Returns: a charge fraction [0-1] imposed into the pad + auto shift1 = -LorsX(pad) + 0.5 * Param::SizePadX(); + auto shift2 = -LorsX(pad) - 0.5 * Param::SizePadX(); + + auto ux1 = Param::SqrtK3x() * TMath::TanH(Param::K2x() * (x + shift1) / Param::PitchAnodeCathode()); + auto ux2 = Param::SqrtK3x() * TMath::TanH(Param::K2x() * (x + shift2) / o2::hmpid::Param::PitchAnodeCathode()); + + return o2::hmpid::Param::K4x() * (TMath::ATan(ux2) - TMath::ATan(ux1)); +} + + +Double_t Digit::IntPartMathiY(Double_t y, int pad) +{ + // Integration of Mathieson. + // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603) + // Arguments: x,y- position of the center of Mathieson distribution + // Returns: a charge fraction [0-1] imposed into the pad + Double_t shift1 = -LorsY(pad) + 0.5 * o2::hmpid::Param::SizePadY(); + Double_t shift2 = -LorsY(pad) - 0.5 * o2::hmpid::Param::SizePadY(); + + Double_t uy1 = Param::SqrtK3y() * TMath::TanH(Param::K2y() * (y + shift1) / Param::PitchAnodeCathode()); + Double_t uy2 = Param::SqrtK3y() * TMath::TanH(Param::K2y() * (y + shift2) / Param::PitchAnodeCathode()); + + return Param::K4y() * (TMath::ATan(uy2) - TMath::ATan(uy1)); +} + +float Digit::InMathieson(float localX, float localY, int pad) +{ + return 4. * Digit::IntPartMathiX(localX, pad) * Digit::IntPartMathiY(localY, pad); +} + diff --git a/Detectors/HMPID/base/src/Geo.cxx b/Detectors/HMPID/base/src/Geo.cxx index ef6f4a1da7858..6bb41aa916be2 100644 --- a/Detectors/HMPID/base/src/Geo.cxx +++ b/Detectors/HMPID/base/src/Geo.cxx @@ -9,6 +9,7 @@ // or submit itself to any jurisdiction. #include "HMPIDBase/Geo.h" +#include "HMPIDBase/Param.h" #include "TGeoManager.h" #include "TMath.h" #include "FairLogger.h" @@ -72,3 +73,28 @@ void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int } return; } + +//Int_t Geo::GetPad(int eqi, intnt_t row,Int_t dil,Int_t pad) +Int_t Geo::GetPad(int Equi, int Colu, int Dilo, int Chan) +{ + // The method returns the absolute pad number or -1 + // in case the charge from the channels + // has not been read or invalid arguments + + + if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= N_COLUMNS || + Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= N_CHANNELS ) return -1; + + int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) + int ch = Equi / 2; // The Module + + int tmp = (23 - Colu) / N_COLXSEGMENT; + int pc = (Equi % 2) ? 5-2*tmp : 2*tmp; // The PhotoCatode + + int px = (N_DILOGICS+1 - Dilo) * DILOPADSROWS - Chan / DILOPADSCOLS - 1; //flip according to Paolo (2-9-2008) + + tmp = (Equi % 2) ? Colu : (23-Colu); + int py = DILOPADSCOLS * (tmp % DILOPADSROWS)+a2y[Chan % DILOPADSCOLS]; + + return Param::Abs(ch,pc,px,py); +} diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h similarity index 87% rename from Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h rename to Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h index 38bebe8d31d77..bc3444583d634 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h @@ -44,16 +44,16 @@ class HmpidDecodeRawFile: public HmpidDecoder bool setUpStream(void *InpuFileName, long Size); private: - bool getBlockFromStream(int32_t **streamPtr, uint32_t Size); - bool getHeaderFromStream(int32_t **streamPtr); - bool getWordFromStream(int32_t *word); + bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size); + bool getHeaderFromStream(uint32_t **streamPtr); + bool getWordFromStream(uint32_t *word); int fileExists(char *filewithpath); void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); private: FILE *fh; char mInputFile[MAXFILENAMEBUFFER]; - int32_t mFileBuffer[MAXRAWFILEBUFFER]; + uint32_t mFileBuffer[MAXRAWFILEBUFFER]; }; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h similarity index 69% rename from Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.h rename to Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h index 9767a58d1f892..6d9160237e07d 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h @@ -24,7 +24,10 @@ #include #include #include +#include +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" #include "HmpidDecoder.h" namespace o2{ @@ -41,15 +44,30 @@ class HmpidDecodeRawMem: public HmpidDecoder bool setUpStream(void *Buffer, long BufferLen); private: - bool getBlockFromStream(int32_t **streamPtr, uint32_t Size); - bool getHeaderFromStream(int32_t **streamPtr); - bool getWordFromStream(int32_t *word); + bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size); + bool getHeaderFromStream(uint32_t **streamPtr); + bool getWordFromStream(uint32_t *word); void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); private: }; +class HmpidDecodeRawDigit: public HmpidDecodeRawMem +{ + public: + HmpidDecodeRawDigit(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); + HmpidDecodeRawDigit(int numOfEquipments); + ~HmpidDecodeRawDigit(); + + vector mDigits; + + private: + void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + + +}; + } } #endif /* COMMON_HMPIDDECODERAWFILE_H_ */ diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h similarity index 78% rename from Detectors/HMPID/reconstruction/src/HmpidDecoder.h rename to Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index f01a58962d54a..a1935caae561d 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -59,7 +59,7 @@ class HmpidDecoder static char sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT]; public: - int mHeEvent; + uint64_t mHeEvent; int mHeBusy; int mNumberWordToRead; int mPayloadTail; @@ -89,11 +89,13 @@ class HmpidDecoder int mHeORBIT; int mHeTType; - int32_t *mActualStreamPtr; - int32_t *mEndStreamPtr; - int32_t *mStartStreamPtr; + uint32_t *mActualStreamPtr; + uint32_t *mEndStreamPtr; + uint32_t *mStartStreamPtr; + int mRDHSize; + int mRDHAcceptedVersion; - // Methods + // Methods public: HmpidDecoder(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); HmpidDecoder(int numOfEquipments); @@ -121,6 +123,8 @@ class HmpidDecoder int getEquipmentIndex(int CruID, int LinkId); int getEquipmentID(int CruId, int LinkId); + void decodePage(uint32_t **streamBuffer); + void decodePageFast(uint32_t **streamBuf); bool decodeBuffer(); bool decodeBufferFast(); @@ -139,23 +143,24 @@ class HmpidDecoder float getAverageBusyTime(int Equipment); protected: - int checkType(int32_t wp, int *p1, int *p2, int *p3, int *p4); - bool isRowMarker(int32_t wp, int *Err, int *rowSize, int *mark); - bool isSegmentMarker(int32_t wp, int *Err, int *segSize, int *Seg, int *mark); - bool isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge); - bool isEoEmarker(int32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize); - int decodeHeader(int32_t *streamPtrAdr, int *EquipIndex); + int checkType(uint32_t wp, int *p1, int *p2, int *p3, int *p4); + bool isRowMarker(uint32_t wp, int *Err, int *rowSize, int *mark); + bool isSegmentMarker(uint32_t wp, int *Err, int *segSize, int *Seg, int *mark); + bool isEoEmarker(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize); + public: bool decodeHmpidError(int ErrorField, char *outbuf); void dumpHmpidError(int ErrorField); + bool isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge); + int decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex); HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); void updateStatistics(HmpidEquipment *eq); - + protected: virtual void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) = 0; - virtual bool getBlockFromStream(int32_t **streamPtr, uint32_t Size) = 0; - virtual bool getHeaderFromStream(int32_t **streamPtr) = 0; - virtual bool getWordFromStream(int32_t *word) = 0; - int32_t* getActualStreamPtr() + virtual bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size) = 0; + virtual bool getHeaderFromStream(uint32_t **streamPtr) = 0; + virtual bool getWordFromStream(uint32_t *word) = 0; + uint32_t* getActualStreamPtr() { return (mActualStreamPtr); } diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h similarity index 99% rename from Detectors/HMPID/reconstruction/src/HmpidEquipment.h rename to Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h index aa324ea9c2fa9..920a502eccc1a 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidEquipment.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h @@ -93,7 +93,7 @@ class HmpidEquipment int mErrorsCounter; int mErrorPadsPerEvent; - int mEventNumber; + uint64_t mEventNumber; int mNumberOfEvents; float mEventSizeAverage; int mEventSize; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx index 3c1c30b592fd0..e828bc629e6c1 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx @@ -18,7 +18,7 @@ /* ------ HISTORY --------- */ -#include "HmpidDecodeRawFile.h" +#include "HMPIDReconstruction/HmpidDecodeRawFile.h" using namespace o2::hmpid; @@ -60,13 +60,13 @@ bool HmpidDecodeRawFile::setUpStream(void *FileName, long Size) strcpy(mInputFile, (const char*) FileName); // files section ---- if (!fileExists(mInputFile)) { - ILOG(ERROR) << "The input file " << mInputFile << " does not exist at this time." << FairLogger::endl; + LOG(ERROR) << "The input file " << mInputFile << " does not exist at this time." << FairLogger::endl; throw TH_FILENOTEXISTS; } // open the file fh = fopen(mInputFile, "rb"); if (fh == 0) { - ILOG(ERROR) << "ERROR to open Input file ! [" << mInputFile << "]" << FairLogger::endl; + LOG(ERROR) << "ERROR to open Input file ! [" << mInputFile << "]" << FairLogger::endl; throw TH_OPENFILE; } @@ -87,7 +87,7 @@ bool HmpidDecodeRawFile::setUpStream(void *FileName, long Size) /// @param[in] Size : not used /// @returns True if the file is opened /// @throws TH_WRONGFILELEN Thrown if the file doesn't contains enough words -bool HmpidDecodeRawFile::getBlockFromStream(int32_t **streamPtr, uint32_t Size) +bool HmpidDecodeRawFile::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) { if (Size > MAXRAWFILEBUFFER) return (false); @@ -97,7 +97,7 @@ bool HmpidDecodeRawFile::getBlockFromStream(int32_t **streamPtr, uint32_t Size) } Size = ((mFileBuffer[2] & 0x0000FFFF) / sizeof(int32_t)) - HEADERDIMENSION_W; nr = fread(mFileBuffer+HEADERDIMENSION_W, sizeof(int32_t), Size, fh); - ILOG(DEBUG) << " getBlockFromStream read " << nr << " of " << Size+HEADERDIMENSION_W << " words !" << FairLogger::endl; + LOG(DEBUG) << " getBlockFromStream read " << nr << " of " << Size+HEADERDIMENSION_W << " words !" << FairLogger::endl; if (nr != Size) { throw TH_WRONGFILELEN; } @@ -111,7 +111,7 @@ bool HmpidDecodeRawFile::getBlockFromStream(int32_t **streamPtr, uint32_t Size) /// Reads the Header from the file /// @param[in] **streamPtr : the pointer to the memory buffer /// @returns True if the header is read -bool HmpidDecodeRawFile::getHeaderFromStream(int32_t **streamPtr) +bool HmpidDecodeRawFile::getHeaderFromStream(uint32_t **streamPtr) { bool flag = getBlockFromStream(streamPtr, RAWBLOCKDIMENSION_W); // reads the 8k block mActualStreamPtr += HEADERDIMENSION_W; // Move forward for the first word @@ -121,7 +121,7 @@ bool HmpidDecodeRawFile::getHeaderFromStream(int32_t **streamPtr) /// Read one word from the pre-load buffer /// @param[in] *word : the buffer for the read word /// @returns True every time -bool HmpidDecodeRawFile::getWordFromStream(int32_t *word) +bool HmpidDecodeRawFile::getWordFromStream(uint32_t *word) { *word = *mActualStreamPtr; mActualStreamPtr++; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index c9d39361d9536..607043e94a619 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -18,7 +18,9 @@ /* ------ HISTORY --------- */ -#include "HmpidDecodeRawMem.h" +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDReconstruction/HmpidDecodeRawMem.h" using namespace o2::hmpid; @@ -66,21 +68,21 @@ bool HmpidDecodeRawMem::setUpStream(void *Buffer, long BufferLen) { long wordsBufferLen = BufferLen / (sizeof(int32_t) / sizeof(char)); // Converts the len in words if (Buffer == nullptr) { - ILOG(ERROR) << "Raw data buffer null Pointer ! " << FairLogger::endl; + LOG(ERROR) << "Raw data buffer null Pointer ! "; throw TH_NULLBUFFERPOINTER; } if (wordsBufferLen == 0) { - ILOG(Error) << "Raw data buffer Empty ! " <> 20 == 0xAB0) { @@ -247,7 +251,7 @@ bool HmpidDecoder::isSegmentMarker(int32_t wp, int *Err, int *segSize, int *Seg, *Seg = wp & 0x0000000F; if (*Seg > 3 || *Seg < 1) { - ILOG(INFO) << " Wrong segment Marker Word, bad Number of segment" << *Seg << "!" << FairLogger::endl; + LOG(INFO) << " Wrong segment Marker Word, bad Number of segment" << *Seg << "!"; *Err = true; } return (true); @@ -265,7 +269,7 @@ bool HmpidDecoder::isSegmentMarker(int32_t wp, int *Err, int *segSize, int *Seg, /// @param[out] *Channel : the channel number [0..47] /// @param[out] *Charge : the value of Charge [0..4095] /// @returns True if PAD Word is detected -bool HmpidDecoder::isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge) +bool HmpidDecoder::isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge) { *Err = false; if ((wp & 0x08000000) == 0) { // # this is a pad @@ -274,8 +278,8 @@ bool HmpidDecoder::isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int * *Channel = (wp & 0x0003F000) >> 12; *Charge = (wp & 0x00000FFF); if (*Dilogic > 10 || *Channel > 47 || *Dilogic < 1 || *Col > 24 || *Col < 1) { - ILOG(WARNING) << " Wrong Pad values Col=" << *Col << " Dilogic="<< *Dilogic << \ - " Channel=" << *Channel << " Charge=" << *Charge << FairLogger::endl; + LOG(WARNING) << " Wrong Pad values Col=" << *Col << " Dilogic="<< *Dilogic << \ + " Channel=" << *Channel << " Charge=" << *Charge; *Err = true; } return (true); @@ -291,7 +295,7 @@ bool HmpidDecoder::isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int * /// @param[out] *Dilogic : the dilogic number [1..10] /// @param[out] *Eoesize : the number of words for dilogic /// @returns True if EoE marker is detected -bool HmpidDecoder::isEoEmarker(int32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize) +bool HmpidDecoder::isEoEmarker(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize) { *Err = false; // #EX MASK Raul 0x3803FF80 # ex mask 0xF803FF80 - this is EoE marker 0586800B0 @@ -300,7 +304,7 @@ bool HmpidDecoder::isEoEmarker(int32_t wp, int *Err, int *Col, int *Dilogic, int *Dilogic = (wp & 0x003C0000) >> 18; *Eoesize = (wp & 0x0000007F); if (*Col > 24 || *Dilogic > 10) { - ILOG(INFO) << " EoE size wrong definition. Col=" << *Col << " Dilogic=" << *Dilogic << FairLogger::endl; + LOG(INFO) << " EoE size wrong definition. Col=" << *Col << " Dilogic=" << *Dilogic; *Err = true; } return (true); @@ -341,10 +345,12 @@ bool HmpidDecoder::decodeHmpidError(int ErrorField, char *outbuf) /// @param[out] *EquipIndex : the Index to the Equipment Object Array [0..13] /// @returns True every time /// @throws TH_WRONGEQUIPINDEX Thrown if the Equipment Index is out of boundary (Equipment not recognized) -int HmpidDecoder::decodeHeader(int32_t *streamPtrAdr, int *EquipIndex) +int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) { - int32_t *buffer = streamPtrAdr; // Sets the pointer to buffer + uint32_t *buffer = streamPtrAdr; // Sets the pointer to buffer + o2::header::RAWDataHeaderV6 *hpt = (o2::header::RAWDataHeaderV6 *)buffer; + /* mHeFEEID = (buffer[0] & 0x000f0000) >> 16; mHeSize = (buffer[0] & 0x0000ff00) >> 8; mHeVer = (buffer[0] & 0x000000ff); @@ -365,6 +371,27 @@ int HmpidDecoder::decodeHeader(int32_t *streamPtrAdr, int *EquipIndex) mHeFirmwareVersion = buffer[12] & 0x0000000f; mHeHmpidError = (buffer[12] & 0x000001F0) >> 4; mHePAR = buffer[13] & 0x0000FFFF; + */ + mHeFEEID = hpt->feeId; + mHeSize = hpt->headerSize; + mHeVer = hpt->version; + mHePrior = hpt->priority; + mHeDetectorID = hpt->sourceID; + mHeOffsetNewPack = hpt->offsetToNext; + mHeMemorySize = hpt->memorySize; + mHeDW = hpt->endPointID; + mHeCruID = hpt->cruID; + mHePackNum = hpt->packetCounter; + mHeLinkNum = hpt->linkID; + mHeBCDI = hpt->bunchCrossing; + mHeORBIT = hpt->orbit; + mHeTType = hpt->triggerType; + mHePageNum = hpt->pageCnt; + mHeStop = hpt->stop; + mHeBusy = (hpt->detectorField & 0xfffffe00) >> 9; + mHeFirmwareVersion = hpt->detectorField & 0x0000000f; + mHeHmpidError = (hpt->detectorField & 0x000001F0) >> 4; + mHePAR = hpt->detectorPAR; *EquipIndex = getEquipmentIndex(mHeCruID, mHeLinkNum); // mEquipment = (*EquipIndex != -1) ? mTheEquipments[*EquipIndex]->getEquipmentId() : -1; @@ -372,19 +399,19 @@ int HmpidDecoder::decodeHeader(int32_t *streamPtrAdr, int *EquipIndex) mNumberWordToRead = ((mHeMemorySize - mHeSize) / sizeof(uint32_t)); mPayloadTail = ((mHeOffsetNewPack - mHeMemorySize) / sizeof(uint32_t)); - // ---- Event ID : Actualy based on ORBIT NUMBER ... - mHeEvent = mHeORBIT; + // ---- Event ID : Actualy based on ORBIT NUMBER and BC + mHeEvent = (mHeORBIT<<12) | mHeBCDI; - ILOG(INFO) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID <<\ - " HeMemorySize=" << mHeMemorySize << " HeOffsetNewPack=" << mHeOffsetNewPack << FairLogger::endl; - ILOG(INFO) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << \ - mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT << FairLogger::endl; - ILOG(INFO) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ - mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR << FairLogger::endl; - ILOG(INFO) << " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail << FairLogger::endl; + LOG(INFO) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID <<\ + " HeMemorySize=" << mHeMemorySize << " HeOffsetNewPack=" << mHeOffsetNewPack; + LOG(INFO) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << \ + mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT; + LOG(INFO) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ + mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR; + LOG(INFO) << " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; if (*EquipIndex == -1) { - ILOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment << FairLogger::endl; + LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; throw TH_WRONGEQUIPINDEX; } return (true); @@ -430,374 +457,396 @@ HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) } eq->mEventSize += mNumberWordToRead * sizeof(uint32_t); // Calculate the size in bytes if (mHeHmpidError != 0) { - ILOG(ERROR) << "HMPID Header reports an error : " << mHeHmpidError << FairLogger::endl; + LOG(ERROR) << "HMPID Header reports an error : " << mHeHmpidError; dumpHmpidError(mHeHmpidError); eq->setError(ERR_HMPID); } return (eq); } -/// --------------- Read Raw Data Buffer --------------- -/// Read the stream, decode the contents and store resuls. -/// ATTENTION : Assumes that the input stream was set -/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header -bool HmpidDecoder::decodeBuffer() +void HmpidDecoder::decodePage(uint32_t **streamBuf) { - // ---------resets the PAdMap----------- - for (int i = 0; i < mNumberOfEquipments; i++) { - mTheEquipments[i]->init(); - mTheEquipments[i]->resetPadMap(); - mTheEquipments[i]->resetErrors(); + int equipmentIndex; + try { + getHeaderFromStream(streamBuf); + } + catch (int e) { + // The stream end ! + LOG(DEBUG) << "End main decoding loop !"; + break; + } + try { + decodeHeader(*streamBuf, &equipmentIndex); + } + catch (int e) { + LOG(ERROR) << "Failed to decode the Header !"; + throw TH_WRONGHEADER; } - int type; - int equipmentIndex = -1; - int isIt; - HmpidEquipment *eq; - int32_t *streamBuf; - ILOG(DEBUG) << "Enter decoding !" << FairLogger::endl; - - // Input Stream Main Loop - while (true) { - try { - getHeaderFromStream(&streamBuf); - } - catch (int e) { - // The stream end ! - ILOG(DEBUG) << "End main decoding loop !" << FairLogger::endl; - break; - } - try { - decodeHeader(streamBuf, &equipmentIndex); - } - catch (int e) { - ILOG(ERROR) << "Failed to decode the Header !" << FairLogger::endl; - throw TH_WRONGHEADER; - } - - eq = evaluateHeaderContents(equipmentIndex); + HmpidEquipment *eq = evaluateHeaderContents(equipmentIndex); - int wpprev = 0; - int wp = 0; - int newOne = true; - int p1, p2, p3, p4; - int error; + uint32_t wpprev = 0; + uint32_t wp = 0; + int newOne = true; + int p1, p2, p3, p4; + int error; + int type; + bool isIt; - int payIndex = 0; - while (payIndex < mNumberWordToRead) { //start the payload loop word by word - if (newOne == true) { - wpprev = wp; - if (!getWordFromStream(&wp)) { // end the stream - break; - } + int payIndex = 0; + while (payIndex < mNumberWordToRead) { //start the payload loop word by word + if (newOne == true) { + wpprev = wp; + if (!getWordFromStream(&wp)) { // end the stream + break; + } - type = checkType(wp, &p1, &p2, &p3, &p4); - if (type == WTYPE_NONE) { - if (eq->mWillBePad == true) { // try to recover the first pad ! - type = checkType((wp & 0xF7FFFFFF), &p1, &p2, &p3, &p4); - if (type == WTYPE_PAD && p3 == 0 && eq->mWordsPerDilogicCounter == 0) { - newOne = false; // # reprocess as pad - continue; - } + type = checkType(wp, &p1, &p2, &p3, &p4); + if (type == WTYPE_NONE) { + if (eq->mWillBePad == true) { // try to recover the first pad ! + type = checkType((wp & 0xF7FFFFFF), &p1, &p2, &p3, &p4); + if (type == WTYPE_PAD && p3 == 0 && eq->mWordsPerDilogicCounter == 0) { + newOne = false; // # reprocess as pad + continue; } - eq->setError(ERR_NOTKNOWN); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_NOTKNOWN] << " [" << wp << "]" << FairLogger::endl; - eq->mWordsPerRowCounter++; - eq->mWordsPerSegCounter++; - payIndex++; - continue; } + eq->setError(ERR_NOTKNOWN); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_NOTKNOWN] << " [" << wp << "]"; + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; + payIndex++; + continue; } + } - if (eq->mWillBeRowMarker == true) { // #shoud be a Row Marker - if (type == WTYPE_ROW) { - eq->mColumnCounter++; - eq->mWordsPerSegCounter++; - eq->mRowSize = p2; - switch (p2) { - case 0: // Empty column - eq->setError(ERR_ROWMARKEMPTY); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKEMPTY] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeRowMarker = true; - break; - case 0x3FF: // Error in column - eq->setError(ERR_ROWMARKERROR); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKERROR] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeRowMarker = true; - break; - case 0x3FE: // Masked column - ILOG(INFO) << "Equip=" << mEquipment << "The column=" << (eq->mSegment) * 8 + eq->mColumnCounter << " is Masked !" << FairLogger::endl; - eq->mWillBeRowMarker = true; - break; - default: - eq->mWillBeRowMarker = false; - eq->mWillBePad = true; - break; - } - newOne = true; - } else { - if (wp == wpprev) { - eq->setError(ERR_DUPLICATEPAD); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - newOne = true; - } else if (type == WTYPE_EOE) { // # Could be a EoE - eq->mColumnCounter++; - eq->setError(ERR_ROWMARKWRONG); - eq->mWillBeRowMarker = false; - eq->mWillBePad = true; - newOne = true; - } else if (type == WTYPE_PAD) { //# Could be a PAD - eq->mColumnCounter++; - eq->setError(ERR_ROWMARKLOST); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeRowMarker = false; - eq->mWillBePad = true; - newOne = true; - } else if (type == WTYPE_EOS) { // # Could be a EoS - eq->mWillBeRowMarker = false; - eq->mWillBeSegmentMarker = true; - newOne = false; - } else { - eq->mColumnCounter++; - eq->setError(ERR_ROWMARKLOST); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; + if (eq->mWillBeRowMarker == true) { // #shoud be a Row Marker + if (type == WTYPE_ROW) { + eq->mColumnCounter++; + eq->mWordsPerSegCounter++; + eq->mRowSize = p2; + switch (p2) { + case 0: // Empty column + eq->setError(ERR_ROWMARKEMPTY); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKEMPTY] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeRowMarker = true; + break; + case 0x3FF: // Error in column + eq->setError(ERR_ROWMARKERROR); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKERROR] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeRowMarker = true; + break; + case 0x3FE: // Masked column + LOG(INFO) << "Equip=" << mEquipment << "The column=" << (eq->mSegment) * 8 + eq->mColumnCounter << " is Masked !"; + eq->mWillBeRowMarker = true; + break; + default: eq->mWillBeRowMarker = false; eq->mWillBePad = true; - newOne = true; - } + break; } - } else if (eq->mWillBePad == true) { // # We expect a pad - //# PAD:0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value - // c = 1..24 d = 1..10 n = 0..47 - if (type == WTYPE_PAD) { + newOne = true; + } else { + if (wp == wpprev) { + eq->setError(ERR_DUPLICATEPAD); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; newOne = true; - if (wp == wpprev) { - eq->setError(ERR_DUPLICATEPAD); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - } else if (p1 != (eq->mSegment * 8 + eq->mColumnCounter)) { // # Manage - // We try to recover the RowMarker misunderstanding - isIt = isRowMarker(wp, &error, &p2, &p1); - if (isIt == true && error == false) { - type = WTYPE_ROW; - newOne = false; - eq->mWillBeEoE = true; - eq->mWillBePad = false; - } else { - ILOG(DEBUG) << "Equip=" << mEquipment << " Mismatch in column" << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mColumnCounter = p1 % 8; - } - } else { - setPad(eq, p1 - 1, p2 - 1, p3, p4); - eq->mWordsPerDilogicCounter++; - eq->mSampleNumber++; - if (p3 == 47) { - eq->mWillBeEoE = true; - eq->mWillBePad = false; - } - } - eq->mWordsPerRowCounter++; - eq->mWordsPerSegCounter++; - } else if (type == WTYPE_EOE) { //# the pads are end ok - eq->mWillBeEoE = true; - eq->mWillBePad = false; + } else if (type == WTYPE_EOE) { // # Could be a EoE + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKWRONG); + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } else if (type == WTYPE_PAD) { //# Could be a PAD + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKLOST); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } else if (type == WTYPE_EOS) { // # Could be a EoS + eq->mWillBeRowMarker = false; + eq->mWillBeSegmentMarker = true; newOne = false; - } else if (type == WTYPE_ROW) { // # We Lost the EoE ! - // We try to recover the PAD misunderstanding - isIt = isPadWord(wp, &error, &p1, &p2, &p3, &p4); + } else { + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKLOST); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } + } + } else if (eq->mWillBePad == true) { // # We expect a pad + //# PAD:0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value + // c = 1..24 d = 1..10 n = 0..47 + if (type == WTYPE_PAD) { + newOne = true; + if (wp == wpprev) { + eq->setError(ERR_DUPLICATEPAD); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + } else if (p1 != (eq->mSegment * 8 + eq->mColumnCounter)) { // # Manage + // We try to recover the RowMarker misunderstanding + isIt = isRowMarker(wp, &error, &p2, &p1); if (isIt == true && error == false) { - type = WTYPE_PAD; - newOne = false; // # reprocess as pad + type = WTYPE_ROW; + newOne = false; + eq->mWillBeEoE = true; + eq->mWillBePad = false; } else { - eq->setError(ERR_LOSTEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeRowMarker = true; + LOG(DEBUG) << "Equip=" << mEquipment << " Mismatch in column" << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mColumnCounter = p1 % 8; + } + } else { + setPad(eq, p1 - 1, p2 - 1, p3, p4); + eq->mWordsPerDilogicCounter++; + eq->mSampleNumber++; + if (p3 == 47) { + eq->mWillBeEoE = true; eq->mWillBePad = false; - newOne = false; } - } else if (type == WTYPE_EOS) { // # We Lost the EoE ! - eq->setError(ERR_LOSTEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeSegmentMarker = true; - eq->mWillBePad = false; - newOne = false; } - } else if (eq->mWillBeEoE == true) { // # We expect a EoE - if (type == WTYPE_EOE) { - eq->mWordsPerRowCounter++; - eq->mWordsPerSegCounter++; - if (wpprev == wp) { - eq->setError(ERR_DOUBLEEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEEOEMARK] << " col=" << p1 << FairLogger::endl; - } else if (p3 != eq->mWordsPerDilogicCounter) { - eq->setError(ERR_WRONGSIZEINEOE); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZEINEOE] << " col=" << p1 << FairLogger::endl; - } - eq->mWordsPerDilogicCounter = 0; - if (p2 == 10) { - if (p1 % 8 != 0) { // # we expect the Row Marker - eq->mWillBeRowMarker = true; - } else { - eq->mWillBeSegmentMarker = true; - } - } else { - eq->mWillBePad = true; - } - eq->mWillBeEoE = false; - newOne = true; - } else if (type == WTYPE_EOS) { // We Lost the EoE ! - eq->setError(ERR_LOSTEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeSegmentMarker = true; - eq->mWillBeEoE = false; - newOne = false; - } else if (type == WTYPE_ROW) { //# We Lost the EoE ! + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; + } else if (type == WTYPE_EOE) { //# the pads are end ok + eq->mWillBeEoE = true; + eq->mWillBePad = false; + newOne = false; + } else if (type == WTYPE_ROW) { // # We Lost the EoE ! + // We try to recover the PAD misunderstanding + isIt = isPadWord(wp, &error, &p1, &p2, &p3, &p4); + if (isIt == true && error == false) { + type = WTYPE_PAD; + newOne = false; // # reprocess as pad + } else { eq->setError(ERR_LOSTEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; eq->mWillBeRowMarker = true; - eq->mWillBeEoE = false; + eq->mWillBePad = false; newOne = false; - } else if (type == WTYPE_PAD) { // # We Lost the EoE ! - int typb, p1b, p2b, p3b, p4b; - typb = checkType((wp | 0x08000000), &p1b, &p2b, &p3b, &p4b); - if (typb == WTYPE_EOE && p3b == 48) { - type = typb; - p1 = p1b; - p2 = p2b; - p3 = p3b; - p4 = p4b; - newOne = false; // # reprocess as EoE - } else { - eq->setError(ERR_LOSTEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBePad = true; - eq->mWillBeEoE = false; - newOne = false; - } } - } else if (eq->mWillBeSegmentMarker == true) { // # We expect a EoSegment + } else if (type == WTYPE_EOS) { // # We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeSegmentMarker = true; + eq->mWillBePad = false; + newOne = false; + } + } else if (eq->mWillBeEoE == true) { // # We expect a EoE + if (type == WTYPE_EOE) { + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; if (wpprev == wp) { - eq->setError(ERR_DOUBLEMARKWORD); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEMARKWORD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - newOne = true; - } else if (type == 2) { - if (abs(eq->mWordsPerSegCounter - p2) > 5) { - eq->setError(ERR_WRONGSIZESEGMENTMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZESEGMENTMARK] << " Seg=" << p2 << FairLogger::endl; + eq->setError(ERR_DOUBLEEOEMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEEOEMARK] << " col=" << p1; + } else if (p3 != eq->mWordsPerDilogicCounter) { + eq->setError(ERR_WRONGSIZEINEOE); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZEINEOE] << " col=" << p1; + } + eq->mWordsPerDilogicCounter = 0; + if (p2 == 10) { + if (p1 % 8 != 0) { // # we expect the Row Marker + eq->mWillBeRowMarker = true; + } else { + eq->mWillBeSegmentMarker = true; } - eq->mWordsPerSegCounter = 0; - eq->mWordsPerRowCounter = 0; - eq->mColumnCounter = 0; - eq->mSegment = p3 % 3; - eq->mWillBeRowMarker = true; - eq->mWillBeSegmentMarker = false; - newOne = true; } else { - eq->setError(ERR_LOSTEOSMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOSMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeSegmentMarker = false; - eq->mWillBeRowMarker = true; + eq->mWillBePad = true; + } + eq->mWillBeEoE = false; + newOne = true; + } else if (type == WTYPE_EOS) { // We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeSegmentMarker = true; + eq->mWillBeEoE = false; + newOne = false; + } else if (type == WTYPE_ROW) { //# We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeRowMarker = true; + eq->mWillBeEoE = false; + newOne = false; + } else if (type == WTYPE_PAD) { // # We Lost the EoE ! + int typb, p1b, p2b, p3b, p4b; + typb = checkType((wp | 0x08000000), &p1b, &p2b, &p3b, &p4b); + if (typb == WTYPE_EOE && p3b == 48) { + type = typb; + p1 = p1b; + p2 = p2b; + p3 = p3b; + p4 = p4b; + newOne = false; // # reprocess as EoE + } else { + eq->setError(ERR_LOSTEOEMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBePad = true; + eq->mWillBeEoE = false; newOne = false; } } - if (newOne) { - payIndex += 1; + } else if (eq->mWillBeSegmentMarker == true) { // # We expect a EoSegment + if (wpprev == wp) { + eq->setError(ERR_DOUBLEMARKWORD); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEMARKWORD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + newOne = true; + } else if (type == 2) { + if (abs(eq->mWordsPerSegCounter - p2) > 5) { + eq->setError(ERR_WRONGSIZESEGMENTMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZESEGMENTMARK] << " Seg=" << p2; + } + eq->mWordsPerSegCounter = 0; + eq->mWordsPerRowCounter = 0; + eq->mColumnCounter = 0; + eq->mSegment = p3 % 3; + eq->mWillBeRowMarker = true; + eq->mWillBeSegmentMarker = false; + newOne = true; + } else { + eq->setError(ERR_LOSTEOSMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOSMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeSegmentMarker = false; + eq->mWillBeRowMarker = true; + newOne = false; } } - for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail - getWordFromStream(&wp); - } - } // this is the end of stream - - // cycle in order to update info for the last event - for (int i = 0; i < mNumberOfEquipments; i++) { - if (mTheEquipments[i]->mNumberOfEvents > 0) { - updateStatistics(mTheEquipments[i]); + if (newOne) { + payIndex += 1; } } - return (true); + for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail + getWordFromStream(&wp); + } } -/// ---------- Read Raw Data Buffer with Fast Decoding ---------- +/// --------------- Read Raw Data Buffer --------------- /// Read the stream, decode the contents and store resuls. -/// Fast alghoritm : no parsing of control words ! /// ATTENTION : Assumes that the input stream was set /// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header -bool HmpidDecoder::decodeBufferFast() +bool HmpidDecoder::decodeBuffer() { // ---------resets the PAdMap----------- for (int i = 0; i < mNumberOfEquipments; i++) { mTheEquipments[i]->init(); mTheEquipments[i]->resetPadMap(); + mTheEquipments[i]->resetErrors(); } int type; int equipmentIndex = -1; int isIt; HmpidEquipment *eq; - int32_t *streamBuf; - ILOG(DEBUG) << "Enter FAST decoding !" << FairLogger::endl; + uint32_t *streamBuf; + LOG(DEBUG) << "Enter decoding !"; // Input Stream Main Loop while (true) { try { - getHeaderFromStream(&streamBuf); + decodePage(&streamBuf); } catch (int e) { - // The stream end ! - ILOG(DEBUG) << "End main decoding loop !" << FairLogger::endl; + LOG(DEBUG) << "End main buffer decoding loop !"; break; } - try { - decodeHeader(streamBuf, &equipmentIndex); - } - catch (int e) { - ILOG(ERROR) << "Failed to decode the Header !" << FairLogger::endl; - throw TH_WRONGHEADER; + } // this is the end of stream + + // cycle in order to update info for the last event + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->mNumberOfEvents > 0) { + updateStatistics(mTheEquipments[i]); } + } + return (true); +} + +void HmpidDecoder::decodePageFast(uint32_t **streamBuf) +{ + int equipmentIndex; + try { + getHeaderFromStream(streamBuf); + } + catch (int e) { + // The stream end ! + LOG(DEBUG) << "End Fast Page decoding loop !"; + break; + } + try { + decodeHeader(*streamBuf, &equipmentIndex); + } + catch (int e) { + LOG(ERROR) << "Failed to decode the Header !"; + throw TH_WRONGHEADER; + } - eq = evaluateHeaderContents(equipmentIndex); + HmpidEquipment *eq = evaluateHeaderContents(equipmentIndex); - int wpprev = 0; - int wp = 0; - int newOne = true; - int p1, p2, p3, p4; - int error; + uint32_t wpprev = 0; + uint32_t wp = 0; + int newOne = true; + int Column, Dilogic, Channel, Charge; + int error; - int payIndex = 0; - while (payIndex < mNumberWordToRead) { //start the payload loop word by word - wpprev = wp; - if (!getWordFromStream(&wp)) { // end the stream - break; - } - if (wp == wpprev) { - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - } else { - if( isPadWord(wp, &error, &p1, &p2, &p3, &p4) == true) { - if( error != false) { - setPad(eq, p1 - 1, p2 - 1, p3, p4); - eq->mSampleNumber++; - } + int payIndex = 0; + while (payIndex < mNumberWordToRead) { //start the payload loop word by word + wpprev = wp; + if (!getWordFromStream(&wp)) { // end the stream + break; + } + if (wp == wpprev) { + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << Column << "]"; + } else { + if( isPadWord(wp, &error, &Column, &Dilogic, &Channel, &Charge) == true) { + if( error != false) { + setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); + eq->mSampleNumber++; } } - payIndex += 1; } - for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail - getWordFromStream(&wp); + payIndex += 1; + } + for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail + getWordFromStream(&wp); + } + return; +} +/// ---------- Read Raw Data Buffer with Fast Decoding ---------- +/// Read the stream, decode the contents and store resuls. +/// Fast alghoritm : no parsing of control words ! +/// ATTENTION : Assumes that the input stream was set +/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header +bool HmpidDecoder::decodeBufferFast() +{ + // ---------resets the PAdMap----------- + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i]->init(); + mTheEquipments[i]->resetPadMap(); + } + + uint32_t *streamBuf; + LOG(DEBUG) << "Enter FAST decoding !"; + + // Input Stream Main Loop + while (true) { + try { + decodePageFast(&streamBuf); + } + catch(int e) { + LOG(DEBUG) << " End Buffer Fast Decoding !"; + break; } } // this is the end of stream @@ -984,7 +1033,7 @@ void HmpidDecoder::dumpHmpidError(int ErrorField) { char printbuf[MAXHMPIDERRORS * MAXDESCRIPTIONLENGHT]; if (decodeHmpidError(ErrorField, printbuf) == true) { - ILOG(ERROR) << "HMPID Error field = " << ErrorField << " : " << printbuf << FairLogger::endl; + LOG(ERROR) << "HMPID Error field = " << ErrorField << " : " << printbuf; } return; } diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx index fc442cc92be1b..d752f96165e2a 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx @@ -18,7 +18,7 @@ /* ------ HISTORY --------- */ -#include "HmpidEquipment.h" +#include "HMPIDReconstruction/HmpidEquipment.h" using namespace o2::hmpid; diff --git a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx index d9b8dfe5f9c48..0a70d3c28851b 100644 --- a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx +++ b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx @@ -110,8 +110,11 @@ void HMPIDDigitizer::process(std::vector const& hits, std::v } } else { // create digit ... and register - mDigits.emplace_back(mCurrentTriggerTime, pad, totalQ * fraction); - mIndexForPad[pad] = mDigits.size() - 1; +int Orbit = 1; +int Bc = 1; +// mDigits.emplace_back(mCurrentTriggerTime, pad, totalQ * fraction); + mDigits.emplace_back(Orbit, Bc, pad, totalQ * fraction); + mIndexForPad[pad] = mDigits.size() - 1; mInvolvedPads.emplace_back(pad); if (mRegisteredLabelContainer) { diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index fc1da045c6742..c57603fd16363 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -19,12 +19,28 @@ #define O2_MCH_DATADECODERSPEC_H_ #include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" namespace o2 { namespace hmpid { + class DataDecoderTask : public Task + { + public: + DataDecoderTask() = default; + ~DataDecoderTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + void decodeTF(framework::ProcessingContext& pc); + + private: + o2::hmpid::HmpidDecodeRawDigit *mDeco; + // vector mDigits; + + }; + o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec = "TF:HMP/RAWDATA"); //o2::framework::DataProcessorSpec getDecodingSpec(); } // end namespace hmpid diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index d0be3a60eb70e..b37bcc6acf9c0 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include "Framework/CallbackService.h" #include "Framework/ConfigParamRegistry.h" @@ -37,6 +38,8 @@ #include "DPLUtils/DPLRawParser.h" #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDReconstruction/HmpidDecodeRawMem.h" #include "HMPIDWorkflow/DataDecoderSpec.h" namespace o2 @@ -50,50 +53,132 @@ using RDH = o2::header::RDHAny; //======================= // Data decoder -class DataDecoderTask +void DataDecoderTask::init(framework::InitContext& ic) { - public: - //_________________________________________________________________________________________________ - void init(framework::InitContext& ic) - { - /* SampaChannelHandler channelHandler; - RdhHandler rdhHandler; + mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); + mDeco->init(); + + + return; +} + +void DataDecoderTask::run(framework::ProcessingContext& pc) +{ + mDeco->mDigits.clear(); - auto ds2manu = ic.options().get("ds2manu"); - mPrint = ic.options().get("print"); - auto mapCRUfile = ic.options().get("cru-map"); - auto mapFECfile = ic.options().get("fec-map"); + decodeTF(pc); - mDecoder = new DataDecoder(channelHandler, rdhHandler, mapCRUfile, mapFECfile, ds2manu, mPrint); - */ + +// for (auto&& input : pc.inputs()) { +// std::cout << " ******* input " << input.spec->binding << std::endl; + + + LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; + pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + +} + +/* auto& digits = mDecoder->getOutputDigits(); + auto& orbits = mDecoder->getOrbits(); + + if (mPrint) { + for (auto d : digits) { + std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; + } } + // send the output buffer via DPL + size_t digitsSize, orbitsSize; + char* digitsBuffer = createBuffer(digits, digitsSize); + char* orbitsBuffer = createBuffer(orbits, orbitsSize); + + // create the output message + auto freefct = [](void* data, void*) { free(data); }; +// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); +// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); +*/ + //_________________________________________________________________________________________________ - // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder - void decodeTF(framework::ProcessingContext& pc) - { - Printf("*********** In decodeTF **************"); +// the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder +void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) +{ + LOG(INFO) << "*********** In decodeTF **************"); + + // get the input buffer + auto& inputs = pc.inputs(); + DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); + + for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { + uint32_t *theBuffer = (uint32_t *)it.raw(); + mDeco->setUpStream(theBuffer, it.size()+it.offset()); + mDeco->decodePageFast(&theBuffer); + } + /* + int equipmentIndex = -1; + HmpidEquipment *eq; // get the input buffer auto& inputs = pc.inputs(); DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - auto const* rdh = it.get_if(); - auto const* raw = it.raw(); size_t payloadSize = it.size(); - // stampare solo payload - std::cout << " ***** payloadSize = " << payloadSize << std::endl; - - /* if (payloadSize == 0) { + if(payloadSize <= 0) { + LOG(INFO) << "Payload empty"; continue; } - gsl::span buffer(reinterpret_cast(raw), sizeof(RDH) + payloadSize); - mDecoder->decodeBuffer(buffer); - */ + auto const* rdh = it.get_if(); + auto const* raw = it.raw(); + uint32_t* data = (uint32_t*)it.data(); + + try { + mDeco->decodeHeader((uint32_t *)rdh, &equipmentIndex); + } + catch (int e) { + LOG(ERROR) << "Failed to decode the Header !"; + throw TH_WRONGHEADER; + } + eq = mDeco->evaluateHeaderContents(equipmentIndex); + + uint32_t wpprev = 0; + uint32_t wp = 0; + int newOne = true; + int p1, p2, p3, p4; + int error; + + int payIndex = 0; + while (payIndex < mDeco->mNumberWordToRead) { //start the payload loop word by word + wpprev = wp; + wp = *data; data++; + if (wp == wpprev) { + LOG(DEBUG) << "Equip=" << mDeco->mEquipment << mDeco->sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + } else { + if( mDeco->isPadWord(wp, &error, &p1, &p2, &p3, &p4) == true) { + if( error != false) { + eq->setPad(p1 - 1, p2 - 1, p3, p4); + mDigits.push_back(Digit(mDeco->mHeBCDI, mDeco->mHeORBIT, + o2::hmpid::Geo::GetPad(equipmentIndex, p1 - 1, p2 - 1, p3), + p4)); + eq->mSampleNumber++; + } + } + } + payIndex += 1; + } + + LOG(DEBUG) << " ***** payloadSize = " << payloadSize; + } - } + // cycle in order to update info for the last event + for (int i = 0; i < mDeco->mNumberOfEquipments; i++) { + if (mDeco->mTheEquipments[i]->mNumberOfEvents > 0) { + mDeco->updateStatistics(mDeco->mTheEquipments[i]); + } + } +*/ +} //_________________________________________________________________________________________________ // the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow @@ -128,55 +213,25 @@ class DataDecoderTask } */ //_________________________________________________________________________________________________ - void run(framework::ProcessingContext& pc) - { - - decodeTF(pc); - for (auto&& input : pc.inputs()) { - - std::cout << " ******* input " << input.spec->binding << std::endl; - // if (input.spec->binding == "readout") { // solo cout - // decodeReadout(input); - // } - } - -/* auto& digits = mDecoder->getOutputDigits(); - auto& orbits = mDecoder->getOrbits(); - - if (mPrint) { - for (auto d : digits) { - std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; - } - } - // send the output buffer via DPL - size_t digitsSize, orbitsSize; - char* digitsBuffer = createBuffer(digits, digitsSize); - char* orbitsBuffer = createBuffer(orbits, orbitsSize); - - // create the output message - auto freefct = [](void* data, void*) { free(data); }; - // pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); - // pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); - */ - } - - private: - bool mPrint = {false}; -// DataDecoder* mDecoder = {nullptr}; -}; //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) //o2::framework::DataPrecessorSpec getDecodingSpec() { - std::vector inputs; + std::vector inputs; inputs.emplace_back("RAWDATA", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + + std::vector outputs; + outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); + outputs.emplace_back("HMP", "ORBITS", 0, o2::framework::Lifetime::Timeframe); + outputs.emplace_back("HMP", "STATS", 0, o2::framework::Lifetime::Timeframe); + return DataProcessorSpec{ "HMP-DataDecoder", - o2::framework::select(inputSpec.c_str()), - Outputs{OutputSpec{"HMP", "DIGITS", 0, Lifetime::Timeframe}, OutputSpec{"HMP", "ORBITS", 0, Lifetime::Timeframe}}, + inputs, + outputs, AlgorithmSpec{adaptFromTask()}, Options{{"print", VariantType::Bool, false, {"print digits"}}, {"cru-map", VariantType::String, "", {"custom CRU mapping"}}, From f2d7414800fbb21487fd6353ab8f0d6a404c7077 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 18 Jan 2021 17:34:25 +0100 Subject: [PATCH 006/208] MORE WORKFLOWS --- Detectors/HMPID/base/CMakeLists.txt | 5 +- .../HMPID/base/include/HMPIDBase/Digit.h | 2 + Detectors/HMPID/base/src/HMPIDBaseLinkDef.h | 1 + Detectors/HMPID/reconstruction/CMakeLists.txt | 2 +- .../HMPIDReconstruction/HmpidDecodeRawMem.h | 4 +- .../reconstruction/src/HmpidDecodeRawMem.cxx | 4 +- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 6 +- Detectors/HMPID/workflow/CMakeLists.txt | 20 ++- .../include/HMPIDWorkflow/DataDecoderSpec.h | 9 +- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 46 ++++++ .../include/HMPIDWorkflow/RawFileReaderSpec.h | 49 ++++++ .../HMPID/workflow/src/DataDecoderSpec.cxx | 148 +++++------------ .../HMPID/workflow/src/DumpDigitsSpec.cxx | 110 +++++++++++++ .../HMPID/workflow/src/RawFileReaderSpec.cxx | 150 ++++++++++++++++++ .../workflow/src/dump-digits-workflow.cxx | 43 +++++ .../workflow/src/raw-to-digits-workflow.cxx | 1 + .../src/rawfile-to-digits-workflow.cxx | 43 +++++ 17 files changed, 522 insertions(+), 121 deletions(-) create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h create mode 100644 Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/dump-digits-workflow.cxx create mode 100644 Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx diff --git a/Detectors/HMPID/base/CMakeLists.txt b/Detectors/HMPID/base/CMakeLists.txt index 424f49648c968..579e279202b51 100644 --- a/Detectors/HMPID/base/CMakeLists.txt +++ b/Detectors/HMPID/base/CMakeLists.txt @@ -9,11 +9,12 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDBase - SOURCES src/Param.cxx src/Digit.cxx src/Cluster.cxx + SOURCES src/Param.cxx src/Digit.cxx src/Cluster.cxx src/Geo.cxx PUBLIC_LINK_LIBRARIES O2::CommonDataFormat O2::SimulationDataFormat ROOT::Physics) o2_target_root_dictionary(HMPIDBase HEADERS include/HMPIDBase/Param.h include/HMPIDBase/Digit.h - include/HMPIDBase/Cluster.h) + include/HMPIDBase/Cluster.h + include/HMPIDBase/Geo.h) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index be5116f0da64e..644862a0a889b 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -38,6 +38,8 @@ class Digit // convenience conversion to x-y pad coordinates int getPx() const { return Param::A2X(mPad); } int getPy() const { return Param::A2Y(mPad); } + int getPhC() const { return Param::A2P(mPad); } + int getCh() const { return Param::A2C(mPad); } static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); static float getFractionalContributionForPad(HitType const& hit, int somepad); diff --git a/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h b/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h index fc5aa9c380584..ea6c399143946 100644 --- a/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h +++ b/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h @@ -21,5 +21,6 @@ #pragma link C++ class vector < o2::hmpid::Digit> + ; #pragma link C++ class o2::hmpid::HitType + ; #pragma link C++ class vector < o2::hmpid::HitType> + ; +#pragma link C++ class o2::hmpid::Geo + ; #endif diff --git a/Detectors/HMPID/reconstruction/CMakeLists.txt b/Detectors/HMPID/reconstruction/CMakeLists.txt index 346cad9e40c7f..b4ed8db47cec7 100644 --- a/Detectors/HMPID/reconstruction/CMakeLists.txt +++ b/Detectors/HMPID/reconstruction/CMakeLists.txt @@ -9,7 +9,7 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDReconstruction - SOURCES src/Clusterer.cxx + SOURCES src/Clusterer.cxx SOURCES src/HmpidDecoder.cxx src/HmpidDecodeRawMem.cxx src/HmpidEquipment.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDBase O2::HMPIDSimulation) diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h index 6d9160237e07d..0b3d221a1569e 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include "HMPIDBase/Digit.h" #include "HMPIDBase/Geo.h" @@ -60,7 +60,7 @@ class HmpidDecodeRawDigit: public HmpidDecodeRawMem HmpidDecodeRawDigit(int numOfEquipments); ~HmpidDecodeRawDigit(); - vector mDigits; + std::vector mDigits; private: void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 607043e94a619..8d89c773bfc06 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -143,7 +143,7 @@ void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, int /// @param[in] numOfEquipments : the number of equipments to define [1..14] HmpidDecodeRawDigit::HmpidDecodeRawDigit(int numOfEquipments) : - HmpidDecoder(numOfEquipments) + HmpidDecodeRawMem(numOfEquipments) { } @@ -158,7 +158,7 @@ HmpidDecodeRawDigit::HmpidDecodeRawDigit(int numOfEquipments) /// @param[in] *LinkIds : the pointer to the Link ID array HmpidDecodeRawDigit::HmpidDecodeRawDigit(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) : - HmpidDecoder(EqIds, CruIds, LinkIds, numOfEquipments) + HmpidDecodeRawMem(EqIds, CruIds, LinkIds, numOfEquipments) { } diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 7eb5d751901f0..1966abc517308 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -18,7 +18,7 @@ /* ------ HISTORY --------- */ -#include "FairLogger.h" +#include "Framework/Logger.h" #include "Headers/RAWDataHeader.h" #include "HMPIDReconstruction/HmpidDecoder.h" @@ -473,7 +473,7 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) catch (int e) { // The stream end ! LOG(DEBUG) << "End main decoding loop !"; - break; + throw TH_BUFFEREMPTY; } try { decodeHeader(*streamBuf, &equipmentIndex); @@ -781,7 +781,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) catch (int e) { // The stream end ! LOG(DEBUG) << "End Fast Page decoding loop !"; - break; + throw TH_BUFFEREMPTY; } try { decodeHeader(*streamBuf, &equipmentIndex); diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index 6bd41689209b6..bddf7ddaccb1c 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -9,7 +9,11 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDWorkflow - SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx + SOURCES src/DataDecoderSpec.cxx + src/DigitReaderSpec.cxx + src/ClusterizerSpec.cxx + src/RawFileReaderSpec.cxx + src/DumpDigitsSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::DetectorsRaw @@ -19,11 +23,21 @@ o2_add_library(HMPIDWorkflow o2_add_executable(recoworkflow COMPONENT_NAME hmpid - SOURCES src/HMPIDRecoWorkflow.cxx + SOURCES src/HMPIDRecoWorkflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) - o2_add_executable(raw-to-digits-workflow COMPONENT_NAME hmpid SOURCES src/raw-to-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + +o2_add_executable(rawfile-to-digits-workflow + COMPONENT_NAME hmpid + SOURCES src/rawfile-to-digits-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + +o2_add_executable(dump-digits-workflow + COMPONENT_NAME hmpid + SOURCES src/dump-digits-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + \ No newline at end of file diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index c57603fd16363..7b649dbf6fb60 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -21,12 +21,14 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" +#include "HMPIDReconstruction/HmpidDecodeRawMem.h" + namespace o2 { namespace hmpid { - class DataDecoderTask : public Task + class DataDecoderTask : public framework::Task { public: DataDecoderTask() = default; @@ -34,10 +36,11 @@ namespace hmpid void init(framework::InitContext& ic) final; void run(framework::ProcessingContext& pc) final; void decodeTF(framework::ProcessingContext& pc); + void decodeReadout(framework::ProcessingContext& pc); + void decodeRawFile(framework::ProcessingContext& pc); private: - o2::hmpid::HmpidDecodeRawDigit *mDeco; - // vector mDigits; + HmpidDecodeRawDigit *mDeco; }; diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h new file mode 100644 index 0000000000000..800ffc1c08e8d --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -0,0 +1,46 @@ +// 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 DatDecoderSpec.h +/// \author Andrea Ferrero +/// +/// \brief Definition of a data processor to run the raw decoding +/// + +#ifndef O2_MCH_DATADECODERSPEC_H_ +#define O2_MCH_DATADECODERSPEC_H_ + +#include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" + +namespace o2 +{ +namespace hmpid +{ + + class DumpDigitsTask : public framework::Task + { + public: + DumpDigitsTask() = default; + ~DumpDigitsTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + + private: + + }; + +o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec = "HMP/DIGITS"); + +} // end namespace hmpid +} // end namespace o2 + +#endif diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h new file mode 100644 index 0000000000000..1d54d2fedac44 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h @@ -0,0 +1,49 @@ +/* + * RawFilereader.h + * + * Created on: 18 gen 2021 + * Author: fap + */ + +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ + +#include +#include +#include +#include +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/runDataProcessing.h" + +namespace o2 +{ +namespace hmpid +{ + +class RawFileReaderTask : public framework::Task +{ + public: + RawFileReaderTask() = default; + ~RawFileReaderTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + + private: + std::ifstream mInputFile{}; ///< input file +}; + +o2::framework::DataProcessorSpec getRawFileReaderSpec(std::string inputSpec = "HMP/rawfile"); +} // end namespace hmpid +} // end namespace o2 + + + +#endif /* DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ */ diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index b37bcc6acf9c0..b751a476302f6 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -32,6 +32,7 @@ #include "Framework/Output.h" #include "Framework/Task.h" #include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" #include "Headers/RAWDataHeader.h" #include "DetectorsRaw/RDHUtils.h" @@ -67,10 +68,8 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) mDeco->mDigits.clear(); decodeTF(pc); - - -// for (auto&& input : pc.inputs()) { -// std::cout << " ******* input " << input.spec->binding << std::endl; + decodeReadout(pc); + decodeRawFile(pc); LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; @@ -98,121 +97,61 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) */ - //_________________________________________________________________________________________________ +//_________________________________________________________________________________________________ // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) { - LOG(INFO) << "*********** In decodeTF **************"); + LOG(INFO) << "*********** In decodeTF **************"; + // get the input buffer auto& inputs = pc.inputs(); - DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); + DPLRawParser parser(inputs, o2::framework::select("TF:HMP/rawdata")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); } - /* - int equipmentIndex = -1; - HmpidEquipment *eq; - - // get the input buffer - auto& inputs = pc.inputs(); - DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); - - for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - size_t payloadSize = it.size(); - if(payloadSize <= 0) { - LOG(INFO) << "Payload empty"; - continue; - } - - auto const* rdh = it.get_if(); - auto const* raw = it.raw(); - uint32_t* data = (uint32_t*)it.data(); - - try { - mDeco->decodeHeader((uint32_t *)rdh, &equipmentIndex); - } - catch (int e) { - LOG(ERROR) << "Failed to decode the Header !"; - throw TH_WRONGHEADER; - } - eq = mDeco->evaluateHeaderContents(equipmentIndex); - - uint32_t wpprev = 0; - uint32_t wp = 0; - int newOne = true; - int p1, p2, p3, p4; - int error; - - int payIndex = 0; - while (payIndex < mDeco->mNumberWordToRead) { //start the payload loop word by word - wpprev = wp; - wp = *data; data++; - if (wp == wpprev) { - LOG(DEBUG) << "Equip=" << mDeco->mEquipment << mDeco->sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; - } else { - if( mDeco->isPadWord(wp, &error, &p1, &p2, &p3, &p4) == true) { - if( error != false) { - eq->setPad(p1 - 1, p2 - 1, p3, p4); - mDigits.push_back(Digit(mDeco->mHeBCDI, mDeco->mHeORBIT, - o2::hmpid::Geo::GetPad(equipmentIndex, p1 - 1, p2 - 1, p3), - p4)); - eq->mSampleNumber++; - } - } - } - payIndex += 1; - } - - LOG(DEBUG) << " ***** payloadSize = " << payloadSize; - - } - // cycle in order to update info for the last event - for (int i = 0; i < mDeco->mNumberOfEquipments; i++) { - if (mDeco->mTheEquipments[i]->mNumberOfEvents > 0) { - mDeco->updateStatistics(mDeco->mTheEquipments[i]); - } - } -*/ + return; } +//_________________________________________________________________________________________________ +// the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow +void DataDecoderTask::decodeReadout(framework::ProcessingContext& pc) +{ + LOG(INFO) << "*********** In decode readout **************"; - //_________________________________________________________________________________________________ - // the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow -/* void decodeReadout(const o2::framework::DataRef& input) - { - static int nFrame = 1; - // get the input buffer - if (input.spec->binding != "readout") { - return; - } + // get the input buffer + auto& inputs = pc.inputs(); + DPLRawParser parser(inputs, o2::framework::select("HMP/readout")); - const auto* header = o2::header::get(input.header); - if (!header) { - return; - } + for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { + uint32_t *theBuffer = (uint32_t *)it.raw(); + mDeco->setUpStream(theBuffer, it.size()+it.offset()); + mDeco->decodePageFast(&theBuffer); + } + return; +} - auto const* raw = input.payload; - // cout size of payload - std::cout << " payloadSize " << header->payloadSize << std::endl; - //size_t payloadSize = header->payloadSize; +// the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow +void DataDecoderTask::decodeRawFile(framework::ProcessingContext& pc) +{ + LOG(INFO) << "*********** In decode rawfile **************"; - if (mPrint) { - std::cout << nFrame << " payloadSize=" << payloadSize << std::endl; - } - nFrame += 1; - if (payloadSize == 0) { - return; + for (auto&& input : pc.inputs()) { + if (input.spec->binding == "rawfile") { + const auto* header = o2::header::get(input.header); + if (!header) { + return; + } + uint32_t *theBuffer = (uint32_t *)input.payload; + int pagesize = header->payloadSize; + mDeco->setUpStream(theBuffer, pagesize); + mDeco->decodePageFast(&theBuffer); } - - gsl::span buffer(reinterpret_cast(raw), payloadSize); - mDecoder->decodeBuffer(buffer); } -*/ - //_________________________________________________________________________________________________ + return; +} //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) @@ -220,7 +159,9 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("RAWDATA", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); + inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); + inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); @@ -233,10 +174,7 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) inputs, outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"print", VariantType::Bool, false, {"print digits"}}, - {"cru-map", VariantType::String, "", {"custom CRU mapping"}}, - {"fec-map", VariantType::String, "", {"custom FEC mapping"}}, - {"ds2manu", VariantType::Bool, false, {"convert channel numbering from Run3 to Run1-2 order"}}}}; + Options{{"print", VariantType::Bool, false, {"print digits"}}} }; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx new file mode 100644 index 0000000000000..1f75f3291b50b --- /dev/null +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -0,0 +1,110 @@ +// draft +// 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 DatDecoderSpec.cxx +/// \author +/// +/// \brief Implementation of a data processor to run the HMPID raw decoding +/// + +#include +#include +#include +#include +#include +#include +#include + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" + +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" +#include "DPLUtils/DPLRawParser.h" + +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDWorkflow/DumpDigitsSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using namespace o2; +using namespace o2::framework; +using RDH = o2::header::RDHAny; + +//======================= +// Data decoder +void DumpDigitsTask::init(framework::InitContext& ic) +{ + + return; +} + +void DumpDigitsTask::run(framework::ProcessingContext& pc) +{ + + LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; + + for (auto&& input : pc.inputs()) { + if (input.spec->binding == "DIGITS") { + const auto* header = o2::header::get(input.header); + if (!header) { + return; + } + std::vector*theDigits = (std::vector*)input.payload; + + for(o2::hmpid::Digit Dig : *theDigits) { + std::cout << Dig.getOrbit() << "," << Dig.getBC() << "," << Dig.getPadID() << + " (" << Dig.getCh() << "," << Dig.getPhC() << "," << Dig.getPx() << "," << Dig.getPy() << ") =" << + Dig.getCharge() << std::endl; + } + + } + } + + + + + +} + +//_________________________________________________________________________________________________ +o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) +//o2::framework::DataPrecessorSpec getDecodingSpec() +{ + + std::vector inputs; + inputs.emplace_back("DIGITS", o2::header::gDataOriginHMP, "DIGITS_VECT", 0, Lifetime::Timeframe); + + std::vector outputs; + + + return DataProcessorSpec{ + "HMP-DataDecoder", + inputs, + outputs, + AlgorithmSpec{adaptFromTask()}, + Options{{"print", VariantType::Bool, false, {"print digits"}}} }; +} + +} // namespace hmpid +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx b/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx new file mode 100644 index 0000000000000..b120571fbd4fa --- /dev/null +++ b/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx @@ -0,0 +1,150 @@ +// 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 RawFileReaderSpec.cxx +/// \author Antonio Franco +/// +/// \brief This is an executable that reads a data file from disk and sends the individual CRU pages via DPL. +/// +/// This is an executable that reads a data file from disk and sends the individual CRU pages via the Data Processing Layer. +// + +#include +#include +#include +#include +#include +#include +#include + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" + + +#include "DPLUtils/DPLRawParser.h" +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" + +#include "HMPIDWorkflow/RawFileReaderSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using RDH = o2::header::RDHAny; +using namespace o2; +using namespace o2::framework; + + +void RawFileReaderTask::init(framework::InitContext& ic) +{ + // Get the input file and other options from the context + LOG(INFO) << "Raw file reader Init"; + + auto inputFileName = ic.options().get("infile"); + mInputFile.open(inputFileName, std::ios::binary); + if (!mInputFile.is_open()) { + throw std::invalid_argument("Cannot open input file \"" + inputFileName + "\""); + } + + // define the callback to close the file + auto stop = [this]() { + LOG(INFO) << "stop file reader"; + this->mInputFile.close(); + }; + ic.services().get().set(CallbackService::Id::Stop, stop); +} + +//_________________________________________________________________________________________________ +void RawFileReaderTask::run(framework::ProcessingContext& pc) +{ + // send one RDH block via DPL + RDH rdh; + char* buf{nullptr}; + size_t bufSize{0}; + + while (true) { + + // read the next RDH, stop if no more data is available + mInputFile.read((char*)(&rdh), sizeof(RDH)); + if (mInputFile.fail()) { + pc.services().get().endOfStream(); + return; // probably reached eof + } + + // check that the RDH version is ok (only RDH versions from 4 to 6 are supported at the moment) + auto rdhVersion = o2::raw::RDHUtils::getVersion(rdh); + auto rdhHeaderSize = o2::raw::RDHUtils::getHeaderSize(rdh); + if (rdhVersion != 6 || rdhHeaderSize != 64) { + return; + } + + // get the frame size from the RDH offsetToNext field + auto frameSize = o2::raw::RDHUtils::getOffsetToNext(rdh); + + // stop if the frame size is too small + if (frameSize < rdhHeaderSize) { + LOG(WARNING) << " FrameSize too small: " << frameSize; + pc.services().get().endOfStream(); + return; + } + + // allocate the output buffer + buf = (char*)realloc(buf, frameSize); + if (buf == nullptr) { + LOG(ERROR) << " Failed to allocate buffer"; + pc.services().get().endOfStream(); + return; + } + + // copy the RDH into the output buffer + memcpy(buf, &rdh, rdhHeaderSize); + + // read the frame payload into the output buffer + mInputFile.read(buf + rdhHeaderSize, frameSize - rdhHeaderSize); + // stop if data cannot be read completely + if (mInputFile.fail()) { + LOG(ERROR) << "Fail to read the payload "; + free(buf); + pc.services().get().endOfStream(); + return; // probably reached eof + } + // create the output message + auto freefct = [](void* data, void* /*hint*/) { free(data); }; + pc.outputs().adoptChunk(Output{"HMP", "rawfile"}, buf, bufSize, freefct, nullptr); + } +} + +//_________________________________________________________________________________________________ +// clang-format off +o2::framework::DataProcessorSpec getRawFileReaderSpec() +{ + return DataProcessorSpec{ + "RawFileReader", + Inputs{}, + Outputs{OutputSpec{"HMP", "rawfile", 0, Lifetime::Timeframe}}, + AlgorithmSpec{adaptFromTask()}, + Options{{"infile", VariantType::String, "", {"input file name"}}} + }; +} +// clang-format on + + +} // end namespace mch +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx new file mode 100644 index 0000000000000..c84533839ce68 --- /dev/null +++ b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx @@ -0,0 +1,43 @@ +// 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 raw-to-digits-workflow.cxx +/// \author Andrea Ferrero +/// +/// \brief This is an executable that runs the decoding via DPL. +/// +/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. +/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow +/// + +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/Task.h" +#include "Framework/runDataProcessing.h" + +#include "HMPIDWorkflow/DumpDigitsSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + DataProcessorSpec consumer = o2::hmpid::getDumpDigitsSpec(); +// DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); + specs.push_back(consumer); +// specs.push_back(consumer); + + return specs; +} diff --git a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx index 462ee37e15521..ea0ee629fcce7 100644 --- a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx @@ -24,6 +24,7 @@ #include "Framework/ControlService.h" #include "Framework/Task.h" #include "Framework/runDataProcessing.h" + #include "HMPIDWorkflow/DataDecoderSpec.h" using namespace o2; diff --git a/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx new file mode 100644 index 0000000000000..52bd546179a25 --- /dev/null +++ b/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx @@ -0,0 +1,43 @@ +// 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 raw-to-digits-workflow.cxx +/// \author Andrea Ferrero +/// +/// \brief This is an executable that runs the decoding via DPL. +/// +/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. +/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow +/// + +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/Task.h" +#include "Framework/runDataProcessing.h" + +#include "HMPIDWorkflow/RawFileReaderSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + DataProcessorSpec producer = o2::hmpid::getRawFileReaderSpec(); +// DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); + specs.push_back(producer); +// specs.push_back(consumer); + + return specs; +} From 289e61621b8110561d19f4d9be0f4078549bcf72 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 19 Jan 2021 10:17:59 +0100 Subject: [PATCH 007/208] Version 0 --- Detectors/HMPID/workflow/CMakeLists.txt | 15 +++----- .../include/HMPIDWorkflow/DataDecoderSpec.h | 4 +- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 4 +- ...ReaderSpec.h => RawFileReaderSpec.h_trash} | 30 +++++++-------- .../HMPID/workflow/src/DataDecoderSpec.cxx | 38 +++++++++++++++++++ ...erSpec.cxx => RawFileReaderSpec.cxx_trash} | 23 +++++++---- ...x => rawfile-to-digits-workflow.cxx_trash} | 0 7 files changed, 78 insertions(+), 36 deletions(-) rename Detectors/HMPID/workflow/include/HMPIDWorkflow/{RawFileReaderSpec.h => RawFileReaderSpec.h_trash} (60%) rename Detectors/HMPID/workflow/src/{RawFileReaderSpec.cxx => RawFileReaderSpec.cxx_trash} (84%) rename Detectors/HMPID/workflow/src/{rawfile-to-digits-workflow.cxx => rawfile-to-digits-workflow.cxx_trash} (100%) diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index bddf7ddaccb1c..0d8f894699251 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -9,11 +9,8 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDWorkflow - SOURCES src/DataDecoderSpec.cxx - src/DigitReaderSpec.cxx - src/ClusterizerSpec.cxx - src/RawFileReaderSpec.cxx - src/DumpDigitsSpec.cxx +# SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/RawFileReaderSpec.cxx src/DumpDigitsSpec.cxx + SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::DetectorsRaw @@ -31,10 +28,10 @@ o2_add_executable(raw-to-digits-workflow SOURCES src/raw-to-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) -o2_add_executable(rawfile-to-digits-workflow - COMPONENT_NAME hmpid - SOURCES src/rawfile-to-digits-workflow.cxx - PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) +#o2_add_executable(rawfile-to-digits-workflow +# COMPONENT_NAME hmpid +# SOURCES src/rawfile-to-digits-workflow.cxx +# PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) o2_add_executable(dump-digits-workflow COMPONENT_NAME hmpid diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index 7b649dbf6fb60..4d09f3ae4b186 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -15,8 +15,8 @@ /// \brief Definition of a data processor to run the raw decoding /// -#ifndef O2_MCH_DATADECODERSPEC_H_ -#define O2_MCH_DATADECODERSPEC_H_ +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index 800ffc1c08e8d..12ff4633986d6 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -15,8 +15,8 @@ /// \brief Definition of a data processor to run the raw decoding /// -#ifndef O2_MCH_DATADECODERSPEC_H_ -#define O2_MCH_DATADECODERSPEC_H_ +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DUMPDIGITSPEC_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DUMPDIGITSPEC_H_ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash similarity index 60% rename from Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h rename to Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash index 1d54d2fedac44..90f252aa0afc1 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash @@ -5,23 +5,23 @@ * Author: fap */ -#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ -#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ -#include -#include +//#include +//#include #include -#include -#include "Framework/CallbackService.h" -#include "Framework/ConfigParamRegistry.h" -#include "Framework/ControlService.h" -#include "Framework/DataProcessorSpec.h" -#include "Framework/Lifetime.h" -#include "Framework/Output.h" +//#include +//#include "Framework/CallbackService.h" +//#include "Framework/ConfigParamRegistry.h" +//#include "Framework/ControlService.h" +//#include "Framework/DataProcessorSpec.h" +//#include "Framework/Lifetime.h" +//#include "Framework/Output.h" #include "Framework/Task.h" -#include "Framework/WorkflowSpec.h" +//#include "Framework/WorkflowSpec.h" #include "Framework/DataProcessorSpec.h" -#include "Framework/runDataProcessing.h" +//#include "Framework/runDataProcessing.h" namespace o2 { @@ -40,10 +40,10 @@ class RawFileReaderTask : public framework::Task std::ifstream mInputFile{}; ///< input file }; -o2::framework::DataProcessorSpec getRawFileReaderSpec(std::string inputSpec = "HMP/rawfile"); +o2::framework::DataProcessorSpec getRawFileReaderSpec(); } // end namespace hmpid } // end namespace o2 -#endif /* DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ */ +#endif /* DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ */ diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index b751a476302f6..9164ed0fe5f71 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -24,6 +24,8 @@ #include #include +#include "TTree.h" + #include "Framework/CallbackService.h" #include "Framework/ConfigParamRegistry.h" #include "Framework/ControlService.h" @@ -75,6 +77,42 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + + float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; + float avgBusyTime[o2::hmpid::Geo::MAXEQUIPMENTS]; + + uint32_t numOfSamples[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + + TTree theObj("t", "HMPID Data Decoding Statistic results"); + + theObj.Branch("Average_Event_Size", avgEventSize,"f[14]"); + theObj.Branch("Average_Busy_Time", avgBusyTime,"f[14]"); + theObj.Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); + theObj.Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); + theObj.Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); + + + int numEqui = mDeco->getNumberOfEquipments(); + for(int e=0;egetAverageEventSize(e); + avgBusyTime[e] = mDeco->getAverageBusyTime(e); + } + for(int m=0; m < o2::hmpid::Geo::N_MODULES; m++) + for(int y=0; y < o2::hmpid::Geo::N_YCOLS; y++) + for(int x=0; x < o2::hmpid::Geo::N_XROWS; x++ ) { + numOfSamples[m][y][x] = mDeco->getPadSamples(m, y, x); + sumOfCharges[m][y][x] = mDeco->getPadSum(m, y, x); + squareOfCharges[m][y][x] = mDeco->getPadSquares(m, y, x); + } + theObj.Fill(); + //t.Write(); + // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); + // mDeco->getChannelSquare(Equipment, Column, Dilogic, Channel); + // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); + pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, theObj); + } /* auto& digits = mDecoder->getOutputDigits(); diff --git a/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx b/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash similarity index 84% rename from Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx rename to Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash index b120571fbd4fa..b87e288dd055e 100644 --- a/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx +++ b/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash @@ -56,8 +56,8 @@ void RawFileReaderTask::init(framework::InitContext& ic) { // Get the input file and other options from the context LOG(INFO) << "Raw file reader Init"; - - auto inputFileName = ic.options().get("infile"); +std::cout << ">>> INIT !" << std::endl; + auto inputFileName = ic.options().get("input-file"); mInputFile.open(inputFileName, std::ios::binary); if (!mInputFile.is_open()) { throw std::invalid_argument("Cannot open input file \"" + inputFileName + "\""); @@ -85,6 +85,7 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) mInputFile.read((char*)(&rdh), sizeof(RDH)); if (mInputFile.fail()) { pc.services().get().endOfStream(); + LOG(INFO) << " Fails to read the header ! "; return; // probably reached eof } @@ -92,9 +93,10 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) auto rdhVersion = o2::raw::RDHUtils::getVersion(rdh); auto rdhHeaderSize = o2::raw::RDHUtils::getHeaderSize(rdh); if (rdhVersion != 6 || rdhHeaderSize != 64) { + LOG(WARNING) << " Wrong RDH (v." << rdhVersion << ", size=" << rdhHeaderSize << ")"; return; } - + std::cout<<"h"; // get the frame size from the RDH offsetToNext field auto frameSize = o2::raw::RDHUtils::getOffsetToNext(rdh); @@ -118,6 +120,7 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) // read the frame payload into the output buffer mInputFile.read(buf + rdhHeaderSize, frameSize - rdhHeaderSize); + std::cout<<"p"; // stop if data cannot be read completely if (mInputFile.fail()) { LOG(ERROR) << "Fail to read the payload "; @@ -127,21 +130,25 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) } // create the output message auto freefct = [](void* data, void* /*hint*/) { free(data); }; - pc.outputs().adoptChunk(Output{"HMP", "rawfile"}, buf, bufSize, freefct, nullptr); + + pc.outputs().make(Output{"HMP","rawfile"},buf, bufSize ); +// pc.outputs().snapshot(Output{"HMP", "rawfile", 0, o2::framework::Lifetime::Timeframe}, buf); +// pc.outputs().adoptChunk(Output{"HMP", "rawfile"}, buf, bufSize, freefct, nullptr); + std::cout<<"w"<()}, - Options{{"infile", VariantType::String, "", {"input file name"}}} - }; + Options{{"input-file", VariantType::String, "", {"input raw file name"}}}}; } // clang-format on diff --git a/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash similarity index 100% rename from Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx rename to Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash From c3205e5321cd5ab171c290f53f2ada70fb411df0 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 21 Jan 2021 10:17:07 +0100 Subject: [PATCH 008/208] V.0 --- .../HMPID/base/include/HMPIDBase/Digit.h | 44 ++++++++-- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 6 +- .../HMPID/base/include/HMPIDBase/Param.h | 25 ++++-- Detectors/HMPID/base/src/Digit.cxx | 81 ++++++++++++++++++- Detectors/HMPID/base/src/Geo.cxx | 24 ------ .../reconstruction/src/HmpidDecodeRawMem.cxx | 5 +- 6 files changed, 136 insertions(+), 49 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 644862a0a889b..35933e26da868 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -26,9 +26,36 @@ namespace hmpid //using DigitBase = o2::dataformats::TimeStamp; class Digit { + public: + + // Conversion functions + static inline uint32_t Abs(int ch, int pc, int x, int y) { return ch << 20 | pc << 16 | x << 8 | y; } + static inline int DDL2C(int ddl) { return ddl >> 1; } //ddl -> chamber + static inline int A2C(uint32_t pad) { return (pad & 0x00F00000) >> 20; } //abs pad -> chamber + static inline int A2P(uint32_t pad) { return (pad & 0x000F0000) >> 16; } //abs pad -> pc + static inline int A2X(uint32_t pad) { return (pad & 0x0000FF00) >> 8; } //abs pad -> pad X + static inline int A2Y(uint32_t pad) { return (pad & 0x000000FF); } //abs pad -> pad Y + static inline uint32_t Photo2Pad(int ch, int pc, int x, int y) { return Abs(ch, pc, x, y); } + static uint32_t Equipment2Pad(int Equi, int Colu, int Dilo, int Chan); + static void Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Chan); + static void Pad2Absolute(uint32_t pad, int *Module, int *x, int *y); + static uint32_t Absolute2Pad(int Module, int x, int y); + static void Pad2Photo(uint32_t pad, int *chamber, int *photo, int *x, int *y); + + // Operators definition ! + inline bool operator<(const Digit& l, const Digit& r) { return l.mPad < r.mPad; }; + inline bool operator==(const Digit& l, const Digit& r) { return l.mPad == r.mPad; }; + inline bool operator> (const Digit& l, const Digit& r){ return r < l; }; + inline bool operator<=(const Digit& l, const Digit& r){ return !(l > r); }; + inline bool operator>=(const Digit& l, const Digit& r){ return !(l < r); }; + inline bool operator!=(const Digit& l, const Digit& r) { return !(l == r); }; + public: Digit() = default; - Digit(int bc, int orbit, int pad, float charge) : mBc(bc), mOrbit(orbit), mPad(pad), mQ(charge) {}; + Digit(int bc, int orbit, int pad, float charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad) {}; + Digit(int bc, int orbit, int chamber, int photo, int x, int y, float charge); + Digit(int bc, int orbit, float charge, int equipment, int column, int dilogic, int channel) ; + Digit(int bc, int orbit, float charge, int module, int x, int y); float getCharge() const { return mQ; } int getPadID() const { return mPad; } @@ -36,10 +63,11 @@ class Digit int getBC() const { return mBc; } // convenience conversion to x-y pad coordinates - int getPx() const { return Param::A2X(mPad); } - int getPy() const { return Param::A2Y(mPad); } - int getPhC() const { return Param::A2P(mPad); } - int getCh() const { return Param::A2C(mPad); } + int getPx() const { return A2X(mPad); } + int getPy() const { return A2Y(mPad); } + int getPhC() const { return A2P(mPad); } + int getCh() const { return A2C(mPad); } + static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); static float getFractionalContributionForPad(HitType const& hit, int somepad); @@ -49,12 +77,12 @@ class Digit private: float mQ = 0.; - int mPad = 0.; // -1 indicates invalid digit + uint32_t mPad = 0.; // -1 indicates invalid digit int mBc = 0.; int mOrbit = 0; - static float LorsX(int pad) { return Param::LorsX(Param::A2P(pad), Param::A2X(pad)); } //center of the pad x, [cm] - static float LorsY(int pad) { return Param::LorsY(Param::A2P(pad), Param::A2Y(pad)); } //center of the pad y, [cm] + static float LorsX(int pad) { return Param::LorsX(A2P(pad), A2X(pad)); } //center of the pad x, [cm] + static float LorsY(int pad) { return Param::LorsY(A2P(pad), A2Y(pad)); } //center of the pad y, [cm] // determines the total charge created by a hit // might modify the localX, localY coordiates associated to the hit diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 92c543fdeb2d2..48b6bed60fdd2 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -57,15 +57,13 @@ class Geo static constexpr int EQUIPMENTSPERMODULE = 2; - static constexpr int N_EQUIPMENTTOTALPADS = N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; static constexpr int N_HMPIDTOTALPADS = MAXEQUIPMENTS * N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; - static void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); - static Int_t GetPad(int Equi, int Colu, int Dilo, int Chan); - + + // from //static constexpr Bool_t FEAWITHMASKS[NSECTORS] = // // TOF sectors with Nino masks: 0, 8, 9, 10, 16 diff --git a/Detectors/HMPID/base/include/HMPIDBase/Param.h b/Detectors/HMPID/base/include/HMPIDBase/Param.h index d94a6c2caee95..18c4de8dce030 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Param.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Param.h @@ -80,9 +80,9 @@ class Param static float SizeAllY() { return fgAllY; } //all PCs size y, [cm] //center of the pad x, [cm] - static float LorsX(Int_t pc, Int_t padx) { return (padx + 0.5) * SizePadX() + fgkMinPcX[pc]; } + static float LorsX(Int_t pc, int padx) { return (padx + 0.5) * SizePadX() + fgkMinPcX[pc]; } //center of the pad y, [cm] - static float LorsY(Int_t pc, Int_t pady) { return (pady + 0.5) * SizePadY() + fgkMinPcY[pc]; } + static float LorsY(Int_t pc, int pady) { return (pady + 0.5) * SizePadY() + fgkMinPcY[pc]; } //PhiMin (degree) of the camber ch float ChPhiMin(Int_t ch) { return Lors2Mars(ch, LorsX(ch, kMinPx) - mX, LorsY(ch, kMinPy) - mY).Phi() * r2d(); } @@ -96,12 +96,21 @@ class Param static void Lors2Pad(float x, float y, Int_t& pc, Int_t& px, Int_t& py); //(x,y)->(pc,px,py) //(ch,pc,padx,pady)-> abs pad - static Int_t Abs(Int_t ch, Int_t pc, Int_t x, Int_t y) { return ch * 100000000 + pc * 1000000 + x * 1000 + y; } - static Int_t DDL2C(Int_t ddl) { return ddl / 2; } //ddl -> chamber - static Int_t A2C(Int_t pad) { return pad / 100000000; } //abs pad -> chamber - static Int_t A2P(Int_t pad) { return pad % 100000000 / 1000000; } //abs pad -> pc - static Int_t A2X(Int_t pad) { return pad % 1000000 / 1000; } //abs pad -> pad X - static Int_t A2Y(Int_t pad) { return pad % 1000; } //abs pad -> pad Y +// static Int_t Abs(Int_t ch, Int_t pc, Int_t x, Int_t y) { return ch * 100000000 + pc * 1000000 + x * 1000 + y; } +// static Int_t DDL2C(Int_t ddl) { return ddl / 2; } //ddl -> chamber +// static Int_t A2C(Int_t pad) { return pad / 100000000; } //abs pad -> chamber +// static Int_t A2P(Int_t pad) { return pad % 100000000 / 1000000; } //abs pad -> pc +// static Int_t A2X(Int_t pad) { return pad % 1000000 / 1000; } //abs pad -> pad X +// static Int_t A2Y(Int_t pad) { return pad % 1000; } //abs pad -> pad Y + + + // Moved in Digit.h + static Int_t Abs(Int_t ch, Int_t pc, Int_t x, Int_t y) { return ch << 20 | pc << 16 | x << 8 | y; } + static Int_t DDL2C(Int_t ddl) { return ddl >> 1; } //ddl -> chamber + static Int_t A2C(Int_t pad) { return (pad & 0x00F00000) >> 20; } //abs pad -> chamber + static Int_t A2P(Int_t pad) { return (pad & 0x000F0000) >> 16; } //abs pad -> pc + static Int_t A2X(Int_t pad) { return (pad & 0x0000FF00) >> 8; } //abs pad -> pad X + static Int_t A2Y(Int_t pad) { return (pad & 0x000000FF); } //abs pad -> pad Y static bool IsOverTh(float q) { return q >= fgThreshold; } //is digit over threshold? diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index e82d63fa5f5b9..87135473d880b 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -9,6 +9,7 @@ // or submit itself to any jurisdiction. #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" #include "HMPIDBase/Param.h" #include "TRandom.h" #include "TMath.h" @@ -17,6 +18,84 @@ using namespace o2::hmpid; ClassImp(o2::hmpid::Digit); +// ----- Constructors ------------ + Digit::Digit(int bc, int orbit, int chamber, int photo, int x, int y, float charge) +{ + mBc = bc; + mOrbit = orbit; + mQ = charge; + mPad = Abs(chamber, photo, x, y); +} + + Digit::Digit(int bc, int orbit, float charge, int equipment, int column, int dilogic, int channel) +{ + mBc = bc; + mOrbit = orbit; + mQ = charge; + mPad = Equipment2Pad(equipment, column, dilogic, channel); +} + + Digit::Digit(int bc, int orbit, float charge, int module, int x, int y) +{ + mBc = bc; + mOrbit = orbit; + mQ = charge; + mPad = Absolute2Pad(module, x, y); +} + +// ----- Coordinate Conversion ---- +uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) +{ + if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || + Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return -1; + + int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) + int ch = Equi / 2; // The Module + int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; + int pc = (Equi % 2) ? 5-2*tmp : 2*tmp; // The PhotoCatode + int px = (Geo::N_DILOGICS+1 - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; + tmp = (Equi % 2) ? Colu : (23-Colu); + int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; + return Abs(ch,pc,px,py); +} + +void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Chan) +{ + int ch, ar, ac; + Pad2Absolute(pad, &ch, &ar, &ac); + Geo::Module2Equipment(ch, ac, ar, Equi, Colu, Dilo, Chan); + return; +} + +uint32_t Digit::Absolute2Pad(int Module, int x, int y) +{ + int ph = (y/Geo::N_COLXSEGMENT)+((x >= Geo::HALFXROWS ) ? 1 : 0); + int px = x % Geo::N_COLXSEGMENT; + int py = y % Geo::HALFXROWS; + return Abs(Module,ph,px,py); +} + +void Digit::Pad2Absolute(uint32_t pad, int *Module, int *x, int *y) +{ + *Module = A2C(pad); + int ph = A2P(pad); + int px = A2X(pad); + int py = A2Y(pad); + *x = (ph % 2 == 0) ? px : (px + Geo::HALFXROWS); + *y = ((ph >> 1) * Geo::N_COLXSEGMENT) + py; + return; +} + +void Digit::Pad2Photo(uint32_t pad, int *chamber, int *photo, int *x, int *y) +{ + *chamber = A2C(pad); + *photo = A2P(pad); + *x = A2X(pad); + *y = A2Y(pad); + return; +} + +// ----- Getter Methods --------- void Digit::getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge) { float localX; @@ -27,6 +106,7 @@ void Digit::getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& Param::Lors2Pad(localX, localY, pc, px, py); totalcharge = Digit::QdcTot(hit.GetEnergyLoss(), hit.GetTime(), pc, px, py, localX, localY); + return; } float Digit::getFractionalContributionForPad(HitType const& hit, int somepad) @@ -43,7 +123,6 @@ float Digit::getFractionalContributionForPad(HitType const& hit, int somepad) return Digit::InMathieson(localX, localY, somepad); } - float Digit::QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY) { // Samples total charge associated to a hit diff --git a/Detectors/HMPID/base/src/Geo.cxx b/Detectors/HMPID/base/src/Geo.cxx index 6bb41aa916be2..8b0957a3e9b1e 100644 --- a/Detectors/HMPID/base/src/Geo.cxx +++ b/Detectors/HMPID/base/src/Geo.cxx @@ -24,7 +24,6 @@ using namespace o2::hmpid; void Geo::Init() { LOG(INFO) << "hmpid::Geo: Initialization of HMPID parameters"; - } // =================== General Purposes HMPID Functions ======================= /// Functions to translate coordinates : from Module,Col,Row to Equipment,Col,Dilogic,Channel @@ -74,27 +73,4 @@ void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int return; } -//Int_t Geo::GetPad(int eqi, intnt_t row,Int_t dil,Int_t pad) -Int_t Geo::GetPad(int Equi, int Colu, int Dilo, int Chan) -{ - // The method returns the absolute pad number or -1 - // in case the charge from the channels - // has not been read or invalid arguments - - - if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= N_COLUMNS || - Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= N_CHANNELS ) return -1; - - int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) - int ch = Equi / 2; // The Module - int tmp = (23 - Colu) / N_COLXSEGMENT; - int pc = (Equi % 2) ? 5-2*tmp : 2*tmp; // The PhotoCatode - - int px = (N_DILOGICS+1 - Dilo) * DILOPADSROWS - Chan / DILOPADSCOLS - 1; //flip according to Paolo (2-9-2008) - - tmp = (Equi % 2) ? Colu : (23-Colu); - int py = DILOPADSCOLS * (tmp % DILOPADSROWS)+a2y[Chan % DILOPADSCOLS]; - - return Param::Abs(ch,pc,px,py); -} diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 8d89c773bfc06..5acef2e4d4799 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -179,10 +179,7 @@ HmpidDecodeRawDigit::~HmpidDecodeRawDigit() void HmpidDecodeRawDigit::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) { eq->setPad(col, dil, ch, charge); - mDigits.push_back(Digit(mHeBCDI, mHeORBIT, - o2::hmpid::Geo::GetPad(eq->getEquipmentId(), col - 1, dil - 1, ch), - charge)); + mDigits.push_back(Digit(mHeBCDI, mHeORBIT, (float)charge, eq->getEquipmentId(), col, dil, ch)); return; } - From 5b7b86872d5f650a8b199aa905f44ccd7be12544 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 21 Jan 2021 11:07:17 +0100 Subject: [PATCH 009/208] Add out_stream operator to DIgit --- Detectors/HMPID/base/include/HMPIDBase/Digit.h | 18 ++++++++++++------ .../HMPID/workflow/src/DumpDigitsSpec.cxx | 8 +++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 35933e26da868..c8a225b3443a3 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -43,12 +43,18 @@ class Digit static void Pad2Photo(uint32_t pad, int *chamber, int *photo, int *x, int *y); // Operators definition ! - inline bool operator<(const Digit& l, const Digit& r) { return l.mPad < r.mPad; }; - inline bool operator==(const Digit& l, const Digit& r) { return l.mPad == r.mPad; }; - inline bool operator> (const Digit& l, const Digit& r){ return r < l; }; - inline bool operator<=(const Digit& l, const Digit& r){ return !(l > r); }; - inline bool operator>=(const Digit& l, const Digit& r){ return !(l < r); }; - inline bool operator!=(const Digit& l, const Digit& r) { return !(l == r); }; + friend inline bool operator<(const Digit& l, const Digit& r) { return l.mPad < r.mPad; }; + friend inline bool operator==(const Digit& l, const Digit& r) { return l.mPad == r.mPad; }; + friend inline bool operator> (const Digit& l, const Digit& r){ return r < l; }; + friend inline bool operator<=(const Digit& l, const Digit& r){ return !(l > r); }; + friend inline bool operator>=(const Digit& l, const Digit& r){ return !(l < r); }; + friend inline bool operator!=(const Digit& l, const Digit& r) { return !(l == r); }; + + friend std::ostream& operator<< (std::ostream& os, const Digit& d) { + os << "[" << A2C(d.mPad) << "," << A2P(d.mPad) << "," << A2X(d.mPad) << "," << + A2Y(d.mPad) << "}@(" << d.mOrbit << "," << d.mBc << ")=" << d.mQ; + return os; + }; public: Digit() = default; diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 1f75f3291b50b..70dfe133428b6 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -71,13 +71,11 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) return; } std::vector*theDigits = (std::vector*)input.payload; - + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; for(o2::hmpid::Digit Dig : *theDigits) { - std::cout << Dig.getOrbit() << "," << Dig.getBC() << "," << Dig.getPadID() << - " (" << Dig.getCh() << "," << Dig.getPhC() << "," << Dig.getPx() << "," << Dig.getPy() << ") =" << - Dig.getCharge() << std::endl; + std::cout << Dig << std::endl; } - + std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } } From 06aa83bc134720572653a1628857d54f6aaf78a6 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sun, 24 Jan 2021 23:44:23 +0100 Subject: [PATCH 010/208] change spec --- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 49 +++++++++++++++++++ .../HMPID/workflow/src/DataDecoderSpec.cxx | 7 +-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 48b6bed60fdd2..85e94dad97dfb 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -17,6 +17,55 @@ namespace o2 { namespace hmpid { + +/* ------------------ HMPID Detector Coordinate definition ------------------- + + 143 .-------------. .-------------. 0 ------.------ 23 + | | |.-----.-----.| | | --> | + | | || | || | | 0 9 | + | | || 4 | 5 || | | Dil. | + ^ | | || | || | | | | ^ + | | | ||_____|_____|| | | | | | + | | | |.-----.-----.| | | | | | + Y | | || | || | | | + | | | || 2 | 3 || Column | n | n+1 | Column + | | | || | || | | | + | | ||_____|_____|| | | | | | + | | 47 ^ |.-----.-----.| | | | | | + | | | || | || V | | | | + | | Y || 0 | 1 || | Dil. | | + | | | || | || | 9 0 | | + | | 0 ||_____|_____|| | <-- | | + 0 .-------------. ------------- 23 ------.------ 0 + 0 --X--> 159 0 -X->79 + + Pad(Module,x,y) Pad(Chamber,PhotoCat,x,y) Pad(Equipment,Column,Dilogic,Channel) + + Equipment n Equipment n+1 + + 143 + ^ + | 40 32 24 16 08 00 07 15 23 31 39 47 + | 41 33 25 17 09 01 06 14 22 30 38 46 + 42 34 26 18 10 02 05 13 21 29 37 45 + y 43 35 27 19 11 03 04 12 20 28 36 44 (Column,Dil.) + 44 36 28 20 12 04 03 11 19 27 35 43 + | 45 37 29 21 13 05 02 10 18 26 34 42 + | 46 38 30 22 14 06 01 09 17 25 33 41 + 47 39 31 23 15 07 00 08 16 24 32 40 + 0 + + + 0 --------- x ------> 79 80 ------ x -----------> 159 + + For Equipment n : x = 79 - (Dilo * 8 + Chan / 8) + y = 143 - (Column * 6 + Chan % 6) + + For Equipment n+1 : x = 80 + (Dilo * 8 + Chan / 8) + y = Column * 6 + Chan % 6 + + + --------------------------------------------------------------------------- */ /// \class Geo /// \brief HMPID detector geometry (only statics) class Geo diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 9164ed0fe5f71..ce10af1fd03ab 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -197,9 +197,10 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); - inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); - inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); + inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); +// inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); +// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); +// inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); From 201da6c38748ee4522a4a278a492db6abc6bdc44 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 09:27:03 +0100 Subject: [PATCH 011/208] StfBuilder ... II attempt --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index ce10af1fd03ab..f25ae02021b3e 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -144,7 +144,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) // get the input buffer auto& inputs = pc.inputs(); - DPLRawParser parser(inputs, o2::framework::select("TF:HMP/rawdata")); + DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); @@ -161,7 +161,8 @@ void DataDecoderTask::decodeReadout(framework::ProcessingContext& pc) // get the input buffer auto& inputs = pc.inputs(); - DPLRawParser parser(inputs, o2::framework::select("HMP/readout")); + DPLRawParser parser(inputs, o2::framework::select("readout:HMP/RAWDATA")); +// DPLRawParser parser(inputs, o2::framework::select("HMP/readout")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); @@ -197,9 +198,10 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + inputs.emplace_back("TF", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); + inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); std::vector outputs; From bf980e29e59a3695473e6ae1551328951b520c9f Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 10:05:15 +0100 Subject: [PATCH 012/208] 1 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index f25ae02021b3e..ce652769b260c 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -70,8 +70,8 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) mDeco->mDigits.clear(); decodeTF(pc); - decodeReadout(pc); - decodeRawFile(pc); +// decodeReadout(pc); +// decodeRawFile(pc); LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; From 4d87168d8e34baf140b76797573dca260ba0b5ac Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 10:15:55 +0100 Subject: [PATCH 013/208] 2 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 70dfe133428b6..6a129765e206f 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -91,7 +91,7 @@ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("DIGITS", o2::header::gDataOriginHMP, "DIGITS_VECT", 0, Lifetime::Timeframe); + inputs.emplace_back("DIGITS", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); std::vector outputs; From 8333a4958aa184aa71a6f75d59b601df72bb58fa Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 10:54:08 +0100 Subject: [PATCH 014/208] 3 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index ce652769b260c..1213226455d63 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -58,8 +58,10 @@ using RDH = o2::header::RDHAny; // Data decoder void DataDecoderTask::init(framework::InitContext& ic) { - mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); - mDeco->init(); + + LOG(INFO) << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !"; + mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); + mDeco->init(); return; From 8ca4e550fa4369fb26ae68a94832c70897bd5023 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 10:59:20 +0100 Subject: [PATCH 015/208] 4 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 1213226455d63..dcf2974115cbc 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -60,6 +60,8 @@ void DataDecoderTask::init(framework::InitContext& ic) { LOG(INFO) << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !"; + std::cout << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !" << std::endl; + mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); mDeco->init(); @@ -77,6 +79,8 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; + std::cout << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..." << std::endl; + pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); @@ -142,6 +146,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) { LOG(INFO) << "*********** In decodeTF **************"; + std::cout << "*********** In decodeTF **************" << std::endl; // get the input buffer @@ -152,6 +157,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) uint32_t *theBuffer = (uint32_t *)it.raw(); mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); + std::cout << "." ; } return; } From f44a4bae207f87dd1ef714db8caabbf6afd20721 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 11:40:47 +0100 Subject: [PATCH 016/208] 5 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index dcf2974115cbc..7745764168826 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -209,7 +209,7 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) inputs.emplace_back("TF", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); - inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); +// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); std::vector outputs; From cd5bc926c4e5db26b1b34856c9fd2468ad40833f Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 12:02:28 +0100 Subject: [PATCH 017/208] 6 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 7745764168826..f21e17a8388ef 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -206,7 +206,10 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("TF", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); +// inputs.emplace_back("TF", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + + inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); + // inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); From 17a41d0f6a0408cf1577bd44520be950d776a91b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 12:34:11 +0100 Subject: [PATCH 018/208] Fix the Equipment decodinf from FEE-ID field --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 1966abc517308..10819367ea2c4 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -395,7 +395,7 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) *EquipIndex = getEquipmentIndex(mHeCruID, mHeLinkNum); // mEquipment = (*EquipIndex != -1) ? mTheEquipments[*EquipIndex]->getEquipmentId() : -1; - mEquipment = mHeFEEID; + mEquipment = mHeFEEID & 0x000F; mNumberWordToRead = ((mHeMemorySize - mHeSize) / sizeof(uint32_t)); mPayloadTail = ((mHeOffsetNewPack - mHeMemorySize) / sizeof(uint32_t)); From 0e4859afefc7afa0685d52c4bf94c4d27aff43b1 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 12:40:42 +0100 Subject: [PATCH 019/208] 1 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 10819367ea2c4..f810378a2c85a 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -408,7 +408,7 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT; LOG(INFO) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR; - LOG(INFO) << " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; + LOG(INFO) << " EquIdx = "<<*EquipIndex<< " Event = "<< mHeEvent<< " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; if (*EquipIndex == -1) { LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; From ec4ebf357145fa321184b15c79da1a4d31eb83af Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 12:55:53 +0100 Subject: [PATCH 020/208] 2 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 10 +++++----- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index f810378a2c85a..c95599e66d838 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -780,14 +780,14 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) } catch (int e) { // The stream end ! - LOG(DEBUG) << "End Fast Page decoding loop !"; + LOG(INFO) << "End Fast Page decoding loop !"; throw TH_BUFFEREMPTY; } try { decodeHeader(*streamBuf, &equipmentIndex); } catch (int e) { - LOG(ERROR) << "Failed to decode the Header !"; + LOG(INFO) << "Failed to decode the Header !"; throw TH_WRONGHEADER; } @@ -806,7 +806,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) break; } if (wp == wpprev) { - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + LOG(INFO) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ "[" << Column << "]"; } else { if( isPadWord(wp, &error, &Column, &Dilogic, &Channel, &Charge) == true) { @@ -837,7 +837,7 @@ bool HmpidDecoder::decodeBufferFast() } uint32_t *streamBuf; - LOG(DEBUG) << "Enter FAST decoding !"; + LOG(INFO) << "Enter FAST decoding !"; // Input Stream Main Loop while (true) { @@ -845,7 +845,7 @@ bool HmpidDecoder::decodeBufferFast() decodePageFast(&streamBuf); } catch(int e) { - LOG(DEBUG) << " End Buffer Fast Decoding !"; + LOG(INFO) << " End Buffer Fast Decoding !"; break; } } // this is the end of stream diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index f21e17a8388ef..1bf2ee4fcff0a 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -146,7 +146,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) { LOG(INFO) << "*********** In decodeTF **************"; - std::cout << "*********** In decodeTF **************" << std::endl; + // std::cout << "*********** In decodeTF **************" << std::endl; // get the input buffer @@ -157,7 +157,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) uint32_t *theBuffer = (uint32_t *)it.raw(); mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); - std::cout << "." ; + std::cout << "Decode parser loop ..." ; } return; } From 28d08ac8bfbf3c5ac30b40eb4744cef22b848d7f Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 13:03:54 +0100 Subject: [PATCH 021/208] 4 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index c95599e66d838..859ade5a913b7 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -414,6 +414,7 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; throw TH_WRONGEQUIPINDEX; } + std::cout << "HMPID ! Exit decode header" << std::endl; return (true); } From 287488a94aa4d32fc46633ebda63a0caf00c53a9 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 13:09:16 +0100 Subject: [PATCH 022/208] 6 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 859ade5a913b7..0bf9740ec5e94 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -444,6 +444,7 @@ void HmpidDecoder::updateStatistics(HmpidEquipment *eq) /// @returns the Pointer to the modified Equipment object HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) { + std::cout << "Enter evaluateHeaderContents.."; HmpidEquipment *eq = mTheEquipments[EquipmentIndex]; if (mHeEvent != eq->mEventNumber) { // Is a new event if (eq->mEventNumber != -1) { // skip the first @@ -458,10 +459,11 @@ HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) } eq->mEventSize += mNumberWordToRead * sizeof(uint32_t); // Calculate the size in bytes if (mHeHmpidError != 0) { - LOG(ERROR) << "HMPID Header reports an error : " << mHeHmpidError; + LOG(INFO) << "HMPID Header reports an error : " << mHeHmpidError; dumpHmpidError(mHeHmpidError); eq->setError(ERR_HMPID); } + std::cout << ".. end evaluateHeaderContents = " << eq->mEventNumber << std::endl; return (eq); } From d9dacd3263adb79e1a29a7d5b76f7324222a5f48 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 13:15:22 +0100 Subject: [PATCH 023/208] 7 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 5acef2e4d4799..aecc8a512cdf5 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -96,8 +96,10 @@ bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) { *streamPtr = mActualStreamPtr; mActualStreamPtr += Size; - if (mActualStreamPtr > mEndStreamPtr) + if (mActualStreamPtr > mEndStreamPtr) { + std::cout << "Beccato " << std::cout; throw TH_WRONGBUFFERDIM; + } return (true); } From 00f42289d5a855f6787b537a88a20c362aea6fa6 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 14:41:20 +0100 Subject: [PATCH 024/208] 7 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index aecc8a512cdf5..da57649d4b0fd 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -97,7 +97,7 @@ bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) *streamPtr = mActualStreamPtr; mActualStreamPtr += Size; if (mActualStreamPtr > mEndStreamPtr) { - std::cout << "Beccato " << std::cout; + std::cout << "Beccato " << std::endl; throw TH_WRONGBUFFERDIM; } return (true); From 3198d69a99f6c1f36a95abe39bf9079d650a3bb4 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 14:48:05 +0100 Subject: [PATCH 025/208] 8 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 1bf2ee4fcff0a..279f3c1b3eb2a 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -155,9 +155,10 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); + std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset(); mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); - std::cout << "Decode parser loop ..." ; + } return; } From 272221655ebe0582d14e348f7a5f34896b34c122 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 14:58:39 +0100 Subject: [PATCH 026/208] 8 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 2 +- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index da57649d4b0fd..ce415ed110e7c 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -83,7 +83,7 @@ bool HmpidDecodeRawMem::setUpStream(void *Buffer, long BufferLen) mActualStreamPtr = (uint32_t*) Buffer; // sets the pointer to the Buffer mEndStreamPtr = ((uint32_t*) Buffer) + wordsBufferLen; //sets the End of buffer mStartStreamPtr = ((uint32_t*) Buffer); - + std::cout << " setUpStrem : StPtr=" << mStartStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << wordsBufferLen << std::endl; return (true); } diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 279f3c1b3eb2a..359dc6f308cb4 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -155,7 +155,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); - std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset(); + std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); From 22fbb833c6ab79349c13927b1efdb2f89fac29e7 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:05:20 +0100 Subject: [PATCH 027/208] 9 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index ce415ed110e7c..c7ac6931bc819 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -97,6 +97,7 @@ bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) *streamPtr = mActualStreamPtr; mActualStreamPtr += Size; if (mActualStreamPtr > mEndStreamPtr) { + std::cout << " getBlockFromStream : StPtr=" << mActualStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << Size << std::endl; std::cout << "Beccato " << std::endl; throw TH_WRONGBUFFERDIM; } From 4aef686bac545b667782397d41262b37bc440348 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:12:32 +0100 Subject: [PATCH 028/208] 12 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index c7ac6931bc819..5bdef8f897cc5 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -96,10 +96,12 @@ bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) { *streamPtr = mActualStreamPtr; mActualStreamPtr += Size; + std::cout << "."; if (mActualStreamPtr > mEndStreamPtr) { - std::cout << " getBlockFromStream : StPtr=" << mActualStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << Size << std::endl; - std::cout << "Beccato " << std::endl; - throw TH_WRONGBUFFERDIM; +// std::cout << " getBlockFromStream : StPtr=" << mActualStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << Size << std::endl; +// std::cout << "Beccato " << std::endl; +// throw TH_WRONGBUFFERDIM; + return(false); } return (true); } From 90fdb65def90fd8962aa60dde4f9266224322319 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:20:35 +0100 Subject: [PATCH 029/208] fix --- .../HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 3 +-- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 12 ++++++------ Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 5bdef8f897cc5..0627b8fe4b144 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -83,7 +83,7 @@ bool HmpidDecodeRawMem::setUpStream(void *Buffer, long BufferLen) mActualStreamPtr = (uint32_t*) Buffer; // sets the pointer to the Buffer mEndStreamPtr = ((uint32_t*) Buffer) + wordsBufferLen; //sets the End of buffer mStartStreamPtr = ((uint32_t*) Buffer); - std::cout << " setUpStrem : StPtr=" << mStartStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << wordsBufferLen << std::endl; +// std::cout << " setUpStrem : StPtr=" << mStartStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << wordsBufferLen << std::endl; return (true); } @@ -96,7 +96,6 @@ bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) { *streamPtr = mActualStreamPtr; mActualStreamPtr += Size; - std::cout << "."; if (mActualStreamPtr > mEndStreamPtr) { // std::cout << " getBlockFromStream : StPtr=" << mActualStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << Size << std::endl; // std::cout << "Beccato " << std::endl; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 0bf9740ec5e94..15106c48509f5 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -402,11 +402,11 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) // ---- Event ID : Actualy based on ORBIT NUMBER and BC mHeEvent = (mHeORBIT<<12) | mHeBCDI; - LOG(INFO) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID <<\ + LOG(DEBUG) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID <<\ " HeMemorySize=" << mHeMemorySize << " HeOffsetNewPack=" << mHeOffsetNewPack; - LOG(INFO) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << \ + LOG(DEBUG) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << \ mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT; - LOG(INFO) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ + LOG(DEBUG) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR; LOG(INFO) << " EquIdx = "<<*EquipIndex<< " Event = "<< mHeEvent<< " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; @@ -414,7 +414,7 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; throw TH_WRONGEQUIPINDEX; } - std::cout << "HMPID ! Exit decode header" << std::endl; + // std::cout << "HMPID ! Exit decode header" << std::endl; return (true); } @@ -444,7 +444,7 @@ void HmpidDecoder::updateStatistics(HmpidEquipment *eq) /// @returns the Pointer to the modified Equipment object HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) { - std::cout << "Enter evaluateHeaderContents.."; + //std::cout << "Enter evaluateHeaderContents.."; HmpidEquipment *eq = mTheEquipments[EquipmentIndex]; if (mHeEvent != eq->mEventNumber) { // Is a new event if (eq->mEventNumber != -1) { // skip the first @@ -463,7 +463,7 @@ HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) dumpHmpidError(mHeHmpidError); eq->setError(ERR_HMPID); } - std::cout << ".. end evaluateHeaderContents = " << eq->mEventNumber << std::endl; + // std::cout << ".. end evaluateHeaderContents = " << eq->mEventNumber << std::endl; return (eq); } diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 359dc6f308cb4..b10a1e3ec180d 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -155,7 +155,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); - std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; + // std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); From faa8d4945410635bdd8d3898bc8f76e2b5756855 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:28:53 +0100 Subject: [PATCH 030/208] 1 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 0627b8fe4b144..1d111ebe07a36 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -184,6 +184,7 @@ void HmpidDecodeRawDigit::setPad(HmpidEquipment *eq, int col, int dil, int ch, i { eq->setPad(col, dil, ch, charge); mDigits.push_back(Digit(mHeBCDI, mHeORBIT, (float)charge, eq->getEquipmentId(), col, dil, ch)); + std::cout << "."; return; } From 3f102d31af8e2ab07689bdcdca27964d360a5a47 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:36:22 +0100 Subject: [PATCH 031/208] 2 --- .../reconstruction/include/HMPIDReconstruction/HmpidDecoder.h | 1 - Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index a1935caae561d..2cc9b3ff40af9 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -156,7 +156,6 @@ class HmpidDecoder void updateStatistics(HmpidEquipment *eq); protected: virtual void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) = 0; - virtual bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size) = 0; virtual bool getHeaderFromStream(uint32_t **streamPtr) = 0; virtual bool getWordFromStream(uint32_t *word) = 0; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 1d111ebe07a36..45f89ecc43d5f 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -135,6 +135,7 @@ bool HmpidDecodeRawMem::getWordFromStream(uint32_t *word) void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) { eq->setPad(col, dil, ch, charge); + std::cout << ":"; return; } From 722b350ea55ac59c2a0f722860eeae46593346d3 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:43:33 +0100 Subject: [PATCH 032/208] 2 --- .../include/HMPIDReconstruction/HmpidDecoder.h | 2 +- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index 2cc9b3ff40af9..96d59a209d0e4 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -150,7 +150,7 @@ class HmpidDecoder public: bool decodeHmpidError(int ErrorField, char *outbuf); void dumpHmpidError(int ErrorField); - bool isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge); + bool isPadWord(uint32_t wp, bool *Err, int *Col, int *Dilogic, int *Channel, int *Charge); int decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex); HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); void updateStatistics(HmpidEquipment *eq); diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 15106c48509f5..e49142598a43e 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -269,7 +269,7 @@ bool HmpidDecoder::isSegmentMarker(uint32_t wp, int *Err, int *segSize, int *Seg /// @param[out] *Channel : the channel number [0..47] /// @param[out] *Charge : the value of Charge [0..4095] /// @returns True if PAD Word is detected -bool HmpidDecoder::isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge) +bool HmpidDecoder::isPadWord(uint32_t wp, bool *Err, int *Col, int *Dilogic, int *Channel, int *Charge) { *Err = false; if ((wp & 0x08000000) == 0) { // # this is a pad @@ -800,7 +800,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) uint32_t wp = 0; int newOne = true; int Column, Dilogic, Channel, Charge; - int error; + bool pwer; int payIndex = 0; while (payIndex < mNumberWordToRead) { //start the payload loop word by word @@ -812,8 +812,8 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) LOG(INFO) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ "[" << Column << "]"; } else { - if( isPadWord(wp, &error, &Column, &Dilogic, &Channel, &Charge) == true) { - if( error != false) { + if( isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { + if( pwer != false) { setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); eq->mSampleNumber++; } From 5958ffd94e28df0a3ec19f975f7d1e481471b80e Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:50:32 +0100 Subject: [PATCH 033/208] 3 --- .../reconstruction/include/HMPIDReconstruction/HmpidDecoder.h | 2 +- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index 96d59a209d0e4..2cc9b3ff40af9 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -150,7 +150,7 @@ class HmpidDecoder public: bool decodeHmpidError(int ErrorField, char *outbuf); void dumpHmpidError(int ErrorField); - bool isPadWord(uint32_t wp, bool *Err, int *Col, int *Dilogic, int *Channel, int *Charge); + bool isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge); int decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex); HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); void updateStatistics(HmpidEquipment *eq); diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index e49142598a43e..8c139be9b9aec 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -269,7 +269,7 @@ bool HmpidDecoder::isSegmentMarker(uint32_t wp, int *Err, int *segSize, int *Seg /// @param[out] *Channel : the channel number [0..47] /// @param[out] *Charge : the value of Charge [0..4095] /// @returns True if PAD Word is detected -bool HmpidDecoder::isPadWord(uint32_t wp, bool *Err, int *Col, int *Dilogic, int *Channel, int *Charge) +bool HmpidDecoder::isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge) { *Err = false; if ((wp & 0x08000000) == 0) { // # this is a pad From cef886dcbebb0ca3abbb82c6a9d999434aacabdd Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:52:18 +0100 Subject: [PATCH 034/208] 3 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 8c139be9b9aec..5b31d1e7558a9 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -800,7 +800,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) uint32_t wp = 0; int newOne = true; int Column, Dilogic, Channel, Charge; - bool pwer; + int pwer; int payIndex = 0; while (payIndex < mNumberWordToRead) { //start the payload loop word by word From ac9f36d90013897d80568ca47525cf5412f72dde Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:57:10 +0100 Subject: [PATCH 035/208] 4 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 5b31d1e7558a9..8b421796943a4 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -813,6 +813,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) "[" << Column << "]"; } else { if( isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { + std::cout << "."; if( pwer != false) { setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); eq->mSampleNumber++; From aabafe43a19cf649293987e8c7f63183b4bffc0b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:02:23 +0100 Subject: [PATCH 036/208] 1 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 8b421796943a4..05748f7ee3ef3 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -813,8 +813,8 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) "[" << Column << "]"; } else { if( isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { - std::cout << "."; if( pwer != false) { + std::cout << "."; setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); eq->mSampleNumber++; } From 8b397dc81c03ce810e7793da541119a01cfba16e Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:06:11 +0100 Subject: [PATCH 037/208] fix --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 05748f7ee3ef3..788f3732af1e2 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -813,8 +813,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) "[" << Column << "]"; } else { if( isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { - if( pwer != false) { - std::cout << "."; + if( pwer != true) { setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); eq->mSampleNumber++; } From ed0e5f7d5db46feccd0fff6838f43b2a818d8333 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:28:06 +0100 Subject: [PATCH 038/208] try to recover TTree --- .../reconstruction/src/HmpidDecodeRawMem.cxx | 2 -- .../HMPID/workflow/src/DataDecoderSpec.cxx | 27 +++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 45f89ecc43d5f..0627b8fe4b144 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -135,7 +135,6 @@ bool HmpidDecodeRawMem::getWordFromStream(uint32_t *word) void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) { eq->setPad(col, dil, ch, charge); - std::cout << ":"; return; } @@ -185,7 +184,6 @@ void HmpidDecodeRawDigit::setPad(HmpidEquipment *eq, int col, int dil, int ch, i { eq->setPad(col, dil, ch, charge); mDigits.push_back(Digit(mHeBCDI, mHeORBIT, (float)charge, eq->getEquipmentId(), col, dil, ch)); - std::cout << "."; return; } diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index b10a1e3ec180d..245f9c33f37ba 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -91,13 +91,19 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - TTree theObj("t", "HMPID Data Decoding Statistic results"); + TString filename = TString::Format("%s_%06d.root", "test", 1); + LOG(DEBUG) << "opening file " << filename.Data(); + std::unique_ptr mfileOut = nullptr; + mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); - theObj.Branch("Average_Event_Size", avgEventSize,"f[14]"); - theObj.Branch("Average_Busy_Time", avgBusyTime,"f[14]"); - theObj.Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); - theObj.Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); - theObj.Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); + std::unique_ptr theObj; + theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); + + theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); + theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); + theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); + theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); + theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); int numEqui = mDeco->getNumberOfEquipments(); @@ -112,8 +118,13 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) sumOfCharges[m][y][x] = mDeco->getPadSum(m, y, x); squareOfCharges[m][y][x] = mDeco->getPadSquares(m, y, x); } - theObj.Fill(); - //t.Write(); + theObj->Fill(); + + mfileOut->cd(); + theObj->Write(); + theObj.reset(); + mfileOut.reset(); + // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSquare(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); From 400c28e3ec72a6187f66b3b43d263338e8260fa5 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:30:20 +0100 Subject: [PATCH 039/208] 1 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 245f9c33f37ba..d967c64cff5a2 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -125,6 +125,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) theObj.reset(); mfileOut.reset(); + // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSquare(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); From 26c76c1ef2dd880bfdb49e03fb08329486e9d66c Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:48:21 +0100 Subject: [PATCH 040/208] 4 --- .../HMPID/workflow/src/DataDecoderSpec.cxx | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index d967c64cff5a2..5ecba9a0a5867 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -25,6 +25,7 @@ #include #include "TTree.h" +#include #include "Framework/CallbackService.h" #include "Framework/ConfigParamRegistry.h" @@ -65,8 +66,7 @@ void DataDecoderTask::init(framework::InitContext& ic) mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); mDeco->init(); - - return; + return; } void DataDecoderTask::run(framework::ProcessingContext& pc) @@ -91,10 +91,10 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - TString filename = TString::Format("%s_%06d.root", "test", 1); - LOG(DEBUG) << "opening file " << filename.Data(); - std::unique_ptr mfileOut = nullptr; - mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); + // TString filename = TString::Format("%s_%06d.root", "test", 1); + // LOG(DEBUG) << "opening file " << filename.Data(); + // std::unique_ptr mfileOut = nullptr; + // mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); std::unique_ptr theObj; theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); @@ -120,10 +120,10 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) } theObj->Fill(); - mfileOut->cd(); - theObj->Write(); - theObj.reset(); - mfileOut.reset(); +// mfileOut->cd(); +// theObj->Write(); +// theObj.reset(); +// mfileOut.reset(); // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); @@ -131,6 +131,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, theObj); + theObj.reset(); } /* auto& digits = mDecoder->getOutputDigits(); From f02c176609ee9d7b176859ae4a013a8ec3000ef1 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:52:29 +0100 Subject: [PATCH 041/208] 4 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 5ecba9a0a5867..6def0bb9fb450 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -129,7 +129,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSquare(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); - pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, theObj); + pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); theObj.reset(); } From 8b925ae56a60ea00c5cea995e7f76f873191e52c Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:06:33 +0100 Subject: [PATCH 042/208] 3 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 6a129765e206f..39ea4a8964617 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -64,6 +64,9 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; +// auto digits = pc.inputs().get("digits"); +// mPDigits = &digits; + for (auto&& input : pc.inputs()) { if (input.spec->binding == "DIGITS") { const auto* header = o2::header::get(input.header); @@ -91,13 +94,13 @@ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("DIGITS", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); + inputs.emplace_back("digits", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); std::vector outputs; return DataProcessorSpec{ - "HMP-DataDecoder", + "HMP-DigitsDump", inputs, outputs, AlgorithmSpec{adaptFromTask()}, From 36db82fe70e07e2669cc0223c1904b133a408b90 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:11:17 +0100 Subject: [PATCH 043/208] 5 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 39ea4a8964617..553dc67d8b1ca 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -68,7 +68,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) // mPDigits = &digits; for (auto&& input : pc.inputs()) { - if (input.spec->binding == "DIGITS") { + if (input.spec->binding == "digits") { const auto* header = o2::header::get(input.header); if (!header) { return; From 191f6e5c10f3aa0d68d7c233deaa982e6a244e9d Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:12:03 +0100 Subject: [PATCH 044/208] 5 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 553dc67d8b1ca..096d9789101c8 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -68,6 +68,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) // mPDigits = &digits; for (auto&& input : pc.inputs()) { + std::cout << input.spec->binding << std::endl; if (input.spec->binding == "digits") { const auto* header = o2::header::get(input.header); if (!header) { From 3f82942a14f2e71127570f316a8d6d3e74bc7c11 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:21:01 +0100 Subject: [PATCH 045/208] 1 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 096d9789101c8..41cfec18e50da 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -76,7 +76,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) } std::vector*theDigits = (std::vector*)input.payload; std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - for(o2::hmpid::Digit Dig : *theDigits) { + for(o2::hmpid::Digit Dig : theDigits) { std::cout << Dig << std::endl; } std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; From 87800eb44edd14f709b86813f840f5b79396abee Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:30:27 +0100 Subject: [PATCH 046/208] 5 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 41cfec18e50da..5ed9fd78bd35a 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -76,9 +76,10 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) } std::vector*theDigits = (std::vector*)input.payload; std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - for(o2::hmpid::Digit Dig : theDigits) { - std::cout << Dig << std::endl; - } + std::cout << "The size of the vector " << theDigits->size() << std::endl; +// for(o2::hmpid::Digit Dig : *theDigits) { +// std::cout << Dig << std::endl; +// } std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } } From aa309f2189ce56bb047967bb0de2ccaf5c6152bb Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:45:53 +0100 Subject: [PATCH 047/208] 1 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 5ed9fd78bd35a..a208c5e4f4707 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -64,12 +64,16 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; -// auto digits = pc.inputs().get("digits"); -// mPDigits = &digits; + auto digits = pc.inputs().get>("digits"); + const std::vector* mPDigits = &digits; + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + std::cout << "The size of the vector " << mPDigits->size() << std::endl; +/* for (auto&& input : pc.inputs()) { std::cout << input.spec->binding << std::endl; if (input.spec->binding == "digits") { + const auto* header = o2::header::get(input.header); if (!header) { return; @@ -80,6 +84,8 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) // for(o2::hmpid::Digit Dig : *theDigits) { // std::cout << Dig << std::endl; // } + + */ std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } } From bd16ee7c10c4f962b17e2f5006f7a2a424bb05cb Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:48:06 +0100 Subject: [PATCH 048/208] 2 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index a208c5e4f4707..d35e8c4654416 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -85,9 +85,10 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) // std::cout << Dig << std::endl; // } - */ + std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } + */ } From 4e875d00e3f70dcbe3314cbd0f68c7710c2a2900 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:49:38 +0100 Subject: [PATCH 049/208] 2 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index d35e8c4654416..8527ecc94907c 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -88,11 +88,11 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } - */ - } + } + */ } From 4d0b986e642542eee5aa64c0b950124a81a01205 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:59:04 +0100 Subject: [PATCH 050/208] 2 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 8527ecc94907c..a93ede6616284 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -65,9 +65,9 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; auto digits = pc.inputs().get>("digits"); - const std::vector* mPDigits = &digits; +// const std::vector* mPDigits = &digits; std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - std::cout << "The size of the vector " << mPDigits->size() << std::endl; + std::cout << "The size of the vector " << digits.size() << std::endl; /* for (auto&& input : pc.inputs()) { From a559202339191021ccb3ee5f4af50cddaf2dfdfb Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:01:19 +0100 Subject: [PATCH 051/208] 3 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index a93ede6616284..669eb6fde2450 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -63,7 +63,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) { LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; - +return; auto digits = pc.inputs().get>("digits"); // const std::vector* mPDigits = &digits; std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; From e5ac87b911ee6f9503f900315496f71eec5fe2ab Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:03:21 +0100 Subject: [PATCH 052/208] 1 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 669eb6fde2450..2bad129b63a75 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -63,13 +63,13 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) { LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; -return; - auto digits = pc.inputs().get>("digits"); + +// auto digits = pc.inputs().get>("digits"); // const std::vector* mPDigits = &digits; - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - std::cout << "The size of the vector " << digits.size() << std::endl; +// std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; +// std::cout << "The size of the vector " << digits.size() << std::endl; + -/* for (auto&& input : pc.inputs()) { std::cout << input.spec->binding << std::endl; if (input.spec->binding == "digits") { @@ -88,13 +88,7 @@ return; std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } - } - - - */ - - } //_________________________________________________________________________________________________ From c64d1bd23e7311c2e0e4f662fdb1c83a76229419 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:16:12 +0100 Subject: [PATCH 053/208] XX --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 2bad129b63a75..929188f5688e3 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -64,12 +64,12 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; -// auto digits = pc.inputs().get>("digits"); + auto digits = pc.inputs().get>("digits"); // const std::vector* mPDigits = &digits; -// std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; -// std::cout << "The size of the vector " << digits.size() << std::endl; - + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + std::cout << "The size of the vector " << digits.size() << std::endl; +/* for (auto&& input : pc.inputs()) { std::cout << input.spec->binding << std::endl; if (input.spec->binding == "digits") { @@ -89,6 +89,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } } + */ } //_________________________________________________________________________________________________ From 23330c0de659a84c8f18d4429be303350b674902 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:19:30 +0100 Subject: [PATCH 054/208] Work --- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 929188f5688e3..285ec405bf6be 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -65,31 +65,13 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; auto digits = pc.inputs().get>("digits"); -// const std::vector* mPDigits = &digits; std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; std::cout << "The size of the vector " << digits.size() << std::endl; - -/* - for (auto&& input : pc.inputs()) { - std::cout << input.spec->binding << std::endl; - if (input.spec->binding == "digits") { - - const auto* header = o2::header::get(input.header); - if (!header) { - return; - } - std::vector*theDigits = (std::vector*)input.payload; - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - std::cout << "The size of the vector " << theDigits->size() << std::endl; -// for(o2::hmpid::Digit Dig : *theDigits) { -// std::cout << Dig << std::endl; -// } - - - std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; - } + for(o2::hmpid::Digit Dig : digits) { + std::cout << Dig << std::endl; } - */ + std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; + } //_________________________________________________________________________________________________ From c26a6fcb02bd995c32c2582686e6d8d5b5ce26e3 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:26:40 +0100 Subject: [PATCH 055/208] Out Digit per Page --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 6def0bb9fb450..f257191c11659 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -71,7 +71,7 @@ void DataDecoderTask::init(framework::InitContext& ic) void DataDecoderTask::run(framework::ProcessingContext& pc) { - mDeco->mDigits.clear(); +//---- mDeco->mDigits.clear(); decodeTF(pc); // decodeReadout(pc); @@ -79,9 +79,8 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; - std::cout << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..." << std::endl; - pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); +//----- pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; @@ -167,11 +166,15 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { + mDeco->mDigits.clear(); + uint32_t *theBuffer = (uint32_t *)it.raw(); // std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); + pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + } return; } From b7ad62ec2b3e14c8916743c1efe20aa24feeb1bc Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:34:03 +0100 Subject: [PATCH 056/208] try --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index f257191c11659..d00cdba148689 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -173,7 +173,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); - pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + pc.outputs().adoptChunk(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); } return; From 669b94e43a7952b40357283e06a3f8f9b1c6c0f7 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:35:57 +0100 Subject: [PATCH 057/208] This version works, but react to the first chumk ! --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index d00cdba148689..f257191c11659 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -173,7 +173,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); - pc.outputs().adoptChunk(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); } return; From ab9c4d7178206a60abe06d0706f794939807da3e Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 01:10:14 +0100 Subject: [PATCH 058/208] New output skema --- .../include/HMPIDWorkflow/DataDecoderSpec.h | 1 + .../include/HMPIDWorkflow/DumpDigitsSpec.h | 1 + .../HMPID/workflow/src/DataDecoderSpec.cxx | 58 +++++++++---------- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 17 +++--- 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index 4d09f3ae4b186..3e984862e56db 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -38,6 +38,7 @@ namespace hmpid void decodeTF(framework::ProcessingContext& pc); void decodeReadout(framework::ProcessingContext& pc); void decodeRawFile(framework::ProcessingContext& pc); + void endOfStream(framework::EndOfStreamContext& ec); private: HmpidDecodeRawDigit *mDeco; diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index 12ff4633986d6..7255d3d2bbcde 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -33,6 +33,7 @@ namespace hmpid ~DumpDigitsTask() override = default; void init(framework::InitContext& ic) final; void run(framework::ProcessingContext& pc) final; + void endOfStream(framework::EndOfStreamContext& ec) final; private: diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index f257191c11659..d273ce44f38c5 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -77,11 +77,29 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // decodeReadout(pc); // decodeRawFile(pc); +} - LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; +/* auto& digits = mDecoder->getOutputDigits(); + auto& orbits = mDecoder->getOrbits(); -//----- pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + if (mPrint) { + for (auto d : digits) { + std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; + } + } + // send the output buffer via DPL + size_t digitsSize, orbitsSize; + char* digitsBuffer = createBuffer(digits, digitsSize); + char* orbitsBuffer = createBuffer(orbits, orbitsSize); + // create the output message + auto freefct = [](void* data, void*) { free(data); }; +// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); +// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); +*/ +void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) +{ + LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; float avgBusyTime[o2::hmpid::Geo::MAXEQUIPMENTS]; @@ -104,7 +122,6 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); - int numEqui = mDeco->getNumberOfEquipments(); for(int e=0;egetAverageEventSize(e); @@ -124,47 +141,25 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // theObj.reset(); // mfileOut.reset(); - - // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); - // mDeco->getChannelSquare(Equipment, Column, Dilogic, Channel); - // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); - pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); + ec.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); theObj.reset(); + return; } -/* auto& digits = mDecoder->getOutputDigits(); - auto& orbits = mDecoder->getOrbits(); - - if (mPrint) { - for (auto d : digits) { - std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; - } - } - // send the output buffer via DPL - size_t digitsSize, orbitsSize; - char* digitsBuffer = createBuffer(digits, digitsSize); - char* orbitsBuffer = createBuffer(orbits, orbitsSize); - - // create the output message - auto freefct = [](void* data, void*) { free(data); }; -// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); -// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); -*/ - //_________________________________________________________________________________________________ // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) { LOG(INFO) << "*********** In decodeTF **************"; - // std::cout << "*********** In decodeTF **************" << std::endl; - // get the input buffer auto& inputs = pc.inputs(); DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); + auto& digitsV = pc.outputs().make>(Output{"HMP", "DIGITS", 0, Lifetime::Timeframe}); + for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { mDeco->mDigits.clear(); @@ -172,12 +167,15 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) // std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); + for(auto d : mDeco->mDigits) + digitsV.push_back(d); - pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + // pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); } return; } +//pc.outputs().make //_________________________________________________________________________________________________ // the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow void DataDecoderTask::decodeReadout(framework::ProcessingContext& pc) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 285ec405bf6be..7d5d6893bc85c 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -55,25 +55,26 @@ using RDH = o2::header::RDHAny; // Data decoder void DumpDigitsTask::init(framework::InitContext& ic) { - - return; + LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + return; } void DumpDigitsTask::run(framework::ProcessingContext& pc) { - - LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; - auto digits = pc.inputs().get>("digits"); - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; std::cout << "The size of the vector " << digits.size() << std::endl; for(o2::hmpid::Digit Dig : digits) { std::cout << Dig << std::endl; } - std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; - + return; } +void DumpDigitsTask::endOfStream(framework::EndOfStreamContext& ec) +{ + std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; + return; +} //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) //o2::framework::DataPrecessorSpec getDecodingSpec() From a02ed12b1bbf5b7a375f07f337e83ecf94e6841a Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 01:21:05 +0100 Subject: [PATCH 059/208] only size .. --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 7d5d6893bc85c..9d75917f37ced 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -64,9 +64,9 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) { auto digits = pc.inputs().get>("digits"); std::cout << "The size of the vector " << digits.size() << std::endl; - for(o2::hmpid::Digit Dig : digits) { - std::cout << Dig << std::endl; - } +// for(o2::hmpid::Digit Dig : digits) { +// std::cout << Dig << std::endl; +// } return; } From 2cad9e2250acd75ac6ba475db7c6d7d550eb22e3 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 10:28:30 +0100 Subject: [PATCH 060/208] try --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index d273ce44f38c5..1a5e89845387d 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -77,6 +77,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // decodeReadout(pc); // decodeRawFile(pc); + pc.services().get().endOfStream(); } /* auto& digits = mDecoder->getOutputDigits(); @@ -225,10 +226,10 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); -// inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); -// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); +// inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); -// inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); +// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); +// inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); From 90ffb41f6136a9421d077a06470db900dff744cd Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 11:35:48 +0100 Subject: [PATCH 061/208] W1 --- .../include/HMPIDWorkflow/DataDecoderSpec.h | 2 +- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 4 +- .../HMPID/workflow/src/DataDecoderSpec.cxx | 43 ++++++++----------- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 18 ++++---- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index 3e984862e56db..81c701712f141 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -38,7 +38,7 @@ namespace hmpid void decodeTF(framework::ProcessingContext& pc); void decodeReadout(framework::ProcessingContext& pc); void decodeRawFile(framework::ProcessingContext& pc); - void endOfStream(framework::EndOfStreamContext& ec); + private: HmpidDecodeRawDigit *mDeco; diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index 7255d3d2bbcde..2e5fa69cccbbb 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -33,10 +33,10 @@ namespace hmpid ~DumpDigitsTask() override = default; void init(framework::InitContext& ic) final; void run(framework::ProcessingContext& pc) final; - void endOfStream(framework::EndOfStreamContext& ec) final; - private: + private: + bool mPrintDigits = false; }; o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 1a5e89845387d..17afa50b580e1 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -77,29 +77,6 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // decodeReadout(pc); // decodeRawFile(pc); - pc.services().get().endOfStream(); -} - -/* auto& digits = mDecoder->getOutputDigits(); - auto& orbits = mDecoder->getOrbits(); - - if (mPrint) { - for (auto d : digits) { - std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; - } - } - // send the output buffer via DPL - size_t digitsSize, orbitsSize; - char* digitsBuffer = createBuffer(digits, digitsSize); - char* orbitsBuffer = createBuffer(orbits, orbitsSize); - - // create the output message - auto freefct = [](void* data, void*) { free(data); }; -// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); -// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); -*/ -void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) -{ LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; @@ -145,9 +122,27 @@ void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) ec.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); theObj.reset(); - return; + } +/* auto& digits = mDecoder->getOutputDigits(); + auto& orbits = mDecoder->getOrbits(); + + if (mPrint) { + for (auto d : digits) { + std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; + } + } + // send the output buffer via DPL + size_t digitsSize, orbitsSize; + char* digitsBuffer = createBuffer(digits, digitsSize); + char* orbitsBuffer = createBuffer(orbits, orbitsSize); + + // create the output message + auto freefct = [](void* data, void*) { free(data); }; +// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); +// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); +*/ //_________________________________________________________________________________________________ // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 9d75917f37ced..6c184b2ad2bdd 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -56,6 +56,8 @@ using RDH = o2::header::RDHAny; void DumpDigitsTask::init(framework::InitContext& ic) { LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; + mPrintDigits = ic.options().get("print"); + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; return; } @@ -64,17 +66,15 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) { auto digits = pc.inputs().get>("digits"); std::cout << "The size of the vector " << digits.size() << std::endl; -// for(o2::hmpid::Digit Dig : digits) { -// std::cout << Dig << std::endl; -// } - return; -} - -void DumpDigitsTask::endOfStream(framework::EndOfStreamContext& ec) -{ + if (mPrintDigits) { + for(o2::hmpid::Digit Dig : digits) { + std::cout << Dig << std::endl; + } + } std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; return; } + //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) //o2::framework::DataPrecessorSpec getDecodingSpec() @@ -91,7 +91,7 @@ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) inputs, outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"print", VariantType::Bool, false, {"print digits"}}} }; + Options{{"print", VariantType::Bool, false, {"print digits (default false )"}}} }; } } // namespace hmpid From e008884c6e117e9e25502fc1aca68fe1cbd2c8e2 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 11:45:26 +0100 Subject: [PATCH 062/208] fix --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 17afa50b580e1..44e05a4e8cbb4 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -119,7 +119,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // theObj.reset(); // mfileOut.reset(); - ec.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); + pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); theObj.reset(); From fca999d14ad57475e5da057aace2e0d9b052bbbe Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 11:58:03 +0100 Subject: [PATCH 063/208] fix --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 6c184b2ad2bdd..a0e19829b2372 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -56,7 +56,7 @@ using RDH = o2::header::RDHAny; void DumpDigitsTask::init(framework::InitContext& ic) { LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; - mPrintDigits = ic.options().get("print"); + mPrintDigits = ic.options().get("print"); std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; return; From aa601650e2368d0887494844f6ba53a0d1ed744d Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:19:45 +0100 Subject: [PATCH 064/208] first --- .../HMPID/base/include/HMPIDBase/Digit.h | 23 +- Detectors/HMPID/base/src/Digit.cxx | 6 +- .../include/HMPIDSimulation/HmpidCoder.h | 142 ++++++++ Detectors/HMPID/simulation/src/HmpidCoder.cxx | 312 ++++++++++++++++++ .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 47 +++ .../workflow/src/WriteRawFromDigitsSpec.cxx | 116 +++++++ .../src/write-raw-from-digits-workflow.cxx | 43 +++ 7 files changed, 675 insertions(+), 14 deletions(-) create mode 100644 Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h create mode 100644 Detectors/HMPID/simulation/src/HmpidCoder.cxx create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h create mode 100644 Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index c8a225b3443a3..d86c7bab9679f 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -58,15 +58,16 @@ class Digit public: Digit() = default; - Digit(int bc, int orbit, int pad, float charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad) {}; - Digit(int bc, int orbit, int chamber, int photo, int x, int y, float charge); - Digit(int bc, int orbit, float charge, int equipment, int column, int dilogic, int channel) ; - Digit(int bc, int orbit, float charge, int module, int x, int y); + Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad) {}; + Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge); + Digit(uint16_t bc, uint32_t orbit, float uint16_t, int equipment, int column, int dilogic, int channel) ; + Digit(uint16_t bc, uint32_t orbit, float uint16_t, int module, int x, int y); - float getCharge() const { return mQ; } + uint16_t getCharge() const { return mQ; } int getPadID() const { return mPad; } - int getOrbit() const { return mOrbit; } - int getBC() const { return mBc; } + uint32_t getOrbit() const { return mOrbit; } + uint16_t getBC() const { return mBc; } + uint64_t getTriggerID() const { return ((mOrbit << 12) | mBc); } // convenience conversion to x-y pad coordinates int getPx() const { return A2X(mPad); } @@ -82,10 +83,10 @@ class Digit void addCharge(float q) { mQ += q; } private: - float mQ = 0.; - uint32_t mPad = 0.; // -1 indicates invalid digit - int mBc = 0.; - int mOrbit = 0; + uint16_t mQ = 0; + uint32_t mPad = 0; // -1 indicates invalid digit + uint16_t mBc = 0.; + uint32_t mOrbit = 0; static float LorsX(int pad) { return Param::LorsX(A2P(pad), A2X(pad)); } //center of the pad x, [cm] static float LorsY(int pad) { return Param::LorsY(A2P(pad), A2Y(pad)); } //center of the pad y, [cm] diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 87135473d880b..85517ffb0b209 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -19,7 +19,7 @@ using namespace o2::hmpid; ClassImp(o2::hmpid::Digit); // ----- Constructors ------------ - Digit::Digit(int bc, int orbit, int chamber, int photo, int x, int y, float charge) + Digit::Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge) { mBc = bc; mOrbit = orbit; @@ -27,7 +27,7 @@ ClassImp(o2::hmpid::Digit); mPad = Abs(chamber, photo, x, y); } - Digit::Digit(int bc, int orbit, float charge, int equipment, int column, int dilogic, int channel) + Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int column, int dilogic, int channel) { mBc = bc; mOrbit = orbit; @@ -35,7 +35,7 @@ ClassImp(o2::hmpid::Digit); mPad = Equipment2Pad(equipment, column, dilogic, channel); } - Digit::Digit(int bc, int orbit, float charge, int module, int x, int y) + Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, int y) { mBc = bc; mOrbit = orbit; diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h new file mode 100644 index 0000000000000..7e197e821757c --- /dev/null +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h @@ -0,0 +1,142 @@ +// 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 HmpidCoder.h +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to code HMPID Raw Data file +/// + +#ifndef COMMON_HMPIDCODER_H_ +#define COMMON_HMPIDCODER_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include "FairLogger.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDBase/Digit.h" + +// ---- RDH 6 standard dimension ------- +#define RAWBLOCKDIMENSION_W 2048 +#define HEADERDIMENSION_W 16 +#define PAYLOADDIMENSION_W 2032 +#define PAYLOADMAXSPACE_W 2028 + +// ---- CHARGE CONSTANTS ----- +#define CHARGE_CONST 150 +#define CHARGE_RAND_MAX 400 + +namespace o2 { + +namespace hmpid { + +class HmpidCoder +{ + public: + int mVerbose; + int mNumberOfEquipments; + + private: + // The standard definition of HMPID equipments at P2 + const int mEqIds[Geo::MAXEQUIPMENTS] = { 0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13 }; + const int mCruIds[Geo::MAXEQUIPMENTS] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3 }; + const int mLinkIds[Geo::MAXEQUIPMENTS] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2 }; + const int mFlpIds[Geo::MAXEQUIPMENTS] = { 160, 160, 160, 160, 160, 160, 160, 160, 161, 161, 161, 161, 161, 161 }; + + bool mRandomCharge; + bool mRandomOccupancy; + + int mOccupancyPercentage; + + int mPailoadBufferDimPerEquipment; + uint32_t *mPayloadBufferPtr; + uint32_t *mEventBufferPtr; + uint32_t *mEventBufferBasePtr; + int mEventSizePerEquipment[Geo::MAXEQUIPMENTS]; + + FILE *mOutStream160; + FILE *mOutStream161; + + public: + HmpidCoder(int numOfEquipments); + virtual ~HmpidCoder(); + + void init(); + void setVerbosity(int Level) + { + mVerbose = Level; + }; + int getVerbosity() + { + return (mVerbose); + }; + int getNumberOfEquipments() + { + return (mNumberOfEquipments); + }; + + void setChargeRandomize(bool isRandom) + { + mRandomCharge = isRandom; + }; + bool getChargeRandomize() + { + return(mRandomCharge); + }; + + void setOccupancyRandomize(bool isRandom) + { + mRandomOccupancy = isRandom; + }; + bool getOccupancyRandomize() + { + return(mRandomOccupancy); + }; + + void setOccupancy(int Occupancy) + { + mOccupancyPercentage = Occupancy; + }; + int getOccupancy() + { + return(mOccupancyPercentage); + }; + + void openOutputStream(const char *OutputFileName); + void closeOutputStream(); + + void createRandomEvent(uint32_t orbit, uint16_t bc); + void codeDigitsVector(std::vector); + + + protected: + void createRandomPayloadPerEvent(); + void saveEventPage(int Flp); + int calculateNumberOfPads(); + + private: + void getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId); + int getEquipmentPadIndex(int eq, int col, int dil, int cha); + void writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum); + void fillPadsMap(uint32_t *padMap); + void fillTheOutputBuffer(uint32_t* padMap); + void writePaginatedEvent(uint32_t orbit, uint16_t bc); +}; + +} +} + +#endif /* COMMON_HMPIDCODER_H_ */ diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx new file mode 100644 index 0000000000000..0e2cc15971451 --- /dev/null +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -0,0 +1,312 @@ +// 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 HmpidCoder.cxx +/// \author Antonio Franco - INFN Bari +/// \brief Base Class for coding HMPID Raw Data File +/// \version 1.0 +/// \date 24 set 2020 + +#include "HMPIDSimulation/HmpidCoder.h" + +using namespace o2::hmpid; + +HmpidCoder::HmpidCoder(int numOfEquipments) +{ + + mNumberOfEquipments = numOfEquipments; + mVerbose = 0; + mOccupancyPercentage = 0; + mRandomOccupancy = false; + mRandomCharge = false; + mOutStream160 = NULL; + mOutStream161 = NULL; + + mPailoadBufferDimPerEquipment = ((Geo::N_SEGMENTS * (Geo::N_COLXSEGMENT * (Geo::N_DILOGICS * (Geo::N_CHANNELS + 1) + 1) + 1)) + 10); + + mPayloadBufferPtr = (uint32_t *) std::malloc(mNumberOfEquipments * sizeof(uint32_t) * mPailoadBufferDimPerEquipment ); + mEventBufferBasePtr = (uint32_t *) std::malloc(sizeof(uint32_t) * RAWBLOCKDIMENSION_W); + mEventBufferPtr = mEventBufferBasePtr; + srand( (unsigned)time(NULL) ); + +} + +HmpidCoder::~HmpidCoder() +{ + // TODO Auto-generated destructor stub + std::free(mPayloadBufferPtr); + std::free(mEventBufferBasePtr); +} + +// ===================== Random production of Raw Files =================== + +int HmpidCoder::calculateNumberOfPads() +{ +// int numOfEqipments = 0; + int occupancyPercentage = 0; +// for(int i = 0; i < MAXEQUIPMENTS; i++) +// if(mFlpIds[i] == Flp) +// numOfEqipments++; + + if(mRandomOccupancy) { + occupancyPercentage = rand() % 1000; + } else { + occupancyPercentage = mOccupancyPercentage; + } + return( occupancyPercentage * Geo::MAXEQUIPMENTS * Geo::N_EQUIPMENTTOTALPADS / 1000); +} + +void HmpidCoder::fillPadsMap(uint32_t *padMap) +{ + int numberOfpads = calculateNumberOfPads(); + int mo, yc, xr, eq, col, dil, cha; + for (int i = 0; i 0) { + pads[j]++; + rowSize++; + } + } + } + rowSize += Geo::N_DILOGICS; + segSize += (rowSize + 1); + rowMarker = 0x000036A8 | ((rowSize << 16) & 0x03ff0000); + // fills the Payload Buffer + mPayloadBufferPtr[ptr++] = rowMarker; + int col = (s - 1) * Geo::N_COLXSEGMENT + c; + for (int d = 1; d <= Geo::N_DILOGICS; d++) { + for (int p = 0; p < Geo::N_CHANNELS; p++) { + int idx = getEquipmentPadIndex(eq, ((s-1)*Geo::N_COLXSEGMENT+(c-1)), (d-1), p); + if(padMap[idx] > 0) { + padWord = ((col << 22) & 0x07c00000) | ((d << 18) & 0x003C0000) | ((p << 12) & 0x0003F000) + | (padMap[idx] & 0x00000FFF); + mPayloadBufferPtr[ptr++] = padWord; + } + } + eoeMarker = 0x08000080 | ((col << 22) & 0x07c00000) | (d << 18 & 0x003C0000) | (pads[d-1] & 0x0000007F); + mPayloadBufferPtr[ptr++] = eoeMarker; + } + } + segSize += 1; + segMarker = 0xAB000000 | ((segSize << 8) & 0x000fff00) | (s & 0x0000000F); + mPayloadBufferPtr[ptr++] = segMarker; + } + mEventSizePerEquipment[eq] = ptr - startPtr; + } + return; +} + +void HmpidCoder::writePaginatedEvent(uint32_t orbit, uint16_t bc) +{ + int nWordToRead; + int count; + int payloatPtr = 0; + + for (int eq = 0; eq < mNumberOfEquipments; eq++) { + int EventSize = mEventSizePerEquipment[eq]; + int EquipmentCounter = 0; + int numOfPages = EventSize / PAYLOADMAXSPACE_W + 1; + + for (uint32_t PageNum = 1; PageNum <= numOfPages; PageNum++) { + count = 0; + while (count < PAYLOADMAXSPACE_W && EquipmentCounter < EventSize) { + mEventBufferPtr[HEADERDIMENSION_W + count++] = mPayloadBufferPtr[payloatPtr++]; + EquipmentCounter++; + } + nWordToRead = count; + while (count < PAYLOADDIMENSION_W) + mEventBufferPtr[HEADERDIMENSION_W + count++] = 0; + uint32_t MemSize = nWordToRead * sizeof(uint32_t) + HEADERDIMENSION_W * sizeof(uint32_t); + uint32_t PackNum = PageNum; + writeHeader(mEventBufferPtr, MemSize, mEqIds[eq], PackNum, bc, orbit, PageNum); + saveEventPage(mFlpIds[eq]); + } + } + return; +} + +void HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum) +{ + uint32_t CruId, LinkId; + uint32_t TType = 0; + uint32_t HeStop = 0; + uint32_t FirmVers = 9; + uint32_t HeError = 0; + uint32_t Busy = 3000; + uint32_t PAR = 0; + + getEquipCoord(Equip, &CruId, &LinkId); + + // FEEID Header Size Header version + Buffer[0] = 0xFFF00000 | ((Equip & 0x0F) << 16) | 0x00004000 | 0x00000006; + // Priority System ID + Buffer[1] = 0x00000100 | 0x00000006; + // .....Memory Size HeOffsetNewPack; + Buffer[2] = (MemSize << 16) | 0x00002000; + // DW CruId PacNum Link Num + Buffer[3] = 0x10000000 | ((CruId & 0x00FF) << 16) | ((PackNum & 0x0FF) << 8) | (LinkId & 0x0FF); + Buffer[4] = 0x00000FFF & BCDI; + Buffer[5] = ORBIT; + Buffer[6] = 0; + Buffer[7] = 0; + Buffer[8] = TType; + Buffer[9] = ((HeStop & 0x00ff0000) << 16) | (PageNum & 0x0000FFFF); + Buffer[10] = 0; + Buffer[11] = 0; + Buffer[12] = (Busy << 9) | ((HeError & 0x000001F0) << 4) | (FirmVers & 0x0000000f); + Buffer[13] = PAR; + Buffer[14] = 0xAAAA0001; + Buffer[15] = 0xAAAA0001; + return; +} + +void HmpidCoder::codeDigitsVector(std::vectordigits) +{ + uint32_t pv_orbit, orbit = 0; + uint16_t pv_bc, bc = 0; + + uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + int eq,col,dil,cha,mo,x,y, idx; + + for(o2::hmpid::Digit d : digits) { + orbit = d.getOrbit(); + bc = d.getBC(); + if(orbit != pv_orbit || bc != pv_bc) { //the event is changed + if (orbit != 0) { + fillTheOutputBuffer(padMap); + writePaginatedEvent(pv_orbit, pv_bc); + } + memset(padMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + pv_orbit = orbit; + pv_bc = bc; + } + Digit::Pad2Absolute(d.getPadID(), &mo, &x, &y); + Geo::Module2Equipment(mo, y, x, &eq, &col, &dil, &cha); + idx = getEquipmentPadIndex(eq, col, dil, cha); + padMap[idx] = d.getCharge(); + } + fillTheOutputBuffer(padMap); + writePaginatedEvent(pv_orbit, pv_bc); + + std::free(padMap); + return; +} + + +// ====================== FILES management functions ====================== + +void HmpidCoder::saveEventPage(int Flp) +{ + if(Flp == 160) + fwrite(mEventBufferPtr, RAWBLOCKDIMENSION_W, sizeof(uint32_t), mOutStream160); + else + fwrite(mEventBufferPtr, RAWBLOCKDIMENSION_W, sizeof(uint32_t), mOutStream161); + return; +} + +/// @throws TH_CREATEFILE Thrown if Fails to create the file +void HmpidCoder::openOutputStream(const char *OutputFileName) +{ + char FileName[512]; + + sprintf(FileName, "%s%d%s", OutputFileName, 160, ".dat"); + mOutStream160 = fopen(FileName, "wb"); + if (mOutStream160 == 0) { + LOG(ERROR) << "ERROR to open Output file " << FileName; + throw 0; + } + sprintf(FileName, "%s%d%s", OutputFileName, 161, ".dat"); + mOutStream161 = fopen(FileName, "wb"); + if (mOutStream161 == 0) { + LOG(ERROR) << "ERROR to open Output file " << FileName; + throw 0; + } + return; +} + +void HmpidCoder::closeOutputStream() +{ + fclose(mOutStream160); + fclose(mOutStream161); + return; +} diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h new file mode 100644 index 0000000000000..365f45d977bc3 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -0,0 +1,47 @@ +// 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 DatDecoderSpec.h +/// \author Andrea Ferrero +/// +/// \brief Definition of a data processor to run the raw decoding +/// + +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMDIGITS_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMDIGITS_H_ + +#include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" + +namespace o2 +{ +namespace hmpid +{ + + class WriteRawFromDigitsTask : public framework::Task + { + public: + WriteRawFromDigitsTask() = default; + ~WriteRawFromDigitsTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + + + private: + bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); + }; + +o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec = "HMP/DIGITS"); + +} // end namespace hmpid +} // end namespace o2 + +#endif diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx new file mode 100644 index 0000000000000..eabc76d0360ae --- /dev/null +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -0,0 +1,116 @@ +// draft +// 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 DatDecoderSpec.cxx +/// \author +/// +/// \brief Implementation of a data processor to run the HMPID raw decoding +/// + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" + +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" +#include "DPLUtils/DPLRawParser.h" + +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDSimulation/HmpidCoder.h" +#include "HMPIDWorkflow/WriteRawFromDigitsSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using namespace o2; +using namespace o2::framework; +using RDH = o2::header::RDHAny; + +//======================= +// Data decoder +void WriteRawFromDigitsTask::init(framework::InitContext& ic) +{ + LOG(INFO) << "[HMPID Write Raw File From Digits vector - run] Dumping ..."; + + + return; +} + +bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2) +{ + uint64_t t1,t2; + t1 = d1.getTriggerID(); + t2 = d2.getTriggerID(); + + if (t1 < t2) return true; + if (t2 < t1) return false; + + if (d1.getPadID() < d2.getPadID()) return true; + return false; +} + + +void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) +{ + std::vector digits = pc.inputs().get>("digits"); + LOG(INFO) << "The size of the digits vector " << digits.size(); + + sort(digits.begin(), digits.end(), eventEquipPadsComparision); + LOG(INFO) << "Digits sorted ! " ; + + HmpidCoder cod(Geo::MAXEQUIPMENTS); + cod.openOutputStream("pippo"); + cod.codeDigitsVector(digits); + cod.closeOutputStream(); + LOG(INFO) << "Raw File created ! " ; + return; +} + +//_________________________________________________________________________________________________ +o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec) +//o2::framework::DataPrecessorSpec getDecodingSpec() +{ + + std::vector inputs; + inputs.emplace_back("digits", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); + + std::vector outputs; + + + return DataProcessorSpec{ + "HMP-WriteRawFrtomDigits", + inputs, + outputs, + AlgorithmSpec{adaptFromTask()}, + Options{{"print", VariantType::Bool, false, {"print"}}} }; +} + +} // namespace hmpid +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx new file mode 100644 index 0000000000000..f9fcb800bb3ed --- /dev/null +++ b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx @@ -0,0 +1,43 @@ +// 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 raw-to-digits-workflow.cxx +/// \author Andrea Ferrero +/// +/// \brief This is an executable that runs the decoding via DPL. +/// +/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. +/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow +/// + +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/Task.h" +#include "Framework/runDataProcessing.h" + +#include "HMPIDWorkflow/WriteRawFromDigitsSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + DataProcessorSpec consumer = o2::hmpid::getWriteRawFromDigitsSpec(); +// DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); + specs.push_back(consumer); +// specs.push_back(consumer); + + return specs; +} From 37fe2e31bcdf667cf05668f5a2466b21565f387b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:24:59 +0100 Subject: [PATCH 065/208] fix cmakes --- Detectors/HMPID/simulation/CMakeLists.txt | 3 ++- Detectors/HMPID/workflow/CMakeLists.txt | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Detectors/HMPID/simulation/CMakeLists.txt b/Detectors/HMPID/simulation/CMakeLists.txt index 75a4e0d973265..639816aa14992 100644 --- a/Detectors/HMPID/simulation/CMakeLists.txt +++ b/Detectors/HMPID/simulation/CMakeLists.txt @@ -9,11 +9,12 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDSimulation - SOURCES src/Detector.cxx src/HMPIDDigitizer.cxx + SOURCES src/Detector.cxx src/HMPIDDigitizer.cxx src/HmpidCoder.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDBase) o2_target_root_dictionary(HMPIDSimulation HEADERS include/HMPIDSimulation/Detector.h + include/HMPIDSimulation/HmpidCoder.h include/HMPIDSimulation/HMPIDDigitizer.h) diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index 0d8f894699251..5ad041ef5f3eb 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -10,7 +10,7 @@ o2_add_library(HMPIDWorkflow # SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/RawFileReaderSpec.cxx src/DumpDigitsSpec.cxx - SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx + SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx src/WriteRawFromDigitSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::DetectorsRaw @@ -28,10 +28,10 @@ o2_add_executable(raw-to-digits-workflow SOURCES src/raw-to-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) -#o2_add_executable(rawfile-to-digits-workflow -# COMPONENT_NAME hmpid -# SOURCES src/rawfile-to-digits-workflow.cxx -# PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) +o2_add_executable(write-raw-from-digits-workflow + COMPONENT_NAME hmpid + SOURCES src/write-rawfrom-digits-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) o2_add_executable(dump-digits-workflow COMPONENT_NAME hmpid From 02cf14ccc52cb7eb7d91554e68708137779a965a Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:26:22 +0100 Subject: [PATCH 066/208] fix --- Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h b/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h index 804d708d9da3b..5367c5bcb20e1 100644 --- a/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h +++ b/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h @@ -17,5 +17,6 @@ #pragma link C++ class o2::hmpid::Detector + ; #pragma link C++ class o2::base::DetImpl < o2::hmpid::Detector> + ; #pragma link C++ class o2::hmpid::HMPIDDigitizer + ; +#pragma link C++ class o2::hmpid::HmpidCoder + ; #endif From 5589f0106f9c60b616b7edd84f7c2067a873d5b9 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:27:44 +0100 Subject: [PATCH 067/208] fix --- Detectors/HMPID/workflow/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index 5ad041ef5f3eb..b3ab2144e9c41 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -30,7 +30,7 @@ o2_add_executable(raw-to-digits-workflow o2_add_executable(write-raw-from-digits-workflow COMPONENT_NAME hmpid - SOURCES src/write-rawfrom-digits-workflow.cxx + SOURCES src/write-raw-from-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) o2_add_executable(dump-digits-workflow From 551686aad5226690049f2f0cb54810a4af515af5 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:28:41 +0100 Subject: [PATCH 068/208] fix --- Detectors/HMPID/workflow/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index b3ab2144e9c41..ccb511a9998ba 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -10,7 +10,7 @@ o2_add_library(HMPIDWorkflow # SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/RawFileReaderSpec.cxx src/DumpDigitsSpec.cxx - SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx src/WriteRawFromDigitSpec.cxx + SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx src/WriteRawFromDigitsSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::DetectorsRaw From 1e43e4302994a9f792c72213e9ffaecf8c0f0dc5 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:57:05 +0100 Subject: [PATCH 069/208] fix --- Detectors/HMPID/base/include/HMPIDBase/Digit.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index d86c7bab9679f..5a86cd4e09b78 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -60,8 +60,8 @@ class Digit Digit() = default; Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad) {}; Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge); - Digit(uint16_t bc, uint32_t orbit, float uint16_t, int equipment, int column, int dilogic, int channel) ; - Digit(uint16_t bc, uint32_t orbit, float uint16_t, int module, int x, int y); + Digit(uint16_t bc, uint32_t orbit, uint16_t, int equipment, int column, int dilogic, int channel) ; + Digit(uint16_t bc, uint32_t orbit, uint16_t, int module, int x, int y); uint16_t getCharge() const { return mQ; } int getPadID() const { return mPad; } From 0bd3cae99fe392fad63f50ff792aafb140a65f1b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 22:33:17 +0100 Subject: [PATCH 070/208] Build Ok --- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 12 ++++++++++++ .../include/HMPIDWorkflow/WriteRawFromDigitsSpec.h | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index 0e2cc15971451..417e13c5fa2b5 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -47,6 +47,18 @@ HmpidCoder::~HmpidCoder() } // ===================== Random production of Raw Files =================== +void HmpidCoder::getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId) +{ + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + if (mEqIds[i] == Equi) { + *CruId = mCruIds[i]; + *LinkId = mLinkIds[i]; + return; + } + *CruId = mCruIds[0]; + *LinkId = mLinkIds[0]; + return; +} int HmpidCoder::calculateNumberOfPads() { diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h index 365f45d977bc3..ba51bef8179b2 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -20,6 +20,7 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" +#include "HMPIDBase/Digit.h" namespace o2 { @@ -36,7 +37,7 @@ namespace hmpid private: - bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); + static bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); }; o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec = "HMP/DIGITS"); From 93b0cf5d235ada6672a03934da27d50acfa70435 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 28 Jan 2021 11:30:50 +0100 Subject: [PATCH 071/208] Troubles .... --- .../HMPID/base/include/HMPIDBase/Digit.h | 2 +- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 7 +++ Detectors/HMPID/base/src/Digit.cxx | 8 ++-- .../HMPIDReconstruction/HmpidDecodeRawFile.h | 2 +- .../HMPIDReconstruction/HmpidDecodeRawMem.h | 4 +- .../HMPIDReconstruction/HmpidDecoder.h | 2 +- .../HMPIDReconstruction/HmpidEquipment.h | 2 +- .../reconstruction/src/HmpidDecodeRawFile.cxx | 2 +- .../reconstruction/src/HmpidDecodeRawMem.cxx | 7 +-- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 7 +-- .../reconstruction/src/HmpidEquipment.cxx | 2 +- .../include/HMPIDSimulation/HmpidCoder.h | 3 +- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 43 +++++++++++++++-- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 4 ++ .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 2 +- .../HMPID/workflow/src/DataDecoderSpec.cxx | 48 +++++++++++-------- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 38 +++++++++++---- .../workflow/src/WriteRawFromDigitsSpec.cxx | 45 +++++++++++++---- 18 files changed, 165 insertions(+), 63 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 5a86cd4e09b78..38680fb3b1d0f 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -52,7 +52,7 @@ class Digit friend std::ostream& operator<< (std::ostream& os, const Digit& d) { os << "[" << A2C(d.mPad) << "," << A2P(d.mPad) << "," << A2X(d.mPad) << "," << - A2Y(d.mPad) << "}@(" << d.mOrbit << "," << d.mBc << ")=" << d.mQ; + A2Y(d.mPad) << "]@(" << d.mOrbit << "," << d.mBc << ")=" << d.mQ; return os; }; diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 85e94dad97dfb..86365fcfd71f9 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -109,6 +109,13 @@ class Geo static constexpr int N_EQUIPMENTTOTALPADS = N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; static constexpr int N_HMPIDTOTALPADS = MAXEQUIPMENTS * N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; + static constexpr int N_PHOTOCATODS = 6; + static constexpr int N_PHOTOCATODSX = 80; + static constexpr int N_PHOTOCATODSY = 48; + static constexpr int MAXXPHOTO = 79; + static constexpr int MAXYPHOTO = 47; + + static void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 85517ffb0b209..1166d492d4603 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -69,9 +69,9 @@ void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Ch uint32_t Digit::Absolute2Pad(int Module, int x, int y) { - int ph = (y/Geo::N_COLXSEGMENT)+((x >= Geo::HALFXROWS ) ? 1 : 0); - int px = x % Geo::N_COLXSEGMENT; - int py = y % Geo::HALFXROWS; + int ph = (y/Geo::N_PHOTOCATODSY)+((x >= Geo::HALFXROWS ) ? 1 : 0); + int px = x % Geo::HALFXROWS; + int py = y % Geo::N_PHOTOCATODSY; return Abs(Module,ph,px,py); } @@ -82,7 +82,7 @@ void Digit::Pad2Absolute(uint32_t pad, int *Module, int *x, int *y) int px = A2X(pad); int py = A2Y(pad); *x = (ph % 2 == 0) ? px : (px + Geo::HALFXROWS); - *y = ((ph >> 1) * Geo::N_COLXSEGMENT) + py; + *y = ((ph >> 1) * Geo::N_PHOTOCATODSY) + py; return; } diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h index bc3444583d634..5f9fbd7020dfb 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h @@ -48,7 +48,7 @@ class HmpidDecodeRawFile: public HmpidDecoder bool getHeaderFromStream(uint32_t **streamPtr); bool getWordFromStream(uint32_t *word); int fileExists(char *filewithpath); - void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge); private: FILE *fh; diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h index 0b3d221a1569e..209660fb3f4d1 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h @@ -47,7 +47,7 @@ class HmpidDecodeRawMem: public HmpidDecoder bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size); bool getHeaderFromStream(uint32_t **streamPtr); bool getWordFromStream(uint32_t *word); - void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge); private: @@ -63,7 +63,7 @@ class HmpidDecodeRawDigit: public HmpidDecodeRawMem std::vector mDigits; private: - void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge); }; diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index 2cc9b3ff40af9..6280f8ac355c7 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -155,7 +155,7 @@ class HmpidDecoder HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); void updateStatistics(HmpidEquipment *eq); protected: - virtual void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) = 0; + virtual void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) = 0; virtual bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size) = 0; virtual bool getHeaderFromStream(uint32_t **streamPtr) = 0; virtual bool getWordFromStream(uint32_t *word) = 0; diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h index 920a502eccc1a..2ed68883b2064 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h @@ -124,7 +124,7 @@ class HmpidEquipment void resetPadMap(); void resetErrors(); void setError(int ErrType); - void setPad(int col, int dil, int cha, int charge); + void setPad(int col, int dil, int cha, uint16_t charge); }; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx index e828bc629e6c1..f9b66f5eda0f1 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx @@ -137,7 +137,7 @@ bool HmpidDecodeRawFile::getWordFromStream(uint32_t *word) /// @param[in] dil : the dilogic [0..9] /// @param[in] ch : the channel [0..47] /// @param[in] charge : the value of the charge -void HmpidDecodeRawFile::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) +void HmpidDecodeRawFile::setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) { eq->setPad(col, dil, ch, charge); return; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 0627b8fe4b144..5fabdd32190bf 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -132,7 +132,7 @@ bool HmpidDecodeRawMem::getWordFromStream(uint32_t *word) /// @param[in] dil : the dilogic [0..9] /// @param[in] ch : the channel [0..47] /// @param[in] charge : the value of the charge -void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) +void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) { eq->setPad(col, dil, ch, charge); return; @@ -180,10 +180,11 @@ HmpidDecodeRawDigit::~HmpidDecodeRawDigit() /// @param[in] dil : the dilogic [0..9] /// @param[in] ch : the channel [0..47] /// @param[in] charge : the value of the charge -void HmpidDecodeRawDigit::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) +void HmpidDecodeRawDigit::setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) { eq->setPad(col, dil, ch, charge); - mDigits.push_back(Digit(mHeBCDI, mHeORBIT, (float)charge, eq->getEquipmentId(), col, dil, ch)); + mDigits.push_back(Digit(mHeBCDI, mHeORBIT, charge, eq->getEquipmentId(), col, dil, ch)); + //std::cout << "DI " << mDigits.back() << " "<>> Coding size "<< digits.size() << std::endl; +int padsCount =0; for(o2::hmpid::Digit d : digits) { orbit = d.getOrbit(); bc = d.getBC(); if(orbit != pv_orbit || bc != pv_bc) { //the event is changed - if (orbit != 0) { + if (pv_orbit != 0 || pv_bc != 0 ) { fillTheOutputBuffer(padMap); writePaginatedEvent(pv_orbit, pv_bc); } @@ -275,16 +279,45 @@ void HmpidCoder::codeDigitsVector(std::vectordigits) Digit::Pad2Absolute(d.getPadID(), &mo, &x, &y); Geo::Module2Equipment(mo, y, x, &eq, &col, &dil, &cha); idx = getEquipmentPadIndex(eq, col, dil, cha); + if(idx == 107562) { + std::cout << ">>> Beccato >"<< idx << " " << d <<" ("<< mo <<","<>> CPads set "<< padsCount << std::endl; std::free(padMap); return; } +void HmpidCoder::codeDigitsTest(int Events, uint16_t charge) +{ + uint32_t orbit = 0; + uint16_t bc = 0; + + uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + int eq,col,dil,cha,mo,x,y, idx; + for(int e=0; e #include "TTree.h" +#include "TFile.h" + #include #include "Framework/CallbackService.h" @@ -71,13 +73,14 @@ void DataDecoderTask::init(framework::InitContext& ic) void DataDecoderTask::run(framework::ProcessingContext& pc) { -//---- mDeco->mDigits.clear(); + mDeco->mDigits.clear(); decodeTF(pc); // decodeReadout(pc); // decodeRawFile(pc); LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; + pc.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginHMP, "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; float avgBusyTime[o2::hmpid::Geo::MAXEQUIPMENTS]; @@ -86,19 +89,21 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - // TString filename = TString::Format("%s_%06d.root", "test", 1); + TString filename = TString::Format("%s_%06d.root", "test", 1); // LOG(DEBUG) << "opening file " << filename.Data(); - // std::unique_ptr mfileOut = nullptr; - // mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); +//-- std::unique_ptr mfileOut = nullptr; +//-- mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); - std::unique_ptr theObj; - theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); + //std::unique_ptr theObj; +// TTree * theObj; + //theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); +// theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); - theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); - theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); - theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); - theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); - theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); +// theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); +// theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); +// theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); +// theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); +// theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); int numEqui = mDeco->getNumberOfEquipments(); for(int e=0;egetPadSamples(m, y, x); sumOfCharges[m][y][x] = mDeco->getPadSum(m, y, x); squareOfCharges[m][y][x] = mDeco->getPadSquares(m, y, x); + // std::cout << "@ " << m <<","<cd(); // theObj->Write(); // theObj.reset(); // mfileOut.reset(); - pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); + // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); - theObj.reset(); + //--- theObj->Reset(); + //---- mfileOut.reset(); } @@ -154,17 +162,17 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) auto& inputs = pc.inputs(); DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); - auto& digitsV = pc.outputs().make>(Output{"HMP", "DIGITS", 0, Lifetime::Timeframe}); +// auto& digitsV = pc.outputs().make>(Output{"HMP", "DIGITS", 0, Lifetime::Timeframe}); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - mDeco->mDigits.clear(); + // mDeco->mDigits.clear(); uint32_t *theBuffer = (uint32_t *)it.raw(); // std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); - for(auto d : mDeco->mDigits) - digitsV.push_back(d); +// for(auto d : mDeco->mDigits) +// digitsV.push_back(d); // pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); @@ -228,8 +236,8 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); - outputs.emplace_back("HMP", "ORBITS", 0, o2::framework::Lifetime::Timeframe); - outputs.emplace_back("HMP", "STATS", 0, o2::framework::Lifetime::Timeframe); + // outputs.emplace_back("HMP", "ORBITS", 0, o2::framework::Lifetime::Timeframe); + // outputs.emplace_back("HMP", "STATS", 0, o2::framework::Lifetime::Timeframe); return DataProcessorSpec{ diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index a0e19829b2372..bcb364c202267 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -58,20 +58,41 @@ void DumpDigitsTask::init(framework::InitContext& ic) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; mPrintDigits = ic.options().get("print"); - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + mIsOutputOnFile = false; + mOutputFileName = ic.options().get("out-file"); + if(mOutputFileName != "") { + mOsFile.open(mOutputFileName, std::ios::out); + if (mOsFile.is_open()) { + mIsOutputOnFile = true; + } + } return; } void DumpDigitsTask::run(framework::ProcessingContext& pc) { - auto digits = pc.inputs().get>("digits"); - std::cout << "The size of the vector " << digits.size() << std::endl; - if (mPrintDigits) { - for(o2::hmpid::Digit Dig : digits) { - std::cout << Dig << std::endl; + //LOG(INFO) << "Enter Dump run..."; + + for (auto&& input : pc.inputs()) { + if (input.spec->binding == "digits") { + auto digits = pc.inputs().get>("digits"); + LOG(INFO) << "The size of the vector =" << digits.size(); + if (mPrintDigits) { + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + for(o2::hmpid::Digit Dig : digits) { + std::cout << Dig << std::endl; + } + std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; + } + if (mIsOutputOnFile) { + mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + for(o2::hmpid::Digit Dig : digits) { + mOsFile << Dig << std::endl; + } + mOsFile.close(); + } } } - std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; return; } @@ -91,7 +112,8 @@ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) inputs, outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"print", VariantType::Bool, false, {"print digits (default false )"}}} }; + Options{{"out-file", VariantType::String, "", {"name of the output file"}}, + {"print", VariantType::Bool, false, {"print digits (default false )"}}} }; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index eabc76d0360ae..ebeace124575b 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -58,6 +58,7 @@ using RDH = o2::header::RDHAny; void WriteRawFromDigitsTask::init(framework::InitContext& ic) { LOG(INFO) << "[HMPID Write Raw File From Digits vector - run] Dumping ..."; + mBaseFileName = ic.options().get("out-file"); return; @@ -79,17 +80,41 @@ bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2:: void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) { - std::vector digits = pc.inputs().get>("digits"); - LOG(INFO) << "The size of the digits vector " << digits.size(); + uint32_t pad; + int Equi, Colu, Dilo, Chan; + int Equi1, Colu1, Dilo1, Chan1; - sort(digits.begin(), digits.end(), eventEquipPadsComparision); - LOG(INFO) << "Digits sorted ! " ; + for(Equi=0; Equi<14; Equi++) + for(Colu=0;Colu<24;Colu++) + for(Dilo=0;Dilo<10;Dilo++) + for(Chan=0;Chan<48;Chan++) { + pad = Digit::Equipment2Pad(Equi, Colu, Dilo, Chan); + Digit::Pad2Equipment(pad, &Equi1, &Colu1, &Dilo1, &Chan1); + if(Equi!=Equi1 ||Colu!=Colu1||Dilo!=Dilo1||Chan!=Chan1) { + std::cout << ">>>> !" << Equi<<","<< Colu<<","<< Dilo<<","<< Chan << std::endl; + } + } - HmpidCoder cod(Geo::MAXEQUIPMENTS); - cod.openOutputStream("pippo"); - cod.codeDigitsVector(digits); - cod.closeOutputStream(); - LOG(INFO) << "Raw File created ! " ; + + + return; + + for (auto&& input : pc.inputs()) { + if (input.spec->binding == "digits") { + auto digits = pc.inputs().get>("digits"); + + LOG(INFO) << "The size of the digits vector " << digits.size(); + sort(digits.begin(), digits.end(), eventEquipPadsComparision); + LOG(INFO) << "Digits sorted ! " ; + + HmpidCoder cod(Geo::MAXEQUIPMENTS); + cod.openOutputStream(mBaseFileName.c_str()); + //cod.codeDigitsTest(2, 100); + cod.codeDigitsVector(digits); + cod.closeOutputStream(); + LOG(INFO) << "Raw File created ! " ; + } + } return; } @@ -109,7 +134,7 @@ o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec inputs, outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"print", VariantType::Bool, false, {"print"}}} }; + Options{{"out-file", VariantType::String, "hmpidRaw", {"name of the output file"}}} }; } } // namespace hmpid From 75d498ae2ade479b54235c6f6b5757d18abf2b2b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 28 Jan 2021 13:26:00 +0100 Subject: [PATCH 072/208] fix --- Detectors/HMPID/base/src/Digit.cxx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 1166d492d4603..2e4c4554725d8 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -46,6 +46,21 @@ ClassImp(o2::hmpid::Digit); // ----- Coordinate Conversion ---- uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) { + /* + * + * kNDILOGICAdd = 10 + * + if(ddl<0 || ddl >13 || row<1 || row >25 || dil<1 || dil >10 || pad<0 || pad >47 ) return -1; + Int_t a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) + Int_t ch=ddl/2; + Int_t tmp=(24-row)/8; + Int_t pc=(ddl%2)?5-2*tmp:2*tmp; + Int_t px=(kNDILOGICAdd+1 - dil)*8-pad/6-1; //flip according to Paolo (2-9-2008) + + tmp=(ddl%2)?row-1:(24-row); + Int_t py=6*(tmp%8)+a2y[pad%6]; + + */ if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return -1; @@ -53,7 +68,7 @@ uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) int ch = Equi / 2; // The Module int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; int pc = (Equi % 2) ? 5-2*tmp : 2*tmp; // The PhotoCatode - int px = (Geo::N_DILOGICS+1 - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; + int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; tmp = (Equi % 2) ? Colu : (23-Colu); int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; return Abs(ch,pc,px,py); From a2f1b4fb19a782e9d141ee00a9afc526dbb2cc00 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 29 Jan 2021 09:06:51 +0100 Subject: [PATCH 073/208] Compile OK, not yet correct the coordinate translation --- .../HMPID/base/include/HMPIDBase/Digit.h | 2 + Detectors/HMPID/base/include/HMPIDBase/Geo.h | 20 +++--- Detectors/HMPID/base/src/Digit.cxx | 61 ++++++++++++++++--- Detectors/HMPID/base/src/Geo.cxx | 37 ++++++++++- .../HMPIDReconstruction/HmpidDecoder.h | 6 +- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 19 +++--- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 13 ++-- .../HMPID/workflow/src/DataDecoderSpec.cxx | 6 +- .../workflow/src/WriteRawFromDigitsSpec.cxx | 21 ------- 9 files changed, 123 insertions(+), 62 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 38680fb3b1d0f..cc5892f6e7489 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -41,6 +41,8 @@ class Digit static void Pad2Absolute(uint32_t pad, int *Module, int *x, int *y); static uint32_t Absolute2Pad(int Module, int x, int y); static void Pad2Photo(uint32_t pad, int *chamber, int *photo, int *x, int *y); + static void Absolute2Equipment(int Module, int x, int y, int *Equi, int *Colu, int *Dilo, int *Chan); + static void Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int *Module, int *x, int *y); // Operators definition ! friend inline bool operator<(const Digit& l, const Digit& r) { return l.mPad < r.mPad; }; diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 86365fcfd71f9..49a489e419d34 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -45,14 +45,14 @@ namespace hmpid 143 ^ - | 40 32 24 16 08 00 07 15 23 31 39 47 - | 41 33 25 17 09 01 06 14 22 30 38 46 - 42 34 26 18 10 02 05 13 21 29 37 45 - y 43 35 27 19 11 03 04 12 20 28 36 44 (Column,Dil.) - 44 36 28 20 12 04 03 11 19 27 35 43 - | 45 37 29 21 13 05 02 10 18 26 34 42 - | 46 38 30 22 14 06 01 09 17 25 33 41 - 47 39 31 23 15 07 00 08 16 24 32 40 + | 46 40 34 28 22 16 10 04 05 11 17 23 29 35 41 47 + | 44 38 32 26 20 14 08 02 03 09 15 21 27 33 39 45 + 40 36 30 24 18 12 06 00 01 07 13 19 25 31 37 43 + y 43 37 31 25 19 13 07 01 00 06 12 18 24 30 36 40 (Column,Dil.) + 45 39 33 27 21 15 09 03 02 08 14 20 26 32 38 44 + | 47 41 35 29 23 17 11 05 04 10 16 22 28 34 40 46 + | + 0 @@ -116,8 +116,8 @@ class Geo static constexpr int MAXYPHOTO = 47; - static void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); - static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); + static void Module2Equipment(int Mod, int Row, int Col, int *Equi, int *Colu, int *Dilo, int *Chan); + static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Row, int *Col); // from diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 2e4c4554725d8..19ac5cb3dbae7 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -65,20 +65,65 @@ uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return -1; int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) - int ch = Equi / 2; // The Module + int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; - int pc = (Equi % 2) ? 5-2*tmp : 2*tmp; // The PhotoCatode - int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; - tmp = (Equi % 2) ? Colu : (23-Colu); - int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; + + int py; + int pc; + int px; + if((Equi % Geo::EQUIPMENTSPERMODULE) != 0 ) { + pc = 5-2*tmp; + px = Dilo * Geo::DILOPADSROWS + Chan / Geo::DILOPADSCOLS; + tmp = Colu; + }else { + pc = 2*tmp; + px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; + tmp = (23-Colu); + + } + py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; + py = py % 48; + +// int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5-2*tmp : 2*tmp; // The PhotoCatode +// int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; +// tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23-Colu); +// int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; return Abs(ch,pc,px,py); } void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Chan) { - int ch, ar, ac; - Pad2Absolute(pad, &ch, &ar, &ac); - Geo::Module2Equipment(ch, ac, ar, Equi, Colu, Dilo, Chan); + int ch, ax, ay; + int y2a[6]={4,2,0,1,3,5}; + + Pad2Absolute(pad, &ch, &ax, &ay); + + if (ax > Geo::MAXHALFXROWS) { + *Equi = ch * Geo::EQUIPMENTSPERMODULE + 1; + ax = ax - Geo::HALFXROWS; + *Chan = (ax % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2a[5 -(ay % Geo::DILOPADSCOLS)]; + } else { + *Equi = ch * Geo::EQUIPMENTSPERMODULE; + ax = Geo::MAXHALFXROWS - ax; + ay = Geo::MAXYCOLS - ay; + *Chan = (ax % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2a[ay % Geo::DILOPADSCOLS]; + } + *Dilo = ax / Geo::DILOPADSROWS; + *Colu = ay / Geo::DILOPADSCOLS; + return; +} + +void Digit::Absolute2Equipment(int Module, int x, int y, int *Equi, int *Colu, int *Dilo, int *Chan) +{ + uint32_t pad = Absolute2Pad(Module, x, y); + Pad2Equipment(pad, Equi, Colu, Dilo, Chan); + return; +} + +void Digit::Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int *Module, int *x, int *y) +{ + uint32_t pad = Equipment2Pad(Equi, Colu, Dilo, Chan); + Pad2Absolute(pad, Module, x, y); return; } diff --git a/Detectors/HMPID/base/src/Geo.cxx b/Detectors/HMPID/base/src/Geo.cxx index 8b0957a3e9b1e..f2c8ad232d3b2 100644 --- a/Detectors/HMPID/base/src/Geo.cxx +++ b/Detectors/HMPID/base/src/Geo.cxx @@ -34,9 +34,9 @@ void Geo::Init() /// /// (0,0,0,0) Right Top (1,0,0,0) Left Bottom /// -void Geo::Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan) +void Geo::Module2Equipment(int Mod, int Row, int Col, int *Equi, int *Colu, int *Dilo, int *Chan) { - if (Row > MAXHALFXROWS) { +/* if (Row > MAXHALFXROWS) { *Equi = Mod * EQUIPMENTSPERMODULE + 1; Row = Row - HALFXROWS; } else { @@ -48,6 +48,21 @@ void Geo::Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Colu = Col / DILOPADSCOLS; *Chan = (Row % DILOPADSROWS) * DILOPADSCOLS + (Col % DILOPADSCOLS); return; +*/ + int y2a[6]={5,3,1,0,2,4}; + int ch, ax, ay; + if (ax > Geo::MAXHALFXROWS) { + *Equi = ch * Geo::EQUIPMENTSPERMODULE + 1; + ax = ax - Geo::HALFXROWS; + } else { + *Equi = ch * Geo::EQUIPMENTSPERMODULE; + ax = Geo::MAXHALFXROWS - ax; + ay = Geo::MAXYCOLS - ay; + } + *Dilo = ax / Geo::DILOPADSROWS; + *Colu = ay / Geo::DILOPADSCOLS; + *Chan = (ax % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2a[ay % Geo::DILOPADSCOLS]; + return; } /// Functions to translate coordinates : from Equipment,Col,Dilogic,Channel to Module,Col,Row @@ -58,8 +73,10 @@ void Geo::Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int /// /// (0,0,0,0) Right Top (1,0,0,0) Left Bottom /// -void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row) +void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Row, int *Col) { +/* + *Mod = Equi / EQUIPMENTSPERMODULE; *Row = Dilo * DILOPADSROWS + Chan / DILOPADSROWS; *Col = (Colu * DILOPADSCOLS) + Chan % DILOPADSCOLS; @@ -70,6 +87,20 @@ void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Row = MAXHALFXROWS - *Row; *Col = MAXYCOLS - *Col; } + */ + if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || + Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return; + + int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) + int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module + int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; + int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5-2*tmp : 2*tmp; // The PhotoCatode + int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; + tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23-Colu); + int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; + *Mod = ch; + *Row = px; + *Col = py; return; } diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index 6280f8ac355c7..506fe5e5a5946 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -131,9 +131,9 @@ class HmpidDecoder uint16_t getChannelSamples(int Equipment, int Column, int Dilogic, int Channel); double getChannelSum(int Equipment, int Column, int Dilogic, int Channel); double getChannelSquare(int Equipment, int Column, int Dilogic, int Channel); - uint16_t getPadSamples(int Module, int Column, int Row); - double getPadSum(int Module, int Column, int Row); - double getPadSquares(int Module, int Column, int Row); + uint16_t getPadSamples(int Module, int Row, int Column); + double getPadSum(int Module, int Row, int Column); + double getPadSquares(int Module, int Row, int Column); void dumpErrors(int Equipment); void dumpPads(int Equipment, int type = 0); diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 3f0700581ea9d..f70da4e558e07 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -21,6 +21,7 @@ #include "Framework/Logger.h" #include "Headers/RAWDataHeader.h" #include "HMPIDReconstruction/HmpidDecoder.h" +#include "HMPIDBase/Digit.h" using namespace o2::hmpid; @@ -872,10 +873,10 @@ bool HmpidDecoder::decodeBufferFast() /// @param[in] Column : the HMPID Module Column number [0..143] /// @param[in] Row : the HMPID Module Row number [0..159] /// @returns The Number of entries for specified pad -uint16_t HmpidDecoder::getPadSamples(int Module, int Column, int Row) +uint16_t HmpidDecoder::getPadSamples(int Module, int Row, int Column) { int e, c, d, h; - Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + Digit::Absolute2Equipment(Module, Row, Column, &e, &c, &d, &h); int EqInd = getEquipmentIndex(e); if (EqInd < 0) return (0); @@ -887,10 +888,10 @@ uint16_t HmpidDecoder::getPadSamples(int Module, int Column, int Row) /// @param[in] Column : the HMPID Module Column number [0..143] /// @param[in] Row : the HMPID Module Row number [0..159] /// @returns The Sum of Charges for specified pad -double HmpidDecoder::getPadSum(int Module, int Column, int Row) +double HmpidDecoder::getPadSum(int Module, int Row, int Column) { int e, c, d, h; - Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + Digit::Absolute2Equipment(Module, Row, Column, &e, &c, &d, &h); int EqInd = getEquipmentIndex(e); if (EqInd < 0) return (0); @@ -902,10 +903,10 @@ double HmpidDecoder::getPadSum(int Module, int Column, int Row) /// @param[in] Column : the HMPID Module Column number [0..143] /// @param[in] Row : the HMPID Module Row number [0..159] /// @returns The Sum of Square Charges for specified pad -double HmpidDecoder::getPadSquares(int Module, int Column, int Row) +double HmpidDecoder::getPadSquares(int Module, int Row, int Column) { int e, c, d, h; - Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + Digit::Absolute2Equipment(Module, Row, Column, &e, &c, &d, &h); int EqInd = getEquipmentIndex(e); if (EqInd < 0) return (0); @@ -1015,13 +1016,13 @@ void HmpidDecoder::dumpPads(int EquipmId, int type) for (int r = StartRow; r < EndRow; r++) { switch (type) { case 0: - std::cout << getPadSamples(Module, c, r) << ","; + std::cout << getPadSamples(Module, r, c) << ","; break; case 1: - std::cout << getPadSum(Module, c, r) << ","; + std::cout << getPadSum(Module, r, c) << ","; break; case 2: - std::cout << getPadSquares(Module, c, r) << ","; + std::cout << getPadSquares(Module, r, c) << ","; break; } } diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index c5137ede2ee7e..f1c7cbcc14757 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -15,6 +15,7 @@ /// \version 1.0 /// \date 24 set 2020 +#include "HMPIDBase/Digit.h" #include "HMPIDSimulation/HmpidCoder.h" using namespace o2::hmpid; @@ -86,7 +87,7 @@ void HmpidCoder::fillPadsMap(uint32_t *padMap) mo = rand() % Geo::N_MODULES; xr = rand() % Geo::N_XROWS; yc = rand() % Geo::N_YCOLS; - Geo::Module2Equipment(mo, yc, xr, &eq, &col, &dil, &cha); + Digit::Absolute2Equipment(mo, xr, yc, &eq, &col, &dil, &cha); int index = getEquipmentPadIndex(eq, col, dil, cha); if( padMap[index] == 0) { if(mRandomCharge) { @@ -276,11 +277,13 @@ int padsCount =0; pv_orbit = orbit; pv_bc = bc; } - Digit::Pad2Absolute(d.getPadID(), &mo, &x, &y); - Geo::Module2Equipment(mo, y, x, &eq, &col, &dil, &cha); + Digit::Pad2Equipment(d.getPadID(),&eq, &col, &dil, &cha); idx = getEquipmentPadIndex(eq, col, dil, cha); - if(idx == 107562) { - std::cout << ">>> Beccato >"<< idx << " " << d <<" ("<< mo <<","<>> Beccato >"<< idx << " " << d <<" ("<>> >"<< idx << " " << d <<" ("<< mo <<","<getPadSamples(m, y, x); - sumOfCharges[m][y][x] = mDeco->getPadSum(m, y, x); - squareOfCharges[m][y][x] = mDeco->getPadSquares(m, y, x); + numOfSamples[m][y][x] = mDeco->getPadSamples(m, x, y); + sumOfCharges[m][y][x] = mDeco->getPadSum(m, x, y); + squareOfCharges[m][y][x] = mDeco->getPadSquares(m, x, y); // std::cout << "@ " << m <<","<>>> !" << Equi<<","<< Colu<<","<< Dilo<<","<< Chan << std::endl; - } - } - - - - return; - for (auto&& input : pc.inputs()) { if (input.spec->binding == "digits") { auto digits = pc.inputs().get>("digits"); @@ -122,12 +103,10 @@ void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec) //o2::framework::DataPrecessorSpec getDecodingSpec() { - std::vector inputs; inputs.emplace_back("digits", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); std::vector outputs; - return DataProcessorSpec{ "HMP-WriteRawFrtomDigits", From 080066be14d53e069681539aea7dc18b8a062117 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 29 Jan 2021 12:47:39 +0100 Subject: [PATCH 074/208] This works fine ... But only one event from file --- Detectors/HMPID/base/src/Digit.cxx | 64 ++++++++++++++++--- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 6 +- .../HMPID/workflow/src/DataDecoderSpec.cxx | 12 ++-- 3 files changed, 66 insertions(+), 16 deletions(-) diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 19ac5cb3dbae7..40e9109c69505 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -47,6 +47,7 @@ ClassImp(o2::hmpid::Digit); uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) { /* + * Original algorithm in AliROOT Run 1/2 * * kNDILOGICAdd = 10 * @@ -59,11 +60,31 @@ uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) tmp=(ddl%2)?row-1:(24-row); Int_t py=6*(tmp%8)+a2y[pad%6]; - */ + + // Check the input data if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return -1; + int chan2y[6]={3,2,4,1,5,0}; // y coordinate translation for a channel address (index position) for even chamber + + // Calculate the odd/even of geometry + bool isEven = (Equi % Geo::EQUIPMENTSPERMODULE) == 0 ? true : false; + int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module + + // Calculate the x,y photo cathode relative coords + int pc = (23-Colu) / Geo::N_COLXSEGMENT * 2; // pho = [0,2,4] + int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; // (dil [0..9] ,chan[0..47]) -> x [79..0] + int py = Geo::DILOPADSCOLS * ((23-Colu) % Geo::N_COLXSEGMENT) + chan2y[Chan % Geo::DILOPADSCOLS];// Col[0..23] -> y [47..0] + + if(!isEven) { + pc = 5 - pc; // revert the photo cathode index + px = Geo::MAXXPHOTO - px; // revert the x coordinate + py = Geo::MAXYPHOTO - py; // revert the y coordinate + } + + /* ---- Last good algorithm ------- + int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; @@ -83,21 +104,45 @@ uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) } py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; py = py % 48; + */ + + /* Direct Translation from Aliroot + int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5-2*tmp : 2*tmp; // The PhotoCatode + int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; + tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23-Colu); + int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; -// int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5-2*tmp : 2*tmp; // The PhotoCatode -// int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; -// tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23-Colu); -// int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; - return Abs(ch,pc,px,py); + */ + + return Abs(ch,pc,px,py); // Pack the coords into the PadID word } void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Chan) { + int ch, ph, px, py; + int y2chan[6]={5,3,1,0,2,4}; + + Pad2Photo(pad, &ch, &ph, &px, &py); // Unpak the pad ID in the photo cathode coords + + bool isEven = (ph % 2) == 0 ? true : false; + int eq = ch * Geo::EQUIPMENTSPERMODULE; + + if(!isEven) { + eq++; // Correct the equipment number + px = Geo::MAXXPHOTO - px; // revert the X coord + py = Geo::MAXYPHOTO - py; // revert the Y coord + ph = 5 - ph; // revert the photo cathode index + } + *Dilo = Geo::N_DILOGICS - (px / Geo::DILOPADSROWS) -1; // Calculate the Dilogic x [0..79] -> dil [9..0] + *Colu = 23 - (((ph / 2) * Geo::N_COLXSEGMENT) + (py / Geo::DILOPADSCOLS)); // calculate the column (ph [0,2,4], y [0..47]) -> col [23..0] + *Chan = ((Geo::MAXXPHOTO-px) % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2chan[py % Geo::DILOPADSCOLS]; + *Equi = eq; + + return; + /* last good algorithm int ch, ax, ay; int y2a[6]={4,2,0,1,3,5}; - Pad2Absolute(pad, &ch, &ax, &ay); - if (ax > Geo::MAXHALFXROWS) { *Equi = ch * Geo::EQUIPMENTSPERMODULE + 1; ax = ax - Geo::HALFXROWS; @@ -111,6 +156,7 @@ void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Ch *Dilo = ax / Geo::DILOPADSROWS; *Colu = ay / Geo::DILOPADSCOLS; return; + */ } void Digit::Absolute2Equipment(int Module, int x, int y, int *Equi, int *Colu, int *Dilo, int *Chan) @@ -129,7 +175,7 @@ void Digit::Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int *Modu uint32_t Digit::Absolute2Pad(int Module, int x, int y) { - int ph = (y/Geo::N_PHOTOCATODSY)+((x >= Geo::HALFXROWS ) ? 1 : 0); + int ph = (y/Geo::N_PHOTOCATODSY)*2+((x >= Geo::HALFXROWS ) ? 1 : 0); int px = x % Geo::HALFXROWS; int py = y % Geo::N_PHOTOCATODSY; return Abs(Module,ph,px,py); diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index f1c7cbcc14757..9488273737ec6 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -279,11 +279,13 @@ int padsCount =0; } Digit::Pad2Equipment(d.getPadID(),&eq, &col, &dil, &cha); idx = getEquipmentPadIndex(eq, col, dil, cha); + // std::cout << ">>> "<< idx << " " << d <<" ("<>> Beccato >"<< idx << " " << d <<" ("<>> "<< idx << " " << d <<" ("<>> >"<< idx << " " << d <<" ("<< mo <<","<>> Errore >"<<" abso("<< mo <<","<binding == "rawfile") { - const auto* header = o2::header::get(input.header); - if (!header) { - return; - } + // const auto* header = o2::header::get(input.header); + // if (!header) { + // return; + // } + const o2::header::DataHeader* header = o2::header::get(input.header); uint32_t *theBuffer = (uint32_t *)input.payload; int pagesize = header->payloadSize; + std::cout << "Get page !" << std::endl; mDeco->setUpStream(theBuffer, pagesize); mDeco->decodePageFast(&theBuffer); } @@ -229,7 +231,7 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); -// inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + // inputs.emplace_back("rawfile", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); From f4e596a3b67a49f380d718409f97cef2d0363147 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 29 Jan 2021 18:19:18 +0100 Subject: [PATCH 075/208] Version 0.1 --- Detectors/HMPID/base/src/Digit.cxx | 105 +++++------------------------ 1 file changed, 17 insertions(+), 88 deletions(-) diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 40e9109c69505..c9d8e312ab919 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -46,74 +46,23 @@ ClassImp(o2::hmpid::Digit); // ----- Coordinate Conversion ---- uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) { - /* - * Original algorithm in AliROOT Run 1/2 - * - * kNDILOGICAdd = 10 - * - if(ddl<0 || ddl >13 || row<1 || row >25 || dil<1 || dil >10 || pad<0 || pad >47 ) return -1; - Int_t a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) - Int_t ch=ddl/2; - Int_t tmp=(24-row)/8; - Int_t pc=(ddl%2)?5-2*tmp:2*tmp; - Int_t px=(kNDILOGICAdd+1 - dil)*8-pad/6-1; //flip according to Paolo (2-9-2008) - - tmp=(ddl%2)?row-1:(24-row); - Int_t py=6*(tmp%8)+a2y[pad%6]; - */ - // Check the input data if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return -1; int chan2y[6]={3,2,4,1,5,0}; // y coordinate translation for a channel address (index position) for even chamber - // Calculate the odd/even of geometry - bool isEven = (Equi % Geo::EQUIPMENTSPERMODULE) == 0 ? true : false; - int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module - - // Calculate the x,y photo cathode relative coords - int pc = (23-Colu) / Geo::N_COLXSEGMENT * 2; // pho = [0,2,4] - int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; // (dil [0..9] ,chan[0..47]) -> x [79..0] - int py = Geo::DILOPADSCOLS * ((23-Colu) % Geo::N_COLXSEGMENT) + chan2y[Chan % Geo::DILOPADSCOLS];// Col[0..23] -> y [47..0] - - if(!isEven) { - pc = 5 - pc; // revert the photo cathode index - px = Geo::MAXXPHOTO - px; // revert the x coordinate - py = Geo::MAXYPHOTO - py; // revert the y coordinate - } - - /* ---- Last good algorithm ------- - - int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) + bool isEven = (Equi % Geo::EQUIPMENTSPERMODULE) == 0 ? true : false; // Calculate the odd/even of geometry int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module - int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; - - int py; - int pc; - int px; - if((Equi % Geo::EQUIPMENTSPERMODULE) != 0 ) { - pc = 5-2*tmp; - px = Dilo * Geo::DILOPADSROWS + Chan / Geo::DILOPADSCOLS; - tmp = Colu; - }else { - pc = 2*tmp; - px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; - tmp = (23-Colu); + // Calculate the x,y photo cathode relative coords For Odd equipment + int pc = (Colu / Geo::N_COLXSEGMENT) * 2 + 1; // col [0..23] -> [1,3,5] + int px = Geo::MAXXPHOTO - ((Dilo * Geo::DILOPADSROWS) + (Chan / Geo::DILOPADSCOLS)); + int py = (Colu % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + chan2y[Chan % Geo::DILOPADSCOLS]; + if(isEven) { + pc = 5 - pc; + py = Geo::MAXYPHOTO - py; } - py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; - py = py % 48; - */ - - /* Direct Translation from Aliroot - int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5-2*tmp : 2*tmp; // The PhotoCatode - int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; - tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23-Colu); - int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; - - */ - return Abs(ch,pc,px,py); // Pack the coords into the PadID word } @@ -125,38 +74,18 @@ void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Ch Pad2Photo(pad, &ch, &ph, &px, &py); // Unpak the pad ID in the photo cathode coords bool isEven = (ph % 2) == 0 ? true : false; - int eq = ch * Geo::EQUIPMENTSPERMODULE; - - if(!isEven) { - eq++; // Correct the equipment number - px = Geo::MAXXPHOTO - px; // revert the X coord + int eq = ch * Geo::EQUIPMENTSPERMODULE +1; + px = Geo::MAXXPHOTO - px; // revert the X coord + if(isEven) { + eq--; // Correct the equipment number py = Geo::MAXYPHOTO - py; // revert the Y coord - ph = 5 - ph; // revert the photo cathode index + ph = 5 - ph; // revert the photo cathode index [0,2,4] -> [5,3,1] } - *Dilo = Geo::N_DILOGICS - (px / Geo::DILOPADSROWS) -1; // Calculate the Dilogic x [0..79] -> dil [9..0] - *Colu = 23 - (((ph / 2) * Geo::N_COLXSEGMENT) + (py / Geo::DILOPADSCOLS)); // calculate the column (ph [0,2,4], y [0..47]) -> col [23..0] - *Chan = ((Geo::MAXXPHOTO-px) % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2chan[py % Geo::DILOPADSCOLS]; + *Dilo = px / Geo::DILOPADSROWS; // Calculate the Dilogic x [0..79] -> dil [0..9] + *Colu = ((ph / 2) * Geo::N_COLXSEGMENT) + (py / Geo::DILOPADSCOLS); // calculate the column (ph [1,3,5], y [0..47]) -> col [0..23] + *Chan = ((px % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS) + y2chan[py % Geo::DILOPADSCOLS]; *Equi = eq; - - return; - /* last good algorithm - int ch, ax, ay; - int y2a[6]={4,2,0,1,3,5}; - Pad2Absolute(pad, &ch, &ax, &ay); - if (ax > Geo::MAXHALFXROWS) { - *Equi = ch * Geo::EQUIPMENTSPERMODULE + 1; - ax = ax - Geo::HALFXROWS; - *Chan = (ax % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2a[5 -(ay % Geo::DILOPADSCOLS)]; - } else { - *Equi = ch * Geo::EQUIPMENTSPERMODULE; - ax = Geo::MAXHALFXROWS - ax; - ay = Geo::MAXYCOLS - ay; - *Chan = (ax % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2a[ay % Geo::DILOPADSCOLS]; - } - *Dilo = ax / Geo::DILOPADSROWS; - *Colu = ay / Geo::DILOPADSCOLS; return; - */ } void Digit::Absolute2Equipment(int Module, int x, int y, int *Equi, int *Colu, int *Dilo, int *Chan) @@ -187,7 +116,7 @@ void Digit::Pad2Absolute(uint32_t pad, int *Module, int *x, int *y) int ph = A2P(pad); int px = A2X(pad); int py = A2Y(pad); - *x = (ph % 2 == 0) ? px : (px + Geo::HALFXROWS); + *x = px + ((ph % 2 == 1) ? Geo::HALFXROWS : 0); *y = ((ph >> 1) * Geo::N_PHOTOCATODSY) + py; return; } From 690a9d1e0e2845b2f2387b9b995212a8509c09d6 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:22:17 +0100 Subject: [PATCH 076/208] Version 0.2 - Works on Centos ! Test the StfBuilder chain -> Decode -> WriteRawFile Need to verify the loss of Pads --- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 24 ++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 49a489e419d34..2f6b3144e6080 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -21,8 +21,8 @@ namespace hmpid /* ------------------ HMPID Detector Coordinate definition ------------------- 143 .-------------. .-------------. 0 ------.------ 23 - | | |.-----.-----.| | | --> | - | | || | || | | 0 9 | + | | |.-----.-----.| | | <-- | + | | || | || | | 9 0 | | | || 4 | 5 || | | Dil. | ^ | | || | || | | | | ^ | | | ||_____|_____|| | | | | | @@ -41,30 +41,26 @@ namespace hmpid Pad(Module,x,y) Pad(Chamber,PhotoCat,x,y) Pad(Equipment,Column,Dilogic,Channel) - Equipment n Equipment n+1 + Equipment n 143 ^ - | 46 40 34 28 22 16 10 04 05 11 17 23 29 35 41 47 - | 44 38 32 26 20 14 08 02 03 09 15 21 27 33 39 45 - 40 36 30 24 18 12 06 00 01 07 13 19 25 31 37 43 - y 43 37 31 25 19 13 07 01 00 06 12 18 24 30 36 40 (Column,Dil.) - 45 39 33 27 21 15 09 03 02 08 14 20 26 32 38 44 - | 47 41 35 29 23 17 11 05 04 10 16 22 28 34 40 46 + | 46 40 34 28 22 16 10 04 + | 44 38 32 26 20 14 08 02 + 40 36 30 24 18 12 06 00 + y 43 37 31 25 19 13 07 01 + 45 39 33 27 21 15 09 03 + | 47 41 35 29 23 17 11 05 | 0 - 0 --------- x ------> 79 80 ------ x -----------> 159 + 0 --------- x ------> 79 For Equipment n : x = 79 - (Dilo * 8 + Chan / 8) y = 143 - (Column * 6 + Chan % 6) - For Equipment n+1 : x = 80 + (Dilo * 8 + Chan / 8) - y = Column * 6 + Chan % 6 - - --------------------------------------------------------------------------- */ /// \class Geo /// \brief HMPID detector geometry (only statics) From 5b61d59d8d02405f00f1fab645f9e4f5bbfefb9f Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:23:50 +0100 Subject: [PATCH 077/208] try to open Root File --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 1b30a6997f0b7..252a32178dc77 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -90,9 +90,9 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; TString filename = TString::Format("%s_%06d.root", "test", 1); - // LOG(DEBUG) << "opening file " << filename.Data(); -//-- std::unique_ptr mfileOut = nullptr; -//-- mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); + LOG(DEBUG) << "opening the stat file " << filename.Data(); + std::unique_ptr mfileOut = nullptr; + mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); //std::unique_ptr theObj; // TTree * theObj; @@ -124,7 +124,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // mfileOut->cd(); // theObj->Write(); // theObj.reset(); -// mfileOut.reset(); + mfileOut.reset(); // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); From 386f3ab7a24f8697899063e1bcab9b71c910d19e Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:36:22 +0100 Subject: [PATCH 078/208] try write ttree --- .../HMPID/workflow/src/DataDecoderSpec.cxx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 252a32178dc77..9879abc1e6355 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -94,16 +94,16 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) std::unique_ptr mfileOut = nullptr; mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); - //std::unique_ptr theObj; -// TTree * theObj; - //theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); -// theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); + std::unique_ptr theObj; + TTree * theObj; + theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); + theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); -// theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); -// theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); -// theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); -// theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); -// theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); + theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); + theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); + theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); + theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); + theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); int numEqui = mDeco->getNumberOfEquipments(); for(int e=0;egetPadSquares(m, x, y); // std::cout << "@ " << m <<","<WriteObject((TTree *)theObj, "HMPID Decoding Statistics"); // mfileOut->cd(); // theObj->Write(); -// theObj.reset(); + theObj.reset(); mfileOut.reset(); // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); From 875f148accc67984bd9f7d5f63d6b719cb108ac0 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:43:57 +0100 Subject: [PATCH 079/208] fix --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 9879abc1e6355..80a07ef56ba4a 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -96,7 +96,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) std::unique_ptr theObj; TTree * theObj; - theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); + // theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); @@ -120,9 +120,9 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) } theObj->Fill(); - mfileOut->WriteObject((TTree *)theObj, "HMPID Decoding Statistics"); + // mfileOut->WriteObject((TTree *)theObj, "HMPID Decoding Statistics"); // mfileOut->cd(); -// theObj->Write(); + theObj->Write(); theObj.reset(); mfileOut.reset(); From 396e64b45a5f48b28f1a448ed6f0076af7d3767a Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:49:12 +0100 Subject: [PATCH 080/208] fix --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 80a07ef56ba4a..3e0a5f266efad 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -91,10 +91,11 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) TString filename = TString::Format("%s_%06d.root", "test", 1); LOG(DEBUG) << "opening the stat file " << filename.Data(); - std::unique_ptr mfileOut = nullptr; +// std::unique_ptr mfileOut = nullptr; + TFile mfileOut; mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); - std::unique_ptr theObj; + // std::unique_ptr theObj; TTree * theObj; // theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); From 344a24ff1b1cae3ff57110f2e9f92766870370a1 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:53:54 +0100 Subject: [PATCH 081/208] fix --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 3e0a5f266efad..bdc758fa9f19e 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -92,8 +92,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) TString filename = TString::Format("%s_%06d.root", "test", 1); LOG(DEBUG) << "opening the stat file " << filename.Data(); // std::unique_ptr mfileOut = nullptr; - TFile mfileOut; - mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); + TFile mfileOut(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); // std::unique_ptr theObj; TTree * theObj; @@ -124,8 +123,6 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // mfileOut->WriteObject((TTree *)theObj, "HMPID Decoding Statistics"); // mfileOut->cd(); theObj->Write(); - theObj.reset(); - mfileOut.reset(); // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); From 645a282369b773318537c1b8fc278e02b76e2b6b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:57:56 +0100 Subject: [PATCH 082/208] fix --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index bdc758fa9f19e..e2548e4747697 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -92,7 +92,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) TString filename = TString::Format("%s_%06d.root", "test", 1); LOG(DEBUG) << "opening the stat file " << filename.Data(); // std::unique_ptr mfileOut = nullptr; - TFile mfileOut(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); + TFile mfileOut(TString::Format("%s", filename.Data()), "RECREATE"); // std::unique_ptr theObj; TTree * theObj; From 085ccfe20eeb85fc6ede2a5cff8bcd9d0088804c Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 4 Feb 2021 12:29:09 +0100 Subject: [PATCH 083/208] Works with streming. --- .../HMPID/base/include/HMPIDBase/Digit.h | 3 + .../HMPID/reconstruction/src/HmpidDecoder.cxx | 4 +- .../include/HMPIDSimulation/HmpidCoder.h | 21 ++- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 174 +++++++++++------- Detectors/HMPID/workflow/CMakeLists.txt | 13 +- .../include/HMPIDWorkflow/DataDecoderSpec.h | 10 +- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 5 +- .../include/HMPIDWorkflow/ReadRawFileSpec.h | 43 +++++ .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 19 +- .../HMPID/workflow/src/DataDecoderSpec.cxx | 119 +++++------- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 43 +++-- .../HMPID/workflow/src/ReadRawFileSpec.cxx | 153 +++++++++++++++ .../workflow/src/WriteRawFromDigitsSpec.cxx | 72 +++++--- .../workflow/src/dump-digits-workflow.cxx | 12 ++ .../workflow/src/raw-to-digits-workflow.cxx | 38 +++- .../workflow/src/read-raw-file-workflow.cxx | 62 +++++++ .../src/write-raw-from-digits-workflow.cxx | 21 ++- 17 files changed, 589 insertions(+), 223 deletions(-) create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h create mode 100644 Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index cc5892f6e7489..ffe60a28f9dfa 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -70,6 +70,9 @@ class Digit uint32_t getOrbit() const { return mOrbit; } uint16_t getBC() const { return mBc; } uint64_t getTriggerID() const { return ((mOrbit << 12) | mBc); } + void setOrbit(uint32_t orbit) { mOrbit = orbit; return; } + void setBC(uint16_t bc) { mBc = bc; return; } + void setTriggerID(uint64_t trigger) { mOrbit = (trigger >> 12); mBc = (trigger & 0x0FFF); return; } // convenience conversion to x-y pad coordinates int getPx() const { return A2X(mPad); } diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index f70da4e558e07..5217550c16b0f 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -410,7 +410,7 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT; LOG(DEBUG) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR; - LOG(INFO) << " EquIdx = "<<*EquipIndex<< " Event = "<< mHeEvent<< " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; + LOG(DEBUG) << " EquIdx = "<<*EquipIndex<< " Event = "<< mHeEvent<< " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; if (*EquipIndex == -1) { LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; @@ -811,7 +811,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) break; } if (wp == wpprev) { - LOG(INFO) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ "[" << Column << "]"; } else { if( isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h index 790d4a3707d87..b6efa62ca85ed 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h @@ -67,15 +67,22 @@ class HmpidCoder uint32_t *mEventBufferBasePtr; int mEventSizePerEquipment[Geo::MAXEQUIPMENTS]; uint32_t mPacketCounterPerEquipment[Geo::MAXEQUIPMENTS]; + bool mSkipEmptyEvents; + bool mFixedPacketLenght; + std::string mFileName160; + std::string mFileName161; FILE *mOutStream160; FILE *mOutStream161; + long mPadsCoded; + long mPacketsCoded; + public: - HmpidCoder(int numOfEquipments); + HmpidCoder(int numOfEquipments, bool skipEmptyEvents = false, bool fixedPacketLenght = true); virtual ~HmpidCoder(); - void init(); + void reset(); void setVerbosity(int Level) { mVerbose = Level; @@ -119,19 +126,21 @@ class HmpidCoder void openOutputStream(const char *OutputFileName); void closeOutputStream(); - void createRandomEvent(uint32_t orbit, uint16_t bc); + void codeRandomEvent(uint32_t orbit, uint16_t bc); void codeDigitsVector(std::vector); - void codeDigitsTest(int Events, uint16_t charge); + void codeTest(int Events, uint16_t charge); + + void dumpResults(); protected: void createRandomPayloadPerEvent(); - void saveEventPage(int Flp); + void savePacket(int Flp, int packetSize); int calculateNumberOfPads(); private: void getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId); int getEquipmentPadIndex(int eq, int col, int dil, int cha); - void writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum); + int writeHeader(uint32_t *Buffer, uint32_t WordsToRead, uint32_t PayloadWords, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum); void fillPadsMap(uint32_t *padMap); void fillTheOutputBuffer(uint32_t* padMap); void writePaginatedEvent(uint32_t orbit, uint16_t bc); diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index 9488273737ec6..866d776f6d368 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -20,16 +20,21 @@ using namespace o2::hmpid; -HmpidCoder::HmpidCoder(int numOfEquipments) +HmpidCoder::HmpidCoder(int numOfEquipments, bool skipEmptyEvents, bool fixedPacketsLenght) { mNumberOfEquipments = numOfEquipments; + mSkipEmptyEvents = skipEmptyEvents; + mFixedPacketLenght = fixedPacketsLenght; + mVerbose = 0; mOccupancyPercentage = 0; mRandomOccupancy = false; mRandomCharge = false; mOutStream160 = NULL; mOutStream161 = NULL; + mFileName160 = ""; + mFileName161 = ""; mPailoadBufferDimPerEquipment = ((Geo::N_SEGMENTS * (Geo::N_COLXSEGMENT * (Geo::N_DILOGICS * (Geo::N_CHANNELS + 1) + 1) + 1)) + 10); @@ -38,7 +43,7 @@ HmpidCoder::HmpidCoder(int numOfEquipments) mPayloadBufferPtr = (uint32_t *) std::malloc(mNumberOfEquipments * sizeof(uint32_t) * mPailoadBufferDimPerEquipment ); mEventBufferBasePtr = (uint32_t *) std::malloc(sizeof(uint32_t) * RAWBLOCKDIMENSION_W); mEventBufferPtr = mEventBufferBasePtr; - srand( (unsigned)time(NULL) ); + reset(); } @@ -49,28 +54,17 @@ HmpidCoder::~HmpidCoder() std::free(mEventBufferBasePtr); } -// ===================== Random production of Raw Files =================== -void HmpidCoder::getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId) +void HmpidCoder::reset() { - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) - if (mEqIds[i] == Equi) { - *CruId = mCruIds[i]; - *LinkId = mLinkIds[i]; - return; - } - *CruId = mCruIds[0]; - *LinkId = mLinkIds[0]; - return; + srand( (unsigned)time(NULL) ); + mPadsCoded = 0; + mPacketsCoded = 0; } +// ===================== Random production of Raw Files =================== int HmpidCoder::calculateNumberOfPads() { -// int numOfEqipments = 0; int occupancyPercentage = 0; -// for(int i = 0; i < MAXEQUIPMENTS; i++) -// if(mFlpIds[i] == Flp) -// numOfEqipments++; - if(mRandomOccupancy) { occupancyPercentage = rand() % 1000; } else { @@ -102,15 +96,6 @@ void HmpidCoder::fillPadsMap(uint32_t *padMap) return; } -constexpr int p1() { return(Geo::N_SEGMENTS * Geo::N_COLXSEGMENT * Geo::N_DILOGICS * Geo::N_CHANNELS); } -constexpr int p2() { return(Geo::N_DILOGICS * Geo::N_CHANNELS); } - -int HmpidCoder::getEquipmentPadIndex(int eq, int col, int dil, int cha) -{ - return( eq * p1() + col * p2() + dil * Geo::N_CHANNELS + cha); - -} - void HmpidCoder::createRandomPayloadPerEvent() { uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); @@ -123,24 +108,43 @@ void HmpidCoder::createRandomPayloadPerEvent() return; } - -void HmpidCoder::createRandomEvent(uint32_t orbit, uint16_t bc) +void HmpidCoder::codeRandomEvent(uint32_t orbit, uint16_t bc) { - createRandomPayloadPerEvent(); writePaginatedEvent(orbit, bc); + return; +} +// ===================== END of Random production of Raw Files =================== +void HmpidCoder::getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId) +{ + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + if (mEqIds[i] == Equi) { + *CruId = mCruIds[i]; + *LinkId = mLinkIds[i]; + return; + } + *CruId = mCruIds[0]; + *LinkId = mLinkIds[0]; return; } -// ===================== END of Random production of Raw Files =================== +constexpr int p1() { return(Geo::N_SEGMENTS * Geo::N_COLXSEGMENT * Geo::N_DILOGICS * Geo::N_CHANNELS); } +constexpr int p2() { return(Geo::N_DILOGICS * Geo::N_CHANNELS); } + +int HmpidCoder::getEquipmentPadIndex(int eq, int col, int dil, int cha) +{ + return( eq * p1() + col * p2() + dil * Geo::N_CHANNELS + cha); + +} + void HmpidCoder::fillTheOutputBuffer(uint32_t* padMap) { uint32_t rowMarker, segMarker, eoeMarker, padWord; uint32_t rowSize; uint32_t ptr = 0; int pads[Geo::MAXEQUIPMENTS]; - int count; + int padsCount; int segSize; for(int i=0; i 0) { pads[j]++; rowSize++; + padsCount++; } } } rowSize += Geo::N_DILOGICS; segSize += (rowSize + 1); rowMarker = 0x000036A8 | ((rowSize << 16) & 0x03ff0000); - // fills the Payload Buffer + + // ---- fills the Payload Buffer mPayloadBufferPtr[ptr++] = rowMarker; int col = (s - 1) * Geo::N_COLXSEGMENT + c; for (int d = 1; d <= Geo::N_DILOGICS; d++) { @@ -187,7 +195,12 @@ void HmpidCoder::fillTheOutputBuffer(uint32_t* padMap) segMarker = 0xAB000000 | ((segSize << 8) & 0x000fff00) | (s & 0x0000000F); mPayloadBufferPtr[ptr++] = segMarker; } - mEventSizePerEquipment[eq] = ptr - startPtr; + + if(mSkipEmptyEvents && padsCount == 0) { // Sets the lenght of Events + mEventSizePerEquipment[eq] = 0; + } else { + mEventSizePerEquipment[eq] = ptr - startPtr; + } } return; } @@ -197,9 +210,15 @@ void HmpidCoder::writePaginatedEvent(uint32_t orbit, uint16_t bc) int nWordToRead; int count; int payloatPtr = 0; + if(orbit == 0 || bc == 0){ + std::cerr << "HmpidCoder [ERROR] : Bad Orbit/BCid number (ORBIT="<< orbit << " BCID=" << bc << ")" << std::endl; + return; + } for (int eq = 0; eq < mNumberOfEquipments; eq++) { int EventSize = mEventSizePerEquipment[eq]; + if(EventSize == 0) continue; // Skips the Events sized with 0 + int EquipmentCounter = 0; int numOfPages = EventSize / PAYLOADMAXSPACE_W + 1; @@ -210,18 +229,21 @@ void HmpidCoder::writePaginatedEvent(uint32_t orbit, uint16_t bc) EquipmentCounter++; } nWordToRead = count; - while (count < PAYLOADDIMENSION_W) - mEventBufferPtr[HEADERDIMENSION_W + count++] = 0; - uint32_t MemSize = nWordToRead * sizeof(uint32_t) + HEADERDIMENSION_W * sizeof(uint32_t); + + int nWordsTail = (mFixedPacketLenght) ? PAYLOADDIMENSION_W : ((count / 8 + 1) * 8); + while (count < nWordsTail) + mEventBufferPtr[HEADERDIMENSION_W + count++] = 0; + uint32_t PackNum = mPacketCounterPerEquipment[eq]++; - writeHeader(mEventBufferPtr, MemSize, mEqIds[eq], PackNum, bc, orbit, PageNum); - saveEventPage(mFlpIds[eq]); + int PacketSize = writeHeader(mEventBufferPtr, nWordToRead, nWordsTail, mEqIds[eq], PackNum, bc, orbit, PageNum); + savePacket(mFlpIds[eq], PacketSize); } } return; } -void HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum) +int HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t WordsToRead, uint32_t PayloadWords, + int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum) { uint32_t CruId, LinkId; uint32_t TType = 0; @@ -231,6 +253,8 @@ void HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint uint32_t Busy = 3000; uint32_t PAR = 0; + uint32_t MemSize = WordsToRead * sizeof(uint32_t) + HEADERDIMENSION_W * sizeof(uint32_t); + uint32_t OffsetNext = PayloadWords * sizeof(uint32_t) + HEADERDIMENSION_W * sizeof(uint32_t); getEquipCoord(Equip, &CruId, &LinkId); // FEEID Header Size Header version @@ -238,7 +262,7 @@ void HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint // Priority System ID Buffer[1] = 0x00000100 | 0x00000006; // .....Memory Size HeOffsetNewPack; - Buffer[2] = (MemSize << 16) | 0x00002000; + Buffer[2] = (MemSize << 16) | (OffsetNext & 0x0000FFFF); // DW CruId PacNum Link Num Buffer[3] = 0x10000000 | ((CruId & 0x00FF) << 16) | ((PackNum & 0x0FF) << 8) | (LinkId & 0x0FF); Buffer[4] = 0x00000FFF & BCDI; @@ -253,51 +277,53 @@ void HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint Buffer[13] = PAR; Buffer[14] = 0xAAAA0001; Buffer[15] = 0xAAAA0001; - return; + return (OffsetNext); } void HmpidCoder::codeDigitsVector(std::vectordigits) { - uint32_t pv_orbit, orbit = 0; - uint16_t pv_bc, bc = 0; + int eq,col,dil,cha,mo,x,y, idx; + uint32_t pv_orbit = 0; + uint32_t orbit = 0; + uint16_t pv_bc = 0; + uint16_t bc = 0; uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); - int eq,col,dil,cha,mo,x,y, idx; -std::cout << ">>> Coding size "<< digits.size() << std::endl; -int padsCount =0; + // TODO: Add memory allocation error check + + int padsCount =0; for(o2::hmpid::Digit d : digits) { orbit = d.getOrbit(); bc = d.getBC(); if(orbit != pv_orbit || bc != pv_bc) { //the event is changed - if (pv_orbit != 0 || pv_bc != 0 ) { + if (pv_orbit != 0 || pv_bc != 0 ) { // isn't the first ! fillTheOutputBuffer(padMap); writePaginatedEvent(pv_orbit, pv_bc); } - memset(padMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + memset(padMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event pv_orbit = orbit; pv_bc = bc; } - Digit::Pad2Equipment(d.getPadID(),&eq, &col, &dil, &cha); - idx = getEquipmentPadIndex(eq, col, dil, cha); - // std::cout << ">>> "<< idx << " " << d <<" ("<>> "<< idx << " " << d <<" ("<>> Errore >"<<" abso("<< mo <<","<>> CPads set "<< padsCount << std::endl; std::free(padMap); + mPadsCoded += padsCount; + return; } -void HmpidCoder::codeDigitsTest(int Events, uint16_t charge) +void HmpidCoder::codeTest(int Events, uint16_t charge) { uint32_t orbit = 0; uint16_t bc = 0; @@ -325,12 +351,13 @@ void HmpidCoder::codeDigitsTest(int Events, uint16_t charge) } // ====================== FILES management functions ====================== -void HmpidCoder::saveEventPage(int Flp) +void HmpidCoder::savePacket(int Flp, int packetSize) { + mPacketsCoded++; if(Flp == 160) - fwrite(mEventBufferPtr, RAWBLOCKDIMENSION_W, sizeof(uint32_t), mOutStream160); + fwrite(mEventBufferPtr, packetSize, sizeof(uint8_t), mOutStream160); else - fwrite(mEventBufferPtr, RAWBLOCKDIMENSION_W, sizeof(uint32_t), mOutStream161); + fwrite(mEventBufferPtr, packetSize, sizeof(uint8_t), mOutStream161); return; } @@ -338,19 +365,21 @@ void HmpidCoder::saveEventPage(int Flp) void HmpidCoder::openOutputStream(const char *OutputFileName) { char FileName[512]; - sprintf(FileName, "%s%d%s", OutputFileName, 160, ".dat"); mOutStream160 = fopen(FileName, "wb"); if (mOutStream160 == 0) { LOG(ERROR) << "ERROR to open Output file " << FileName; throw 0; } + mFileName160 = FileName; + sprintf(FileName, "%s%d%s", OutputFileName, 161, ".dat"); mOutStream161 = fopen(FileName, "wb"); if (mOutStream161 == 0) { LOG(ERROR) << "ERROR to open Output file " << FileName; throw 0; } + mFileName161 = FileName; return; } @@ -360,3 +389,12 @@ void HmpidCoder::closeOutputStream() fclose(mOutStream161); return; } + +void HmpidCoder::dumpResults() +{ + std::cout << " **** HMPID RawFile Coder : results ****" << std::endl; + std::cout << " Created files : " << mFileName160 << " ," << mFileName161 << std::endl; + std::cout << " Number of Pads coded : " << mPadsCoded << std::endl; + std::cout << " Number of Packets written : " << mPacketsCoded << std::endl; + std::cout << " ----------------------------------------" << std::endl; +} diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index ccb511a9998ba..6095de8f32eab 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -9,8 +9,12 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDWorkflow -# SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/RawFileReaderSpec.cxx src/DumpDigitsSpec.cxx - SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx src/WriteRawFromDigitsSpec.cxx + SOURCES src/DataDecoderSpec.cxx + src/DigitReaderSpec.cxx + src/ClusterizerSpec.cxx + src/DumpDigitsSpec.cxx + src/ReadRawFileSpec.cxx + src/WriteRawFromDigitsSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::DetectorsRaw @@ -23,6 +27,11 @@ o2_add_executable(recoworkflow SOURCES src/HMPIDRecoWorkflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) +o2_add_executable(read-raw-file-workflow + COMPONENT_NAME hmpid + SOURCES src/read-raw-file-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + o2_add_executable(raw-to-digits-workflow COMPONENT_NAME hmpid SOURCES src/raw-to-digits-workflow.cxx diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index 81c701712f141..21e3227aa8706 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -8,12 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file DatDecoderSpec.h -/// \author Andrea Ferrero -/// -/// \brief Definition of a data processor to run the raw decoding -/// #ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ #define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ @@ -38,10 +32,12 @@ namespace hmpid void decodeTF(framework::ProcessingContext& pc); void decodeReadout(framework::ProcessingContext& pc); void decodeRawFile(framework::ProcessingContext& pc); - + void endOfStream(framework::EndOfStreamContext& ec) override; private: HmpidDecodeRawDigit *mDeco; + long mTotalDigits; + long mTotalFrames; }; diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index 252788704cad6..4d9d724c15bf1 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -20,6 +20,7 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" namespace o2 { @@ -33,7 +34,7 @@ namespace hmpid ~DumpDigitsTask() override = default; void init(framework::InitContext& ic) final; void run(framework::ProcessingContext& pc) final; - + void endOfStream(framework::EndOfStreamContext& ec) override; private: bool mPrintDigits = false; @@ -41,6 +42,8 @@ namespace hmpid std::string mOutputFileName = ""; std::ofstream mOsFile; + int mOrbit; + int mBc; }; o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h new file mode 100644 index 0000000000000..5a952d105cf74 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h @@ -0,0 +1,43 @@ +// 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. + + +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_READRAWFILESPEC_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_READRAWFILESPEC_H_ + +#include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" +#include "HMPIDBase/Digit.h" + +namespace o2 +{ +namespace hmpid +{ + + class RawFileReaderTask : public framework::Task + { + public: + RawFileReaderTask() = default; + ~RawFileReaderTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + + private: + std::ifstream mInputFile{}; ///< input file + bool mPrint = false; ///< print debug messages + // auto stop(void); + }; + +o2::framework::DataProcessorSpec getReadRawFileSpec(std::string inputSpec = "HMP/RAWDATA"); + +} // end namespace hmpid +} // end namespace o2 + +#endif /* DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_READRAWFILESPEC_H_ */ diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h index 04d0386ba11a0..bfd44cbc588a6 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -8,16 +8,11 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file DatDecoderSpec.h -/// \author Andrea Ferrero -/// -/// \brief Definition of a data processor to run the raw decoding -/// #ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMDIGITS_H_ #define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMDIGITS_H_ +#include #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" #include "HMPIDBase/Digit.h" @@ -30,14 +25,24 @@ namespace hmpid class WriteRawFromDigitsTask : public framework::Task { public: - WriteRawFromDigitsTask() = default; + WriteRawFromDigitsTask() = default; ~WriteRawFromDigitsTask() override = default; void init(framework::InitContext& ic) final; void run(framework::ProcessingContext& pc) final; + void endOfStream(framework::EndOfStreamContext& ec) override; private: static bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); + void createRawFile(framework::ProcessingContext& pc); std::string mBaseFileName = ""; + std::vector mDigits; + bool mSkipEmpty = false; + bool mFixedPacketLenght = false; + bool mOrderTheEvents = true; + long mDigitsReceived; + long mFramesReceived; + bool mIsTheStremClosed = false; + }; o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index e2548e4747697..b6a4e983497f0 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -63,11 +63,11 @@ void DataDecoderTask::init(framework::InitContext& ic) { LOG(INFO) << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !"; - std::cout << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !" << std::endl; mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); mDeco->init(); - + mTotalDigits = 0; + mTotalFrames = 0; return; } @@ -77,26 +77,32 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) decodeTF(pc); // decodeReadout(pc); -// decodeRawFile(pc); +// decodeRawFile(pc); + +// LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; +// pc.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginHMP, "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + + + // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); + + //--- theObj->Reset(); + //---- mfileOut.reset(); - LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; - pc.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginHMP, "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); +} +void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) +{ + // Records the statistics float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; float avgBusyTime[o2::hmpid::Geo::MAXEQUIPMENTS]; - uint32_t numOfSamples[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; TString filename = TString::Format("%s_%06d.root", "test", 1); - LOG(DEBUG) << "opening the stat file " << filename.Data(); -// std::unique_ptr mfileOut = nullptr; + LOG(INFO) << "Create the stat file " << filename.Data(); TFile mfileOut(TString::Format("%s", filename.Data()), "RECREATE"); - - // std::unique_ptr theObj; TTree * theObj; - // theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); @@ -116,64 +122,37 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) numOfSamples[m][y][x] = mDeco->getPadSamples(m, x, y); sumOfCharges[m][y][x] = mDeco->getPadSum(m, x, y); squareOfCharges[m][y][x] = mDeco->getPadSquares(m, x, y); - // std::cout << "@ " << m <<","<cd(); + // theObj->Fill(); theObj->Write(); - // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); + LOG(INFO) << "End the Decoding ! Digits decoded = " << mTotalDigits << " Frames received = " << mTotalFrames; + // LOG(INFO)<< "Sleep 10 sec"<< std::endl; + // sleep(30); - //--- theObj->Reset(); - //---- mfileOut.reset(); + //ec.services().get().endOfStream(); + // ec.services().get().readyToQuit(framework::QuitRequest::Me); + return; } - -/* auto& digits = mDecoder->getOutputDigits(); - auto& orbits = mDecoder->getOrbits(); - - if (mPrint) { - for (auto d : digits) { - std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; - } - } - // send the output buffer via DPL - size_t digitsSize, orbitsSize; - char* digitsBuffer = createBuffer(digits, digitsSize); - char* orbitsBuffer = createBuffer(orbits, orbitsSize); - - // create the output message - auto freefct = [](void* data, void*) { free(data); }; -// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); -// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); -*/ - //_________________________________________________________________________________________________ // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) { - LOG(INFO) << "*********** In decodeTF **************"; + LOG(DEBUG) << "*********** In decodeTF **************"; // get the input buffer auto& inputs = pc.inputs(); DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); - -// auto& digitsV = pc.outputs().make>(Output{"HMP", "DIGITS", 0, Lifetime::Timeframe}); - for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - // mDeco->mDigits.clear(); - + mDeco->mDigits.clear(); uint32_t *theBuffer = (uint32_t *)it.raw(); - // std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); -// for(auto d : mDeco->mDigits) -// digitsV.push_back(d); - - // pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); - + mTotalFrames++; + pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits);// + mTotalDigits += mDeco->mDigits.size(); + LOG(DEBUG) << "Writing " << mDeco->mDigits.size() << "/" << mTotalDigits << " Digits ..."; } return; } @@ -203,15 +182,22 @@ void DataDecoderTask::decodeRawFile(framework::ProcessingContext& pc) LOG(INFO) << "*********** In decode rawfile **************"; for (auto&& input : pc.inputs()) { - if (input.spec->binding == "rawfile") { - // const auto* header = o2::header::get(input.header); - // if (!header) { - // return; - // } - const o2::header::DataHeader* header = o2::header::get(input.header); - uint32_t *theBuffer = (uint32_t *)input.payload; - int pagesize = header->payloadSize; - std::cout << "Get page !" << std::endl; + if (input.spec->binding == "file") { + const header::DataHeader* header = o2::header::get(input.header); + if (!header) { + return; + } + + auto const* raw = input.payload; + size_t payloadSize = header->payloadSize; + + LOG(INFO) << " payloadSize=" << payloadSize; + if (payloadSize == 0) { + return; + } + + uint32_t *theBuffer = (uint32_t *)input.payload; + int pagesize = header->payloadSize; mDeco->setUpStream(theBuffer, pagesize); mDeco->decodePageFast(&theBuffer); } @@ -221,31 +207,24 @@ void DataDecoderTask::decodeRawFile(framework::ProcessingContext& pc) //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) -//o2::framework::DataPrecessorSpec getDecodingSpec() { std::vector inputs; -// inputs.emplace_back("TF", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); - inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); - - // inputs.emplace_back("rawfile", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); + inputs.emplace_back("file", o2::framework::ConcreteDataTypeMatcher{"ROUT", "RAWDATA"}, o2::framework::Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); - // outputs.emplace_back("HMP", "ORBITS", 0, o2::framework::Lifetime::Timeframe); - // outputs.emplace_back("HMP", "STATS", 0, o2::framework::Lifetime::Timeframe); - return DataProcessorSpec{ "HMP-DataDecoder", - inputs, + o2::framework::select(inputSpec.c_str()), outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"print", VariantType::Bool, false, {"print digits"}}} }; + Options{{"root-file", VariantType::String, "/tmp/hmpRawDecodeResults", {"Name of the Root file with the decoding results."}}} }; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index bcb364c202267..c491960a755ff 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -55,7 +55,7 @@ using RDH = o2::header::RDHAny; // Data decoder void DumpDigitsTask::init(framework::InitContext& ic) { - LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; + LOG(INFO) << "[HMPID Dump Digits - init() ] "; mPrintDigits = ic.options().get("print"); mIsOutputOnFile = false; @@ -66,36 +66,53 @@ void DumpDigitsTask::init(framework::InitContext& ic) mIsOutputOnFile = true; } } + + if (mPrintDigits) { + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + } + if (mIsOutputOnFile) { + mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + } + + mOrbit = -1; + mBc = -1; return; } void DumpDigitsTask::run(framework::ProcessingContext& pc) { - //LOG(INFO) << "Enter Dump run..."; + LOG(DEBUG) << "[HMPID Dump Digits - run() ] Enter Dump ..."; for (auto&& input : pc.inputs()) { if (input.spec->binding == "digits") { auto digits = pc.inputs().get>("digits"); - LOG(INFO) << "The size of the vector =" << digits.size(); + LOG(DEBUG) << "The size of the vector =" << digits.size(); if (mPrintDigits) { - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - for(o2::hmpid::Digit Dig : digits) { - std::cout << Dig << std::endl; - } - std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; + for(o2::hmpid::Digit Dig : digits) { + std::cout << Dig << std::endl; + } } if (mIsOutputOnFile) { - mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - for(o2::hmpid::Digit Dig : digits) { - mOsFile << Dig << std::endl; - } - mOsFile.close(); + for(o2::hmpid::Digit Dig : digits) { + mOsFile << Dig << std::endl; + if(Dig.getOrbit() != mOrbit || Dig.getBC() != mBc) { + mOrbit = Dig.getOrbit(); mBc = Dig.getBC(); + LOG(INFO) << "Event :" << mOrbit << " / " << mBc; + } + } } } } return; } +void DumpDigitsTask::endOfStream(framework::EndOfStreamContext& ec) +{ + mOsFile.close(); + LOG(INFO) << "End Dump !"; + return; +} + //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) //o2::framework::DataPrecessorSpec getDecodingSpec() diff --git a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx new file mode 100644 index 0000000000000..44428dad717cf --- /dev/null +++ b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx @@ -0,0 +1,153 @@ +// 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. + + +#include +#include +#include +#include + + + + + + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" + +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" +#include "DPLUtils/DPLRawParser.h" + + + + +#include "HMPIDWorkflow/ReadRawFileSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using namespace o2; +using namespace o2::framework; +using RDH = o2::header::RDHAny; + +//auto RawFileReaderTask::stop(void) +//{ +// LOG(INFO) << "Stop file reader"; +// mInputFile.close(); +// return; +//} + +void RawFileReaderTask::init(framework::InitContext& ic) +{ + LOG(INFO) << "Raw file reader init "; + + // read input parameters + mPrint = ic.options().get("print"); + std::string inFileName = ic.options().get("raw-file"); + mInputFile.open(inFileName, std::ios::binary); + if (!mInputFile.is_open()) { + throw std::invalid_argument("Cannot open input file \"" + inFileName + "\""); + } + + auto stop = [this]() { + LOG(INFO) << "stop file reader"; // close the input file + this->mInputFile.close(); + }; + ic.services().get().set(CallbackService::Id::Stop, stop); +} + + +void RawFileReaderTask::run(framework::ProcessingContext& pc) +{ + + RDH rdh; + char* outBuffer{nullptr}; + size_t bufSize{0}; + int numberOfFrames = 0; + LOG(INFO)<< "Sleep 5 sec"<< std::endl; + sleep(5); + + while (true) { + //usleep(100); + mInputFile.read((char*)(&rdh), sizeof(RDH)); // read the next RDH, stop if no more data is available + if (mInputFile.fail()) { + LOG(INFO) << "End of file ! Number of frames processed :" << numberOfFrames; + free(outBuffer); + mInputFile.close(); + // LOG(INFO)<< "Sleep 10 sec"<< std::endl; + // for(int i=0;i<10;i++) sleep(1); + pc.services().get().endOfStream(); + // pc.services().get().readyToQuit(framework::QuitRequest::Me); + break; + } + auto rdhVersion = o2::raw::RDHUtils::getVersion(rdh); + auto rdhHeaderSize = o2::raw::RDHUtils::getHeaderSize(rdh); + LOG(DEBUG) << "header_version=" << (int)rdhVersion; + if (rdhVersion < 6 || rdhHeaderSize != 64) { + LOG(INFO) << "Old or corrupted raw file, abort !"; + return; + } + auto frameSize = o2::raw::RDHUtils::getOffsetToNext(rdh); // get the frame size + LOG(DEBUG) << "frameSize=" << frameSize; + if (frameSize < rdhHeaderSize) { // stop if the frame size is too small + LOG(INFO) << "Wrong Frame size - frameSize too small: " << frameSize; + pc.services().get().endOfStream(); + return; + } + numberOfFrames++; + LOG(DEBUG) << "Process page " << numberOfFrames << " dim = " << frameSize; + + outBuffer = (char*)realloc(outBuffer, bufSize + frameSize); // allocate the buffer + if (outBuffer == nullptr) { + LOG(INFO) << "Buffer allocation error. Abort !"; + pc.services().get().endOfStream(); + return; + } + memcpy(outBuffer, &rdh, rdhHeaderSize); // fill the buffer + mInputFile.read(outBuffer + rdhHeaderSize, frameSize - rdhHeaderSize); + if (mInputFile.fail()) { // Could be EoF + LOG(INFO) << "end of file reached"; + free(outBuffer); + pc.services().get().endOfStream(); + break; // probably reached eof + } + bufSize = frameSize; // Set the buffer pointer + pc.outputs().snapshot(Output{"HMP","RAWDATA"}, outBuffer, bufSize); + } // while (true) +} + +//_________________________________________________________________________________________________ +// clang-format off +o2::framework::DataProcessorSpec getReadRawFileSpec(std::string inputSpec) +{ + std::vector inputs; + return DataProcessorSpec{ + "HMP-ReadRawFile", + inputs, + Outputs{OutputSpec{"HMP", "RAWDATA", 0, Lifetime::Timeframe}}, + AlgorithmSpec{adaptFromTask()}, + Options{{"raw-file", VariantType::String, "", {"Raw input file name"}}, + {"print", VariantType::Bool, false, {"verbose output"}}}}; +} +// clang-format on + +} // end namespace hmpid +} // end namespace o2 + diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index 00ede675778b3..6603e634b96b1 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -9,12 +9,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file DatDecoderSpec.cxx -/// \author -/// -/// \brief Implementation of a data processor to run the HMPID raw decoding -/// #include #include @@ -34,6 +28,7 @@ #include "Framework/Task.h" #include "Framework/WorkflowSpec.h" #include "Framework/Logger.h" +#include "Framework/InputRecordWalker.h" #include "Headers/RAWDataHeader.h" #include "DetectorsRaw/RDHUtils.h" @@ -57,10 +52,13 @@ using RDH = o2::header::RDHAny; // Data decoder void WriteRawFromDigitsTask::init(framework::InitContext& ic) { - LOG(INFO) << "[HMPID Write Raw File From Digits vector - run] Dumping ..."; + LOG(INFO) << "[HMPID Write Raw File From Digits vector - init()]"; mBaseFileName = ic.options().get("out-file"); - - + mSkipEmpty = ic.options().get("skip-empty"); + mFixedPacketLenght = ic.options().get("fixed-lenght"); + mOrderTheEvents = ic.options().get("order-events"); + mDigitsReceived = 0; + mFramesReceived = 0; return; } @@ -69,10 +67,8 @@ bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2:: uint64_t t1,t2; t1 = d1.getTriggerID(); t2 = d2.getTriggerID(); - if (t1 < t2) return true; if (t2 < t1) return false; - if (d1.getPadID() < d2.getPadID()) return true; return false; } @@ -80,28 +76,43 @@ bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2:: void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) { - for (auto&& input : pc.inputs()) { - if (input.spec->binding == "digits") { - auto digits = pc.inputs().get>("digits"); - - LOG(INFO) << "The size of the digits vector " << digits.size(); - sort(digits.begin(), digits.end(), eventEquipPadsComparision); - LOG(INFO) << "Digits sorted ! " ; - - HmpidCoder cod(Geo::MAXEQUIPMENTS); - cod.openOutputStream(mBaseFileName.c_str()); - //cod.codeDigitsTest(2, 100); - cod.codeDigitsVector(digits); - cod.closeOutputStream(); - LOG(INFO) << "Raw File created ! " ; - } + + for (auto const& ref : InputRecordWalker(pc.inputs())) { + std::vector digits = pc.inputs().get>(ref); + mDigits.insert(mDigits.end(), digits.begin(), digits.end()); + mDigitsReceived += digits.size(); + mFramesReceived++; + LOG(INFO) << "run() Digits received =" << mDigitsReceived << " frames = " << mFramesReceived; + } + return; +} + +void WriteRawFromDigitsTask::createRawFile(framework::ProcessingContext& pc) +{ + return; +} + + +void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) +{ + LOG(INFO) << "Received an End Of Stream !"; + HmpidCoder cod(Geo::MAXEQUIPMENTS, mSkipEmpty, mFixedPacketLenght); + cod.openOutputStream(mBaseFileName.c_str()); + + if(mOrderTheEvents) { + sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); + LOG(INFO) << mDigits.size() << " Digits sorted ! " ; } + //cod.codeDigitsTest(2, 100); + cod.codeDigitsVector(mDigits); + cod.closeOutputStream(); + LOG(INFO) << "Raw File created ! Digits received = " << mDigitsReceived << " Frame received =" << mFramesReceived; + cod.dumpResults(); return; } //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec) -//o2::framework::DataPrecessorSpec getDecodingSpec() { std::vector inputs; inputs.emplace_back("digits", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); @@ -109,11 +120,14 @@ o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec std::vector outputs; return DataProcessorSpec{ - "HMP-WriteRawFrtomDigits", + "HMP-WriteRawFromDigits", inputs, outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"out-file", VariantType::String, "hmpidRaw", {"name of the output file"}}} }; + Options{{"out-file", VariantType::String, "hmpidRaw", {"name of the output file"}}, + {"order-events", VariantType::Bool, false, {"order the events time"}}, + {"skip-empty", VariantType::Bool, false, {"skip empty events"}}, + {"fixed-lenght", VariantType::Bool, false, {"fixed lenght packets = 8K bytes"}}}}; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx index c84533839ce68..1b0936c00414a 100644 --- a/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx @@ -23,6 +23,18 @@ #include "Framework/CallbackService.h" #include "Framework/ControlService.h" #include "Framework/Task.h" +#include "Framework/CompletionPolicy.h" +#include "Framework/CompletionPolicyHelpers.h" +#include "Framework/DispatchPolicy.h" + +// customize the completion policy +void customize(std::vector& policies) +{ + using o2::framework::CompletionPolicy; + using o2::framework::CompletionPolicyHelpers; + policies.push_back(CompletionPolicyHelpers::defineByName("digit-hmpid-dump", CompletionPolicy::CompletionOp::Consume)); +} + #include "Framework/runDataProcessing.h" #include "HMPIDWorkflow/DumpDigitsSpec.h" diff --git a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx index ea0ee629fcce7..a674bd849cc62 100644 --- a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx @@ -8,21 +8,41 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file raw-to-digits-workflow.cxx -/// \author Andrea Ferrero -/// -/// \brief This is an executable that runs the decoding via DPL. -/// -/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. -/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow -/// #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" #include "Framework/CallbackService.h" #include "Framework/ControlService.h" #include "Framework/Task.h" +#include "Framework/CompletionPolicy.h" +#include "Framework/CompletionPolicyHelpers.h" +#include "Framework/DispatchPolicy.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/InputRecordWalker.h" +#include "Framework/Logger.h" +#include "Framework/ConfigParamSpec.h" + +// customize dispatch policy, dispatch immediately what is ready +void customize(std::vector& policies) +{ + using DispatchOp = o2::framework::DispatchPolicy::DispatchOp; + auto readerMatcher = [](auto const& spec) { + return true; + }; + auto triggerMatcher = [](auto const& query) { + return true; + }; + policies.push_back({"decoded-hmpid-digits", readerMatcher, DispatchOp::WhenReady, triggerMatcher}); +} + +// customize the completion policy +void customize(std::vector& policies) +{ + using o2::framework::CompletionPolicy; + using o2::framework::CompletionPolicyHelpers; + policies.push_back(CompletionPolicyHelpers::defineByName("raw-hmpid-decode", CompletionPolicy::CompletionOp::Consume)); +} + #include "Framework/runDataProcessing.h" #include "HMPIDWorkflow/DataDecoderSpec.h" diff --git a/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx b/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx new file mode 100644 index 0000000000000..eba897b0aa2e7 --- /dev/null +++ b/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx @@ -0,0 +1,62 @@ +// 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. + +#include +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/DispatchPolicy.h" +#include "Framework/Task.h" + + +// customize dispatch policy, dispatch immediately what is ready +void customize(std::vector& policies) +{ + using DispatchOp = o2::framework::DispatchPolicy::DispatchOp; + // we customize all devices to dispatch data immediately + auto readerMatcher = [](auto const& spec) { + // + // std::cout << "customize reader = " << spec.name << std::endl; +// std::cout << "PingReader" << std::endl; + return true; +// return std::regex_match(spec.name.begin(), spec.name.end(), std::regex(".*-reader")); + }; + auto triggerMatcher = [](auto const& query) { + // a bit of a hack but we want this to be configurable from the command line, + // however DispatchPolicy is inserted before all other setup. Triggering depending + // on the global variable set from the command line option. If scheduled messages + // are not triggered they are sent out at the end of the computation + // std::cout << "customize Trigger origin = " << query.origin << " description = " << query.description << std::endl; + // std::cout << "PingTrig" << std::endl; + return true; +// return gDispatchTrigger.origin == query.origin && gDispatchTrigger.description == query.description; + }; + policies.push_back({"pr-f-re", readerMatcher, DispatchOp::WhenReady, triggerMatcher}); +} + + +#include "Framework/runDataProcessing.h" + +#include "HMPIDWorkflow/ReadRawFileSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + // The producer to generate some data in the workflow + DataProcessorSpec producer = o2::hmpid::getReadRawFileSpec(); + specs.push_back(producer); + + return specs; +} diff --git a/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx index f9fcb800bb3ed..dda6d2a9ab76e 100644 --- a/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx @@ -8,21 +8,24 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file raw-to-digits-workflow.cxx -/// \author Andrea Ferrero -/// -/// \brief This is an executable that runs the decoding via DPL. -/// -/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. -/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow -/// #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" #include "Framework/CallbackService.h" #include "Framework/ControlService.h" #include "Framework/Task.h" +#include "Framework/CompletionPolicy.h" +#include "Framework/CompletionPolicyHelpers.h" +#include "Framework/DispatchPolicy.h" + +// customize the completion policy +void customize(std::vector& policies) +{ + using o2::framework::CompletionPolicy; + using o2::framework::CompletionPolicyHelpers; + policies.push_back(CompletionPolicyHelpers::defineByName("digit-hmpid-write", CompletionPolicy::CompletionOp::Consume)); +} + #include "Framework/runDataProcessing.h" #include "HMPIDWorkflow/WriteRawFromDigitsSpec.h" From 037c8774f66dd7b031d1daad5ae304700ab76701 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 4 Feb 2021 12:33:48 +0100 Subject: [PATCH 084/208] Some fix --- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 1 + .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 1 - .../HMPID/workflow/src/DumpDigitsSpec.cxx | 33 +++++++++---------- .../workflow/src/WriteRawFromDigitsSpec.cxx | 6 ---- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index 4d9d724c15bf1..d9150e5a48e3f 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -44,6 +44,7 @@ namespace hmpid int mOrbit; int mBc; + long mDigitsReceived; }; o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h index bfd44cbc588a6..9d27be22a24b8 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -33,7 +33,6 @@ namespace hmpid private: static bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); - void createRawFile(framework::ProcessingContext& pc); std::string mBaseFileName = ""; std::vector mDigits; bool mSkipEmpty = false; diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index c491960a755ff..fc9d144042680 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -76,29 +76,28 @@ void DumpDigitsTask::init(framework::InitContext& ic) mOrbit = -1; mBc = -1; + mDigitsReceived = 0; return; } void DumpDigitsTask::run(framework::ProcessingContext& pc) { LOG(DEBUG) << "[HMPID Dump Digits - run() ] Enter Dump ..."; - - for (auto&& input : pc.inputs()) { - if (input.spec->binding == "digits") { - auto digits = pc.inputs().get>("digits"); - LOG(DEBUG) << "The size of the vector =" << digits.size(); - if (mPrintDigits) { - for(o2::hmpid::Digit Dig : digits) { - std::cout << Dig << std::endl; - } + for (auto const& ref : InputRecordWalker(pc.inputs())) { + std::vector digits = pc.inputs().get>(ref); + LOG(DEBUG) << "The size of the vector =" << digits.size(); + mDigitsReceived += digits.size(); + if (mPrintDigits) { + for(o2::hmpid::Digit Dig : digits) { + std::cout << Dig << std::endl; } - if (mIsOutputOnFile) { - for(o2::hmpid::Digit Dig : digits) { - mOsFile << Dig << std::endl; - if(Dig.getOrbit() != mOrbit || Dig.getBC() != mBc) { - mOrbit = Dig.getOrbit(); mBc = Dig.getBC(); - LOG(INFO) << "Event :" << mOrbit << " / " << mBc; - } + } + if (mIsOutputOnFile) { + for(o2::hmpid::Digit Dig : digits) { + mOsFile << Dig << std::endl; + if(Dig.getOrbit() != mOrbit || Dig.getBC() != mBc) { + mOrbit = Dig.getOrbit(); mBc = Dig.getBC(); + LOG(INFO) << "Event :" << mOrbit << " / " << mBc; } } } @@ -109,7 +108,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) void DumpDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { mOsFile.close(); - LOG(INFO) << "End Dump !"; + LOG(INFO) << "End Digits Dump ! Dumped digits = " << mDigitsReceived; return; } diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index 6603e634b96b1..df46b6fe84686 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -87,12 +87,6 @@ void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) return; } -void WriteRawFromDigitsTask::createRawFile(framework::ProcessingContext& pc) -{ - return; -} - - void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { LOG(INFO) << "Received an End Of Stream !"; From 29b69d8627df33c36bd890de227c61b5f5462359 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 4 Feb 2021 13:08:02 +0100 Subject: [PATCH 085/208] Version 0 - Compiled and tested. Works fine the Read-decode-write workflow. tested with huge raw file, 176'235'199 digits. --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 1 + Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx | 5 ++--- Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index fc9d144042680..228ca63af4eec 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -33,6 +33,7 @@ #include "Framework/Task.h" #include "Framework/WorkflowSpec.h" #include "Framework/Logger.h" +#include "Framework/InputRecordWalker.h" #include "Headers/RAWDataHeader.h" #include "DetectorsRaw/RDHUtils.h" diff --git a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx index 44428dad717cf..f0ad87c6efd2f 100644 --- a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx +++ b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx @@ -91,10 +91,8 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) LOG(INFO) << "End of file ! Number of frames processed :" << numberOfFrames; free(outBuffer); mInputFile.close(); - // LOG(INFO)<< "Sleep 10 sec"<< std::endl; - // for(int i=0;i<10;i++) sleep(1); pc.services().get().endOfStream(); - // pc.services().get().readyToQuit(framework::QuitRequest::Me); + pc.services().get().readyToQuit(framework::QuitRequest::Me); break; } auto rdhVersion = o2::raw::RDHUtils::getVersion(rdh); @@ -126,6 +124,7 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) LOG(INFO) << "end of file reached"; free(outBuffer); pc.services().get().endOfStream(); + pc.services().get().readyToQuit(framework::QuitRequest::Me); break; // probably reached eof } bufSize = frameSize; // Set the buffer pointer diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index df46b6fe84686..d2655edecf038 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -97,7 +97,6 @@ void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); LOG(INFO) << mDigits.size() << " Digits sorted ! " ; } - //cod.codeDigitsTest(2, 100); cod.codeDigitsVector(mDigits); cod.closeOutputStream(); LOG(INFO) << "Raw File created ! Digits received = " << mDigitsReceived << " Frame received =" << mFramesReceived; From 741e2d08a325f5f01638881eb77080c3ade59a58 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 4 Feb 2021 15:57:21 +0100 Subject: [PATCH 086/208] V0.1 - Compiled and Tested Add the syncronous write of the File ! --- .../include/HMPIDSimulation/HmpidCoder.h | 12 ++- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 90 +++++++++++++------ .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 2 + .../workflow/src/WriteRawFromDigitsSpec.cxx | 24 +++-- 4 files changed, 91 insertions(+), 37 deletions(-) diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h index b6efa62ca85ed..e435e9fcc2cc9 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h @@ -78,6 +78,12 @@ class HmpidCoder long mPadsCoded; long mPacketsCoded; + std::vector mDigits; + uint32_t mPreviousOrbit = 0; + uint16_t mPreviousBc = 0; + long mLastProcessedDigit =0; + uint32_t *mPadMap; + public: HmpidCoder(int numOfEquipments, bool skipEmptyEvents = false, bool fixedPacketLenght = true); virtual ~HmpidCoder(); @@ -123,11 +129,14 @@ class HmpidCoder return(mOccupancyPercentage); }; + int addDigitsChunk(std::vector &digits); + void codeDigitsChunk(bool flushBuffer = false); + void codeDigitsVector(std::vector &digits); + void openOutputStream(const char *OutputFileName); void closeOutputStream(); void codeRandomEvent(uint32_t orbit, uint16_t bc); - void codeDigitsVector(std::vector); void codeTest(int Events, uint16_t charge); void dumpResults(); @@ -136,6 +145,7 @@ class HmpidCoder void createRandomPayloadPerEvent(); void savePacket(int Flp, int packetSize); int calculateNumberOfPads(); + void codeEventChunkDigits(std::vector &digits, bool flushVector = false); private: void getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId); diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index 866d776f6d368..e81fea90fffc3 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -43,6 +43,10 @@ HmpidCoder::HmpidCoder(int numOfEquipments, bool skipEmptyEvents, bool fixedPack mPayloadBufferPtr = (uint32_t *) std::malloc(mNumberOfEquipments * sizeof(uint32_t) * mPailoadBufferDimPerEquipment ); mEventBufferBasePtr = (uint32_t *) std::malloc(sizeof(uint32_t) * RAWBLOCKDIMENSION_W); mEventBufferPtr = mEventBufferBasePtr; + + mPadMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + // TODO: Add memory allocation error check + reset(); } @@ -52,6 +56,7 @@ HmpidCoder::~HmpidCoder() // TODO Auto-generated destructor stub std::free(mPayloadBufferPtr); std::free(mEventBufferBasePtr); + std::free(mPadMap); } void HmpidCoder::reset() @@ -59,6 +64,12 @@ void HmpidCoder::reset() srand( (unsigned)time(NULL) ); mPadsCoded = 0; mPacketsCoded = 0; + mDigits.clear(); + mPreviousOrbit = 0; + mPreviousBc = 0; + mLastProcessedDigit =0; + + return; } // ===================== Random production of Raw Files =================== @@ -98,13 +109,11 @@ void HmpidCoder::fillPadsMap(uint32_t *padMap) void HmpidCoder::createRandomPayloadPerEvent() { - uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); - memset(padMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); - fillPadsMap(padMap); - fillTheOutputBuffer(padMap); + fillPadsMap(mPadMap); + fillTheOutputBuffer(mPadMap); - std::free(padMap); return; } @@ -280,46 +289,72 @@ int HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t WordsToRead, uint32_t Pay return (OffsetNext); } -void HmpidCoder::codeDigitsVector(std::vectordigits) +void HmpidCoder::codeDigitsChunk(bool flushBuffer) +{ + codeEventChunkDigits(mDigits, flushBuffer); + return; +} + +int HmpidCoder::addDigitsChunk(std::vector &digits) +{ + mDigits.insert(mDigits.end(), digits.begin(), digits.end()); + return(mDigits.size()); +} + +void HmpidCoder::codeDigitsVector(std::vector &digits) +{ + codeEventChunkDigits(digits, true); + return; +} + +void HmpidCoder::codeEventChunkDigits(std::vector &digits, bool flushVector) { int eq,col,dil,cha,mo,x,y, idx; - uint32_t pv_orbit = 0; uint32_t orbit = 0; - uint16_t pv_bc = 0; uint16_t bc = 0; - uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); - // TODO: Add memory allocation error check - int padsCount =0; + int lastEventDigit = -1; + mLastProcessedDigit = -1; + for(o2::hmpid::Digit d : digits) { orbit = d.getOrbit(); bc = d.getBC(); - if(orbit != pv_orbit || bc != pv_bc) { //the event is changed - if (pv_orbit != 0 || pv_bc != 0 ) { // isn't the first ! - fillTheOutputBuffer(padMap); - writePaginatedEvent(pv_orbit, pv_bc); + lastEventDigit++; + + if(orbit != mPreviousOrbit || bc != mPreviousBc) { //the event is changed + if (mPreviousOrbit != 0 || mPreviousBc != 0 ) { // isn't the first ! + fillTheOutputBuffer(mPadMap); + writePaginatedEvent(mPreviousOrbit, mPreviousBc); + mLastProcessedDigit = lastEventDigit; } - memset(padMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event - pv_orbit = orbit; - pv_bc = bc; + memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event + mPreviousOrbit = orbit; + mPreviousBc = bc; } Digit::Pad2Equipment(d.getPadID(),&eq, &col, &dil, &cha); // From Digit to Hardware coords eq = mEqIds[eq]; // converts the Equipment Id in Cru/Link position ref idx = getEquipmentPadIndex(eq, col, dil, cha); // finally to the unique padmap index - if(padMap[idx] != 0) { // We already have the pad set + if(mPadMap[idx] != 0) { // We already have the pad set std::cerr << "HmpidCoder [ERROR] : Duplicated DIGIT ="<< d <<" ("<("order-events"); mDigitsReceived = 0; mFramesReceived = 0; + + mCod = new HmpidCoder(Geo::MAXEQUIPMENTS, mSkipEmpty, mFixedPacketLenght); + mCod->reset(); + mCod->openOutputStream(mBaseFileName.c_str()); + return; } @@ -76,10 +81,14 @@ bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2:: void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) { - for (auto const& ref : InputRecordWalker(pc.inputs())) { std::vector digits = pc.inputs().get>(ref); - mDigits.insert(mDigits.end(), digits.begin(), digits.end()); + if(mOrderTheEvents) { + mDigits.insert(mDigits.end(), digits.begin(), digits.end()); + } else { + mCod->addDigitsChunk(digits); + mCod->codeDigitsChunk(); + } mDigitsReceived += digits.size(); mFramesReceived++; LOG(INFO) << "run() Digits received =" << mDigitsReceived << " frames = " << mFramesReceived; @@ -90,17 +99,16 @@ void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { LOG(INFO) << "Received an End Of Stream !"; - HmpidCoder cod(Geo::MAXEQUIPMENTS, mSkipEmpty, mFixedPacketLenght); - cod.openOutputStream(mBaseFileName.c_str()); - if(mOrderTheEvents) { sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); LOG(INFO) << mDigits.size() << " Digits sorted ! " ; + mCod->codeDigitsVector(mDigits); + } else { + mCod->codeDigitsChunk(true); } - cod.codeDigitsVector(mDigits); - cod.closeOutputStream(); + mCod->closeOutputStream(); LOG(INFO) << "Raw File created ! Digits received = " << mDigitsReceived << " Frame received =" << mFramesReceived; - cod.dumpResults(); + mCod->dumpResults(); return; } From 9dcab2d5ebda3c305dd75441ed917a8087424f89 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 5 Feb 2021 10:58:55 +0100 Subject: [PATCH 087/208] V 1. Compiled and tested. Run modules in readme, implements the full streaming flow. Correct Root object creation. --- .../HMPID/base/include/HMPIDBase/Common.h | 73 ++++++++ .../HMPIDReconstruction/HmpidEquipment.h | 2 +- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 9 +- .../reconstruction/src/HmpidEquipment.cxx | 2 +- Detectors/HMPID/workflow/README.md | 91 ++++++++++ .../include/HMPIDWorkflow/DataDecoderSpec.h | 3 + .../include/HMPIDWorkflow/DumpDigitsSpec.h | 4 + .../HMPIDWorkflow/RawFileReaderSpec.h_trash | 49 ------ .../include/HMPIDWorkflow/ReadRawFileSpec.h | 5 +- .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 3 + .../HMPID/workflow/src/DataDecoderSpec.cxx | 83 ++++----- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 16 +- .../workflow/src/RawFileReaderSpec.cxx_trash | 157 ------------------ .../HMPID/workflow/src/ReadRawFileSpec.cxx | 29 ++-- .../workflow/src/WriteRawFromDigitsSpec.cxx | 12 +- .../src/rawfile-to-digits-workflow.cxx_trash | 43 ----- 16 files changed, 261 insertions(+), 320 deletions(-) create mode 100644 Detectors/HMPID/base/include/HMPIDBase/Common.h create mode 100644 Detectors/HMPID/workflow/README.md delete mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash delete mode 100644 Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash delete mode 100644 Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash diff --git a/Detectors/HMPID/base/include/HMPIDBase/Common.h b/Detectors/HMPID/base/include/HMPIDBase/Common.h new file mode 100644 index 0000000000000..37fc38f9049c1 --- /dev/null +++ b/Detectors/HMPID/base/include/HMPIDBase/Common.h @@ -0,0 +1,73 @@ +/* + * Common.h + * + * Created on: 5 feb 2021 + * Author: fap + */ + +#ifndef DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_COMMON_H_ +#define DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_COMMON_H_ + +#include +#include "Framework/Logger.h" + +namespace o2 +{ +namespace hmpid +{ + +// ------- Execution time functions +class ExecutionTimer +{ +private: + TStopwatch mTimer; + Double_t mStartTime; + Double_t mLastLogTime; + Double_t mElapseLogTime; + +public: + ExecutionTimer() { + mStartTime = 0; + mLastLogTime = 0; + mElapseLogTime = 10; // default 10 seconds + }; + + ~ExecutionTimer() {}; + + Double_t getElapseLogTime() { return mElapseLogTime; }; + void setElapseLogTime(Double_t interval) { mElapseLogTime = interval; return; }; + + void start() { + mStartTime = mTimer.CpuTime(); + mLastLogTime = mStartTime; + mTimer.Start(false); + return; + }; + + void stop() { + mTimer.Stop(); + return; + }; + + void logMes(std::string const message) { + LOG(INFO) << message << " Execution time = " << (mTimer.CpuTime() - mStartTime); + mTimer.Continue(); + return; + }; + + void elapseMes(std::string const message) { + if(mTimer.CpuTime() - mLastLogTime > mElapseLogTime) { + LOG(INFO) << message << " Execution time = " << (mTimer.CpuTime() - mStartTime); + mLastLogTime = mTimer.CpuTime(); + } + mTimer.Continue(); + return; + }; + +}; + +} +} + + +#endif /* DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_COMMON_H_ */ diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h index 2ed68883b2064..91f91987102ad 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h @@ -59,7 +59,7 @@ const int TH_NULLBUFFERPOINTER = 13; const int TH_BUFFEREMPTY = 12; const int TH_WRONGBUFFERDIM = 11; - +const uint64_t OUTRANGEEVENTNUMBER = 0x1FFFFFFFFFFF; class HmpidEquipment diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 5217550c16b0f..63b3102e33215 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -123,6 +123,10 @@ void HmpidDecoder::init() mEndStreamPtr = 0; mStartStreamPtr = 0; + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i]->init(); + } + } /// Returns the Equipment Index (Pointer of the array) converting @@ -437,6 +441,9 @@ void HmpidDecoder::updateStatistics(HmpidEquipment *eq) eq->mNumberOfWrongEvents += 1; eq->mTotalPads += eq->mSampleNumber; eq->mTotalErrors += eq->mErrorsCounter; + + // std::cout << ">>>>.. end >>> "<mNumberOfEvents<<" :" <mEventSize<<","<< eq->mEventSizeAverage<< ", "<mEventNumber<<" "<mEventNumber) { // Is a new event - if (eq->mEventNumber != -1) { // skip the first + if (eq->mEventNumber != OUTRANGEEVENTNUMBER) { // skip the first updateStatistics(eq); // update previous statistics } eq->mNumberOfEvents++; diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx index ec1c99517bc06..9e92ac1151043 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx @@ -60,7 +60,7 @@ void HmpidEquipment::init() mErrorsCounter = 0; mErrorPadsPerEvent = 0; - mEventNumber = -1; + mEventNumber = OUTRANGEEVENTNUMBER; // The Magic out-range event number mNumberOfEvents = 0; mBusyTimeValue = 0.0; diff --git a/Detectors/HMPID/workflow/README.md b/Detectors/HMPID/workflow/README.md new file mode 100644 index 0000000000000..6e09e8bd71469 --- /dev/null +++ b/Detectors/HMPID/workflow/README.md @@ -0,0 +1,91 @@ + + +# DPL workflows for the HMPID + +## HMPID DPL processors + +* `hmpid-read-raw-file` reads data from ReadOut Raw File and outputs a stream of RDH6 pages as HMP/RAWDATA stream +* `hmpid-raw-to-digits` decodes the input raw pages stream (HMP/RAWDATA) and produces a vector of o2::hmpid::Digits (HMP/DIGITS) +* `hmpid-write-raw-from-digits` codes input o2::hmpid::Digits vector (HMP/DIGITS) into the binary HMPID raw file +* `hmpid-dump-digits` dumps the input o2::hmpid::Digits vector (HMP/DIGITS) to the stdout or in a ASCII file + +### Workflow example +The input is a HMPID rawfile and after the decoding the result is a reconstructed rawfile. + +``` + o2-hmpid-read-raw-file-workflow --raw-file test_full_flp1.raw -b | o2-hmpid-raw-to-digits-workflow -b | o2-hmpid-write-raw-from-digits-workflow --out-file /tmp/pippo -b +``` + +This reads the `test_full_flp1.raw` file and after the decodeing produce a couple of raw files in the /tmp/ folder that are prefixed with `pippo` + + + +### o2-hmpid-read-raw-file-workflow +Reads data from ReadOut Raw File and outputs a stream of RDH6 pages as HMP/RAWDATA stream. + +Display all options + +``` +o2-hmpid-read-raw-file-workflow --help full +``` + +Data processor options: HMP-ReadRawFile: + +``` +--raw-file arg Raw input file name +``` + +### o2-hmpid-raw-to-digits-workflow +Decodes the input raw pages stream (HMP/RAWDATA) and produces a vector of o2::hmpid::Digits (HMP/DIGITS). + +Display all options + +``` +o2-hmpid-raw-to-digits-workflow --help full +``` + +Data processor options: HMP-DataDecoder: + +``` + --root-file arg (=/tmp/hmpRawDecodeResults) + Name of the Root file with the decoding + results. +``` + + +### o2-hmpid-write-raw-from-digits-workflow +Codes input o2::hmpid::Digits vector (HMP/DIGITS) into the binary HMPID raw file. + +Display all options + +``` +o2-hmpid-write-raw-from-digits-workflow --help full +``` + +Data processor options: HMP-WriteRawFromDigits: + +``` + --out-file arg (=hmpidRaw) name prefix of the two output files + --order-events order the events in ascending time + --skip-empty skip empty events + --fixed-lenght fixed lenght packets = 8K bytes +``` + + +### o2-hmpid-dump-digits-workflow +Dumps the input o2::hmpid::Digits vector (HMP/DIGITS) to the stdout or in a ASCII file. + +Display all options + +``` +o2-hmpid-dump-digits-workflow --help full +``` + +Data processor options: HMP-DigitsDump: + +``` + --out-file arg name of the output file + --print print digits (default false ) +``` diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index 21e3227aa8706..035235156a047 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -15,6 +15,7 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" +#include "HMPIDBase/Common.h" #include "HMPIDReconstruction/HmpidDecodeRawMem.h" namespace o2 @@ -38,7 +39,9 @@ namespace hmpid HmpidDecodeRawDigit *mDeco; long mTotalDigits; long mTotalFrames; + std::string mRootStatFile; + ExecutionTimer mExTimer; }; o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec = "TF:HMP/RAWDATA"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index d9150e5a48e3f..615486fa44960 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -20,6 +20,8 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" + +#include "HMPIDBase/Common.h" #include "Framework/WorkflowSpec.h" namespace o2 @@ -45,6 +47,8 @@ namespace hmpid int mOrbit; int mBc; long mDigitsReceived; + + ExecutionTimer mExTimer; }; o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash b/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash deleted file mode 100644 index 90f252aa0afc1..0000000000000 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash +++ /dev/null @@ -1,49 +0,0 @@ -/* - * RawFilereader.h - * - * Created on: 18 gen 2021 - * Author: fap - */ - -#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ -#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ - -//#include -//#include -#include -//#include -//#include "Framework/CallbackService.h" -//#include "Framework/ConfigParamRegistry.h" -//#include "Framework/ControlService.h" -//#include "Framework/DataProcessorSpec.h" -//#include "Framework/Lifetime.h" -//#include "Framework/Output.h" -#include "Framework/Task.h" -//#include "Framework/WorkflowSpec.h" -#include "Framework/DataProcessorSpec.h" -//#include "Framework/runDataProcessing.h" - -namespace o2 -{ -namespace hmpid -{ - -class RawFileReaderTask : public framework::Task -{ - public: - RawFileReaderTask() = default; - ~RawFileReaderTask() override = default; - void init(framework::InitContext& ic) final; - void run(framework::ProcessingContext& pc) final; - - private: - std::ifstream mInputFile{}; ///< input file -}; - -o2::framework::DataProcessorSpec getRawFileReaderSpec(); -} // end namespace hmpid -} // end namespace o2 - - - -#endif /* DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ */ diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h index 5a952d105cf74..fab72e3185f12 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h @@ -14,6 +14,8 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" + +#include "HMPIDBase/Common.h" #include "HMPIDBase/Digit.h" namespace o2 @@ -32,7 +34,8 @@ namespace hmpid private: std::ifstream mInputFile{}; ///< input file bool mPrint = false; ///< print debug messages - // auto stop(void); + + ExecutionTimer mExTimer; }; o2::framework::DataProcessorSpec getReadRawFileSpec(std::string inputSpec = "HMP/RAWDATA"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h index e21bae9bb6cf2..54ac4d140a2b6 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -15,6 +15,8 @@ #include #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" + +#include "HMPIDBase/Common.h" #include "HMPIDBase/Digit.h" #include "HMPIDSimulation/HmpidCoder.h" @@ -44,6 +46,7 @@ namespace hmpid bool mIsTheStremClosed = false; HmpidCoder *mCod; + ExecutionTimer mExTimer; }; o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index b6a4e983497f0..0827dd287b185 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -64,76 +64,85 @@ void DataDecoderTask::init(framework::InitContext& ic) LOG(INFO) << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !"; + mRootStatFile = ic.options().get("root-file"); mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); mDeco->init(); mTotalDigits = 0; mTotalFrames = 0; + + mExTimer.start(); return; } void DataDecoderTask::run(framework::ProcessingContext& pc) { mDeco->mDigits.clear(); - decodeTF(pc); +// TODO: accept other types of Raw Streams ... // decodeReadout(pc); // decodeRawFile(pc); -// LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; -// pc.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginHMP, "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); - - - // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); - - //--- theObj->Reset(); - //---- mfileOut.reset(); - + mExTimer.elapseMes("... Decoding... Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); + return; } void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) { // Records the statistics - float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; - float avgBusyTime[o2::hmpid::Geo::MAXEQUIPMENTS]; - uint32_t numOfSamples[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - - TString filename = TString::Format("%s_%06d.root", "test", 1); + float avgEventSize;//[o2::hmpid::Geo::MAXEQUIPMENTS]; + float avgBusyTime;//[o2::hmpid::Geo::MAXEQUIPMENTS]; + float numOfSamples;//[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + float sumOfCharges;//[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + float squareOfCharges;//[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + float xb; + float yb; + + TString filename = TString::Format("%s_stat.root", mRootStatFile.c_str()); LOG(INFO) << "Create the stat file " << filename.Data(); TFile mfileOut(TString::Format("%s", filename.Data()), "RECREATE"); - TTree * theObj; - theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); - - theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); - theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); - theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); - theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); - theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); + TTree *theObj[Geo::N_MODULES+1]; + for(int i=0; iBranch("x", &xb,"s"); + theObj[i]->Branch("y", &yb,"s"); + theObj[i]->Branch("Samples", &numOfSamples,"i"); + theObj[i]->Branch("Sum_of_charges", &sumOfCharges,"l"); + theObj[i]->Branch("Sum_of_square", &squareOfCharges,"l"); + } + theObj[Geo::N_MODULES] = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); + theObj[Geo::N_MODULES]->Branch("Average_Event_Size", &avgEventSize,"F"); + theObj[Geo::N_MODULES]->Branch("Average_Busy_Time", &avgBusyTime,"F"); + char summaryFileName[254]; + sprintf(summaryFileName,"%s_stat.txt", mRootStatFile.c_str()); + mDeco->writeSummaryFile(summaryFileName); int numEqui = mDeco->getNumberOfEquipments(); for(int e=0;egetAverageEventSize(e); - avgBusyTime[e] = mDeco->getAverageBusyTime(e); + avgEventSize = mDeco->getAverageEventSize(e); + avgBusyTime = mDeco->getAverageBusyTime(e); + theObj[Geo::N_MODULES]->Fill(); } for(int m=0; m < o2::hmpid::Geo::N_MODULES; m++) for(int y=0; y < o2::hmpid::Geo::N_YCOLS; y++) for(int x=0; x < o2::hmpid::Geo::N_XROWS; x++ ) { - numOfSamples[m][y][x] = mDeco->getPadSamples(m, x, y); - sumOfCharges[m][y][x] = mDeco->getPadSum(m, x, y); - squareOfCharges[m][y][x] = mDeco->getPadSquares(m, x, y); + xb = x; + yb = y; + numOfSamples = mDeco->getPadSamples(m, x, y); + sumOfCharges = mDeco->getPadSum(m, x, y); + squareOfCharges = mDeco->getPadSquares(m, x, y); + theObj[m]->Fill(); } - // theObj->Fill(); - theObj->Write(); - LOG(INFO) << "End the Decoding ! Digits decoded = " << mTotalDigits << " Frames received = " << mTotalFrames; - // LOG(INFO)<< "Sleep 10 sec"<< std::endl; - // sleep(30); + for(int i=0; i<=Geo::N_MODULES; i++) { + theObj[i]->Write(); + } + mExTimer.logMes("End the Decoding ! Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); + mExTimer.stop(); //ec.services().get().endOfStream(); - // ec.services().get().readyToQuit(framework::QuitRequest::Me); + // ec.services().get().readyToQuit(framework::QuitRequest::Me); return; - } //_________________________________________________________________________________________________ // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 228ca63af4eec..cf24fe0abca58 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -67,17 +67,14 @@ void DumpDigitsTask::init(framework::InitContext& ic) mIsOutputOnFile = true; } } - - if (mPrintDigits) { - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - } - if (mIsOutputOnFile) { - mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - } + if (mPrintDigits) std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + if (mIsOutputOnFile) mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; mOrbit = -1; mBc = -1; mDigitsReceived = 0; + + mExTimer.start(); return; } @@ -103,13 +100,16 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) } } } + mExTimer.elapseMes( "... Dumping... Digits received = " + std::to_string(mDigitsReceived)); return; } void DumpDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { mOsFile.close(); - LOG(INFO) << "End Digits Dump ! Dumped digits = " << mDigitsReceived; + + mExTimer.stop(); + mExTimer.logMes("End Digits Dump ! Dumped digits = " + std::to_string(mDigitsReceived)); return; } diff --git a/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash b/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash deleted file mode 100644 index b87e288dd055e..0000000000000 --- a/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash +++ /dev/null @@ -1,157 +0,0 @@ -// 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 RawFileReaderSpec.cxx -/// \author Antonio Franco -/// -/// \brief This is an executable that reads a data file from disk and sends the individual CRU pages via DPL. -/// -/// This is an executable that reads a data file from disk and sends the individual CRU pages via the Data Processing Layer. -// - -#include -#include -#include -#include -#include -#include -#include - -#include "Framework/CallbackService.h" -#include "Framework/ConfigParamRegistry.h" -#include "Framework/ControlService.h" -#include "Framework/DataProcessorSpec.h" -#include "Framework/Lifetime.h" -#include "Framework/Output.h" -#include "Framework/Task.h" -#include "Framework/WorkflowSpec.h" -#include "Framework/Logger.h" - - -#include "DPLUtils/DPLRawParser.h" -#include "Headers/RAWDataHeader.h" -#include "DetectorsRaw/RDHUtils.h" - -#include "HMPIDWorkflow/RawFileReaderSpec.h" - -namespace o2 -{ -namespace hmpid -{ - -using RDH = o2::header::RDHAny; -using namespace o2; -using namespace o2::framework; - - -void RawFileReaderTask::init(framework::InitContext& ic) -{ - // Get the input file and other options from the context - LOG(INFO) << "Raw file reader Init"; -std::cout << ">>> INIT !" << std::endl; - auto inputFileName = ic.options().get("input-file"); - mInputFile.open(inputFileName, std::ios::binary); - if (!mInputFile.is_open()) { - throw std::invalid_argument("Cannot open input file \"" + inputFileName + "\""); - } - - // define the callback to close the file - auto stop = [this]() { - LOG(INFO) << "stop file reader"; - this->mInputFile.close(); - }; - ic.services().get().set(CallbackService::Id::Stop, stop); -} - -//_________________________________________________________________________________________________ -void RawFileReaderTask::run(framework::ProcessingContext& pc) -{ - // send one RDH block via DPL - RDH rdh; - char* buf{nullptr}; - size_t bufSize{0}; - - while (true) { - - // read the next RDH, stop if no more data is available - mInputFile.read((char*)(&rdh), sizeof(RDH)); - if (mInputFile.fail()) { - pc.services().get().endOfStream(); - LOG(INFO) << " Fails to read the header ! "; - return; // probably reached eof - } - - // check that the RDH version is ok (only RDH versions from 4 to 6 are supported at the moment) - auto rdhVersion = o2::raw::RDHUtils::getVersion(rdh); - auto rdhHeaderSize = o2::raw::RDHUtils::getHeaderSize(rdh); - if (rdhVersion != 6 || rdhHeaderSize != 64) { - LOG(WARNING) << " Wrong RDH (v." << rdhVersion << ", size=" << rdhHeaderSize << ")"; - return; - } - std::cout<<"h"; - // get the frame size from the RDH offsetToNext field - auto frameSize = o2::raw::RDHUtils::getOffsetToNext(rdh); - - // stop if the frame size is too small - if (frameSize < rdhHeaderSize) { - LOG(WARNING) << " FrameSize too small: " << frameSize; - pc.services().get().endOfStream(); - return; - } - - // allocate the output buffer - buf = (char*)realloc(buf, frameSize); - if (buf == nullptr) { - LOG(ERROR) << " Failed to allocate buffer"; - pc.services().get().endOfStream(); - return; - } - - // copy the RDH into the output buffer - memcpy(buf, &rdh, rdhHeaderSize); - - // read the frame payload into the output buffer - mInputFile.read(buf + rdhHeaderSize, frameSize - rdhHeaderSize); - std::cout<<"p"; - // stop if data cannot be read completely - if (mInputFile.fail()) { - LOG(ERROR) << "Fail to read the payload "; - free(buf); - pc.services().get().endOfStream(); - return; // probably reached eof - } - // create the output message - auto freefct = [](void* data, void* /*hint*/) { free(data); }; - - pc.outputs().make(Output{"HMP","rawfile"},buf, bufSize ); -// pc.outputs().snapshot(Output{"HMP", "rawfile", 0, o2::framework::Lifetime::Timeframe}, buf); -// pc.outputs().adoptChunk(Output{"HMP", "rawfile"}, buf, bufSize, freefct, nullptr); - std::cout<<"w"<()}, - Options{{"input-file", VariantType::String, "", {"input raw file name"}}}}; -} -// clang-format on - - -} // end namespace mch -} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx index f0ad87c6efd2f..24bb0f751b6f3 100644 --- a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx +++ b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx @@ -14,11 +14,6 @@ #include #include - - - - - #include "Framework/CallbackService.h" #include "Framework/ConfigParamRegistry.h" #include "Framework/ControlService.h" @@ -33,9 +28,6 @@ #include "DetectorsRaw/RDHUtils.h" #include "DPLUtils/DPLRawParser.h" - - - #include "HMPIDWorkflow/ReadRawFileSpec.h" namespace o2 @@ -47,12 +39,6 @@ using namespace o2; using namespace o2::framework; using RDH = o2::header::RDHAny; -//auto RawFileReaderTask::stop(void) -//{ -// LOG(INFO) << "Stop file reader"; -// mInputFile.close(); -// return; -//} void RawFileReaderTask::init(framework::InitContext& ic) { @@ -71,6 +57,9 @@ void RawFileReaderTask::init(framework::InitContext& ic) this->mInputFile.close(); }; ic.services().get().set(CallbackService::Id::Stop, stop); + + mExTimer.start(); + return; } @@ -81,14 +70,13 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) char* outBuffer{nullptr}; size_t bufSize{0}; int numberOfFrames = 0; - LOG(INFO)<< "Sleep 5 sec"<< std::endl; - sleep(5); + LOG(INFO)<< "Sleep 1 sec for sync"; + sleep(1); while (true) { //usleep(100); mInputFile.read((char*)(&rdh), sizeof(RDH)); // read the next RDH, stop if no more data is available if (mInputFile.fail()) { - LOG(INFO) << "End of file ! Number of frames processed :" << numberOfFrames; free(outBuffer); mInputFile.close(); pc.services().get().endOfStream(); @@ -121,7 +109,6 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) memcpy(outBuffer, &rdh, rdhHeaderSize); // fill the buffer mInputFile.read(outBuffer + rdhHeaderSize, frameSize - rdhHeaderSize); if (mInputFile.fail()) { // Could be EoF - LOG(INFO) << "end of file reached"; free(outBuffer); pc.services().get().endOfStream(); pc.services().get().readyToQuit(framework::QuitRequest::Me); @@ -129,7 +116,13 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) } bufSize = frameSize; // Set the buffer pointer pc.outputs().snapshot(Output{"HMP","RAWDATA"}, outBuffer, bufSize); +//std::cout << mExTimer.mTimer.CpuTime() << " " << mExTimer.mLastLogTime << std::endl; + mExTimer.elapseMes("... Reading... Number of Pages = " + std::to_string(numberOfFrames)); } // while (true) + + mExTimer.logMes("End of file ! Number of frames processed = " + std::to_string(numberOfFrames)); + mExTimer.stop(); + return; } //_________________________________________________________________________________________________ diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index ce020729564a5..66156b4c5dd59 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -64,6 +64,7 @@ void WriteRawFromDigitsTask::init(framework::InitContext& ic) mCod->reset(); mCod->openOutputStream(mBaseFileName.c_str()); + mExTimer.start(); return; } @@ -91,24 +92,27 @@ void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) } mDigitsReceived += digits.size(); mFramesReceived++; - LOG(INFO) << "run() Digits received =" << mDigitsReceived << " frames = " << mFramesReceived; + LOG(DEBUG) << "run() Digits received =" << mDigitsReceived << " frames = " << mFramesReceived; } + mExTimer.elapseMes("... Write raw file ... Digits received = " + std::to_string(mDigitsReceived) + " Frames received = " + std::to_string(mFramesReceived)); return; } void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { - LOG(INFO) << "Received an End Of Stream !"; + mExTimer.logMes("Received an End Of Stream !"); if(mOrderTheEvents) { sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); - LOG(INFO) << mDigits.size() << " Digits sorted ! " ; + mExTimer.logMes("We sort " + std::to_string(mDigits.size()) + " ! "); mCod->codeDigitsVector(mDigits); } else { mCod->codeDigitsChunk(true); } mCod->closeOutputStream(); - LOG(INFO) << "Raw File created ! Digits received = " << mDigitsReceived << " Frame received =" << mFramesReceived; mCod->dumpResults(); + + mExTimer.logMes( "Raw File created ! Digits received = " + std::to_string(mDigitsReceived) + " Frame received =" + std::to_string(mFramesReceived)); + mExTimer.stop(); return; } diff --git a/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash b/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash deleted file mode 100644 index 52bd546179a25..0000000000000 --- a/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash +++ /dev/null @@ -1,43 +0,0 @@ -// 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 raw-to-digits-workflow.cxx -/// \author Andrea Ferrero -/// -/// \brief This is an executable that runs the decoding via DPL. -/// -/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. -/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow -/// - -#include "Framework/WorkflowSpec.h" -#include "Framework/DataSpecUtils.h" -#include "Framework/CallbackService.h" -#include "Framework/ControlService.h" -#include "Framework/Task.h" -#include "Framework/runDataProcessing.h" - -#include "HMPIDWorkflow/RawFileReaderSpec.h" - -using namespace o2; -using namespace o2::framework; - -WorkflowSpec defineDataProcessing(const ConfigContext&) -{ - WorkflowSpec specs; - - DataProcessorSpec producer = o2::hmpid::getRawFileReaderSpec(); -// DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); - specs.push_back(producer); -// specs.push_back(consumer); - - return specs; -} From aefe665633ca9dbf7d0571f1683e27d825645c2b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 5 Feb 2021 15:42:45 +0100 Subject: [PATCH 088/208] Try --- Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index 66156b4c5dd59..f444023871a87 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -1,4 +1,4 @@ -// draft +// V0.1 // 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". From 87b9d081cf6ccfdbf7938f123757ed4f130bd692 Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 8 Feb 2021 10:54:04 +0100 Subject: [PATCH 089/208] Fix the erase digit vector bug --- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index e81fea90fffc3..70e2cd91bcf73 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -352,7 +352,8 @@ void HmpidCoder::codeEventChunkDigits(std::vector &digits, bool flushVect writePaginatedEvent(orbit, bc); digits.clear(); } else { - digits.erase(digits.begin(), digits.begin() + mLastProcessedDigit); + if(mLastProcessedDigit>=0) + digits.erase(digits.begin(), digits.begin() + mLastProcessedDigit); } memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event return; From a1dcaffe729394b25e1e2c16d041ba8c8c30b756 Mon Sep 17 00:00:00 2001 From: Giacomo Volpe Date: Thu, 8 Aug 2019 15:41:42 +0200 Subject: [PATCH 090/208] WIP: clusterizer workflow --- Detectors/HMPID/CMakeLists.txt | 2 + Detectors/HMPID/base/CMakeLists.txt | 5 +- .../HMPID/base/include/HMPIDBase/Cluster.h | 33 ++++++ Detectors/HMPID/base/src/Cluster.cxx | 18 +++ Detectors/HMPID/reconstruction/CMakeLists.txt | 18 +++ .../include/HMPIDReconstruction/Clusterer.h | 59 ++++++++++ .../include/HMPIDReconstruction/DataReader.h | 12 ++ .../HMPID/reconstruction/src/Clusterer.cxx | 63 ++++++++++ .../HMPID/reconstruction/src/DataReader.cxx | 12 ++ .../src/HMPIDReconstructionLinkDef.h | 20 ++++ Detectors/HMPID/workflow/CMakeLists.txt | 23 ++++ .../include/HMPIDWorkflow/ClusterizerSpec.h | 26 ++++ .../include/HMPIDWorkflow/DigitReaderSpec.h | 52 ++++++++ .../HMPID/workflow/src/ClusterizerSpec.cxx | 111 ++++++++++++++++++ .../HMPID/workflow/src/DigitReaderSpec.cxx | 90 ++++++++++++++ .../HMPID/workflow/src/HMPIDRecoWorkflow.cxx | 35 ++++++ 16 files changed, 577 insertions(+), 2 deletions(-) create mode 100644 Detectors/HMPID/base/include/HMPIDBase/Cluster.h create mode 100644 Detectors/HMPID/base/src/Cluster.cxx create mode 100644 Detectors/HMPID/reconstruction/CMakeLists.txt create mode 100644 Detectors/HMPID/reconstruction/include/HMPIDReconstruction/Clusterer.h create mode 100644 Detectors/HMPID/reconstruction/include/HMPIDReconstruction/DataReader.h create mode 100644 Detectors/HMPID/reconstruction/src/Clusterer.cxx create mode 100644 Detectors/HMPID/reconstruction/src/DataReader.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h create mode 100644 Detectors/HMPID/workflow/CMakeLists.txt create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/ClusterizerSpec.h create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/DigitReaderSpec.h create mode 100644 Detectors/HMPID/workflow/src/ClusterizerSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/DigitReaderSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/HMPIDRecoWorkflow.cxx diff --git a/Detectors/HMPID/CMakeLists.txt b/Detectors/HMPID/CMakeLists.txt index 46b43743c005e..f9ecc0c9f62be 100644 --- a/Detectors/HMPID/CMakeLists.txt +++ b/Detectors/HMPID/CMakeLists.txt @@ -10,3 +10,5 @@ add_subdirectory(base) add_subdirectory(simulation) +add_subdirectory(reconstruction) +add_subdirectory(workflow) diff --git a/Detectors/HMPID/base/CMakeLists.txt b/Detectors/HMPID/base/CMakeLists.txt index 5f1940e8a6597..424f49648c968 100644 --- a/Detectors/HMPID/base/CMakeLists.txt +++ b/Detectors/HMPID/base/CMakeLists.txt @@ -9,10 +9,11 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDBase - SOURCES src/Param.cxx src/Digit.cxx + SOURCES src/Param.cxx src/Digit.cxx src/Cluster.cxx PUBLIC_LINK_LIBRARIES O2::CommonDataFormat O2::SimulationDataFormat ROOT::Physics) o2_target_root_dictionary(HMPIDBase HEADERS include/HMPIDBase/Param.h - include/HMPIDBase/Digit.h) + include/HMPIDBase/Digit.h + include/HMPIDBase/Cluster.h) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Cluster.h b/Detectors/HMPID/base/include/HMPIDBase/Cluster.h new file mode 100644 index 0000000000000..764dcfcf9c602 --- /dev/null +++ b/Detectors/HMPID/base/include/HMPIDBase/Cluster.h @@ -0,0 +1,33 @@ +// 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. + +#ifndef DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_CLUSTER_H_ +#define DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_CLUSTER_H_ + +#include "CommonDataFormat/TimeStamp.h" +//#include "HMPIDBase/Hit.h" // for hit +#include "HMPIDBase/Param.h" // for param +#include "TMath.h" + +namespace o2 +{ +namespace hmpid +{ + +/// \class Claster +/// \brief HMPID cluster implementation +class Cluster +{ +}; + +} // namespace hmpid +} // namespace o2 + +#endif /* DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_CLUSTER_H_ */ diff --git a/Detectors/HMPID/base/src/Cluster.cxx b/Detectors/HMPID/base/src/Cluster.cxx new file mode 100644 index 0000000000000..6c5dec851a0ad --- /dev/null +++ b/Detectors/HMPID/base/src/Cluster.cxx @@ -0,0 +1,18 @@ +// 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. + +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Param.h" +#include "TRandom.h" +#include "TMath.h" + +using namespace o2::hmpid; + +ClassImp(o2::hmpid::Digit); diff --git a/Detectors/HMPID/reconstruction/CMakeLists.txt b/Detectors/HMPID/reconstruction/CMakeLists.txt new file mode 100644 index 0000000000000..a9e882fa411b7 --- /dev/null +++ b/Detectors/HMPID/reconstruction/CMakeLists.txt @@ -0,0 +1,18 @@ +# 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. + +o2_add_library(HMPIDReconstruction + SOURCES src/Clusterer.cxx src/DataReader.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDBase + O2::HMPIDSimulation) + +o2_target_root_dictionary(HMPIDReconstruction + HEADERS include/HMPIDReconstruction/Clusterer.h + include/HMPIDReconstruction/DataReader.h) diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/Clusterer.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/Clusterer.h new file mode 100644 index 0000000000000..461729f2704e5 --- /dev/null +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/Clusterer.h @@ -0,0 +1,59 @@ +// 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 Clusterer.h +/// \brief Definition of the HMPID cluster finder +#ifndef ALICEO2_HMPID_CLUSTERER_H +#define ALICEO2_HMPID_CLUSTERER_H + +#include +#include +#include "HMPIDBase/Cluster.h" +#include "HMPIDBase/Digit.h" +#include "SimulationDataFormat/MCTruthContainer.h" +#include "SimulationDataFormat/MCCompLabel.h" + +namespace o2 +{ + +namespace hmpid +{ +class Clusterer +{ + using MCLabelContainer = o2::dataformats::MCTruthContainer; + using Cluster = o2::hmpid::Cluster; + using Digit = o2::hmpid::Digit; + + public: + Clusterer() = default; + ~Clusterer() = default; + + Clusterer(const Clusterer&) = delete; + Clusterer& operator=(const Clusterer&) = delete; + + void process(std::vector const& digits, std::vector& clusters, MCLabelContainer const* digitMCTruth); + + void setMCTruthContainer(o2::dataformats::MCTruthContainer* truth) { mClsLabels = truth; } + + private: + //void processChamber(std::vector& clusters, MCLabelContainer const* digitMCTruth); + //void fetchMCLabels(const Digit* dig, std::array& labels, int& nfilled) const; + + o2::dataformats::MCTruthContainer* mClsLabels = nullptr; // Cluster MC labels + + Digit* mContributingDigit[6]; //! array of digits contributing to the cluster; this will not be stored, it is temporary to build the final cluster + int mNumberOfContributingDigits; //! number of digits contributing to the cluster; this will not be stored, it is temporary to build the final cluster + void addContributingDigit(Digit* dig); + void buildCluster(Cluster& c, MCLabelContainer const* digitMCTruth); +}; + +} // namespace hmpid +} // namespace o2 +#endif /* ALICEO2_TOF_CLUSTERER_H */ diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/DataReader.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/DataReader.h new file mode 100644 index 0000000000000..e0cfd8791af4a --- /dev/null +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/DataReader.h @@ -0,0 +1,12 @@ +// 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 DataReader.h +/// \brief Definition of the TOF hit reader diff --git a/Detectors/HMPID/reconstruction/src/Clusterer.cxx b/Detectors/HMPID/reconstruction/src/Clusterer.cxx new file mode 100644 index 0000000000000..089b63787cde8 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/Clusterer.cxx @@ -0,0 +1,63 @@ +// 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 Clusterer.cxx +/// \brief Implementation of the HMPID cluster finder +#include +#include "FairLogger.h" // for LOG +#include "HMPIDBase/Cluster.h" +#include "HMPIDReconstruction/Clusterer.h" +#include "SimulationDataFormat/MCCompLabel.h" +#include "SimulationDataFormat/MCTruthContainer.h" +#include + +using namespace o2::hmpid; + +//__________________________________________________ +void Clusterer::process(std::vector const& digits, std::vector& clusters, MCLabelContainer const* digitMCTruth) +{ + TStopwatch timerProcess; + timerProcess.Start(); + + // reader.init(); + // int totNumDigits = 0; + // + // while (reader.getNextStripData(mStripData)) { + // LOG(DEBUG) << "HMPIDClusterer got Strip " << mStripData.stripID << " with Ndigits " + // << mStripData.digits.size(); + // totNumDigits += mStripData.digits.size(); + // + // processStrip(clusters, digitMCTruth); + // } + + // LOG(DEBUG) << "We had " << totNumDigits << " digits in this event"; + timerProcess.Stop(); + printf("Timing:\n"); + printf("Clusterer::process: "); + timerProcess.Print(); +} + +////__________________________________________________ +//void Clusterer::dig2Clu(std::vector& clusters, MCLabelContainer const* digitMCTruth) +//{ +// // method to clusterize +// +// // to be implemented +// +//} +////______________________________________________________________________ +//void Clusterer::formClu(Cluster& c, Digit* dig, o2::hmpid::Digit>& digits, MCLabelContainer const* digitMCTruth) +//{ +// // method to clusterize +// +// // to be implemented +// +//} +//______________________________________________________________________ diff --git a/Detectors/HMPID/reconstruction/src/DataReader.cxx b/Detectors/HMPID/reconstruction/src/DataReader.cxx new file mode 100644 index 0000000000000..b2306eab0eb09 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/DataReader.cxx @@ -0,0 +1,12 @@ +// 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 Clusterer.cxx +/// \brief Implementation of the HMPID data reader class diff --git a/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h b/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h new file mode 100644 index 0000000000000..23608c4bc6a4c --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h @@ -0,0 +1,20 @@ +// 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. + +#ifdef __CLING__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ class o2::hmpid::DataReader + ; +#pragma link C++ class o2::hmpid::Clusterer + ; + +#endif diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt new file mode 100644 index 0000000000000..78a7a79e3c9ea --- /dev/null +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -0,0 +1,23 @@ +# 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. + +o2_add_library(HMPIDWorkflow + SOURCES src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDBase + O2::HMPIDSimulation + O2::HMPIDReconstruction + O2::Framework) + +o2_add_executable(recoworkflow + COMPONENT_NAME hmpid + SOURCES src/HMPIDRecoWorkflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + + diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/ClusterizerSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ClusterizerSpec.h new file mode 100644 index 0000000000000..bf5f5bdbb5313 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ClusterizerSpec.h @@ -0,0 +1,26 @@ +// 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. + +#ifndef STEER_DIGITIZERWORKFLOW_HMPIDCLUSTERIZER_H_ +#define STEER_DIGITIZERWORKFLOW_HMPIDCLUSTERIZER_H_ + +#include "Framework/DataProcessorSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +o2::framework::DataProcessorSpec getHMPIDClusterizerSpec(bool useMC); + +} // end namespace hmpid +} // end namespace o2 + +#endif /* STEER_DIGITIZERWORKFLOW_HMPIDCLUSTERIZERSPEC_H_ */ diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DigitReaderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DigitReaderSpec.h new file mode 100644 index 0000000000000..147c7f22976c5 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DigitReaderSpec.h @@ -0,0 +1,52 @@ +// 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 DigitReader.h + +#ifndef O2_HMPID_DIGITREADER +#define O2_HMPID_DIGITREADER + +#include "TFile.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" +#include "HMPIDBase/Digit.h" +#include "SimulationDataFormat/MCCompLabel.h" +#include "SimulationDataFormat/MCTruthContainer.h" + +namespace o2 +{ +namespace hmpid +{ + +class DigitReader : public o2::framework::Task +{ + public: + DigitReader(bool useMC) : mUseMC(useMC) {} + ~DigitReader() override = default; + void init(o2::framework::InitContext& ic) final; + void run(o2::framework::ProcessingContext& pc) final; + + private: + int mState = 0; + bool mUseMC = true; + std::unique_ptr mFile = nullptr; + + std::vector mDigits, *mPdigits = &mDigits; + + o2::dataformats::MCTruthContainer mLabels, *mPlabels = &mLabels; +}; + +/// read simulated HMPID digits from a root file +framework::DataProcessorSpec getDigitReaderSpec(bool useMC); + +} // namespace hmpid +} // namespace o2 + +#endif /* O2_HMPID_DIGITREADER */ diff --git a/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx b/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx new file mode 100644 index 0000000000000..463a3f97753ee --- /dev/null +++ b/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx @@ -0,0 +1,111 @@ +// 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. + +#include "HMPIDWorkflow/ClusterizerSpec.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/DataRefUtils.h" +#include "Framework/Lifetime.h" +#include "Framework/Task.h" +#include "Headers/DataHeader.h" +#include "HMPIDReconstruction/Clusterer.h" +#include "HMPIDBase/Cluster.h" +#include "SimulationDataFormat/MCTruthContainer.h" +#include "SimulationDataFormat/MCCompLabel.h" +#include // for make_shared, make_unique, unique_ptr +#include + +using namespace o2::framework; + +namespace o2 +{ +namespace hmpid +{ + +// use the tasking system of DPL +// just need to implement 2 special methods init + run (there is no need to inherit from anything) +class HMPIDDPLClustererTask +{ + using MCLabelContainer = o2::dataformats::MCTruthContainer; + bool mUseMC = true; + + public: + explicit HMPIDDPLClustererTask(bool useMC) : mUseMC(useMC) {} + void init(framework::InitContext& ic) + { + // nothing special to be set up + } + + void run(framework::ProcessingContext& pc) + { + static bool finished = false; + if (finished) { + return; + } + // get digit data + auto digits = pc.inputs().get*>("hmpiddigits"); + LOG(INFO) << "RECEIVED " << digits->size() << " DIGITS"; + auto labelvector = std::make_shared>(); + if (mUseMC) { + auto digitlabels = pc.inputs().get*>("hmpiddigitlabels"); + *labelvector.get() = std::move(*digitlabels); + mClusterer.setMCTruthContainer(&mClsLabels); + mClsLabels.clear(); + } + // call actual clustering routine + mClustersArray.clear(); + + if (mUseMC) { + mClusterer.process(*digits.get(), mClustersArray, labelvector.get()); + } else { + mClusterer.process(*digits.get(), mClustersArray, nullptr); + } + + LOG(INFO) << "HMPID CLUSTERER : TRANSFORMED " << digits->size() + << " DIGITS TO " << mClustersArray.size() << " CLUSTERS"; + + // send clusters + //pc.outputs().snapshot(Output{"HMP", "CLUSTERS", 0, Lifetime::Timeframe}, mClustersArray); + // send labels + if (mUseMC) { + //pc.outputs().snapshot(Output{"HMP", "CLUSTERSMCTR", 0, Lifetime::Timeframe}, mClsLabels); + } + + // declare done + finished = true; + pc.services().get().readyToQuit(false); + } + + private: + Clusterer mClusterer; ///< Cluster finder + + std::vector mClustersArray; ///< Array of clusters + MCLabelContainer mClsLabels; +}; + +o2::framework::DataProcessorSpec getHMPIDClusterizerSpec(bool useMC) +{ + std::vector inputs; + inputs.emplace_back("hmpiddigits", "HMP", "DIGITS", 0, Lifetime::Timeframe); + if (useMC) + inputs.emplace_back("hmpiddigitlabels", "HMP", "DIGITSMCTR", 0, Lifetime::Timeframe); + + return DataProcessorSpec{ + "HMPClusterer", + inputs, + // Outputs{OutputSpec{"HMP", "CLUSTERS", 0, Lifetime::Timeframe}, + // OutputSpec{"HMP", "CLUSTERSMCTR", 0, Lifetime::Timeframe}}, + Outputs{}, + AlgorithmSpec{adaptFromTask(useMC)}, + Options{/* for the moment no options */}}; +} + +} // end namespace hmpid +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx b/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx new file mode 100644 index 0000000000000..007a5343c5b71 --- /dev/null +++ b/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx @@ -0,0 +1,90 @@ +// 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 DigitReader.cxx + +#include + +#include "../include/HMPIDWorkflow/DigitReaderSpec.h" +#include "TTree.h" + +#include "Framework/ControlService.h" +#include "DataFormatsParameters/GRPObject.h" +using namespace o2::framework; +using namespace o2::hmpid; + +namespace o2 +{ +namespace hmpid +{ + +void DigitReader::init(InitContext& ic) +{ + LOG(INFO) << "Init Digit reader!"; + auto filename = ic.options().get("hmpid-digit-infile"); + mFile = std::make_unique(filename.c_str(), "OLD"); + if (!mFile->IsOpen()) { + LOG(ERROR) << "Cannot open the " << filename.c_str() << " file !"; + mState = 0; + return; + } + mState = 1; +} + +void DigitReader::run(ProcessingContext& pc) +{ + if (mState != 1) { + return; + } + + std::unique_ptr treeDig((TTree*)mFile->Get("o2sim")); + + if (treeDig) { + treeDig->SetBranchAddress("HMPDigit", &mPdigits); + + if (mUseMC) { + treeDig->SetBranchAddress("HMPDigitLabels", &mPlabels); + } + + treeDig->GetEntry(0); + + // add digits loaded in the output snapshot + pc.outputs().snapshot(Output{"HMP", "DIGITS", 0, Lifetime::Timeframe}, mDigits); + if (mUseMC) { + pc.outputs().snapshot(Output{"HMP", "DIGITSMCTR", 0, Lifetime::Timeframe}, mLabels); + } + } else { + LOG(ERROR) << "Cannot read the HMPID digits !"; + return; + } + + mState = 2; + pc.services().get().readyToQuit(false); +} + +DataProcessorSpec getDigitReaderSpec(bool useMC) +{ + std::vector outputs; + outputs.emplace_back("HMP", "DIGITS", 0, Lifetime::Timeframe); + if (useMC) { + outputs.emplace_back("HMP", "DIGITSMCTR", 0, Lifetime::Timeframe); + } + + return DataProcessorSpec{ + "hmpid-digit-reader", + Inputs{}, + outputs, + AlgorithmSpec{adaptFromTask(useMC)}, + Options{ + {"hmpid-digit-infile", VariantType::String, "hmpiddigits.root", {"Name of the input file"}}}}; +} + +} // namespace hmpid +} // namespace o2 diff --git a/Detectors/HMPID/workflow/src/HMPIDRecoWorkflow.cxx b/Detectors/HMPID/workflow/src/HMPIDRecoWorkflow.cxx new file mode 100644 index 0000000000000..a8f392b86481e --- /dev/null +++ b/Detectors/HMPID/workflow/src/HMPIDRecoWorkflow.cxx @@ -0,0 +1,35 @@ +// 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. + +#include "HMPIDWorkflow/DigitReaderSpec.h" +#include "HMPIDWorkflow/ClusterizerSpec.h" + +#include "Framework/WorkflowSpec.h" +#include "Framework/ConfigParamSpec.h" + +#include "Framework/runDataProcessing.h" // the main driver + +using namespace o2::framework; + +/// The standalone workflow executable for HMPID reconstruction workflow +/// - digit reader +/// - clusterer + +/// This function hooks up the the workflow specifications into the DPL driver. +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + WorkflowSpec specs; + + bool useMC = true; + specs.emplace_back(o2::hmpid::getDigitReaderSpec(useMC)); + specs.emplace_back(o2::hmpid::getHMPIDClusterizerSpec(useMC)); + + return std::move(specs); +} From a253aa32da1b5732e91ecba908b6004fc5e98bd1 Mon Sep 17 00:00:00 2001 From: Giacomo Volpe Date: Fri, 30 Aug 2019 19:02:33 +0200 Subject: [PATCH 091/208] Preliminary HMPID cluster implementation --- .../HMPID/base/include/HMPIDBase/Cluster.h | 38 +++++++++++++++++++ Detectors/HMPID/base/src/Cluster.cxx | 9 ++++- Detectors/HMPID/base/src/HMPIDBaseLinkDef.h | 2 + .../HMPID/reconstruction/src/Clusterer.cxx | 17 --------- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Cluster.h b/Detectors/HMPID/base/include/HMPIDBase/Cluster.h index 764dcfcf9c602..836f804136e14 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Cluster.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Cluster.h @@ -25,6 +25,44 @@ namespace hmpid /// \brief HMPID cluster implementation class Cluster { + public: + Cluster() = default; + + Cluster(Int_t chamber, Int_t size, Int_t NlocMax, Double_t QRaw, Double_t Q, Double_t X, Double_t Y); + ~Cluster() = default; + + + Int_t getCh() const { return mChamber; } + void setCh(Int_t chamber) { mChamber = chamber; } + + Int_t getSize() const { return mSize; } + void setSize(Int_t size) { mSize = size; } + + Int_t getQRaw() const { return mQRaw; } + void setQRaw(Int_t QRaw) { mQRaw = QRaw; } + + Int_t getQ() const { return mQ; } + void setQ(Int_t Q) { mQ = Q; } + + Int_t getX() const { return mX; } + void setX(Int_t X) { mX = X; } + + Int_t getY() const { return mY; } + void setY(Int_t Y) { mY = Y; } + + + protected: + + Int_t mChamber; /// chamber number + Int_t mSize; /// size of the formed cluster from which this cluster deduced + Int_t mNlocMax; /// number of local maxima in formed cluster + Double_t mQRaw; /// QDC value of the raw cluster + Double_t mQ; /// QDC value of the actual cluster + Double_t mX; /// local x postion, [cm] + Double_t mY; /// local y postion, [cm] + + + ClassDefNV(Cluster, 1); }; } // namespace hmpid diff --git a/Detectors/HMPID/base/src/Cluster.cxx b/Detectors/HMPID/base/src/Cluster.cxx index 6c5dec851a0ad..05770b85e1ffd 100644 --- a/Detectors/HMPID/base/src/Cluster.cxx +++ b/Detectors/HMPID/base/src/Cluster.cxx @@ -8,11 +8,16 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Cluster.h" #include "HMPIDBase/Param.h" #include "TRandom.h" #include "TMath.h" using namespace o2::hmpid; -ClassImp(o2::hmpid::Digit); +ClassImp(o2::hmpid::Cluster); + +Cluster::Cluster(Int_t chamber, Int_t size, Int_t NlocMax, Double_t QRaw, Double_t Q, Double_t X, Double_t Y) + : mChamber(chamber), mSize(size), mNlocMax(NlocMax), mQRaw(QRaw), mQ(Q), mX(X), mY(Y) +{ +} diff --git a/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h b/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h index 179ba16791750..fc5aa9c380584 100644 --- a/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h +++ b/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h @@ -14,6 +14,8 @@ #pragma link off all classes; #pragma link off all functions; +#pragma link C++ class o2::hmpid::Cluster + ; +#pragma link C++ class vector < o2::hmpid::Cluster> + ; #pragma link C++ class o2::hmpid::Param + ; #pragma link C++ class o2::hmpid::Digit + ; #pragma link C++ class vector < o2::hmpid::Digit> + ; diff --git a/Detectors/HMPID/reconstruction/src/Clusterer.cxx b/Detectors/HMPID/reconstruction/src/Clusterer.cxx index 089b63787cde8..e3d026c3479ac 100644 --- a/Detectors/HMPID/reconstruction/src/Clusterer.cxx +++ b/Detectors/HMPID/reconstruction/src/Clusterer.cxx @@ -44,20 +44,3 @@ void Clusterer::process(std::vector const& digits, std::vector timerProcess.Print(); } -////__________________________________________________ -//void Clusterer::dig2Clu(std::vector& clusters, MCLabelContainer const* digitMCTruth) -//{ -// // method to clusterize -// -// // to be implemented -// -//} -////______________________________________________________________________ -//void Clusterer::formClu(Cluster& c, Digit* dig, o2::hmpid::Digit>& digits, MCLabelContainer const* digitMCTruth) -//{ -// // method to clusterize -// -// // to be implemented -// -//} -//______________________________________________________________________ From c9c0ce499851cc562ae10f0e0e21f998c449d007 Mon Sep 17 00:00:00 2001 From: Giacomo Volpe Date: Thu, 7 Jan 2021 16:34:39 +0100 Subject: [PATCH 092/208] First data decoder workflow implementation --- Detectors/HMPID/reconstruction/CMakeLists.txt | 9 +- .../HMPID/reconstruction/src/Clusterer.cxx | 1 + .../src/HMPIDReconstructionLinkDef.h | 5 +- Detectors/HMPID/simulation/src/Detector.cxx | 2 + .../HMPID/simulation/src/HMPIDDigitizer.cxx | 2 + Detectors/HMPID/workflow/CMakeLists.txt | 14 +- .../include/HMPIDWorkflow/DataDecoderSpec.h | 33 +++ .../HMPID/workflow/src/ClusterizerSpec.cxx | 1 + .../HMPID/workflow/src/DataDecoderSpec.cxx | 188 ++++++++++++++++++ .../HMPID/workflow/src/DigitReaderSpec.cxx | 5 +- .../workflow/src/raw-to-digits-workflow.cxx | 40 ++++ 11 files changed, 291 insertions(+), 9 deletions(-) create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h create mode 100644 Detectors/HMPID/workflow/src/DataDecoderSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx diff --git a/Detectors/HMPID/reconstruction/CMakeLists.txt b/Detectors/HMPID/reconstruction/CMakeLists.txt index a9e882fa411b7..346cad9e40c7f 100644 --- a/Detectors/HMPID/reconstruction/CMakeLists.txt +++ b/Detectors/HMPID/reconstruction/CMakeLists.txt @@ -9,10 +9,13 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDReconstruction - SOURCES src/Clusterer.cxx src/DataReader.cxx + SOURCES src/Clusterer.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDBase O2::HMPIDSimulation) o2_target_root_dictionary(HMPIDReconstruction - HEADERS include/HMPIDReconstruction/Clusterer.h - include/HMPIDReconstruction/DataReader.h) + HEADERS include/HMPIDReconstruction/Clusterer.h) + #include/HMPIDReconstruction/HmpidDecodeRawMem.h + #include/HMPIDReconstruction/HmpidDecoder.h + #include/HMPIDReconstruction/HmpidEquipment.h) + #include/HMPIDReconstruction/DataReader.h) diff --git a/Detectors/HMPID/reconstruction/src/Clusterer.cxx b/Detectors/HMPID/reconstruction/src/Clusterer.cxx index e3d026c3479ac..e543d99193290 100644 --- a/Detectors/HMPID/reconstruction/src/Clusterer.cxx +++ b/Detectors/HMPID/reconstruction/src/Clusterer.cxx @@ -12,6 +12,7 @@ /// \brief Implementation of the HMPID cluster finder #include #include "FairLogger.h" // for LOG +#include "Framework/Logger.h" #include "HMPIDBase/Cluster.h" #include "HMPIDReconstruction/Clusterer.h" #include "SimulationDataFormat/MCCompLabel.h" diff --git a/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h b/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h index 23608c4bc6a4c..26b789b661b47 100644 --- a/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h +++ b/Detectors/HMPID/reconstruction/src/HMPIDReconstructionLinkDef.h @@ -14,7 +14,10 @@ #pragma link off all classes; #pragma link off all functions; -#pragma link C++ class o2::hmpid::DataReader + ; +//#pragma link C++ class o2::hmpid::DataReader + ; #pragma link C++ class o2::hmpid::Clusterer + ; +//#pragma link C++ class o2::hmpid::HmpidDecodeRawMem + ; +//#pragma link C++ class o2::hmpid::HmpidDecoder + ; +//#pragma link C++ class o2::hmpid::HmpidEquipment + ; #endif diff --git a/Detectors/HMPID/simulation/src/Detector.cxx b/Detectors/HMPID/simulation/src/Detector.cxx index 89af501ba15cd..86f22a867cf98 100644 --- a/Detectors/HMPID/simulation/src/Detector.cxx +++ b/Detectors/HMPID/simulation/src/Detector.cxx @@ -32,6 +32,8 @@ #include "DetectorsBase/MaterialManager.h" +#include "Framework/Logger.h" + namespace o2 { namespace hmpid diff --git a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx index 155e2a8ae4455..d9b8dfe5f9c48 100644 --- a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx +++ b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx @@ -11,6 +11,8 @@ #include "HMPIDSimulation/HMPIDDigitizer.h" #include "HMPIDBase/Digit.h" +#include "Framework/Logger.h" + using namespace o2::hmpid; ClassImp(HMPIDDigitizer); diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index 78a7a79e3c9ea..6bd41689209b6 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -9,11 +9,13 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDWorkflow - SOURCES src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx - PUBLIC_LINK_LIBRARIES O2::HMPIDBase + SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx + PUBLIC_LINK_LIBRARIES O2::Framework + O2::DPLUtils + O2::DetectorsRaw + O2::HMPIDBase O2::HMPIDSimulation - O2::HMPIDReconstruction - O2::Framework) + O2::HMPIDReconstruction) o2_add_executable(recoworkflow COMPONENT_NAME hmpid @@ -21,3 +23,7 @@ o2_add_executable(recoworkflow PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) +o2_add_executable(raw-to-digits-workflow + COMPONENT_NAME hmpid + SOURCES src/raw-to-digits-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h new file mode 100644 index 0000000000000..fc1da045c6742 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -0,0 +1,33 @@ +// 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 DatDecoderSpec.h +/// \author Andrea Ferrero +/// +/// \brief Definition of a data processor to run the raw decoding +/// + +#ifndef O2_MCH_DATADECODERSPEC_H_ +#define O2_MCH_DATADECODERSPEC_H_ + +#include "Framework/DataProcessorSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec = "TF:HMP/RAWDATA"); +//o2::framework::DataProcessorSpec getDecodingSpec(); +} // end namespace hmpid +} // end namespace o2 + +#endif diff --git a/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx b/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx index 463a3f97753ee..3e39b04b16cba 100644 --- a/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx +++ b/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx @@ -14,6 +14,7 @@ #include "Framework/DataRefUtils.h" #include "Framework/Lifetime.h" #include "Framework/Task.h" +#include "Framework/Logger.h" #include "Headers/DataHeader.h" #include "HMPIDReconstruction/Clusterer.h" #include "HMPIDBase/Cluster.h" diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx new file mode 100644 index 0000000000000..d0be3a60eb70e --- /dev/null +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -0,0 +1,188 @@ +// draft +// 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 DatDecoderSpec.cxx +/// \author +/// +/// \brief Implementation of a data processor to run the HMPID raw decoding +/// + +#include +#include +#include +#include +#include +#include + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" + +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" +#include "DPLUtils/DPLRawParser.h" + +#include "HMPIDBase/Digit.h" +#include "HMPIDWorkflow/DataDecoderSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using namespace o2; +using namespace o2::framework; +using RDH = o2::header::RDHAny; + +//======================= +// Data decoder +class DataDecoderTask +{ + public: + //_________________________________________________________________________________________________ + void init(framework::InitContext& ic) + { + /* SampaChannelHandler channelHandler; + RdhHandler rdhHandler; + + auto ds2manu = ic.options().get("ds2manu"); + mPrint = ic.options().get("print"); + auto mapCRUfile = ic.options().get("cru-map"); + auto mapFECfile = ic.options().get("fec-map"); + + mDecoder = new DataDecoder(channelHandler, rdhHandler, mapCRUfile, mapFECfile, ds2manu, mPrint); + */ + } + + //_________________________________________________________________________________________________ + // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder + void decodeTF(framework::ProcessingContext& pc) + { + Printf("*********** In decodeTF **************"); + + // get the input buffer + auto& inputs = pc.inputs(); + DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); + + for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { + auto const* rdh = it.get_if(); + auto const* raw = it.raw(); + size_t payloadSize = it.size(); + // stampare solo payload + std::cout << " ***** payloadSize = " << payloadSize << std::endl; + + /* if (payloadSize == 0) { + continue; + } + + gsl::span buffer(reinterpret_cast(raw), sizeof(RDH) + payloadSize); + mDecoder->decodeBuffer(buffer); + */ + } + } + + //_________________________________________________________________________________________________ + // the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow +/* void decodeReadout(const o2::framework::DataRef& input) + { + static int nFrame = 1; + // get the input buffer + if (input.spec->binding != "readout") { + return; + } + + const auto* header = o2::header::get(input.header); + if (!header) { + return; + } + + auto const* raw = input.payload; + // cout size of payload + std::cout << " payloadSize " << header->payloadSize << std::endl; + //size_t payloadSize = header->payloadSize; + + if (mPrint) { + std::cout << nFrame << " payloadSize=" << payloadSize << std::endl; + } + nFrame += 1; + if (payloadSize == 0) { + return; + } + + gsl::span buffer(reinterpret_cast(raw), payloadSize); + mDecoder->decodeBuffer(buffer); + } +*/ + //_________________________________________________________________________________________________ + void run(framework::ProcessingContext& pc) + { + + decodeTF(pc); + for (auto&& input : pc.inputs()) { + + std::cout << " ******* input " << input.spec->binding << std::endl; + // if (input.spec->binding == "readout") { // solo cout + // decodeReadout(input); + // } + } + +/* auto& digits = mDecoder->getOutputDigits(); + auto& orbits = mDecoder->getOrbits(); + + if (mPrint) { + for (auto d : digits) { + std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; + } + } + // send the output buffer via DPL + size_t digitsSize, orbitsSize; + char* digitsBuffer = createBuffer(digits, digitsSize); + char* orbitsBuffer = createBuffer(orbits, orbitsSize); + + // create the output message + auto freefct = [](void* data, void*) { free(data); }; + // pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); + // pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); + */ + } + + private: + bool mPrint = {false}; +// DataDecoder* mDecoder = {nullptr}; +}; + +//_________________________________________________________________________________________________ +o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) +//o2::framework::DataPrecessorSpec getDecodingSpec() +{ + + std::vector inputs; + inputs.emplace_back("RAWDATA", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + + return DataProcessorSpec{ + "HMP-DataDecoder", + o2::framework::select(inputSpec.c_str()), + Outputs{OutputSpec{"HMP", "DIGITS", 0, Lifetime::Timeframe}, OutputSpec{"HMP", "ORBITS", 0, Lifetime::Timeframe}}, + AlgorithmSpec{adaptFromTask()}, + Options{{"print", VariantType::Bool, false, {"print digits"}}, + {"cru-map", VariantType::String, "", {"custom CRU mapping"}}, + {"fec-map", VariantType::String, "", {"custom FEC mapping"}}, + {"ds2manu", VariantType::Bool, false, {"convert channel numbering from Run3 to Run1-2 order"}}}}; +} + +} // namespace hmpid +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx b/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx index 007a5343c5b71..9d67bd722c1fe 100644 --- a/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DigitReaderSpec.cxx @@ -12,11 +12,14 @@ #include -#include "../include/HMPIDWorkflow/DigitReaderSpec.h" +#include "HMPIDWorkflow/DigitReaderSpec.h" #include "TTree.h" #include "Framework/ControlService.h" +#include "Framework/ConfigParamRegistry.h" #include "DataFormatsParameters/GRPObject.h" +#include "Framework/Logger.h" + using namespace o2::framework; using namespace o2::hmpid; diff --git a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx new file mode 100644 index 0000000000000..462ee37e15521 --- /dev/null +++ b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx @@ -0,0 +1,40 @@ +// 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 raw-to-digits-workflow.cxx +/// \author Andrea Ferrero +/// +/// \brief This is an executable that runs the decoding via DPL. +/// +/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. +/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow +/// + +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/Task.h" +#include "Framework/runDataProcessing.h" +#include "HMPIDWorkflow/DataDecoderSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + DataProcessorSpec producer = o2::hmpid::getDecodingSpec(); + specs.push_back(producer); + + return specs; +} From 073384f6292c24f07c5122e08385e4d5cbecec92 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 8 Jan 2021 12:03:23 +0100 Subject: [PATCH 093/208] Add Decoder Class --- DataFormats/Detectors/HMPID/CMakeLists.txt | 17 + .../HMPID/include/DataFormatsHMP/DataFormat.h | 46 + .../HMPID/src/DataFormatsHMPLinkDef.h | 18 + Detectors/HMPID/base/include/HMPIDBase/Geo.h | 86 ++ Detectors/HMPID/base/src/Geo.cxx | 74 ++ .../reconstruction/src/HmpidDecodeRawFile.cxx | 157 +++ .../reconstruction/src/HmpidDecodeRawFile.h | 62 + .../reconstruction/src/HmpidDecodeRawMem.cxx | 134 +++ .../reconstruction/src/HmpidDecodeRawMem.h | 55 + .../HMPID/reconstruction/src/HmpidDecoder.cxx | 1065 +++++++++++++++++ .../HMPID/reconstruction/src/HmpidDecoder.h | 167 +++ .../reconstruction/src/HmpidEquipment.cxx | 139 +++ .../HMPID/reconstruction/src/HmpidEquipment.h | 135 +++ GPU/GPUTracking/Standalone/Common | 2 +- GPU/GPUTracking/Standalone/Global | 2 +- GPU/GPUTracking/Standalone/HLTHeaders | 2 +- GPU/GPUTracking/Standalone/ITS | 2 +- GPU/GPUTracking/Standalone/Merger | 2 +- GPU/GPUTracking/Standalone/SliceTracker | 2 +- .../Standalone/TPCFastTransformation | 2 +- GPU/GPUTracking/Standalone/TRDTracking | 2 +- GPU/GPUTracking/Standalone/dependencies | 2 +- 22 files changed, 2164 insertions(+), 9 deletions(-) create mode 100644 DataFormats/Detectors/HMPID/CMakeLists.txt create mode 100644 DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h create mode 100644 DataFormats/Detectors/HMPID/src/DataFormatsHMPLinkDef.h create mode 100644 Detectors/HMPID/base/include/HMPIDBase/Geo.h create mode 100644 Detectors/HMPID/base/src/Geo.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.h create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HmpidDecoder.h create mode 100644 Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx create mode 100644 Detectors/HMPID/reconstruction/src/HmpidEquipment.h diff --git a/DataFormats/Detectors/HMPID/CMakeLists.txt b/DataFormats/Detectors/HMPID/CMakeLists.txt new file mode 100644 index 0000000000000..7c5851c1560cb --- /dev/null +++ b/DataFormats/Detectors/HMPID/CMakeLists.txt @@ -0,0 +1,17 @@ +# 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. + +# o2_add_library(DataFormatsHMP +# SOURCES src/Cluster.cxx +# PUBLIC_LINK_LIBRARIES O2::ReconstructionDataFormats +# Boost::serialization) + +# o2_target_root_dictionary(DataFormatsHMP +# HEADERS include/DataFormatsHMP/DataFormat.h diff --git a/DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h b/DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h new file mode 100644 index 0000000000000..ac6f3397e2829 --- /dev/null +++ b/DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h @@ -0,0 +1,46 @@ +// 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 DataFormat.h +/// \brief Definition of the HMPID raw data format + +#ifndef ALICEO2_HMP_DATAFORMAT_H +#define ALICEO2_HMP_DATAFORMAT_H + +#include + +namespace o2 +{ +namespace hmpid +{ + +namespace raw +{ + + /** generic word * + + struct Word_t { + uint32_t undefined : 31; + uint32_t wordType : 1; + }; + + union Union_t { + uint32_t data; + Word_t word; + CrateHeader_t crateHeader; + FrameHeader_t frameHeader; + PackedHit_t packedHit; + CrateTrailer_t crateTrailer; + }; +*/ +} // namespace raw +} // namespace tof +} // namespace o2 +#endif diff --git a/DataFormats/Detectors/HMPID/src/DataFormatsHMPLinkDef.h b/DataFormats/Detectors/HMPID/src/DataFormatsHMPLinkDef.h new file mode 100644 index 0000000000000..027b310bd7b29 --- /dev/null +++ b/DataFormats/Detectors/HMPID/src/DataFormatsHMPLinkDef.h @@ -0,0 +1,18 @@ +// 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. + +#ifdef __CLING__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; +//#pragma link C++ class o2::hmpid::Cluster + ; + +#endif diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h new file mode 100644 index 0000000000000..469c32a5cba26 --- /dev/null +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -0,0 +1,86 @@ +// 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. + +#ifndef ALICEO2_HMPID_GEO_H +#define ALICEO2_HMPID_GEO_H + +//#include "Rtypes.h" + +namespace o2 +{ +namespace hmpid +{ +/// \class Geo +/// \brief HMPID detector geometry (only statics) +class Geo +{ + public: + // From AliTOFGeometry +// static void translate(Float_t* xyz, Float_t translationVector[3]); +// enum { +// // DAQ characteristics +// kNDDL = 4, // Number of DDL (Detector Data Link) per sector +// kNTRM = 12, // Number of TRM ( Readout Module) per DDL +// kNTdc = 15, // Number of Tdc (Time to Digital Converter) per TRM +// kNChain = 2, // Number of chains per TRM +// kNCrate = 72, // Number of Crates +// kNCh = 8 // Number of channels per Tdc +// }; + + + // ---- HMPID geometry ------- + static constexpr int MAXEQUIPMENTS = 14; + static constexpr int N_SEGMENTS = 3; + static constexpr int N_COLXSEGMENT = 8; + static constexpr int N_COLUMNS = 24; + static constexpr int N_DILOGICS = 10; + static constexpr int N_CHANNELS = 48; + static constexpr int N_DILOCHANNELS = 64; + + static constexpr int N_MODULES = 7; + static constexpr int N_XROWS = 160; + static constexpr int N_YCOLS = 144; + + static constexpr int MAXYCOLS = 143; + static constexpr int MAXHALFXROWS = 79; + static constexpr int HALFXROWS = 80; + + static constexpr int DILOPADSCOLS = 6; + static constexpr int DILOPADSROWS = 8; + + static constexpr int EQUIPMENTSPERMODULE = 2; + + + static constexpr int N_EQUIPMENTTOTALPADS = N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; + static constexpr int N_HMPIDTOTALPADS = MAXEQUIPMENTS * N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; + + + void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); + void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); + + // from + //static constexpr Bool_t FEAWITHMASKS[NSECTORS] = + // // TOF sectors with Nino masks: 0, 8, 9, 10, 16 + // {kTRUE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, + // kTRUE, kTRUE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, kFALSE}; + //; // Selecting TOF sectors containing FEA cooling masks + + +// static Float_t getCableLength(Int_t icrate, Int_t islot, Int_t ichain, Int_t itdc) { return CABLELENGTH[icrate][islot - 3][ichain][itdc / 3]; } + + private: + static void Init(); + + ClassDefNV(Geo, 1); +}; +} // namespace hmpid +} // namespace o2 + +#endif diff --git a/Detectors/HMPID/base/src/Geo.cxx b/Detectors/HMPID/base/src/Geo.cxx new file mode 100644 index 0000000000000..ef6f4a1da7858 --- /dev/null +++ b/Detectors/HMPID/base/src/Geo.cxx @@ -0,0 +1,74 @@ +// 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. + +#include "HMPIDBase/Geo.h" +#include "TGeoManager.h" +#include "TMath.h" +#include "FairLogger.h" +#include "DetectorsBase/GeometryManager.h" + +ClassImp(o2::hmpid::Geo); + +using namespace o2::hmpid; + +//constexpr Bool_t Geo::FEAWITHMASKS[NSECTORS]; + +void Geo::Init() +{ + LOG(INFO) << "hmpid::Geo: Initialization of HMPID parameters"; + +} +// =================== General Purposes HMPID Functions ======================= +/// Functions to translate coordinates : from Module,Col,Row to Equipment,Col,Dilogic,Channel +/// Digit coordinates " Mod,Row,Col := Mod = {0..6} Row = {0..159} Col = {0..143} +/// (0,0) Left Bottom +/// +/// Hardware coordinates Equ,Col,Dil,Cha := Equ = {0..13} Col = {0..23} Dil = {0..9} Cha = {0..47} +/// +/// (0,0,0,0) Right Top (1,0,0,0) Left Bottom +/// +void Geo::Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan) +{ + if (Row > MAXHALFXROWS) { + *Equi = Mod * EQUIPMENTSPERMODULE + 1; + Row = Row - HALFXROWS; + } else { + *Equi = Mod * EQUIPMENTSPERMODULE; + Row = MAXHALFXROWS - Row; + Col = MAXYCOLS - Col; + } + *Dilo = Row / DILOPADSROWS; + *Colu = Col / DILOPADSCOLS; + *Chan = (Row % DILOPADSROWS) * DILOPADSCOLS + (Col % DILOPADSCOLS); + return; +} + +/// Functions to translate coordinates : from Equipment,Col,Dilogic,Channel to Module,Col,Row +/// Digit coordinates " Mod,Row,Col := Mod = {0..6} Row = {0..159} Col = {0..143} +/// (0,0) Left Bottom +/// +/// Hardware coordinates Equ,Col,Dil,Cha := Equ = {0..13} Col = {0..23} Dil = {0..9} Cha = {0..47} +/// +/// (0,0,0,0) Right Top (1,0,0,0) Left Bottom +/// +void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row) +{ + *Mod = Equi / EQUIPMENTSPERMODULE; + *Row = Dilo * DILOPADSROWS + Chan / DILOPADSROWS; + *Col = (Colu * DILOPADSCOLS) + Chan % DILOPADSCOLS; + + if (Equi % EQUIPMENTSPERMODULE == 1) { + *Row += HALFXROWS; + } else { + *Row = MAXHALFXROWS - *Row; + *Col = MAXYCOLS - *Col; + } + return; +} diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx new file mode 100644 index 0000000000000..3c1c30b592fd0 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx @@ -0,0 +1,157 @@ +// 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 HmpidDecodeRawFile.cxx +/// \author Antonio Franco - INFN Bari +/// \brief Derived Class for decoding Raw Data File stream +/// \version 1.0 +/// \date 24 set 2020 + +/* ------ HISTORY --------- +*/ + +#include "HmpidDecodeRawFile.h" + +using namespace o2::hmpid; + +/// Constructor with the default HMPID equipments map at P2 +/// @param[in] numOfEquipments : number of defined equipments [0..13] +HmpidDecodeRawFile::HmpidDecodeRawFile(int numOfEquipments) + : + HmpidDecoder(numOfEquipments) +{ + fh = 0; +} + +/// Constructor with the HMPID address map +/// @param[in] numOfEquipments : the number of equipments to define [1..14] +/// @param[in] *EqIds : the pointer to the Equipments ID array +/// @param[in] *CruIds : the pointer to the CRU ID array +/// @param[in] *LinkIds : the pointer to the Link ID array +HmpidDecodeRawFile::HmpidDecodeRawFile(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) + : + HmpidDecoder(EqIds, CruIds, LinkIds, numOfEquipments) +{ + fh = 0; +} + +/// Destructor +HmpidDecodeRawFile::~HmpidDecodeRawFile() +{ +} + +/// Setup the Input Stream with a File Handle +/// verify the existence and try to open it +/// @param[in] *FileName : the string that contains the File Name +/// @param[in] Size : not used +/// @returns True if the file is opened +/// @throws TH_FILENOTEXISTS Thrown if the file doesn't exists +/// @throws TH_OPENFILE Thrown if Fails to open the file +bool HmpidDecodeRawFile::setUpStream(void *FileName, long Size) +{ + strcpy(mInputFile, (const char*) FileName); + // files section ---- + if (!fileExists(mInputFile)) { + ILOG(ERROR) << "The input file " << mInputFile << " does not exist at this time." << FairLogger::endl; + throw TH_FILENOTEXISTS; + } + // open the file + fh = fopen(mInputFile, "rb"); + if (fh == 0) { + ILOG(ERROR) << "ERROR to open Input file ! [" << mInputFile << "]" << FairLogger::endl; + throw TH_OPENFILE; + } + + mActualStreamPtr = 0; // sets the pointer to the Buffer + mEndStreamPtr = 0; //sets the End of buffer + mStartStreamPtr = 0; + + return (true); +} + +/// Gets a sized chunk from the stream. Read from the file and update the pointers +/// ATTENTION : in order to optimize the disk accesses the block read pre-load a +/// complete Header+Payload block, the Size parameter is recalculated with the +/// dimension of the pack extract from the header field 'Offeset' +/// +/// verify the existence and try to open it +/// @param[in] **streamPtr : the pointer to the memory buffer +/// @param[in] Size : not used +/// @returns True if the file is opened +/// @throws TH_WRONGFILELEN Thrown if the file doesn't contains enough words +bool HmpidDecodeRawFile::getBlockFromStream(int32_t **streamPtr, uint32_t Size) +{ + if (Size > MAXRAWFILEBUFFER) + return (false); + int nr = fread(mFileBuffer, sizeof(int32_t), HEADERDIMENSION_W, fh); + if (nr != HEADERDIMENSION_W) { + throw TH_WRONGFILELEN; + } + Size = ((mFileBuffer[2] & 0x0000FFFF) / sizeof(int32_t)) - HEADERDIMENSION_W; + nr = fread(mFileBuffer+HEADERDIMENSION_W, sizeof(int32_t), Size, fh); + ILOG(DEBUG) << " getBlockFromStream read " << nr << " of " << Size+HEADERDIMENSION_W << " words !" << FairLogger::endl; + if (nr != Size) { + throw TH_WRONGFILELEN; + } + *streamPtr = mFileBuffer; + mStartStreamPtr = mFileBuffer; + mActualStreamPtr = mFileBuffer; + mEndStreamPtr = mFileBuffer + Size; + return (true); +} + +/// Reads the Header from the file +/// @param[in] **streamPtr : the pointer to the memory buffer +/// @returns True if the header is read +bool HmpidDecodeRawFile::getHeaderFromStream(int32_t **streamPtr) +{ + bool flag = getBlockFromStream(streamPtr, RAWBLOCKDIMENSION_W); // reads the 8k block + mActualStreamPtr += HEADERDIMENSION_W; // Move forward for the first word + return (flag); +} + +/// Read one word from the pre-load buffer +/// @param[in] *word : the buffer for the read word +/// @returns True every time +bool HmpidDecodeRawFile::getWordFromStream(int32_t *word) +{ + *word = *mActualStreamPtr; + mActualStreamPtr++; + return (true); +} + +/// ----- Sets the Pad ! ------ +/// this is an overloaded method. In this version the value of the charge +/// is used to update the statistical matrix of the base class +/// +/// @param[in] *eq : the pointer to the Equipment object +/// @param[in] col : the column [0..23] +/// @param[in] dil : the dilogic [0..9] +/// @param[in] ch : the channel [0..47] +/// @param[in] charge : the value of the charge +void HmpidDecodeRawFile::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) +{ + eq->setPad(col, dil, ch, charge); + return; +} + +/// Checks if the file exists ! +/// @param[in] *filewithpath : the File Name to check +/// @returns True if the file exists +int HmpidDecodeRawFile::fileExists(char *filewithpath) +{ + if (access(filewithpath, F_OK) != -1) { + return (true); + } else { + return (false); + } +} + diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h new file mode 100644 index 0000000000000..38bebe8d31d77 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h @@ -0,0 +1,62 @@ +// 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 HmpidDecodeRawFile.h +/// \author Antonio Franco - INFN Bari +/// \brief Derived Class for decoding Raw Data File stream +/// \version 1.0 +/// \date 24 set 2020 + +#ifndef COMMON_HMPIDDECODERAWFILE_H_ +#define COMMON_HMPIDDECODERAWFILE_H_ + +#include +#include +#include +#include +#include +#include + +#include "HmpidDecoder.h" + +#define MAXFILENAMEBUFFER 512 +#define MAXRAWFILEBUFFER RAWBLOCKDIMENSION_W * 4 + 8 + +namespace o2 { + namespace hmpid { + + +class HmpidDecodeRawFile: public HmpidDecoder +{ + public: + HmpidDecodeRawFile(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); + HmpidDecodeRawFile(int numOfEquipments); + ~HmpidDecodeRawFile(); + + bool setUpStream(void *InpuFileName, long Size); + + private: + bool getBlockFromStream(int32_t **streamPtr, uint32_t Size); + bool getHeaderFromStream(int32_t **streamPtr); + bool getWordFromStream(int32_t *word); + int fileExists(char *filewithpath); + void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + + private: + FILE *fh; + char mInputFile[MAXFILENAMEBUFFER]; + int32_t mFileBuffer[MAXRAWFILEBUFFER]; + +}; + + } +} +#endif /* COMMON_HMPIDDECODERAWFILE_H_ */ diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx new file mode 100644 index 0000000000000..c9d39361d9536 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -0,0 +1,134 @@ +// 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 HmpidDecodeRawMem.cxx +/// \author Antonio Franco - INFN Bari +/// \brief Derived Class for decoding Raw Data Memory stream +/// \version 1.0 +/// \date 24 set 2020 + +/* ------ HISTORY --------- +*/ + +#include "HmpidDecodeRawMem.h" + +using namespace o2::hmpid; + +/// Constructor : accepts the number of equipments to define +/// The mapping is the default at P2 +/// Allocates instances for all defined equipments +/// normally it is equal to 14 +/// @param[in] numOfEquipments : the number of equipments to define [1..14] +HmpidDecodeRawMem::HmpidDecodeRawMem(int numOfEquipments) + : + HmpidDecoder(numOfEquipments) +{ +} + +/// Constructor : accepts the number of equipments to define +/// and their complete address map +/// Allocates instances for all defined equipments +/// +/// The Address map is build from three array +/// @param[in] numOfEquipments : the number of equipments to define [1..14] +/// @param[in] *EqIds : the pointer to the Equipments ID array +/// @param[in] *CruIds : the pointer to the CRU ID array +/// @param[in] *LinkIds : the pointer to the Link ID array +HmpidDecodeRawMem::HmpidDecodeRawMem(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) + : + HmpidDecoder(EqIds, CruIds, LinkIds, numOfEquipments) +{ +} + +/// Destructor +HmpidDecodeRawMem::~HmpidDecodeRawMem() +{ +} + +/// Setup the Input Stream with a Memory Pointer +/// the buffer length is in byte, some controls are done +/// +/// @param[in] *Buffer : the pointer to Memory buffer +/// @param[in] BufferLen : the length of the buffer (bytes) +/// @returns True if the stream is set +/// @throws TH_NULLBUFFERPOINTER Thrown if the pointer to the buffer is NULL +/// @throws TH_BUFFEREMPTY Thrown if the buffer is empty +/// @throws TH_WRONGBUFFERDIM Thrown if the buffer len is less then one header +bool HmpidDecodeRawMem::setUpStream(void *Buffer, long BufferLen) +{ + long wordsBufferLen = BufferLen / (sizeof(int32_t) / sizeof(char)); // Converts the len in words + if (Buffer == nullptr) { + ILOG(ERROR) << "Raw data buffer null Pointer ! " << FairLogger::endl; + throw TH_NULLBUFFERPOINTER; + } + if (wordsBufferLen == 0) { + ILOG(Error) << "Raw data buffer Empty ! " < +#include +#include +#include +#include +#include + +#include "HmpidDecoder.h" + +namespace o2{ + namespace hmpid { + + +class HmpidDecodeRawMem: public HmpidDecoder +{ + public: + HmpidDecodeRawMem(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); + HmpidDecodeRawMem(int numOfEquipments); + ~HmpidDecodeRawMem(); + + bool setUpStream(void *Buffer, long BufferLen); + + private: + bool getBlockFromStream(int32_t **streamPtr, uint32_t Size); + bool getHeaderFromStream(int32_t **streamPtr); + bool getWordFromStream(int32_t *word); + void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + + private: + +}; + +} +} +#endif /* COMMON_HMPIDDECODERAWFILE_H_ */ diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx new file mode 100644 index 0000000000000..d2350216140be --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -0,0 +1,1065 @@ +// 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 HmpidDecoder.cxx +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to decode HMPID Raw Data stream +/// \version 1.0 +/// \date 17/11/2020 + +/* ------ HISTORY --------- +*/ + +#include "FairLogger.h" +#include "HmpidDecoder.h" + +using namespace o2::hmpid; + +// ============= HmpidDecoder Class implementation ======= + + +/// Decoding Error Messages Definitions +char HmpidDecoder::sErrorDescription[MAXERRORS][MAXDESCRIPTIONLENGHT] = { "Word that I don't known !", + "Row Marker Word with 0 words", "Duplicated Pad Word !", "Row Marker Wrong/Lost -> to EoE", + "Row Marker Wrong/Lost -> to EoE", "Row Marker reports an ERROR !", "Lost EoE Marker !", "Double EoE marker", + "Wrong size definition in EoE Marker", "Double Mark Word", "Wrong Size in Segment Marker", "Lost EoS Marker !", + "HMPID Header Errors" }; + +/// HMPID Firmware Error Messages Definitions +char HmpidDecoder::sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT] = { "L0 Missing," + "L1 is received without L0", "L1A signal arrived before the L1 Latency", "L1A signal arrived after the L1 Latency", + "L1A is missing or L1 timeout", "L1A Message is missing or L1 Message" }; + +/// Constructor : accepts the number of equipments to define +/// The mapping is the default at P2 +/// Allocates instances for all defined equipments +/// normally it is equal to 14 +/// @param[in] numOfEquipments : the number of equipments to define [1..14] +HmpidDecoder::HmpidDecoder(int numOfEquipments) +{ + // The standard definition of HMPID equipments at P2 + int EqIds[] = { 0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13 }; + int CruIds[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3 }; + int LinkIds[] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2 }; + + mNumberOfEquipments = numOfEquipments; + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i] = new HmpidEquipment(EqIds[i], CruIds[i], LinkIds[i]); + } +} + +/// Constructor : accepts the number of equipments to define +/// and their complete address map +/// Allocates instances for all defined equipments +/// +/// The Address map is build from three array +/// @param[in] numOfEquipments : the number of equipments to define [1..14] +/// @param[in] *EqIds : the pointer to the Equipments ID array +/// @param[in] *CruIds : the pointer to the CRU ID array +/// @param[in] *LinkIds : the pointer to the Link ID array +HmpidDecoder::HmpidDecoder(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) +{ + mNumberOfEquipments = numOfEquipments; + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i] = new HmpidEquipment(EqIds[i], CruIds[i], LinkIds[i]); + } +} + +/// Destructor : remove the Equipments instances +HmpidDecoder::~HmpidDecoder() +{ + for (int i = 0; i < mNumberOfEquipments; i++) { + delete mTheEquipments[i]; + } +} + +/// Resets to 0 all the class members +void HmpidDecoder::init() +{ + mVerbose = 0; + mHeEvent = 0; + mHeBusy = 0; + mNumberWordToRead = 0; + mPayloadTail = 0; + + mHeFEEID = 0; + mHeSize = 0; + mHeVer = 0; + mHePrior = 0; + mHeStop = 0; + mHePages = 0; + mEquipment = 0; + + mHeOffsetNewPack = 0; + mHeMemorySize = 0; + + mHeDetectorID = 0; + mHeDW = 0; + mHeCruID = 0; + mHePackNum = 0; + mHePAR = 0; + mHePageNum = 0; + mHeLinkNum = 0; + mHeFirmwareVersion = 0; + mHeHmpidError = 0; + mHeBCDI = 0; + mHeORBIT = 0; + mHeTType = 0; + + mActualStreamPtr = 0; + mEndStreamPtr = 0; + mStartStreamPtr = 0; + +} + +/// Returns the Equipment Index (Pointer of the array) converting +/// the FLP hardware coords (CRU_Id and Link_Id) +/// @param[in] CruId : the CRU ID [0..3] -> FLP 160 = [0,1] FLP 161 = [2,3] +/// @param[in] LinkId : the Link ID [0..3] +/// @returns EquipmentIndex : the index in the Equipment array [0..13] (-1 := error) +int HmpidDecoder::getEquipmentIndex(int CruId, int LinkId) +{ + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->getEquipmentId(CruId, LinkId) != -1) { + return (i); + } + } + return (-1); +} + +/// Returns the Equipment Index (Pointer of the array) converting +/// the Equipment_ID (Firmaware defined Id AKA FFEID) +/// @param[in] EquipmentId : the Equipment ID [0..13] +/// @returns EquipmentIndex : the index in the Equipment array [0..13] (-1 := error) +int HmpidDecoder::getEquipmentIndex(int EquipmentId) +{ + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->getEquipmentId() == EquipmentId) { + return (i); + } + } + return (-1); +} + +/// Returns the Equipment_ID converting the FLP hardware coords +/// @param[in] CruId : the CRU ID [0..3] -> FLP 160 = [0,1] FLP 161 = [2,3] +/// @param[in] LinkId : the Link ID [0..3] +/// @returns EquipmentID : the ID of the Equipment [0..13] (-1 := error) +int HmpidDecoder::getEquipmentID(int CruId, int LinkId) +{ + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->getEquipmentId(CruId, LinkId) != -1) { + return (mTheEquipments[i]->getEquipmentId()); + } + } + return (-1); +} + +/// Scans the BitMap of Raw Data File word and detect the type +/// and the parameters +/// @param[in] wp : the word to analyze +/// @param[out] *p1 : first parameter extract (if it exists) +/// @param[out] *p2 : second parameter extract (if it exists) +/// @param[out] *p3 : third parameter extract (if it exists) +/// @param[out] *p4 : fourth parameter extract (if it exists) +/// @returns Type of Word : the type of word [0..4] (0 := undetect) +int HmpidDecoder::checkType(int32_t wp, int *p1, int *p2, int *p3, int *p4) +{ + if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 + || (wp & 0x0800ffff) == 0x080010A0) { + *p2 = (wp & 0x03ff0000) >> 16; // Number of words of row + *p1 = wp & 0x0000ffff; + return (WTYPE_ROW); + } + if ((wp & 0xfff00000) >> 20 == 0xAB0) { + *p2 = (wp & 0x000fff00) >> 8; // Number of words of Segment + *p1 = (wp & 0xfff00000) >> 20; + *p3 = wp & 0x0000000F; + if (*p3 < 4 && *p3 > 0) { + return (WTYPE_EOS); + } + } + // #EX MASK Raul 0x3803FF80 # ex mask 0xF803FF80 - this is EoE marker 0586800B0 + if ((wp & 0x0803FF80) == 0x08000080) { + *p1 = (wp & 0x07c00000) >> 22; + *p2 = (wp & 0x003C0000) >> 18; + *p3 = (wp & 0x0000007F); + if (*p1 < 25 && *p2 < 11) { + return (WTYPE_EOE); + } + } + if ((wp & 0x08000000) == 0) { // # this is a pad + // PAD:0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value + *p1 = (wp & 0x07c00000) >> 22; + *p2 = (wp & 0x003C0000) >> 18; + *p3 = (wp & 0x0003F000) >> 12; + *p4 = (wp & 0x00000FFF); + if (*p1 > 0 && *p1 < 25 && *p2 > 0 && *p2 < 11 && *p3 < 48) { + return (WTYPE_PAD); + } + } else { + return (WTYPE_NONE); + } + return (WTYPE_NONE); +} + +/// Checks if is a Raw Marker and extract the Row Size +/// @param[in] wp : the word to check +/// @param[out] *Err : true if an error is detected +/// @param[out] *rowSize : the number of words of the row +/// @param[out] *mark : the row marker +/// @returns True if Row Marker is detected +bool HmpidDecoder::isRowMarker(int32_t wp, int *Err, int *rowSize, int *mark) +{ + if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 + || (wp & 0x0800ffff) == 0x080010A0) { + *rowSize = (wp & 0x03ff0000) >> 16; // # Number of words of row + *mark = wp & 0x0000ffff; + *Err = false; + return (true); + } else { + *Err = true; + return (false); + } +} + +/// Checks if is a Segment Marker and extracts the Segment number and the size +/// @param[in] wp : the word to check +/// @param[out] *Err : true if an error is detected +/// @param[out] *segSize : the number of words of the segment +/// @param[out] *Seg : the Segment number [1..3] +/// @param[out] *mark : the Segment Marker +/// @returns True if Segment Marker is detected +bool HmpidDecoder::isSegmentMarker(int32_t wp, int *Err, int *segSize, int *Seg, int *mark) +{ + *Err = false; + if ((wp & 0xfff00000) >> 20 == 0xAB0) { + *segSize = (wp & 0x000fff00) >> 8; // # Number of words of Segment + *mark = (wp & 0xfff00000) >> 20; + *Seg = wp & 0x0000000F; + + if (*Seg > 3 || *Seg < 1) { + ILOG(INFO) << " Wrong segment Marker Word, bad Number of segment" << *Seg << "!" << FairLogger::endl; + *Err = true; + } + return (true); + } else { + return (false); + } +} + +/// Checks if is a PAD Word and extracts all the parameters +/// PAD map : 0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value +/// @param[in] wp : the word to check +/// @param[out] *Err : true if an error is detected +/// @param[out] *Col : the column number [1..24] +/// @param[out] *Dilogic : the dilogic number [1..10] +/// @param[out] *Channel : the channel number [0..47] +/// @param[out] *Charge : the value of Charge [0..4095] +/// @returns True if PAD Word is detected +bool HmpidDecoder::isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge) +{ + *Err = false; + if ((wp & 0x08000000) == 0) { // # this is a pad + *Col = (wp & 0x07c00000) >> 22; + *Dilogic = (wp & 0x003C0000) >> 18; + *Channel = (wp & 0x0003F000) >> 12; + *Charge = (wp & 0x00000FFF); + if (*Dilogic > 10 || *Channel > 47 || *Dilogic < 1 || *Col > 24 || *Col < 1) { + ILOG(WARNING) << " Wrong Pad values Col=" << *Col << " Dilogic="<< *Dilogic << \ + " Channel=" << *Channel << " Charge=" << *Charge << FairLogger::endl; + *Err = true; + } + return (true); + } else { + return (false); + } +} + +/// Checks if is a EoE Marker and extracts the Column, Dilogic and the size +/// @param[in] wp : the word to check +/// @param[out] *Err : true if an error is detected +/// @param[out] *Col : the column number [1..24] +/// @param[out] *Dilogic : the dilogic number [1..10] +/// @param[out] *Eoesize : the number of words for dilogic +/// @returns True if EoE marker is detected +bool HmpidDecoder::isEoEmarker(int32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize) +{ + *Err = false; + // #EX MASK Raul 0x3803FF80 # ex mask 0xF803FF80 - this is EoE marker 0586800B0 + if ((wp & 0x0803FF80) == 0x08000080) { + *Col = (wp & 0x07c00000) >> 22; + *Dilogic = (wp & 0x003C0000) >> 18; + *Eoesize = (wp & 0x0000007F); + if (*Col > 24 || *Dilogic > 10) { + ILOG(INFO) << " EoE size wrong definition. Col=" << *Col << " Dilogic=" << *Dilogic << FairLogger::endl; + *Err = true; + } + return (true); + } else { + return (false); + } +} + +/// Decode the HMPID error BitMap field (5 bits) and returns true if there are +/// errors and in addition the concat string that contains the error messages +/// ATTENTION : the char * outbuf MUST point to a 250 bytes buffer +/// @param[in] ErrorField : the HMPID Error field +/// @param[out] *outbuf : the output buffer that contains the error description +/// @returns True if EoE marker is detected +bool HmpidDecoder::decodeHmpidError(int ErrorField, char *outbuf) +{ + int res = false; + outbuf[0] = '\0'; + for (int i = 0; i < MAXHMPIDERRORS; i++) { + if ((ErrorField & (0x01 << i)) != 0) { + res = true; + strcat(outbuf, sHmpidErrorDescription[i]); + } + } + return (res); +} + +/// This Decode the Raw Data Header, returns the EquipmentIndex +/// that is obtained with the FLP hardware coords +/// +/// ATTENTION : the 'EquipIndex' parameter and the mEquipment member +/// are different data: the first is the pointer in the Equipments instances +/// array, the second is the FEE_ID number +/// +/// The EVENT_NUMBER : actually is calculated from the ORBIT number +/// +/// @param[in] *streamPtrAdr : the pointer to the Header buffer +/// @param[out] *EquipIndex : the Index to the Equipment Object Array [0..13] +/// @returns True every time +/// @throws TH_WRONGEQUIPINDEX Thrown if the Equipment Index is out of boundary (Equipment not recognized) +int HmpidDecoder::decodeHeader(int32_t *streamPtrAdr, int *EquipIndex) +{ + int32_t *buffer = streamPtrAdr; // Sets the pointer to buffer + + mHeFEEID = (buffer[0] & 0x000f0000) >> 16; + mHeSize = (buffer[0] & 0x0000ff00) >> 8; + mHeVer = (buffer[0] & 0x000000ff); + mHePrior = (buffer[1] & 0x000000FF); + mHeDetectorID = (buffer[1] & 0x0000FF00) >> 8; + mHeOffsetNewPack = (buffer[2] & 0x0000FFFF); + mHeMemorySize = (buffer[2] & 0xffff0000) >> 16; + mHeDW = (buffer[3] & 0xF0000000) >> 24; + mHeCruID = (buffer[3] & 0x0FF0000) >> 16; + mHePackNum = (buffer[3] & 0x0000FF00) >> 8; + mHeLinkNum = (buffer[3] & 0x000000FF); + mHeBCDI = (buffer[4] & 0x00000FFF); + mHeORBIT = buffer[5]; + mHeTType = buffer[8]; + mHePageNum = (buffer[9] & 0x0000FFFF); + mHeStop = (buffer[9] & 0x00ff0000) >> 16; + mHeBusy = (buffer[12] & 0xfffffe00) >> 9; + mHeFirmwareVersion = buffer[12] & 0x0000000f; + mHeHmpidError = (buffer[12] & 0x000001F0) >> 4; + mHePAR = buffer[13] & 0x0000FFFF; + + *EquipIndex = getEquipmentIndex(mHeCruID, mHeLinkNum); + // mEquipment = (*EquipIndex != -1) ? mTheEquipments[*EquipIndex]->getEquipmentId() : -1; + mEquipment = mHeFEEID; + mNumberWordToRead = ((mHeMemorySize - mHeSize) / sizeof(uint32_t)); + mPayloadTail = ((mHeOffsetNewPack - mHeMemorySize) / sizeof(uint32_t)); + + // ---- Event ID : Actualy based on ORBIT NUMBER ... + mHeEvent = mHeORBIT; + + ILOG(INFO) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID <<\ + " HeMemorySize=" << mHeMemorySize << " HeOffsetNewPack=" << mHeOffsetNewPack << FairLogger::endl; + ILOG(INFO) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << \ + mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT << FairLogger::endl; + ILOG(INFO) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ + mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR << FairLogger::endl; + ILOG(INFO) << " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail << FairLogger::endl; + + if (*EquipIndex == -1) { + ILOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment << FairLogger::endl; + throw TH_WRONGEQUIPINDEX; + } + return (true); +} + +/// Updates some information related to the Event +/// this function is called at the end of the event +/// @param[in] *eq : the pointer to the Equipment Object +void HmpidDecoder::updateStatistics(HmpidEquipment *eq) +{ + eq->mPadsPerEventAverage = ((eq->mPadsPerEventAverage * (eq->mNumberOfEvents - 1)) + eq->mSampleNumber) + / (eq->mNumberOfEvents); + eq->mEventSizeAverage = ((eq->mEventSizeAverage * (eq->mNumberOfEvents - 1)) + eq->mEventSize) + / (eq->mNumberOfEvents); + eq->mBusyTimeAverage = ((eq->mBusyTimeAverage * eq->mBusyTimeSamples) + eq->mBusyTimeValue) + / (++(eq->mBusyTimeSamples)); + if (eq->mSampleNumber == 0) + eq->mNumberOfEmptyEvents += 1; + if (eq->mErrorsCounter > 0) + eq->mNumberOfWrongEvents += 1; + eq->mTotalPads += eq->mSampleNumber; + eq->mTotalErrors += eq->mErrorsCounter; + return; +} + +/// Evaluates the content of the header and detect the change of the event +/// with the relevant updates... +/// @param[in] EquipmentIndex : the pointer to the Array of Equipments Array +/// @returns the Pointer to the modified Equipment object +HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) +{ + HmpidEquipment *eq = mTheEquipments[EquipmentIndex]; + if (mHeEvent != eq->mEventNumber) { // Is a new event + if (eq->mEventNumber != -1) { // skip the first + updateStatistics(eq); // update previous statistics + } + eq->mNumberOfEvents++; + eq->mEventNumber = mHeEvent; + eq->mBusyTimeValue = mHeBusy * 0.00000005; + eq->mEventSize = 0; // reset the event + eq->mSampleNumber = 0; + eq->mErrorsCounter = 0; + } + eq->mEventSize += mNumberWordToRead * sizeof(uint32_t); // Calculate the size in bytes + if (mHeHmpidError != 0) { + ILOG(ERROR) << "HMPID Header reports an error : " << mHeHmpidError << FairLogger::endl; + dumpHmpidError(mHeHmpidError); + eq->setError(ERR_HMPID); + } + return (eq); +} + +/// --------------- Read Raw Data Buffer --------------- +/// Read the stream, decode the contents and store resuls. +/// ATTENTION : Assumes that the input stream was set +/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header +bool HmpidDecoder::decodeBuffer() +{ + // ---------resets the PAdMap----------- + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i]->init(); + mTheEquipments[i]->resetPadMap(); + mTheEquipments[i]->resetErrors(); + } + + int type; + int equipmentIndex = -1; + int isIt; + HmpidEquipment *eq; + int32_t *streamBuf; + ILOG(DEBUG) << "Enter decoding !" << FairLogger::endl; + + // Input Stream Main Loop + while (true) { + try { + getHeaderFromStream(&streamBuf); + } + catch (int e) { + // The stream end ! + ILOG(DEBUG) << "End main decoding loop !" << FairLogger::endl; + break; + } + try { + decodeHeader(streamBuf, &equipmentIndex); + } + catch (int e) { + ILOG(ERROR) << "Failed to decode the Header !" << FairLogger::endl; + throw TH_WRONGHEADER; + } + + eq = evaluateHeaderContents(equipmentIndex); + + int wpprev = 0; + int wp = 0; + int newOne = true; + int p1, p2, p3, p4; + int error; + + int payIndex = 0; + while (payIndex < mNumberWordToRead) { //start the payload loop word by word + if (newOne == true) { + wpprev = wp; + if (!getWordFromStream(&wp)) { // end the stream + break; + } + + type = checkType(wp, &p1, &p2, &p3, &p4); + if (type == WTYPE_NONE) { + if (eq->mWillBePad == true) { // try to recover the first pad ! + type = checkType((wp & 0xF7FFFFFF), &p1, &p2, &p3, &p4); + if (type == WTYPE_PAD && p3 == 0 && eq->mWordsPerDilogicCounter == 0) { + newOne = false; // # reprocess as pad + continue; + } + } + eq->setError(ERR_NOTKNOWN); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_NOTKNOWN] << " [" << wp << "]" << FairLogger::endl; + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; + payIndex++; + continue; + } + } + + if (eq->mWillBeRowMarker == true) { // #shoud be a Row Marker + if (type == WTYPE_ROW) { + eq->mColumnCounter++; + eq->mWordsPerSegCounter++; + eq->mRowSize = p2; + switch (p2) { + case 0: // Empty column + eq->setError(ERR_ROWMARKEMPTY); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKEMPTY] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = true; + break; + case 0x3FF: // Error in column + eq->setError(ERR_ROWMARKERROR); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKERROR] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = true; + break; + case 0x3FE: // Masked column + ILOG(INFO) << "Equip=" << mEquipment << "The column=" << (eq->mSegment) * 8 + eq->mColumnCounter << " is Masked !" << FairLogger::endl; + eq->mWillBeRowMarker = true; + break; + default: + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + break; + } + newOne = true; + } else { + if (wp == wpprev) { + eq->setError(ERR_DUPLICATEPAD); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + newOne = true; + } else if (type == WTYPE_EOE) { // # Could be a EoE + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKWRONG); + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } else if (type == WTYPE_PAD) { //# Could be a PAD + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKLOST); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } else if (type == WTYPE_EOS) { // # Could be a EoS + eq->mWillBeRowMarker = false; + eq->mWillBeSegmentMarker = true; + newOne = false; + } else { + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKLOST); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } + } + } else if (eq->mWillBePad == true) { // # We expect a pad + //# PAD:0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value + // c = 1..24 d = 1..10 n = 0..47 + if (type == WTYPE_PAD) { + newOne = true; + if (wp == wpprev) { + eq->setError(ERR_DUPLICATEPAD); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + } else if (p1 != (eq->mSegment * 8 + eq->mColumnCounter)) { // # Manage + // We try to recover the RowMarker misunderstanding + isIt = isRowMarker(wp, &error, &p2, &p1); + if (isIt == true && error == false) { + type = WTYPE_ROW; + newOne = false; + eq->mWillBeEoE = true; + eq->mWillBePad = false; + } else { + ILOG(DEBUG) << "Equip=" << mEquipment << " Mismatch in column" << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mColumnCounter = p1 % 8; + } + } else { + setPad(eq, p1 - 1, p2 - 1, p3, p4); + eq->mWordsPerDilogicCounter++; + eq->mSampleNumber++; + if (p3 == 47) { + eq->mWillBeEoE = true; + eq->mWillBePad = false; + } + } + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; + } else if (type == WTYPE_EOE) { //# the pads are end ok + eq->mWillBeEoE = true; + eq->mWillBePad = false; + newOne = false; + } else if (type == WTYPE_ROW) { // # We Lost the EoE ! + // We try to recover the PAD misunderstanding + isIt = isPadWord(wp, &error, &p1, &p2, &p3, &p4); + if (isIt == true && error == false) { + type = WTYPE_PAD; + newOne = false; // # reprocess as pad + } else { + eq->setError(ERR_LOSTEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = true; + eq->mWillBePad = false; + newOne = false; + } + } else if (type == WTYPE_EOS) { // # We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeSegmentMarker = true; + eq->mWillBePad = false; + newOne = false; + } + } else if (eq->mWillBeEoE == true) { // # We expect a EoE + if (type == WTYPE_EOE) { + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; + if (wpprev == wp) { + eq->setError(ERR_DOUBLEEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEEOEMARK] << " col=" << p1 << FairLogger::endl; + } else if (p3 != eq->mWordsPerDilogicCounter) { + eq->setError(ERR_WRONGSIZEINEOE); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZEINEOE] << " col=" << p1 << FairLogger::endl; + } + eq->mWordsPerDilogicCounter = 0; + if (p2 == 10) { + if (p1 % 8 != 0) { // # we expect the Row Marker + eq->mWillBeRowMarker = true; + } else { + eq->mWillBeSegmentMarker = true; + } + } else { + eq->mWillBePad = true; + } + eq->mWillBeEoE = false; + newOne = true; + } else if (type == WTYPE_EOS) { // We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeSegmentMarker = true; + eq->mWillBeEoE = false; + newOne = false; + } else if (type == WTYPE_ROW) { //# We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeRowMarker = true; + eq->mWillBeEoE = false; + newOne = false; + } else if (type == WTYPE_PAD) { // # We Lost the EoE ! + int typb, p1b, p2b, p3b, p4b; + typb = checkType((wp | 0x08000000), &p1b, &p2b, &p3b, &p4b); + if (typb == WTYPE_EOE && p3b == 48) { + type = typb; + p1 = p1b; + p2 = p2b; + p3 = p3b; + p4 = p4b; + newOne = false; // # reprocess as EoE + } else { + eq->setError(ERR_LOSTEOEMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBePad = true; + eq->mWillBeEoE = false; + newOne = false; + } + } + } else if (eq->mWillBeSegmentMarker == true) { // # We expect a EoSegment + if (wpprev == wp) { + eq->setError(ERR_DOUBLEMARKWORD); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEMARKWORD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + newOne = true; + } else if (type == 2) { + if (abs(eq->mWordsPerSegCounter - p2) > 5) { + eq->setError(ERR_WRONGSIZESEGMENTMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZESEGMENTMARK] << " Seg=" << p2 << FairLogger::endl; + } + eq->mWordsPerSegCounter = 0; + eq->mWordsPerRowCounter = 0; + eq->mColumnCounter = 0; + eq->mSegment = p3 % 3; + eq->mWillBeRowMarker = true; + eq->mWillBeSegmentMarker = false; + newOne = true; + } else { + eq->setError(ERR_LOSTEOSMARK); + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOSMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + eq->mWillBeSegmentMarker = false; + eq->mWillBeRowMarker = true; + newOne = false; + } + } + if (newOne) { + payIndex += 1; + } + } + for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail + getWordFromStream(&wp); + } + } // this is the end of stream + + // cycle in order to update info for the last event + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->mNumberOfEvents > 0) { + updateStatistics(mTheEquipments[i]); + } + } + return (true); +} + +/// ---------- Read Raw Data Buffer with Fast Decoding ---------- +/// Read the stream, decode the contents and store resuls. +/// Fast alghoritm : no parsing of control words ! +/// ATTENTION : Assumes that the input stream was set +/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header +bool HmpidDecoder::decodeBufferFast() +{ + // ---------resets the PAdMap----------- + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i]->init(); + mTheEquipments[i]->resetPadMap(); + } + + int type; + int equipmentIndex = -1; + int isIt; + HmpidEquipment *eq; + int32_t *streamBuf; + ILOG(DEBUG) << "Enter FAST decoding !" << FairLogger::endl; + + // Input Stream Main Loop + while (true) { + try { + getHeaderFromStream(&streamBuf); + } + catch (int e) { + // The stream end ! + ILOG(DEBUG) << "End main decoding loop !" << FairLogger::endl; + break; + } + try { + decodeHeader(streamBuf, &equipmentIndex); + } + catch (int e) { + ILOG(ERROR) << "Failed to decode the Header !" << FairLogger::endl; + throw TH_WRONGHEADER; + } + + eq = evaluateHeaderContents(equipmentIndex); + + int wpprev = 0; + int wp = 0; + int newOne = true; + int p1, p2, p3, p4; + int error; + + int payIndex = 0; + while (payIndex < mNumberWordToRead) { //start the payload loop word by word + wpprev = wp; + if (!getWordFromStream(&wp)) { // end the stream + break; + } + if (wp == wpprev) { + ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]" << FairLogger::endl; + } else { + if( isPadWord(wp, &error, &p1, &p2, &p3, &p4) == true) { + if( error != false) { + setPad(eq, p1 - 1, p2 - 1, p3, p4); + eq->mSampleNumber++; + } + } + } + payIndex += 1; + } + for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail + getWordFromStream(&wp); + } + } // this is the end of stream + + // cycle in order to update info for the last event + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->mNumberOfEvents > 0) { + updateStatistics(mTheEquipments[i]); + } + } + return (true); +} + + + +// ========================================================= + +/// Getter method to extract Statistic Data in Digit Coords +/// @param[in] Module : the HMPID Module number [0..6] +/// @param[in] Column : the HMPID Module Column number [0..143] +/// @param[in] Row : the HMPID Module Row number [0..159] +/// @returns The Number of entries for specified pad +uint16_t HmpidDecoder::getPadSamples(int Module, int Column, int Row) +{ + int e, c, d, h; + Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + int EqInd = getEquipmentIndex(e); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSamples[c][d][h]); +} + +/// Getter method to extract Statistic Data in Digit Coords +/// @param[in] Module : the HMPID Module number [0..6] +/// @param[in] Column : the HMPID Module Column number [0..143] +/// @param[in] Row : the HMPID Module Row number [0..159] +/// @returns The Sum of Charges for specified pad +double HmpidDecoder::getPadSum(int Module, int Column, int Row) +{ + int e, c, d, h; + Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + int EqInd = getEquipmentIndex(e); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSum[c][d][h]); +} + +/// Getter method to extract Statistic Data in Digit Coords +/// @param[in] Module : the HMPID Module number [0..6] +/// @param[in] Column : the HMPID Module Column number [0..143] +/// @param[in] Row : the HMPID Module Row number [0..159] +/// @returns The Sum of Square Charges for specified pad +double HmpidDecoder::getPadSquares(int Module, int Column, int Row) +{ + int e, c, d, h; + Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + int EqInd = getEquipmentIndex(e); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSquares[c][d][h]); +} + +/// Getter method to extract Statistic Data in Hardware Coords +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @param[in] Column : the HMPID Module Column number [0..23] +/// @param[in] Dilogic : the HMPID Module Row number [0..9] +/// @param[in] Channel : the HMPID Module Row number [0..47] +/// @returns The Number of Entries for specified pad +uint16_t HmpidDecoder::getChannelSamples(int EquipmId, int Column, int Dilogic, int Channel) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSamples[Column][Dilogic][Channel]); +} + +/// Getter method to extract Statistic Data in Hardware Coords +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @param[in] Column : the HMPID Module Column number [0..23] +/// @param[in] Dilogic : the HMPID Module Row number [0..9] +/// @param[in] Channel : the HMPID Module Row number [0..47] +/// @returns The Sum of Charges for specified pad +double HmpidDecoder::getChannelSum(int EquipmId, int Column, int Dilogic, int Channel) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSum[Column][Dilogic][Channel]); +} + +/// Getter method to extract Statistic Data in Hardware Coords +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @param[in] Column : the HMPID Module Column number [0..23] +/// @param[in] Dilogic : the HMPID Module Row number [0..9] +/// @param[in] Channel : the HMPID Module Row number [0..47] +/// @returns The Sum of Square Charges for specified pad +double HmpidDecoder::getChannelSquare(int EquipmId, int Column, int Dilogic, int Channel) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return (0); + return (mTheEquipments[EqInd]->mPadSquares[Column][Dilogic][Channel]); +} + +/// Gets the Average Event Size value +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @returns The Average Event Size value ( 0 for wrong Equipment Id) +float HmpidDecoder::getAverageEventSize(int EquipmId) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return (0.0); + return (mTheEquipments[EqInd]->mEventSizeAverage); +} + +/// Gets the Average Busy Time value +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @returns The Average Busy Time value ( 0 for wrong Equipment Id) +float HmpidDecoder::getAverageBusyTime(int EquipmId) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return (0.0); + return (mTheEquipments[EqInd]->mBusyTimeAverage); +} + +// =================================================== +// Methods to dump info + + +/// Prints on the standard output the table of decoding +/// errors for one equipment +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +void HmpidDecoder::dumpErrors(int EquipmId) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return; + + std::cout << "Dump Errors for the Equipment = " << EquipmId << std::endl; + for (int i = 0; i < MAXERRORS; i++) { + std::cout << sErrorDescription[i] << " = " << mTheEquipments[EqInd]->mErrors[i] << std::endl; + } + std::cout << " -------- " << std::endl; + return; +} + +/// Prints on the standard output a Table of statistical +/// decoding information for one equipment +/// @param[in] EquipmId : the HMPID EquipmentId [0..13] +/// @type[in] The type of info. 0 = Entries, 1 = Sum, 2 = Sum of squares +void HmpidDecoder::dumpPads(int EquipmId, int type) +{ + int EqInd = getEquipmentIndex(EquipmId); + if (EqInd < 0) + return; + + int Module = EquipmId / 2; + int StartRow = (EquipmId % 2 == 1) ? 80 : 0; + int EndRow = (EquipmId % 2 == 1) ? 160 : 80; + std::cout << "Dump Pads for the Equipment = " << EquipmId << std::endl; + for (int c = 0; c < 144; c++) { + for (int r = StartRow; r < EndRow; r++) { + switch (type) { + case 0: + std::cout << getPadSamples(Module, c, r) << ","; + break; + case 1: + std::cout << getPadSum(Module, c, r) << ","; + break; + case 2: + std::cout << getPadSquares(Module, c, r) << ","; + break; + } + } + std::cout << std::endl; + } + std::cout << " -------- " << std::endl; + return; +} + +/// Prints on the standard output the decoded HMPID error field +/// @param[in] ErrorField : the HMPID readout error field +void HmpidDecoder::dumpHmpidError(int ErrorField) +{ + char printbuf[MAXHMPIDERRORS * MAXDESCRIPTIONLENGHT]; + if (decodeHmpidError(ErrorField, printbuf) == true) { + ILOG(ERROR) << "HMPID Error field = " << ErrorField << " : " << printbuf << FairLogger::endl; + } + return; +} + +/// Writes in a ASCCI File the complete report of the decoding +/// procedure +/// @param[in] *summaryFileName : the name of the output file +/// @throws TH_CREATEFILE Thrown if was not able to create the file +void HmpidDecoder::writeSummaryFile(char *summaryFileName) +{ + FILE *fs = fopen(summaryFileName, "w"); + if (fs == 0) { + printf("Error opening the file %s !\n", summaryFileName); + throw TH_CREATEFILE; + } + + fprintf(fs, "HMPID Readout Raw Data Decoding Summary File\n"); + fprintf(fs, "Equipment Id\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->getEquipmentId()); + fprintf(fs, "\n"); + + fprintf(fs, "Number of events\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mNumberOfEvents); + fprintf(fs, "\n"); + + fprintf(fs, "Average Event Size\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%f\t", mTheEquipments[i]->mEventSizeAverage); + fprintf(fs, "\n"); + + fprintf(fs, "Total pads\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mTotalPads); + fprintf(fs, "\n"); + + fprintf(fs, "Average pads per event\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%f\t", mTheEquipments[i]->mPadsPerEventAverage); + fprintf(fs, "\n"); + + fprintf(fs, "Busy Time average\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%e\t", mTheEquipments[i]->mBusyTimeAverage); + fprintf(fs, "\n"); + + fprintf(fs, "Event rate\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%e\t", 1 / mTheEquipments[i]->mBusyTimeAverage); + fprintf(fs, "\n"); + + fprintf(fs, "Number of Empty Events\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mNumberOfEmptyEvents); + fprintf(fs, "\n"); + + fprintf(fs, "-------------Errors--------------------\n"); + fprintf(fs, "Wrong events\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mNumberOfWrongEvents); + fprintf(fs, "\n"); + + for (int j = 0; j < MAXERRORS; j++) { + fprintf(fs, "%s\t", sErrorDescription[j]); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mErrors[j]); + fprintf(fs, "\n"); + } + + fprintf(fs, "Total errors\t"); + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + fprintf(fs, "%d\t", mTheEquipments[i]->mTotalErrors); + fprintf(fs, "\n"); + + fclose(fs); + return; +} diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.h b/Detectors/HMPID/reconstruction/src/HmpidDecoder.h new file mode 100644 index 0000000000000..f01a58962d54a --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.h @@ -0,0 +1,167 @@ +// 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 HmpidDecoder.h +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to decode HMPID Raw Data stream +/// + +#ifndef COMMON_HMPIDDECODER_H_ +#define COMMON_HMPIDDECODER_H_ + +#include +#include +#include +#include + +#include "FairLogger.h" + +#include "HmpidEquipment.h" + +#define MAXDESCRIPTIONLENGHT 50 + +// ---- RDH 6 standard dimension ------- +#define RAWBLOCKDIMENSION_W 2048 +#define HEADERDIMENSION_W 16 +#define PAYLOADDIMENSION_W 2032 + +// ---- Defines for the decoding +#define WTYPE_ROW 1 +#define WTYPE_EOS 2 +#define WTYPE_PAD 3 +#define WTYPE_EOE 4 +#define WTYPE_NONE 0 + + +// Hmpid Equipment class +namespace o2 { + +namespace hmpid { + +class HmpidDecoder +{ + + // Members + public: + int mVerbose; + HmpidEquipment *mTheEquipments[Geo::MAXEQUIPMENTS]; + int mNumberOfEquipments; + + static char sErrorDescription[MAXERRORS][MAXDESCRIPTIONLENGHT]; + static char sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT]; + + public: + int mHeEvent; + int mHeBusy; + int mNumberWordToRead; + int mPayloadTail; + + int mHeFEEID; + int mHeSize; + int mHeVer; + int mHePrior; + int mHeStop; + int mHePages; + int mEquipment; + + int mHeOffsetNewPack; + int mHeMemorySize; + + int mHeDetectorID; + int mHeDW; + int mHeCruID; + int mHePackNum; + int mHePAR; + + int mHePageNum; + int mHeLinkNum; + int mHeFirmwareVersion; + int mHeHmpidError; + int mHeBCDI; + int mHeORBIT; + int mHeTType; + + int32_t *mActualStreamPtr; + int32_t *mEndStreamPtr; + int32_t *mStartStreamPtr; + + // Methods + public: + HmpidDecoder(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); + HmpidDecoder(int numOfEquipments); + ~HmpidDecoder(); + + void init(); + virtual bool setUpStream(void *Buffer, long BufferLen) = 0; + void setVerbosity(int Level) + { + mVerbose = Level; + } + ; + int getVerbosity() + { + return (mVerbose); + } + ; + + int getNumberOfEquipments() + { + return (mNumberOfEquipments); + } + ; + int getEquipmentIndex(int EquipmentId); + int getEquipmentIndex(int CruID, int LinkId); + int getEquipmentID(int CruId, int LinkId); + + bool decodeBuffer(); + bool decodeBufferFast(); + + uint16_t getChannelSamples(int Equipment, int Column, int Dilogic, int Channel); + double getChannelSum(int Equipment, int Column, int Dilogic, int Channel); + double getChannelSquare(int Equipment, int Column, int Dilogic, int Channel); + uint16_t getPadSamples(int Module, int Column, int Row); + double getPadSum(int Module, int Column, int Row); + double getPadSquares(int Module, int Column, int Row); + + void dumpErrors(int Equipment); + void dumpPads(int Equipment, int type = 0); + void writeSummaryFile(char *summaryFileName); + + float getAverageEventSize(int Equipment); + float getAverageBusyTime(int Equipment); + + protected: + int checkType(int32_t wp, int *p1, int *p2, int *p3, int *p4); + bool isRowMarker(int32_t wp, int *Err, int *rowSize, int *mark); + bool isSegmentMarker(int32_t wp, int *Err, int *segSize, int *Seg, int *mark); + bool isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge); + bool isEoEmarker(int32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize); + int decodeHeader(int32_t *streamPtrAdr, int *EquipIndex); + bool decodeHmpidError(int ErrorField, char *outbuf); + void dumpHmpidError(int ErrorField); + HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); + void updateStatistics(HmpidEquipment *eq); + + virtual void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) = 0; + + virtual bool getBlockFromStream(int32_t **streamPtr, uint32_t Size) = 0; + virtual bool getHeaderFromStream(int32_t **streamPtr) = 0; + virtual bool getWordFromStream(int32_t *word) = 0; + int32_t* getActualStreamPtr() + { + return (mActualStreamPtr); + } + ; + +}; +} +} +#endif /* COMMON_HMPIDDECODER_H_ */ diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx new file mode 100644 index 0000000000000..fc442cc92be1b --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx @@ -0,0 +1,139 @@ +// 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 HmpidEquipments.h +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to describe HMPID Equipment +/// \version 1.0 +/// \date 24 set 2020 + +/* ------ HISTORY --------- +*/ + +#include "HmpidEquipment.h" + +using namespace o2::hmpid; + +// ============= HmpidEquipment Class implementation ======= + +/// Constructor : map the Equipment_ID with the CRU_Id and Link_Id +/// +/// @param[in] Equipment : the HMPID EquipmentId [0..13] +/// @param[in] Cru : the HMPID Cru [0..3] (FLP160 = 0,1 FLP161 = 2,3) +/// @param[in] Link : the FLP Link [0..3] +HmpidEquipment::HmpidEquipment(int Equipment, int Cru, int Link) +{ + mEquipmentId = Equipment; + mCruId = Cru; + mLinkId = Link; + return; +} + +/// Destructor : do nothing +HmpidEquipment::~HmpidEquipment() +{ + return; +} + +/// Inits the members for the decoding +void HmpidEquipment::init() +{ + mWillBeRowMarker = true; + mWillBeSegmentMarker = false; + mWillBeEoE = false; + mWillBePad = false; + mRowSize = 0; + mSegment = 0; + mColumnCounter = 0; + mWordsPerRowCounter = 0; + mWordsPerSegCounter = 0; + mWordsPerDilogicCounter = 0; + mSampleNumber = 0; + mErrorsCounter = 0; + mErrorPadsPerEvent = 0; + + mEventNumber = -1; + mNumberOfEvents = 0; + + mBusyTimeValue = 0.0; + mBusyTimeAverage = 0.0; + mBusyTimeSamples = 0; + + mEventSizeAverage = 0.0; + mEventSize = 0; + + mPadsPerEventAverage = 0.0; + + mNumberOfEmptyEvents = 0; + mNumberOfWrongEvents = 0; + mTotalPads = 0; + mTotalErrors = 0; + + return; +} + +/// Resets the matrix that contains the results of the decoding +void HmpidEquipment::resetPadMap() +{ + for (int r = 0; r < Geo::N_COLUMNS; r++) + for (int d = 0; d < Geo::N_DILOGICS; d++) + for (int c = 0; c < Geo::N_CHANNELS; c++) { + mPadSamples[r][d][c] = 0; + mPadSum[r][d][c] = 0.0; + mPadSquares[r][d][c] = 0.0; + } + return; +} + +/// Resets the decoding errors statistics +void HmpidEquipment::resetErrors() +{ + for (int i = 0; i < MAXERRORS; i++) + mErrors[i] = 0; + return; +} + +/// Setup an error by type +/// TODO : control of array boundary +/// @param[in] ErrType : the Decoding error type [0..MAXERRORS] +void HmpidEquipment::setError(int ErrType) +{ + mErrors[ErrType]++; + mErrorsCounter++; + return; +} + +/// Set the charge value of a pad into the three statistics +/// matrix : Entries, Sum of charge, Sum of Charge squares +/// @param[in] col : column [0..23] +/// @param[in] dil : dilogic [0..9] +/// @param[in] cha : channel [0..47] +/// @param[in] charge : the value of the charge +void HmpidEquipment::setPad(int col, int dil, int cha, int charge) +{ + mPadSamples[col][dil][cha]++; + mPadSum[col][dil][cha] += (double) charge; + mPadSquares[col][dil][cha] += (double) charge * (double) charge; + return; +} + +/// Return the EquipmentId with the check of CRU_Id and Link_Id +/// @param[in] cru : FLP CRU Id [0..3] +/// @param[in] link : CRU Link Id [0..3] +/// @returns the Equipment Id +int HmpidEquipment::getEquipmentId(int cru, int link) +{ + if (cru == mCruId && link == mLinkId) + return (mEquipmentId); + else + return (-1); +} + diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.h b/Detectors/HMPID/reconstruction/src/HmpidEquipment.h new file mode 100644 index 0000000000000..aa324ea9c2fa9 --- /dev/null +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.h @@ -0,0 +1,135 @@ +// 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 HmpidEquipments.h +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to describe HMPID Equipment for the decoding of RawData stream +/// \version 1.0 +/// \date 24 set 2020 + +#ifndef COMMON_HMPIDEQUIPMENT_H_ +#define COMMON_HMPIDEQUIPMENT_H_ + +#include +#include +#include + +#include "HMPIDBase/Geo.h" + +namespace o2 +{ +namespace hmpid +{ + +const int MAXERRORS = 13; +const int MAXHMPIDERRORS = 5; + +const int ERR_NOTKNOWN = 0; +const int ERR_ROWMARKEMPTY = 1; +const int ERR_DUPLICATEPAD = 2; +const int ERR_ROWMARKWRONG = 3; +const int ERR_ROWMARKLOST = 4; +const int ERR_ROWMARKERROR = 5; +const int ERR_LOSTEOEMARK = 6; +const int ERR_DOUBLEEOEMARK = 7; +const int ERR_WRONGSIZEINEOE = 8; +const int ERR_DOUBLEMARKWORD = 9; +const int ERR_WRONGSIZESEGMENTMARK = 10; +const int ERR_LOSTEOSMARK = 11; +const int ERR_HMPID = 12; + +// ---- HMPID error def ------- +const int TH_FILENOTEXISTS = 9; +const int TH_OPENFILE = 8; +const int TH_CREATEFILE = 7; +const int TH_READFILE = 6; +const int TH_WRITEFILE = 5; +const int TH_WRONGEQUIPINDEX = 19; +const int TH_WRONGHEADER = 15; +const int TH_WRONGFILELEN = 14; +const int TH_NULLBUFFERPOINTER = 13; +const int TH_BUFFEREMPTY = 12; +const int TH_WRONGBUFFERDIM = 11; + + + + +class HmpidEquipment +{ + + private: + + uint32_t mEquipmentId; + uint32_t mCruId; + uint32_t mLinkId; + + public: + + uint32_t mPadSamples[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; + double mPadSum[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; + double mPadSquares[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; + + int mErrors[MAXERRORS]; + + int mWillBeRowMarker; + int mWillBeSegmentMarker; + int mWillBeEoE; + int mWillBePad; + int mRowSize; + int mSegment; + int mColumnCounter; + int mWordsPerRowCounter; + int mWordsPerSegCounter; + int mWordsPerDilogicCounter; + + int mErrorsCounter; + int mErrorPadsPerEvent; + + int mEventNumber; + int mNumberOfEvents; + float mEventSizeAverage; + int mEventSize; + + int mSampleNumber; + float mPadsPerEventAverage; + + float mBusyTimeValue; + float mBusyTimeAverage; + int mBusyTimeSamples; + int mNumberOfEmptyEvents; + int mNumberOfWrongEvents; + int mTotalPads; + int mTotalErrors; + + public: + HmpidEquipment(int Equipment, int Cru, int Link); + ~HmpidEquipment(); + + int getEquipmentId() + { + return (mEquipmentId); + } + ; + int getEquipmentId(int cru, int link); + + void init(); + void resetPadMap(); + void resetErrors(); + void setError(int ErrType); + void setPad(int col, int dil, int cha, int charge); + +}; + +} // namespace hmpid +} // namespace o2 + + +#endif /* COMMON_HMPIDEQUIPMENT_H_ */ diff --git a/GPU/GPUTracking/Standalone/Common b/GPU/GPUTracking/Standalone/Common index a66ad39d9318c..8267556b4adf4 120000 --- a/GPU/GPUTracking/Standalone/Common +++ b/GPU/GPUTracking/Standalone/Common @@ -1 +1 @@ -../../Common/ \ No newline at end of file +../../Common \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/Global b/GPU/GPUTracking/Standalone/Global index 7bfca6e01147e..f0aa85e860967 120000 --- a/GPU/GPUTracking/Standalone/Global +++ b/GPU/GPUTracking/Standalone/Global @@ -1 +1 @@ -../Global/ \ No newline at end of file +../Global \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/HLTHeaders b/GPU/GPUTracking/Standalone/HLTHeaders index 3f271033d8eeb..04ee42150c2fa 120000 --- a/GPU/GPUTracking/Standalone/HLTHeaders +++ b/GPU/GPUTracking/Standalone/HLTHeaders @@ -1 +1 @@ -../HLTHeaders/ \ No newline at end of file +../HLTHeaders \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/ITS b/GPU/GPUTracking/Standalone/ITS index 3ed25d6858b1e..d8e5c8b49d528 120000 --- a/GPU/GPUTracking/Standalone/ITS +++ b/GPU/GPUTracking/Standalone/ITS @@ -1 +1 @@ -../ITS/ \ No newline at end of file +../ITS \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/Merger b/GPU/GPUTracking/Standalone/Merger index ddb7c2e13a8d9..8bb6fe6d7b583 120000 --- a/GPU/GPUTracking/Standalone/Merger +++ b/GPU/GPUTracking/Standalone/Merger @@ -1 +1 @@ -../Merger/ \ No newline at end of file +../Merger \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/SliceTracker b/GPU/GPUTracking/Standalone/SliceTracker index b2ff0a64ab1a7..c34e64b9edf11 120000 --- a/GPU/GPUTracking/Standalone/SliceTracker +++ b/GPU/GPUTracking/Standalone/SliceTracker @@ -1 +1 @@ -../SliceTracker/ \ No newline at end of file +../SliceTracker \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/TPCFastTransformation b/GPU/GPUTracking/Standalone/TPCFastTransformation index a8c5e0a2ebd0c..d631da4216cd7 120000 --- a/GPU/GPUTracking/Standalone/TPCFastTransformation +++ b/GPU/GPUTracking/Standalone/TPCFastTransformation @@ -1 +1 @@ -../../TPCFastTransformation/ \ No newline at end of file +../../TPCFastTransformation \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/TRDTracking b/GPU/GPUTracking/Standalone/TRDTracking index db0ce36effe8b..8fb1cffa1420c 120000 --- a/GPU/GPUTracking/Standalone/TRDTracking +++ b/GPU/GPUTracking/Standalone/TRDTracking @@ -1 +1 @@ -../TRDTracking/ \ No newline at end of file +../TRDTracking \ No newline at end of file diff --git a/GPU/GPUTracking/Standalone/dependencies b/GPU/GPUTracking/Standalone/dependencies index 90273dd71ef60..c2e0ef0135d70 120000 --- a/GPU/GPUTracking/Standalone/dependencies +++ b/GPU/GPUTracking/Standalone/dependencies @@ -1 +1 @@ -../../../dependencies/ \ No newline at end of file +../../../dependencies \ No newline at end of file From acf6ceb9319e016dad810696273309baeb68056c Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 18 Jan 2021 10:03:04 +0100 Subject: [PATCH 094/208] Prima versione --- .../HMPID/base/include/HMPIDBase/Digit.h | 127 +--- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 7 +- Detectors/HMPID/base/src/Digit.cxx | 64 ++ Detectors/HMPID/base/src/Geo.cxx | 26 + .../HMPIDReconstruction}/HmpidDecodeRawFile.h | 8 +- .../HMPIDReconstruction}/HmpidDecodeRawMem.h | 24 +- .../HMPIDReconstruction}/HmpidDecoder.h | 37 +- .../HMPIDReconstruction}/HmpidEquipment.h | 2 +- .../reconstruction/src/HmpidDecodeRawFile.cxx | 14 +- .../reconstruction/src/HmpidDecodeRawMem.cxx | 78 +- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 689 ++++++++++-------- .../reconstruction/src/HmpidEquipment.cxx | 2 +- .../HMPID/simulation/src/HMPIDDigitizer.cxx | 7 +- .../include/HMPIDWorkflow/DataDecoderSpec.h | 16 + .../HMPID/workflow/src/DataDecoderSpec.cxx | 187 +++-- 15 files changed, 764 insertions(+), 524 deletions(-) rename Detectors/HMPID/reconstruction/{src => include/HMPIDReconstruction}/HmpidDecodeRawFile.h (87%) rename Detectors/HMPID/reconstruction/{src => include/HMPIDReconstruction}/HmpidDecodeRawMem.h (69%) rename Detectors/HMPID/reconstruction/{src => include/HMPIDReconstruction}/HmpidDecoder.h (78%) rename Detectors/HMPID/reconstruction/{src => include/HMPIDReconstruction}/HmpidEquipment.h (99%) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 27f43af50cedb..be5116f0da64e 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -23,96 +23,45 @@ namespace hmpid /// \class Digit /// \brief HMPID digit implementation -using DigitBase = o2::dataformats::TimeStamp; -class Digit : public DigitBase +//using DigitBase = o2::dataformats::TimeStamp; +class Digit { - public: - Digit() = default; - Digit(double time, int pad, float charge) : DigitBase(time), mPad(pad), mQ(charge) {} - - float getCharge() const { return mQ; } - int getPadID() const { return mPad; } - // convenience conversion to x-y pad coordinates - int getPx() const { return Param::A2X(mPad); } - int getPy() const { return Param::A2Y(mPad); } - - static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge) - { - float localX; - float localY; - chamber = hit.GetDetectorID(); - double tmp[3] = {hit.GetX(), hit.GetY(), hit.GetZ()}; - Param::Instance()->Mars2Lors(chamber, tmp, localX, localY); - Param::Lors2Pad(localX, localY, pc, px, py); - - totalcharge = Digit::QdcTot(hit.GetEnergyLoss(), hit.GetTime(), pc, px, py, localX, localY); - } - - static float getFractionalContributionForPad(HitType const& hit, int somepad) - { - float localX; - float localY; - - // chamber number is in detID - const auto chamber = hit.GetDetectorID(); - double tmp[3] = {hit.GetX(), hit.GetY(), hit.GetZ()}; - // converting chamber id and hit coordiates to local coordinates - Param::Instance()->Mars2Lors(chamber, tmp, localX, localY); - // calculate charge fraction in given pad - return Digit::InMathieson(localX, localY, somepad); - } - - // add charge to existing digit - void addCharge(float q) { mQ += q; } - - private: - float mQ = 0.; - int mPad = 0.; // -1 indicates invalid digit - - static float LorsX(int pad) { return Param::LorsX(Param::A2P(pad), Param::A2X(pad)); } //center of the pad x, [cm] - static float LorsY(int pad) { return Param::LorsY(Param::A2P(pad), Param::A2Y(pad)); } //center of the pad y, [cm] - - // determines the total charge created by a hit - // might modify the localX, localY coordiates associated to the hit - static float QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY); - - static float IntPartMathiX(float x, int pad) - { - // Integration of Mathieson. - // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603) - // Arguments: x,y- position of the center of Mathieson distribution - // Returns: a charge fraction [0-1] imposed into the pad - auto shift1 = -LorsX(pad) + 0.5 * Param::SizePadX(); - auto shift2 = -LorsX(pad) - 0.5 * Param::SizePadX(); - - auto ux1 = Param::SqrtK3x() * TMath::TanH(Param::K2x() * (x + shift1) / Param::PitchAnodeCathode()); - auto ux2 = Param::SqrtK3x() * TMath::TanH(Param::K2x() * (x + shift2) / o2::hmpid::Param::PitchAnodeCathode()); - - return o2::hmpid::Param::K4x() * (TMath::ATan(ux2) - TMath::ATan(ux1)); - } - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - static Double_t IntPartMathiY(Double_t y, int pad) - { - // Integration of Mathieson. - // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603) - // Arguments: x,y- position of the center of Mathieson distribution - // Returns: a charge fraction [0-1] imposed into the pad - Double_t shift1 = -LorsY(pad) + 0.5 * o2::hmpid::Param::SizePadY(); - Double_t shift2 = -LorsY(pad) - 0.5 * o2::hmpid::Param::SizePadY(); - - Double_t uy1 = Param::SqrtK3y() * TMath::TanH(Param::K2y() * (y + shift1) / Param::PitchAnodeCathode()); - Double_t uy2 = Param::SqrtK3y() * TMath::TanH(Param::K2y() * (y + shift2) / Param::PitchAnodeCathode()); - - return Param::K4y() * (TMath::ATan(uy2) - TMath::ATan(uy1)); - } - - static float InMathieson(float localX, float localY, int pad) - { - return 4. * Digit::IntPartMathiX(localX, pad) * Digit::IntPartMathiY(localY, pad); - } - - ClassDefNV(Digit, 2); + public: + Digit() = default; + Digit(int bc, int orbit, int pad, float charge) : mBc(bc), mOrbit(orbit), mPad(pad), mQ(charge) {}; + + float getCharge() const { return mQ; } + int getPadID() const { return mPad; } + int getOrbit() const { return mOrbit; } + int getBC() const { return mBc; } + + // convenience conversion to x-y pad coordinates + int getPx() const { return Param::A2X(mPad); } + int getPy() const { return Param::A2Y(mPad); } + + static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); + static float getFractionalContributionForPad(HitType const& hit, int somepad); + + // add charge to existing digit + void addCharge(float q) { mQ += q; } + + private: + float mQ = 0.; + int mPad = 0.; // -1 indicates invalid digit + int mBc = 0.; + int mOrbit = 0; + + static float LorsX(int pad) { return Param::LorsX(Param::A2P(pad), Param::A2X(pad)); } //center of the pad x, [cm] + static float LorsY(int pad) { return Param::LorsY(Param::A2P(pad), Param::A2Y(pad)); } //center of the pad y, [cm] + + // determines the total charge created by a hit + // might modify the localX, localY coordiates associated to the hit + static float QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY); + static float IntPartMathiX(float x, int pad); + static Double_t IntPartMathiY(Double_t y, int pad); + static float InMathieson(float localX, float localY, int pad); + + ClassDefNV(Digit, 2); }; } // namespace hmpid diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 469c32a5cba26..92c543fdeb2d2 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -11,7 +11,7 @@ #ifndef ALICEO2_HMPID_GEO_H #define ALICEO2_HMPID_GEO_H -//#include "Rtypes.h" +#include namespace o2 { @@ -62,8 +62,9 @@ class Geo static constexpr int N_HMPIDTOTALPADS = MAXEQUIPMENTS * N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; - void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); - void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); + static void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); + static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); + static Int_t GetPad(int Equi, int Colu, int Dilo, int Chan); // from //static constexpr Bool_t FEAWITHMASKS[NSECTORS] = diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index de4c9cea63ff4..e82d63fa5f5b9 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -17,6 +17,33 @@ using namespace o2::hmpid; ClassImp(o2::hmpid::Digit); +void Digit::getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge) +{ + float localX; + float localY; + chamber = hit.GetDetectorID(); + double tmp[3] = {hit.GetX(), hit.GetY(), hit.GetZ()}; + Param::Instance()->Mars2Lors(chamber, tmp, localX, localY); + Param::Lors2Pad(localX, localY, pc, px, py); + + totalcharge = Digit::QdcTot(hit.GetEnergyLoss(), hit.GetTime(), pc, px, py, localX, localY); +} + +float Digit::getFractionalContributionForPad(HitType const& hit, int somepad) +{ + float localX; + float localY; + + // chamber number is in detID + const auto chamber = hit.GetDetectorID(); + double tmp[3] = {hit.GetX(), hit.GetY(), hit.GetZ()}; + // converting chamber id and hit coordiates to local coordinates + Param::Instance()->Mars2Lors(chamber, tmp, localX, localY); + // calculate charge fraction in given pad + return Digit::InMathieson(localX, localY, somepad); +} + + float Digit::QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY) { // Samples total charge associated to a hit @@ -49,3 +76,40 @@ float Digit::QdcTot(float e, float time, int pc, int px, int py, float& localX, } return Q; } + +float Digit::IntPartMathiX(float x, int pad) +{ + // Integration of Mathieson. + // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603) + // Arguments: x,y- position of the center of Mathieson distribution + // Returns: a charge fraction [0-1] imposed into the pad + auto shift1 = -LorsX(pad) + 0.5 * Param::SizePadX(); + auto shift2 = -LorsX(pad) - 0.5 * Param::SizePadX(); + + auto ux1 = Param::SqrtK3x() * TMath::TanH(Param::K2x() * (x + shift1) / Param::PitchAnodeCathode()); + auto ux2 = Param::SqrtK3x() * TMath::TanH(Param::K2x() * (x + shift2) / o2::hmpid::Param::PitchAnodeCathode()); + + return o2::hmpid::Param::K4x() * (TMath::ATan(ux2) - TMath::ATan(ux1)); +} + + +Double_t Digit::IntPartMathiY(Double_t y, int pad) +{ + // Integration of Mathieson. + // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603) + // Arguments: x,y- position of the center of Mathieson distribution + // Returns: a charge fraction [0-1] imposed into the pad + Double_t shift1 = -LorsY(pad) + 0.5 * o2::hmpid::Param::SizePadY(); + Double_t shift2 = -LorsY(pad) - 0.5 * o2::hmpid::Param::SizePadY(); + + Double_t uy1 = Param::SqrtK3y() * TMath::TanH(Param::K2y() * (y + shift1) / Param::PitchAnodeCathode()); + Double_t uy2 = Param::SqrtK3y() * TMath::TanH(Param::K2y() * (y + shift2) / Param::PitchAnodeCathode()); + + return Param::K4y() * (TMath::ATan(uy2) - TMath::ATan(uy1)); +} + +float Digit::InMathieson(float localX, float localY, int pad) +{ + return 4. * Digit::IntPartMathiX(localX, pad) * Digit::IntPartMathiY(localY, pad); +} + diff --git a/Detectors/HMPID/base/src/Geo.cxx b/Detectors/HMPID/base/src/Geo.cxx index ef6f4a1da7858..6bb41aa916be2 100644 --- a/Detectors/HMPID/base/src/Geo.cxx +++ b/Detectors/HMPID/base/src/Geo.cxx @@ -9,6 +9,7 @@ // or submit itself to any jurisdiction. #include "HMPIDBase/Geo.h" +#include "HMPIDBase/Param.h" #include "TGeoManager.h" #include "TMath.h" #include "FairLogger.h" @@ -72,3 +73,28 @@ void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int } return; } + +//Int_t Geo::GetPad(int eqi, intnt_t row,Int_t dil,Int_t pad) +Int_t Geo::GetPad(int Equi, int Colu, int Dilo, int Chan) +{ + // The method returns the absolute pad number or -1 + // in case the charge from the channels + // has not been read or invalid arguments + + + if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= N_COLUMNS || + Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= N_CHANNELS ) return -1; + + int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) + int ch = Equi / 2; // The Module + + int tmp = (23 - Colu) / N_COLXSEGMENT; + int pc = (Equi % 2) ? 5-2*tmp : 2*tmp; // The PhotoCatode + + int px = (N_DILOGICS+1 - Dilo) * DILOPADSROWS - Chan / DILOPADSCOLS - 1; //flip according to Paolo (2-9-2008) + + tmp = (Equi % 2) ? Colu : (23-Colu); + int py = DILOPADSCOLS * (tmp % DILOPADSROWS)+a2y[Chan % DILOPADSCOLS]; + + return Param::Abs(ch,pc,px,py); +} diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h similarity index 87% rename from Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h rename to Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h index 38bebe8d31d77..bc3444583d634 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h @@ -44,16 +44,16 @@ class HmpidDecodeRawFile: public HmpidDecoder bool setUpStream(void *InpuFileName, long Size); private: - bool getBlockFromStream(int32_t **streamPtr, uint32_t Size); - bool getHeaderFromStream(int32_t **streamPtr); - bool getWordFromStream(int32_t *word); + bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size); + bool getHeaderFromStream(uint32_t **streamPtr); + bool getWordFromStream(uint32_t *word); int fileExists(char *filewithpath); void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); private: FILE *fh; char mInputFile[MAXFILENAMEBUFFER]; - int32_t mFileBuffer[MAXRAWFILEBUFFER]; + uint32_t mFileBuffer[MAXRAWFILEBUFFER]; }; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h similarity index 69% rename from Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.h rename to Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h index 9767a58d1f892..6d9160237e07d 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h @@ -24,7 +24,10 @@ #include #include #include +#include +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" #include "HmpidDecoder.h" namespace o2{ @@ -41,15 +44,30 @@ class HmpidDecodeRawMem: public HmpidDecoder bool setUpStream(void *Buffer, long BufferLen); private: - bool getBlockFromStream(int32_t **streamPtr, uint32_t Size); - bool getHeaderFromStream(int32_t **streamPtr); - bool getWordFromStream(int32_t *word); + bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size); + bool getHeaderFromStream(uint32_t **streamPtr); + bool getWordFromStream(uint32_t *word); void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); private: }; +class HmpidDecodeRawDigit: public HmpidDecodeRawMem +{ + public: + HmpidDecodeRawDigit(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); + HmpidDecodeRawDigit(int numOfEquipments); + ~HmpidDecodeRawDigit(); + + vector mDigits; + + private: + void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + + +}; + } } #endif /* COMMON_HMPIDDECODERAWFILE_H_ */ diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h similarity index 78% rename from Detectors/HMPID/reconstruction/src/HmpidDecoder.h rename to Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index f01a58962d54a..a1935caae561d 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -59,7 +59,7 @@ class HmpidDecoder static char sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT]; public: - int mHeEvent; + uint64_t mHeEvent; int mHeBusy; int mNumberWordToRead; int mPayloadTail; @@ -89,11 +89,13 @@ class HmpidDecoder int mHeORBIT; int mHeTType; - int32_t *mActualStreamPtr; - int32_t *mEndStreamPtr; - int32_t *mStartStreamPtr; + uint32_t *mActualStreamPtr; + uint32_t *mEndStreamPtr; + uint32_t *mStartStreamPtr; + int mRDHSize; + int mRDHAcceptedVersion; - // Methods + // Methods public: HmpidDecoder(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); HmpidDecoder(int numOfEquipments); @@ -121,6 +123,8 @@ class HmpidDecoder int getEquipmentIndex(int CruID, int LinkId); int getEquipmentID(int CruId, int LinkId); + void decodePage(uint32_t **streamBuffer); + void decodePageFast(uint32_t **streamBuf); bool decodeBuffer(); bool decodeBufferFast(); @@ -139,23 +143,24 @@ class HmpidDecoder float getAverageBusyTime(int Equipment); protected: - int checkType(int32_t wp, int *p1, int *p2, int *p3, int *p4); - bool isRowMarker(int32_t wp, int *Err, int *rowSize, int *mark); - bool isSegmentMarker(int32_t wp, int *Err, int *segSize, int *Seg, int *mark); - bool isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge); - bool isEoEmarker(int32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize); - int decodeHeader(int32_t *streamPtrAdr, int *EquipIndex); + int checkType(uint32_t wp, int *p1, int *p2, int *p3, int *p4); + bool isRowMarker(uint32_t wp, int *Err, int *rowSize, int *mark); + bool isSegmentMarker(uint32_t wp, int *Err, int *segSize, int *Seg, int *mark); + bool isEoEmarker(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize); + public: bool decodeHmpidError(int ErrorField, char *outbuf); void dumpHmpidError(int ErrorField); + bool isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge); + int decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex); HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); void updateStatistics(HmpidEquipment *eq); - + protected: virtual void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) = 0; - virtual bool getBlockFromStream(int32_t **streamPtr, uint32_t Size) = 0; - virtual bool getHeaderFromStream(int32_t **streamPtr) = 0; - virtual bool getWordFromStream(int32_t *word) = 0; - int32_t* getActualStreamPtr() + virtual bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size) = 0; + virtual bool getHeaderFromStream(uint32_t **streamPtr) = 0; + virtual bool getWordFromStream(uint32_t *word) = 0; + uint32_t* getActualStreamPtr() { return (mActualStreamPtr); } diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h similarity index 99% rename from Detectors/HMPID/reconstruction/src/HmpidEquipment.h rename to Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h index aa324ea9c2fa9..920a502eccc1a 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidEquipment.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h @@ -93,7 +93,7 @@ class HmpidEquipment int mErrorsCounter; int mErrorPadsPerEvent; - int mEventNumber; + uint64_t mEventNumber; int mNumberOfEvents; float mEventSizeAverage; int mEventSize; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx index 3c1c30b592fd0..e828bc629e6c1 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx @@ -18,7 +18,7 @@ /* ------ HISTORY --------- */ -#include "HmpidDecodeRawFile.h" +#include "HMPIDReconstruction/HmpidDecodeRawFile.h" using namespace o2::hmpid; @@ -60,13 +60,13 @@ bool HmpidDecodeRawFile::setUpStream(void *FileName, long Size) strcpy(mInputFile, (const char*) FileName); // files section ---- if (!fileExists(mInputFile)) { - ILOG(ERROR) << "The input file " << mInputFile << " does not exist at this time." << FairLogger::endl; + LOG(ERROR) << "The input file " << mInputFile << " does not exist at this time." << FairLogger::endl; throw TH_FILENOTEXISTS; } // open the file fh = fopen(mInputFile, "rb"); if (fh == 0) { - ILOG(ERROR) << "ERROR to open Input file ! [" << mInputFile << "]" << FairLogger::endl; + LOG(ERROR) << "ERROR to open Input file ! [" << mInputFile << "]" << FairLogger::endl; throw TH_OPENFILE; } @@ -87,7 +87,7 @@ bool HmpidDecodeRawFile::setUpStream(void *FileName, long Size) /// @param[in] Size : not used /// @returns True if the file is opened /// @throws TH_WRONGFILELEN Thrown if the file doesn't contains enough words -bool HmpidDecodeRawFile::getBlockFromStream(int32_t **streamPtr, uint32_t Size) +bool HmpidDecodeRawFile::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) { if (Size > MAXRAWFILEBUFFER) return (false); @@ -97,7 +97,7 @@ bool HmpidDecodeRawFile::getBlockFromStream(int32_t **streamPtr, uint32_t Size) } Size = ((mFileBuffer[2] & 0x0000FFFF) / sizeof(int32_t)) - HEADERDIMENSION_W; nr = fread(mFileBuffer+HEADERDIMENSION_W, sizeof(int32_t), Size, fh); - ILOG(DEBUG) << " getBlockFromStream read " << nr << " of " << Size+HEADERDIMENSION_W << " words !" << FairLogger::endl; + LOG(DEBUG) << " getBlockFromStream read " << nr << " of " << Size+HEADERDIMENSION_W << " words !" << FairLogger::endl; if (nr != Size) { throw TH_WRONGFILELEN; } @@ -111,7 +111,7 @@ bool HmpidDecodeRawFile::getBlockFromStream(int32_t **streamPtr, uint32_t Size) /// Reads the Header from the file /// @param[in] **streamPtr : the pointer to the memory buffer /// @returns True if the header is read -bool HmpidDecodeRawFile::getHeaderFromStream(int32_t **streamPtr) +bool HmpidDecodeRawFile::getHeaderFromStream(uint32_t **streamPtr) { bool flag = getBlockFromStream(streamPtr, RAWBLOCKDIMENSION_W); // reads the 8k block mActualStreamPtr += HEADERDIMENSION_W; // Move forward for the first word @@ -121,7 +121,7 @@ bool HmpidDecodeRawFile::getHeaderFromStream(int32_t **streamPtr) /// Read one word from the pre-load buffer /// @param[in] *word : the buffer for the read word /// @returns True every time -bool HmpidDecodeRawFile::getWordFromStream(int32_t *word) +bool HmpidDecodeRawFile::getWordFromStream(uint32_t *word) { *word = *mActualStreamPtr; mActualStreamPtr++; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index c9d39361d9536..607043e94a619 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -18,7 +18,9 @@ /* ------ HISTORY --------- */ -#include "HmpidDecodeRawMem.h" +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDReconstruction/HmpidDecodeRawMem.h" using namespace o2::hmpid; @@ -66,21 +68,21 @@ bool HmpidDecodeRawMem::setUpStream(void *Buffer, long BufferLen) { long wordsBufferLen = BufferLen / (sizeof(int32_t) / sizeof(char)); // Converts the len in words if (Buffer == nullptr) { - ILOG(ERROR) << "Raw data buffer null Pointer ! " << FairLogger::endl; + LOG(ERROR) << "Raw data buffer null Pointer ! "; throw TH_NULLBUFFERPOINTER; } if (wordsBufferLen == 0) { - ILOG(Error) << "Raw data buffer Empty ! " <> 20 == 0xAB0) { @@ -247,7 +251,7 @@ bool HmpidDecoder::isSegmentMarker(int32_t wp, int *Err, int *segSize, int *Seg, *Seg = wp & 0x0000000F; if (*Seg > 3 || *Seg < 1) { - ILOG(INFO) << " Wrong segment Marker Word, bad Number of segment" << *Seg << "!" << FairLogger::endl; + LOG(INFO) << " Wrong segment Marker Word, bad Number of segment" << *Seg << "!"; *Err = true; } return (true); @@ -265,7 +269,7 @@ bool HmpidDecoder::isSegmentMarker(int32_t wp, int *Err, int *segSize, int *Seg, /// @param[out] *Channel : the channel number [0..47] /// @param[out] *Charge : the value of Charge [0..4095] /// @returns True if PAD Word is detected -bool HmpidDecoder::isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge) +bool HmpidDecoder::isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge) { *Err = false; if ((wp & 0x08000000) == 0) { // # this is a pad @@ -274,8 +278,8 @@ bool HmpidDecoder::isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int * *Channel = (wp & 0x0003F000) >> 12; *Charge = (wp & 0x00000FFF); if (*Dilogic > 10 || *Channel > 47 || *Dilogic < 1 || *Col > 24 || *Col < 1) { - ILOG(WARNING) << " Wrong Pad values Col=" << *Col << " Dilogic="<< *Dilogic << \ - " Channel=" << *Channel << " Charge=" << *Charge << FairLogger::endl; + LOG(WARNING) << " Wrong Pad values Col=" << *Col << " Dilogic="<< *Dilogic << \ + " Channel=" << *Channel << " Charge=" << *Charge; *Err = true; } return (true); @@ -291,7 +295,7 @@ bool HmpidDecoder::isPadWord(int32_t wp, int *Err, int *Col, int *Dilogic, int * /// @param[out] *Dilogic : the dilogic number [1..10] /// @param[out] *Eoesize : the number of words for dilogic /// @returns True if EoE marker is detected -bool HmpidDecoder::isEoEmarker(int32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize) +bool HmpidDecoder::isEoEmarker(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize) { *Err = false; // #EX MASK Raul 0x3803FF80 # ex mask 0xF803FF80 - this is EoE marker 0586800B0 @@ -300,7 +304,7 @@ bool HmpidDecoder::isEoEmarker(int32_t wp, int *Err, int *Col, int *Dilogic, int *Dilogic = (wp & 0x003C0000) >> 18; *Eoesize = (wp & 0x0000007F); if (*Col > 24 || *Dilogic > 10) { - ILOG(INFO) << " EoE size wrong definition. Col=" << *Col << " Dilogic=" << *Dilogic << FairLogger::endl; + LOG(INFO) << " EoE size wrong definition. Col=" << *Col << " Dilogic=" << *Dilogic; *Err = true; } return (true); @@ -341,10 +345,12 @@ bool HmpidDecoder::decodeHmpidError(int ErrorField, char *outbuf) /// @param[out] *EquipIndex : the Index to the Equipment Object Array [0..13] /// @returns True every time /// @throws TH_WRONGEQUIPINDEX Thrown if the Equipment Index is out of boundary (Equipment not recognized) -int HmpidDecoder::decodeHeader(int32_t *streamPtrAdr, int *EquipIndex) +int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) { - int32_t *buffer = streamPtrAdr; // Sets the pointer to buffer + uint32_t *buffer = streamPtrAdr; // Sets the pointer to buffer + o2::header::RAWDataHeaderV6 *hpt = (o2::header::RAWDataHeaderV6 *)buffer; + /* mHeFEEID = (buffer[0] & 0x000f0000) >> 16; mHeSize = (buffer[0] & 0x0000ff00) >> 8; mHeVer = (buffer[0] & 0x000000ff); @@ -365,6 +371,27 @@ int HmpidDecoder::decodeHeader(int32_t *streamPtrAdr, int *EquipIndex) mHeFirmwareVersion = buffer[12] & 0x0000000f; mHeHmpidError = (buffer[12] & 0x000001F0) >> 4; mHePAR = buffer[13] & 0x0000FFFF; + */ + mHeFEEID = hpt->feeId; + mHeSize = hpt->headerSize; + mHeVer = hpt->version; + mHePrior = hpt->priority; + mHeDetectorID = hpt->sourceID; + mHeOffsetNewPack = hpt->offsetToNext; + mHeMemorySize = hpt->memorySize; + mHeDW = hpt->endPointID; + mHeCruID = hpt->cruID; + mHePackNum = hpt->packetCounter; + mHeLinkNum = hpt->linkID; + mHeBCDI = hpt->bunchCrossing; + mHeORBIT = hpt->orbit; + mHeTType = hpt->triggerType; + mHePageNum = hpt->pageCnt; + mHeStop = hpt->stop; + mHeBusy = (hpt->detectorField & 0xfffffe00) >> 9; + mHeFirmwareVersion = hpt->detectorField & 0x0000000f; + mHeHmpidError = (hpt->detectorField & 0x000001F0) >> 4; + mHePAR = hpt->detectorPAR; *EquipIndex = getEquipmentIndex(mHeCruID, mHeLinkNum); // mEquipment = (*EquipIndex != -1) ? mTheEquipments[*EquipIndex]->getEquipmentId() : -1; @@ -372,19 +399,19 @@ int HmpidDecoder::decodeHeader(int32_t *streamPtrAdr, int *EquipIndex) mNumberWordToRead = ((mHeMemorySize - mHeSize) / sizeof(uint32_t)); mPayloadTail = ((mHeOffsetNewPack - mHeMemorySize) / sizeof(uint32_t)); - // ---- Event ID : Actualy based on ORBIT NUMBER ... - mHeEvent = mHeORBIT; + // ---- Event ID : Actualy based on ORBIT NUMBER and BC + mHeEvent = (mHeORBIT<<12) | mHeBCDI; - ILOG(INFO) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID <<\ - " HeMemorySize=" << mHeMemorySize << " HeOffsetNewPack=" << mHeOffsetNewPack << FairLogger::endl; - ILOG(INFO) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << \ - mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT << FairLogger::endl; - ILOG(INFO) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ - mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR << FairLogger::endl; - ILOG(INFO) << " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail << FairLogger::endl; + LOG(INFO) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID <<\ + " HeMemorySize=" << mHeMemorySize << " HeOffsetNewPack=" << mHeOffsetNewPack; + LOG(INFO) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << \ + mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT; + LOG(INFO) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ + mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR; + LOG(INFO) << " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; if (*EquipIndex == -1) { - ILOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment << FairLogger::endl; + LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; throw TH_WRONGEQUIPINDEX; } return (true); @@ -430,374 +457,396 @@ HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) } eq->mEventSize += mNumberWordToRead * sizeof(uint32_t); // Calculate the size in bytes if (mHeHmpidError != 0) { - ILOG(ERROR) << "HMPID Header reports an error : " << mHeHmpidError << FairLogger::endl; + LOG(ERROR) << "HMPID Header reports an error : " << mHeHmpidError; dumpHmpidError(mHeHmpidError); eq->setError(ERR_HMPID); } return (eq); } -/// --------------- Read Raw Data Buffer --------------- -/// Read the stream, decode the contents and store resuls. -/// ATTENTION : Assumes that the input stream was set -/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header -bool HmpidDecoder::decodeBuffer() +void HmpidDecoder::decodePage(uint32_t **streamBuf) { - // ---------resets the PAdMap----------- - for (int i = 0; i < mNumberOfEquipments; i++) { - mTheEquipments[i]->init(); - mTheEquipments[i]->resetPadMap(); - mTheEquipments[i]->resetErrors(); + int equipmentIndex; + try { + getHeaderFromStream(streamBuf); + } + catch (int e) { + // The stream end ! + LOG(DEBUG) << "End main decoding loop !"; + break; + } + try { + decodeHeader(*streamBuf, &equipmentIndex); + } + catch (int e) { + LOG(ERROR) << "Failed to decode the Header !"; + throw TH_WRONGHEADER; } - int type; - int equipmentIndex = -1; - int isIt; - HmpidEquipment *eq; - int32_t *streamBuf; - ILOG(DEBUG) << "Enter decoding !" << FairLogger::endl; - - // Input Stream Main Loop - while (true) { - try { - getHeaderFromStream(&streamBuf); - } - catch (int e) { - // The stream end ! - ILOG(DEBUG) << "End main decoding loop !" << FairLogger::endl; - break; - } - try { - decodeHeader(streamBuf, &equipmentIndex); - } - catch (int e) { - ILOG(ERROR) << "Failed to decode the Header !" << FairLogger::endl; - throw TH_WRONGHEADER; - } - - eq = evaluateHeaderContents(equipmentIndex); + HmpidEquipment *eq = evaluateHeaderContents(equipmentIndex); - int wpprev = 0; - int wp = 0; - int newOne = true; - int p1, p2, p3, p4; - int error; + uint32_t wpprev = 0; + uint32_t wp = 0; + int newOne = true; + int p1, p2, p3, p4; + int error; + int type; + bool isIt; - int payIndex = 0; - while (payIndex < mNumberWordToRead) { //start the payload loop word by word - if (newOne == true) { - wpprev = wp; - if (!getWordFromStream(&wp)) { // end the stream - break; - } + int payIndex = 0; + while (payIndex < mNumberWordToRead) { //start the payload loop word by word + if (newOne == true) { + wpprev = wp; + if (!getWordFromStream(&wp)) { // end the stream + break; + } - type = checkType(wp, &p1, &p2, &p3, &p4); - if (type == WTYPE_NONE) { - if (eq->mWillBePad == true) { // try to recover the first pad ! - type = checkType((wp & 0xF7FFFFFF), &p1, &p2, &p3, &p4); - if (type == WTYPE_PAD && p3 == 0 && eq->mWordsPerDilogicCounter == 0) { - newOne = false; // # reprocess as pad - continue; - } + type = checkType(wp, &p1, &p2, &p3, &p4); + if (type == WTYPE_NONE) { + if (eq->mWillBePad == true) { // try to recover the first pad ! + type = checkType((wp & 0xF7FFFFFF), &p1, &p2, &p3, &p4); + if (type == WTYPE_PAD && p3 == 0 && eq->mWordsPerDilogicCounter == 0) { + newOne = false; // # reprocess as pad + continue; } - eq->setError(ERR_NOTKNOWN); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_NOTKNOWN] << " [" << wp << "]" << FairLogger::endl; - eq->mWordsPerRowCounter++; - eq->mWordsPerSegCounter++; - payIndex++; - continue; } + eq->setError(ERR_NOTKNOWN); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_NOTKNOWN] << " [" << wp << "]"; + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; + payIndex++; + continue; } + } - if (eq->mWillBeRowMarker == true) { // #shoud be a Row Marker - if (type == WTYPE_ROW) { - eq->mColumnCounter++; - eq->mWordsPerSegCounter++; - eq->mRowSize = p2; - switch (p2) { - case 0: // Empty column - eq->setError(ERR_ROWMARKEMPTY); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKEMPTY] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeRowMarker = true; - break; - case 0x3FF: // Error in column - eq->setError(ERR_ROWMARKERROR); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKERROR] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeRowMarker = true; - break; - case 0x3FE: // Masked column - ILOG(INFO) << "Equip=" << mEquipment << "The column=" << (eq->mSegment) * 8 + eq->mColumnCounter << " is Masked !" << FairLogger::endl; - eq->mWillBeRowMarker = true; - break; - default: - eq->mWillBeRowMarker = false; - eq->mWillBePad = true; - break; - } - newOne = true; - } else { - if (wp == wpprev) { - eq->setError(ERR_DUPLICATEPAD); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - newOne = true; - } else if (type == WTYPE_EOE) { // # Could be a EoE - eq->mColumnCounter++; - eq->setError(ERR_ROWMARKWRONG); - eq->mWillBeRowMarker = false; - eq->mWillBePad = true; - newOne = true; - } else if (type == WTYPE_PAD) { //# Could be a PAD - eq->mColumnCounter++; - eq->setError(ERR_ROWMARKLOST); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeRowMarker = false; - eq->mWillBePad = true; - newOne = true; - } else if (type == WTYPE_EOS) { // # Could be a EoS - eq->mWillBeRowMarker = false; - eq->mWillBeSegmentMarker = true; - newOne = false; - } else { - eq->mColumnCounter++; - eq->setError(ERR_ROWMARKLOST); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; + if (eq->mWillBeRowMarker == true) { // #shoud be a Row Marker + if (type == WTYPE_ROW) { + eq->mColumnCounter++; + eq->mWordsPerSegCounter++; + eq->mRowSize = p2; + switch (p2) { + case 0: // Empty column + eq->setError(ERR_ROWMARKEMPTY); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKEMPTY] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeRowMarker = true; + break; + case 0x3FF: // Error in column + eq->setError(ERR_ROWMARKERROR); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKERROR] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeRowMarker = true; + break; + case 0x3FE: // Masked column + LOG(INFO) << "Equip=" << mEquipment << "The column=" << (eq->mSegment) * 8 + eq->mColumnCounter << " is Masked !"; + eq->mWillBeRowMarker = true; + break; + default: eq->mWillBeRowMarker = false; eq->mWillBePad = true; - newOne = true; - } + break; } - } else if (eq->mWillBePad == true) { // # We expect a pad - //# PAD:0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value - // c = 1..24 d = 1..10 n = 0..47 - if (type == WTYPE_PAD) { + newOne = true; + } else { + if (wp == wpprev) { + eq->setError(ERR_DUPLICATEPAD); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; newOne = true; - if (wp == wpprev) { - eq->setError(ERR_DUPLICATEPAD); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - } else if (p1 != (eq->mSegment * 8 + eq->mColumnCounter)) { // # Manage - // We try to recover the RowMarker misunderstanding - isIt = isRowMarker(wp, &error, &p2, &p1); - if (isIt == true && error == false) { - type = WTYPE_ROW; - newOne = false; - eq->mWillBeEoE = true; - eq->mWillBePad = false; - } else { - ILOG(DEBUG) << "Equip=" << mEquipment << " Mismatch in column" << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mColumnCounter = p1 % 8; - } - } else { - setPad(eq, p1 - 1, p2 - 1, p3, p4); - eq->mWordsPerDilogicCounter++; - eq->mSampleNumber++; - if (p3 == 47) { - eq->mWillBeEoE = true; - eq->mWillBePad = false; - } - } - eq->mWordsPerRowCounter++; - eq->mWordsPerSegCounter++; - } else if (type == WTYPE_EOE) { //# the pads are end ok - eq->mWillBeEoE = true; - eq->mWillBePad = false; + } else if (type == WTYPE_EOE) { // # Could be a EoE + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKWRONG); + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } else if (type == WTYPE_PAD) { //# Could be a PAD + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKLOST); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } else if (type == WTYPE_EOS) { // # Could be a EoS + eq->mWillBeRowMarker = false; + eq->mWillBeSegmentMarker = true; newOne = false; - } else if (type == WTYPE_ROW) { // # We Lost the EoE ! - // We try to recover the PAD misunderstanding - isIt = isPadWord(wp, &error, &p1, &p2, &p3, &p4); + } else { + eq->mColumnCounter++; + eq->setError(ERR_ROWMARKLOST); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeRowMarker = false; + eq->mWillBePad = true; + newOne = true; + } + } + } else if (eq->mWillBePad == true) { // # We expect a pad + //# PAD:0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value + // c = 1..24 d = 1..10 n = 0..47 + if (type == WTYPE_PAD) { + newOne = true; + if (wp == wpprev) { + eq->setError(ERR_DUPLICATEPAD); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + } else if (p1 != (eq->mSegment * 8 + eq->mColumnCounter)) { // # Manage + // We try to recover the RowMarker misunderstanding + isIt = isRowMarker(wp, &error, &p2, &p1); if (isIt == true && error == false) { - type = WTYPE_PAD; - newOne = false; // # reprocess as pad + type = WTYPE_ROW; + newOne = false; + eq->mWillBeEoE = true; + eq->mWillBePad = false; } else { - eq->setError(ERR_LOSTEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeRowMarker = true; + LOG(DEBUG) << "Equip=" << mEquipment << " Mismatch in column" << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mColumnCounter = p1 % 8; + } + } else { + setPad(eq, p1 - 1, p2 - 1, p3, p4); + eq->mWordsPerDilogicCounter++; + eq->mSampleNumber++; + if (p3 == 47) { + eq->mWillBeEoE = true; eq->mWillBePad = false; - newOne = false; } - } else if (type == WTYPE_EOS) { // # We Lost the EoE ! - eq->setError(ERR_LOSTEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeSegmentMarker = true; - eq->mWillBePad = false; - newOne = false; } - } else if (eq->mWillBeEoE == true) { // # We expect a EoE - if (type == WTYPE_EOE) { - eq->mWordsPerRowCounter++; - eq->mWordsPerSegCounter++; - if (wpprev == wp) { - eq->setError(ERR_DOUBLEEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEEOEMARK] << " col=" << p1 << FairLogger::endl; - } else if (p3 != eq->mWordsPerDilogicCounter) { - eq->setError(ERR_WRONGSIZEINEOE); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZEINEOE] << " col=" << p1 << FairLogger::endl; - } - eq->mWordsPerDilogicCounter = 0; - if (p2 == 10) { - if (p1 % 8 != 0) { // # we expect the Row Marker - eq->mWillBeRowMarker = true; - } else { - eq->mWillBeSegmentMarker = true; - } - } else { - eq->mWillBePad = true; - } - eq->mWillBeEoE = false; - newOne = true; - } else if (type == WTYPE_EOS) { // We Lost the EoE ! - eq->setError(ERR_LOSTEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeSegmentMarker = true; - eq->mWillBeEoE = false; - newOne = false; - } else if (type == WTYPE_ROW) { //# We Lost the EoE ! + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; + } else if (type == WTYPE_EOE) { //# the pads are end ok + eq->mWillBeEoE = true; + eq->mWillBePad = false; + newOne = false; + } else if (type == WTYPE_ROW) { // # We Lost the EoE ! + // We try to recover the PAD misunderstanding + isIt = isPadWord(wp, &error, &p1, &p2, &p3, &p4); + if (isIt == true && error == false) { + type = WTYPE_PAD; + newOne = false; // # reprocess as pad + } else { eq->setError(ERR_LOSTEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; eq->mWillBeRowMarker = true; - eq->mWillBeEoE = false; + eq->mWillBePad = false; newOne = false; - } else if (type == WTYPE_PAD) { // # We Lost the EoE ! - int typb, p1b, p2b, p3b, p4b; - typb = checkType((wp | 0x08000000), &p1b, &p2b, &p3b, &p4b); - if (typb == WTYPE_EOE && p3b == 48) { - type = typb; - p1 = p1b; - p2 = p2b; - p3 = p3b; - p4 = p4b; - newOne = false; // # reprocess as EoE - } else { - eq->setError(ERR_LOSTEOEMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBePad = true; - eq->mWillBeEoE = false; - newOne = false; - } } - } else if (eq->mWillBeSegmentMarker == true) { // # We expect a EoSegment + } else if (type == WTYPE_EOS) { // # We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeSegmentMarker = true; + eq->mWillBePad = false; + newOne = false; + } + } else if (eq->mWillBeEoE == true) { // # We expect a EoE + if (type == WTYPE_EOE) { + eq->mWordsPerRowCounter++; + eq->mWordsPerSegCounter++; if (wpprev == wp) { - eq->setError(ERR_DOUBLEMARKWORD); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEMARKWORD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - newOne = true; - } else if (type == 2) { - if (abs(eq->mWordsPerSegCounter - p2) > 5) { - eq->setError(ERR_WRONGSIZESEGMENTMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZESEGMENTMARK] << " Seg=" << p2 << FairLogger::endl; + eq->setError(ERR_DOUBLEEOEMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEEOEMARK] << " col=" << p1; + } else if (p3 != eq->mWordsPerDilogicCounter) { + eq->setError(ERR_WRONGSIZEINEOE); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZEINEOE] << " col=" << p1; + } + eq->mWordsPerDilogicCounter = 0; + if (p2 == 10) { + if (p1 % 8 != 0) { // # we expect the Row Marker + eq->mWillBeRowMarker = true; + } else { + eq->mWillBeSegmentMarker = true; } - eq->mWordsPerSegCounter = 0; - eq->mWordsPerRowCounter = 0; - eq->mColumnCounter = 0; - eq->mSegment = p3 % 3; - eq->mWillBeRowMarker = true; - eq->mWillBeSegmentMarker = false; - newOne = true; } else { - eq->setError(ERR_LOSTEOSMARK); - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOSMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - eq->mWillBeSegmentMarker = false; - eq->mWillBeRowMarker = true; + eq->mWillBePad = true; + } + eq->mWillBeEoE = false; + newOne = true; + } else if (type == WTYPE_EOS) { // We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeSegmentMarker = true; + eq->mWillBeEoE = false; + newOne = false; + } else if (type == WTYPE_ROW) { //# We Lost the EoE ! + eq->setError(ERR_LOSTEOEMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeRowMarker = true; + eq->mWillBeEoE = false; + newOne = false; + } else if (type == WTYPE_PAD) { // # We Lost the EoE ! + int typb, p1b, p2b, p3b, p4b; + typb = checkType((wp | 0x08000000), &p1b, &p2b, &p3b, &p4b); + if (typb == WTYPE_EOE && p3b == 48) { + type = typb; + p1 = p1b; + p2 = p2b; + p3 = p3b; + p4 = p4b; + newOne = false; // # reprocess as EoE + } else { + eq->setError(ERR_LOSTEOEMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBePad = true; + eq->mWillBeEoE = false; newOne = false; } } - if (newOne) { - payIndex += 1; + } else if (eq->mWillBeSegmentMarker == true) { // # We expect a EoSegment + if (wpprev == wp) { + eq->setError(ERR_DOUBLEMARKWORD); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEMARKWORD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + newOne = true; + } else if (type == 2) { + if (abs(eq->mWordsPerSegCounter - p2) > 5) { + eq->setError(ERR_WRONGSIZESEGMENTMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZESEGMENTMARK] << " Seg=" << p2; + } + eq->mWordsPerSegCounter = 0; + eq->mWordsPerRowCounter = 0; + eq->mColumnCounter = 0; + eq->mSegment = p3 % 3; + eq->mWillBeRowMarker = true; + eq->mWillBeSegmentMarker = false; + newOne = true; + } else { + eq->setError(ERR_LOSTEOSMARK); + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOSMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + eq->mWillBeSegmentMarker = false; + eq->mWillBeRowMarker = true; + newOne = false; } } - for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail - getWordFromStream(&wp); - } - } // this is the end of stream - - // cycle in order to update info for the last event - for (int i = 0; i < mNumberOfEquipments; i++) { - if (mTheEquipments[i]->mNumberOfEvents > 0) { - updateStatistics(mTheEquipments[i]); + if (newOne) { + payIndex += 1; } } - return (true); + for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail + getWordFromStream(&wp); + } } -/// ---------- Read Raw Data Buffer with Fast Decoding ---------- +/// --------------- Read Raw Data Buffer --------------- /// Read the stream, decode the contents and store resuls. -/// Fast alghoritm : no parsing of control words ! /// ATTENTION : Assumes that the input stream was set /// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header -bool HmpidDecoder::decodeBufferFast() +bool HmpidDecoder::decodeBuffer() { // ---------resets the PAdMap----------- for (int i = 0; i < mNumberOfEquipments; i++) { mTheEquipments[i]->init(); mTheEquipments[i]->resetPadMap(); + mTheEquipments[i]->resetErrors(); } int type; int equipmentIndex = -1; int isIt; HmpidEquipment *eq; - int32_t *streamBuf; - ILOG(DEBUG) << "Enter FAST decoding !" << FairLogger::endl; + uint32_t *streamBuf; + LOG(DEBUG) << "Enter decoding !"; // Input Stream Main Loop while (true) { try { - getHeaderFromStream(&streamBuf); + decodePage(&streamBuf); } catch (int e) { - // The stream end ! - ILOG(DEBUG) << "End main decoding loop !" << FairLogger::endl; + LOG(DEBUG) << "End main buffer decoding loop !"; break; } - try { - decodeHeader(streamBuf, &equipmentIndex); - } - catch (int e) { - ILOG(ERROR) << "Failed to decode the Header !" << FairLogger::endl; - throw TH_WRONGHEADER; + } // this is the end of stream + + // cycle in order to update info for the last event + for (int i = 0; i < mNumberOfEquipments; i++) { + if (mTheEquipments[i]->mNumberOfEvents > 0) { + updateStatistics(mTheEquipments[i]); } + } + return (true); +} + +void HmpidDecoder::decodePageFast(uint32_t **streamBuf) +{ + int equipmentIndex; + try { + getHeaderFromStream(streamBuf); + } + catch (int e) { + // The stream end ! + LOG(DEBUG) << "End Fast Page decoding loop !"; + break; + } + try { + decodeHeader(*streamBuf, &equipmentIndex); + } + catch (int e) { + LOG(ERROR) << "Failed to decode the Header !"; + throw TH_WRONGHEADER; + } - eq = evaluateHeaderContents(equipmentIndex); + HmpidEquipment *eq = evaluateHeaderContents(equipmentIndex); - int wpprev = 0; - int wp = 0; - int newOne = true; - int p1, p2, p3, p4; - int error; + uint32_t wpprev = 0; + uint32_t wp = 0; + int newOne = true; + int Column, Dilogic, Channel, Charge; + int error; - int payIndex = 0; - while (payIndex < mNumberWordToRead) { //start the payload loop word by word - wpprev = wp; - if (!getWordFromStream(&wp)) { // end the stream - break; - } - if (wp == wpprev) { - ILOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]" << FairLogger::endl; - } else { - if( isPadWord(wp, &error, &p1, &p2, &p3, &p4) == true) { - if( error != false) { - setPad(eq, p1 - 1, p2 - 1, p3, p4); - eq->mSampleNumber++; - } + int payIndex = 0; + while (payIndex < mNumberWordToRead) { //start the payload loop word by word + wpprev = wp; + if (!getWordFromStream(&wp)) { // end the stream + break; + } + if (wp == wpprev) { + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << Column << "]"; + } else { + if( isPadWord(wp, &error, &Column, &Dilogic, &Channel, &Charge) == true) { + if( error != false) { + setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); + eq->mSampleNumber++; } } - payIndex += 1; } - for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail - getWordFromStream(&wp); + payIndex += 1; + } + for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail + getWordFromStream(&wp); + } + return; +} +/// ---------- Read Raw Data Buffer with Fast Decoding ---------- +/// Read the stream, decode the contents and store resuls. +/// Fast alghoritm : no parsing of control words ! +/// ATTENTION : Assumes that the input stream was set +/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header +bool HmpidDecoder::decodeBufferFast() +{ + // ---------resets the PAdMap----------- + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i]->init(); + mTheEquipments[i]->resetPadMap(); + } + + uint32_t *streamBuf; + LOG(DEBUG) << "Enter FAST decoding !"; + + // Input Stream Main Loop + while (true) { + try { + decodePageFast(&streamBuf); + } + catch(int e) { + LOG(DEBUG) << " End Buffer Fast Decoding !"; + break; } } // this is the end of stream @@ -984,7 +1033,7 @@ void HmpidDecoder::dumpHmpidError(int ErrorField) { char printbuf[MAXHMPIDERRORS * MAXDESCRIPTIONLENGHT]; if (decodeHmpidError(ErrorField, printbuf) == true) { - ILOG(ERROR) << "HMPID Error field = " << ErrorField << " : " << printbuf << FairLogger::endl; + LOG(ERROR) << "HMPID Error field = " << ErrorField << " : " << printbuf; } return; } diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx index fc442cc92be1b..d752f96165e2a 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx @@ -18,7 +18,7 @@ /* ------ HISTORY --------- */ -#include "HmpidEquipment.h" +#include "HMPIDReconstruction/HmpidEquipment.h" using namespace o2::hmpid; diff --git a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx index d9b8dfe5f9c48..0a70d3c28851b 100644 --- a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx +++ b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx @@ -110,8 +110,11 @@ void HMPIDDigitizer::process(std::vector const& hits, std::v } } else { // create digit ... and register - mDigits.emplace_back(mCurrentTriggerTime, pad, totalQ * fraction); - mIndexForPad[pad] = mDigits.size() - 1; +int Orbit = 1; +int Bc = 1; +// mDigits.emplace_back(mCurrentTriggerTime, pad, totalQ * fraction); + mDigits.emplace_back(Orbit, Bc, pad, totalQ * fraction); + mIndexForPad[pad] = mDigits.size() - 1; mInvolvedPads.emplace_back(pad); if (mRegisteredLabelContainer) { diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index fc1da045c6742..c57603fd16363 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -19,12 +19,28 @@ #define O2_MCH_DATADECODERSPEC_H_ #include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" namespace o2 { namespace hmpid { + class DataDecoderTask : public Task + { + public: + DataDecoderTask() = default; + ~DataDecoderTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + void decodeTF(framework::ProcessingContext& pc); + + private: + o2::hmpid::HmpidDecodeRawDigit *mDeco; + // vector mDigits; + + }; + o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec = "TF:HMP/RAWDATA"); //o2::framework::DataProcessorSpec getDecodingSpec(); } // end namespace hmpid diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index d0be3a60eb70e..b37bcc6acf9c0 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include "Framework/CallbackService.h" #include "Framework/ConfigParamRegistry.h" @@ -37,6 +38,8 @@ #include "DPLUtils/DPLRawParser.h" #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDReconstruction/HmpidDecodeRawMem.h" #include "HMPIDWorkflow/DataDecoderSpec.h" namespace o2 @@ -50,50 +53,132 @@ using RDH = o2::header::RDHAny; //======================= // Data decoder -class DataDecoderTask +void DataDecoderTask::init(framework::InitContext& ic) { - public: - //_________________________________________________________________________________________________ - void init(framework::InitContext& ic) - { - /* SampaChannelHandler channelHandler; - RdhHandler rdhHandler; + mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); + mDeco->init(); + + + return; +} + +void DataDecoderTask::run(framework::ProcessingContext& pc) +{ + mDeco->mDigits.clear(); - auto ds2manu = ic.options().get("ds2manu"); - mPrint = ic.options().get("print"); - auto mapCRUfile = ic.options().get("cru-map"); - auto mapFECfile = ic.options().get("fec-map"); + decodeTF(pc); - mDecoder = new DataDecoder(channelHandler, rdhHandler, mapCRUfile, mapFECfile, ds2manu, mPrint); - */ + +// for (auto&& input : pc.inputs()) { +// std::cout << " ******* input " << input.spec->binding << std::endl; + + + LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; + pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + +} + +/* auto& digits = mDecoder->getOutputDigits(); + auto& orbits = mDecoder->getOrbits(); + + if (mPrint) { + for (auto d : digits) { + std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; + } } + // send the output buffer via DPL + size_t digitsSize, orbitsSize; + char* digitsBuffer = createBuffer(digits, digitsSize); + char* orbitsBuffer = createBuffer(orbits, orbitsSize); + + // create the output message + auto freefct = [](void* data, void*) { free(data); }; +// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); +// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); +*/ + //_________________________________________________________________________________________________ - // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder - void decodeTF(framework::ProcessingContext& pc) - { - Printf("*********** In decodeTF **************"); +// the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder +void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) +{ + LOG(INFO) << "*********** In decodeTF **************"); + + // get the input buffer + auto& inputs = pc.inputs(); + DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); + + for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { + uint32_t *theBuffer = (uint32_t *)it.raw(); + mDeco->setUpStream(theBuffer, it.size()+it.offset()); + mDeco->decodePageFast(&theBuffer); + } + /* + int equipmentIndex = -1; + HmpidEquipment *eq; // get the input buffer auto& inputs = pc.inputs(); DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - auto const* rdh = it.get_if(); - auto const* raw = it.raw(); size_t payloadSize = it.size(); - // stampare solo payload - std::cout << " ***** payloadSize = " << payloadSize << std::endl; - - /* if (payloadSize == 0) { + if(payloadSize <= 0) { + LOG(INFO) << "Payload empty"; continue; } - gsl::span buffer(reinterpret_cast(raw), sizeof(RDH) + payloadSize); - mDecoder->decodeBuffer(buffer); - */ + auto const* rdh = it.get_if(); + auto const* raw = it.raw(); + uint32_t* data = (uint32_t*)it.data(); + + try { + mDeco->decodeHeader((uint32_t *)rdh, &equipmentIndex); + } + catch (int e) { + LOG(ERROR) << "Failed to decode the Header !"; + throw TH_WRONGHEADER; + } + eq = mDeco->evaluateHeaderContents(equipmentIndex); + + uint32_t wpprev = 0; + uint32_t wp = 0; + int newOne = true; + int p1, p2, p3, p4; + int error; + + int payIndex = 0; + while (payIndex < mDeco->mNumberWordToRead) { //start the payload loop word by word + wpprev = wp; + wp = *data; data++; + if (wp == wpprev) { + LOG(DEBUG) << "Equip=" << mDeco->mEquipment << mDeco->sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + "[" << p1 << "]"; + } else { + if( mDeco->isPadWord(wp, &error, &p1, &p2, &p3, &p4) == true) { + if( error != false) { + eq->setPad(p1 - 1, p2 - 1, p3, p4); + mDigits.push_back(Digit(mDeco->mHeBCDI, mDeco->mHeORBIT, + o2::hmpid::Geo::GetPad(equipmentIndex, p1 - 1, p2 - 1, p3), + p4)); + eq->mSampleNumber++; + } + } + } + payIndex += 1; + } + + LOG(DEBUG) << " ***** payloadSize = " << payloadSize; + } - } + // cycle in order to update info for the last event + for (int i = 0; i < mDeco->mNumberOfEquipments; i++) { + if (mDeco->mTheEquipments[i]->mNumberOfEvents > 0) { + mDeco->updateStatistics(mDeco->mTheEquipments[i]); + } + } +*/ +} //_________________________________________________________________________________________________ // the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow @@ -128,55 +213,25 @@ class DataDecoderTask } */ //_________________________________________________________________________________________________ - void run(framework::ProcessingContext& pc) - { - - decodeTF(pc); - for (auto&& input : pc.inputs()) { - - std::cout << " ******* input " << input.spec->binding << std::endl; - // if (input.spec->binding == "readout") { // solo cout - // decodeReadout(input); - // } - } - -/* auto& digits = mDecoder->getOutputDigits(); - auto& orbits = mDecoder->getOrbits(); - - if (mPrint) { - for (auto d : digits) { - std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; - } - } - // send the output buffer via DPL - size_t digitsSize, orbitsSize; - char* digitsBuffer = createBuffer(digits, digitsSize); - char* orbitsBuffer = createBuffer(orbits, orbitsSize); - - // create the output message - auto freefct = [](void* data, void*) { free(data); }; - // pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); - // pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); - */ - } - - private: - bool mPrint = {false}; -// DataDecoder* mDecoder = {nullptr}; -}; //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) //o2::framework::DataPrecessorSpec getDecodingSpec() { - std::vector inputs; + std::vector inputs; inputs.emplace_back("RAWDATA", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + + std::vector outputs; + outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); + outputs.emplace_back("HMP", "ORBITS", 0, o2::framework::Lifetime::Timeframe); + outputs.emplace_back("HMP", "STATS", 0, o2::framework::Lifetime::Timeframe); + return DataProcessorSpec{ "HMP-DataDecoder", - o2::framework::select(inputSpec.c_str()), - Outputs{OutputSpec{"HMP", "DIGITS", 0, Lifetime::Timeframe}, OutputSpec{"HMP", "ORBITS", 0, Lifetime::Timeframe}}, + inputs, + outputs, AlgorithmSpec{adaptFromTask()}, Options{{"print", VariantType::Bool, false, {"print digits"}}, {"cru-map", VariantType::String, "", {"custom CRU mapping"}}, From e42cae17b858365ae3ba8185da1169b9597ad831 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 18 Jan 2021 17:34:25 +0100 Subject: [PATCH 095/208] MORE WORKFLOWS --- Detectors/HMPID/base/CMakeLists.txt | 5 +- .../HMPID/base/include/HMPIDBase/Digit.h | 2 + Detectors/HMPID/base/src/HMPIDBaseLinkDef.h | 1 + Detectors/HMPID/reconstruction/CMakeLists.txt | 2 +- .../HMPIDReconstruction/HmpidDecodeRawMem.h | 4 +- .../reconstruction/src/HmpidDecodeRawMem.cxx | 4 +- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 6 +- Detectors/HMPID/workflow/CMakeLists.txt | 20 ++- .../include/HMPIDWorkflow/DataDecoderSpec.h | 9 +- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 46 ++++++ .../include/HMPIDWorkflow/RawFileReaderSpec.h | 49 ++++++ .../HMPID/workflow/src/DataDecoderSpec.cxx | 148 +++++------------ .../HMPID/workflow/src/DumpDigitsSpec.cxx | 110 +++++++++++++ .../HMPID/workflow/src/RawFileReaderSpec.cxx | 150 ++++++++++++++++++ .../workflow/src/dump-digits-workflow.cxx | 43 +++++ .../workflow/src/raw-to-digits-workflow.cxx | 1 + .../src/rawfile-to-digits-workflow.cxx | 43 +++++ 17 files changed, 522 insertions(+), 121 deletions(-) create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h create mode 100644 Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/dump-digits-workflow.cxx create mode 100644 Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx diff --git a/Detectors/HMPID/base/CMakeLists.txt b/Detectors/HMPID/base/CMakeLists.txt index 424f49648c968..579e279202b51 100644 --- a/Detectors/HMPID/base/CMakeLists.txt +++ b/Detectors/HMPID/base/CMakeLists.txt @@ -9,11 +9,12 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDBase - SOURCES src/Param.cxx src/Digit.cxx src/Cluster.cxx + SOURCES src/Param.cxx src/Digit.cxx src/Cluster.cxx src/Geo.cxx PUBLIC_LINK_LIBRARIES O2::CommonDataFormat O2::SimulationDataFormat ROOT::Physics) o2_target_root_dictionary(HMPIDBase HEADERS include/HMPIDBase/Param.h include/HMPIDBase/Digit.h - include/HMPIDBase/Cluster.h) + include/HMPIDBase/Cluster.h + include/HMPIDBase/Geo.h) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index be5116f0da64e..644862a0a889b 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -38,6 +38,8 @@ class Digit // convenience conversion to x-y pad coordinates int getPx() const { return Param::A2X(mPad); } int getPy() const { return Param::A2Y(mPad); } + int getPhC() const { return Param::A2P(mPad); } + int getCh() const { return Param::A2C(mPad); } static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); static float getFractionalContributionForPad(HitType const& hit, int somepad); diff --git a/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h b/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h index fc5aa9c380584..ea6c399143946 100644 --- a/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h +++ b/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h @@ -21,5 +21,6 @@ #pragma link C++ class vector < o2::hmpid::Digit> + ; #pragma link C++ class o2::hmpid::HitType + ; #pragma link C++ class vector < o2::hmpid::HitType> + ; +#pragma link C++ class o2::hmpid::Geo + ; #endif diff --git a/Detectors/HMPID/reconstruction/CMakeLists.txt b/Detectors/HMPID/reconstruction/CMakeLists.txt index 346cad9e40c7f..b4ed8db47cec7 100644 --- a/Detectors/HMPID/reconstruction/CMakeLists.txt +++ b/Detectors/HMPID/reconstruction/CMakeLists.txt @@ -9,7 +9,7 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDReconstruction - SOURCES src/Clusterer.cxx + SOURCES src/Clusterer.cxx SOURCES src/HmpidDecoder.cxx src/HmpidDecodeRawMem.cxx src/HmpidEquipment.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDBase O2::HMPIDSimulation) diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h index 6d9160237e07d..0b3d221a1569e 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include "HMPIDBase/Digit.h" #include "HMPIDBase/Geo.h" @@ -60,7 +60,7 @@ class HmpidDecodeRawDigit: public HmpidDecodeRawMem HmpidDecodeRawDigit(int numOfEquipments); ~HmpidDecodeRawDigit(); - vector mDigits; + std::vector mDigits; private: void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 607043e94a619..8d89c773bfc06 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -143,7 +143,7 @@ void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, int /// @param[in] numOfEquipments : the number of equipments to define [1..14] HmpidDecodeRawDigit::HmpidDecodeRawDigit(int numOfEquipments) : - HmpidDecoder(numOfEquipments) + HmpidDecodeRawMem(numOfEquipments) { } @@ -158,7 +158,7 @@ HmpidDecodeRawDigit::HmpidDecodeRawDigit(int numOfEquipments) /// @param[in] *LinkIds : the pointer to the Link ID array HmpidDecodeRawDigit::HmpidDecodeRawDigit(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) : - HmpidDecoder(EqIds, CruIds, LinkIds, numOfEquipments) + HmpidDecodeRawMem(EqIds, CruIds, LinkIds, numOfEquipments) { } diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 7eb5d751901f0..1966abc517308 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -18,7 +18,7 @@ /* ------ HISTORY --------- */ -#include "FairLogger.h" +#include "Framework/Logger.h" #include "Headers/RAWDataHeader.h" #include "HMPIDReconstruction/HmpidDecoder.h" @@ -473,7 +473,7 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) catch (int e) { // The stream end ! LOG(DEBUG) << "End main decoding loop !"; - break; + throw TH_BUFFEREMPTY; } try { decodeHeader(*streamBuf, &equipmentIndex); @@ -781,7 +781,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) catch (int e) { // The stream end ! LOG(DEBUG) << "End Fast Page decoding loop !"; - break; + throw TH_BUFFEREMPTY; } try { decodeHeader(*streamBuf, &equipmentIndex); diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index 6bd41689209b6..bddf7ddaccb1c 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -9,7 +9,11 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDWorkflow - SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx + SOURCES src/DataDecoderSpec.cxx + src/DigitReaderSpec.cxx + src/ClusterizerSpec.cxx + src/RawFileReaderSpec.cxx + src/DumpDigitsSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::DetectorsRaw @@ -19,11 +23,21 @@ o2_add_library(HMPIDWorkflow o2_add_executable(recoworkflow COMPONENT_NAME hmpid - SOURCES src/HMPIDRecoWorkflow.cxx + SOURCES src/HMPIDRecoWorkflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) - o2_add_executable(raw-to-digits-workflow COMPONENT_NAME hmpid SOURCES src/raw-to-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + +o2_add_executable(rawfile-to-digits-workflow + COMPONENT_NAME hmpid + SOURCES src/rawfile-to-digits-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + +o2_add_executable(dump-digits-workflow + COMPONENT_NAME hmpid + SOURCES src/dump-digits-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + \ No newline at end of file diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index c57603fd16363..7b649dbf6fb60 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -21,12 +21,14 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" +#include "HMPIDReconstruction/HmpidDecodeRawMem.h" + namespace o2 { namespace hmpid { - class DataDecoderTask : public Task + class DataDecoderTask : public framework::Task { public: DataDecoderTask() = default; @@ -34,10 +36,11 @@ namespace hmpid void init(framework::InitContext& ic) final; void run(framework::ProcessingContext& pc) final; void decodeTF(framework::ProcessingContext& pc); + void decodeReadout(framework::ProcessingContext& pc); + void decodeRawFile(framework::ProcessingContext& pc); private: - o2::hmpid::HmpidDecodeRawDigit *mDeco; - // vector mDigits; + HmpidDecodeRawDigit *mDeco; }; diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h new file mode 100644 index 0000000000000..800ffc1c08e8d --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -0,0 +1,46 @@ +// 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 DatDecoderSpec.h +/// \author Andrea Ferrero +/// +/// \brief Definition of a data processor to run the raw decoding +/// + +#ifndef O2_MCH_DATADECODERSPEC_H_ +#define O2_MCH_DATADECODERSPEC_H_ + +#include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" + +namespace o2 +{ +namespace hmpid +{ + + class DumpDigitsTask : public framework::Task + { + public: + DumpDigitsTask() = default; + ~DumpDigitsTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + + private: + + }; + +o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec = "HMP/DIGITS"); + +} // end namespace hmpid +} // end namespace o2 + +#endif diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h new file mode 100644 index 0000000000000..1d54d2fedac44 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h @@ -0,0 +1,49 @@ +/* + * RawFilereader.h + * + * Created on: 18 gen 2021 + * Author: fap + */ + +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ + +#include +#include +#include +#include +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/runDataProcessing.h" + +namespace o2 +{ +namespace hmpid +{ + +class RawFileReaderTask : public framework::Task +{ + public: + RawFileReaderTask() = default; + ~RawFileReaderTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + + private: + std::ifstream mInputFile{}; ///< input file +}; + +o2::framework::DataProcessorSpec getRawFileReaderSpec(std::string inputSpec = "HMP/rawfile"); +} // end namespace hmpid +} // end namespace o2 + + + +#endif /* DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ */ diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index b37bcc6acf9c0..b751a476302f6 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -32,6 +32,7 @@ #include "Framework/Output.h" #include "Framework/Task.h" #include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" #include "Headers/RAWDataHeader.h" #include "DetectorsRaw/RDHUtils.h" @@ -67,10 +68,8 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) mDeco->mDigits.clear(); decodeTF(pc); - - -// for (auto&& input : pc.inputs()) { -// std::cout << " ******* input " << input.spec->binding << std::endl; + decodeReadout(pc); + decodeRawFile(pc); LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; @@ -98,121 +97,61 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) */ - //_________________________________________________________________________________________________ +//_________________________________________________________________________________________________ // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) { - LOG(INFO) << "*********** In decodeTF **************"); + LOG(INFO) << "*********** In decodeTF **************"; + // get the input buffer auto& inputs = pc.inputs(); - DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); + DPLRawParser parser(inputs, o2::framework::select("TF:HMP/rawdata")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); } - /* - int equipmentIndex = -1; - HmpidEquipment *eq; - - // get the input buffer - auto& inputs = pc.inputs(); - DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); - - for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - size_t payloadSize = it.size(); - if(payloadSize <= 0) { - LOG(INFO) << "Payload empty"; - continue; - } - - auto const* rdh = it.get_if(); - auto const* raw = it.raw(); - uint32_t* data = (uint32_t*)it.data(); - - try { - mDeco->decodeHeader((uint32_t *)rdh, &equipmentIndex); - } - catch (int e) { - LOG(ERROR) << "Failed to decode the Header !"; - throw TH_WRONGHEADER; - } - eq = mDeco->evaluateHeaderContents(equipmentIndex); - - uint32_t wpprev = 0; - uint32_t wp = 0; - int newOne = true; - int p1, p2, p3, p4; - int error; - - int payIndex = 0; - while (payIndex < mDeco->mNumberWordToRead) { //start the payload loop word by word - wpprev = wp; - wp = *data; data++; - if (wp == wpprev) { - LOG(DEBUG) << "Equip=" << mDeco->mEquipment << mDeco->sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; - } else { - if( mDeco->isPadWord(wp, &error, &p1, &p2, &p3, &p4) == true) { - if( error != false) { - eq->setPad(p1 - 1, p2 - 1, p3, p4); - mDigits.push_back(Digit(mDeco->mHeBCDI, mDeco->mHeORBIT, - o2::hmpid::Geo::GetPad(equipmentIndex, p1 - 1, p2 - 1, p3), - p4)); - eq->mSampleNumber++; - } - } - } - payIndex += 1; - } - - LOG(DEBUG) << " ***** payloadSize = " << payloadSize; - - } - // cycle in order to update info for the last event - for (int i = 0; i < mDeco->mNumberOfEquipments; i++) { - if (mDeco->mTheEquipments[i]->mNumberOfEvents > 0) { - mDeco->updateStatistics(mDeco->mTheEquipments[i]); - } - } -*/ + return; } +//_________________________________________________________________________________________________ +// the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow +void DataDecoderTask::decodeReadout(framework::ProcessingContext& pc) +{ + LOG(INFO) << "*********** In decode readout **************"; - //_________________________________________________________________________________________________ - // the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow -/* void decodeReadout(const o2::framework::DataRef& input) - { - static int nFrame = 1; - // get the input buffer - if (input.spec->binding != "readout") { - return; - } + // get the input buffer + auto& inputs = pc.inputs(); + DPLRawParser parser(inputs, o2::framework::select("HMP/readout")); - const auto* header = o2::header::get(input.header); - if (!header) { - return; - } + for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { + uint32_t *theBuffer = (uint32_t *)it.raw(); + mDeco->setUpStream(theBuffer, it.size()+it.offset()); + mDeco->decodePageFast(&theBuffer); + } + return; +} - auto const* raw = input.payload; - // cout size of payload - std::cout << " payloadSize " << header->payloadSize << std::endl; - //size_t payloadSize = header->payloadSize; +// the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow +void DataDecoderTask::decodeRawFile(framework::ProcessingContext& pc) +{ + LOG(INFO) << "*********** In decode rawfile **************"; - if (mPrint) { - std::cout << nFrame << " payloadSize=" << payloadSize << std::endl; - } - nFrame += 1; - if (payloadSize == 0) { - return; + for (auto&& input : pc.inputs()) { + if (input.spec->binding == "rawfile") { + const auto* header = o2::header::get(input.header); + if (!header) { + return; + } + uint32_t *theBuffer = (uint32_t *)input.payload; + int pagesize = header->payloadSize; + mDeco->setUpStream(theBuffer, pagesize); + mDeco->decodePageFast(&theBuffer); } - - gsl::span buffer(reinterpret_cast(raw), payloadSize); - mDecoder->decodeBuffer(buffer); } -*/ - //_________________________________________________________________________________________________ + return; +} //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) @@ -220,7 +159,9 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("RAWDATA", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); + inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); + inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); @@ -233,10 +174,7 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) inputs, outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"print", VariantType::Bool, false, {"print digits"}}, - {"cru-map", VariantType::String, "", {"custom CRU mapping"}}, - {"fec-map", VariantType::String, "", {"custom FEC mapping"}}, - {"ds2manu", VariantType::Bool, false, {"convert channel numbering from Run3 to Run1-2 order"}}}}; + Options{{"print", VariantType::Bool, false, {"print digits"}}} }; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx new file mode 100644 index 0000000000000..1f75f3291b50b --- /dev/null +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -0,0 +1,110 @@ +// draft +// 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 DatDecoderSpec.cxx +/// \author +/// +/// \brief Implementation of a data processor to run the HMPID raw decoding +/// + +#include +#include +#include +#include +#include +#include +#include + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" + +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" +#include "DPLUtils/DPLRawParser.h" + +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDWorkflow/DumpDigitsSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using namespace o2; +using namespace o2::framework; +using RDH = o2::header::RDHAny; + +//======================= +// Data decoder +void DumpDigitsTask::init(framework::InitContext& ic) +{ + + return; +} + +void DumpDigitsTask::run(framework::ProcessingContext& pc) +{ + + LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; + + for (auto&& input : pc.inputs()) { + if (input.spec->binding == "DIGITS") { + const auto* header = o2::header::get(input.header); + if (!header) { + return; + } + std::vector*theDigits = (std::vector*)input.payload; + + for(o2::hmpid::Digit Dig : *theDigits) { + std::cout << Dig.getOrbit() << "," << Dig.getBC() << "," << Dig.getPadID() << + " (" << Dig.getCh() << "," << Dig.getPhC() << "," << Dig.getPx() << "," << Dig.getPy() << ") =" << + Dig.getCharge() << std::endl; + } + + } + } + + + + + +} + +//_________________________________________________________________________________________________ +o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) +//o2::framework::DataPrecessorSpec getDecodingSpec() +{ + + std::vector inputs; + inputs.emplace_back("DIGITS", o2::header::gDataOriginHMP, "DIGITS_VECT", 0, Lifetime::Timeframe); + + std::vector outputs; + + + return DataProcessorSpec{ + "HMP-DataDecoder", + inputs, + outputs, + AlgorithmSpec{adaptFromTask()}, + Options{{"print", VariantType::Bool, false, {"print digits"}}} }; +} + +} // namespace hmpid +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx b/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx new file mode 100644 index 0000000000000..b120571fbd4fa --- /dev/null +++ b/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx @@ -0,0 +1,150 @@ +// 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 RawFileReaderSpec.cxx +/// \author Antonio Franco +/// +/// \brief This is an executable that reads a data file from disk and sends the individual CRU pages via DPL. +/// +/// This is an executable that reads a data file from disk and sends the individual CRU pages via the Data Processing Layer. +// + +#include +#include +#include +#include +#include +#include +#include + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" + + +#include "DPLUtils/DPLRawParser.h" +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" + +#include "HMPIDWorkflow/RawFileReaderSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using RDH = o2::header::RDHAny; +using namespace o2; +using namespace o2::framework; + + +void RawFileReaderTask::init(framework::InitContext& ic) +{ + // Get the input file and other options from the context + LOG(INFO) << "Raw file reader Init"; + + auto inputFileName = ic.options().get("infile"); + mInputFile.open(inputFileName, std::ios::binary); + if (!mInputFile.is_open()) { + throw std::invalid_argument("Cannot open input file \"" + inputFileName + "\""); + } + + // define the callback to close the file + auto stop = [this]() { + LOG(INFO) << "stop file reader"; + this->mInputFile.close(); + }; + ic.services().get().set(CallbackService::Id::Stop, stop); +} + +//_________________________________________________________________________________________________ +void RawFileReaderTask::run(framework::ProcessingContext& pc) +{ + // send one RDH block via DPL + RDH rdh; + char* buf{nullptr}; + size_t bufSize{0}; + + while (true) { + + // read the next RDH, stop if no more data is available + mInputFile.read((char*)(&rdh), sizeof(RDH)); + if (mInputFile.fail()) { + pc.services().get().endOfStream(); + return; // probably reached eof + } + + // check that the RDH version is ok (only RDH versions from 4 to 6 are supported at the moment) + auto rdhVersion = o2::raw::RDHUtils::getVersion(rdh); + auto rdhHeaderSize = o2::raw::RDHUtils::getHeaderSize(rdh); + if (rdhVersion != 6 || rdhHeaderSize != 64) { + return; + } + + // get the frame size from the RDH offsetToNext field + auto frameSize = o2::raw::RDHUtils::getOffsetToNext(rdh); + + // stop if the frame size is too small + if (frameSize < rdhHeaderSize) { + LOG(WARNING) << " FrameSize too small: " << frameSize; + pc.services().get().endOfStream(); + return; + } + + // allocate the output buffer + buf = (char*)realloc(buf, frameSize); + if (buf == nullptr) { + LOG(ERROR) << " Failed to allocate buffer"; + pc.services().get().endOfStream(); + return; + } + + // copy the RDH into the output buffer + memcpy(buf, &rdh, rdhHeaderSize); + + // read the frame payload into the output buffer + mInputFile.read(buf + rdhHeaderSize, frameSize - rdhHeaderSize); + // stop if data cannot be read completely + if (mInputFile.fail()) { + LOG(ERROR) << "Fail to read the payload "; + free(buf); + pc.services().get().endOfStream(); + return; // probably reached eof + } + // create the output message + auto freefct = [](void* data, void* /*hint*/) { free(data); }; + pc.outputs().adoptChunk(Output{"HMP", "rawfile"}, buf, bufSize, freefct, nullptr); + } +} + +//_________________________________________________________________________________________________ +// clang-format off +o2::framework::DataProcessorSpec getRawFileReaderSpec() +{ + return DataProcessorSpec{ + "RawFileReader", + Inputs{}, + Outputs{OutputSpec{"HMP", "rawfile", 0, Lifetime::Timeframe}}, + AlgorithmSpec{adaptFromTask()}, + Options{{"infile", VariantType::String, "", {"input file name"}}} + }; +} +// clang-format on + + +} // end namespace mch +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx new file mode 100644 index 0000000000000..c84533839ce68 --- /dev/null +++ b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx @@ -0,0 +1,43 @@ +// 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 raw-to-digits-workflow.cxx +/// \author Andrea Ferrero +/// +/// \brief This is an executable that runs the decoding via DPL. +/// +/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. +/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow +/// + +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/Task.h" +#include "Framework/runDataProcessing.h" + +#include "HMPIDWorkflow/DumpDigitsSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + DataProcessorSpec consumer = o2::hmpid::getDumpDigitsSpec(); +// DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); + specs.push_back(consumer); +// specs.push_back(consumer); + + return specs; +} diff --git a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx index 462ee37e15521..ea0ee629fcce7 100644 --- a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx @@ -24,6 +24,7 @@ #include "Framework/ControlService.h" #include "Framework/Task.h" #include "Framework/runDataProcessing.h" + #include "HMPIDWorkflow/DataDecoderSpec.h" using namespace o2; diff --git a/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx new file mode 100644 index 0000000000000..52bd546179a25 --- /dev/null +++ b/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx @@ -0,0 +1,43 @@ +// 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 raw-to-digits-workflow.cxx +/// \author Andrea Ferrero +/// +/// \brief This is an executable that runs the decoding via DPL. +/// +/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. +/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow +/// + +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/Task.h" +#include "Framework/runDataProcessing.h" + +#include "HMPIDWorkflow/RawFileReaderSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + DataProcessorSpec producer = o2::hmpid::getRawFileReaderSpec(); +// DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); + specs.push_back(producer); +// specs.push_back(consumer); + + return specs; +} From e59122972c3dabef752c07fba03678f66f791862 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 19 Jan 2021 10:17:59 +0100 Subject: [PATCH 096/208] Version 0 --- Detectors/HMPID/workflow/CMakeLists.txt | 15 +++----- .../include/HMPIDWorkflow/DataDecoderSpec.h | 4 +- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 4 +- ...ReaderSpec.h => RawFileReaderSpec.h_trash} | 30 +++++++-------- .../HMPID/workflow/src/DataDecoderSpec.cxx | 38 +++++++++++++++++++ ...erSpec.cxx => RawFileReaderSpec.cxx_trash} | 23 +++++++---- ...x => rawfile-to-digits-workflow.cxx_trash} | 0 7 files changed, 78 insertions(+), 36 deletions(-) rename Detectors/HMPID/workflow/include/HMPIDWorkflow/{RawFileReaderSpec.h => RawFileReaderSpec.h_trash} (60%) rename Detectors/HMPID/workflow/src/{RawFileReaderSpec.cxx => RawFileReaderSpec.cxx_trash} (84%) rename Detectors/HMPID/workflow/src/{rawfile-to-digits-workflow.cxx => rawfile-to-digits-workflow.cxx_trash} (100%) diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index bddf7ddaccb1c..0d8f894699251 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -9,11 +9,8 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDWorkflow - SOURCES src/DataDecoderSpec.cxx - src/DigitReaderSpec.cxx - src/ClusterizerSpec.cxx - src/RawFileReaderSpec.cxx - src/DumpDigitsSpec.cxx +# SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/RawFileReaderSpec.cxx src/DumpDigitsSpec.cxx + SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::DetectorsRaw @@ -31,10 +28,10 @@ o2_add_executable(raw-to-digits-workflow SOURCES src/raw-to-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) -o2_add_executable(rawfile-to-digits-workflow - COMPONENT_NAME hmpid - SOURCES src/rawfile-to-digits-workflow.cxx - PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) +#o2_add_executable(rawfile-to-digits-workflow +# COMPONENT_NAME hmpid +# SOURCES src/rawfile-to-digits-workflow.cxx +# PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) o2_add_executable(dump-digits-workflow COMPONENT_NAME hmpid diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index 7b649dbf6fb60..4d09f3ae4b186 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -15,8 +15,8 @@ /// \brief Definition of a data processor to run the raw decoding /// -#ifndef O2_MCH_DATADECODERSPEC_H_ -#define O2_MCH_DATADECODERSPEC_H_ +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index 800ffc1c08e8d..12ff4633986d6 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -15,8 +15,8 @@ /// \brief Definition of a data processor to run the raw decoding /// -#ifndef O2_MCH_DATADECODERSPEC_H_ -#define O2_MCH_DATADECODERSPEC_H_ +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DUMPDIGITSPEC_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DUMPDIGITSPEC_H_ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash similarity index 60% rename from Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h rename to Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash index 1d54d2fedac44..90f252aa0afc1 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash @@ -5,23 +5,23 @@ * Author: fap */ -#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ -#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ -#include -#include +//#include +//#include #include -#include -#include "Framework/CallbackService.h" -#include "Framework/ConfigParamRegistry.h" -#include "Framework/ControlService.h" -#include "Framework/DataProcessorSpec.h" -#include "Framework/Lifetime.h" -#include "Framework/Output.h" +//#include +//#include "Framework/CallbackService.h" +//#include "Framework/ConfigParamRegistry.h" +//#include "Framework/ControlService.h" +//#include "Framework/DataProcessorSpec.h" +//#include "Framework/Lifetime.h" +//#include "Framework/Output.h" #include "Framework/Task.h" -#include "Framework/WorkflowSpec.h" +//#include "Framework/WorkflowSpec.h" #include "Framework/DataProcessorSpec.h" -#include "Framework/runDataProcessing.h" +//#include "Framework/runDataProcessing.h" namespace o2 { @@ -40,10 +40,10 @@ class RawFileReaderTask : public framework::Task std::ifstream mInputFile{}; ///< input file }; -o2::framework::DataProcessorSpec getRawFileReaderSpec(std::string inputSpec = "HMP/rawfile"); +o2::framework::DataProcessorSpec getRawFileReaderSpec(); } // end namespace hmpid } // end namespace o2 -#endif /* DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_ */ +#endif /* DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ */ diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index b751a476302f6..9164ed0fe5f71 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -24,6 +24,8 @@ #include #include +#include "TTree.h" + #include "Framework/CallbackService.h" #include "Framework/ConfigParamRegistry.h" #include "Framework/ControlService.h" @@ -75,6 +77,42 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + + float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; + float avgBusyTime[o2::hmpid::Geo::MAXEQUIPMENTS]; + + uint32_t numOfSamples[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + + TTree theObj("t", "HMPID Data Decoding Statistic results"); + + theObj.Branch("Average_Event_Size", avgEventSize,"f[14]"); + theObj.Branch("Average_Busy_Time", avgBusyTime,"f[14]"); + theObj.Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); + theObj.Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); + theObj.Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); + + + int numEqui = mDeco->getNumberOfEquipments(); + for(int e=0;egetAverageEventSize(e); + avgBusyTime[e] = mDeco->getAverageBusyTime(e); + } + for(int m=0; m < o2::hmpid::Geo::N_MODULES; m++) + for(int y=0; y < o2::hmpid::Geo::N_YCOLS; y++) + for(int x=0; x < o2::hmpid::Geo::N_XROWS; x++ ) { + numOfSamples[m][y][x] = mDeco->getPadSamples(m, y, x); + sumOfCharges[m][y][x] = mDeco->getPadSum(m, y, x); + squareOfCharges[m][y][x] = mDeco->getPadSquares(m, y, x); + } + theObj.Fill(); + //t.Write(); + // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); + // mDeco->getChannelSquare(Equipment, Column, Dilogic, Channel); + // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); + pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, theObj); + } /* auto& digits = mDecoder->getOutputDigits(); diff --git a/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx b/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash similarity index 84% rename from Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx rename to Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash index b120571fbd4fa..b87e288dd055e 100644 --- a/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx +++ b/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash @@ -56,8 +56,8 @@ void RawFileReaderTask::init(framework::InitContext& ic) { // Get the input file and other options from the context LOG(INFO) << "Raw file reader Init"; - - auto inputFileName = ic.options().get("infile"); +std::cout << ">>> INIT !" << std::endl; + auto inputFileName = ic.options().get("input-file"); mInputFile.open(inputFileName, std::ios::binary); if (!mInputFile.is_open()) { throw std::invalid_argument("Cannot open input file \"" + inputFileName + "\""); @@ -85,6 +85,7 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) mInputFile.read((char*)(&rdh), sizeof(RDH)); if (mInputFile.fail()) { pc.services().get().endOfStream(); + LOG(INFO) << " Fails to read the header ! "; return; // probably reached eof } @@ -92,9 +93,10 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) auto rdhVersion = o2::raw::RDHUtils::getVersion(rdh); auto rdhHeaderSize = o2::raw::RDHUtils::getHeaderSize(rdh); if (rdhVersion != 6 || rdhHeaderSize != 64) { + LOG(WARNING) << " Wrong RDH (v." << rdhVersion << ", size=" << rdhHeaderSize << ")"; return; } - + std::cout<<"h"; // get the frame size from the RDH offsetToNext field auto frameSize = o2::raw::RDHUtils::getOffsetToNext(rdh); @@ -118,6 +120,7 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) // read the frame payload into the output buffer mInputFile.read(buf + rdhHeaderSize, frameSize - rdhHeaderSize); + std::cout<<"p"; // stop if data cannot be read completely if (mInputFile.fail()) { LOG(ERROR) << "Fail to read the payload "; @@ -127,21 +130,25 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) } // create the output message auto freefct = [](void* data, void* /*hint*/) { free(data); }; - pc.outputs().adoptChunk(Output{"HMP", "rawfile"}, buf, bufSize, freefct, nullptr); + + pc.outputs().make(Output{"HMP","rawfile"},buf, bufSize ); +// pc.outputs().snapshot(Output{"HMP", "rawfile", 0, o2::framework::Lifetime::Timeframe}, buf); +// pc.outputs().adoptChunk(Output{"HMP", "rawfile"}, buf, bufSize, freefct, nullptr); + std::cout<<"w"<()}, - Options{{"infile", VariantType::String, "", {"input file name"}}} - }; + Options{{"input-file", VariantType::String, "", {"input raw file name"}}}}; } // clang-format on diff --git a/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash similarity index 100% rename from Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx rename to Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash From 4869002d883c23f9fe0fd61cbeb3dea806423baf Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 21 Jan 2021 10:17:07 +0100 Subject: [PATCH 097/208] V.0 --- .../HMPID/base/include/HMPIDBase/Digit.h | 44 ++++++++-- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 6 +- .../HMPID/base/include/HMPIDBase/Param.h | 25 ++++-- Detectors/HMPID/base/src/Digit.cxx | 81 ++++++++++++++++++- Detectors/HMPID/base/src/Geo.cxx | 24 ------ .../reconstruction/src/HmpidDecodeRawMem.cxx | 5 +- 6 files changed, 136 insertions(+), 49 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 644862a0a889b..35933e26da868 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -26,9 +26,36 @@ namespace hmpid //using DigitBase = o2::dataformats::TimeStamp; class Digit { + public: + + // Conversion functions + static inline uint32_t Abs(int ch, int pc, int x, int y) { return ch << 20 | pc << 16 | x << 8 | y; } + static inline int DDL2C(int ddl) { return ddl >> 1; } //ddl -> chamber + static inline int A2C(uint32_t pad) { return (pad & 0x00F00000) >> 20; } //abs pad -> chamber + static inline int A2P(uint32_t pad) { return (pad & 0x000F0000) >> 16; } //abs pad -> pc + static inline int A2X(uint32_t pad) { return (pad & 0x0000FF00) >> 8; } //abs pad -> pad X + static inline int A2Y(uint32_t pad) { return (pad & 0x000000FF); } //abs pad -> pad Y + static inline uint32_t Photo2Pad(int ch, int pc, int x, int y) { return Abs(ch, pc, x, y); } + static uint32_t Equipment2Pad(int Equi, int Colu, int Dilo, int Chan); + static void Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Chan); + static void Pad2Absolute(uint32_t pad, int *Module, int *x, int *y); + static uint32_t Absolute2Pad(int Module, int x, int y); + static void Pad2Photo(uint32_t pad, int *chamber, int *photo, int *x, int *y); + + // Operators definition ! + inline bool operator<(const Digit& l, const Digit& r) { return l.mPad < r.mPad; }; + inline bool operator==(const Digit& l, const Digit& r) { return l.mPad == r.mPad; }; + inline bool operator> (const Digit& l, const Digit& r){ return r < l; }; + inline bool operator<=(const Digit& l, const Digit& r){ return !(l > r); }; + inline bool operator>=(const Digit& l, const Digit& r){ return !(l < r); }; + inline bool operator!=(const Digit& l, const Digit& r) { return !(l == r); }; + public: Digit() = default; - Digit(int bc, int orbit, int pad, float charge) : mBc(bc), mOrbit(orbit), mPad(pad), mQ(charge) {}; + Digit(int bc, int orbit, int pad, float charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad) {}; + Digit(int bc, int orbit, int chamber, int photo, int x, int y, float charge); + Digit(int bc, int orbit, float charge, int equipment, int column, int dilogic, int channel) ; + Digit(int bc, int orbit, float charge, int module, int x, int y); float getCharge() const { return mQ; } int getPadID() const { return mPad; } @@ -36,10 +63,11 @@ class Digit int getBC() const { return mBc; } // convenience conversion to x-y pad coordinates - int getPx() const { return Param::A2X(mPad); } - int getPy() const { return Param::A2Y(mPad); } - int getPhC() const { return Param::A2P(mPad); } - int getCh() const { return Param::A2C(mPad); } + int getPx() const { return A2X(mPad); } + int getPy() const { return A2Y(mPad); } + int getPhC() const { return A2P(mPad); } + int getCh() const { return A2C(mPad); } + static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); static float getFractionalContributionForPad(HitType const& hit, int somepad); @@ -49,12 +77,12 @@ class Digit private: float mQ = 0.; - int mPad = 0.; // -1 indicates invalid digit + uint32_t mPad = 0.; // -1 indicates invalid digit int mBc = 0.; int mOrbit = 0; - static float LorsX(int pad) { return Param::LorsX(Param::A2P(pad), Param::A2X(pad)); } //center of the pad x, [cm] - static float LorsY(int pad) { return Param::LorsY(Param::A2P(pad), Param::A2Y(pad)); } //center of the pad y, [cm] + static float LorsX(int pad) { return Param::LorsX(A2P(pad), A2X(pad)); } //center of the pad x, [cm] + static float LorsY(int pad) { return Param::LorsY(A2P(pad), A2Y(pad)); } //center of the pad y, [cm] // determines the total charge created by a hit // might modify the localX, localY coordiates associated to the hit diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 92c543fdeb2d2..48b6bed60fdd2 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -57,15 +57,13 @@ class Geo static constexpr int EQUIPMENTSPERMODULE = 2; - static constexpr int N_EQUIPMENTTOTALPADS = N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; static constexpr int N_HMPIDTOTALPADS = MAXEQUIPMENTS * N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; - static void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); - static Int_t GetPad(int Equi, int Colu, int Dilo, int Chan); - + + // from //static constexpr Bool_t FEAWITHMASKS[NSECTORS] = // // TOF sectors with Nino masks: 0, 8, 9, 10, 16 diff --git a/Detectors/HMPID/base/include/HMPIDBase/Param.h b/Detectors/HMPID/base/include/HMPIDBase/Param.h index d94a6c2caee95..18c4de8dce030 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Param.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Param.h @@ -80,9 +80,9 @@ class Param static float SizeAllY() { return fgAllY; } //all PCs size y, [cm] //center of the pad x, [cm] - static float LorsX(Int_t pc, Int_t padx) { return (padx + 0.5) * SizePadX() + fgkMinPcX[pc]; } + static float LorsX(Int_t pc, int padx) { return (padx + 0.5) * SizePadX() + fgkMinPcX[pc]; } //center of the pad y, [cm] - static float LorsY(Int_t pc, Int_t pady) { return (pady + 0.5) * SizePadY() + fgkMinPcY[pc]; } + static float LorsY(Int_t pc, int pady) { return (pady + 0.5) * SizePadY() + fgkMinPcY[pc]; } //PhiMin (degree) of the camber ch float ChPhiMin(Int_t ch) { return Lors2Mars(ch, LorsX(ch, kMinPx) - mX, LorsY(ch, kMinPy) - mY).Phi() * r2d(); } @@ -96,12 +96,21 @@ class Param static void Lors2Pad(float x, float y, Int_t& pc, Int_t& px, Int_t& py); //(x,y)->(pc,px,py) //(ch,pc,padx,pady)-> abs pad - static Int_t Abs(Int_t ch, Int_t pc, Int_t x, Int_t y) { return ch * 100000000 + pc * 1000000 + x * 1000 + y; } - static Int_t DDL2C(Int_t ddl) { return ddl / 2; } //ddl -> chamber - static Int_t A2C(Int_t pad) { return pad / 100000000; } //abs pad -> chamber - static Int_t A2P(Int_t pad) { return pad % 100000000 / 1000000; } //abs pad -> pc - static Int_t A2X(Int_t pad) { return pad % 1000000 / 1000; } //abs pad -> pad X - static Int_t A2Y(Int_t pad) { return pad % 1000; } //abs pad -> pad Y +// static Int_t Abs(Int_t ch, Int_t pc, Int_t x, Int_t y) { return ch * 100000000 + pc * 1000000 + x * 1000 + y; } +// static Int_t DDL2C(Int_t ddl) { return ddl / 2; } //ddl -> chamber +// static Int_t A2C(Int_t pad) { return pad / 100000000; } //abs pad -> chamber +// static Int_t A2P(Int_t pad) { return pad % 100000000 / 1000000; } //abs pad -> pc +// static Int_t A2X(Int_t pad) { return pad % 1000000 / 1000; } //abs pad -> pad X +// static Int_t A2Y(Int_t pad) { return pad % 1000; } //abs pad -> pad Y + + + // Moved in Digit.h + static Int_t Abs(Int_t ch, Int_t pc, Int_t x, Int_t y) { return ch << 20 | pc << 16 | x << 8 | y; } + static Int_t DDL2C(Int_t ddl) { return ddl >> 1; } //ddl -> chamber + static Int_t A2C(Int_t pad) { return (pad & 0x00F00000) >> 20; } //abs pad -> chamber + static Int_t A2P(Int_t pad) { return (pad & 0x000F0000) >> 16; } //abs pad -> pc + static Int_t A2X(Int_t pad) { return (pad & 0x0000FF00) >> 8; } //abs pad -> pad X + static Int_t A2Y(Int_t pad) { return (pad & 0x000000FF); } //abs pad -> pad Y static bool IsOverTh(float q) { return q >= fgThreshold; } //is digit over threshold? diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index e82d63fa5f5b9..87135473d880b 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -9,6 +9,7 @@ // or submit itself to any jurisdiction. #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" #include "HMPIDBase/Param.h" #include "TRandom.h" #include "TMath.h" @@ -17,6 +18,84 @@ using namespace o2::hmpid; ClassImp(o2::hmpid::Digit); +// ----- Constructors ------------ + Digit::Digit(int bc, int orbit, int chamber, int photo, int x, int y, float charge) +{ + mBc = bc; + mOrbit = orbit; + mQ = charge; + mPad = Abs(chamber, photo, x, y); +} + + Digit::Digit(int bc, int orbit, float charge, int equipment, int column, int dilogic, int channel) +{ + mBc = bc; + mOrbit = orbit; + mQ = charge; + mPad = Equipment2Pad(equipment, column, dilogic, channel); +} + + Digit::Digit(int bc, int orbit, float charge, int module, int x, int y) +{ + mBc = bc; + mOrbit = orbit; + mQ = charge; + mPad = Absolute2Pad(module, x, y); +} + +// ----- Coordinate Conversion ---- +uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) +{ + if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || + Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return -1; + + int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) + int ch = Equi / 2; // The Module + int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; + int pc = (Equi % 2) ? 5-2*tmp : 2*tmp; // The PhotoCatode + int px = (Geo::N_DILOGICS+1 - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; + tmp = (Equi % 2) ? Colu : (23-Colu); + int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; + return Abs(ch,pc,px,py); +} + +void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Chan) +{ + int ch, ar, ac; + Pad2Absolute(pad, &ch, &ar, &ac); + Geo::Module2Equipment(ch, ac, ar, Equi, Colu, Dilo, Chan); + return; +} + +uint32_t Digit::Absolute2Pad(int Module, int x, int y) +{ + int ph = (y/Geo::N_COLXSEGMENT)+((x >= Geo::HALFXROWS ) ? 1 : 0); + int px = x % Geo::N_COLXSEGMENT; + int py = y % Geo::HALFXROWS; + return Abs(Module,ph,px,py); +} + +void Digit::Pad2Absolute(uint32_t pad, int *Module, int *x, int *y) +{ + *Module = A2C(pad); + int ph = A2P(pad); + int px = A2X(pad); + int py = A2Y(pad); + *x = (ph % 2 == 0) ? px : (px + Geo::HALFXROWS); + *y = ((ph >> 1) * Geo::N_COLXSEGMENT) + py; + return; +} + +void Digit::Pad2Photo(uint32_t pad, int *chamber, int *photo, int *x, int *y) +{ + *chamber = A2C(pad); + *photo = A2P(pad); + *x = A2X(pad); + *y = A2Y(pad); + return; +} + +// ----- Getter Methods --------- void Digit::getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge) { float localX; @@ -27,6 +106,7 @@ void Digit::getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& Param::Lors2Pad(localX, localY, pc, px, py); totalcharge = Digit::QdcTot(hit.GetEnergyLoss(), hit.GetTime(), pc, px, py, localX, localY); + return; } float Digit::getFractionalContributionForPad(HitType const& hit, int somepad) @@ -43,7 +123,6 @@ float Digit::getFractionalContributionForPad(HitType const& hit, int somepad) return Digit::InMathieson(localX, localY, somepad); } - float Digit::QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY) { // Samples total charge associated to a hit diff --git a/Detectors/HMPID/base/src/Geo.cxx b/Detectors/HMPID/base/src/Geo.cxx index 6bb41aa916be2..8b0957a3e9b1e 100644 --- a/Detectors/HMPID/base/src/Geo.cxx +++ b/Detectors/HMPID/base/src/Geo.cxx @@ -24,7 +24,6 @@ using namespace o2::hmpid; void Geo::Init() { LOG(INFO) << "hmpid::Geo: Initialization of HMPID parameters"; - } // =================== General Purposes HMPID Functions ======================= /// Functions to translate coordinates : from Module,Col,Row to Equipment,Col,Dilogic,Channel @@ -74,27 +73,4 @@ void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int return; } -//Int_t Geo::GetPad(int eqi, intnt_t row,Int_t dil,Int_t pad) -Int_t Geo::GetPad(int Equi, int Colu, int Dilo, int Chan) -{ - // The method returns the absolute pad number or -1 - // in case the charge from the channels - // has not been read or invalid arguments - - - if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= N_COLUMNS || - Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= N_CHANNELS ) return -1; - - int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) - int ch = Equi / 2; // The Module - int tmp = (23 - Colu) / N_COLXSEGMENT; - int pc = (Equi % 2) ? 5-2*tmp : 2*tmp; // The PhotoCatode - - int px = (N_DILOGICS+1 - Dilo) * DILOPADSROWS - Chan / DILOPADSCOLS - 1; //flip according to Paolo (2-9-2008) - - tmp = (Equi % 2) ? Colu : (23-Colu); - int py = DILOPADSCOLS * (tmp % DILOPADSROWS)+a2y[Chan % DILOPADSCOLS]; - - return Param::Abs(ch,pc,px,py); -} diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 8d89c773bfc06..5acef2e4d4799 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -179,10 +179,7 @@ HmpidDecodeRawDigit::~HmpidDecodeRawDigit() void HmpidDecodeRawDigit::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) { eq->setPad(col, dil, ch, charge); - mDigits.push_back(Digit(mHeBCDI, mHeORBIT, - o2::hmpid::Geo::GetPad(eq->getEquipmentId(), col - 1, dil - 1, ch), - charge)); + mDigits.push_back(Digit(mHeBCDI, mHeORBIT, (float)charge, eq->getEquipmentId(), col, dil, ch)); return; } - From 7fbc7f219046ea3f6f99ff85116a7905b2d6a6f9 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 21 Jan 2021 11:07:17 +0100 Subject: [PATCH 098/208] Add out_stream operator to DIgit --- Detectors/HMPID/base/include/HMPIDBase/Digit.h | 18 ++++++++++++------ .../HMPID/workflow/src/DumpDigitsSpec.cxx | 8 +++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 35933e26da868..c8a225b3443a3 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -43,12 +43,18 @@ class Digit static void Pad2Photo(uint32_t pad, int *chamber, int *photo, int *x, int *y); // Operators definition ! - inline bool operator<(const Digit& l, const Digit& r) { return l.mPad < r.mPad; }; - inline bool operator==(const Digit& l, const Digit& r) { return l.mPad == r.mPad; }; - inline bool operator> (const Digit& l, const Digit& r){ return r < l; }; - inline bool operator<=(const Digit& l, const Digit& r){ return !(l > r); }; - inline bool operator>=(const Digit& l, const Digit& r){ return !(l < r); }; - inline bool operator!=(const Digit& l, const Digit& r) { return !(l == r); }; + friend inline bool operator<(const Digit& l, const Digit& r) { return l.mPad < r.mPad; }; + friend inline bool operator==(const Digit& l, const Digit& r) { return l.mPad == r.mPad; }; + friend inline bool operator> (const Digit& l, const Digit& r){ return r < l; }; + friend inline bool operator<=(const Digit& l, const Digit& r){ return !(l > r); }; + friend inline bool operator>=(const Digit& l, const Digit& r){ return !(l < r); }; + friend inline bool operator!=(const Digit& l, const Digit& r) { return !(l == r); }; + + friend std::ostream& operator<< (std::ostream& os, const Digit& d) { + os << "[" << A2C(d.mPad) << "," << A2P(d.mPad) << "," << A2X(d.mPad) << "," << + A2Y(d.mPad) << "}@(" << d.mOrbit << "," << d.mBc << ")=" << d.mQ; + return os; + }; public: Digit() = default; diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 1f75f3291b50b..70dfe133428b6 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -71,13 +71,11 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) return; } std::vector*theDigits = (std::vector*)input.payload; - + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; for(o2::hmpid::Digit Dig : *theDigits) { - std::cout << Dig.getOrbit() << "," << Dig.getBC() << "," << Dig.getPadID() << - " (" << Dig.getCh() << "," << Dig.getPhC() << "," << Dig.getPx() << "," << Dig.getPy() << ") =" << - Dig.getCharge() << std::endl; + std::cout << Dig << std::endl; } - + std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } } From 49ca9b5a787b741df5eea0e0a635266e248b4be5 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sun, 24 Jan 2021 23:44:23 +0100 Subject: [PATCH 099/208] change spec --- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 49 +++++++++++++++++++ .../HMPID/workflow/src/DataDecoderSpec.cxx | 7 +-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 48b6bed60fdd2..85e94dad97dfb 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -17,6 +17,55 @@ namespace o2 { namespace hmpid { + +/* ------------------ HMPID Detector Coordinate definition ------------------- + + 143 .-------------. .-------------. 0 ------.------ 23 + | | |.-----.-----.| | | --> | + | | || | || | | 0 9 | + | | || 4 | 5 || | | Dil. | + ^ | | || | || | | | | ^ + | | | ||_____|_____|| | | | | | + | | | |.-----.-----.| | | | | | + Y | | || | || | | | + | | | || 2 | 3 || Column | n | n+1 | Column + | | | || | || | | | + | | ||_____|_____|| | | | | | + | | 47 ^ |.-----.-----.| | | | | | + | | | || | || V | | | | + | | Y || 0 | 1 || | Dil. | | + | | | || | || | 9 0 | | + | | 0 ||_____|_____|| | <-- | | + 0 .-------------. ------------- 23 ------.------ 0 + 0 --X--> 159 0 -X->79 + + Pad(Module,x,y) Pad(Chamber,PhotoCat,x,y) Pad(Equipment,Column,Dilogic,Channel) + + Equipment n Equipment n+1 + + 143 + ^ + | 40 32 24 16 08 00 07 15 23 31 39 47 + | 41 33 25 17 09 01 06 14 22 30 38 46 + 42 34 26 18 10 02 05 13 21 29 37 45 + y 43 35 27 19 11 03 04 12 20 28 36 44 (Column,Dil.) + 44 36 28 20 12 04 03 11 19 27 35 43 + | 45 37 29 21 13 05 02 10 18 26 34 42 + | 46 38 30 22 14 06 01 09 17 25 33 41 + 47 39 31 23 15 07 00 08 16 24 32 40 + 0 + + + 0 --------- x ------> 79 80 ------ x -----------> 159 + + For Equipment n : x = 79 - (Dilo * 8 + Chan / 8) + y = 143 - (Column * 6 + Chan % 6) + + For Equipment n+1 : x = 80 + (Dilo * 8 + Chan / 8) + y = Column * 6 + Chan % 6 + + + --------------------------------------------------------------------------- */ /// \class Geo /// \brief HMPID detector geometry (only statics) class Geo diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 9164ed0fe5f71..ce10af1fd03ab 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -197,9 +197,10 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); - inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); - inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); + inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); +// inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); +// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); +// inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); From 5d7808baa92009db47a42a24a723d5cb5669d7a9 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 09:27:03 +0100 Subject: [PATCH 100/208] StfBuilder ... II attempt --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index ce10af1fd03ab..f25ae02021b3e 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -144,7 +144,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) // get the input buffer auto& inputs = pc.inputs(); - DPLRawParser parser(inputs, o2::framework::select("TF:HMP/rawdata")); + DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); @@ -161,7 +161,8 @@ void DataDecoderTask::decodeReadout(framework::ProcessingContext& pc) // get the input buffer auto& inputs = pc.inputs(); - DPLRawParser parser(inputs, o2::framework::select("HMP/readout")); + DPLRawParser parser(inputs, o2::framework::select("readout:HMP/RAWDATA")); +// DPLRawParser parser(inputs, o2::framework::select("HMP/readout")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); @@ -197,9 +198,10 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + inputs.emplace_back("TF", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); + inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); std::vector outputs; From b84ed9d1737d29189804cc9bbe37a8d88f5f794e Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 10:05:15 +0100 Subject: [PATCH 101/208] 1 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index f25ae02021b3e..ce652769b260c 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -70,8 +70,8 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) mDeco->mDigits.clear(); decodeTF(pc); - decodeReadout(pc); - decodeRawFile(pc); +// decodeReadout(pc); +// decodeRawFile(pc); LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; From ca24daa5963ace668dff77acaff4e72a36b7f40a Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 10:15:55 +0100 Subject: [PATCH 102/208] 2 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 70dfe133428b6..6a129765e206f 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -91,7 +91,7 @@ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("DIGITS", o2::header::gDataOriginHMP, "DIGITS_VECT", 0, Lifetime::Timeframe); + inputs.emplace_back("DIGITS", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); std::vector outputs; From 0be9c02a1611c5e699540b1a9e545e9c6e7f7138 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 10:54:08 +0100 Subject: [PATCH 103/208] 3 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index ce652769b260c..1213226455d63 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -58,8 +58,10 @@ using RDH = o2::header::RDHAny; // Data decoder void DataDecoderTask::init(framework::InitContext& ic) { - mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); - mDeco->init(); + + LOG(INFO) << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !"; + mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); + mDeco->init(); return; From 81e689e6a4e21adc71ee07715d93556a4b0d2c60 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 10:59:20 +0100 Subject: [PATCH 104/208] 4 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 1213226455d63..dcf2974115cbc 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -60,6 +60,8 @@ void DataDecoderTask::init(framework::InitContext& ic) { LOG(INFO) << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !"; + std::cout << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !" << std::endl; + mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); mDeco->init(); @@ -77,6 +79,8 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; + std::cout << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..." << std::endl; + pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); @@ -142,6 +146,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) { LOG(INFO) << "*********** In decodeTF **************"; + std::cout << "*********** In decodeTF **************" << std::endl; // get the input buffer @@ -152,6 +157,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) uint32_t *theBuffer = (uint32_t *)it.raw(); mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); + std::cout << "." ; } return; } From 0f62621b9092e4f1a8ee8d0781d6d2735e93faa5 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 11:40:47 +0100 Subject: [PATCH 105/208] 5 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index dcf2974115cbc..7745764168826 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -209,7 +209,7 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) inputs.emplace_back("TF", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); - inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); +// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); std::vector outputs; From 65149bb11ad306d08ebf0763ea46aed5aef165ad Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 12:02:28 +0100 Subject: [PATCH 106/208] 6 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 7745764168826..f21e17a8388ef 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -206,7 +206,10 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("TF", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); +// inputs.emplace_back("TF", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + + inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); + // inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); From 7fc9f34e02332fecd676eb46fa560c9c63264a65 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 12:34:11 +0100 Subject: [PATCH 107/208] Fix the Equipment decodinf from FEE-ID field --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 1966abc517308..10819367ea2c4 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -395,7 +395,7 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) *EquipIndex = getEquipmentIndex(mHeCruID, mHeLinkNum); // mEquipment = (*EquipIndex != -1) ? mTheEquipments[*EquipIndex]->getEquipmentId() : -1; - mEquipment = mHeFEEID; + mEquipment = mHeFEEID & 0x000F; mNumberWordToRead = ((mHeMemorySize - mHeSize) / sizeof(uint32_t)); mPayloadTail = ((mHeOffsetNewPack - mHeMemorySize) / sizeof(uint32_t)); From 01d9982252cd8ebf7145b83f8eb402d41dc3e053 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 12:40:42 +0100 Subject: [PATCH 108/208] 1 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 10819367ea2c4..f810378a2c85a 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -408,7 +408,7 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT; LOG(INFO) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR; - LOG(INFO) << " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; + LOG(INFO) << " EquIdx = "<<*EquipIndex<< " Event = "<< mHeEvent<< " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; if (*EquipIndex == -1) { LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; From 7bc4d398ddc98a24a9ebdc7493e9c782eb619300 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 12:55:53 +0100 Subject: [PATCH 109/208] 2 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 10 +++++----- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index f810378a2c85a..c95599e66d838 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -780,14 +780,14 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) } catch (int e) { // The stream end ! - LOG(DEBUG) << "End Fast Page decoding loop !"; + LOG(INFO) << "End Fast Page decoding loop !"; throw TH_BUFFEREMPTY; } try { decodeHeader(*streamBuf, &equipmentIndex); } catch (int e) { - LOG(ERROR) << "Failed to decode the Header !"; + LOG(INFO) << "Failed to decode the Header !"; throw TH_WRONGHEADER; } @@ -806,7 +806,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) break; } if (wp == wpprev) { - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + LOG(INFO) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ "[" << Column << "]"; } else { if( isPadWord(wp, &error, &Column, &Dilogic, &Channel, &Charge) == true) { @@ -837,7 +837,7 @@ bool HmpidDecoder::decodeBufferFast() } uint32_t *streamBuf; - LOG(DEBUG) << "Enter FAST decoding !"; + LOG(INFO) << "Enter FAST decoding !"; // Input Stream Main Loop while (true) { @@ -845,7 +845,7 @@ bool HmpidDecoder::decodeBufferFast() decodePageFast(&streamBuf); } catch(int e) { - LOG(DEBUG) << " End Buffer Fast Decoding !"; + LOG(INFO) << " End Buffer Fast Decoding !"; break; } } // this is the end of stream diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index f21e17a8388ef..1bf2ee4fcff0a 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -146,7 +146,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) { LOG(INFO) << "*********** In decodeTF **************"; - std::cout << "*********** In decodeTF **************" << std::endl; + // std::cout << "*********** In decodeTF **************" << std::endl; // get the input buffer @@ -157,7 +157,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) uint32_t *theBuffer = (uint32_t *)it.raw(); mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); - std::cout << "." ; + std::cout << "Decode parser loop ..." ; } return; } From 6f83582f4f43f842edc7e895585f695e4f007d6b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 13:03:54 +0100 Subject: [PATCH 110/208] 4 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index c95599e66d838..859ade5a913b7 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -414,6 +414,7 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; throw TH_WRONGEQUIPINDEX; } + std::cout << "HMPID ! Exit decode header" << std::endl; return (true); } From 45277298ff0751bcfe817c412f992ee1605f0b1c Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 13:09:16 +0100 Subject: [PATCH 111/208] 6 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 859ade5a913b7..0bf9740ec5e94 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -444,6 +444,7 @@ void HmpidDecoder::updateStatistics(HmpidEquipment *eq) /// @returns the Pointer to the modified Equipment object HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) { + std::cout << "Enter evaluateHeaderContents.."; HmpidEquipment *eq = mTheEquipments[EquipmentIndex]; if (mHeEvent != eq->mEventNumber) { // Is a new event if (eq->mEventNumber != -1) { // skip the first @@ -458,10 +459,11 @@ HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) } eq->mEventSize += mNumberWordToRead * sizeof(uint32_t); // Calculate the size in bytes if (mHeHmpidError != 0) { - LOG(ERROR) << "HMPID Header reports an error : " << mHeHmpidError; + LOG(INFO) << "HMPID Header reports an error : " << mHeHmpidError; dumpHmpidError(mHeHmpidError); eq->setError(ERR_HMPID); } + std::cout << ".. end evaluateHeaderContents = " << eq->mEventNumber << std::endl; return (eq); } From 4e30952847ae01abbd025eb2a7940be65bfd65c4 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 13:15:22 +0100 Subject: [PATCH 112/208] 7 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 5acef2e4d4799..aecc8a512cdf5 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -96,8 +96,10 @@ bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) { *streamPtr = mActualStreamPtr; mActualStreamPtr += Size; - if (mActualStreamPtr > mEndStreamPtr) + if (mActualStreamPtr > mEndStreamPtr) { + std::cout << "Beccato " << std::cout; throw TH_WRONGBUFFERDIM; + } return (true); } From 867e77d827d44e0ff187082915b9a06fb7363ded Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 14:41:20 +0100 Subject: [PATCH 113/208] 7 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index aecc8a512cdf5..da57649d4b0fd 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -97,7 +97,7 @@ bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) *streamPtr = mActualStreamPtr; mActualStreamPtr += Size; if (mActualStreamPtr > mEndStreamPtr) { - std::cout << "Beccato " << std::cout; + std::cout << "Beccato " << std::endl; throw TH_WRONGBUFFERDIM; } return (true); From 4037b38c946669c0914965c085714bd57b9de955 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 14:48:05 +0100 Subject: [PATCH 114/208] 8 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 1bf2ee4fcff0a..279f3c1b3eb2a 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -155,9 +155,10 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); + std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset(); mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); - std::cout << "Decode parser loop ..." ; + } return; } From 21e469a4f3aa69fab6a595f0423c41c6f413fcea Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 14:58:39 +0100 Subject: [PATCH 115/208] 8 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 2 +- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index da57649d4b0fd..ce415ed110e7c 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -83,7 +83,7 @@ bool HmpidDecodeRawMem::setUpStream(void *Buffer, long BufferLen) mActualStreamPtr = (uint32_t*) Buffer; // sets the pointer to the Buffer mEndStreamPtr = ((uint32_t*) Buffer) + wordsBufferLen; //sets the End of buffer mStartStreamPtr = ((uint32_t*) Buffer); - + std::cout << " setUpStrem : StPtr=" << mStartStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << wordsBufferLen << std::endl; return (true); } diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 279f3c1b3eb2a..359dc6f308cb4 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -155,7 +155,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); - std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset(); + std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); From 3acfa61f74c145efa01a828c073eb940e640eee8 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:05:20 +0100 Subject: [PATCH 116/208] 9 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index ce415ed110e7c..c7ac6931bc819 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -97,6 +97,7 @@ bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) *streamPtr = mActualStreamPtr; mActualStreamPtr += Size; if (mActualStreamPtr > mEndStreamPtr) { + std::cout << " getBlockFromStream : StPtr=" << mActualStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << Size << std::endl; std::cout << "Beccato " << std::endl; throw TH_WRONGBUFFERDIM; } From db761d2dedfabf8515bde885f113fbedcedb371b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:12:32 +0100 Subject: [PATCH 117/208] 12 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index c7ac6931bc819..5bdef8f897cc5 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -96,10 +96,12 @@ bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) { *streamPtr = mActualStreamPtr; mActualStreamPtr += Size; + std::cout << "."; if (mActualStreamPtr > mEndStreamPtr) { - std::cout << " getBlockFromStream : StPtr=" << mActualStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << Size << std::endl; - std::cout << "Beccato " << std::endl; - throw TH_WRONGBUFFERDIM; +// std::cout << " getBlockFromStream : StPtr=" << mActualStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << Size << std::endl; +// std::cout << "Beccato " << std::endl; +// throw TH_WRONGBUFFERDIM; + return(false); } return (true); } From 846a8198dab406715bfb76bae371e79a4ce307ae Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:20:35 +0100 Subject: [PATCH 118/208] fix --- .../HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 3 +-- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 12 ++++++------ Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 5bdef8f897cc5..0627b8fe4b144 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -83,7 +83,7 @@ bool HmpidDecodeRawMem::setUpStream(void *Buffer, long BufferLen) mActualStreamPtr = (uint32_t*) Buffer; // sets the pointer to the Buffer mEndStreamPtr = ((uint32_t*) Buffer) + wordsBufferLen; //sets the End of buffer mStartStreamPtr = ((uint32_t*) Buffer); - std::cout << " setUpStrem : StPtr=" << mStartStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << wordsBufferLen << std::endl; +// std::cout << " setUpStrem : StPtr=" << mStartStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << wordsBufferLen << std::endl; return (true); } @@ -96,7 +96,6 @@ bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) { *streamPtr = mActualStreamPtr; mActualStreamPtr += Size; - std::cout << "."; if (mActualStreamPtr > mEndStreamPtr) { // std::cout << " getBlockFromStream : StPtr=" << mActualStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << Size << std::endl; // std::cout << "Beccato " << std::endl; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 0bf9740ec5e94..15106c48509f5 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -402,11 +402,11 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) // ---- Event ID : Actualy based on ORBIT NUMBER and BC mHeEvent = (mHeORBIT<<12) | mHeBCDI; - LOG(INFO) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID <<\ + LOG(DEBUG) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID <<\ " HeMemorySize=" << mHeMemorySize << " HeOffsetNewPack=" << mHeOffsetNewPack; - LOG(INFO) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << \ + LOG(DEBUG) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << \ mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT; - LOG(INFO) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ + LOG(DEBUG) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR; LOG(INFO) << " EquIdx = "<<*EquipIndex<< " Event = "<< mHeEvent<< " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; @@ -414,7 +414,7 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; throw TH_WRONGEQUIPINDEX; } - std::cout << "HMPID ! Exit decode header" << std::endl; + // std::cout << "HMPID ! Exit decode header" << std::endl; return (true); } @@ -444,7 +444,7 @@ void HmpidDecoder::updateStatistics(HmpidEquipment *eq) /// @returns the Pointer to the modified Equipment object HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) { - std::cout << "Enter evaluateHeaderContents.."; + //std::cout << "Enter evaluateHeaderContents.."; HmpidEquipment *eq = mTheEquipments[EquipmentIndex]; if (mHeEvent != eq->mEventNumber) { // Is a new event if (eq->mEventNumber != -1) { // skip the first @@ -463,7 +463,7 @@ HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) dumpHmpidError(mHeHmpidError); eq->setError(ERR_HMPID); } - std::cout << ".. end evaluateHeaderContents = " << eq->mEventNumber << std::endl; + // std::cout << ".. end evaluateHeaderContents = " << eq->mEventNumber << std::endl; return (eq); } diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 359dc6f308cb4..b10a1e3ec180d 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -155,7 +155,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { uint32_t *theBuffer = (uint32_t *)it.raw(); - std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; + // std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); From 36cee85487eb445fca4d8fbe93598b2196625bb3 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:28:53 +0100 Subject: [PATCH 119/208] 1 --- Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 0627b8fe4b144..1d111ebe07a36 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -184,6 +184,7 @@ void HmpidDecodeRawDigit::setPad(HmpidEquipment *eq, int col, int dil, int ch, i { eq->setPad(col, dil, ch, charge); mDigits.push_back(Digit(mHeBCDI, mHeORBIT, (float)charge, eq->getEquipmentId(), col, dil, ch)); + std::cout << "."; return; } From 6bb0934ed7b91c0aeb5b27239a1237a254ba6503 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:36:22 +0100 Subject: [PATCH 120/208] 2 --- .../reconstruction/include/HMPIDReconstruction/HmpidDecoder.h | 1 - Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index a1935caae561d..2cc9b3ff40af9 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -156,7 +156,6 @@ class HmpidDecoder void updateStatistics(HmpidEquipment *eq); protected: virtual void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) = 0; - virtual bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size) = 0; virtual bool getHeaderFromStream(uint32_t **streamPtr) = 0; virtual bool getWordFromStream(uint32_t *word) = 0; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 1d111ebe07a36..45f89ecc43d5f 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -135,6 +135,7 @@ bool HmpidDecodeRawMem::getWordFromStream(uint32_t *word) void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) { eq->setPad(col, dil, ch, charge); + std::cout << ":"; return; } From dbc53b9129e4c06622c9add23a2adc3763c7ab3b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:43:33 +0100 Subject: [PATCH 121/208] 2 --- .../include/HMPIDReconstruction/HmpidDecoder.h | 2 +- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index 2cc9b3ff40af9..96d59a209d0e4 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -150,7 +150,7 @@ class HmpidDecoder public: bool decodeHmpidError(int ErrorField, char *outbuf); void dumpHmpidError(int ErrorField); - bool isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge); + bool isPadWord(uint32_t wp, bool *Err, int *Col, int *Dilogic, int *Channel, int *Charge); int decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex); HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); void updateStatistics(HmpidEquipment *eq); diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 15106c48509f5..e49142598a43e 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -269,7 +269,7 @@ bool HmpidDecoder::isSegmentMarker(uint32_t wp, int *Err, int *segSize, int *Seg /// @param[out] *Channel : the channel number [0..47] /// @param[out] *Charge : the value of Charge [0..4095] /// @returns True if PAD Word is detected -bool HmpidDecoder::isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge) +bool HmpidDecoder::isPadWord(uint32_t wp, bool *Err, int *Col, int *Dilogic, int *Channel, int *Charge) { *Err = false; if ((wp & 0x08000000) == 0) { // # this is a pad @@ -800,7 +800,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) uint32_t wp = 0; int newOne = true; int Column, Dilogic, Channel, Charge; - int error; + bool pwer; int payIndex = 0; while (payIndex < mNumberWordToRead) { //start the payload loop word by word @@ -812,8 +812,8 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) LOG(INFO) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ "[" << Column << "]"; } else { - if( isPadWord(wp, &error, &Column, &Dilogic, &Channel, &Charge) == true) { - if( error != false) { + if( isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { + if( pwer != false) { setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); eq->mSampleNumber++; } From a5e2ddce678b62b380057a4fa6877856fc0ec555 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:50:32 +0100 Subject: [PATCH 122/208] 3 --- .../reconstruction/include/HMPIDReconstruction/HmpidDecoder.h | 2 +- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index 96d59a209d0e4..2cc9b3ff40af9 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -150,7 +150,7 @@ class HmpidDecoder public: bool decodeHmpidError(int ErrorField, char *outbuf); void dumpHmpidError(int ErrorField); - bool isPadWord(uint32_t wp, bool *Err, int *Col, int *Dilogic, int *Channel, int *Charge); + bool isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge); int decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex); HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); void updateStatistics(HmpidEquipment *eq); diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index e49142598a43e..8c139be9b9aec 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -269,7 +269,7 @@ bool HmpidDecoder::isSegmentMarker(uint32_t wp, int *Err, int *segSize, int *Seg /// @param[out] *Channel : the channel number [0..47] /// @param[out] *Charge : the value of Charge [0..4095] /// @returns True if PAD Word is detected -bool HmpidDecoder::isPadWord(uint32_t wp, bool *Err, int *Col, int *Dilogic, int *Channel, int *Charge) +bool HmpidDecoder::isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge) { *Err = false; if ((wp & 0x08000000) == 0) { // # this is a pad From 19545dcf8c0e87ea794c4fbd4db609555d3b2005 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:52:18 +0100 Subject: [PATCH 123/208] 3 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 8c139be9b9aec..5b31d1e7558a9 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -800,7 +800,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) uint32_t wp = 0; int newOne = true; int Column, Dilogic, Channel, Charge; - bool pwer; + int pwer; int payIndex = 0; while (payIndex < mNumberWordToRead) { //start the payload loop word by word From 06b407538d46b3f1b774dd6eb88afdca9d80cc3f Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 15:57:10 +0100 Subject: [PATCH 124/208] 4 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 5b31d1e7558a9..8b421796943a4 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -813,6 +813,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) "[" << Column << "]"; } else { if( isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { + std::cout << "."; if( pwer != false) { setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); eq->mSampleNumber++; From 97d70eded129e3f7f583b504e073c4965ba67245 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:02:23 +0100 Subject: [PATCH 125/208] 1 --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 8b421796943a4..05748f7ee3ef3 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -813,8 +813,8 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) "[" << Column << "]"; } else { if( isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { - std::cout << "."; if( pwer != false) { + std::cout << "."; setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); eq->mSampleNumber++; } From e3ac5cf3a2a325189851ef7bcafbdedfed6cab84 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:06:11 +0100 Subject: [PATCH 126/208] fix --- Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 05748f7ee3ef3..788f3732af1e2 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -813,8 +813,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) "[" << Column << "]"; } else { if( isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { - if( pwer != false) { - std::cout << "."; + if( pwer != true) { setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); eq->mSampleNumber++; } From 0df32159ece59f94fc100be138f819f7afe774cd Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:28:06 +0100 Subject: [PATCH 127/208] try to recover TTree --- .../reconstruction/src/HmpidDecodeRawMem.cxx | 2 -- .../HMPID/workflow/src/DataDecoderSpec.cxx | 27 +++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 45f89ecc43d5f..0627b8fe4b144 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -135,7 +135,6 @@ bool HmpidDecodeRawMem::getWordFromStream(uint32_t *word) void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) { eq->setPad(col, dil, ch, charge); - std::cout << ":"; return; } @@ -185,7 +184,6 @@ void HmpidDecodeRawDigit::setPad(HmpidEquipment *eq, int col, int dil, int ch, i { eq->setPad(col, dil, ch, charge); mDigits.push_back(Digit(mHeBCDI, mHeORBIT, (float)charge, eq->getEquipmentId(), col, dil, ch)); - std::cout << "."; return; } diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index b10a1e3ec180d..245f9c33f37ba 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -91,13 +91,19 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - TTree theObj("t", "HMPID Data Decoding Statistic results"); + TString filename = TString::Format("%s_%06d.root", "test", 1); + LOG(DEBUG) << "opening file " << filename.Data(); + std::unique_ptr mfileOut = nullptr; + mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); - theObj.Branch("Average_Event_Size", avgEventSize,"f[14]"); - theObj.Branch("Average_Busy_Time", avgBusyTime,"f[14]"); - theObj.Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); - theObj.Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); - theObj.Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); + std::unique_ptr theObj; + theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); + + theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); + theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); + theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); + theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); + theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); int numEqui = mDeco->getNumberOfEquipments(); @@ -112,8 +118,13 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) sumOfCharges[m][y][x] = mDeco->getPadSum(m, y, x); squareOfCharges[m][y][x] = mDeco->getPadSquares(m, y, x); } - theObj.Fill(); - //t.Write(); + theObj->Fill(); + + mfileOut->cd(); + theObj->Write(); + theObj.reset(); + mfileOut.reset(); + // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSquare(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); From bd018fea6d4e1f735610bd07a2d22b75de718608 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:30:20 +0100 Subject: [PATCH 128/208] 1 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 245f9c33f37ba..d967c64cff5a2 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -125,6 +125,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) theObj.reset(); mfileOut.reset(); + // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSquare(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); From 08063c93ff8ec8ec54d74ddf550273c4d4c0938f Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:48:21 +0100 Subject: [PATCH 129/208] 4 --- .../HMPID/workflow/src/DataDecoderSpec.cxx | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index d967c64cff5a2..5ecba9a0a5867 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -25,6 +25,7 @@ #include #include "TTree.h" +#include #include "Framework/CallbackService.h" #include "Framework/ConfigParamRegistry.h" @@ -65,8 +66,7 @@ void DataDecoderTask::init(framework::InitContext& ic) mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); mDeco->init(); - - return; + return; } void DataDecoderTask::run(framework::ProcessingContext& pc) @@ -91,10 +91,10 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - TString filename = TString::Format("%s_%06d.root", "test", 1); - LOG(DEBUG) << "opening file " << filename.Data(); - std::unique_ptr mfileOut = nullptr; - mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); + // TString filename = TString::Format("%s_%06d.root", "test", 1); + // LOG(DEBUG) << "opening file " << filename.Data(); + // std::unique_ptr mfileOut = nullptr; + // mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); std::unique_ptr theObj; theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); @@ -120,10 +120,10 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) } theObj->Fill(); - mfileOut->cd(); - theObj->Write(); - theObj.reset(); - mfileOut.reset(); +// mfileOut->cd(); +// theObj->Write(); +// theObj.reset(); +// mfileOut.reset(); // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); @@ -131,6 +131,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, theObj); + theObj.reset(); } /* auto& digits = mDecoder->getOutputDigits(); From 71f06dd0f005a54ec09afa26c0daaf61f27ec7fa Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 16:52:29 +0100 Subject: [PATCH 130/208] 4 --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 5ecba9a0a5867..6def0bb9fb450 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -129,7 +129,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSquare(Equipment, Column, Dilogic, Channel); // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); - pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, theObj); + pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); theObj.reset(); } From 4003d73a7bbd4b0f19bb2310f7823bb83282bd90 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:06:33 +0100 Subject: [PATCH 131/208] 3 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 6a129765e206f..39ea4a8964617 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -64,6 +64,9 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; +// auto digits = pc.inputs().get("digits"); +// mPDigits = &digits; + for (auto&& input : pc.inputs()) { if (input.spec->binding == "DIGITS") { const auto* header = o2::header::get(input.header); @@ -91,13 +94,13 @@ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) { std::vector inputs; - inputs.emplace_back("DIGITS", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); + inputs.emplace_back("digits", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); std::vector outputs; return DataProcessorSpec{ - "HMP-DataDecoder", + "HMP-DigitsDump", inputs, outputs, AlgorithmSpec{adaptFromTask()}, From d9e9467983ec30df8f268a322ac62155bff5c11a Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:11:17 +0100 Subject: [PATCH 132/208] 5 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 39ea4a8964617..553dc67d8b1ca 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -68,7 +68,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) // mPDigits = &digits; for (auto&& input : pc.inputs()) { - if (input.spec->binding == "DIGITS") { + if (input.spec->binding == "digits") { const auto* header = o2::header::get(input.header); if (!header) { return; From 2c93f68f88de03a6275b90f1795b41cde8e81573 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:12:03 +0100 Subject: [PATCH 133/208] 5 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 553dc67d8b1ca..096d9789101c8 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -68,6 +68,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) // mPDigits = &digits; for (auto&& input : pc.inputs()) { + std::cout << input.spec->binding << std::endl; if (input.spec->binding == "digits") { const auto* header = o2::header::get(input.header); if (!header) { From 1d5f088a0d7987392274983f203cceb5bb372044 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:21:01 +0100 Subject: [PATCH 134/208] 1 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 096d9789101c8..41cfec18e50da 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -76,7 +76,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) } std::vector*theDigits = (std::vector*)input.payload; std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - for(o2::hmpid::Digit Dig : *theDigits) { + for(o2::hmpid::Digit Dig : theDigits) { std::cout << Dig << std::endl; } std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; From 3db7b1783bd2b33caaf11806ffca6a09baa33471 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:30:27 +0100 Subject: [PATCH 135/208] 5 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 41cfec18e50da..5ed9fd78bd35a 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -76,9 +76,10 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) } std::vector*theDigits = (std::vector*)input.payload; std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - for(o2::hmpid::Digit Dig : theDigits) { - std::cout << Dig << std::endl; - } + std::cout << "The size of the vector " << theDigits->size() << std::endl; +// for(o2::hmpid::Digit Dig : *theDigits) { +// std::cout << Dig << std::endl; +// } std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } } From 77320323e7c8bcf0e983cabd749ef8537576017c Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:45:53 +0100 Subject: [PATCH 136/208] 1 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 5ed9fd78bd35a..a208c5e4f4707 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -64,12 +64,16 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; -// auto digits = pc.inputs().get("digits"); -// mPDigits = &digits; + auto digits = pc.inputs().get>("digits"); + const std::vector* mPDigits = &digits; + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + std::cout << "The size of the vector " << mPDigits->size() << std::endl; +/* for (auto&& input : pc.inputs()) { std::cout << input.spec->binding << std::endl; if (input.spec->binding == "digits") { + const auto* header = o2::header::get(input.header); if (!header) { return; @@ -80,6 +84,8 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) // for(o2::hmpid::Digit Dig : *theDigits) { // std::cout << Dig << std::endl; // } + + */ std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } } From 05c4b361a9227095a0c7c88726abd1a3f3ce0aea Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:48:06 +0100 Subject: [PATCH 137/208] 2 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index a208c5e4f4707..d35e8c4654416 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -85,9 +85,10 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) // std::cout << Dig << std::endl; // } - */ + std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } + */ } From 1559cbd5b9d46c437c014829289a308aa7dd202a Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:49:38 +0100 Subject: [PATCH 138/208] 2 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index d35e8c4654416..8527ecc94907c 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -88,11 +88,11 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } - */ - } + } + */ } From 4705f4720b92d561d83dc7b746ee93cd368f3dd2 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 17:59:04 +0100 Subject: [PATCH 139/208] 2 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 8527ecc94907c..a93ede6616284 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -65,9 +65,9 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; auto digits = pc.inputs().get>("digits"); - const std::vector* mPDigits = &digits; +// const std::vector* mPDigits = &digits; std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - std::cout << "The size of the vector " << mPDigits->size() << std::endl; + std::cout << "The size of the vector " << digits.size() << std::endl; /* for (auto&& input : pc.inputs()) { From 678b30bf735f4e439734f720385f5b3d489203bd Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:01:19 +0100 Subject: [PATCH 140/208] 3 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index a93ede6616284..669eb6fde2450 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -63,7 +63,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) { LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; - +return; auto digits = pc.inputs().get>("digits"); // const std::vector* mPDigits = &digits; std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; From 77ef50649e5974b629b6f344c508440f6291dc7f Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:03:21 +0100 Subject: [PATCH 141/208] 1 --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 669eb6fde2450..2bad129b63a75 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -63,13 +63,13 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) { LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; -return; - auto digits = pc.inputs().get>("digits"); + +// auto digits = pc.inputs().get>("digits"); // const std::vector* mPDigits = &digits; - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - std::cout << "The size of the vector " << digits.size() << std::endl; +// std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; +// std::cout << "The size of the vector " << digits.size() << std::endl; + -/* for (auto&& input : pc.inputs()) { std::cout << input.spec->binding << std::endl; if (input.spec->binding == "digits") { @@ -88,13 +88,7 @@ return; std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } - } - - - */ - - } //_________________________________________________________________________________________________ From bdfa6469cd9d56bd54a6edf0907c40bcfd224348 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:16:12 +0100 Subject: [PATCH 142/208] XX --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 2bad129b63a75..929188f5688e3 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -64,12 +64,12 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; -// auto digits = pc.inputs().get>("digits"); + auto digits = pc.inputs().get>("digits"); // const std::vector* mPDigits = &digits; -// std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; -// std::cout << "The size of the vector " << digits.size() << std::endl; - + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + std::cout << "The size of the vector " << digits.size() << std::endl; +/* for (auto&& input : pc.inputs()) { std::cout << input.spec->binding << std::endl; if (input.spec->binding == "digits") { @@ -89,6 +89,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; } } + */ } //_________________________________________________________________________________________________ From 212efb677f2a5ddc6b24acd192b95a9931ded910 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:19:30 +0100 Subject: [PATCH 143/208] Work --- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 929188f5688e3..285ec405bf6be 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -65,31 +65,13 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; auto digits = pc.inputs().get>("digits"); -// const std::vector* mPDigits = &digits; std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; std::cout << "The size of the vector " << digits.size() << std::endl; - -/* - for (auto&& input : pc.inputs()) { - std::cout << input.spec->binding << std::endl; - if (input.spec->binding == "digits") { - - const auto* header = o2::header::get(input.header); - if (!header) { - return; - } - std::vector*theDigits = (std::vector*)input.payload; - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - std::cout << "The size of the vector " << theDigits->size() << std::endl; -// for(o2::hmpid::Digit Dig : *theDigits) { -// std::cout << Dig << std::endl; -// } - - - std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; - } + for(o2::hmpid::Digit Dig : digits) { + std::cout << Dig << std::endl; } - */ + std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; + } //_________________________________________________________________________________________________ From ff22e9a496128a55c9dbdc9d5f4cf92616550cd3 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:26:40 +0100 Subject: [PATCH 144/208] Out Digit per Page --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 6def0bb9fb450..f257191c11659 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -71,7 +71,7 @@ void DataDecoderTask::init(framework::InitContext& ic) void DataDecoderTask::run(framework::ProcessingContext& pc) { - mDeco->mDigits.clear(); +//---- mDeco->mDigits.clear(); decodeTF(pc); // decodeReadout(pc); @@ -79,9 +79,8 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; - std::cout << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..." << std::endl; - pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); +//----- pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; @@ -167,11 +166,15 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { + mDeco->mDigits.clear(); + uint32_t *theBuffer = (uint32_t *)it.raw(); // std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); + pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + } return; } From 08c32fa536634cf35da164ceeafec7ae60e1c69c Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:34:03 +0100 Subject: [PATCH 145/208] try --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index f257191c11659..d00cdba148689 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -173,7 +173,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); - pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + pc.outputs().adoptChunk(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); } return; From d6f30b4db3658d2d32692475e065dcd67f26f574 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 25 Jan 2021 18:35:57 +0100 Subject: [PATCH 146/208] This version works, but react to the first chumk ! --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index d00cdba148689..f257191c11659 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -173,7 +173,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); - pc.outputs().adoptChunk(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); } return; From c24417aec0132be4cf0daa3dba184528ecc54ba1 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 01:10:14 +0100 Subject: [PATCH 147/208] New output skema --- .../include/HMPIDWorkflow/DataDecoderSpec.h | 1 + .../include/HMPIDWorkflow/DumpDigitsSpec.h | 1 + .../HMPID/workflow/src/DataDecoderSpec.cxx | 58 +++++++++---------- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 17 +++--- 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index 4d09f3ae4b186..3e984862e56db 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -38,6 +38,7 @@ namespace hmpid void decodeTF(framework::ProcessingContext& pc); void decodeReadout(framework::ProcessingContext& pc); void decodeRawFile(framework::ProcessingContext& pc); + void endOfStream(framework::EndOfStreamContext& ec); private: HmpidDecodeRawDigit *mDeco; diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index 12ff4633986d6..7255d3d2bbcde 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -33,6 +33,7 @@ namespace hmpid ~DumpDigitsTask() override = default; void init(framework::InitContext& ic) final; void run(framework::ProcessingContext& pc) final; + void endOfStream(framework::EndOfStreamContext& ec) final; private: diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index f257191c11659..d273ce44f38c5 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -77,11 +77,29 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // decodeReadout(pc); // decodeRawFile(pc); +} - LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; +/* auto& digits = mDecoder->getOutputDigits(); + auto& orbits = mDecoder->getOrbits(); -//----- pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + if (mPrint) { + for (auto d : digits) { + std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; + } + } + // send the output buffer via DPL + size_t digitsSize, orbitsSize; + char* digitsBuffer = createBuffer(digits, digitsSize); + char* orbitsBuffer = createBuffer(orbits, orbitsSize); + // create the output message + auto freefct = [](void* data, void*) { free(data); }; +// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); +// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); +*/ +void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) +{ + LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; float avgBusyTime[o2::hmpid::Geo::MAXEQUIPMENTS]; @@ -104,7 +122,6 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); - int numEqui = mDeco->getNumberOfEquipments(); for(int e=0;egetAverageEventSize(e); @@ -124,47 +141,25 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // theObj.reset(); // mfileOut.reset(); - - // mDeco->getChannelSamples(Equipment, Column, Dilogic, Channel); - // mDeco->getChannelSquare(Equipment, Column, Dilogic, Channel); - // mDeco->getChannelSum(Equipment, Column, Dilogic, Channel); - pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); + ec.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); theObj.reset(); + return; } -/* auto& digits = mDecoder->getOutputDigits(); - auto& orbits = mDecoder->getOrbits(); - - if (mPrint) { - for (auto d : digits) { - std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; - } - } - // send the output buffer via DPL - size_t digitsSize, orbitsSize; - char* digitsBuffer = createBuffer(digits, digitsSize); - char* orbitsBuffer = createBuffer(orbits, orbitsSize); - - // create the output message - auto freefct = [](void* data, void*) { free(data); }; -// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); -// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); -*/ - //_________________________________________________________________________________________________ // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) { LOG(INFO) << "*********** In decodeTF **************"; - // std::cout << "*********** In decodeTF **************" << std::endl; - // get the input buffer auto& inputs = pc.inputs(); DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); + auto& digitsV = pc.outputs().make>(Output{"HMP", "DIGITS", 0, Lifetime::Timeframe}); + for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { mDeco->mDigits.clear(); @@ -172,12 +167,15 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) // std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); + for(auto d : mDeco->mDigits) + digitsV.push_back(d); - pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + // pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); } return; } +//pc.outputs().make //_________________________________________________________________________________________________ // the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow void DataDecoderTask::decodeReadout(framework::ProcessingContext& pc) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 285ec405bf6be..7d5d6893bc85c 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -55,25 +55,26 @@ using RDH = o2::header::RDHAny; // Data decoder void DumpDigitsTask::init(framework::InitContext& ic) { - - return; + LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + return; } void DumpDigitsTask::run(framework::ProcessingContext& pc) { - - LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; - auto digits = pc.inputs().get>("digits"); - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; std::cout << "The size of the vector " << digits.size() << std::endl; for(o2::hmpid::Digit Dig : digits) { std::cout << Dig << std::endl; } - std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; - + return; } +void DumpDigitsTask::endOfStream(framework::EndOfStreamContext& ec) +{ + std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; + return; +} //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) //o2::framework::DataPrecessorSpec getDecodingSpec() From 79ea8fed89ac74d1639c837337a4b9eeb5dbcb6b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 01:21:05 +0100 Subject: [PATCH 148/208] only size .. --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 7d5d6893bc85c..9d75917f37ced 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -64,9 +64,9 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) { auto digits = pc.inputs().get>("digits"); std::cout << "The size of the vector " << digits.size() << std::endl; - for(o2::hmpid::Digit Dig : digits) { - std::cout << Dig << std::endl; - } +// for(o2::hmpid::Digit Dig : digits) { +// std::cout << Dig << std::endl; +// } return; } From 4e94d28d608fa9e431ef9de9a64789cd8c0939d2 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 10:28:30 +0100 Subject: [PATCH 149/208] try --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index d273ce44f38c5..1a5e89845387d 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -77,6 +77,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // decodeReadout(pc); // decodeRawFile(pc); + pc.services().get().endOfStream(); } /* auto& digits = mDecoder->getOutputDigits(); @@ -225,10 +226,10 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); -// inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA_TF", 0, Lifetime::Timeframe); -// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA_QC", 0, Lifetime::Timeframe); +// inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); -// inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA_FILE", 0, Lifetime::Timeframe); +// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); +// inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); From 827165aa03a99b0365fd3bc95436cf63f9d4a52c Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 11:35:48 +0100 Subject: [PATCH 150/208] W1 --- .../include/HMPIDWorkflow/DataDecoderSpec.h | 2 +- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 4 +- .../HMPID/workflow/src/DataDecoderSpec.cxx | 43 ++++++++----------- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 18 ++++---- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index 3e984862e56db..81c701712f141 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -38,7 +38,7 @@ namespace hmpid void decodeTF(framework::ProcessingContext& pc); void decodeReadout(framework::ProcessingContext& pc); void decodeRawFile(framework::ProcessingContext& pc); - void endOfStream(framework::EndOfStreamContext& ec); + private: HmpidDecodeRawDigit *mDeco; diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index 7255d3d2bbcde..2e5fa69cccbbb 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -33,10 +33,10 @@ namespace hmpid ~DumpDigitsTask() override = default; void init(framework::InitContext& ic) final; void run(framework::ProcessingContext& pc) final; - void endOfStream(framework::EndOfStreamContext& ec) final; - private: + private: + bool mPrintDigits = false; }; o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 1a5e89845387d..17afa50b580e1 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -77,29 +77,6 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // decodeReadout(pc); // decodeRawFile(pc); - pc.services().get().endOfStream(); -} - -/* auto& digits = mDecoder->getOutputDigits(); - auto& orbits = mDecoder->getOrbits(); - - if (mPrint) { - for (auto d : digits) { - std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; - } - } - // send the output buffer via DPL - size_t digitsSize, orbitsSize; - char* digitsBuffer = createBuffer(digits, digitsSize); - char* orbitsBuffer = createBuffer(orbits, orbitsSize); - - // create the output message - auto freefct = [](void* data, void*) { free(data); }; -// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); -// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); -*/ -void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) -{ LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; @@ -145,9 +122,27 @@ void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) ec.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); theObj.reset(); - return; + } +/* auto& digits = mDecoder->getOutputDigits(); + auto& orbits = mDecoder->getOrbits(); + + if (mPrint) { + for (auto d : digits) { + std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; + } + } + // send the output buffer via DPL + size_t digitsSize, orbitsSize; + char* digitsBuffer = createBuffer(digits, digitsSize); + char* orbitsBuffer = createBuffer(orbits, orbitsSize); + + // create the output message + auto freefct = [](void* data, void*) { free(data); }; +// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); +// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); +*/ //_________________________________________________________________________________________________ // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 9d75917f37ced..6c184b2ad2bdd 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -56,6 +56,8 @@ using RDH = o2::header::RDHAny; void DumpDigitsTask::init(framework::InitContext& ic) { LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; + mPrintDigits = ic.options().get("print"); + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; return; } @@ -64,17 +66,15 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) { auto digits = pc.inputs().get>("digits"); std::cout << "The size of the vector " << digits.size() << std::endl; -// for(o2::hmpid::Digit Dig : digits) { -// std::cout << Dig << std::endl; -// } - return; -} - -void DumpDigitsTask::endOfStream(framework::EndOfStreamContext& ec) -{ + if (mPrintDigits) { + for(o2::hmpid::Digit Dig : digits) { + std::cout << Dig << std::endl; + } + } std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; return; } + //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) //o2::framework::DataPrecessorSpec getDecodingSpec() @@ -91,7 +91,7 @@ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) inputs, outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"print", VariantType::Bool, false, {"print digits"}}} }; + Options{{"print", VariantType::Bool, false, {"print digits (default false )"}}} }; } } // namespace hmpid From 9e8e962517dced0a76a6f3ced8d64929e9797b62 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 11:45:26 +0100 Subject: [PATCH 151/208] fix --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 17afa50b580e1..44e05a4e8cbb4 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -119,7 +119,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // theObj.reset(); // mfileOut.reset(); - ec.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); + pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); theObj.reset(); From b67f22c0a43d14767c71621f201bad7daa168d6c Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 11:58:03 +0100 Subject: [PATCH 152/208] fix --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 6c184b2ad2bdd..a0e19829b2372 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -56,7 +56,7 @@ using RDH = o2::header::RDHAny; void DumpDigitsTask::init(framework::InitContext& ic) { LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; - mPrintDigits = ic.options().get("print"); + mPrintDigits = ic.options().get("print"); std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; return; From f4892f2311bb0ca82b31408cee2ea4b9bd734010 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:19:45 +0100 Subject: [PATCH 153/208] first --- .../HMPID/base/include/HMPIDBase/Digit.h | 23 +- Detectors/HMPID/base/src/Digit.cxx | 6 +- .../include/HMPIDSimulation/HmpidCoder.h | 142 ++++++++ Detectors/HMPID/simulation/src/HmpidCoder.cxx | 312 ++++++++++++++++++ .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 47 +++ .../workflow/src/WriteRawFromDigitsSpec.cxx | 116 +++++++ .../src/write-raw-from-digits-workflow.cxx | 43 +++ 7 files changed, 675 insertions(+), 14 deletions(-) create mode 100644 Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h create mode 100644 Detectors/HMPID/simulation/src/HmpidCoder.cxx create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h create mode 100644 Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index c8a225b3443a3..d86c7bab9679f 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -58,15 +58,16 @@ class Digit public: Digit() = default; - Digit(int bc, int orbit, int pad, float charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad) {}; - Digit(int bc, int orbit, int chamber, int photo, int x, int y, float charge); - Digit(int bc, int orbit, float charge, int equipment, int column, int dilogic, int channel) ; - Digit(int bc, int orbit, float charge, int module, int x, int y); + Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad) {}; + Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge); + Digit(uint16_t bc, uint32_t orbit, float uint16_t, int equipment, int column, int dilogic, int channel) ; + Digit(uint16_t bc, uint32_t orbit, float uint16_t, int module, int x, int y); - float getCharge() const { return mQ; } + uint16_t getCharge() const { return mQ; } int getPadID() const { return mPad; } - int getOrbit() const { return mOrbit; } - int getBC() const { return mBc; } + uint32_t getOrbit() const { return mOrbit; } + uint16_t getBC() const { return mBc; } + uint64_t getTriggerID() const { return ((mOrbit << 12) | mBc); } // convenience conversion to x-y pad coordinates int getPx() const { return A2X(mPad); } @@ -82,10 +83,10 @@ class Digit void addCharge(float q) { mQ += q; } private: - float mQ = 0.; - uint32_t mPad = 0.; // -1 indicates invalid digit - int mBc = 0.; - int mOrbit = 0; + uint16_t mQ = 0; + uint32_t mPad = 0; // -1 indicates invalid digit + uint16_t mBc = 0.; + uint32_t mOrbit = 0; static float LorsX(int pad) { return Param::LorsX(A2P(pad), A2X(pad)); } //center of the pad x, [cm] static float LorsY(int pad) { return Param::LorsY(A2P(pad), A2Y(pad)); } //center of the pad y, [cm] diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 87135473d880b..85517ffb0b209 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -19,7 +19,7 @@ using namespace o2::hmpid; ClassImp(o2::hmpid::Digit); // ----- Constructors ------------ - Digit::Digit(int bc, int orbit, int chamber, int photo, int x, int y, float charge) + Digit::Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge) { mBc = bc; mOrbit = orbit; @@ -27,7 +27,7 @@ ClassImp(o2::hmpid::Digit); mPad = Abs(chamber, photo, x, y); } - Digit::Digit(int bc, int orbit, float charge, int equipment, int column, int dilogic, int channel) + Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int column, int dilogic, int channel) { mBc = bc; mOrbit = orbit; @@ -35,7 +35,7 @@ ClassImp(o2::hmpid::Digit); mPad = Equipment2Pad(equipment, column, dilogic, channel); } - Digit::Digit(int bc, int orbit, float charge, int module, int x, int y) + Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, int y) { mBc = bc; mOrbit = orbit; diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h new file mode 100644 index 0000000000000..7e197e821757c --- /dev/null +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h @@ -0,0 +1,142 @@ +// 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 HmpidCoder.h +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to code HMPID Raw Data file +/// + +#ifndef COMMON_HMPIDCODER_H_ +#define COMMON_HMPIDCODER_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include "FairLogger.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDBase/Digit.h" + +// ---- RDH 6 standard dimension ------- +#define RAWBLOCKDIMENSION_W 2048 +#define HEADERDIMENSION_W 16 +#define PAYLOADDIMENSION_W 2032 +#define PAYLOADMAXSPACE_W 2028 + +// ---- CHARGE CONSTANTS ----- +#define CHARGE_CONST 150 +#define CHARGE_RAND_MAX 400 + +namespace o2 { + +namespace hmpid { + +class HmpidCoder +{ + public: + int mVerbose; + int mNumberOfEquipments; + + private: + // The standard definition of HMPID equipments at P2 + const int mEqIds[Geo::MAXEQUIPMENTS] = { 0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13 }; + const int mCruIds[Geo::MAXEQUIPMENTS] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3 }; + const int mLinkIds[Geo::MAXEQUIPMENTS] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2 }; + const int mFlpIds[Geo::MAXEQUIPMENTS] = { 160, 160, 160, 160, 160, 160, 160, 160, 161, 161, 161, 161, 161, 161 }; + + bool mRandomCharge; + bool mRandomOccupancy; + + int mOccupancyPercentage; + + int mPailoadBufferDimPerEquipment; + uint32_t *mPayloadBufferPtr; + uint32_t *mEventBufferPtr; + uint32_t *mEventBufferBasePtr; + int mEventSizePerEquipment[Geo::MAXEQUIPMENTS]; + + FILE *mOutStream160; + FILE *mOutStream161; + + public: + HmpidCoder(int numOfEquipments); + virtual ~HmpidCoder(); + + void init(); + void setVerbosity(int Level) + { + mVerbose = Level; + }; + int getVerbosity() + { + return (mVerbose); + }; + int getNumberOfEquipments() + { + return (mNumberOfEquipments); + }; + + void setChargeRandomize(bool isRandom) + { + mRandomCharge = isRandom; + }; + bool getChargeRandomize() + { + return(mRandomCharge); + }; + + void setOccupancyRandomize(bool isRandom) + { + mRandomOccupancy = isRandom; + }; + bool getOccupancyRandomize() + { + return(mRandomOccupancy); + }; + + void setOccupancy(int Occupancy) + { + mOccupancyPercentage = Occupancy; + }; + int getOccupancy() + { + return(mOccupancyPercentage); + }; + + void openOutputStream(const char *OutputFileName); + void closeOutputStream(); + + void createRandomEvent(uint32_t orbit, uint16_t bc); + void codeDigitsVector(std::vector); + + + protected: + void createRandomPayloadPerEvent(); + void saveEventPage(int Flp); + int calculateNumberOfPads(); + + private: + void getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId); + int getEquipmentPadIndex(int eq, int col, int dil, int cha); + void writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum); + void fillPadsMap(uint32_t *padMap); + void fillTheOutputBuffer(uint32_t* padMap); + void writePaginatedEvent(uint32_t orbit, uint16_t bc); +}; + +} +} + +#endif /* COMMON_HMPIDCODER_H_ */ diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx new file mode 100644 index 0000000000000..0e2cc15971451 --- /dev/null +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -0,0 +1,312 @@ +// 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 HmpidCoder.cxx +/// \author Antonio Franco - INFN Bari +/// \brief Base Class for coding HMPID Raw Data File +/// \version 1.0 +/// \date 24 set 2020 + +#include "HMPIDSimulation/HmpidCoder.h" + +using namespace o2::hmpid; + +HmpidCoder::HmpidCoder(int numOfEquipments) +{ + + mNumberOfEquipments = numOfEquipments; + mVerbose = 0; + mOccupancyPercentage = 0; + mRandomOccupancy = false; + mRandomCharge = false; + mOutStream160 = NULL; + mOutStream161 = NULL; + + mPailoadBufferDimPerEquipment = ((Geo::N_SEGMENTS * (Geo::N_COLXSEGMENT * (Geo::N_DILOGICS * (Geo::N_CHANNELS + 1) + 1) + 1)) + 10); + + mPayloadBufferPtr = (uint32_t *) std::malloc(mNumberOfEquipments * sizeof(uint32_t) * mPailoadBufferDimPerEquipment ); + mEventBufferBasePtr = (uint32_t *) std::malloc(sizeof(uint32_t) * RAWBLOCKDIMENSION_W); + mEventBufferPtr = mEventBufferBasePtr; + srand( (unsigned)time(NULL) ); + +} + +HmpidCoder::~HmpidCoder() +{ + // TODO Auto-generated destructor stub + std::free(mPayloadBufferPtr); + std::free(mEventBufferBasePtr); +} + +// ===================== Random production of Raw Files =================== + +int HmpidCoder::calculateNumberOfPads() +{ +// int numOfEqipments = 0; + int occupancyPercentage = 0; +// for(int i = 0; i < MAXEQUIPMENTS; i++) +// if(mFlpIds[i] == Flp) +// numOfEqipments++; + + if(mRandomOccupancy) { + occupancyPercentage = rand() % 1000; + } else { + occupancyPercentage = mOccupancyPercentage; + } + return( occupancyPercentage * Geo::MAXEQUIPMENTS * Geo::N_EQUIPMENTTOTALPADS / 1000); +} + +void HmpidCoder::fillPadsMap(uint32_t *padMap) +{ + int numberOfpads = calculateNumberOfPads(); + int mo, yc, xr, eq, col, dil, cha; + for (int i = 0; i 0) { + pads[j]++; + rowSize++; + } + } + } + rowSize += Geo::N_DILOGICS; + segSize += (rowSize + 1); + rowMarker = 0x000036A8 | ((rowSize << 16) & 0x03ff0000); + // fills the Payload Buffer + mPayloadBufferPtr[ptr++] = rowMarker; + int col = (s - 1) * Geo::N_COLXSEGMENT + c; + for (int d = 1; d <= Geo::N_DILOGICS; d++) { + for (int p = 0; p < Geo::N_CHANNELS; p++) { + int idx = getEquipmentPadIndex(eq, ((s-1)*Geo::N_COLXSEGMENT+(c-1)), (d-1), p); + if(padMap[idx] > 0) { + padWord = ((col << 22) & 0x07c00000) | ((d << 18) & 0x003C0000) | ((p << 12) & 0x0003F000) + | (padMap[idx] & 0x00000FFF); + mPayloadBufferPtr[ptr++] = padWord; + } + } + eoeMarker = 0x08000080 | ((col << 22) & 0x07c00000) | (d << 18 & 0x003C0000) | (pads[d-1] & 0x0000007F); + mPayloadBufferPtr[ptr++] = eoeMarker; + } + } + segSize += 1; + segMarker = 0xAB000000 | ((segSize << 8) & 0x000fff00) | (s & 0x0000000F); + mPayloadBufferPtr[ptr++] = segMarker; + } + mEventSizePerEquipment[eq] = ptr - startPtr; + } + return; +} + +void HmpidCoder::writePaginatedEvent(uint32_t orbit, uint16_t bc) +{ + int nWordToRead; + int count; + int payloatPtr = 0; + + for (int eq = 0; eq < mNumberOfEquipments; eq++) { + int EventSize = mEventSizePerEquipment[eq]; + int EquipmentCounter = 0; + int numOfPages = EventSize / PAYLOADMAXSPACE_W + 1; + + for (uint32_t PageNum = 1; PageNum <= numOfPages; PageNum++) { + count = 0; + while (count < PAYLOADMAXSPACE_W && EquipmentCounter < EventSize) { + mEventBufferPtr[HEADERDIMENSION_W + count++] = mPayloadBufferPtr[payloatPtr++]; + EquipmentCounter++; + } + nWordToRead = count; + while (count < PAYLOADDIMENSION_W) + mEventBufferPtr[HEADERDIMENSION_W + count++] = 0; + uint32_t MemSize = nWordToRead * sizeof(uint32_t) + HEADERDIMENSION_W * sizeof(uint32_t); + uint32_t PackNum = PageNum; + writeHeader(mEventBufferPtr, MemSize, mEqIds[eq], PackNum, bc, orbit, PageNum); + saveEventPage(mFlpIds[eq]); + } + } + return; +} + +void HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum) +{ + uint32_t CruId, LinkId; + uint32_t TType = 0; + uint32_t HeStop = 0; + uint32_t FirmVers = 9; + uint32_t HeError = 0; + uint32_t Busy = 3000; + uint32_t PAR = 0; + + getEquipCoord(Equip, &CruId, &LinkId); + + // FEEID Header Size Header version + Buffer[0] = 0xFFF00000 | ((Equip & 0x0F) << 16) | 0x00004000 | 0x00000006; + // Priority System ID + Buffer[1] = 0x00000100 | 0x00000006; + // .....Memory Size HeOffsetNewPack; + Buffer[2] = (MemSize << 16) | 0x00002000; + // DW CruId PacNum Link Num + Buffer[3] = 0x10000000 | ((CruId & 0x00FF) << 16) | ((PackNum & 0x0FF) << 8) | (LinkId & 0x0FF); + Buffer[4] = 0x00000FFF & BCDI; + Buffer[5] = ORBIT; + Buffer[6] = 0; + Buffer[7] = 0; + Buffer[8] = TType; + Buffer[9] = ((HeStop & 0x00ff0000) << 16) | (PageNum & 0x0000FFFF); + Buffer[10] = 0; + Buffer[11] = 0; + Buffer[12] = (Busy << 9) | ((HeError & 0x000001F0) << 4) | (FirmVers & 0x0000000f); + Buffer[13] = PAR; + Buffer[14] = 0xAAAA0001; + Buffer[15] = 0xAAAA0001; + return; +} + +void HmpidCoder::codeDigitsVector(std::vectordigits) +{ + uint32_t pv_orbit, orbit = 0; + uint16_t pv_bc, bc = 0; + + uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + int eq,col,dil,cha,mo,x,y, idx; + + for(o2::hmpid::Digit d : digits) { + orbit = d.getOrbit(); + bc = d.getBC(); + if(orbit != pv_orbit || bc != pv_bc) { //the event is changed + if (orbit != 0) { + fillTheOutputBuffer(padMap); + writePaginatedEvent(pv_orbit, pv_bc); + } + memset(padMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + pv_orbit = orbit; + pv_bc = bc; + } + Digit::Pad2Absolute(d.getPadID(), &mo, &x, &y); + Geo::Module2Equipment(mo, y, x, &eq, &col, &dil, &cha); + idx = getEquipmentPadIndex(eq, col, dil, cha); + padMap[idx] = d.getCharge(); + } + fillTheOutputBuffer(padMap); + writePaginatedEvent(pv_orbit, pv_bc); + + std::free(padMap); + return; +} + + +// ====================== FILES management functions ====================== + +void HmpidCoder::saveEventPage(int Flp) +{ + if(Flp == 160) + fwrite(mEventBufferPtr, RAWBLOCKDIMENSION_W, sizeof(uint32_t), mOutStream160); + else + fwrite(mEventBufferPtr, RAWBLOCKDIMENSION_W, sizeof(uint32_t), mOutStream161); + return; +} + +/// @throws TH_CREATEFILE Thrown if Fails to create the file +void HmpidCoder::openOutputStream(const char *OutputFileName) +{ + char FileName[512]; + + sprintf(FileName, "%s%d%s", OutputFileName, 160, ".dat"); + mOutStream160 = fopen(FileName, "wb"); + if (mOutStream160 == 0) { + LOG(ERROR) << "ERROR to open Output file " << FileName; + throw 0; + } + sprintf(FileName, "%s%d%s", OutputFileName, 161, ".dat"); + mOutStream161 = fopen(FileName, "wb"); + if (mOutStream161 == 0) { + LOG(ERROR) << "ERROR to open Output file " << FileName; + throw 0; + } + return; +} + +void HmpidCoder::closeOutputStream() +{ + fclose(mOutStream160); + fclose(mOutStream161); + return; +} diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h new file mode 100644 index 0000000000000..365f45d977bc3 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -0,0 +1,47 @@ +// 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 DatDecoderSpec.h +/// \author Andrea Ferrero +/// +/// \brief Definition of a data processor to run the raw decoding +/// + +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMDIGITS_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMDIGITS_H_ + +#include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" + +namespace o2 +{ +namespace hmpid +{ + + class WriteRawFromDigitsTask : public framework::Task + { + public: + WriteRawFromDigitsTask() = default; + ~WriteRawFromDigitsTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + + + private: + bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); + }; + +o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec = "HMP/DIGITS"); + +} // end namespace hmpid +} // end namespace o2 + +#endif diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx new file mode 100644 index 0000000000000..eabc76d0360ae --- /dev/null +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -0,0 +1,116 @@ +// draft +// 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 DatDecoderSpec.cxx +/// \author +/// +/// \brief Implementation of a data processor to run the HMPID raw decoding +/// + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" + +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" +#include "DPLUtils/DPLRawParser.h" + +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDSimulation/HmpidCoder.h" +#include "HMPIDWorkflow/WriteRawFromDigitsSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using namespace o2; +using namespace o2::framework; +using RDH = o2::header::RDHAny; + +//======================= +// Data decoder +void WriteRawFromDigitsTask::init(framework::InitContext& ic) +{ + LOG(INFO) << "[HMPID Write Raw File From Digits vector - run] Dumping ..."; + + + return; +} + +bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2) +{ + uint64_t t1,t2; + t1 = d1.getTriggerID(); + t2 = d2.getTriggerID(); + + if (t1 < t2) return true; + if (t2 < t1) return false; + + if (d1.getPadID() < d2.getPadID()) return true; + return false; +} + + +void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) +{ + std::vector digits = pc.inputs().get>("digits"); + LOG(INFO) << "The size of the digits vector " << digits.size(); + + sort(digits.begin(), digits.end(), eventEquipPadsComparision); + LOG(INFO) << "Digits sorted ! " ; + + HmpidCoder cod(Geo::MAXEQUIPMENTS); + cod.openOutputStream("pippo"); + cod.codeDigitsVector(digits); + cod.closeOutputStream(); + LOG(INFO) << "Raw File created ! " ; + return; +} + +//_________________________________________________________________________________________________ +o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec) +//o2::framework::DataPrecessorSpec getDecodingSpec() +{ + + std::vector inputs; + inputs.emplace_back("digits", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); + + std::vector outputs; + + + return DataProcessorSpec{ + "HMP-WriteRawFrtomDigits", + inputs, + outputs, + AlgorithmSpec{adaptFromTask()}, + Options{{"print", VariantType::Bool, false, {"print"}}} }; +} + +} // namespace hmpid +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx new file mode 100644 index 0000000000000..f9fcb800bb3ed --- /dev/null +++ b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx @@ -0,0 +1,43 @@ +// 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 raw-to-digits-workflow.cxx +/// \author Andrea Ferrero +/// +/// \brief This is an executable that runs the decoding via DPL. +/// +/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. +/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow +/// + +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/Task.h" +#include "Framework/runDataProcessing.h" + +#include "HMPIDWorkflow/WriteRawFromDigitsSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + DataProcessorSpec consumer = o2::hmpid::getWriteRawFromDigitsSpec(); +// DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); + specs.push_back(consumer); +// specs.push_back(consumer); + + return specs; +} From 5daf2f31aaee43e8d10b23b915c1fb7cb5baafdd Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:24:59 +0100 Subject: [PATCH 154/208] fix cmakes --- Detectors/HMPID/simulation/CMakeLists.txt | 3 ++- Detectors/HMPID/workflow/CMakeLists.txt | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Detectors/HMPID/simulation/CMakeLists.txt b/Detectors/HMPID/simulation/CMakeLists.txt index 75a4e0d973265..639816aa14992 100644 --- a/Detectors/HMPID/simulation/CMakeLists.txt +++ b/Detectors/HMPID/simulation/CMakeLists.txt @@ -9,11 +9,12 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDSimulation - SOURCES src/Detector.cxx src/HMPIDDigitizer.cxx + SOURCES src/Detector.cxx src/HMPIDDigitizer.cxx src/HmpidCoder.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDBase) o2_target_root_dictionary(HMPIDSimulation HEADERS include/HMPIDSimulation/Detector.h + include/HMPIDSimulation/HmpidCoder.h include/HMPIDSimulation/HMPIDDigitizer.h) diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index 0d8f894699251..5ad041ef5f3eb 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -10,7 +10,7 @@ o2_add_library(HMPIDWorkflow # SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/RawFileReaderSpec.cxx src/DumpDigitsSpec.cxx - SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx + SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx src/WriteRawFromDigitSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::DetectorsRaw @@ -28,10 +28,10 @@ o2_add_executable(raw-to-digits-workflow SOURCES src/raw-to-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) -#o2_add_executable(rawfile-to-digits-workflow -# COMPONENT_NAME hmpid -# SOURCES src/rawfile-to-digits-workflow.cxx -# PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) +o2_add_executable(write-raw-from-digits-workflow + COMPONENT_NAME hmpid + SOURCES src/write-rawfrom-digits-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) o2_add_executable(dump-digits-workflow COMPONENT_NAME hmpid From 2c7e840128bb92f8d3407b0be235c06f2e7c3b0e Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:26:22 +0100 Subject: [PATCH 155/208] fix --- Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h b/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h index 804d708d9da3b..5367c5bcb20e1 100644 --- a/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h +++ b/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h @@ -17,5 +17,6 @@ #pragma link C++ class o2::hmpid::Detector + ; #pragma link C++ class o2::base::DetImpl < o2::hmpid::Detector> + ; #pragma link C++ class o2::hmpid::HMPIDDigitizer + ; +#pragma link C++ class o2::hmpid::HmpidCoder + ; #endif From d75571fefad6a011c8a84e8940c571408081a311 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:27:44 +0100 Subject: [PATCH 156/208] fix --- Detectors/HMPID/workflow/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index 5ad041ef5f3eb..b3ab2144e9c41 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -30,7 +30,7 @@ o2_add_executable(raw-to-digits-workflow o2_add_executable(write-raw-from-digits-workflow COMPONENT_NAME hmpid - SOURCES src/write-rawfrom-digits-workflow.cxx + SOURCES src/write-raw-from-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) o2_add_executable(dump-digits-workflow From f28c27364023c8c1db998cdc5e911c4c11d309e8 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:28:41 +0100 Subject: [PATCH 157/208] fix --- Detectors/HMPID/workflow/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index b3ab2144e9c41..ccb511a9998ba 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -10,7 +10,7 @@ o2_add_library(HMPIDWorkflow # SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/RawFileReaderSpec.cxx src/DumpDigitsSpec.cxx - SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx src/WriteRawFromDigitSpec.cxx + SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx src/WriteRawFromDigitsSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::DetectorsRaw From 895c2cfcb5d7f5f2815a96a25b22f75f2e5b58a0 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 15:57:05 +0100 Subject: [PATCH 158/208] fix --- Detectors/HMPID/base/include/HMPIDBase/Digit.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index d86c7bab9679f..5a86cd4e09b78 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -60,8 +60,8 @@ class Digit Digit() = default; Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad) {}; Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge); - Digit(uint16_t bc, uint32_t orbit, float uint16_t, int equipment, int column, int dilogic, int channel) ; - Digit(uint16_t bc, uint32_t orbit, float uint16_t, int module, int x, int y); + Digit(uint16_t bc, uint32_t orbit, uint16_t, int equipment, int column, int dilogic, int channel) ; + Digit(uint16_t bc, uint32_t orbit, uint16_t, int module, int x, int y); uint16_t getCharge() const { return mQ; } int getPadID() const { return mPad; } From 257ba0a8ee201e33e2837bfd7ee03be3131507f7 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 26 Jan 2021 22:33:17 +0100 Subject: [PATCH 159/208] Build Ok --- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 12 ++++++++++++ .../include/HMPIDWorkflow/WriteRawFromDigitsSpec.h | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index 0e2cc15971451..417e13c5fa2b5 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -47,6 +47,18 @@ HmpidCoder::~HmpidCoder() } // ===================== Random production of Raw Files =================== +void HmpidCoder::getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId) +{ + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + if (mEqIds[i] == Equi) { + *CruId = mCruIds[i]; + *LinkId = mLinkIds[i]; + return; + } + *CruId = mCruIds[0]; + *LinkId = mLinkIds[0]; + return; +} int HmpidCoder::calculateNumberOfPads() { diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h index 365f45d977bc3..ba51bef8179b2 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -20,6 +20,7 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" +#include "HMPIDBase/Digit.h" namespace o2 { @@ -36,7 +37,7 @@ namespace hmpid private: - bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); + static bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); }; o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec = "HMP/DIGITS"); From 0f7acfdc595bd34ac15ff811bfa3ae28ebe687dd Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 28 Jan 2021 11:30:50 +0100 Subject: [PATCH 160/208] Troubles .... --- .../HMPID/base/include/HMPIDBase/Digit.h | 2 +- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 7 +++ Detectors/HMPID/base/src/Digit.cxx | 8 ++-- .../HMPIDReconstruction/HmpidDecodeRawFile.h | 2 +- .../HMPIDReconstruction/HmpidDecodeRawMem.h | 4 +- .../HMPIDReconstruction/HmpidDecoder.h | 2 +- .../HMPIDReconstruction/HmpidEquipment.h | 2 +- .../reconstruction/src/HmpidDecodeRawFile.cxx | 2 +- .../reconstruction/src/HmpidDecodeRawMem.cxx | 7 +-- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 7 +-- .../reconstruction/src/HmpidEquipment.cxx | 2 +- .../include/HMPIDSimulation/HmpidCoder.h | 3 +- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 43 +++++++++++++++-- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 4 ++ .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 2 +- .../HMPID/workflow/src/DataDecoderSpec.cxx | 48 +++++++++++-------- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 38 +++++++++++---- .../workflow/src/WriteRawFromDigitsSpec.cxx | 45 +++++++++++++---- 18 files changed, 165 insertions(+), 63 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 5a86cd4e09b78..38680fb3b1d0f 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -52,7 +52,7 @@ class Digit friend std::ostream& operator<< (std::ostream& os, const Digit& d) { os << "[" << A2C(d.mPad) << "," << A2P(d.mPad) << "," << A2X(d.mPad) << "," << - A2Y(d.mPad) << "}@(" << d.mOrbit << "," << d.mBc << ")=" << d.mQ; + A2Y(d.mPad) << "]@(" << d.mOrbit << "," << d.mBc << ")=" << d.mQ; return os; }; diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 85e94dad97dfb..86365fcfd71f9 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -109,6 +109,13 @@ class Geo static constexpr int N_EQUIPMENTTOTALPADS = N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; static constexpr int N_HMPIDTOTALPADS = MAXEQUIPMENTS * N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; + static constexpr int N_PHOTOCATODS = 6; + static constexpr int N_PHOTOCATODSX = 80; + static constexpr int N_PHOTOCATODSY = 48; + static constexpr int MAXXPHOTO = 79; + static constexpr int MAXYPHOTO = 47; + + static void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 85517ffb0b209..1166d492d4603 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -69,9 +69,9 @@ void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Ch uint32_t Digit::Absolute2Pad(int Module, int x, int y) { - int ph = (y/Geo::N_COLXSEGMENT)+((x >= Geo::HALFXROWS ) ? 1 : 0); - int px = x % Geo::N_COLXSEGMENT; - int py = y % Geo::HALFXROWS; + int ph = (y/Geo::N_PHOTOCATODSY)+((x >= Geo::HALFXROWS ) ? 1 : 0); + int px = x % Geo::HALFXROWS; + int py = y % Geo::N_PHOTOCATODSY; return Abs(Module,ph,px,py); } @@ -82,7 +82,7 @@ void Digit::Pad2Absolute(uint32_t pad, int *Module, int *x, int *y) int px = A2X(pad); int py = A2Y(pad); *x = (ph % 2 == 0) ? px : (px + Geo::HALFXROWS); - *y = ((ph >> 1) * Geo::N_COLXSEGMENT) + py; + *y = ((ph >> 1) * Geo::N_PHOTOCATODSY) + py; return; } diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h index bc3444583d634..5f9fbd7020dfb 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h @@ -48,7 +48,7 @@ class HmpidDecodeRawFile: public HmpidDecoder bool getHeaderFromStream(uint32_t **streamPtr); bool getWordFromStream(uint32_t *word); int fileExists(char *filewithpath); - void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge); private: FILE *fh; diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h index 0b3d221a1569e..209660fb3f4d1 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h @@ -47,7 +47,7 @@ class HmpidDecodeRawMem: public HmpidDecoder bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size); bool getHeaderFromStream(uint32_t **streamPtr); bool getWordFromStream(uint32_t *word); - void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge); private: @@ -63,7 +63,7 @@ class HmpidDecodeRawDigit: public HmpidDecodeRawMem std::vector mDigits; private: - void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge); + void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge); }; diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index 2cc9b3ff40af9..6280f8ac355c7 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -155,7 +155,7 @@ class HmpidDecoder HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); void updateStatistics(HmpidEquipment *eq); protected: - virtual void setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) = 0; + virtual void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) = 0; virtual bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size) = 0; virtual bool getHeaderFromStream(uint32_t **streamPtr) = 0; virtual bool getWordFromStream(uint32_t *word) = 0; diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h index 920a502eccc1a..2ed68883b2064 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h @@ -124,7 +124,7 @@ class HmpidEquipment void resetPadMap(); void resetErrors(); void setError(int ErrType); - void setPad(int col, int dil, int cha, int charge); + void setPad(int col, int dil, int cha, uint16_t charge); }; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx index e828bc629e6c1..f9b66f5eda0f1 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx @@ -137,7 +137,7 @@ bool HmpidDecodeRawFile::getWordFromStream(uint32_t *word) /// @param[in] dil : the dilogic [0..9] /// @param[in] ch : the channel [0..47] /// @param[in] charge : the value of the charge -void HmpidDecodeRawFile::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) +void HmpidDecodeRawFile::setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) { eq->setPad(col, dil, ch, charge); return; diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 0627b8fe4b144..5fabdd32190bf 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -132,7 +132,7 @@ bool HmpidDecodeRawMem::getWordFromStream(uint32_t *word) /// @param[in] dil : the dilogic [0..9] /// @param[in] ch : the channel [0..47] /// @param[in] charge : the value of the charge -void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) +void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) { eq->setPad(col, dil, ch, charge); return; @@ -180,10 +180,11 @@ HmpidDecodeRawDigit::~HmpidDecodeRawDigit() /// @param[in] dil : the dilogic [0..9] /// @param[in] ch : the channel [0..47] /// @param[in] charge : the value of the charge -void HmpidDecodeRawDigit::setPad(HmpidEquipment *eq, int col, int dil, int ch, int charge) +void HmpidDecodeRawDigit::setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) { eq->setPad(col, dil, ch, charge); - mDigits.push_back(Digit(mHeBCDI, mHeORBIT, (float)charge, eq->getEquipmentId(), col, dil, ch)); + mDigits.push_back(Digit(mHeBCDI, mHeORBIT, charge, eq->getEquipmentId(), col, dil, ch)); + //std::cout << "DI " << mDigits.back() << " "<>> Coding size "<< digits.size() << std::endl; +int padsCount =0; for(o2::hmpid::Digit d : digits) { orbit = d.getOrbit(); bc = d.getBC(); if(orbit != pv_orbit || bc != pv_bc) { //the event is changed - if (orbit != 0) { + if (pv_orbit != 0 || pv_bc != 0 ) { fillTheOutputBuffer(padMap); writePaginatedEvent(pv_orbit, pv_bc); } @@ -275,16 +279,45 @@ void HmpidCoder::codeDigitsVector(std::vectordigits) Digit::Pad2Absolute(d.getPadID(), &mo, &x, &y); Geo::Module2Equipment(mo, y, x, &eq, &col, &dil, &cha); idx = getEquipmentPadIndex(eq, col, dil, cha); + if(idx == 107562) { + std::cout << ">>> Beccato >"<< idx << " " << d <<" ("<< mo <<","<>> CPads set "<< padsCount << std::endl; std::free(padMap); return; } +void HmpidCoder::codeDigitsTest(int Events, uint16_t charge) +{ + uint32_t orbit = 0; + uint16_t bc = 0; + + uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + int eq,col,dil,cha,mo,x,y, idx; + for(int e=0; e #include "TTree.h" +#include "TFile.h" + #include #include "Framework/CallbackService.h" @@ -71,13 +73,14 @@ void DataDecoderTask::init(framework::InitContext& ic) void DataDecoderTask::run(framework::ProcessingContext& pc) { -//---- mDeco->mDigits.clear(); + mDeco->mDigits.clear(); decodeTF(pc); // decodeReadout(pc); // decodeRawFile(pc); LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; + pc.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginHMP, "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; float avgBusyTime[o2::hmpid::Geo::MAXEQUIPMENTS]; @@ -86,19 +89,21 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - // TString filename = TString::Format("%s_%06d.root", "test", 1); + TString filename = TString::Format("%s_%06d.root", "test", 1); // LOG(DEBUG) << "opening file " << filename.Data(); - // std::unique_ptr mfileOut = nullptr; - // mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); +//-- std::unique_ptr mfileOut = nullptr; +//-- mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); - std::unique_ptr theObj; - theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); + //std::unique_ptr theObj; +// TTree * theObj; + //theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); +// theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); - theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); - theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); - theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); - theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); - theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); +// theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); +// theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); +// theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); +// theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); +// theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); int numEqui = mDeco->getNumberOfEquipments(); for(int e=0;egetPadSamples(m, y, x); sumOfCharges[m][y][x] = mDeco->getPadSum(m, y, x); squareOfCharges[m][y][x] = mDeco->getPadSquares(m, y, x); + // std::cout << "@ " << m <<","<cd(); // theObj->Write(); // theObj.reset(); // mfileOut.reset(); - pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); + // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); - theObj.reset(); + //--- theObj->Reset(); + //---- mfileOut.reset(); } @@ -154,17 +162,17 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) auto& inputs = pc.inputs(); DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); - auto& digitsV = pc.outputs().make>(Output{"HMP", "DIGITS", 0, Lifetime::Timeframe}); +// auto& digitsV = pc.outputs().make>(Output{"HMP", "DIGITS", 0, Lifetime::Timeframe}); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - mDeco->mDigits.clear(); + // mDeco->mDigits.clear(); uint32_t *theBuffer = (uint32_t *)it.raw(); // std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); - for(auto d : mDeco->mDigits) - digitsV.push_back(d); +// for(auto d : mDeco->mDigits) +// digitsV.push_back(d); // pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); @@ -228,8 +236,8 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); - outputs.emplace_back("HMP", "ORBITS", 0, o2::framework::Lifetime::Timeframe); - outputs.emplace_back("HMP", "STATS", 0, o2::framework::Lifetime::Timeframe); + // outputs.emplace_back("HMP", "ORBITS", 0, o2::framework::Lifetime::Timeframe); + // outputs.emplace_back("HMP", "STATS", 0, o2::framework::Lifetime::Timeframe); return DataProcessorSpec{ diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index a0e19829b2372..bcb364c202267 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -58,20 +58,41 @@ void DumpDigitsTask::init(framework::InitContext& ic) LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; mPrintDigits = ic.options().get("print"); - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + mIsOutputOnFile = false; + mOutputFileName = ic.options().get("out-file"); + if(mOutputFileName != "") { + mOsFile.open(mOutputFileName, std::ios::out); + if (mOsFile.is_open()) { + mIsOutputOnFile = true; + } + } return; } void DumpDigitsTask::run(framework::ProcessingContext& pc) { - auto digits = pc.inputs().get>("digits"); - std::cout << "The size of the vector " << digits.size() << std::endl; - if (mPrintDigits) { - for(o2::hmpid::Digit Dig : digits) { - std::cout << Dig << std::endl; + //LOG(INFO) << "Enter Dump run..."; + + for (auto&& input : pc.inputs()) { + if (input.spec->binding == "digits") { + auto digits = pc.inputs().get>("digits"); + LOG(INFO) << "The size of the vector =" << digits.size(); + if (mPrintDigits) { + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + for(o2::hmpid::Digit Dig : digits) { + std::cout << Dig << std::endl; + } + std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; + } + if (mIsOutputOnFile) { + mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + for(o2::hmpid::Digit Dig : digits) { + mOsFile << Dig << std::endl; + } + mOsFile.close(); + } } } - std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; return; } @@ -91,7 +112,8 @@ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) inputs, outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"print", VariantType::Bool, false, {"print digits (default false )"}}} }; + Options{{"out-file", VariantType::String, "", {"name of the output file"}}, + {"print", VariantType::Bool, false, {"print digits (default false )"}}} }; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index eabc76d0360ae..ebeace124575b 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -58,6 +58,7 @@ using RDH = o2::header::RDHAny; void WriteRawFromDigitsTask::init(framework::InitContext& ic) { LOG(INFO) << "[HMPID Write Raw File From Digits vector - run] Dumping ..."; + mBaseFileName = ic.options().get("out-file"); return; @@ -79,17 +80,41 @@ bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2:: void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) { - std::vector digits = pc.inputs().get>("digits"); - LOG(INFO) << "The size of the digits vector " << digits.size(); + uint32_t pad; + int Equi, Colu, Dilo, Chan; + int Equi1, Colu1, Dilo1, Chan1; - sort(digits.begin(), digits.end(), eventEquipPadsComparision); - LOG(INFO) << "Digits sorted ! " ; + for(Equi=0; Equi<14; Equi++) + for(Colu=0;Colu<24;Colu++) + for(Dilo=0;Dilo<10;Dilo++) + for(Chan=0;Chan<48;Chan++) { + pad = Digit::Equipment2Pad(Equi, Colu, Dilo, Chan); + Digit::Pad2Equipment(pad, &Equi1, &Colu1, &Dilo1, &Chan1); + if(Equi!=Equi1 ||Colu!=Colu1||Dilo!=Dilo1||Chan!=Chan1) { + std::cout << ">>>> !" << Equi<<","<< Colu<<","<< Dilo<<","<< Chan << std::endl; + } + } - HmpidCoder cod(Geo::MAXEQUIPMENTS); - cod.openOutputStream("pippo"); - cod.codeDigitsVector(digits); - cod.closeOutputStream(); - LOG(INFO) << "Raw File created ! " ; + + + return; + + for (auto&& input : pc.inputs()) { + if (input.spec->binding == "digits") { + auto digits = pc.inputs().get>("digits"); + + LOG(INFO) << "The size of the digits vector " << digits.size(); + sort(digits.begin(), digits.end(), eventEquipPadsComparision); + LOG(INFO) << "Digits sorted ! " ; + + HmpidCoder cod(Geo::MAXEQUIPMENTS); + cod.openOutputStream(mBaseFileName.c_str()); + //cod.codeDigitsTest(2, 100); + cod.codeDigitsVector(digits); + cod.closeOutputStream(); + LOG(INFO) << "Raw File created ! " ; + } + } return; } @@ -109,7 +134,7 @@ o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec inputs, outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"print", VariantType::Bool, false, {"print"}}} }; + Options{{"out-file", VariantType::String, "hmpidRaw", {"name of the output file"}}} }; } } // namespace hmpid From 5eafb2b6bb376f0a9e7be845230a56799b692a5d Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 28 Jan 2021 13:26:00 +0100 Subject: [PATCH 161/208] fix --- Detectors/HMPID/base/src/Digit.cxx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 1166d492d4603..2e4c4554725d8 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -46,6 +46,21 @@ ClassImp(o2::hmpid::Digit); // ----- Coordinate Conversion ---- uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) { + /* + * + * kNDILOGICAdd = 10 + * + if(ddl<0 || ddl >13 || row<1 || row >25 || dil<1 || dil >10 || pad<0 || pad >47 ) return -1; + Int_t a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) + Int_t ch=ddl/2; + Int_t tmp=(24-row)/8; + Int_t pc=(ddl%2)?5-2*tmp:2*tmp; + Int_t px=(kNDILOGICAdd+1 - dil)*8-pad/6-1; //flip according to Paolo (2-9-2008) + + tmp=(ddl%2)?row-1:(24-row); + Int_t py=6*(tmp%8)+a2y[pad%6]; + + */ if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return -1; @@ -53,7 +68,7 @@ uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) int ch = Equi / 2; // The Module int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; int pc = (Equi % 2) ? 5-2*tmp : 2*tmp; // The PhotoCatode - int px = (Geo::N_DILOGICS+1 - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; + int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; tmp = (Equi % 2) ? Colu : (23-Colu); int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; return Abs(ch,pc,px,py); From a3338c5913bebe0e275c94e21b7a524cc4f364e6 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 29 Jan 2021 09:06:51 +0100 Subject: [PATCH 162/208] Compile OK, not yet correct the coordinate translation --- .../HMPID/base/include/HMPIDBase/Digit.h | 2 + Detectors/HMPID/base/include/HMPIDBase/Geo.h | 20 +++--- Detectors/HMPID/base/src/Digit.cxx | 61 ++++++++++++++++--- Detectors/HMPID/base/src/Geo.cxx | 37 ++++++++++- .../HMPIDReconstruction/HmpidDecoder.h | 6 +- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 19 +++--- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 13 ++-- .../HMPID/workflow/src/DataDecoderSpec.cxx | 6 +- .../workflow/src/WriteRawFromDigitsSpec.cxx | 21 ------- 9 files changed, 123 insertions(+), 62 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 38680fb3b1d0f..cc5892f6e7489 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -41,6 +41,8 @@ class Digit static void Pad2Absolute(uint32_t pad, int *Module, int *x, int *y); static uint32_t Absolute2Pad(int Module, int x, int y); static void Pad2Photo(uint32_t pad, int *chamber, int *photo, int *x, int *y); + static void Absolute2Equipment(int Module, int x, int y, int *Equi, int *Colu, int *Dilo, int *Chan); + static void Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int *Module, int *x, int *y); // Operators definition ! friend inline bool operator<(const Digit& l, const Digit& r) { return l.mPad < r.mPad; }; diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 86365fcfd71f9..49a489e419d34 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -45,14 +45,14 @@ namespace hmpid 143 ^ - | 40 32 24 16 08 00 07 15 23 31 39 47 - | 41 33 25 17 09 01 06 14 22 30 38 46 - 42 34 26 18 10 02 05 13 21 29 37 45 - y 43 35 27 19 11 03 04 12 20 28 36 44 (Column,Dil.) - 44 36 28 20 12 04 03 11 19 27 35 43 - | 45 37 29 21 13 05 02 10 18 26 34 42 - | 46 38 30 22 14 06 01 09 17 25 33 41 - 47 39 31 23 15 07 00 08 16 24 32 40 + | 46 40 34 28 22 16 10 04 05 11 17 23 29 35 41 47 + | 44 38 32 26 20 14 08 02 03 09 15 21 27 33 39 45 + 40 36 30 24 18 12 06 00 01 07 13 19 25 31 37 43 + y 43 37 31 25 19 13 07 01 00 06 12 18 24 30 36 40 (Column,Dil.) + 45 39 33 27 21 15 09 03 02 08 14 20 26 32 38 44 + | 47 41 35 29 23 17 11 05 04 10 16 22 28 34 40 46 + | + 0 @@ -116,8 +116,8 @@ class Geo static constexpr int MAXYPHOTO = 47; - static void Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan); - static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row); + static void Module2Equipment(int Mod, int Row, int Col, int *Equi, int *Colu, int *Dilo, int *Chan); + static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Row, int *Col); // from diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 2e4c4554725d8..19ac5cb3dbae7 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -65,20 +65,65 @@ uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return -1; int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) - int ch = Equi / 2; // The Module + int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; - int pc = (Equi % 2) ? 5-2*tmp : 2*tmp; // The PhotoCatode - int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; - tmp = (Equi % 2) ? Colu : (23-Colu); - int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; + + int py; + int pc; + int px; + if((Equi % Geo::EQUIPMENTSPERMODULE) != 0 ) { + pc = 5-2*tmp; + px = Dilo * Geo::DILOPADSROWS + Chan / Geo::DILOPADSCOLS; + tmp = Colu; + }else { + pc = 2*tmp; + px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; + tmp = (23-Colu); + + } + py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; + py = py % 48; + +// int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5-2*tmp : 2*tmp; // The PhotoCatode +// int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; +// tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23-Colu); +// int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; return Abs(ch,pc,px,py); } void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Chan) { - int ch, ar, ac; - Pad2Absolute(pad, &ch, &ar, &ac); - Geo::Module2Equipment(ch, ac, ar, Equi, Colu, Dilo, Chan); + int ch, ax, ay; + int y2a[6]={4,2,0,1,3,5}; + + Pad2Absolute(pad, &ch, &ax, &ay); + + if (ax > Geo::MAXHALFXROWS) { + *Equi = ch * Geo::EQUIPMENTSPERMODULE + 1; + ax = ax - Geo::HALFXROWS; + *Chan = (ax % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2a[5 -(ay % Geo::DILOPADSCOLS)]; + } else { + *Equi = ch * Geo::EQUIPMENTSPERMODULE; + ax = Geo::MAXHALFXROWS - ax; + ay = Geo::MAXYCOLS - ay; + *Chan = (ax % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2a[ay % Geo::DILOPADSCOLS]; + } + *Dilo = ax / Geo::DILOPADSROWS; + *Colu = ay / Geo::DILOPADSCOLS; + return; +} + +void Digit::Absolute2Equipment(int Module, int x, int y, int *Equi, int *Colu, int *Dilo, int *Chan) +{ + uint32_t pad = Absolute2Pad(Module, x, y); + Pad2Equipment(pad, Equi, Colu, Dilo, Chan); + return; +} + +void Digit::Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int *Module, int *x, int *y) +{ + uint32_t pad = Equipment2Pad(Equi, Colu, Dilo, Chan); + Pad2Absolute(pad, Module, x, y); return; } diff --git a/Detectors/HMPID/base/src/Geo.cxx b/Detectors/HMPID/base/src/Geo.cxx index 8b0957a3e9b1e..f2c8ad232d3b2 100644 --- a/Detectors/HMPID/base/src/Geo.cxx +++ b/Detectors/HMPID/base/src/Geo.cxx @@ -34,9 +34,9 @@ void Geo::Init() /// /// (0,0,0,0) Right Top (1,0,0,0) Left Bottom /// -void Geo::Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Dilo, int *Chan) +void Geo::Module2Equipment(int Mod, int Row, int Col, int *Equi, int *Colu, int *Dilo, int *Chan) { - if (Row > MAXHALFXROWS) { +/* if (Row > MAXHALFXROWS) { *Equi = Mod * EQUIPMENTSPERMODULE + 1; Row = Row - HALFXROWS; } else { @@ -48,6 +48,21 @@ void Geo::Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int *Colu = Col / DILOPADSCOLS; *Chan = (Row % DILOPADSROWS) * DILOPADSCOLS + (Col % DILOPADSCOLS); return; +*/ + int y2a[6]={5,3,1,0,2,4}; + int ch, ax, ay; + if (ax > Geo::MAXHALFXROWS) { + *Equi = ch * Geo::EQUIPMENTSPERMODULE + 1; + ax = ax - Geo::HALFXROWS; + } else { + *Equi = ch * Geo::EQUIPMENTSPERMODULE; + ax = Geo::MAXHALFXROWS - ax; + ay = Geo::MAXYCOLS - ay; + } + *Dilo = ax / Geo::DILOPADSROWS; + *Colu = ay / Geo::DILOPADSCOLS; + *Chan = (ax % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2a[ay % Geo::DILOPADSCOLS]; + return; } /// Functions to translate coordinates : from Equipment,Col,Dilogic,Channel to Module,Col,Row @@ -58,8 +73,10 @@ void Geo::Module2Equipment(int Mod, int Col, int Row, int *Equi, int *Colu, int /// /// (0,0,0,0) Right Top (1,0,0,0) Left Bottom /// -void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col, int *Row) +void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Row, int *Col) { +/* + *Mod = Equi / EQUIPMENTSPERMODULE; *Row = Dilo * DILOPADSROWS + Chan / DILOPADSROWS; *Col = (Colu * DILOPADSCOLS) + Chan % DILOPADSCOLS; @@ -70,6 +87,20 @@ void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Row = MAXHALFXROWS - *Row; *Col = MAXYCOLS - *Col; } + */ + if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || + Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return; + + int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) + int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module + int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; + int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5-2*tmp : 2*tmp; // The PhotoCatode + int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; + tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23-Colu); + int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; + *Mod = ch; + *Row = px; + *Col = py; return; } diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index 6280f8ac355c7..506fe5e5a5946 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -131,9 +131,9 @@ class HmpidDecoder uint16_t getChannelSamples(int Equipment, int Column, int Dilogic, int Channel); double getChannelSum(int Equipment, int Column, int Dilogic, int Channel); double getChannelSquare(int Equipment, int Column, int Dilogic, int Channel); - uint16_t getPadSamples(int Module, int Column, int Row); - double getPadSum(int Module, int Column, int Row); - double getPadSquares(int Module, int Column, int Row); + uint16_t getPadSamples(int Module, int Row, int Column); + double getPadSum(int Module, int Row, int Column); + double getPadSquares(int Module, int Row, int Column); void dumpErrors(int Equipment); void dumpPads(int Equipment, int type = 0); diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 3f0700581ea9d..f70da4e558e07 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -21,6 +21,7 @@ #include "Framework/Logger.h" #include "Headers/RAWDataHeader.h" #include "HMPIDReconstruction/HmpidDecoder.h" +#include "HMPIDBase/Digit.h" using namespace o2::hmpid; @@ -872,10 +873,10 @@ bool HmpidDecoder::decodeBufferFast() /// @param[in] Column : the HMPID Module Column number [0..143] /// @param[in] Row : the HMPID Module Row number [0..159] /// @returns The Number of entries for specified pad -uint16_t HmpidDecoder::getPadSamples(int Module, int Column, int Row) +uint16_t HmpidDecoder::getPadSamples(int Module, int Row, int Column) { int e, c, d, h; - Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + Digit::Absolute2Equipment(Module, Row, Column, &e, &c, &d, &h); int EqInd = getEquipmentIndex(e); if (EqInd < 0) return (0); @@ -887,10 +888,10 @@ uint16_t HmpidDecoder::getPadSamples(int Module, int Column, int Row) /// @param[in] Column : the HMPID Module Column number [0..143] /// @param[in] Row : the HMPID Module Row number [0..159] /// @returns The Sum of Charges for specified pad -double HmpidDecoder::getPadSum(int Module, int Column, int Row) +double HmpidDecoder::getPadSum(int Module, int Row, int Column) { int e, c, d, h; - Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + Digit::Absolute2Equipment(Module, Row, Column, &e, &c, &d, &h); int EqInd = getEquipmentIndex(e); if (EqInd < 0) return (0); @@ -902,10 +903,10 @@ double HmpidDecoder::getPadSum(int Module, int Column, int Row) /// @param[in] Column : the HMPID Module Column number [0..143] /// @param[in] Row : the HMPID Module Row number [0..159] /// @returns The Sum of Square Charges for specified pad -double HmpidDecoder::getPadSquares(int Module, int Column, int Row) +double HmpidDecoder::getPadSquares(int Module, int Row, int Column) { int e, c, d, h; - Geo::Module2Equipment(Module, Column, Row, &e, &c, &d, &h); + Digit::Absolute2Equipment(Module, Row, Column, &e, &c, &d, &h); int EqInd = getEquipmentIndex(e); if (EqInd < 0) return (0); @@ -1015,13 +1016,13 @@ void HmpidDecoder::dumpPads(int EquipmId, int type) for (int r = StartRow; r < EndRow; r++) { switch (type) { case 0: - std::cout << getPadSamples(Module, c, r) << ","; + std::cout << getPadSamples(Module, r, c) << ","; break; case 1: - std::cout << getPadSum(Module, c, r) << ","; + std::cout << getPadSum(Module, r, c) << ","; break; case 2: - std::cout << getPadSquares(Module, c, r) << ","; + std::cout << getPadSquares(Module, r, c) << ","; break; } } diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index c5137ede2ee7e..f1c7cbcc14757 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -15,6 +15,7 @@ /// \version 1.0 /// \date 24 set 2020 +#include "HMPIDBase/Digit.h" #include "HMPIDSimulation/HmpidCoder.h" using namespace o2::hmpid; @@ -86,7 +87,7 @@ void HmpidCoder::fillPadsMap(uint32_t *padMap) mo = rand() % Geo::N_MODULES; xr = rand() % Geo::N_XROWS; yc = rand() % Geo::N_YCOLS; - Geo::Module2Equipment(mo, yc, xr, &eq, &col, &dil, &cha); + Digit::Absolute2Equipment(mo, xr, yc, &eq, &col, &dil, &cha); int index = getEquipmentPadIndex(eq, col, dil, cha); if( padMap[index] == 0) { if(mRandomCharge) { @@ -276,11 +277,13 @@ int padsCount =0; pv_orbit = orbit; pv_bc = bc; } - Digit::Pad2Absolute(d.getPadID(), &mo, &x, &y); - Geo::Module2Equipment(mo, y, x, &eq, &col, &dil, &cha); + Digit::Pad2Equipment(d.getPadID(),&eq, &col, &dil, &cha); idx = getEquipmentPadIndex(eq, col, dil, cha); - if(idx == 107562) { - std::cout << ">>> Beccato >"<< idx << " " << d <<" ("<< mo <<","<>> Beccato >"<< idx << " " << d <<" ("<>> >"<< idx << " " << d <<" ("<< mo <<","<getPadSamples(m, y, x); - sumOfCharges[m][y][x] = mDeco->getPadSum(m, y, x); - squareOfCharges[m][y][x] = mDeco->getPadSquares(m, y, x); + numOfSamples[m][y][x] = mDeco->getPadSamples(m, x, y); + sumOfCharges[m][y][x] = mDeco->getPadSum(m, x, y); + squareOfCharges[m][y][x] = mDeco->getPadSquares(m, x, y); // std::cout << "@ " << m <<","<>>> !" << Equi<<","<< Colu<<","<< Dilo<<","<< Chan << std::endl; - } - } - - - - return; - for (auto&& input : pc.inputs()) { if (input.spec->binding == "digits") { auto digits = pc.inputs().get>("digits"); @@ -122,12 +103,10 @@ void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec) //o2::framework::DataPrecessorSpec getDecodingSpec() { - std::vector inputs; inputs.emplace_back("digits", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); std::vector outputs; - return DataProcessorSpec{ "HMP-WriteRawFrtomDigits", From ef8fe4320b4ff10f299e0eaa9411b6e1c3c69702 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 29 Jan 2021 12:47:39 +0100 Subject: [PATCH 163/208] This works fine ... But only one event from file --- Detectors/HMPID/base/src/Digit.cxx | 64 ++++++++++++++++--- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 6 +- .../HMPID/workflow/src/DataDecoderSpec.cxx | 12 ++-- 3 files changed, 66 insertions(+), 16 deletions(-) diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 19ac5cb3dbae7..40e9109c69505 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -47,6 +47,7 @@ ClassImp(o2::hmpid::Digit); uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) { /* + * Original algorithm in AliROOT Run 1/2 * * kNDILOGICAdd = 10 * @@ -59,11 +60,31 @@ uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) tmp=(ddl%2)?row-1:(24-row); Int_t py=6*(tmp%8)+a2y[pad%6]; - */ + + // Check the input data if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return -1; + int chan2y[6]={3,2,4,1,5,0}; // y coordinate translation for a channel address (index position) for even chamber + + // Calculate the odd/even of geometry + bool isEven = (Equi % Geo::EQUIPMENTSPERMODULE) == 0 ? true : false; + int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module + + // Calculate the x,y photo cathode relative coords + int pc = (23-Colu) / Geo::N_COLXSEGMENT * 2; // pho = [0,2,4] + int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; // (dil [0..9] ,chan[0..47]) -> x [79..0] + int py = Geo::DILOPADSCOLS * ((23-Colu) % Geo::N_COLXSEGMENT) + chan2y[Chan % Geo::DILOPADSCOLS];// Col[0..23] -> y [47..0] + + if(!isEven) { + pc = 5 - pc; // revert the photo cathode index + px = Geo::MAXXPHOTO - px; // revert the x coordinate + py = Geo::MAXYPHOTO - py; // revert the y coordinate + } + + /* ---- Last good algorithm ------- + int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; @@ -83,21 +104,45 @@ uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) } py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; py = py % 48; + */ + + /* Direct Translation from Aliroot + int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5-2*tmp : 2*tmp; // The PhotoCatode + int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; + tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23-Colu); + int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; -// int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5-2*tmp : 2*tmp; // The PhotoCatode -// int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; -// tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23-Colu); -// int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; - return Abs(ch,pc,px,py); + */ + + return Abs(ch,pc,px,py); // Pack the coords into the PadID word } void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Chan) { + int ch, ph, px, py; + int y2chan[6]={5,3,1,0,2,4}; + + Pad2Photo(pad, &ch, &ph, &px, &py); // Unpak the pad ID in the photo cathode coords + + bool isEven = (ph % 2) == 0 ? true : false; + int eq = ch * Geo::EQUIPMENTSPERMODULE; + + if(!isEven) { + eq++; // Correct the equipment number + px = Geo::MAXXPHOTO - px; // revert the X coord + py = Geo::MAXYPHOTO - py; // revert the Y coord + ph = 5 - ph; // revert the photo cathode index + } + *Dilo = Geo::N_DILOGICS - (px / Geo::DILOPADSROWS) -1; // Calculate the Dilogic x [0..79] -> dil [9..0] + *Colu = 23 - (((ph / 2) * Geo::N_COLXSEGMENT) + (py / Geo::DILOPADSCOLS)); // calculate the column (ph [0,2,4], y [0..47]) -> col [23..0] + *Chan = ((Geo::MAXXPHOTO-px) % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2chan[py % Geo::DILOPADSCOLS]; + *Equi = eq; + + return; + /* last good algorithm int ch, ax, ay; int y2a[6]={4,2,0,1,3,5}; - Pad2Absolute(pad, &ch, &ax, &ay); - if (ax > Geo::MAXHALFXROWS) { *Equi = ch * Geo::EQUIPMENTSPERMODULE + 1; ax = ax - Geo::HALFXROWS; @@ -111,6 +156,7 @@ void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Ch *Dilo = ax / Geo::DILOPADSROWS; *Colu = ay / Geo::DILOPADSCOLS; return; + */ } void Digit::Absolute2Equipment(int Module, int x, int y, int *Equi, int *Colu, int *Dilo, int *Chan) @@ -129,7 +175,7 @@ void Digit::Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int *Modu uint32_t Digit::Absolute2Pad(int Module, int x, int y) { - int ph = (y/Geo::N_PHOTOCATODSY)+((x >= Geo::HALFXROWS ) ? 1 : 0); + int ph = (y/Geo::N_PHOTOCATODSY)*2+((x >= Geo::HALFXROWS ) ? 1 : 0); int px = x % Geo::HALFXROWS; int py = y % Geo::N_PHOTOCATODSY; return Abs(Module,ph,px,py); diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index f1c7cbcc14757..9488273737ec6 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -279,11 +279,13 @@ int padsCount =0; } Digit::Pad2Equipment(d.getPadID(),&eq, &col, &dil, &cha); idx = getEquipmentPadIndex(eq, col, dil, cha); + // std::cout << ">>> "<< idx << " " << d <<" ("<>> Beccato >"<< idx << " " << d <<" ("<>> "<< idx << " " << d <<" ("<>> >"<< idx << " " << d <<" ("<< mo <<","<>> Errore >"<<" abso("<< mo <<","<binding == "rawfile") { - const auto* header = o2::header::get(input.header); - if (!header) { - return; - } + // const auto* header = o2::header::get(input.header); + // if (!header) { + // return; + // } + const o2::header::DataHeader* header = o2::header::get(input.header); uint32_t *theBuffer = (uint32_t *)input.payload; int pagesize = header->payloadSize; + std::cout << "Get page !" << std::endl; mDeco->setUpStream(theBuffer, pagesize); mDeco->decodePageFast(&theBuffer); } @@ -229,7 +231,7 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); -// inputs.emplace_back("rawdata", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + // inputs.emplace_back("rawfile", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); From ea1524152271a0a074015148ec59df318d40eda4 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 29 Jan 2021 18:19:18 +0100 Subject: [PATCH 164/208] Version 0.1 --- Detectors/HMPID/base/src/Digit.cxx | 105 +++++------------------------ 1 file changed, 17 insertions(+), 88 deletions(-) diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 40e9109c69505..c9d8e312ab919 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -46,74 +46,23 @@ ClassImp(o2::hmpid::Digit); // ----- Coordinate Conversion ---- uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) { - /* - * Original algorithm in AliROOT Run 1/2 - * - * kNDILOGICAdd = 10 - * - if(ddl<0 || ddl >13 || row<1 || row >25 || dil<1 || dil >10 || pad<0 || pad >47 ) return -1; - Int_t a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) - Int_t ch=ddl/2; - Int_t tmp=(24-row)/8; - Int_t pc=(ddl%2)?5-2*tmp:2*tmp; - Int_t px=(kNDILOGICAdd+1 - dil)*8-pad/6-1; //flip according to Paolo (2-9-2008) - - tmp=(ddl%2)?row-1:(24-row); - Int_t py=6*(tmp%8)+a2y[pad%6]; - */ - // Check the input data if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return -1; int chan2y[6]={3,2,4,1,5,0}; // y coordinate translation for a channel address (index position) for even chamber - // Calculate the odd/even of geometry - bool isEven = (Equi % Geo::EQUIPMENTSPERMODULE) == 0 ? true : false; - int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module - - // Calculate the x,y photo cathode relative coords - int pc = (23-Colu) / Geo::N_COLXSEGMENT * 2; // pho = [0,2,4] - int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; // (dil [0..9] ,chan[0..47]) -> x [79..0] - int py = Geo::DILOPADSCOLS * ((23-Colu) % Geo::N_COLXSEGMENT) + chan2y[Chan % Geo::DILOPADSCOLS];// Col[0..23] -> y [47..0] - - if(!isEven) { - pc = 5 - pc; // revert the photo cathode index - px = Geo::MAXXPHOTO - px; // revert the x coordinate - py = Geo::MAXYPHOTO - py; // revert the y coordinate - } - - /* ---- Last good algorithm ------- - - int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) + bool isEven = (Equi % Geo::EQUIPMENTSPERMODULE) == 0 ? true : false; // Calculate the odd/even of geometry int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module - int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; - - int py; - int pc; - int px; - if((Equi % Geo::EQUIPMENTSPERMODULE) != 0 ) { - pc = 5-2*tmp; - px = Dilo * Geo::DILOPADSROWS + Chan / Geo::DILOPADSCOLS; - tmp = Colu; - }else { - pc = 2*tmp; - px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; - tmp = (23-Colu); + // Calculate the x,y photo cathode relative coords For Odd equipment + int pc = (Colu / Geo::N_COLXSEGMENT) * 2 + 1; // col [0..23] -> [1,3,5] + int px = Geo::MAXXPHOTO - ((Dilo * Geo::DILOPADSROWS) + (Chan / Geo::DILOPADSCOLS)); + int py = (Colu % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + chan2y[Chan % Geo::DILOPADSCOLS]; + if(isEven) { + pc = 5 - pc; + py = Geo::MAXYPHOTO - py; } - py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; - py = py % 48; - */ - - /* Direct Translation from Aliroot - int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5-2*tmp : 2*tmp; // The PhotoCatode - int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; - tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23-Colu); - int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; - - */ - return Abs(ch,pc,px,py); // Pack the coords into the PadID word } @@ -125,38 +74,18 @@ void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Ch Pad2Photo(pad, &ch, &ph, &px, &py); // Unpak the pad ID in the photo cathode coords bool isEven = (ph % 2) == 0 ? true : false; - int eq = ch * Geo::EQUIPMENTSPERMODULE; - - if(!isEven) { - eq++; // Correct the equipment number - px = Geo::MAXXPHOTO - px; // revert the X coord + int eq = ch * Geo::EQUIPMENTSPERMODULE +1; + px = Geo::MAXXPHOTO - px; // revert the X coord + if(isEven) { + eq--; // Correct the equipment number py = Geo::MAXYPHOTO - py; // revert the Y coord - ph = 5 - ph; // revert the photo cathode index + ph = 5 - ph; // revert the photo cathode index [0,2,4] -> [5,3,1] } - *Dilo = Geo::N_DILOGICS - (px / Geo::DILOPADSROWS) -1; // Calculate the Dilogic x [0..79] -> dil [9..0] - *Colu = 23 - (((ph / 2) * Geo::N_COLXSEGMENT) + (py / Geo::DILOPADSCOLS)); // calculate the column (ph [0,2,4], y [0..47]) -> col [23..0] - *Chan = ((Geo::MAXXPHOTO-px) % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2chan[py % Geo::DILOPADSCOLS]; + *Dilo = px / Geo::DILOPADSROWS; // Calculate the Dilogic x [0..79] -> dil [0..9] + *Colu = ((ph / 2) * Geo::N_COLXSEGMENT) + (py / Geo::DILOPADSCOLS); // calculate the column (ph [1,3,5], y [0..47]) -> col [0..23] + *Chan = ((px % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS) + y2chan[py % Geo::DILOPADSCOLS]; *Equi = eq; - - return; - /* last good algorithm - int ch, ax, ay; - int y2a[6]={4,2,0,1,3,5}; - Pad2Absolute(pad, &ch, &ax, &ay); - if (ax > Geo::MAXHALFXROWS) { - *Equi = ch * Geo::EQUIPMENTSPERMODULE + 1; - ax = ax - Geo::HALFXROWS; - *Chan = (ax % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2a[5 -(ay % Geo::DILOPADSCOLS)]; - } else { - *Equi = ch * Geo::EQUIPMENTSPERMODULE; - ax = Geo::MAXHALFXROWS - ax; - ay = Geo::MAXYCOLS - ay; - *Chan = (ax % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + y2a[ay % Geo::DILOPADSCOLS]; - } - *Dilo = ax / Geo::DILOPADSROWS; - *Colu = ay / Geo::DILOPADSCOLS; return; - */ } void Digit::Absolute2Equipment(int Module, int x, int y, int *Equi, int *Colu, int *Dilo, int *Chan) @@ -187,7 +116,7 @@ void Digit::Pad2Absolute(uint32_t pad, int *Module, int *x, int *y) int ph = A2P(pad); int px = A2X(pad); int py = A2Y(pad); - *x = (ph % 2 == 0) ? px : (px + Geo::HALFXROWS); + *x = px + ((ph % 2 == 1) ? Geo::HALFXROWS : 0); *y = ((ph >> 1) * Geo::N_PHOTOCATODSY) + py; return; } From 455cbdbf70202367e7597f48f3e0b4bb9abc1db4 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:22:17 +0100 Subject: [PATCH 165/208] Version 0.2 - Works on Centos ! Test the StfBuilder chain -> Decode -> WriteRawFile Need to verify the loss of Pads --- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 24 ++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 49a489e419d34..2f6b3144e6080 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -21,8 +21,8 @@ namespace hmpid /* ------------------ HMPID Detector Coordinate definition ------------------- 143 .-------------. .-------------. 0 ------.------ 23 - | | |.-----.-----.| | | --> | - | | || | || | | 0 9 | + | | |.-----.-----.| | | <-- | + | | || | || | | 9 0 | | | || 4 | 5 || | | Dil. | ^ | | || | || | | | | ^ | | | ||_____|_____|| | | | | | @@ -41,30 +41,26 @@ namespace hmpid Pad(Module,x,y) Pad(Chamber,PhotoCat,x,y) Pad(Equipment,Column,Dilogic,Channel) - Equipment n Equipment n+1 + Equipment n 143 ^ - | 46 40 34 28 22 16 10 04 05 11 17 23 29 35 41 47 - | 44 38 32 26 20 14 08 02 03 09 15 21 27 33 39 45 - 40 36 30 24 18 12 06 00 01 07 13 19 25 31 37 43 - y 43 37 31 25 19 13 07 01 00 06 12 18 24 30 36 40 (Column,Dil.) - 45 39 33 27 21 15 09 03 02 08 14 20 26 32 38 44 - | 47 41 35 29 23 17 11 05 04 10 16 22 28 34 40 46 + | 46 40 34 28 22 16 10 04 + | 44 38 32 26 20 14 08 02 + 40 36 30 24 18 12 06 00 + y 43 37 31 25 19 13 07 01 + 45 39 33 27 21 15 09 03 + | 47 41 35 29 23 17 11 05 | 0 - 0 --------- x ------> 79 80 ------ x -----------> 159 + 0 --------- x ------> 79 For Equipment n : x = 79 - (Dilo * 8 + Chan / 8) y = 143 - (Column * 6 + Chan % 6) - For Equipment n+1 : x = 80 + (Dilo * 8 + Chan / 8) - y = Column * 6 + Chan % 6 - - --------------------------------------------------------------------------- */ /// \class Geo /// \brief HMPID detector geometry (only statics) From cbd14db52e489dbbaf4a45a50154510f035ff2e3 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:23:50 +0100 Subject: [PATCH 166/208] try to open Root File --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 1b30a6997f0b7..252a32178dc77 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -90,9 +90,9 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; TString filename = TString::Format("%s_%06d.root", "test", 1); - // LOG(DEBUG) << "opening file " << filename.Data(); -//-- std::unique_ptr mfileOut = nullptr; -//-- mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); + LOG(DEBUG) << "opening the stat file " << filename.Data(); + std::unique_ptr mfileOut = nullptr; + mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); //std::unique_ptr theObj; // TTree * theObj; @@ -124,7 +124,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // mfileOut->cd(); // theObj->Write(); // theObj.reset(); -// mfileOut.reset(); + mfileOut.reset(); // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); From 806fbec2f6b2c149ca21ea0c78e7dc08391efb6b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:36:22 +0100 Subject: [PATCH 167/208] try write ttree --- .../HMPID/workflow/src/DataDecoderSpec.cxx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 252a32178dc77..9879abc1e6355 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -94,16 +94,16 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) std::unique_ptr mfileOut = nullptr; mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); - //std::unique_ptr theObj; -// TTree * theObj; - //theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); -// theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); + std::unique_ptr theObj; + TTree * theObj; + theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); + theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); -// theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); -// theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); -// theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); -// theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); -// theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); + theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); + theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); + theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); + theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); + theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); int numEqui = mDeco->getNumberOfEquipments(); for(int e=0;egetPadSquares(m, x, y); // std::cout << "@ " << m <<","<WriteObject((TTree *)theObj, "HMPID Decoding Statistics"); // mfileOut->cd(); // theObj->Write(); -// theObj.reset(); + theObj.reset(); mfileOut.reset(); // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); From 03335e673ea5261e0d306f313bef4e6dde1dcc60 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:43:57 +0100 Subject: [PATCH 168/208] fix --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 9879abc1e6355..80a07ef56ba4a 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -96,7 +96,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) std::unique_ptr theObj; TTree * theObj; - theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); + // theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); @@ -120,9 +120,9 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) } theObj->Fill(); - mfileOut->WriteObject((TTree *)theObj, "HMPID Decoding Statistics"); + // mfileOut->WriteObject((TTree *)theObj, "HMPID Decoding Statistics"); // mfileOut->cd(); -// theObj->Write(); + theObj->Write(); theObj.reset(); mfileOut.reset(); From 6b8d6feb1a498a8ba9560afeae9b918b867bc7d1 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:49:12 +0100 Subject: [PATCH 169/208] fix --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 80a07ef56ba4a..3e0a5f266efad 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -91,10 +91,11 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) TString filename = TString::Format("%s_%06d.root", "test", 1); LOG(DEBUG) << "opening the stat file " << filename.Data(); - std::unique_ptr mfileOut = nullptr; +// std::unique_ptr mfileOut = nullptr; + TFile mfileOut; mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); - std::unique_ptr theObj; + // std::unique_ptr theObj; TTree * theObj; // theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); From e2055db92a690f820267017a5216d42e1a191de5 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:53:54 +0100 Subject: [PATCH 170/208] fix --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 3e0a5f266efad..bdc758fa9f19e 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -92,8 +92,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) TString filename = TString::Format("%s_%06d.root", "test", 1); LOG(DEBUG) << "opening the stat file " << filename.Data(); // std::unique_ptr mfileOut = nullptr; - TFile mfileOut; - mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); + TFile mfileOut(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); // std::unique_ptr theObj; TTree * theObj; @@ -124,8 +123,6 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) // mfileOut->WriteObject((TTree *)theObj, "HMPID Decoding Statistics"); // mfileOut->cd(); theObj->Write(); - theObj.reset(); - mfileOut.reset(); // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); From 0cb23dc1259397d62e96a3940b180d6b07775cc0 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Sat, 30 Jan 2021 01:57:56 +0100 Subject: [PATCH 171/208] fix --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index bdc758fa9f19e..e2548e4747697 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -92,7 +92,7 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) TString filename = TString::Format("%s_%06d.root", "test", 1); LOG(DEBUG) << "opening the stat file " << filename.Data(); // std::unique_ptr mfileOut = nullptr; - TFile mfileOut(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE")); + TFile mfileOut(TString::Format("%s", filename.Data()), "RECREATE"); // std::unique_ptr theObj; TTree * theObj; From 6f23bfadb94f2e5ea9719ac74797a7f5d3cf6230 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 4 Feb 2021 12:29:09 +0100 Subject: [PATCH 172/208] Works with streming. --- .../HMPID/base/include/HMPIDBase/Digit.h | 3 + .../HMPID/reconstruction/src/HmpidDecoder.cxx | 4 +- .../include/HMPIDSimulation/HmpidCoder.h | 21 ++- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 174 +++++++++++------- Detectors/HMPID/workflow/CMakeLists.txt | 13 +- .../include/HMPIDWorkflow/DataDecoderSpec.h | 10 +- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 5 +- .../include/HMPIDWorkflow/ReadRawFileSpec.h | 43 +++++ .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 19 +- .../HMPID/workflow/src/DataDecoderSpec.cxx | 119 +++++------- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 43 +++-- .../HMPID/workflow/src/ReadRawFileSpec.cxx | 153 +++++++++++++++ .../workflow/src/WriteRawFromDigitsSpec.cxx | 72 +++++--- .../workflow/src/dump-digits-workflow.cxx | 12 ++ .../workflow/src/raw-to-digits-workflow.cxx | 38 +++- .../workflow/src/read-raw-file-workflow.cxx | 62 +++++++ .../src/write-raw-from-digits-workflow.cxx | 21 ++- 17 files changed, 589 insertions(+), 223 deletions(-) create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h create mode 100644 Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index cc5892f6e7489..ffe60a28f9dfa 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -70,6 +70,9 @@ class Digit uint32_t getOrbit() const { return mOrbit; } uint16_t getBC() const { return mBc; } uint64_t getTriggerID() const { return ((mOrbit << 12) | mBc); } + void setOrbit(uint32_t orbit) { mOrbit = orbit; return; } + void setBC(uint16_t bc) { mBc = bc; return; } + void setTriggerID(uint64_t trigger) { mOrbit = (trigger >> 12); mBc = (trigger & 0x0FFF); return; } // convenience conversion to x-y pad coordinates int getPx() const { return A2X(mPad); } diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index f70da4e558e07..5217550c16b0f 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -410,7 +410,7 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT; LOG(DEBUG) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR; - LOG(INFO) << " EquIdx = "<<*EquipIndex<< " Event = "<< mHeEvent<< " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; + LOG(DEBUG) << " EquIdx = "<<*EquipIndex<< " Event = "<< mHeEvent<< " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; if (*EquipIndex == -1) { LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; @@ -811,7 +811,7 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) break; } if (wp == wpprev) { - LOG(INFO) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ "[" << Column << "]"; } else { if( isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h index 790d4a3707d87..b6efa62ca85ed 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h @@ -67,15 +67,22 @@ class HmpidCoder uint32_t *mEventBufferBasePtr; int mEventSizePerEquipment[Geo::MAXEQUIPMENTS]; uint32_t mPacketCounterPerEquipment[Geo::MAXEQUIPMENTS]; + bool mSkipEmptyEvents; + bool mFixedPacketLenght; + std::string mFileName160; + std::string mFileName161; FILE *mOutStream160; FILE *mOutStream161; + long mPadsCoded; + long mPacketsCoded; + public: - HmpidCoder(int numOfEquipments); + HmpidCoder(int numOfEquipments, bool skipEmptyEvents = false, bool fixedPacketLenght = true); virtual ~HmpidCoder(); - void init(); + void reset(); void setVerbosity(int Level) { mVerbose = Level; @@ -119,19 +126,21 @@ class HmpidCoder void openOutputStream(const char *OutputFileName); void closeOutputStream(); - void createRandomEvent(uint32_t orbit, uint16_t bc); + void codeRandomEvent(uint32_t orbit, uint16_t bc); void codeDigitsVector(std::vector); - void codeDigitsTest(int Events, uint16_t charge); + void codeTest(int Events, uint16_t charge); + + void dumpResults(); protected: void createRandomPayloadPerEvent(); - void saveEventPage(int Flp); + void savePacket(int Flp, int packetSize); int calculateNumberOfPads(); private: void getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId); int getEquipmentPadIndex(int eq, int col, int dil, int cha); - void writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum); + int writeHeader(uint32_t *Buffer, uint32_t WordsToRead, uint32_t PayloadWords, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum); void fillPadsMap(uint32_t *padMap); void fillTheOutputBuffer(uint32_t* padMap); void writePaginatedEvent(uint32_t orbit, uint16_t bc); diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index 9488273737ec6..866d776f6d368 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -20,16 +20,21 @@ using namespace o2::hmpid; -HmpidCoder::HmpidCoder(int numOfEquipments) +HmpidCoder::HmpidCoder(int numOfEquipments, bool skipEmptyEvents, bool fixedPacketsLenght) { mNumberOfEquipments = numOfEquipments; + mSkipEmptyEvents = skipEmptyEvents; + mFixedPacketLenght = fixedPacketsLenght; + mVerbose = 0; mOccupancyPercentage = 0; mRandomOccupancy = false; mRandomCharge = false; mOutStream160 = NULL; mOutStream161 = NULL; + mFileName160 = ""; + mFileName161 = ""; mPailoadBufferDimPerEquipment = ((Geo::N_SEGMENTS * (Geo::N_COLXSEGMENT * (Geo::N_DILOGICS * (Geo::N_CHANNELS + 1) + 1) + 1)) + 10); @@ -38,7 +43,7 @@ HmpidCoder::HmpidCoder(int numOfEquipments) mPayloadBufferPtr = (uint32_t *) std::malloc(mNumberOfEquipments * sizeof(uint32_t) * mPailoadBufferDimPerEquipment ); mEventBufferBasePtr = (uint32_t *) std::malloc(sizeof(uint32_t) * RAWBLOCKDIMENSION_W); mEventBufferPtr = mEventBufferBasePtr; - srand( (unsigned)time(NULL) ); + reset(); } @@ -49,28 +54,17 @@ HmpidCoder::~HmpidCoder() std::free(mEventBufferBasePtr); } -// ===================== Random production of Raw Files =================== -void HmpidCoder::getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId) +void HmpidCoder::reset() { - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) - if (mEqIds[i] == Equi) { - *CruId = mCruIds[i]; - *LinkId = mLinkIds[i]; - return; - } - *CruId = mCruIds[0]; - *LinkId = mLinkIds[0]; - return; + srand( (unsigned)time(NULL) ); + mPadsCoded = 0; + mPacketsCoded = 0; } +// ===================== Random production of Raw Files =================== int HmpidCoder::calculateNumberOfPads() { -// int numOfEqipments = 0; int occupancyPercentage = 0; -// for(int i = 0; i < MAXEQUIPMENTS; i++) -// if(mFlpIds[i] == Flp) -// numOfEqipments++; - if(mRandomOccupancy) { occupancyPercentage = rand() % 1000; } else { @@ -102,15 +96,6 @@ void HmpidCoder::fillPadsMap(uint32_t *padMap) return; } -constexpr int p1() { return(Geo::N_SEGMENTS * Geo::N_COLXSEGMENT * Geo::N_DILOGICS * Geo::N_CHANNELS); } -constexpr int p2() { return(Geo::N_DILOGICS * Geo::N_CHANNELS); } - -int HmpidCoder::getEquipmentPadIndex(int eq, int col, int dil, int cha) -{ - return( eq * p1() + col * p2() + dil * Geo::N_CHANNELS + cha); - -} - void HmpidCoder::createRandomPayloadPerEvent() { uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); @@ -123,24 +108,43 @@ void HmpidCoder::createRandomPayloadPerEvent() return; } - -void HmpidCoder::createRandomEvent(uint32_t orbit, uint16_t bc) +void HmpidCoder::codeRandomEvent(uint32_t orbit, uint16_t bc) { - createRandomPayloadPerEvent(); writePaginatedEvent(orbit, bc); + return; +} +// ===================== END of Random production of Raw Files =================== +void HmpidCoder::getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId) +{ + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + if (mEqIds[i] == Equi) { + *CruId = mCruIds[i]; + *LinkId = mLinkIds[i]; + return; + } + *CruId = mCruIds[0]; + *LinkId = mLinkIds[0]; return; } -// ===================== END of Random production of Raw Files =================== +constexpr int p1() { return(Geo::N_SEGMENTS * Geo::N_COLXSEGMENT * Geo::N_DILOGICS * Geo::N_CHANNELS); } +constexpr int p2() { return(Geo::N_DILOGICS * Geo::N_CHANNELS); } + +int HmpidCoder::getEquipmentPadIndex(int eq, int col, int dil, int cha) +{ + return( eq * p1() + col * p2() + dil * Geo::N_CHANNELS + cha); + +} + void HmpidCoder::fillTheOutputBuffer(uint32_t* padMap) { uint32_t rowMarker, segMarker, eoeMarker, padWord; uint32_t rowSize; uint32_t ptr = 0; int pads[Geo::MAXEQUIPMENTS]; - int count; + int padsCount; int segSize; for(int i=0; i 0) { pads[j]++; rowSize++; + padsCount++; } } } rowSize += Geo::N_DILOGICS; segSize += (rowSize + 1); rowMarker = 0x000036A8 | ((rowSize << 16) & 0x03ff0000); - // fills the Payload Buffer + + // ---- fills the Payload Buffer mPayloadBufferPtr[ptr++] = rowMarker; int col = (s - 1) * Geo::N_COLXSEGMENT + c; for (int d = 1; d <= Geo::N_DILOGICS; d++) { @@ -187,7 +195,12 @@ void HmpidCoder::fillTheOutputBuffer(uint32_t* padMap) segMarker = 0xAB000000 | ((segSize << 8) & 0x000fff00) | (s & 0x0000000F); mPayloadBufferPtr[ptr++] = segMarker; } - mEventSizePerEquipment[eq] = ptr - startPtr; + + if(mSkipEmptyEvents && padsCount == 0) { // Sets the lenght of Events + mEventSizePerEquipment[eq] = 0; + } else { + mEventSizePerEquipment[eq] = ptr - startPtr; + } } return; } @@ -197,9 +210,15 @@ void HmpidCoder::writePaginatedEvent(uint32_t orbit, uint16_t bc) int nWordToRead; int count; int payloatPtr = 0; + if(orbit == 0 || bc == 0){ + std::cerr << "HmpidCoder [ERROR] : Bad Orbit/BCid number (ORBIT="<< orbit << " BCID=" << bc << ")" << std::endl; + return; + } for (int eq = 0; eq < mNumberOfEquipments; eq++) { int EventSize = mEventSizePerEquipment[eq]; + if(EventSize == 0) continue; // Skips the Events sized with 0 + int EquipmentCounter = 0; int numOfPages = EventSize / PAYLOADMAXSPACE_W + 1; @@ -210,18 +229,21 @@ void HmpidCoder::writePaginatedEvent(uint32_t orbit, uint16_t bc) EquipmentCounter++; } nWordToRead = count; - while (count < PAYLOADDIMENSION_W) - mEventBufferPtr[HEADERDIMENSION_W + count++] = 0; - uint32_t MemSize = nWordToRead * sizeof(uint32_t) + HEADERDIMENSION_W * sizeof(uint32_t); + + int nWordsTail = (mFixedPacketLenght) ? PAYLOADDIMENSION_W : ((count / 8 + 1) * 8); + while (count < nWordsTail) + mEventBufferPtr[HEADERDIMENSION_W + count++] = 0; + uint32_t PackNum = mPacketCounterPerEquipment[eq]++; - writeHeader(mEventBufferPtr, MemSize, mEqIds[eq], PackNum, bc, orbit, PageNum); - saveEventPage(mFlpIds[eq]); + int PacketSize = writeHeader(mEventBufferPtr, nWordToRead, nWordsTail, mEqIds[eq], PackNum, bc, orbit, PageNum); + savePacket(mFlpIds[eq], PacketSize); } } return; } -void HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum) +int HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t WordsToRead, uint32_t PayloadWords, + int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum) { uint32_t CruId, LinkId; uint32_t TType = 0; @@ -231,6 +253,8 @@ void HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint uint32_t Busy = 3000; uint32_t PAR = 0; + uint32_t MemSize = WordsToRead * sizeof(uint32_t) + HEADERDIMENSION_W * sizeof(uint32_t); + uint32_t OffsetNext = PayloadWords * sizeof(uint32_t) + HEADERDIMENSION_W * sizeof(uint32_t); getEquipCoord(Equip, &CruId, &LinkId); // FEEID Header Size Header version @@ -238,7 +262,7 @@ void HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint // Priority System ID Buffer[1] = 0x00000100 | 0x00000006; // .....Memory Size HeOffsetNewPack; - Buffer[2] = (MemSize << 16) | 0x00002000; + Buffer[2] = (MemSize << 16) | (OffsetNext & 0x0000FFFF); // DW CruId PacNum Link Num Buffer[3] = 0x10000000 | ((CruId & 0x00FF) << 16) | ((PackNum & 0x0FF) << 8) | (LinkId & 0x0FF); Buffer[4] = 0x00000FFF & BCDI; @@ -253,51 +277,53 @@ void HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t MemSize, int Equip, uint Buffer[13] = PAR; Buffer[14] = 0xAAAA0001; Buffer[15] = 0xAAAA0001; - return; + return (OffsetNext); } void HmpidCoder::codeDigitsVector(std::vectordigits) { - uint32_t pv_orbit, orbit = 0; - uint16_t pv_bc, bc = 0; + int eq,col,dil,cha,mo,x,y, idx; + uint32_t pv_orbit = 0; + uint32_t orbit = 0; + uint16_t pv_bc = 0; + uint16_t bc = 0; uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); - int eq,col,dil,cha,mo,x,y, idx; -std::cout << ">>> Coding size "<< digits.size() << std::endl; -int padsCount =0; + // TODO: Add memory allocation error check + + int padsCount =0; for(o2::hmpid::Digit d : digits) { orbit = d.getOrbit(); bc = d.getBC(); if(orbit != pv_orbit || bc != pv_bc) { //the event is changed - if (pv_orbit != 0 || pv_bc != 0 ) { + if (pv_orbit != 0 || pv_bc != 0 ) { // isn't the first ! fillTheOutputBuffer(padMap); writePaginatedEvent(pv_orbit, pv_bc); } - memset(padMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + memset(padMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event pv_orbit = orbit; pv_bc = bc; } - Digit::Pad2Equipment(d.getPadID(),&eq, &col, &dil, &cha); - idx = getEquipmentPadIndex(eq, col, dil, cha); - // std::cout << ">>> "<< idx << " " << d <<" ("<>> "<< idx << " " << d <<" ("<>> Errore >"<<" abso("<< mo <<","<>> CPads set "<< padsCount << std::endl; std::free(padMap); + mPadsCoded += padsCount; + return; } -void HmpidCoder::codeDigitsTest(int Events, uint16_t charge) +void HmpidCoder::codeTest(int Events, uint16_t charge) { uint32_t orbit = 0; uint16_t bc = 0; @@ -325,12 +351,13 @@ void HmpidCoder::codeDigitsTest(int Events, uint16_t charge) } // ====================== FILES management functions ====================== -void HmpidCoder::saveEventPage(int Flp) +void HmpidCoder::savePacket(int Flp, int packetSize) { + mPacketsCoded++; if(Flp == 160) - fwrite(mEventBufferPtr, RAWBLOCKDIMENSION_W, sizeof(uint32_t), mOutStream160); + fwrite(mEventBufferPtr, packetSize, sizeof(uint8_t), mOutStream160); else - fwrite(mEventBufferPtr, RAWBLOCKDIMENSION_W, sizeof(uint32_t), mOutStream161); + fwrite(mEventBufferPtr, packetSize, sizeof(uint8_t), mOutStream161); return; } @@ -338,19 +365,21 @@ void HmpidCoder::saveEventPage(int Flp) void HmpidCoder::openOutputStream(const char *OutputFileName) { char FileName[512]; - sprintf(FileName, "%s%d%s", OutputFileName, 160, ".dat"); mOutStream160 = fopen(FileName, "wb"); if (mOutStream160 == 0) { LOG(ERROR) << "ERROR to open Output file " << FileName; throw 0; } + mFileName160 = FileName; + sprintf(FileName, "%s%d%s", OutputFileName, 161, ".dat"); mOutStream161 = fopen(FileName, "wb"); if (mOutStream161 == 0) { LOG(ERROR) << "ERROR to open Output file " << FileName; throw 0; } + mFileName161 = FileName; return; } @@ -360,3 +389,12 @@ void HmpidCoder::closeOutputStream() fclose(mOutStream161); return; } + +void HmpidCoder::dumpResults() +{ + std::cout << " **** HMPID RawFile Coder : results ****" << std::endl; + std::cout << " Created files : " << mFileName160 << " ," << mFileName161 << std::endl; + std::cout << " Number of Pads coded : " << mPadsCoded << std::endl; + std::cout << " Number of Packets written : " << mPacketsCoded << std::endl; + std::cout << " ----------------------------------------" << std::endl; +} diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index ccb511a9998ba..6095de8f32eab 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -9,8 +9,12 @@ # submit itself to any jurisdiction. o2_add_library(HMPIDWorkflow -# SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/RawFileReaderSpec.cxx src/DumpDigitsSpec.cxx - SOURCES src/DataDecoderSpec.cxx src/DigitReaderSpec.cxx src/ClusterizerSpec.cxx src/DumpDigitsSpec.cxx src/WriteRawFromDigitsSpec.cxx + SOURCES src/DataDecoderSpec.cxx + src/DigitReaderSpec.cxx + src/ClusterizerSpec.cxx + src/DumpDigitsSpec.cxx + src/ReadRawFileSpec.cxx + src/WriteRawFromDigitsSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::DetectorsRaw @@ -23,6 +27,11 @@ o2_add_executable(recoworkflow SOURCES src/HMPIDRecoWorkflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) +o2_add_executable(read-raw-file-workflow + COMPONENT_NAME hmpid + SOURCES src/read-raw-file-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + o2_add_executable(raw-to-digits-workflow COMPONENT_NAME hmpid SOURCES src/raw-to-digits-workflow.cxx diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index 81c701712f141..21e3227aa8706 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -8,12 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file DatDecoderSpec.h -/// \author Andrea Ferrero -/// -/// \brief Definition of a data processor to run the raw decoding -/// #ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ #define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ @@ -38,10 +32,12 @@ namespace hmpid void decodeTF(framework::ProcessingContext& pc); void decodeReadout(framework::ProcessingContext& pc); void decodeRawFile(framework::ProcessingContext& pc); - + void endOfStream(framework::EndOfStreamContext& ec) override; private: HmpidDecodeRawDigit *mDeco; + long mTotalDigits; + long mTotalFrames; }; diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index 252788704cad6..4d9d724c15bf1 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -20,6 +20,7 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" namespace o2 { @@ -33,7 +34,7 @@ namespace hmpid ~DumpDigitsTask() override = default; void init(framework::InitContext& ic) final; void run(framework::ProcessingContext& pc) final; - + void endOfStream(framework::EndOfStreamContext& ec) override; private: bool mPrintDigits = false; @@ -41,6 +42,8 @@ namespace hmpid std::string mOutputFileName = ""; std::ofstream mOsFile; + int mOrbit; + int mBc; }; o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h new file mode 100644 index 0000000000000..5a952d105cf74 --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h @@ -0,0 +1,43 @@ +// 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. + + +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_READRAWFILESPEC_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_READRAWFILESPEC_H_ + +#include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" +#include "HMPIDBase/Digit.h" + +namespace o2 +{ +namespace hmpid +{ + + class RawFileReaderTask : public framework::Task + { + public: + RawFileReaderTask() = default; + ~RawFileReaderTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + + private: + std::ifstream mInputFile{}; ///< input file + bool mPrint = false; ///< print debug messages + // auto stop(void); + }; + +o2::framework::DataProcessorSpec getReadRawFileSpec(std::string inputSpec = "HMP/RAWDATA"); + +} // end namespace hmpid +} // end namespace o2 + +#endif /* DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_READRAWFILESPEC_H_ */ diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h index 04d0386ba11a0..bfd44cbc588a6 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -8,16 +8,11 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file DatDecoderSpec.h -/// \author Andrea Ferrero -/// -/// \brief Definition of a data processor to run the raw decoding -/// #ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMDIGITS_H_ #define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMDIGITS_H_ +#include #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" #include "HMPIDBase/Digit.h" @@ -30,14 +25,24 @@ namespace hmpid class WriteRawFromDigitsTask : public framework::Task { public: - WriteRawFromDigitsTask() = default; + WriteRawFromDigitsTask() = default; ~WriteRawFromDigitsTask() override = default; void init(framework::InitContext& ic) final; void run(framework::ProcessingContext& pc) final; + void endOfStream(framework::EndOfStreamContext& ec) override; private: static bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); + void createRawFile(framework::ProcessingContext& pc); std::string mBaseFileName = ""; + std::vector mDigits; + bool mSkipEmpty = false; + bool mFixedPacketLenght = false; + bool mOrderTheEvents = true; + long mDigitsReceived; + long mFramesReceived; + bool mIsTheStremClosed = false; + }; o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index e2548e4747697..b6a4e983497f0 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -63,11 +63,11 @@ void DataDecoderTask::init(framework::InitContext& ic) { LOG(INFO) << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !"; - std::cout << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !" << std::endl; mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); mDeco->init(); - + mTotalDigits = 0; + mTotalFrames = 0; return; } @@ -77,26 +77,32 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) decodeTF(pc); // decodeReadout(pc); -// decodeRawFile(pc); +// decodeRawFile(pc); + +// LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; +// pc.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginHMP, "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); + + + // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); + + //--- theObj->Reset(); + //---- mfileOut.reset(); - LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; - pc.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginHMP, "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); +} +void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) +{ + // Records the statistics float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; float avgBusyTime[o2::hmpid::Geo::MAXEQUIPMENTS]; - uint32_t numOfSamples[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; TString filename = TString::Format("%s_%06d.root", "test", 1); - LOG(DEBUG) << "opening the stat file " << filename.Data(); -// std::unique_ptr mfileOut = nullptr; + LOG(INFO) << "Create the stat file " << filename.Data(); TFile mfileOut(TString::Format("%s", filename.Data()), "RECREATE"); - - // std::unique_ptr theObj; TTree * theObj; - // theObj = std::make_unique("o2hmp", "HMPID Data Decoding Statistic results"); theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); @@ -116,64 +122,37 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) numOfSamples[m][y][x] = mDeco->getPadSamples(m, x, y); sumOfCharges[m][y][x] = mDeco->getPadSum(m, x, y); squareOfCharges[m][y][x] = mDeco->getPadSquares(m, x, y); - // std::cout << "@ " << m <<","<cd(); + // theObj->Fill(); theObj->Write(); - // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); + LOG(INFO) << "End the Decoding ! Digits decoded = " << mTotalDigits << " Frames received = " << mTotalFrames; + // LOG(INFO)<< "Sleep 10 sec"<< std::endl; + // sleep(30); - //--- theObj->Reset(); - //---- mfileOut.reset(); + //ec.services().get().endOfStream(); + // ec.services().get().readyToQuit(framework::QuitRequest::Me); + return; } - -/* auto& digits = mDecoder->getOutputDigits(); - auto& orbits = mDecoder->getOrbits(); - - if (mPrint) { - for (auto d : digits) { - std::cout << " DE# " << d.getDetID() << " PadId " << d.getPadID() << " ADC " << d.getADC() << " time " << d.getTime().sampaTime << std::endl; - } - } - // send the output buffer via DPL - size_t digitsSize, orbitsSize; - char* digitsBuffer = createBuffer(digits, digitsSize); - char* orbitsBuffer = createBuffer(orbits, orbitsSize); - - // create the output message - auto freefct = [](void* data, void*) { free(data); }; -// pc.outputs().adoptChunk(Output{"MCH", "DIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr); -// pc.outputs().adoptChunk(Output{"MCH", "ORBITS", 0}, orbitsBuffer, orbitsSize, freefct, nullptr); -*/ - //_________________________________________________________________________________________________ // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) { - LOG(INFO) << "*********** In decodeTF **************"; + LOG(DEBUG) << "*********** In decodeTF **************"; // get the input buffer auto& inputs = pc.inputs(); DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); - -// auto& digitsV = pc.outputs().make>(Output{"HMP", "DIGITS", 0, Lifetime::Timeframe}); - for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - // mDeco->mDigits.clear(); - + mDeco->mDigits.clear(); uint32_t *theBuffer = (uint32_t *)it.raw(); - // std::cout << "Decode parser loop :"<< it.size() << " , " << it.offset() << std::endl; mDeco->setUpStream(theBuffer, it.size()+it.offset()); mDeco->decodePageFast(&theBuffer); -// for(auto d : mDeco->mDigits) -// digitsV.push_back(d); - - // pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); - + mTotalFrames++; + pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits);// + mTotalDigits += mDeco->mDigits.size(); + LOG(DEBUG) << "Writing " << mDeco->mDigits.size() << "/" << mTotalDigits << " Digits ..."; } return; } @@ -203,15 +182,22 @@ void DataDecoderTask::decodeRawFile(framework::ProcessingContext& pc) LOG(INFO) << "*********** In decode rawfile **************"; for (auto&& input : pc.inputs()) { - if (input.spec->binding == "rawfile") { - // const auto* header = o2::header::get(input.header); - // if (!header) { - // return; - // } - const o2::header::DataHeader* header = o2::header::get(input.header); - uint32_t *theBuffer = (uint32_t *)input.payload; - int pagesize = header->payloadSize; - std::cout << "Get page !" << std::endl; + if (input.spec->binding == "file") { + const header::DataHeader* header = o2::header::get(input.header); + if (!header) { + return; + } + + auto const* raw = input.payload; + size_t payloadSize = header->payloadSize; + + LOG(INFO) << " payloadSize=" << payloadSize; + if (payloadSize == 0) { + return; + } + + uint32_t *theBuffer = (uint32_t *)input.payload; + int pagesize = header->payloadSize; mDeco->setUpStream(theBuffer, pagesize); mDeco->decodePageFast(&theBuffer); } @@ -221,31 +207,24 @@ void DataDecoderTask::decodeRawFile(framework::ProcessingContext& pc) //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) -//o2::framework::DataPrecessorSpec getDecodingSpec() { std::vector inputs; -// inputs.emplace_back("TF", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); - inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); - - // inputs.emplace_back("rawfile", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); + inputs.emplace_back("file", o2::framework::ConcreteDataTypeMatcher{"ROUT", "RAWDATA"}, o2::framework::Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); // inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); - // outputs.emplace_back("HMP", "ORBITS", 0, o2::framework::Lifetime::Timeframe); - // outputs.emplace_back("HMP", "STATS", 0, o2::framework::Lifetime::Timeframe); - return DataProcessorSpec{ "HMP-DataDecoder", - inputs, + o2::framework::select(inputSpec.c_str()), outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"print", VariantType::Bool, false, {"print digits"}}} }; + Options{{"root-file", VariantType::String, "/tmp/hmpRawDecodeResults", {"Name of the Root file with the decoding results."}}} }; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index bcb364c202267..c491960a755ff 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -55,7 +55,7 @@ using RDH = o2::header::RDHAny; // Data decoder void DumpDigitsTask::init(framework::InitContext& ic) { - LOG(INFO) << "[HMPID Dump Digits - run] Dumping ..."; + LOG(INFO) << "[HMPID Dump Digits - init() ] "; mPrintDigits = ic.options().get("print"); mIsOutputOnFile = false; @@ -66,36 +66,53 @@ void DumpDigitsTask::init(framework::InitContext& ic) mIsOutputOnFile = true; } } + + if (mPrintDigits) { + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + } + if (mIsOutputOnFile) { + mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + } + + mOrbit = -1; + mBc = -1; return; } void DumpDigitsTask::run(framework::ProcessingContext& pc) { - //LOG(INFO) << "Enter Dump run..."; + LOG(DEBUG) << "[HMPID Dump Digits - run() ] Enter Dump ..."; for (auto&& input : pc.inputs()) { if (input.spec->binding == "digits") { auto digits = pc.inputs().get>("digits"); - LOG(INFO) << "The size of the vector =" << digits.size(); + LOG(DEBUG) << "The size of the vector =" << digits.size(); if (mPrintDigits) { - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - for(o2::hmpid::Digit Dig : digits) { - std::cout << Dig << std::endl; - } - std::cout << "---------------- HMP Dump Digits : EOF ------------------" << std::endl; + for(o2::hmpid::Digit Dig : digits) { + std::cout << Dig << std::endl; + } } if (mIsOutputOnFile) { - mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - for(o2::hmpid::Digit Dig : digits) { - mOsFile << Dig << std::endl; - } - mOsFile.close(); + for(o2::hmpid::Digit Dig : digits) { + mOsFile << Dig << std::endl; + if(Dig.getOrbit() != mOrbit || Dig.getBC() != mBc) { + mOrbit = Dig.getOrbit(); mBc = Dig.getBC(); + LOG(INFO) << "Event :" << mOrbit << " / " << mBc; + } + } } } } return; } +void DumpDigitsTask::endOfStream(framework::EndOfStreamContext& ec) +{ + mOsFile.close(); + LOG(INFO) << "End Dump !"; + return; +} + //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) //o2::framework::DataPrecessorSpec getDecodingSpec() diff --git a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx new file mode 100644 index 0000000000000..44428dad717cf --- /dev/null +++ b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx @@ -0,0 +1,153 @@ +// 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. + + +#include +#include +#include +#include + + + + + + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" + +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" +#include "DPLUtils/DPLRawParser.h" + + + + +#include "HMPIDWorkflow/ReadRawFileSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using namespace o2; +using namespace o2::framework; +using RDH = o2::header::RDHAny; + +//auto RawFileReaderTask::stop(void) +//{ +// LOG(INFO) << "Stop file reader"; +// mInputFile.close(); +// return; +//} + +void RawFileReaderTask::init(framework::InitContext& ic) +{ + LOG(INFO) << "Raw file reader init "; + + // read input parameters + mPrint = ic.options().get("print"); + std::string inFileName = ic.options().get("raw-file"); + mInputFile.open(inFileName, std::ios::binary); + if (!mInputFile.is_open()) { + throw std::invalid_argument("Cannot open input file \"" + inFileName + "\""); + } + + auto stop = [this]() { + LOG(INFO) << "stop file reader"; // close the input file + this->mInputFile.close(); + }; + ic.services().get().set(CallbackService::Id::Stop, stop); +} + + +void RawFileReaderTask::run(framework::ProcessingContext& pc) +{ + + RDH rdh; + char* outBuffer{nullptr}; + size_t bufSize{0}; + int numberOfFrames = 0; + LOG(INFO)<< "Sleep 5 sec"<< std::endl; + sleep(5); + + while (true) { + //usleep(100); + mInputFile.read((char*)(&rdh), sizeof(RDH)); // read the next RDH, stop if no more data is available + if (mInputFile.fail()) { + LOG(INFO) << "End of file ! Number of frames processed :" << numberOfFrames; + free(outBuffer); + mInputFile.close(); + // LOG(INFO)<< "Sleep 10 sec"<< std::endl; + // for(int i=0;i<10;i++) sleep(1); + pc.services().get().endOfStream(); + // pc.services().get().readyToQuit(framework::QuitRequest::Me); + break; + } + auto rdhVersion = o2::raw::RDHUtils::getVersion(rdh); + auto rdhHeaderSize = o2::raw::RDHUtils::getHeaderSize(rdh); + LOG(DEBUG) << "header_version=" << (int)rdhVersion; + if (rdhVersion < 6 || rdhHeaderSize != 64) { + LOG(INFO) << "Old or corrupted raw file, abort !"; + return; + } + auto frameSize = o2::raw::RDHUtils::getOffsetToNext(rdh); // get the frame size + LOG(DEBUG) << "frameSize=" << frameSize; + if (frameSize < rdhHeaderSize) { // stop if the frame size is too small + LOG(INFO) << "Wrong Frame size - frameSize too small: " << frameSize; + pc.services().get().endOfStream(); + return; + } + numberOfFrames++; + LOG(DEBUG) << "Process page " << numberOfFrames << " dim = " << frameSize; + + outBuffer = (char*)realloc(outBuffer, bufSize + frameSize); // allocate the buffer + if (outBuffer == nullptr) { + LOG(INFO) << "Buffer allocation error. Abort !"; + pc.services().get().endOfStream(); + return; + } + memcpy(outBuffer, &rdh, rdhHeaderSize); // fill the buffer + mInputFile.read(outBuffer + rdhHeaderSize, frameSize - rdhHeaderSize); + if (mInputFile.fail()) { // Could be EoF + LOG(INFO) << "end of file reached"; + free(outBuffer); + pc.services().get().endOfStream(); + break; // probably reached eof + } + bufSize = frameSize; // Set the buffer pointer + pc.outputs().snapshot(Output{"HMP","RAWDATA"}, outBuffer, bufSize); + } // while (true) +} + +//_________________________________________________________________________________________________ +// clang-format off +o2::framework::DataProcessorSpec getReadRawFileSpec(std::string inputSpec) +{ + std::vector inputs; + return DataProcessorSpec{ + "HMP-ReadRawFile", + inputs, + Outputs{OutputSpec{"HMP", "RAWDATA", 0, Lifetime::Timeframe}}, + AlgorithmSpec{adaptFromTask()}, + Options{{"raw-file", VariantType::String, "", {"Raw input file name"}}, + {"print", VariantType::Bool, false, {"verbose output"}}}}; +} +// clang-format on + +} // end namespace hmpid +} // end namespace o2 + diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index 00ede675778b3..6603e634b96b1 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -9,12 +9,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file DatDecoderSpec.cxx -/// \author -/// -/// \brief Implementation of a data processor to run the HMPID raw decoding -/// #include #include @@ -34,6 +28,7 @@ #include "Framework/Task.h" #include "Framework/WorkflowSpec.h" #include "Framework/Logger.h" +#include "Framework/InputRecordWalker.h" #include "Headers/RAWDataHeader.h" #include "DetectorsRaw/RDHUtils.h" @@ -57,10 +52,13 @@ using RDH = o2::header::RDHAny; // Data decoder void WriteRawFromDigitsTask::init(framework::InitContext& ic) { - LOG(INFO) << "[HMPID Write Raw File From Digits vector - run] Dumping ..."; + LOG(INFO) << "[HMPID Write Raw File From Digits vector - init()]"; mBaseFileName = ic.options().get("out-file"); - - + mSkipEmpty = ic.options().get("skip-empty"); + mFixedPacketLenght = ic.options().get("fixed-lenght"); + mOrderTheEvents = ic.options().get("order-events"); + mDigitsReceived = 0; + mFramesReceived = 0; return; } @@ -69,10 +67,8 @@ bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2:: uint64_t t1,t2; t1 = d1.getTriggerID(); t2 = d2.getTriggerID(); - if (t1 < t2) return true; if (t2 < t1) return false; - if (d1.getPadID() < d2.getPadID()) return true; return false; } @@ -80,28 +76,43 @@ bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2:: void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) { - for (auto&& input : pc.inputs()) { - if (input.spec->binding == "digits") { - auto digits = pc.inputs().get>("digits"); - - LOG(INFO) << "The size of the digits vector " << digits.size(); - sort(digits.begin(), digits.end(), eventEquipPadsComparision); - LOG(INFO) << "Digits sorted ! " ; - - HmpidCoder cod(Geo::MAXEQUIPMENTS); - cod.openOutputStream(mBaseFileName.c_str()); - //cod.codeDigitsTest(2, 100); - cod.codeDigitsVector(digits); - cod.closeOutputStream(); - LOG(INFO) << "Raw File created ! " ; - } + + for (auto const& ref : InputRecordWalker(pc.inputs())) { + std::vector digits = pc.inputs().get>(ref); + mDigits.insert(mDigits.end(), digits.begin(), digits.end()); + mDigitsReceived += digits.size(); + mFramesReceived++; + LOG(INFO) << "run() Digits received =" << mDigitsReceived << " frames = " << mFramesReceived; + } + return; +} + +void WriteRawFromDigitsTask::createRawFile(framework::ProcessingContext& pc) +{ + return; +} + + +void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) +{ + LOG(INFO) << "Received an End Of Stream !"; + HmpidCoder cod(Geo::MAXEQUIPMENTS, mSkipEmpty, mFixedPacketLenght); + cod.openOutputStream(mBaseFileName.c_str()); + + if(mOrderTheEvents) { + sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); + LOG(INFO) << mDigits.size() << " Digits sorted ! " ; } + //cod.codeDigitsTest(2, 100); + cod.codeDigitsVector(mDigits); + cod.closeOutputStream(); + LOG(INFO) << "Raw File created ! Digits received = " << mDigitsReceived << " Frame received =" << mFramesReceived; + cod.dumpResults(); return; } //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec) -//o2::framework::DataPrecessorSpec getDecodingSpec() { std::vector inputs; inputs.emplace_back("digits", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); @@ -109,11 +120,14 @@ o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec std::vector outputs; return DataProcessorSpec{ - "HMP-WriteRawFrtomDigits", + "HMP-WriteRawFromDigits", inputs, outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"out-file", VariantType::String, "hmpidRaw", {"name of the output file"}}} }; + Options{{"out-file", VariantType::String, "hmpidRaw", {"name of the output file"}}, + {"order-events", VariantType::Bool, false, {"order the events time"}}, + {"skip-empty", VariantType::Bool, false, {"skip empty events"}}, + {"fixed-lenght", VariantType::Bool, false, {"fixed lenght packets = 8K bytes"}}}}; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx index c84533839ce68..1b0936c00414a 100644 --- a/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx @@ -23,6 +23,18 @@ #include "Framework/CallbackService.h" #include "Framework/ControlService.h" #include "Framework/Task.h" +#include "Framework/CompletionPolicy.h" +#include "Framework/CompletionPolicyHelpers.h" +#include "Framework/DispatchPolicy.h" + +// customize the completion policy +void customize(std::vector& policies) +{ + using o2::framework::CompletionPolicy; + using o2::framework::CompletionPolicyHelpers; + policies.push_back(CompletionPolicyHelpers::defineByName("digit-hmpid-dump", CompletionPolicy::CompletionOp::Consume)); +} + #include "Framework/runDataProcessing.h" #include "HMPIDWorkflow/DumpDigitsSpec.h" diff --git a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx index ea0ee629fcce7..a674bd849cc62 100644 --- a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx @@ -8,21 +8,41 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file raw-to-digits-workflow.cxx -/// \author Andrea Ferrero -/// -/// \brief This is an executable that runs the decoding via DPL. -/// -/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. -/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow -/// #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" #include "Framework/CallbackService.h" #include "Framework/ControlService.h" #include "Framework/Task.h" +#include "Framework/CompletionPolicy.h" +#include "Framework/CompletionPolicyHelpers.h" +#include "Framework/DispatchPolicy.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/InputRecordWalker.h" +#include "Framework/Logger.h" +#include "Framework/ConfigParamSpec.h" + +// customize dispatch policy, dispatch immediately what is ready +void customize(std::vector& policies) +{ + using DispatchOp = o2::framework::DispatchPolicy::DispatchOp; + auto readerMatcher = [](auto const& spec) { + return true; + }; + auto triggerMatcher = [](auto const& query) { + return true; + }; + policies.push_back({"decoded-hmpid-digits", readerMatcher, DispatchOp::WhenReady, triggerMatcher}); +} + +// customize the completion policy +void customize(std::vector& policies) +{ + using o2::framework::CompletionPolicy; + using o2::framework::CompletionPolicyHelpers; + policies.push_back(CompletionPolicyHelpers::defineByName("raw-hmpid-decode", CompletionPolicy::CompletionOp::Consume)); +} + #include "Framework/runDataProcessing.h" #include "HMPIDWorkflow/DataDecoderSpec.h" diff --git a/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx b/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx new file mode 100644 index 0000000000000..eba897b0aa2e7 --- /dev/null +++ b/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx @@ -0,0 +1,62 @@ +// 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. + +#include +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/DispatchPolicy.h" +#include "Framework/Task.h" + + +// customize dispatch policy, dispatch immediately what is ready +void customize(std::vector& policies) +{ + using DispatchOp = o2::framework::DispatchPolicy::DispatchOp; + // we customize all devices to dispatch data immediately + auto readerMatcher = [](auto const& spec) { + // + // std::cout << "customize reader = " << spec.name << std::endl; +// std::cout << "PingReader" << std::endl; + return true; +// return std::regex_match(spec.name.begin(), spec.name.end(), std::regex(".*-reader")); + }; + auto triggerMatcher = [](auto const& query) { + // a bit of a hack but we want this to be configurable from the command line, + // however DispatchPolicy is inserted before all other setup. Triggering depending + // on the global variable set from the command line option. If scheduled messages + // are not triggered they are sent out at the end of the computation + // std::cout << "customize Trigger origin = " << query.origin << " description = " << query.description << std::endl; + // std::cout << "PingTrig" << std::endl; + return true; +// return gDispatchTrigger.origin == query.origin && gDispatchTrigger.description == query.description; + }; + policies.push_back({"pr-f-re", readerMatcher, DispatchOp::WhenReady, triggerMatcher}); +} + + +#include "Framework/runDataProcessing.h" + +#include "HMPIDWorkflow/ReadRawFileSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + // The producer to generate some data in the workflow + DataProcessorSpec producer = o2::hmpid::getReadRawFileSpec(); + specs.push_back(producer); + + return specs; +} diff --git a/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx index f9fcb800bb3ed..dda6d2a9ab76e 100644 --- a/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx @@ -8,21 +8,24 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file raw-to-digits-workflow.cxx -/// \author Andrea Ferrero -/// -/// \brief This is an executable that runs the decoding via DPL. -/// -/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. -/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow -/// #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" #include "Framework/CallbackService.h" #include "Framework/ControlService.h" #include "Framework/Task.h" +#include "Framework/CompletionPolicy.h" +#include "Framework/CompletionPolicyHelpers.h" +#include "Framework/DispatchPolicy.h" + +// customize the completion policy +void customize(std::vector& policies) +{ + using o2::framework::CompletionPolicy; + using o2::framework::CompletionPolicyHelpers; + policies.push_back(CompletionPolicyHelpers::defineByName("digit-hmpid-write", CompletionPolicy::CompletionOp::Consume)); +} + #include "Framework/runDataProcessing.h" #include "HMPIDWorkflow/WriteRawFromDigitsSpec.h" From 86f188c27923f4c836abb707c3d72d0de1bb150c Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 4 Feb 2021 12:33:48 +0100 Subject: [PATCH 173/208] Some fix --- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 1 + .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 1 - .../HMPID/workflow/src/DumpDigitsSpec.cxx | 33 +++++++++---------- .../workflow/src/WriteRawFromDigitsSpec.cxx | 6 ---- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index 4d9d724c15bf1..d9150e5a48e3f 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -44,6 +44,7 @@ namespace hmpid int mOrbit; int mBc; + long mDigitsReceived; }; o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h index bfd44cbc588a6..9d27be22a24b8 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -33,7 +33,6 @@ namespace hmpid private: static bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); - void createRawFile(framework::ProcessingContext& pc); std::string mBaseFileName = ""; std::vector mDigits; bool mSkipEmpty = false; diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index c491960a755ff..fc9d144042680 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -76,29 +76,28 @@ void DumpDigitsTask::init(framework::InitContext& ic) mOrbit = -1; mBc = -1; + mDigitsReceived = 0; return; } void DumpDigitsTask::run(framework::ProcessingContext& pc) { LOG(DEBUG) << "[HMPID Dump Digits - run() ] Enter Dump ..."; - - for (auto&& input : pc.inputs()) { - if (input.spec->binding == "digits") { - auto digits = pc.inputs().get>("digits"); - LOG(DEBUG) << "The size of the vector =" << digits.size(); - if (mPrintDigits) { - for(o2::hmpid::Digit Dig : digits) { - std::cout << Dig << std::endl; - } + for (auto const& ref : InputRecordWalker(pc.inputs())) { + std::vector digits = pc.inputs().get>(ref); + LOG(DEBUG) << "The size of the vector =" << digits.size(); + mDigitsReceived += digits.size(); + if (mPrintDigits) { + for(o2::hmpid::Digit Dig : digits) { + std::cout << Dig << std::endl; } - if (mIsOutputOnFile) { - for(o2::hmpid::Digit Dig : digits) { - mOsFile << Dig << std::endl; - if(Dig.getOrbit() != mOrbit || Dig.getBC() != mBc) { - mOrbit = Dig.getOrbit(); mBc = Dig.getBC(); - LOG(INFO) << "Event :" << mOrbit << " / " << mBc; - } + } + if (mIsOutputOnFile) { + for(o2::hmpid::Digit Dig : digits) { + mOsFile << Dig << std::endl; + if(Dig.getOrbit() != mOrbit || Dig.getBC() != mBc) { + mOrbit = Dig.getOrbit(); mBc = Dig.getBC(); + LOG(INFO) << "Event :" << mOrbit << " / " << mBc; } } } @@ -109,7 +108,7 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) void DumpDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { mOsFile.close(); - LOG(INFO) << "End Dump !"; + LOG(INFO) << "End Digits Dump ! Dumped digits = " << mDigitsReceived; return; } diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index 6603e634b96b1..df46b6fe84686 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -87,12 +87,6 @@ void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) return; } -void WriteRawFromDigitsTask::createRawFile(framework::ProcessingContext& pc) -{ - return; -} - - void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { LOG(INFO) << "Received an End Of Stream !"; From b91051b78587484cdc9fcfe4314e56932e60dfee Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 4 Feb 2021 13:08:02 +0100 Subject: [PATCH 174/208] Version 0 - Compiled and tested. Works fine the Read-decode-write workflow. tested with huge raw file, 176'235'199 digits. --- Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 1 + Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx | 5 ++--- Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index fc9d144042680..228ca63af4eec 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -33,6 +33,7 @@ #include "Framework/Task.h" #include "Framework/WorkflowSpec.h" #include "Framework/Logger.h" +#include "Framework/InputRecordWalker.h" #include "Headers/RAWDataHeader.h" #include "DetectorsRaw/RDHUtils.h" diff --git a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx index 44428dad717cf..f0ad87c6efd2f 100644 --- a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx +++ b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx @@ -91,10 +91,8 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) LOG(INFO) << "End of file ! Number of frames processed :" << numberOfFrames; free(outBuffer); mInputFile.close(); - // LOG(INFO)<< "Sleep 10 sec"<< std::endl; - // for(int i=0;i<10;i++) sleep(1); pc.services().get().endOfStream(); - // pc.services().get().readyToQuit(framework::QuitRequest::Me); + pc.services().get().readyToQuit(framework::QuitRequest::Me); break; } auto rdhVersion = o2::raw::RDHUtils::getVersion(rdh); @@ -126,6 +124,7 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) LOG(INFO) << "end of file reached"; free(outBuffer); pc.services().get().endOfStream(); + pc.services().get().readyToQuit(framework::QuitRequest::Me); break; // probably reached eof } bufSize = frameSize; // Set the buffer pointer diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index df46b6fe84686..d2655edecf038 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -97,7 +97,6 @@ void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); LOG(INFO) << mDigits.size() << " Digits sorted ! " ; } - //cod.codeDigitsTest(2, 100); cod.codeDigitsVector(mDigits); cod.closeOutputStream(); LOG(INFO) << "Raw File created ! Digits received = " << mDigitsReceived << " Frame received =" << mFramesReceived; From e9c5905698bb97baa955bbc827f810650aa965f8 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 4 Feb 2021 15:57:21 +0100 Subject: [PATCH 175/208] V0.1 - Compiled and Tested Add the syncronous write of the File ! --- .../include/HMPIDSimulation/HmpidCoder.h | 12 ++- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 90 +++++++++++++------ .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 2 + .../workflow/src/WriteRawFromDigitsSpec.cxx | 24 +++-- 4 files changed, 91 insertions(+), 37 deletions(-) diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h index b6efa62ca85ed..e435e9fcc2cc9 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h @@ -78,6 +78,12 @@ class HmpidCoder long mPadsCoded; long mPacketsCoded; + std::vector mDigits; + uint32_t mPreviousOrbit = 0; + uint16_t mPreviousBc = 0; + long mLastProcessedDigit =0; + uint32_t *mPadMap; + public: HmpidCoder(int numOfEquipments, bool skipEmptyEvents = false, bool fixedPacketLenght = true); virtual ~HmpidCoder(); @@ -123,11 +129,14 @@ class HmpidCoder return(mOccupancyPercentage); }; + int addDigitsChunk(std::vector &digits); + void codeDigitsChunk(bool flushBuffer = false); + void codeDigitsVector(std::vector &digits); + void openOutputStream(const char *OutputFileName); void closeOutputStream(); void codeRandomEvent(uint32_t orbit, uint16_t bc); - void codeDigitsVector(std::vector); void codeTest(int Events, uint16_t charge); void dumpResults(); @@ -136,6 +145,7 @@ class HmpidCoder void createRandomPayloadPerEvent(); void savePacket(int Flp, int packetSize); int calculateNumberOfPads(); + void codeEventChunkDigits(std::vector &digits, bool flushVector = false); private: void getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId); diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index 866d776f6d368..e81fea90fffc3 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -43,6 +43,10 @@ HmpidCoder::HmpidCoder(int numOfEquipments, bool skipEmptyEvents, bool fixedPack mPayloadBufferPtr = (uint32_t *) std::malloc(mNumberOfEquipments * sizeof(uint32_t) * mPailoadBufferDimPerEquipment ); mEventBufferBasePtr = (uint32_t *) std::malloc(sizeof(uint32_t) * RAWBLOCKDIMENSION_W); mEventBufferPtr = mEventBufferBasePtr; + + mPadMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + // TODO: Add memory allocation error check + reset(); } @@ -52,6 +56,7 @@ HmpidCoder::~HmpidCoder() // TODO Auto-generated destructor stub std::free(mPayloadBufferPtr); std::free(mEventBufferBasePtr); + std::free(mPadMap); } void HmpidCoder::reset() @@ -59,6 +64,12 @@ void HmpidCoder::reset() srand( (unsigned)time(NULL) ); mPadsCoded = 0; mPacketsCoded = 0; + mDigits.clear(); + mPreviousOrbit = 0; + mPreviousBc = 0; + mLastProcessedDigit =0; + + return; } // ===================== Random production of Raw Files =================== @@ -98,13 +109,11 @@ void HmpidCoder::fillPadsMap(uint32_t *padMap) void HmpidCoder::createRandomPayloadPerEvent() { - uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); - memset(padMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); - fillPadsMap(padMap); - fillTheOutputBuffer(padMap); + fillPadsMap(mPadMap); + fillTheOutputBuffer(mPadMap); - std::free(padMap); return; } @@ -280,46 +289,72 @@ int HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t WordsToRead, uint32_t Pay return (OffsetNext); } -void HmpidCoder::codeDigitsVector(std::vectordigits) +void HmpidCoder::codeDigitsChunk(bool flushBuffer) +{ + codeEventChunkDigits(mDigits, flushBuffer); + return; +} + +int HmpidCoder::addDigitsChunk(std::vector &digits) +{ + mDigits.insert(mDigits.end(), digits.begin(), digits.end()); + return(mDigits.size()); +} + +void HmpidCoder::codeDigitsVector(std::vector &digits) +{ + codeEventChunkDigits(digits, true); + return; +} + +void HmpidCoder::codeEventChunkDigits(std::vector &digits, bool flushVector) { int eq,col,dil,cha,mo,x,y, idx; - uint32_t pv_orbit = 0; uint32_t orbit = 0; - uint16_t pv_bc = 0; uint16_t bc = 0; - uint32_t *padMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); - // TODO: Add memory allocation error check - int padsCount =0; + int lastEventDigit = -1; + mLastProcessedDigit = -1; + for(o2::hmpid::Digit d : digits) { orbit = d.getOrbit(); bc = d.getBC(); - if(orbit != pv_orbit || bc != pv_bc) { //the event is changed - if (pv_orbit != 0 || pv_bc != 0 ) { // isn't the first ! - fillTheOutputBuffer(padMap); - writePaginatedEvent(pv_orbit, pv_bc); + lastEventDigit++; + + if(orbit != mPreviousOrbit || bc != mPreviousBc) { //the event is changed + if (mPreviousOrbit != 0 || mPreviousBc != 0 ) { // isn't the first ! + fillTheOutputBuffer(mPadMap); + writePaginatedEvent(mPreviousOrbit, mPreviousBc); + mLastProcessedDigit = lastEventDigit; } - memset(padMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event - pv_orbit = orbit; - pv_bc = bc; + memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event + mPreviousOrbit = orbit; + mPreviousBc = bc; } Digit::Pad2Equipment(d.getPadID(),&eq, &col, &dil, &cha); // From Digit to Hardware coords eq = mEqIds[eq]; // converts the Equipment Id in Cru/Link position ref idx = getEquipmentPadIndex(eq, col, dil, cha); // finally to the unique padmap index - if(padMap[idx] != 0) { // We already have the pad set + if(mPadMap[idx] != 0) { // We already have the pad set std::cerr << "HmpidCoder [ERROR] : Duplicated DIGIT ="<< d <<" ("<("order-events"); mDigitsReceived = 0; mFramesReceived = 0; + + mCod = new HmpidCoder(Geo::MAXEQUIPMENTS, mSkipEmpty, mFixedPacketLenght); + mCod->reset(); + mCod->openOutputStream(mBaseFileName.c_str()); + return; } @@ -76,10 +81,14 @@ bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2:: void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) { - for (auto const& ref : InputRecordWalker(pc.inputs())) { std::vector digits = pc.inputs().get>(ref); - mDigits.insert(mDigits.end(), digits.begin(), digits.end()); + if(mOrderTheEvents) { + mDigits.insert(mDigits.end(), digits.begin(), digits.end()); + } else { + mCod->addDigitsChunk(digits); + mCod->codeDigitsChunk(); + } mDigitsReceived += digits.size(); mFramesReceived++; LOG(INFO) << "run() Digits received =" << mDigitsReceived << " frames = " << mFramesReceived; @@ -90,17 +99,16 @@ void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { LOG(INFO) << "Received an End Of Stream !"; - HmpidCoder cod(Geo::MAXEQUIPMENTS, mSkipEmpty, mFixedPacketLenght); - cod.openOutputStream(mBaseFileName.c_str()); - if(mOrderTheEvents) { sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); LOG(INFO) << mDigits.size() << " Digits sorted ! " ; + mCod->codeDigitsVector(mDigits); + } else { + mCod->codeDigitsChunk(true); } - cod.codeDigitsVector(mDigits); - cod.closeOutputStream(); + mCod->closeOutputStream(); LOG(INFO) << "Raw File created ! Digits received = " << mDigitsReceived << " Frame received =" << mFramesReceived; - cod.dumpResults(); + mCod->dumpResults(); return; } From 2761fc4a3c39b4d643f8f574c88435efe98796a5 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 5 Feb 2021 10:58:55 +0100 Subject: [PATCH 176/208] V 1. Compiled and tested. Run modules in readme, implements the full streaming flow. Correct Root object creation. --- .../HMPID/base/include/HMPIDBase/Common.h | 73 ++++++++ .../HMPIDReconstruction/HmpidEquipment.h | 2 +- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 9 +- .../reconstruction/src/HmpidEquipment.cxx | 2 +- Detectors/HMPID/workflow/README.md | 91 ++++++++++ .../include/HMPIDWorkflow/DataDecoderSpec.h | 3 + .../include/HMPIDWorkflow/DumpDigitsSpec.h | 4 + .../HMPIDWorkflow/RawFileReaderSpec.h_trash | 49 ------ .../include/HMPIDWorkflow/ReadRawFileSpec.h | 5 +- .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 3 + .../HMPID/workflow/src/DataDecoderSpec.cxx | 83 ++++----- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 16 +- .../workflow/src/RawFileReaderSpec.cxx_trash | 157 ------------------ .../HMPID/workflow/src/ReadRawFileSpec.cxx | 29 ++-- .../workflow/src/WriteRawFromDigitsSpec.cxx | 12 +- .../src/rawfile-to-digits-workflow.cxx_trash | 43 ----- 16 files changed, 261 insertions(+), 320 deletions(-) create mode 100644 Detectors/HMPID/base/include/HMPIDBase/Common.h create mode 100644 Detectors/HMPID/workflow/README.md delete mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash delete mode 100644 Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash delete mode 100644 Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash diff --git a/Detectors/HMPID/base/include/HMPIDBase/Common.h b/Detectors/HMPID/base/include/HMPIDBase/Common.h new file mode 100644 index 0000000000000..37fc38f9049c1 --- /dev/null +++ b/Detectors/HMPID/base/include/HMPIDBase/Common.h @@ -0,0 +1,73 @@ +/* + * Common.h + * + * Created on: 5 feb 2021 + * Author: fap + */ + +#ifndef DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_COMMON_H_ +#define DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_COMMON_H_ + +#include +#include "Framework/Logger.h" + +namespace o2 +{ +namespace hmpid +{ + +// ------- Execution time functions +class ExecutionTimer +{ +private: + TStopwatch mTimer; + Double_t mStartTime; + Double_t mLastLogTime; + Double_t mElapseLogTime; + +public: + ExecutionTimer() { + mStartTime = 0; + mLastLogTime = 0; + mElapseLogTime = 10; // default 10 seconds + }; + + ~ExecutionTimer() {}; + + Double_t getElapseLogTime() { return mElapseLogTime; }; + void setElapseLogTime(Double_t interval) { mElapseLogTime = interval; return; }; + + void start() { + mStartTime = mTimer.CpuTime(); + mLastLogTime = mStartTime; + mTimer.Start(false); + return; + }; + + void stop() { + mTimer.Stop(); + return; + }; + + void logMes(std::string const message) { + LOG(INFO) << message << " Execution time = " << (mTimer.CpuTime() - mStartTime); + mTimer.Continue(); + return; + }; + + void elapseMes(std::string const message) { + if(mTimer.CpuTime() - mLastLogTime > mElapseLogTime) { + LOG(INFO) << message << " Execution time = " << (mTimer.CpuTime() - mStartTime); + mLastLogTime = mTimer.CpuTime(); + } + mTimer.Continue(); + return; + }; + +}; + +} +} + + +#endif /* DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_COMMON_H_ */ diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h index 2ed68883b2064..91f91987102ad 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h @@ -59,7 +59,7 @@ const int TH_NULLBUFFERPOINTER = 13; const int TH_BUFFEREMPTY = 12; const int TH_WRONGBUFFERDIM = 11; - +const uint64_t OUTRANGEEVENTNUMBER = 0x1FFFFFFFFFFF; class HmpidEquipment diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 5217550c16b0f..63b3102e33215 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -123,6 +123,10 @@ void HmpidDecoder::init() mEndStreamPtr = 0; mStartStreamPtr = 0; + for (int i = 0; i < mNumberOfEquipments; i++) { + mTheEquipments[i]->init(); + } + } /// Returns the Equipment Index (Pointer of the array) converting @@ -437,6 +441,9 @@ void HmpidDecoder::updateStatistics(HmpidEquipment *eq) eq->mNumberOfWrongEvents += 1; eq->mTotalPads += eq->mSampleNumber; eq->mTotalErrors += eq->mErrorsCounter; + + // std::cout << ">>>>.. end >>> "<mNumberOfEvents<<" :" <mEventSize<<","<< eq->mEventSizeAverage<< ", "<mEventNumber<<" "<mEventNumber) { // Is a new event - if (eq->mEventNumber != -1) { // skip the first + if (eq->mEventNumber != OUTRANGEEVENTNUMBER) { // skip the first updateStatistics(eq); // update previous statistics } eq->mNumberOfEvents++; diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx index ec1c99517bc06..9e92ac1151043 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx @@ -60,7 +60,7 @@ void HmpidEquipment::init() mErrorsCounter = 0; mErrorPadsPerEvent = 0; - mEventNumber = -1; + mEventNumber = OUTRANGEEVENTNUMBER; // The Magic out-range event number mNumberOfEvents = 0; mBusyTimeValue = 0.0; diff --git a/Detectors/HMPID/workflow/README.md b/Detectors/HMPID/workflow/README.md new file mode 100644 index 0000000000000..6e09e8bd71469 --- /dev/null +++ b/Detectors/HMPID/workflow/README.md @@ -0,0 +1,91 @@ + + +# DPL workflows for the HMPID + +## HMPID DPL processors + +* `hmpid-read-raw-file` reads data from ReadOut Raw File and outputs a stream of RDH6 pages as HMP/RAWDATA stream +* `hmpid-raw-to-digits` decodes the input raw pages stream (HMP/RAWDATA) and produces a vector of o2::hmpid::Digits (HMP/DIGITS) +* `hmpid-write-raw-from-digits` codes input o2::hmpid::Digits vector (HMP/DIGITS) into the binary HMPID raw file +* `hmpid-dump-digits` dumps the input o2::hmpid::Digits vector (HMP/DIGITS) to the stdout or in a ASCII file + +### Workflow example +The input is a HMPID rawfile and after the decoding the result is a reconstructed rawfile. + +``` + o2-hmpid-read-raw-file-workflow --raw-file test_full_flp1.raw -b | o2-hmpid-raw-to-digits-workflow -b | o2-hmpid-write-raw-from-digits-workflow --out-file /tmp/pippo -b +``` + +This reads the `test_full_flp1.raw` file and after the decodeing produce a couple of raw files in the /tmp/ folder that are prefixed with `pippo` + + + +### o2-hmpid-read-raw-file-workflow +Reads data from ReadOut Raw File and outputs a stream of RDH6 pages as HMP/RAWDATA stream. + +Display all options + +``` +o2-hmpid-read-raw-file-workflow --help full +``` + +Data processor options: HMP-ReadRawFile: + +``` +--raw-file arg Raw input file name +``` + +### o2-hmpid-raw-to-digits-workflow +Decodes the input raw pages stream (HMP/RAWDATA) and produces a vector of o2::hmpid::Digits (HMP/DIGITS). + +Display all options + +``` +o2-hmpid-raw-to-digits-workflow --help full +``` + +Data processor options: HMP-DataDecoder: + +``` + --root-file arg (=/tmp/hmpRawDecodeResults) + Name of the Root file with the decoding + results. +``` + + +### o2-hmpid-write-raw-from-digits-workflow +Codes input o2::hmpid::Digits vector (HMP/DIGITS) into the binary HMPID raw file. + +Display all options + +``` +o2-hmpid-write-raw-from-digits-workflow --help full +``` + +Data processor options: HMP-WriteRawFromDigits: + +``` + --out-file arg (=hmpidRaw) name prefix of the two output files + --order-events order the events in ascending time + --skip-empty skip empty events + --fixed-lenght fixed lenght packets = 8K bytes +``` + + +### o2-hmpid-dump-digits-workflow +Dumps the input o2::hmpid::Digits vector (HMP/DIGITS) to the stdout or in a ASCII file. + +Display all options + +``` +o2-hmpid-dump-digits-workflow --help full +``` + +Data processor options: HMP-DigitsDump: + +``` + --out-file arg name of the output file + --print print digits (default false ) +``` diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index 21e3227aa8706..035235156a047 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -15,6 +15,7 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" +#include "HMPIDBase/Common.h" #include "HMPIDReconstruction/HmpidDecodeRawMem.h" namespace o2 @@ -38,7 +39,9 @@ namespace hmpid HmpidDecodeRawDigit *mDeco; long mTotalDigits; long mTotalFrames; + std::string mRootStatFile; + ExecutionTimer mExTimer; }; o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec = "TF:HMP/RAWDATA"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index d9150e5a48e3f..615486fa44960 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -20,6 +20,8 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" + +#include "HMPIDBase/Common.h" #include "Framework/WorkflowSpec.h" namespace o2 @@ -45,6 +47,8 @@ namespace hmpid int mOrbit; int mBc; long mDigitsReceived; + + ExecutionTimer mExTimer; }; o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash b/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash deleted file mode 100644 index 90f252aa0afc1..0000000000000 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/RawFileReaderSpec.h_trash +++ /dev/null @@ -1,49 +0,0 @@ -/* - * RawFilereader.h - * - * Created on: 18 gen 2021 - * Author: fap - */ - -#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ -#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ - -//#include -//#include -#include -//#include -//#include "Framework/CallbackService.h" -//#include "Framework/ConfigParamRegistry.h" -//#include "Framework/ControlService.h" -//#include "Framework/DataProcessorSpec.h" -//#include "Framework/Lifetime.h" -//#include "Framework/Output.h" -#include "Framework/Task.h" -//#include "Framework/WorkflowSpec.h" -#include "Framework/DataProcessorSpec.h" -//#include "Framework/runDataProcessing.h" - -namespace o2 -{ -namespace hmpid -{ - -class RawFileReaderTask : public framework::Task -{ - public: - RawFileReaderTask() = default; - ~RawFileReaderTask() override = default; - void init(framework::InitContext& ic) final; - void run(framework::ProcessingContext& pc) final; - - private: - std::ifstream mInputFile{}; ///< input file -}; - -o2::framework::DataProcessorSpec getRawFileReaderSpec(); -} // end namespace hmpid -} // end namespace o2 - - - -#endif /* DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_RAWFILEREADERSPEC_H_TRASH_ */ diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h index 5a952d105cf74..fab72e3185f12 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h @@ -14,6 +14,8 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" + +#include "HMPIDBase/Common.h" #include "HMPIDBase/Digit.h" namespace o2 @@ -32,7 +34,8 @@ namespace hmpid private: std::ifstream mInputFile{}; ///< input file bool mPrint = false; ///< print debug messages - // auto stop(void); + + ExecutionTimer mExTimer; }; o2::framework::DataProcessorSpec getReadRawFileSpec(std::string inputSpec = "HMP/RAWDATA"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h index e21bae9bb6cf2..54ac4d140a2b6 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -15,6 +15,8 @@ #include #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" + +#include "HMPIDBase/Common.h" #include "HMPIDBase/Digit.h" #include "HMPIDSimulation/HmpidCoder.h" @@ -44,6 +46,7 @@ namespace hmpid bool mIsTheStremClosed = false; HmpidCoder *mCod; + ExecutionTimer mExTimer; }; o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index b6a4e983497f0..0827dd287b185 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -64,76 +64,85 @@ void DataDecoderTask::init(framework::InitContext& ic) LOG(INFO) << "[HMPID Data Decoder - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !"; + mRootStatFile = ic.options().get("root-file"); mDeco = new o2::hmpid::HmpidDecodeRawDigit(Geo::MAXEQUIPMENTS); mDeco->init(); mTotalDigits = 0; mTotalFrames = 0; + + mExTimer.start(); return; } void DataDecoderTask::run(framework::ProcessingContext& pc) { mDeco->mDigits.clear(); - decodeTF(pc); +// TODO: accept other types of Raw Streams ... // decodeReadout(pc); // decodeRawFile(pc); -// LOG(INFO) << "[HMPID Data Decoder - run] Writing " << mDeco->mDigits.size() << " Digits ..."; -// pc.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginHMP, "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); - - - // pc.outputs().snapshot(o2::framework::Output{"HMP", "STATS", 0, o2::framework::Lifetime::Timeframe}, *theObj); - - //--- theObj->Reset(); - //---- mfileOut.reset(); - + mExTimer.elapseMes("... Decoding... Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); + return; } void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) { // Records the statistics - float avgEventSize[o2::hmpid::Geo::MAXEQUIPMENTS]; - float avgBusyTime[o2::hmpid::Geo::MAXEQUIPMENTS]; - uint32_t numOfSamples[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - double sumOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - double squareOfCharges[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - - TString filename = TString::Format("%s_%06d.root", "test", 1); + float avgEventSize;//[o2::hmpid::Geo::MAXEQUIPMENTS]; + float avgBusyTime;//[o2::hmpid::Geo::MAXEQUIPMENTS]; + float numOfSamples;//[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + float sumOfCharges;//[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + float squareOfCharges;//[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + float xb; + float yb; + + TString filename = TString::Format("%s_stat.root", mRootStatFile.c_str()); LOG(INFO) << "Create the stat file " << filename.Data(); TFile mfileOut(TString::Format("%s", filename.Data()), "RECREATE"); - TTree * theObj; - theObj = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); - - theObj->Branch("Average_Event_Size", avgEventSize,"f[14]"); - theObj->Branch("Average_Busy_Time", avgBusyTime,"f[14]"); - theObj->Branch("Samples_per_pad", avgBusyTime,"d[7][144][160]"); - theObj->Branch("Sum_of_charges_per_pad", sumOfCharges,"d[7][144][160]"); - theObj->Branch("Sum_of_square_of_charges", squareOfCharges,"d[7][144][160]"); + TTree *theObj[Geo::N_MODULES+1]; + for(int i=0; iBranch("x", &xb,"s"); + theObj[i]->Branch("y", &yb,"s"); + theObj[i]->Branch("Samples", &numOfSamples,"i"); + theObj[i]->Branch("Sum_of_charges", &sumOfCharges,"l"); + theObj[i]->Branch("Sum_of_square", &squareOfCharges,"l"); + } + theObj[Geo::N_MODULES] = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); + theObj[Geo::N_MODULES]->Branch("Average_Event_Size", &avgEventSize,"F"); + theObj[Geo::N_MODULES]->Branch("Average_Busy_Time", &avgBusyTime,"F"); + char summaryFileName[254]; + sprintf(summaryFileName,"%s_stat.txt", mRootStatFile.c_str()); + mDeco->writeSummaryFile(summaryFileName); int numEqui = mDeco->getNumberOfEquipments(); for(int e=0;egetAverageEventSize(e); - avgBusyTime[e] = mDeco->getAverageBusyTime(e); + avgEventSize = mDeco->getAverageEventSize(e); + avgBusyTime = mDeco->getAverageBusyTime(e); + theObj[Geo::N_MODULES]->Fill(); } for(int m=0; m < o2::hmpid::Geo::N_MODULES; m++) for(int y=0; y < o2::hmpid::Geo::N_YCOLS; y++) for(int x=0; x < o2::hmpid::Geo::N_XROWS; x++ ) { - numOfSamples[m][y][x] = mDeco->getPadSamples(m, x, y); - sumOfCharges[m][y][x] = mDeco->getPadSum(m, x, y); - squareOfCharges[m][y][x] = mDeco->getPadSquares(m, x, y); + xb = x; + yb = y; + numOfSamples = mDeco->getPadSamples(m, x, y); + sumOfCharges = mDeco->getPadSum(m, x, y); + squareOfCharges = mDeco->getPadSquares(m, x, y); + theObj[m]->Fill(); } - // theObj->Fill(); - theObj->Write(); - LOG(INFO) << "End the Decoding ! Digits decoded = " << mTotalDigits << " Frames received = " << mTotalFrames; - // LOG(INFO)<< "Sleep 10 sec"<< std::endl; - // sleep(30); + for(int i=0; i<=Geo::N_MODULES; i++) { + theObj[i]->Write(); + } + mExTimer.logMes("End the Decoding ! Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); + mExTimer.stop(); //ec.services().get().endOfStream(); - // ec.services().get().readyToQuit(framework::QuitRequest::Me); + // ec.services().get().readyToQuit(framework::QuitRequest::Me); return; - } //_________________________________________________________________________________________________ // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 228ca63af4eec..cf24fe0abca58 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -67,17 +67,14 @@ void DumpDigitsTask::init(framework::InitContext& ic) mIsOutputOnFile = true; } } - - if (mPrintDigits) { - std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - } - if (mIsOutputOnFile) { - mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - } + if (mPrintDigits) std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + if (mIsOutputOnFile) mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; mOrbit = -1; mBc = -1; mDigitsReceived = 0; + + mExTimer.start(); return; } @@ -103,13 +100,16 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) } } } + mExTimer.elapseMes( "... Dumping... Digits received = " + std::to_string(mDigitsReceived)); return; } void DumpDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { mOsFile.close(); - LOG(INFO) << "End Digits Dump ! Dumped digits = " << mDigitsReceived; + + mExTimer.stop(); + mExTimer.logMes("End Digits Dump ! Dumped digits = " + std::to_string(mDigitsReceived)); return; } diff --git a/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash b/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash deleted file mode 100644 index b87e288dd055e..0000000000000 --- a/Detectors/HMPID/workflow/src/RawFileReaderSpec.cxx_trash +++ /dev/null @@ -1,157 +0,0 @@ -// 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 RawFileReaderSpec.cxx -/// \author Antonio Franco -/// -/// \brief This is an executable that reads a data file from disk and sends the individual CRU pages via DPL. -/// -/// This is an executable that reads a data file from disk and sends the individual CRU pages via the Data Processing Layer. -// - -#include -#include -#include -#include -#include -#include -#include - -#include "Framework/CallbackService.h" -#include "Framework/ConfigParamRegistry.h" -#include "Framework/ControlService.h" -#include "Framework/DataProcessorSpec.h" -#include "Framework/Lifetime.h" -#include "Framework/Output.h" -#include "Framework/Task.h" -#include "Framework/WorkflowSpec.h" -#include "Framework/Logger.h" - - -#include "DPLUtils/DPLRawParser.h" -#include "Headers/RAWDataHeader.h" -#include "DetectorsRaw/RDHUtils.h" - -#include "HMPIDWorkflow/RawFileReaderSpec.h" - -namespace o2 -{ -namespace hmpid -{ - -using RDH = o2::header::RDHAny; -using namespace o2; -using namespace o2::framework; - - -void RawFileReaderTask::init(framework::InitContext& ic) -{ - // Get the input file and other options from the context - LOG(INFO) << "Raw file reader Init"; -std::cout << ">>> INIT !" << std::endl; - auto inputFileName = ic.options().get("input-file"); - mInputFile.open(inputFileName, std::ios::binary); - if (!mInputFile.is_open()) { - throw std::invalid_argument("Cannot open input file \"" + inputFileName + "\""); - } - - // define the callback to close the file - auto stop = [this]() { - LOG(INFO) << "stop file reader"; - this->mInputFile.close(); - }; - ic.services().get().set(CallbackService::Id::Stop, stop); -} - -//_________________________________________________________________________________________________ -void RawFileReaderTask::run(framework::ProcessingContext& pc) -{ - // send one RDH block via DPL - RDH rdh; - char* buf{nullptr}; - size_t bufSize{0}; - - while (true) { - - // read the next RDH, stop if no more data is available - mInputFile.read((char*)(&rdh), sizeof(RDH)); - if (mInputFile.fail()) { - pc.services().get().endOfStream(); - LOG(INFO) << " Fails to read the header ! "; - return; // probably reached eof - } - - // check that the RDH version is ok (only RDH versions from 4 to 6 are supported at the moment) - auto rdhVersion = o2::raw::RDHUtils::getVersion(rdh); - auto rdhHeaderSize = o2::raw::RDHUtils::getHeaderSize(rdh); - if (rdhVersion != 6 || rdhHeaderSize != 64) { - LOG(WARNING) << " Wrong RDH (v." << rdhVersion << ", size=" << rdhHeaderSize << ")"; - return; - } - std::cout<<"h"; - // get the frame size from the RDH offsetToNext field - auto frameSize = o2::raw::RDHUtils::getOffsetToNext(rdh); - - // stop if the frame size is too small - if (frameSize < rdhHeaderSize) { - LOG(WARNING) << " FrameSize too small: " << frameSize; - pc.services().get().endOfStream(); - return; - } - - // allocate the output buffer - buf = (char*)realloc(buf, frameSize); - if (buf == nullptr) { - LOG(ERROR) << " Failed to allocate buffer"; - pc.services().get().endOfStream(); - return; - } - - // copy the RDH into the output buffer - memcpy(buf, &rdh, rdhHeaderSize); - - // read the frame payload into the output buffer - mInputFile.read(buf + rdhHeaderSize, frameSize - rdhHeaderSize); - std::cout<<"p"; - // stop if data cannot be read completely - if (mInputFile.fail()) { - LOG(ERROR) << "Fail to read the payload "; - free(buf); - pc.services().get().endOfStream(); - return; // probably reached eof - } - // create the output message - auto freefct = [](void* data, void* /*hint*/) { free(data); }; - - pc.outputs().make(Output{"HMP","rawfile"},buf, bufSize ); -// pc.outputs().snapshot(Output{"HMP", "rawfile", 0, o2::framework::Lifetime::Timeframe}, buf); -// pc.outputs().adoptChunk(Output{"HMP", "rawfile"}, buf, bufSize, freefct, nullptr); - std::cout<<"w"<()}, - Options{{"input-file", VariantType::String, "", {"input raw file name"}}}}; -} -// clang-format on - - -} // end namespace mch -} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx index f0ad87c6efd2f..24bb0f751b6f3 100644 --- a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx +++ b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx @@ -14,11 +14,6 @@ #include #include - - - - - #include "Framework/CallbackService.h" #include "Framework/ConfigParamRegistry.h" #include "Framework/ControlService.h" @@ -33,9 +28,6 @@ #include "DetectorsRaw/RDHUtils.h" #include "DPLUtils/DPLRawParser.h" - - - #include "HMPIDWorkflow/ReadRawFileSpec.h" namespace o2 @@ -47,12 +39,6 @@ using namespace o2; using namespace o2::framework; using RDH = o2::header::RDHAny; -//auto RawFileReaderTask::stop(void) -//{ -// LOG(INFO) << "Stop file reader"; -// mInputFile.close(); -// return; -//} void RawFileReaderTask::init(framework::InitContext& ic) { @@ -71,6 +57,9 @@ void RawFileReaderTask::init(framework::InitContext& ic) this->mInputFile.close(); }; ic.services().get().set(CallbackService::Id::Stop, stop); + + mExTimer.start(); + return; } @@ -81,14 +70,13 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) char* outBuffer{nullptr}; size_t bufSize{0}; int numberOfFrames = 0; - LOG(INFO)<< "Sleep 5 sec"<< std::endl; - sleep(5); + LOG(INFO)<< "Sleep 1 sec for sync"; + sleep(1); while (true) { //usleep(100); mInputFile.read((char*)(&rdh), sizeof(RDH)); // read the next RDH, stop if no more data is available if (mInputFile.fail()) { - LOG(INFO) << "End of file ! Number of frames processed :" << numberOfFrames; free(outBuffer); mInputFile.close(); pc.services().get().endOfStream(); @@ -121,7 +109,6 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) memcpy(outBuffer, &rdh, rdhHeaderSize); // fill the buffer mInputFile.read(outBuffer + rdhHeaderSize, frameSize - rdhHeaderSize); if (mInputFile.fail()) { // Could be EoF - LOG(INFO) << "end of file reached"; free(outBuffer); pc.services().get().endOfStream(); pc.services().get().readyToQuit(framework::QuitRequest::Me); @@ -129,7 +116,13 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) } bufSize = frameSize; // Set the buffer pointer pc.outputs().snapshot(Output{"HMP","RAWDATA"}, outBuffer, bufSize); +//std::cout << mExTimer.mTimer.CpuTime() << " " << mExTimer.mLastLogTime << std::endl; + mExTimer.elapseMes("... Reading... Number of Pages = " + std::to_string(numberOfFrames)); } // while (true) + + mExTimer.logMes("End of file ! Number of frames processed = " + std::to_string(numberOfFrames)); + mExTimer.stop(); + return; } //_________________________________________________________________________________________________ diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index ce020729564a5..66156b4c5dd59 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -64,6 +64,7 @@ void WriteRawFromDigitsTask::init(framework::InitContext& ic) mCod->reset(); mCod->openOutputStream(mBaseFileName.c_str()); + mExTimer.start(); return; } @@ -91,24 +92,27 @@ void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) } mDigitsReceived += digits.size(); mFramesReceived++; - LOG(INFO) << "run() Digits received =" << mDigitsReceived << " frames = " << mFramesReceived; + LOG(DEBUG) << "run() Digits received =" << mDigitsReceived << " frames = " << mFramesReceived; } + mExTimer.elapseMes("... Write raw file ... Digits received = " + std::to_string(mDigitsReceived) + " Frames received = " + std::to_string(mFramesReceived)); return; } void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { - LOG(INFO) << "Received an End Of Stream !"; + mExTimer.logMes("Received an End Of Stream !"); if(mOrderTheEvents) { sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); - LOG(INFO) << mDigits.size() << " Digits sorted ! " ; + mExTimer.logMes("We sort " + std::to_string(mDigits.size()) + " ! "); mCod->codeDigitsVector(mDigits); } else { mCod->codeDigitsChunk(true); } mCod->closeOutputStream(); - LOG(INFO) << "Raw File created ! Digits received = " << mDigitsReceived << " Frame received =" << mFramesReceived; mCod->dumpResults(); + + mExTimer.logMes( "Raw File created ! Digits received = " + std::to_string(mDigitsReceived) + " Frame received =" + std::to_string(mFramesReceived)); + mExTimer.stop(); return; } diff --git a/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash b/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash deleted file mode 100644 index 52bd546179a25..0000000000000 --- a/Detectors/HMPID/workflow/src/rawfile-to-digits-workflow.cxx_trash +++ /dev/null @@ -1,43 +0,0 @@ -// 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 raw-to-digits-workflow.cxx -/// \author Andrea Ferrero -/// -/// \brief This is an executable that runs the decoding via DPL. -/// -/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. -/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow -/// - -#include "Framework/WorkflowSpec.h" -#include "Framework/DataSpecUtils.h" -#include "Framework/CallbackService.h" -#include "Framework/ControlService.h" -#include "Framework/Task.h" -#include "Framework/runDataProcessing.h" - -#include "HMPIDWorkflow/RawFileReaderSpec.h" - -using namespace o2; -using namespace o2::framework; - -WorkflowSpec defineDataProcessing(const ConfigContext&) -{ - WorkflowSpec specs; - - DataProcessorSpec producer = o2::hmpid::getRawFileReaderSpec(); -// DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); - specs.push_back(producer); -// specs.push_back(consumer); - - return specs; -} From 4b3d3483bd8d14e8c4a797d0a9677a184f498b42 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 5 Feb 2021 15:42:45 +0100 Subject: [PATCH 177/208] Try --- Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index 66156b4c5dd59..f444023871a87 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -1,4 +1,4 @@ -// draft +// V0.1 // 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". From 04378e49fee624bc25207ab81ea7b839f88d202e Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 8 Feb 2021 10:54:04 +0100 Subject: [PATCH 178/208] Fix the erase digit vector bug --- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index e81fea90fffc3..70e2cd91bcf73 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -352,7 +352,8 @@ void HmpidCoder::codeEventChunkDigits(std::vector &digits, bool flushVect writePaginatedEvent(orbit, bc); digits.clear(); } else { - digits.erase(digits.begin(), digits.begin() + mLastProcessedDigit); + if(mLastProcessedDigit>=0) + digits.erase(digits.begin(), digits.begin() + mLastProcessedDigit); } memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event return; From c21b7eefdea189092012ec89aeb775f073a46995 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 8 Feb 2021 18:01:09 +0100 Subject: [PATCH 179/208] Fix the Digit time in the Digitizer Class --- .../HMPID/base/include/HMPIDBase/Digit.h | 5 ++++ Detectors/HMPID/base/src/Digit.cxx | 23 +++++++++++++++++++ .../include/HMPIDSimulation/HMPIDDigitizer.h | 6 +++++ .../HMPID/simulation/src/HMPIDDigitizer.cxx | 6 ++--- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index ffe60a28f9dfa..4565bd389ec82 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -44,6 +44,11 @@ class Digit static void Absolute2Equipment(int Module, int x, int y, int *Equi, int *Colu, int *Dilo, int *Chan); static void Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int *Module, int *x, int *y); + static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC); + static uint32_t TimeNsToOrbit(double TimeNs); + static uint16_t TimeNsToBc(double TimeNs); + static void TimeNsToOrbitBc(double TimeNs, uint32_t &Orbit, uint16_t &Bc); + // Operators definition ! friend inline bool operator<(const Digit& l, const Digit& r) { return l.mPad < r.mPad; }; friend inline bool operator==(const Digit& l, const Digit& r) { return l.mPad == r.mPad; }; diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index c9d8e312ab919..0cfab3e998124 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -13,6 +13,7 @@ #include "HMPIDBase/Param.h" #include "TRandom.h" #include "TMath.h" +#include "CommonConstants/LHCConstants.h" using namespace o2::hmpid; @@ -227,3 +228,25 @@ float Digit::InMathieson(float localX, float localY, int pad) return 4. * Digit::IntPartMathiX(localX, pad) * Digit::IntPartMathiY(localY, pad); } +// Time conversion functions +double Digit::OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) +{ + return( BC * o2::constants::lhc::LHCBunchSpacingNS + Orbit * o2::constants::lhc::LHCOrbitNS); +} + +uint32_t Digit::TimeNsToOrbit(double TimeNs) +{ + return(TimeNs / o2::constants::lhc::LHCOrbitNS); +} + +uint16_t Digit::TimeNsToBc(double TimeNs) +{ + return((TimeNs % o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); +} + +void Digit::TimeNsToOrbitBc(double TimeNs, uint32_t &Orbit, uint16_t &Bc) +{ + Orbit = TimeNsToOrbit(TimeNs); + Bc = TimeNsToBc(TimeNs); + return; +} diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h index d33aa0ff8bbfd..ebe70ec06ecb9 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h @@ -44,10 +44,12 @@ class HMPIDDigitizer // for the first trigger no busy check necessary mCurrentTriggerTime = timeNS; mReadoutCounter++; + Digit::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, Bc); return true; } else { if ((timeNS - mCurrentTriggerTime) > BUSYTIME) { mCurrentTriggerTime = timeNS; + Digit::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, Bc); mReadoutCounter++; return true; } else { @@ -83,6 +85,10 @@ class HMPIDDigitizer // (using noise and other tables for pad) double mCurrentTriggerTime = 0.; + uint32_t mOrbit = 0; + uint16_t mBc = 0; + + int mEventID = 0; int mSrcID = 0; diff --git a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx index 0a70d3c28851b..d24d67753f1e4 100644 --- a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx +++ b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx @@ -110,11 +110,9 @@ void HMPIDDigitizer::process(std::vector const& hits, std::v } } else { // create digit ... and register -int Orbit = 1; -int Bc = 1; // mDigits.emplace_back(mCurrentTriggerTime, pad, totalQ * fraction); - mDigits.emplace_back(Orbit, Bc, pad, totalQ * fraction); - mIndexForPad[pad] = mDigits.size() - 1; + mDigits.emplace_back(mOrbit, mBc, pad, totalQ * fraction); + mIndexForPad[pad] = mDigits.size() - 1; mInvolvedPads.emplace_back(pad); if (mRegisteredLabelContainer) { From 7cc09c8585ab2037785b810b73e9755f577296ce Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 9 Feb 2021 09:25:49 +0100 Subject: [PATCH 180/208] Fix --- Detectors/HMPID/base/src/Digit.cxx | 2 +- .../HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 0cfab3e998124..b9ea6679088d3 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -241,7 +241,7 @@ uint32_t Digit::TimeNsToOrbit(double TimeNs) uint16_t Digit::TimeNsToBc(double TimeNs) { - return((TimeNs % o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); + return(std::fmod(TimeNs , o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); } void Digit::TimeNsToOrbitBc(double TimeNs, uint32_t &Orbit, uint16_t &Bc) diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h index ebe70ec06ecb9..9706216aa26f6 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h @@ -44,12 +44,12 @@ class HMPIDDigitizer // for the first trigger no busy check necessary mCurrentTriggerTime = timeNS; mReadoutCounter++; - Digit::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, Bc); + Digit::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, mBc); return true; } else { if ((timeNS - mCurrentTriggerTime) > BUSYTIME) { mCurrentTriggerTime = timeNS; - Digit::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, Bc); + Digit::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, mBc); mReadoutCounter++; return true; } else { From 91123c46c47fb822d8b6de27e8e37fa3ed0c8c2e Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 9 Feb 2021 20:08:59 +0100 Subject: [PATCH 181/208] Ver.0.2 Runs Add the write root file workflow --- Detectors/HMPID/workflow/CMakeLists.txt | 5 +++ Detectors/HMPID/workflow/README.md | 24 ++++++++++ .../HMPIDWorkflow/WriteRootFromDigitsSpec.h | 44 +++++++++++++++++++ .../src/write-root-from-digits-workflow.cxx | 43 ++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h create mode 100644 Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index 6095de8f32eab..0c19edf783da0 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -46,4 +46,9 @@ o2_add_executable(dump-digits-workflow COMPONENT_NAME hmpid SOURCES src/dump-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + +o2_add_executable(write-root-from-digits-workflow + COMPONENT_NAME hmpid + SOURCES src/write-root-from-digits-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) \ No newline at end of file diff --git a/Detectors/HMPID/workflow/README.md b/Detectors/HMPID/workflow/README.md index 6e09e8bd71469..7485fffb0ac76 100644 --- a/Detectors/HMPID/workflow/README.md +++ b/Detectors/HMPID/workflow/README.md @@ -89,3 +89,27 @@ Data processor options: HMP-DigitsDump: --out-file arg name of the output file --print print digits (default false ) ``` + + +### o2-hmpid-write-root-from-digits-workflow +Write the digit stream into a root formatted file + +``` +o2-hmpid-write-root-from-digit-workflow --help full +``` + +Data processor options: HMPDigitWriter: + +``` + --outfile arg (=hmpiddigits.root) Name of the output file + --treename arg (=o2sim) Name of tree + --treetitle arg (=o2sim) Title of tree + --nevents arg (=-1) Number of events to execute + --terminate arg (=process) Terminate the 'process' or 'workflow' +``` + +Example + +``` +[O2Suite/latest-o2] ~/Downloads/provaRec $> o2-hmpid-read-raw-file-workflow --raw-file test_full_flp1.raw -b | o2-hmpid-raw-to-digits-workflow -b | o2-hmpid-write-root-from-digits-workflow -b +``` \ No newline at end of file diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h new file mode 100644 index 0000000000000..d0cb20ac56b2c --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h @@ -0,0 +1,44 @@ +// 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. + +#ifndef STEER_DIGITIZERWORKFLOW_SRC_HMPDIGITWRITERSPEC_H_ +#define STEER_DIGITIZERWORKFLOW_SRC_HMPDIGITWRITERSPEC_H_ + +#include "Framework/DataProcessorSpec.h" +#include "DPLUtils/MakeRootTreeWriterSpec.h" +#include "Framework/InputSpec.h" +#include "HMPIDBase/Digit.h" +#include "SimulationDataFormat/MCTruthContainer.h" +#include "SimulationDataFormat/MCCompLabel.h" + +namespace o2 +{ +namespace hmpid +{ + +template +using BranchDefinition = framework::MakeRootTreeWriterSpec::BranchDefinition; + +o2::framework::DataProcessorSpec getWriteRootFromDigitSpec(bool mctruth = false) +{ + using InputSpec = framework::InputSpec; + using MakeRootTreeWriterSpec = framework::MakeRootTreeWriterSpec; + return MakeRootTreeWriterSpec("HMPDigitWriter", + "hmpiddigits.root", + "o2sim", + -1, + BranchDefinition>{InputSpec{"digitinput", "HMP", "DIGITS"}, "HMPDigit"}, + BranchDefinition>{InputSpec{"labelinput", "HMP", "DIGITLBL"}, "HMPDigitLabels", mctruth ? 1 : 0})(); +} + +} // end namespace hmpid +} // end namespace o2 + +#endif /* STEER_DIGITIZERWORKFLOW_SRC_HMPIDDIGITWRITERSPEC_H_ */ diff --git a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx new file mode 100644 index 0000000000000..12b4a8295a3bd --- /dev/null +++ b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx @@ -0,0 +1,43 @@ +// 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. + + +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/Task.h" +#include "Framework/CompletionPolicy.h" +#include "Framework/CompletionPolicyHelpers.h" +#include "Framework/DispatchPolicy.h" + +// customize the completion policy +void customize(std::vector& policies) +{ + using o2::framework::CompletionPolicy; + using o2::framework::CompletionPolicyHelpers; + policies.push_back(CompletionPolicyHelpers::defineByName("digit-root-write", CompletionPolicy::CompletionOp::Consume)); +} + +#include "Framework/runDataProcessing.h" + +#include "HMPIDWorkflow/WriteRootFromDigitsSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + DataProcessorSpec consumer = o2::hmpid::getWriteRootFromDigitSpec(); + specs.push_back(consumer); + return specs; +} From d6134af5edeb0cc4e36e97b0a16bfa8334035f09 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Wed, 10 Feb 2021 14:18:17 +0100 Subject: [PATCH 182/208] Integrate the Pedestals calculation --- .../HMPID/base/include/HMPIDBase/Digit.h | 8 + Detectors/HMPID/base/src/Digit.cxx | 38 +++ Detectors/HMPID/workflow/CMakeLists.txt | 6 + .../HMPIDWorkflow/PedestalsCalculationSpec.h | 52 ++++ .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 2 +- .../workflow/src/PedestalsCalculationSpec.cxx | 227 ++++++++++++++++++ .../workflow/src/WriteRawFromDigitsSpec.cxx | 6 +- .../workflow/src/raw-to-pestals-workflow.cxx | 53 ++++ 8 files changed, 389 insertions(+), 3 deletions(-) create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h create mode 100644 Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/raw-to-pestals-workflow.cxx diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 4565bd389ec82..9a3cfdb8b5717 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -11,6 +11,8 @@ #ifndef DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_DIGIT_H_ #define DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_DIGIT_H_ +#include + #include "CommonDataFormat/TimeStamp.h" #include "HMPIDBase/Hit.h" // for hit #include "HMPIDBase/Param.h" // for param @@ -63,6 +65,12 @@ class Digit return os; }; + // Functions to manage Digit vectors + static bool eventEquipPadsComp(Digit &d1, Digit &d2); + static std::vector* extractDigitsPerEvent(std::vector &Digits, uint64_t EventID); + static std::vector* extractEvents(std::vector &Digits); + + public: Digit() = default; Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad) {}; diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index b9ea6679088d3..6e5d03a3f6fc1 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -250,3 +250,41 @@ void Digit::TimeNsToOrbitBc(double TimeNs, uint32_t &Orbit, uint16_t &Bc) Bc = TimeNsToBc(TimeNs); return; } + +// Functions to manage Digit vectors + +// Function for order digits (Event,Chamber,Photo,x,y) +bool Digit::eventEquipPadsComp(Digit &d1, Digit &d2) +{ + uint64_t t1,t2; + t1 = d1.getTriggerID(); + t2 = d2.getTriggerID(); + if (t1 < t2) return true; + if (t2 < t1) return false; + if (d1.getPadID() < d2.getPadID()) return true; + return false; +}; + +std::vector* Digit::extractDigitsPerEvent(std::vector &Digits, uint64_t EventID) +{ + std::vector* subVector = new std::vector(); + for(const auto & digit : Digits) { + if(digit.getTriggerID() == EventID) { + subVector->push_back(digit); + } + } + return(subVector); +}; + +std::vector* Digit::extractEvents(std::vector &Digits) +{ + std::vector* subVector = new std::vector(); + for(const auto & digit : Digits) { + if(find(subVector->begin(), subVector->end(), digit.getTriggerID()) == subVector->end()) { + subVector->push_back(digit.getTriggerID()); + } + } + return(subVector); +}; + + diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index 0c19edf783da0..b6092973b562e 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -15,6 +15,7 @@ o2_add_library(HMPIDWorkflow src/DumpDigitsSpec.cxx src/ReadRawFileSpec.cxx src/WriteRawFromDigitsSpec.cxx + src/PedestalsCalculationSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::DetectorsRaw @@ -51,4 +52,9 @@ o2_add_executable(write-root-from-digits-workflow COMPONENT_NAME hmpid SOURCES src/write-root-from-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + +o2_add_executable(raw-to-pedestals-workflow + COMPONENT_NAME hmpid + SOURCES src/raw-to-pedestals-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) \ No newline at end of file diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h new file mode 100644 index 0000000000000..23816c33bf43b --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h @@ -0,0 +1,52 @@ +// 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. + + +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ + +#include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" + +#include "HMPIDBase/Common.h" +#include "HMPIDReconstruction/HmpidDecodeRawMem.h" + +namespace o2 +{ +namespace hmpid +{ + + class PedestalsCalculationTask : public framework::Task + { + public: + PedestalsCalculationTask() = default; + ~PedestalsCalculationTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + void decodeTF(framework::ProcessingContext& pc); + void decodeReadout(framework::ProcessingContext& pc); + void decodeRawFile(framework::ProcessingContext& pc); + void endOfStream(framework::EndOfStreamContext& ec) override; + + private: + HmpidDecodeRawMem *mDeco; + long mTotalDigits; + long mTotalFrames; + std::string mPedestalsBasePath; + float mSigmaCut; + ExecutionTimer mExTimer; + }; + +o2::framework::DataProcessorSpec getPedestalsCalculationSpec(std::string inputSpec = "TF:HMP/RAWDATA"); +//o2::framework::DataProcessorSpec getDecodingSpec(); +} // end namespace hmpid +} // end namespace o2 + +#endif diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h index 54ac4d140a2b6..7290acf943a39 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -35,7 +35,7 @@ namespace hmpid void endOfStream(framework::EndOfStreamContext& ec) override; private: - static bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); + // static bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); std::string mBaseFileName = ""; std::vector mDigits; bool mSkipEmpty = false; diff --git a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx new file mode 100644 index 0000000000000..cd411966f559a --- /dev/null +++ b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx @@ -0,0 +1,227 @@ +// draft +// 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 DatDecoderSpec.cxx +/// \author +/// +/// \brief Implementation of a data processor to run the HMPID raw decoding +/// + +#include +#include +#include +#include +#include +#include +#include + +#include "TTree.h" +#include "TFile.h" + +#include + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" + +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" +#include "DPLUtils/DPLRawParser.h" + +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDReconstruction/HmpidDecodeRawMem.h" +#include "HMPIDWorkflow/PedestalsCalculationSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using namespace o2; +using namespace o2::framework; +using RDH = o2::header::RDHAny; + +//======================= +// Data decoder +void PedestalsCalculationTask::init(framework::InitContext& ic) +{ + + LOG(INFO) << "[HMPID Pedestal Calculation - Init] ( create Decoder for " << Geo::MAXEQUIPMENTS << " equipments !"; + + mDeco = new o2::hmpid::HmpidDecodeRawMem(Geo::MAXEQUIPMENTS); + mDeco->init(); + mTotalDigits = 0; + mTotalFrames = 0; + + mSigmaCut = ic.options().get("sigmacut"); + mPedestalsBasePath = ic.options().get("files-basepath"); + + mExTimer.start(); + return; +} + +void PedestalsCalculationTask::run(framework::ProcessingContext& pc) +{ + decodeTF(pc); +// TODO: accept other types of Raw Streams ... +// decodeReadout(pc); +// decodeRawFile(pc); + + mExTimer.elapseMes("Decoding... Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); + return; +} + +void PedestalsCalculationTask::endOfStream(framework::EndOfStreamContext& ec) +{ + double Average; + double Variance; + double Samples; + double SumOfCharge; + double SumOfSquares; + + uint32_t Buffer; + uint32_t Pedestal; + uint32_t Threshold; + char padsFileName[1024]; + + for(int e=0; egetChannelSamples(e, c, d, h); + SumOfCharge = mDeco->getChannelSum(e, c, d, h); + SumOfSquares = mDeco->getChannelSquare(e, c, d, h); + + Average = SumOfCharge / Samples; + if(Samples > 0) + Variance = sqrt( abs( (Samples * SumOfSquares) - (SumOfCharge * SumOfCharge) ) ) / Samples; + else + Variance = 0; + Pedestal = (uint32_t) Average; + Threshold = (uint32_t) (Variance * mSigmaCut + Average); + Buffer = ((Threshold & 0x001FF) << 9) | (Pedestal & 0x001FF); + fprintf(fpads, "%05X\n", Buffer); + } + for(int h=48;h<64;h++) { + fprintf(fpads, "%05X\n", 0); + } + } + } + mExTimer.logMes("End write the equipment = " + std::to_string(e) ); + fprintf(fpads, "%05X\n", 0xA0A0A); + fclose(fpads); + } + mExTimer.logMes("End Writing the pedestals ! Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); + mExTimer.stop(); + return; +} +//_________________________________________________________________________________________________ +// the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder +void PedestalsCalculationTask::decodeTF(framework::ProcessingContext& pc) +{ + LOG(DEBUG) << "*********** In decodeTF **************"; + + // get the input buffer + auto& inputs = pc.inputs(); + DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); + for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { + uint32_t *theBuffer = (uint32_t *)it.raw(); + mDeco->setUpStream(theBuffer, it.size()+it.offset()); + mDeco->decodePageFast(&theBuffer); + mTotalFrames++; + } + return; +} +//pc.outputs().make +//_________________________________________________________________________________________________ +// the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow +void PedestalsCalculationTask::decodeReadout(framework::ProcessingContext& pc) +{ + LOG(INFO) << "*********** In decode readout **************"; + + // get the input buffer + auto& inputs = pc.inputs(); + DPLRawParser parser(inputs, o2::framework::select("readout:HMP/RAWDATA")); +// DPLRawParser parser(inputs, o2::framework::select("HMP/readout")); + + for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { + uint32_t *theBuffer = (uint32_t *)it.raw(); + mDeco->setUpStream(theBuffer, it.size()+it.offset()); + mDeco->decodePageFast(&theBuffer); + } + return; +} + +// the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow +void PedestalsCalculationTask::decodeRawFile(framework::ProcessingContext& pc) +{ + LOG(INFO) << "*********** In decode rawfile **************"; + + for (auto&& input : pc.inputs()) { + if (input.spec->binding == "file") { + const header::DataHeader* header = o2::header::get(input.header); + if (!header) { + return; + } + + auto const* raw = input.payload; + size_t payloadSize = header->payloadSize; + + LOG(INFO) << " payloadSize=" << payloadSize; + if (payloadSize == 0) { + return; + } + + uint32_t *theBuffer = (uint32_t *)input.payload; + int pagesize = header->payloadSize; + mDeco->setUpStream(theBuffer, pagesize); + mDeco->decodePageFast(&theBuffer); + } + } + return; +} + +//_________________________________________________________________________________________________ +o2::framework::DataProcessorSpec getPedestalsCalculationSpec(std::string inputSpec) +{ + + std::vector inputs; + inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); + inputs.emplace_back("file", o2::framework::ConcreteDataTypeMatcher{"ROUT", "RAWDATA"}, o2::framework::Lifetime::Timeframe); +// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); +// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); +// inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + + std::vector outputs; +// outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); + + return DataProcessorSpec{ + "HMP-DataDecoder", + o2::framework::select(inputSpec.c_str()), + outputs, + AlgorithmSpec{adaptFromTask()}, + Options{{"files-basepath", VariantType::String, "/tmp/hmpPedThr", {"Name of the Base Path of Pedestals/Thresholds files."}}, + {"sigmacut", VariantType::Float, 3.0, {"Sigma values for the Thresholds calculation."}} }}; +} + +} // namespace hmpid +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index f444023871a87..05d6a6680ee6f 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -68,6 +68,7 @@ void WriteRawFromDigitsTask::init(framework::InitContext& ic) return; } +/* bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2) { uint64_t t1,t2; @@ -78,7 +79,7 @@ bool WriteRawFromDigitsTask::eventEquipPadsComparision(o2::hmpid::Digit d1, o2:: if (d1.getPadID() < d2.getPadID()) return true; return false; } - +*/ void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) { @@ -102,7 +103,8 @@ void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { mExTimer.logMes("Received an End Of Stream !"); if(mOrderTheEvents) { - sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); +// sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); + sort(mDigits.begin(), mDigits.end(), o2::hmpid::Digit::eventEquipPadsComp); mExTimer.logMes("We sort " + std::to_string(mDigits.size()) + " ! "); mCod->codeDigitsVector(mDigits); } else { diff --git a/Detectors/HMPID/workflow/src/raw-to-pestals-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-pestals-workflow.cxx new file mode 100644 index 0000000000000..35fb51994bc9a --- /dev/null +++ b/Detectors/HMPID/workflow/src/raw-to-pestals-workflow.cxx @@ -0,0 +1,53 @@ +// 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. + + +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/Task.h" +#include "Framework/CompletionPolicy.h" +#include "Framework/CompletionPolicyHelpers.h" +#include "Framework/DispatchPolicy.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/InputRecordWalker.h" +#include "Framework/Logger.h" +#include "Framework/ConfigParamSpec.h" + +// customize dispatch policy, dispatch immediately what is ready +void customize(std::vector& policies) +{ + using DispatchOp = o2::framework::DispatchPolicy::DispatchOp; + auto readerMatcher = [](auto const& spec) { + return true; + }; + auto triggerMatcher = [](auto const& query) { + return true; + }; + policies.push_back({"decoded-hmpid-digits", readerMatcher, DispatchOp::WhenReady, triggerMatcher}); +} + +#include "Framework/runDataProcessing.h" + +#include "HMPIDWorkflow/PedestalsCalculationSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + DataProcessorSpec producer = o2::hmpid::getPedestalsCalculationSpec(); + specs.push_back(producer); + + return specs; +} From 3dcc68e2d083562d3b76c8544ddf5153a1517c9a Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Wed, 10 Feb 2021 14:21:08 +0100 Subject: [PATCH 183/208] Fix 1 --- ...{raw-to-pestals-workflow.cxx => raw-to-pedestals-workflow.cxx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Detectors/HMPID/workflow/src/{raw-to-pestals-workflow.cxx => raw-to-pedestals-workflow.cxx} (100%) diff --git a/Detectors/HMPID/workflow/src/raw-to-pestals-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-pedestals-workflow.cxx similarity index 100% rename from Detectors/HMPID/workflow/src/raw-to-pestals-workflow.cxx rename to Detectors/HMPID/workflow/src/raw-to-pedestals-workflow.cxx From 1dbfe2d1d0691364a639e8605a0fb42de2713a9f Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Wed, 10 Feb 2021 14:37:01 +0100 Subject: [PATCH 184/208] Compiled --- Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx index cd411966f559a..aab8cb1c22273 100644 --- a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx +++ b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx @@ -69,7 +69,7 @@ void PedestalsCalculationTask::init(framework::InitContext& ic) mTotalDigits = 0; mTotalFrames = 0; - mSigmaCut = ic.options().get("sigmacut"); + mSigmaCut = ic.options().get("sigmacut"); mPedestalsBasePath = ic.options().get("files-basepath"); mExTimer.start(); From c06ca0ef96a2fec7f806252b8ed648ebaacd626b Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Wed, 10 Feb 2021 18:38:20 +0100 Subject: [PATCH 185/208] Add the CCDB store of pedestals --- Detectors/HMPID/workflow/CMakeLists.txt | 1 + .../HMPIDWorkflow/PedestalsCalculationSpec.h | 11 +++ .../workflow/src/PedestalsCalculationSpec.cxx | 74 ++++++++++++++++++- 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index b6092973b562e..d71773ee8c3aa 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -17,6 +17,7 @@ o2_add_library(HMPIDWorkflow src/WriteRawFromDigitsSpec.cxx src/PedestalsCalculationSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework + O2::CCDB O2::DPLUtils O2::DetectorsRaw O2::HMPIDBase diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h index 23816c33bf43b..7f88a76aa0f50 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h @@ -15,6 +15,8 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" +#include "CCDB/CcdbApi.h" + #include "HMPIDBase/Common.h" #include "HMPIDReconstruction/HmpidDecodeRawMem.h" @@ -35,12 +37,21 @@ namespace hmpid void decodeRawFile(framework::ProcessingContext& pc); void endOfStream(framework::EndOfStreamContext& ec) override; + private: + void recordPedInCcdb(); + private: HmpidDecodeRawMem *mDeco; long mTotalDigits; long mTotalFrames; std::string mPedestalsBasePath; float mSigmaCut; + std::string mPedestalTag; + + o2::ccdb::CcdbApi mDBapi; + std::map mDbMetadata; // can be empty + bool mWriteToDB; + ExecutionTimer mExTimer; }; diff --git a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx index aab8cb1c22273..baf79ba335b65 100644 --- a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx +++ b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx @@ -39,6 +39,8 @@ #include "Framework/WorkflowSpec.h" #include "Framework/Logger.h" +#include "CCDB/CcdbApi.h" + #include "Headers/RAWDataHeader.h" #include "DetectorsRaw/RDHUtils.h" #include "DPLUtils/DPLRawParser.h" @@ -71,6 +73,9 @@ void PedestalsCalculationTask::init(framework::InitContext& ic) mSigmaCut = ic.options().get("sigmacut"); mPedestalsBasePath = ic.options().get("files-basepath"); + mPedestalTag = ic.options().get("pedestals-tag"); + mDBapi.init(ic.options().get("ccdb-uri")); // or http://localhost:8080 for a local installation + mWriteToDB = mDBapi.isHostReachable() ? true : false; mExTimer.start(); return; @@ -81,7 +86,7 @@ void PedestalsCalculationTask::run(framework::ProcessingContext& pc) decodeTF(pc); // TODO: accept other types of Raw Streams ... // decodeReadout(pc); -// decodeRawFile(pc); +// decodeRawFile(pc);ccdb mExTimer.elapseMes("Decoding... Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); return; @@ -131,9 +136,71 @@ void PedestalsCalculationTask::endOfStream(framework::EndOfStreamContext& ec) fclose(fpads); } mExTimer.logMes("End Writing the pedestals ! Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); + + if(mWriteToDB) + recordPedInCcdb(); + mExTimer.stop(); return; + } + + +void PedestalsCalculationTask::recordPedInCcdb() +{ + // create the root structure + + LOG(INFO) << "Store Pedestals in ccdb " ; + + float xb,yb, ch; + float Ped,Thr; + double Samples,SumOfCharge,SumOfSquares,Average,Variance; + + TTree *theObj; + TString tit = TString::Format("Pedestals / Thresholds "); + theObj = new TTree("o2hmp", tit); + + for(int i=0; iBranch("chamber", &ch,"s"); + theObj->Branch("x", &xb,"s"); + theObj->Branch("y", &yb,"s"); + theObj->Branch("Pedestal", &Ped,"i"); + theObj->Branch("Threshold", &Thr,"i"); + } + + for(int m=0; m < o2::hmpid::Geo::N_MODULES; m++) + for(int x=0; x < o2::hmpid::Geo::N_XROWS; x++ ) + for(int y=0; y < o2::hmpid::Geo::N_YCOLS; y++) { + xb = x; + yb = y; + ch = m; + Samples = (double)mDeco->getPadSamples(m, x, y); + SumOfCharge = mDeco->getPadSum(m, x, y); + SumOfSquares = mDeco->getPadSquares(m, x, y); + Average = SumOfCharge / Samples; + if(Samples > 0) + Variance = sqrt( abs( (Samples * SumOfSquares) - (SumOfCharge * SumOfCharge) ) ) / Samples; + else + Variance = 0; + Ped = (uint32_t) Average; + Thr = (uint32_t) (Variance * mSigmaCut + Average); + theObj->Fill(); + } + + struct timeval tp; + gettimeofday(&tp, NULL); + uint64_t ms = tp.tv_sec * 1000 + tp.tv_usec / 1000; + + uint64_t minTimeStamp = ms; + uint64_t maxTimeStamp = ms+1; + TString filename = TString::Format("HMP/Pedestals/%s", mPedestalTag.c_str()); + mDbMetadata.emplace("Tag", mPedestalTag.c_str() ); + mDBapi.storeAsTFileAny(theObj, filename.Data(), mDbMetadata, minTimeStamp, maxTimeStamp); + + + return; +} + //_________________________________________________________________________________________________ // the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder void PedestalsCalculationTask::decodeTF(framework::ProcessingContext& pc) @@ -220,7 +287,10 @@ o2::framework::DataProcessorSpec getPedestalsCalculationSpec(std::string inputSp outputs, AlgorithmSpec{adaptFromTask()}, Options{{"files-basepath", VariantType::String, "/tmp/hmpPedThr", {"Name of the Base Path of Pedestals/Thresholds files."}}, - {"sigmacut", VariantType::Float, 3.0, {"Sigma values for the Thresholds calculation."}} }}; + {"use-ccdb", VariantType::Bool, false, {"Register the Pedestals/Threshold values into the CCDB"}}, + {"ccdb-uri", VariantType::String, "http://ccdb-test.cern.ch:8080", {"URI for the CCDB access."}}, + {"pedestals-tag", VariantType::String, "Latest", {"The tag applied to this set of pedestals/threshold values"}}, + {"sigmacut", VariantType::Float, 3.0f, {"Sigma values for the Thresholds calculation."}} }}; } } // namespace hmpid From f12d9c148395ecca4f0e65d829c156c4efd5cd2d Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 11 Feb 2021 16:07:45 +0100 Subject: [PATCH 186/208] v.0.2 - Fix the Pedestal File format in the CCDB --- .../HMPID/workflow/src/PedestalsCalculationSpec.cxx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx index baf79ba335b65..e373b6868805f 100644 --- a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx +++ b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx @@ -142,7 +142,6 @@ void PedestalsCalculationTask::endOfStream(framework::EndOfStreamContext& ec) mExTimer.stop(); return; - } @@ -153,7 +152,6 @@ void PedestalsCalculationTask::recordPedInCcdb() LOG(INFO) << "Store Pedestals in ccdb " ; float xb,yb, ch; - float Ped,Thr; double Samples,SumOfCharge,SumOfSquares,Average,Variance; TTree *theObj; @@ -164,8 +162,8 @@ void PedestalsCalculationTask::recordPedInCcdb() theObj->Branch("chamber", &ch,"s"); theObj->Branch("x", &xb,"s"); theObj->Branch("y", &yb,"s"); - theObj->Branch("Pedestal", &Ped,"i"); - theObj->Branch("Threshold", &Thr,"i"); + theObj->Branch("Average", &Average,"f"); + theObj->Branch("Sigma", &Variance,"f"); } for(int m=0; m < o2::hmpid::Geo::N_MODULES; m++) @@ -182,8 +180,6 @@ void PedestalsCalculationTask::recordPedInCcdb() Variance = sqrt( abs( (Samples * SumOfSquares) - (SumOfCharge * SumOfCharge) ) ) / Samples; else Variance = 0; - Ped = (uint32_t) Average; - Thr = (uint32_t) (Variance * mSigmaCut + Average); theObj->Fill(); } @@ -197,7 +193,6 @@ void PedestalsCalculationTask::recordPedInCcdb() mDbMetadata.emplace("Tag", mPedestalTag.c_str() ); mDBapi.storeAsTFileAny(theObj, filename.Data(), mDbMetadata, minTimeStamp, maxTimeStamp); - return; } @@ -290,7 +285,7 @@ o2::framework::DataProcessorSpec getPedestalsCalculationSpec(std::string inputSp {"use-ccdb", VariantType::Bool, false, {"Register the Pedestals/Threshold values into the CCDB"}}, {"ccdb-uri", VariantType::String, "http://ccdb-test.cern.ch:8080", {"URI for the CCDB access."}}, {"pedestals-tag", VariantType::String, "Latest", {"The tag applied to this set of pedestals/threshold values"}}, - {"sigmacut", VariantType::Float, 3.0f, {"Sigma values for the Thresholds calculation."}} }}; + {"sigmacut", VariantType::Float, 4.0f, {"Sigma values for the Thresholds calculation."}} }}; } } // namespace hmpid From 8301ece3c6e4cdb04a935da294c2d33079c36368 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 12 Feb 2021 11:11:45 +0100 Subject: [PATCH 187/208] v.0.3 - Change the pedestals/sigma format in CCDB - transform the ccdb in a collection of TMatrixF objects - fix the NaN in case of 0 samples for the Mean calculation --- Detectors/HMPID/workflow/README.md | 76 ++++++++++++++++++- .../workflow/src/PedestalsCalculationSpec.cxx | 66 +++++++++------- 2 files changed, 115 insertions(+), 27 deletions(-) diff --git a/Detectors/HMPID/workflow/README.md b/Detectors/HMPID/workflow/README.md index 7485fffb0ac76..bff8b0a4a0e5f 100644 --- a/Detectors/HMPID/workflow/README.md +++ b/Detectors/HMPID/workflow/README.md @@ -112,4 +112,78 @@ Example ``` [O2Suite/latest-o2] ~/Downloads/provaRec $> o2-hmpid-read-raw-file-workflow --raw-file test_full_flp1.raw -b | o2-hmpid-raw-to-digits-workflow -b | o2-hmpid-write-root-from-digits-workflow -b -``` \ No newline at end of file +``` + +### o2-hmpid-raw-to-pedestals-workflow +Write the Pedestals/Threshold files for the readout and registers Mean and Sigma in the CCDB + +``` +o2-hmpid-raw-to-pedestals-workflow --help full +``` + +Data processor options: HMP-DataDecoder: + +``` + --files-basepath arg (=/tmp/hmpPedThr) + Name of the Base Path of + Pedestals/Thresholds files. + --use-ccdb Register the Pedestals/Threshold values + into the CCDB + --ccdb-uri arg (=http://ccdb-test.cern.ch:8080) + URI for the CCDB access. + --pedestals-tag arg (=Latest) The tag applied to this set of + pedestals/threshold values + --sigmacut arg (=4) Sigma values for the Thresholds + calculation. +``` + +Example + +``` +o2-hmpid-read-raw-file-workflow --raw-file test_full_flp1.raw -b | o2-hmpid-raw-to-pedestals-workflow --sigmacut=2.5 --files-basepath /tmp/pippo -b --use-ccdb --pedestals-tag TEST3 +``` + +this command produce in the ccdb a set of `TMatrixF` object one for each chamber + +``` +Subfolder +HMP/Pedestals/TEST3/Mean_0 +HMP/Pedestals/TEST3/Mean_1 +HMP/Pedestals/TEST3/Mean_2 +HMP/Pedestals/TEST3/Mean_4 +HMP/Pedestals/TEST3/Sigma_0 +HMP/Pedestals/TEST3/Sigma_1 +HMP/Pedestals/TEST3/Sigma_2 +HMP/Pedestals/TEST3/Sigma_4 +``` + +and in addition a set of Ped/Thr files in the `/tmp` folder + +``` +-rw-r--r-- 1 fap wheel 92166 12 Feb 10:45 pippo_0.dat +-rw-r--r-- 1 fap wheel 92166 12 Feb 10:45 pippo_1.dat +-rw-r--r-- 1 fap wheel 92166 12 Feb 10:45 pippo_2.dat +-rw-r--r-- 1 fap wheel 92166 12 Feb 10:45 pippo_3.dat +-rw-r--r-- 1 fap wheel 92166 12 Feb 10:45 pippo_4.dat +-rw-r--r-- 1 fap wheel 92166 12 Feb 10:45 pippo_5.dat +-rw-r--r-- 1 fap wheel 92166 12 Feb 10:45 pippo_8.dat +-rw-r--r-- 1 fap wheel 92166 12 Feb 10:45 pippo_9.dat +``` + +the format of Ped/Thr is ASCII, one Hexadecimal Value for row **((Threshold & 0x001FF) << 9) | (Pedestal & 0x001FF)** , for a total of 15361 rows; the last value is the `End of File` indication (A0A0A) + +``` +0F674 +1027E +1047F +1469F +13699 +. +. +. +00000 +00000 +00000 +00000 +A0A0A +``` diff --git a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx index e373b6868805f..5a371618cc68f 100644 --- a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx +++ b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx @@ -26,6 +26,8 @@ #include "TTree.h" #include "TFile.h" +#include "TMath.h" +#include "TMatrixF.h" #include @@ -106,6 +108,7 @@ void PedestalsCalculationTask::endOfStream(framework::EndOfStreamContext& ec) char padsFileName[1024]; for(int e=0; egetAverageEventSize(e) == 0) continue; sprintf(padsFileName, "%s_%d.dat", mPedestalsBasePath.c_str(), e ); FILE *fpads = fopen( padsFileName, "w" ); // TODO: Add controls on the file open @@ -116,11 +119,13 @@ void PedestalsCalculationTask::endOfStream(framework::EndOfStreamContext& ec) SumOfCharge = mDeco->getChannelSum(e, c, d, h); SumOfSquares = mDeco->getChannelSquare(e, c, d, h); - Average = SumOfCharge / Samples; - if(Samples > 0) + if(Samples > 0) { + Average = SumOfCharge / Samples; Variance = sqrt( abs( (Samples * SumOfSquares) - (SumOfCharge * SumOfCharge) ) ) / Samples; - else + } else { + Average = 0; Variance = 0; + } Pedestal = (uint32_t) Average; Threshold = (uint32_t) (Variance * mSigmaCut + Average); Buffer = ((Threshold & 0x001FF) << 9) | (Pedestal & 0x001FF); @@ -154,45 +159,54 @@ void PedestalsCalculationTask::recordPedInCcdb() float xb,yb, ch; double Samples,SumOfCharge,SumOfSquares,Average,Variance; - TTree *theObj; - TString tit = TString::Format("Pedestals / Thresholds "); - theObj = new TTree("o2hmp", tit); - for(int i=0; iBranch("chamber", &ch,"s"); - theObj->Branch("x", &xb,"s"); - theObj->Branch("y", &yb,"s"); - theObj->Branch("Average", &Average,"f"); - theObj->Branch("Sigma", &Variance,"f"); + TObjArray aSigmas(Geo::N_MODULES); + TObjArray aPedestals(Geo::N_MODULES); + + for(int i=0; igetAverageEventSize(m*2) == 0 && mDeco->getAverageEventSize(m*2+1) == 0) continue; // If no events skip the chamber + TMatrixF *pS=(TMatrixF*)aSigmas.At(m); + TMatrixF *pP=(TMatrixF*)aPedestals.At(m); + for(int x=0; x < o2::hmpid::Geo::N_XROWS; x++ ) for(int y=0; y < o2::hmpid::Geo::N_YCOLS; y++) { - xb = x; - yb = y; - ch = m; + Samples = (double)mDeco->getPadSamples(m, x, y); SumOfCharge = mDeco->getPadSum(m, x, y); SumOfSquares = mDeco->getPadSquares(m, x, y); - Average = SumOfCharge / Samples; - if(Samples > 0) - Variance = sqrt( abs( (Samples * SumOfSquares) - (SumOfCharge * SumOfCharge) ) ) / Samples; - else - Variance = 0; - theObj->Fill(); + if(Samples > 0) { + (*pP)(x,y) = SumOfCharge / Samples; + (*pS)(x,y) = sqrt( abs( (Samples * SumOfSquares) - (SumOfCharge * SumOfCharge) ) ) / Samples; + } else { + (*pP)(x,y) = 0; + (*pS)(x,y) = 0; + } } - + } struct timeval tp; gettimeofday(&tp, NULL); uint64_t ms = tp.tv_sec * 1000 + tp.tv_usec / 1000; uint64_t minTimeStamp = ms; uint64_t maxTimeStamp = ms+1; - TString filename = TString::Format("HMP/Pedestals/%s", mPedestalTag.c_str()); - mDbMetadata.emplace("Tag", mPedestalTag.c_str() ); - mDBapi.storeAsTFileAny(theObj, filename.Data(), mDbMetadata, minTimeStamp, maxTimeStamp); + for(int i=0; igetAverageEventSize(i*2) == 0 && mDeco->getAverageEventSize(i*2+1) == 0) continue; // If no events skip the chamber + TString filename = TString::Format("HMP/Pedestals/%s/Mean_%d", mPedestalTag.c_str(),i); + mDbMetadata.emplace("Tag", mPedestalTag.c_str() ); + mDBapi.storeAsTFileAny(aPedestals.At(i), filename.Data(), mDbMetadata, minTimeStamp, maxTimeStamp); + } + for(int i=0; igetAverageEventSize(i*2) == 0 && mDeco->getAverageEventSize(i*2+1) == 0) continue; // If no events skip the chamber + TString filename = TString::Format("HMP/Pedestals/%s/Sigma_%d", mPedestalTag.c_str(),i); + mDbMetadata.emplace("Tag", mPedestalTag.c_str() ); + mDBapi.storeAsTFileAny(aSigmas.At(i), filename.Data(), mDbMetadata, minTimeStamp, maxTimeStamp); + } return; } From 7183897a27cb6b5a4d3e202bc36bab59c487e62a Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 12 Feb 2021 11:12:18 +0100 Subject: [PATCH 188/208] fix --- Detectors/HMPID/workflow/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/workflow/README.md b/Detectors/HMPID/workflow/README.md index bff8b0a4a0e5f..ce60e40341411 100644 --- a/Detectors/HMPID/workflow/README.md +++ b/Detectors/HMPID/workflow/README.md @@ -2,7 +2,7 @@ \page refHMPworkflow HMP workflow /doxy --> -# DPL workflows for the HMPID +# DPL workflows for the HMPID v.0.3 ## HMPID DPL processors From 39cd8aa8e2fd70fd72a5549f007d0ff463a8f4d5 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 15 Feb 2021 11:17:23 +0100 Subject: [PATCH 189/208] Fix clang format --- .../HMPID/base/include/HMPIDBase/Cluster.h | 24 +- .../HMPID/base/include/HMPIDBase/Common.h | 37 +-- .../HMPID/base/include/HMPIDBase/Digit.h | 186 +++++++------- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 30 +-- .../HMPID/base/include/HMPIDBase/Param.h | 21 +- .../HMPIDReconstruction/HmpidDecodeRawFile.h | 50 ++-- .../HMPIDReconstruction/HmpidDecodeRawMem.h | 54 ++-- .../HMPIDReconstruction/HmpidDecoder.h | 238 +++++++++--------- .../HMPIDReconstruction/HmpidEquipment.h | 120 +++++---- .../include/HMPIDSimulation/HMPIDDigitizer.h | 3 +- .../include/HMPIDSimulation/HmpidCoder.h | 228 ++++++++--------- .../include/HMPIDWorkflow/DataDecoderSpec.h | 41 ++- .../include/HMPIDWorkflow/DumpDigitsSpec.h | 42 ++-- .../HMPIDWorkflow/PedestalsCalculationSpec.h | 59 +++-- .../include/HMPIDWorkflow/ReadRawFileSpec.h | 29 ++- .../HMPIDWorkflow/WriteRawFromDigitsSpec.h | 47 ++-- 16 files changed, 602 insertions(+), 607 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Cluster.h b/Detectors/HMPID/base/include/HMPIDBase/Cluster.h index 836f804136e14..4ceb801e1aee5 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Cluster.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Cluster.h @@ -28,10 +28,9 @@ class Cluster public: Cluster() = default; - Cluster(Int_t chamber, Int_t size, Int_t NlocMax, Double_t QRaw, Double_t Q, Double_t X, Double_t Y); + Cluster(Int_t chamber, Int_t size, Int_t NlocMax, Double_t QRaw, Double_t Q, Double_t X, Double_t Y); ~Cluster() = default; - Int_t getCh() const { return mChamber; } void setCh(Int_t chamber) { mChamber = chamber; } @@ -50,19 +49,16 @@ class Cluster Int_t getY() const { return mY; } void setY(Int_t Y) { mY = Y; } - protected: - - Int_t mChamber; /// chamber number - Int_t mSize; /// size of the formed cluster from which this cluster deduced - Int_t mNlocMax; /// number of local maxima in formed cluster - Double_t mQRaw; /// QDC value of the raw cluster - Double_t mQ; /// QDC value of the actual cluster - Double_t mX; /// local x postion, [cm] - Double_t mY; /// local y postion, [cm] - - - ClassDefNV(Cluster, 1); + Int_t mChamber; /// chamber number + Int_t mSize; /// size of the formed cluster from which this cluster deduced + Int_t mNlocMax; /// number of local maxima in formed cluster + Double_t mQRaw; /// QDC value of the raw cluster + Double_t mQ; /// QDC value of the actual cluster + Double_t mX; /// local x postion, [cm] + Double_t mY; /// local y postion, [cm] + + ClassDefNV(Cluster, 1); }; } // namespace hmpid diff --git a/Detectors/HMPID/base/include/HMPIDBase/Common.h b/Detectors/HMPID/base/include/HMPIDBase/Common.h index 37fc38f9049c1..079fb272d482d 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Common.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Common.h @@ -19,55 +19,62 @@ namespace hmpid // ------- Execution time functions class ExecutionTimer { -private: + private: TStopwatch mTimer; Double_t mStartTime; Double_t mLastLogTime; Double_t mElapseLogTime; -public: - ExecutionTimer() { + public: + ExecutionTimer() + { mStartTime = 0; mLastLogTime = 0; mElapseLogTime = 10; // default 10 seconds - }; + }; - ~ExecutionTimer() {}; + ~ExecutionTimer(){}; Double_t getElapseLogTime() { return mElapseLogTime; }; - void setElapseLogTime(Double_t interval) { mElapseLogTime = interval; return; }; + void setElapseLogTime(Double_t interval) + { + mElapseLogTime = interval; + return; + }; - void start() { + void start() + { mStartTime = mTimer.CpuTime(); mLastLogTime = mStartTime; mTimer.Start(false); return; }; - void stop() { + void stop() + { mTimer.Stop(); return; }; - void logMes(std::string const message) { + void logMes(std::string const message) + { LOG(INFO) << message << " Execution time = " << (mTimer.CpuTime() - mStartTime); mTimer.Continue(); return; }; - void elapseMes(std::string const message) { - if(mTimer.CpuTime() - mLastLogTime > mElapseLogTime) { + void elapseMes(std::string const message) + { + if (mTimer.CpuTime() - mLastLogTime > mElapseLogTime) { LOG(INFO) << message << " Execution time = " << (mTimer.CpuTime() - mStartTime); mLastLogTime = mTimer.CpuTime(); } mTimer.Continue(); return; }; - }; -} -} - +} // namespace hmpid +} // namespace o2 #endif /* DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_COMMON_H_ */ diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 9a3cfdb8b5717..f1f9bc23d08e5 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -28,95 +28,105 @@ namespace hmpid //using DigitBase = o2::dataformats::TimeStamp; class Digit { - public: - + public: // Conversion functions - static inline uint32_t Abs(int ch, int pc, int x, int y) { return ch << 20 | pc << 16 | x << 8 | y; } - static inline int DDL2C(int ddl) { return ddl >> 1; } //ddl -> chamber - static inline int A2C(uint32_t pad) { return (pad & 0x00F00000) >> 20; } //abs pad -> chamber - static inline int A2P(uint32_t pad) { return (pad & 0x000F0000) >> 16; } //abs pad -> pc - static inline int A2X(uint32_t pad) { return (pad & 0x0000FF00) >> 8; } //abs pad -> pad X - static inline int A2Y(uint32_t pad) { return (pad & 0x000000FF); } //abs pad -> pad Y - static inline uint32_t Photo2Pad(int ch, int pc, int x, int y) { return Abs(ch, pc, x, y); } - static uint32_t Equipment2Pad(int Equi, int Colu, int Dilo, int Chan); - static void Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Chan); - static void Pad2Absolute(uint32_t pad, int *Module, int *x, int *y); - static uint32_t Absolute2Pad(int Module, int x, int y); - static void Pad2Photo(uint32_t pad, int *chamber, int *photo, int *x, int *y); - static void Absolute2Equipment(int Module, int x, int y, int *Equi, int *Colu, int *Dilo, int *Chan); - static void Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int *Module, int *x, int *y); - - static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC); - static uint32_t TimeNsToOrbit(double TimeNs); - static uint16_t TimeNsToBc(double TimeNs); - static void TimeNsToOrbitBc(double TimeNs, uint32_t &Orbit, uint16_t &Bc); - - // Operators definition ! - friend inline bool operator<(const Digit& l, const Digit& r) { return l.mPad < r.mPad; }; - friend inline bool operator==(const Digit& l, const Digit& r) { return l.mPad == r.mPad; }; - friend inline bool operator> (const Digit& l, const Digit& r){ return r < l; }; - friend inline bool operator<=(const Digit& l, const Digit& r){ return !(l > r); }; - friend inline bool operator>=(const Digit& l, const Digit& r){ return !(l < r); }; - friend inline bool operator!=(const Digit& l, const Digit& r) { return !(l == r); }; - - friend std::ostream& operator<< (std::ostream& os, const Digit& d) { - os << "[" << A2C(d.mPad) << "," << A2P(d.mPad) << "," << A2X(d.mPad) << "," << - A2Y(d.mPad) << "]@(" << d.mOrbit << "," << d.mBc << ")=" << d.mQ; - return os; - }; - - // Functions to manage Digit vectors - static bool eventEquipPadsComp(Digit &d1, Digit &d2); - static std::vector* extractDigitsPerEvent(std::vector &Digits, uint64_t EventID); - static std::vector* extractEvents(std::vector &Digits); - - - public: - Digit() = default; - Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad) {}; - Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge); - Digit(uint16_t bc, uint32_t orbit, uint16_t, int equipment, int column, int dilogic, int channel) ; - Digit(uint16_t bc, uint32_t orbit, uint16_t, int module, int x, int y); - - uint16_t getCharge() const { return mQ; } - int getPadID() const { return mPad; } - uint32_t getOrbit() const { return mOrbit; } - uint16_t getBC() const { return mBc; } - uint64_t getTriggerID() const { return ((mOrbit << 12) | mBc); } - void setOrbit(uint32_t orbit) { mOrbit = orbit; return; } - void setBC(uint16_t bc) { mBc = bc; return; } - void setTriggerID(uint64_t trigger) { mOrbit = (trigger >> 12); mBc = (trigger & 0x0FFF); return; } - - // convenience conversion to x-y pad coordinates - int getPx() const { return A2X(mPad); } - int getPy() const { return A2Y(mPad); } - int getPhC() const { return A2P(mPad); } - int getCh() const { return A2C(mPad); } - - - static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); - static float getFractionalContributionForPad(HitType const& hit, int somepad); - - // add charge to existing digit - void addCharge(float q) { mQ += q; } - - private: - uint16_t mQ = 0; - uint32_t mPad = 0; // -1 indicates invalid digit - uint16_t mBc = 0.; - uint32_t mOrbit = 0; - - static float LorsX(int pad) { return Param::LorsX(A2P(pad), A2X(pad)); } //center of the pad x, [cm] - static float LorsY(int pad) { return Param::LorsY(A2P(pad), A2Y(pad)); } //center of the pad y, [cm] - - // determines the total charge created by a hit - // might modify the localX, localY coordiates associated to the hit - static float QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY); - static float IntPartMathiX(float x, int pad); - static Double_t IntPartMathiY(Double_t y, int pad); - static float InMathieson(float localX, float localY, int pad); - - ClassDefNV(Digit, 2); + static inline uint32_t Abs(int ch, int pc, int x, int y) { return ch << 20 | pc << 16 | x << 8 | y; } + static inline int DDL2C(int ddl) { return ddl >> 1; } //ddl -> chamber + static inline int A2C(uint32_t pad) { return (pad & 0x00F00000) >> 20; } //abs pad -> chamber + static inline int A2P(uint32_t pad) { return (pad & 0x000F0000) >> 16; } //abs pad -> pc + static inline int A2X(uint32_t pad) { return (pad & 0x0000FF00) >> 8; } //abs pad -> pad X + static inline int A2Y(uint32_t pad) { return (pad & 0x000000FF); } //abs pad -> pad Y + static inline uint32_t Photo2Pad(int ch, int pc, int x, int y) { return Abs(ch, pc, x, y); } + static uint32_t Equipment2Pad(int Equi, int Colu, int Dilo, int Chan); + static void Pad2Equipment(uint32_t pad, int* Equi, int* Colu, int* Dilo, int* Chan); + static void Pad2Absolute(uint32_t pad, int* Module, int* x, int* y); + static uint32_t Absolute2Pad(int Module, int x, int y); + static void Pad2Photo(uint32_t pad, int* chamber, int* photo, int* x, int* y); + static void Absolute2Equipment(int Module, int x, int y, int* Equi, int* Colu, int* Dilo, int* Chan); + static void Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int* Module, int* x, int* y); + + static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC); + static uint32_t TimeNsToOrbit(double TimeNs); + static uint16_t TimeNsToBc(double TimeNs); + static void TimeNsToOrbitBc(double TimeNs, uint32_t& Orbit, uint16_t& Bc); + + // Operators definition ! + friend inline bool operator<(const Digit& l, const Digit& r) { return l.mPad < r.mPad; }; + friend inline bool operator==(const Digit& l, const Digit& r) { return l.mPad == r.mPad; }; + friend inline bool operator>(const Digit& l, const Digit& r) { return r < l; }; + friend inline bool operator<=(const Digit& l, const Digit& r) { return !(l > r); }; + friend inline bool operator>=(const Digit& l, const Digit& r) { return !(l < r); }; + friend inline bool operator!=(const Digit& l, const Digit& r) { return !(l == r); }; + + friend std::ostream& operator<<(std::ostream& os, const Digit& d) + { + os << "[" << A2C(d.mPad) << "," << A2P(d.mPad) << "," << A2X(d.mPad) << "," << A2Y(d.mPad) << "]@(" << d.mOrbit << "," << d.mBc << ")=" << d.mQ; + return os; + }; + + // Functions to manage Digit vectors + static bool eventEquipPadsComp(Digit& d1, Digit& d2); + static std::vector* extractDigitsPerEvent(std::vector& Digits, uint64_t EventID); + static std::vector* extractEvents(std::vector& Digits); + + public: + Digit() = default; + Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad){}; + Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge); + Digit(uint16_t bc, uint32_t orbit, uint16_t, int equipment, int column, int dilogic, int channel); + Digit(uint16_t bc, uint32_t orbit, uint16_t, int module, int x, int y); + + uint16_t getCharge() const { return mQ; } + int getPadID() const { return mPad; } + uint32_t getOrbit() const { return mOrbit; } + uint16_t getBC() const { return mBc; } + uint64_t getTriggerID() const { return ((mOrbit << 12) | mBc); } + void setOrbit(uint32_t orbit) + { + mOrbit = orbit; + return; + } + void setBC(uint16_t bc) + { + mBc = bc; + return; + } + void setTriggerID(uint64_t trigger) + { + mOrbit = (trigger >> 12); + mBc = (trigger & 0x0FFF); + return; + } + + // convenience conversion to x-y pad coordinates + int getPx() const { return A2X(mPad); } + int getPy() const { return A2Y(mPad); } + int getPhC() const { return A2P(mPad); } + int getCh() const { return A2C(mPad); } + + static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); + static float getFractionalContributionForPad(HitType const& hit, int somepad); + + // add charge to existing digit + void addCharge(float q) { mQ += q; } + + private: + uint16_t mQ = 0; + uint32_t mPad = 0; // -1 indicates invalid digit + uint16_t mBc = 0.; + uint32_t mOrbit = 0; + + static float LorsX(int pad) { return Param::LorsX(A2P(pad), A2X(pad)); } //center of the pad x, [cm] + static float LorsY(int pad) { return Param::LorsY(A2P(pad), A2Y(pad)); } //center of the pad y, [cm] + + // determines the total charge created by a hit + // might modify the localX, localY coordiates associated to the hit + static float QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY); + static float IntPartMathiX(float x, int pad); + static Double_t IntPartMathiY(Double_t y, int pad); + static float InMathieson(float localX, float localY, int pad); + + ClassDefNV(Digit, 2); }; } // namespace hmpid diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 2f6b3144e6080..60b70a7119f37 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -68,17 +68,16 @@ class Geo { public: // From AliTOFGeometry -// static void translate(Float_t* xyz, Float_t translationVector[3]); -// enum { -// // DAQ characteristics -// kNDDL = 4, // Number of DDL (Detector Data Link) per sector -// kNTRM = 12, // Number of TRM ( Readout Module) per DDL -// kNTdc = 15, // Number of Tdc (Time to Digital Converter) per TRM -// kNChain = 2, // Number of chains per TRM -// kNCrate = 72, // Number of Crates -// kNCh = 8 // Number of channels per Tdc -// }; - + // static void translate(Float_t* xyz, Float_t translationVector[3]); + // enum { + // // DAQ characteristics + // kNDDL = 4, // Number of DDL (Detector Data Link) per sector + // kNTRM = 12, // Number of TRM ( Readout Module) per DDL + // kNTdc = 15, // Number of Tdc (Time to Digital Converter) per TRM + // kNChain = 2, // Number of chains per TRM + // kNCrate = 72, // Number of Crates + // kNCh = 8 // Number of channels per Tdc + // }; // ---- HMPID geometry ------- static constexpr int MAXEQUIPMENTS = 14; @@ -111,11 +110,9 @@ class Geo static constexpr int MAXXPHOTO = 79; static constexpr int MAXYPHOTO = 47; + static void Module2Equipment(int Mod, int Row, int Col, int* Equi, int* Colu, int* Dilo, int* Chan); + static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int* Mod, int* Row, int* Col); - static void Module2Equipment(int Mod, int Row, int Col, int *Equi, int *Colu, int *Dilo, int *Chan); - static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Row, int *Col); - - // from //static constexpr Bool_t FEAWITHMASKS[NSECTORS] = // // TOF sectors with Nino masks: 0, 8, 9, 10, 16 @@ -123,8 +120,7 @@ class Geo // kTRUE, kTRUE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, kFALSE}; //; // Selecting TOF sectors containing FEA cooling masks - -// static Float_t getCableLength(Int_t icrate, Int_t islot, Int_t ichain, Int_t itdc) { return CABLELENGTH[icrate][islot - 3][ichain][itdc / 3]; } + // static Float_t getCableLength(Int_t icrate, Int_t islot, Int_t ichain, Int_t itdc) { return CABLELENGTH[icrate][islot - 3][ichain][itdc / 3]; } private: static void Init(); diff --git a/Detectors/HMPID/base/include/HMPIDBase/Param.h b/Detectors/HMPID/base/include/HMPIDBase/Param.h index 18c4de8dce030..d8d74ad91504a 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Param.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Param.h @@ -96,21 +96,20 @@ class Param static void Lors2Pad(float x, float y, Int_t& pc, Int_t& px, Int_t& py); //(x,y)->(pc,px,py) //(ch,pc,padx,pady)-> abs pad -// static Int_t Abs(Int_t ch, Int_t pc, Int_t x, Int_t y) { return ch * 100000000 + pc * 1000000 + x * 1000 + y; } -// static Int_t DDL2C(Int_t ddl) { return ddl / 2; } //ddl -> chamber -// static Int_t A2C(Int_t pad) { return pad / 100000000; } //abs pad -> chamber -// static Int_t A2P(Int_t pad) { return pad % 100000000 / 1000000; } //abs pad -> pc -// static Int_t A2X(Int_t pad) { return pad % 1000000 / 1000; } //abs pad -> pad X -// static Int_t A2Y(Int_t pad) { return pad % 1000; } //abs pad -> pad Y - + // static Int_t Abs(Int_t ch, Int_t pc, Int_t x, Int_t y) { return ch * 100000000 + pc * 1000000 + x * 1000 + y; } + // static Int_t DDL2C(Int_t ddl) { return ddl / 2; } //ddl -> chamber + // static Int_t A2C(Int_t pad) { return pad / 100000000; } //abs pad -> chamber + // static Int_t A2P(Int_t pad) { return pad % 100000000 / 1000000; } //abs pad -> pc + // static Int_t A2X(Int_t pad) { return pad % 1000000 / 1000; } //abs pad -> pad X + // static Int_t A2Y(Int_t pad) { return pad % 1000; } //abs pad -> pad Y // Moved in Digit.h static Int_t Abs(Int_t ch, Int_t pc, Int_t x, Int_t y) { return ch << 20 | pc << 16 | x << 8 | y; } - static Int_t DDL2C(Int_t ddl) { return ddl >> 1; } //ddl -> chamber - static Int_t A2C(Int_t pad) { return (pad & 0x00F00000) >> 20; } //abs pad -> chamber + static Int_t DDL2C(Int_t ddl) { return ddl >> 1; } //ddl -> chamber + static Int_t A2C(Int_t pad) { return (pad & 0x00F00000) >> 20; } //abs pad -> chamber static Int_t A2P(Int_t pad) { return (pad & 0x000F0000) >> 16; } //abs pad -> pc - static Int_t A2X(Int_t pad) { return (pad & 0x0000FF00) >> 8; } //abs pad -> pad X - static Int_t A2Y(Int_t pad) { return (pad & 0x000000FF); } //abs pad -> pad Y + static Int_t A2X(Int_t pad) { return (pad & 0x0000FF00) >> 8; } //abs pad -> pad X + static Int_t A2Y(Int_t pad) { return (pad & 0x000000FF); } //abs pad -> pad Y static bool IsOverTh(float q) { return q >= fgThreshold; } //is digit over threshold? diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h index 5f9fbd7020dfb..fed7466e1fd35 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawFile.h @@ -30,33 +30,33 @@ #define MAXFILENAMEBUFFER 512 #define MAXRAWFILEBUFFER RAWBLOCKDIMENSION_W * 4 + 8 -namespace o2 { - namespace hmpid { - - -class HmpidDecodeRawFile: public HmpidDecoder +namespace o2 +{ +namespace hmpid { - public: - HmpidDecodeRawFile(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); - HmpidDecodeRawFile(int numOfEquipments); - ~HmpidDecodeRawFile(); - - bool setUpStream(void *InpuFileName, long Size); - - private: - bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size); - bool getHeaderFromStream(uint32_t **streamPtr); - bool getWordFromStream(uint32_t *word); - int fileExists(char *filewithpath); - void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge); - - private: - FILE *fh; - char mInputFile[MAXFILENAMEBUFFER]; - uint32_t mFileBuffer[MAXRAWFILEBUFFER]; +class HmpidDecodeRawFile : public HmpidDecoder +{ + public: + HmpidDecodeRawFile(int* EqIds, int* CruIds, int* LinkIds, int numOfEquipments); + HmpidDecodeRawFile(int numOfEquipments); + ~HmpidDecodeRawFile(); + + bool setUpStream(void* InpuFileName, long Size); + + private: + bool getBlockFromStream(uint32_t** streamPtr, uint32_t Size); + bool getHeaderFromStream(uint32_t** streamPtr); + bool getWordFromStream(uint32_t* word); + int fileExists(char* filewithpath); + void setPad(HmpidEquipment* eq, int col, int dil, int ch, uint16_t charge); + + private: + FILE* fh; + char mInputFile[MAXFILENAMEBUFFER]; + uint32_t mFileBuffer[MAXRAWFILEBUFFER]; }; - } -} +} // namespace hmpid +} // namespace o2 #endif /* COMMON_HMPIDDECODERAWFILE_H_ */ diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h index 209660fb3f4d1..ff66c5f15c953 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h @@ -30,44 +30,42 @@ #include "HMPIDBase/Geo.h" #include "HmpidDecoder.h" -namespace o2{ - namespace hmpid { - - -class HmpidDecodeRawMem: public HmpidDecoder +namespace o2 +{ +namespace hmpid { - public: - HmpidDecodeRawMem(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); - HmpidDecodeRawMem(int numOfEquipments); - ~HmpidDecodeRawMem(); - bool setUpStream(void *Buffer, long BufferLen); +class HmpidDecodeRawMem : public HmpidDecoder +{ + public: + HmpidDecodeRawMem(int* EqIds, int* CruIds, int* LinkIds, int numOfEquipments); + HmpidDecodeRawMem(int numOfEquipments); + ~HmpidDecodeRawMem(); - private: - bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size); - bool getHeaderFromStream(uint32_t **streamPtr); - bool getWordFromStream(uint32_t *word); - void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge); + bool setUpStream(void* Buffer, long BufferLen); - private: + private: + bool getBlockFromStream(uint32_t** streamPtr, uint32_t Size); + bool getHeaderFromStream(uint32_t** streamPtr); + bool getWordFromStream(uint32_t* word); + void setPad(HmpidEquipment* eq, int col, int dil, int ch, uint16_t charge); + private: }; -class HmpidDecodeRawDigit: public HmpidDecodeRawMem +class HmpidDecodeRawDigit : public HmpidDecodeRawMem { - public: - HmpidDecodeRawDigit(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); - HmpidDecodeRawDigit(int numOfEquipments); - ~HmpidDecodeRawDigit(); - - std::vector mDigits; - - private: - void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge); + public: + HmpidDecodeRawDigit(int* EqIds, int* CruIds, int* LinkIds, int numOfEquipments); + HmpidDecodeRawDigit(int numOfEquipments); + ~HmpidDecodeRawDigit(); + std::vector mDigits; + private: + void setPad(HmpidEquipment* eq, int col, int dil, int ch, uint16_t charge); }; -} -} +} // namespace hmpid +} // namespace o2 #endif /* COMMON_HMPIDDECODERAWFILE_H_ */ diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index 506fe5e5a5946..f1302656abe5d 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -40,132 +40,130 @@ #define WTYPE_EOE 4 #define WTYPE_NONE 0 - // Hmpid Equipment class -namespace o2 { +namespace o2 +{ -namespace hmpid { +namespace hmpid +{ class HmpidDecoder { // Members - public: - int mVerbose; - HmpidEquipment *mTheEquipments[Geo::MAXEQUIPMENTS]; - int mNumberOfEquipments; - - static char sErrorDescription[MAXERRORS][MAXDESCRIPTIONLENGHT]; - static char sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT]; - - public: - uint64_t mHeEvent; - int mHeBusy; - int mNumberWordToRead; - int mPayloadTail; - - int mHeFEEID; - int mHeSize; - int mHeVer; - int mHePrior; - int mHeStop; - int mHePages; - int mEquipment; - - int mHeOffsetNewPack; - int mHeMemorySize; - - int mHeDetectorID; - int mHeDW; - int mHeCruID; - int mHePackNum; - int mHePAR; - - int mHePageNum; - int mHeLinkNum; - int mHeFirmwareVersion; - int mHeHmpidError; - int mHeBCDI; - int mHeORBIT; - int mHeTType; - - uint32_t *mActualStreamPtr; - uint32_t *mEndStreamPtr; - uint32_t *mStartStreamPtr; - int mRDHSize; - int mRDHAcceptedVersion; - - // Methods - public: - HmpidDecoder(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments); - HmpidDecoder(int numOfEquipments); - ~HmpidDecoder(); - - void init(); - virtual bool setUpStream(void *Buffer, long BufferLen) = 0; - void setVerbosity(int Level) - { - mVerbose = Level; - } - ; - int getVerbosity() - { - return (mVerbose); - } - ; - - int getNumberOfEquipments() - { - return (mNumberOfEquipments); - } - ; - int getEquipmentIndex(int EquipmentId); - int getEquipmentIndex(int CruID, int LinkId); - int getEquipmentID(int CruId, int LinkId); - - void decodePage(uint32_t **streamBuffer); - void decodePageFast(uint32_t **streamBuf); - bool decodeBuffer(); - bool decodeBufferFast(); - - uint16_t getChannelSamples(int Equipment, int Column, int Dilogic, int Channel); - double getChannelSum(int Equipment, int Column, int Dilogic, int Channel); - double getChannelSquare(int Equipment, int Column, int Dilogic, int Channel); - uint16_t getPadSamples(int Module, int Row, int Column); - double getPadSum(int Module, int Row, int Column); - double getPadSquares(int Module, int Row, int Column); - - void dumpErrors(int Equipment); - void dumpPads(int Equipment, int type = 0); - void writeSummaryFile(char *summaryFileName); - - float getAverageEventSize(int Equipment); - float getAverageBusyTime(int Equipment); - - protected: - int checkType(uint32_t wp, int *p1, int *p2, int *p3, int *p4); - bool isRowMarker(uint32_t wp, int *Err, int *rowSize, int *mark); - bool isSegmentMarker(uint32_t wp, int *Err, int *segSize, int *Seg, int *mark); - bool isEoEmarker(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize); - public: - bool decodeHmpidError(int ErrorField, char *outbuf); - void dumpHmpidError(int ErrorField); - bool isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge); - int decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex); - HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); - void updateStatistics(HmpidEquipment *eq); - protected: - virtual void setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) = 0; - virtual bool getBlockFromStream(uint32_t **streamPtr, uint32_t Size) = 0; - virtual bool getHeaderFromStream(uint32_t **streamPtr) = 0; - virtual bool getWordFromStream(uint32_t *word) = 0; - uint32_t* getActualStreamPtr() - { - return (mActualStreamPtr); - } - ; - + public: + int mVerbose; + HmpidEquipment* mTheEquipments[Geo::MAXEQUIPMENTS]; + int mNumberOfEquipments; + + static char sErrorDescription[MAXERRORS][MAXDESCRIPTIONLENGHT]; + static char sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT]; + + public: + uint64_t mHeEvent; + int mHeBusy; + int mNumberWordToRead; + int mPayloadTail; + + int mHeFEEID; + int mHeSize; + int mHeVer; + int mHePrior; + int mHeStop; + int mHePages; + int mEquipment; + + int mHeOffsetNewPack; + int mHeMemorySize; + + int mHeDetectorID; + int mHeDW; + int mHeCruID; + int mHePackNum; + int mHePAR; + + int mHePageNum; + int mHeLinkNum; + int mHeFirmwareVersion; + int mHeHmpidError; + int mHeBCDI; + int mHeORBIT; + int mHeTType; + + uint32_t* mActualStreamPtr; + uint32_t* mEndStreamPtr; + uint32_t* mStartStreamPtr; + int mRDHSize; + int mRDHAcceptedVersion; + + // Methods + public: + HmpidDecoder(int* EqIds, int* CruIds, int* LinkIds, int numOfEquipments); + HmpidDecoder(int numOfEquipments); + ~HmpidDecoder(); + + void init(); + virtual bool setUpStream(void* Buffer, long BufferLen) = 0; + void setVerbosity(int Level) + { + mVerbose = Level; + }; + int getVerbosity() + { + return (mVerbose); + }; + + int getNumberOfEquipments() + { + return (mNumberOfEquipments); + }; + int getEquipmentIndex(int EquipmentId); + int getEquipmentIndex(int CruID, int LinkId); + int getEquipmentID(int CruId, int LinkId); + + void decodePage(uint32_t** streamBuffer); + void decodePageFast(uint32_t** streamBuf); + bool decodeBuffer(); + bool decodeBufferFast(); + + uint16_t getChannelSamples(int Equipment, int Column, int Dilogic, int Channel); + double getChannelSum(int Equipment, int Column, int Dilogic, int Channel); + double getChannelSquare(int Equipment, int Column, int Dilogic, int Channel); + uint16_t getPadSamples(int Module, int Row, int Column); + double getPadSum(int Module, int Row, int Column); + double getPadSquares(int Module, int Row, int Column); + + void dumpErrors(int Equipment); + void dumpPads(int Equipment, int type = 0); + void writeSummaryFile(char* summaryFileName); + + float getAverageEventSize(int Equipment); + float getAverageBusyTime(int Equipment); + + protected: + int checkType(uint32_t wp, int* p1, int* p2, int* p3, int* p4); + bool isRowMarker(uint32_t wp, int* Err, int* rowSize, int* mark); + bool isSegmentMarker(uint32_t wp, int* Err, int* segSize, int* Seg, int* mark); + bool isEoEmarker(uint32_t wp, int* Err, int* Col, int* Dilogic, int* Eoesize); + + public: + bool decodeHmpidError(int ErrorField, char* outbuf); + void dumpHmpidError(int ErrorField); + bool isPadWord(uint32_t wp, int* Err, int* Col, int* Dilogic, int* Channel, int* Charge); + int decodeHeader(uint32_t* streamPtrAdr, int* EquipIndex); + HmpidEquipment* evaluateHeaderContents(int EquipmentIndex); + void updateStatistics(HmpidEquipment* eq); + + protected: + virtual void setPad(HmpidEquipment* eq, int col, int dil, int ch, uint16_t charge) = 0; + virtual bool getBlockFromStream(uint32_t** streamPtr, uint32_t Size) = 0; + virtual bool getHeaderFromStream(uint32_t** streamPtr) = 0; + virtual bool getWordFromStream(uint32_t* word) = 0; + uint32_t* getActualStreamPtr() + { + return (mActualStreamPtr); + }; }; -} -} +} // namespace hmpid +} // namespace o2 #endif /* COMMON_HMPIDDECODER_H_ */ diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h index 91f91987102ad..e6db8d4c83025 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h @@ -61,75 +61,69 @@ const int TH_WRONGBUFFERDIM = 11; const uint64_t OUTRANGEEVENTNUMBER = 0x1FFFFFFFFFFF; - class HmpidEquipment { - private: - - uint32_t mEquipmentId; - uint32_t mCruId; - uint32_t mLinkId; - - public: - - uint32_t mPadSamples[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; - double mPadSum[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; - double mPadSquares[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; - - int mErrors[MAXERRORS]; - - int mWillBeRowMarker; - int mWillBeSegmentMarker; - int mWillBeEoE; - int mWillBePad; - int mRowSize; - int mSegment; - int mColumnCounter; - int mWordsPerRowCounter; - int mWordsPerSegCounter; - int mWordsPerDilogicCounter; - - int mErrorsCounter; - int mErrorPadsPerEvent; - - uint64_t mEventNumber; - int mNumberOfEvents; - float mEventSizeAverage; - int mEventSize; - - int mSampleNumber; - float mPadsPerEventAverage; - - float mBusyTimeValue; - float mBusyTimeAverage; - int mBusyTimeSamples; - int mNumberOfEmptyEvents; - int mNumberOfWrongEvents; - int mTotalPads; - int mTotalErrors; - - public: - HmpidEquipment(int Equipment, int Cru, int Link); - ~HmpidEquipment(); - - int getEquipmentId() - { - return (mEquipmentId); - } - ; - int getEquipmentId(int cru, int link); - - void init(); - void resetPadMap(); - void resetErrors(); - void setError(int ErrType); - void setPad(int col, int dil, int cha, uint16_t charge); - + private: + uint32_t mEquipmentId; + uint32_t mCruId; + uint32_t mLinkId; + + public: + uint32_t mPadSamples[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; + double mPadSum[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; + double mPadSquares[Geo::N_COLUMNS][Geo::N_DILOGICS][Geo::N_CHANNELS]; + + int mErrors[MAXERRORS]; + + int mWillBeRowMarker; + int mWillBeSegmentMarker; + int mWillBeEoE; + int mWillBePad; + int mRowSize; + int mSegment; + int mColumnCounter; + int mWordsPerRowCounter; + int mWordsPerSegCounter; + int mWordsPerDilogicCounter; + + int mErrorsCounter; + int mErrorPadsPerEvent; + + uint64_t mEventNumber; + int mNumberOfEvents; + float mEventSizeAverage; + int mEventSize; + + int mSampleNumber; + float mPadsPerEventAverage; + + float mBusyTimeValue; + float mBusyTimeAverage; + int mBusyTimeSamples; + int mNumberOfEmptyEvents; + int mNumberOfWrongEvents; + int mTotalPads; + int mTotalErrors; + + public: + HmpidEquipment(int Equipment, int Cru, int Link); + ~HmpidEquipment(); + + int getEquipmentId() + { + return (mEquipmentId); + }; + int getEquipmentId(int cru, int link); + + void init(); + void resetPadMap(); + void resetErrors(); + void setError(int ErrType); + void setPad(int col, int dil, int cha, uint16_t charge); }; } // namespace hmpid } // namespace o2 - #endif /* COMMON_HMPIDEQUIPMENT_H_ */ diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h index 9706216aa26f6..8ef8b579773bb 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h @@ -87,8 +87,7 @@ class HMPIDDigitizer double mCurrentTriggerTime = 0.; uint32_t mOrbit = 0; uint16_t mBc = 0; - - + int mEventID = 0; int mSrcID = 0; diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h index e435e9fcc2cc9..6decec7a78df3 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h @@ -39,124 +39,126 @@ #define CHARGE_CONST 150 #define CHARGE_RAND_MAX 400 -namespace o2 { +namespace o2 +{ -namespace hmpid { +namespace hmpid +{ class HmpidCoder { - public: - int mVerbose; - int mNumberOfEquipments; - - private: - // The standard definition of HMPID equipments at P2 - const int mEqIds[Geo::MAXEQUIPMENTS] = { 0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13 }; - const int mCruIds[Geo::MAXEQUIPMENTS] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3 }; - const int mLinkIds[Geo::MAXEQUIPMENTS] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2 }; - const int mFlpIds[Geo::MAXEQUIPMENTS] = { 160, 160, 160, 160, 160, 160, 160, 160, 161, 161, 161, 161, 161, 161 }; - - bool mRandomCharge; - bool mRandomOccupancy; - - int mOccupancyPercentage; - - int mPailoadBufferDimPerEquipment; - uint32_t *mPayloadBufferPtr; - uint32_t *mEventBufferPtr; - uint32_t *mEventBufferBasePtr; - int mEventSizePerEquipment[Geo::MAXEQUIPMENTS]; - uint32_t mPacketCounterPerEquipment[Geo::MAXEQUIPMENTS]; - bool mSkipEmptyEvents; - bool mFixedPacketLenght; - - std::string mFileName160; - std::string mFileName161; - FILE *mOutStream160; - FILE *mOutStream161; - - long mPadsCoded; - long mPacketsCoded; - - std::vector mDigits; - uint32_t mPreviousOrbit = 0; - uint16_t mPreviousBc = 0; - long mLastProcessedDigit =0; - uint32_t *mPadMap; - - public: - HmpidCoder(int numOfEquipments, bool skipEmptyEvents = false, bool fixedPacketLenght = true); - virtual ~HmpidCoder(); - - void reset(); - void setVerbosity(int Level) - { - mVerbose = Level; - }; - int getVerbosity() - { - return (mVerbose); - }; - int getNumberOfEquipments() - { - return (mNumberOfEquipments); - }; - - void setChargeRandomize(bool isRandom) - { - mRandomCharge = isRandom; - }; - bool getChargeRandomize() - { - return(mRandomCharge); - }; - - void setOccupancyRandomize(bool isRandom) - { - mRandomOccupancy = isRandom; - }; - bool getOccupancyRandomize() - { - return(mRandomOccupancy); - }; - - void setOccupancy(int Occupancy) - { - mOccupancyPercentage = Occupancy; - }; - int getOccupancy() - { - return(mOccupancyPercentage); - }; - - int addDigitsChunk(std::vector &digits); - void codeDigitsChunk(bool flushBuffer = false); - void codeDigitsVector(std::vector &digits); - - void openOutputStream(const char *OutputFileName); - void closeOutputStream(); - - void codeRandomEvent(uint32_t orbit, uint16_t bc); - void codeTest(int Events, uint16_t charge); - - void dumpResults(); - - protected: - void createRandomPayloadPerEvent(); - void savePacket(int Flp, int packetSize); - int calculateNumberOfPads(); - void codeEventChunkDigits(std::vector &digits, bool flushVector = false); - - private: - void getEquipCoord(int Equi, uint32_t *CruId, uint32_t *LinkId); - int getEquipmentPadIndex(int eq, int col, int dil, int cha); - int writeHeader(uint32_t *Buffer, uint32_t WordsToRead, uint32_t PayloadWords, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum); - void fillPadsMap(uint32_t *padMap); - void fillTheOutputBuffer(uint32_t* padMap); - void writePaginatedEvent(uint32_t orbit, uint16_t bc); + public: + int mVerbose; + int mNumberOfEquipments; + + private: + // The standard definition of HMPID equipments at P2 + const int mEqIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13}; + const int mCruIds[Geo::MAXEQUIPMENTS] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3}; + const int mLinkIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2}; + const int mFlpIds[Geo::MAXEQUIPMENTS] = {160, 160, 160, 160, 160, 160, 160, 160, 161, 161, 161, 161, 161, 161}; + + bool mRandomCharge; + bool mRandomOccupancy; + + int mOccupancyPercentage; + + int mPailoadBufferDimPerEquipment; + uint32_t* mPayloadBufferPtr; + uint32_t* mEventBufferPtr; + uint32_t* mEventBufferBasePtr; + int mEventSizePerEquipment[Geo::MAXEQUIPMENTS]; + uint32_t mPacketCounterPerEquipment[Geo::MAXEQUIPMENTS]; + bool mSkipEmptyEvents; + bool mFixedPacketLenght; + + std::string mFileName160; + std::string mFileName161; + FILE* mOutStream160; + FILE* mOutStream161; + + long mPadsCoded; + long mPacketsCoded; + + std::vector mDigits; + uint32_t mPreviousOrbit = 0; + uint16_t mPreviousBc = 0; + long mLastProcessedDigit = 0; + uint32_t* mPadMap; + + public: + HmpidCoder(int numOfEquipments, bool skipEmptyEvents = false, bool fixedPacketLenght = true); + virtual ~HmpidCoder(); + + void reset(); + void setVerbosity(int Level) + { + mVerbose = Level; + }; + int getVerbosity() + { + return (mVerbose); + }; + int getNumberOfEquipments() + { + return (mNumberOfEquipments); + }; + + void setChargeRandomize(bool isRandom) + { + mRandomCharge = isRandom; + }; + bool getChargeRandomize() + { + return (mRandomCharge); + }; + + void setOccupancyRandomize(bool isRandom) + { + mRandomOccupancy = isRandom; + }; + bool getOccupancyRandomize() + { + return (mRandomOccupancy); + }; + + void setOccupancy(int Occupancy) + { + mOccupancyPercentage = Occupancy; + }; + int getOccupancy() + { + return (mOccupancyPercentage); + }; + + int addDigitsChunk(std::vector& digits); + void codeDigitsChunk(bool flushBuffer = false); + void codeDigitsVector(std::vector& digits); + + void openOutputStream(const char* OutputFileName); + void closeOutputStream(); + + void codeRandomEvent(uint32_t orbit, uint16_t bc); + void codeTest(int Events, uint16_t charge); + + void dumpResults(); + + protected: + void createRandomPayloadPerEvent(); + void savePacket(int Flp, int packetSize); + int calculateNumberOfPads(); + void codeEventChunkDigits(std::vector& digits, bool flushVector = false); + + private: + void getEquipCoord(int Equi, uint32_t* CruId, uint32_t* LinkId); + int getEquipmentPadIndex(int eq, int col, int dil, int cha); + int writeHeader(uint32_t* Buffer, uint32_t WordsToRead, uint32_t PayloadWords, int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum); + void fillPadsMap(uint32_t* padMap); + void fillTheOutputBuffer(uint32_t* padMap); + void writePaginatedEvent(uint32_t orbit, uint16_t bc); }; -} -} +} // namespace hmpid +} // namespace o2 #endif /* COMMON_HMPIDCODER_H_ */ diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h index 035235156a047..ff9151ce28c46 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DataDecoderSpec.h @@ -8,7 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. - #ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ #define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ @@ -23,26 +22,26 @@ namespace o2 namespace hmpid { - class DataDecoderTask : public framework::Task - { - public: - DataDecoderTask() = default; - ~DataDecoderTask() override = default; - void init(framework::InitContext& ic) final; - void run(framework::ProcessingContext& pc) final; - void decodeTF(framework::ProcessingContext& pc); - void decodeReadout(framework::ProcessingContext& pc); - void decodeRawFile(framework::ProcessingContext& pc); - void endOfStream(framework::EndOfStreamContext& ec) override; - - private: - HmpidDecodeRawDigit *mDeco; - long mTotalDigits; - long mTotalFrames; - std::string mRootStatFile; - - ExecutionTimer mExTimer; - }; +class DataDecoderTask : public framework::Task +{ + public: + DataDecoderTask() = default; + ~DataDecoderTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + void decodeTF(framework::ProcessingContext& pc); + void decodeReadout(framework::ProcessingContext& pc); + void decodeRawFile(framework::ProcessingContext& pc); + void endOfStream(framework::EndOfStreamContext& ec) override; + + private: + HmpidDecodeRawDigit* mDeco; + long mTotalDigits; + long mTotalFrames; + std::string mRootStatFile; + + ExecutionTimer mExTimer; +}; o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec = "TF:HMP/RAWDATA"); //o2::framework::DataProcessorSpec getDecodingSpec(); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h index 615486fa44960..b9965c29c1725 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/DumpDigitsSpec.h @@ -29,27 +29,27 @@ namespace o2 namespace hmpid { - class DumpDigitsTask : public framework::Task - { - public: - DumpDigitsTask() = default; - ~DumpDigitsTask() override = default; - void init(framework::InitContext& ic) final; - void run(framework::ProcessingContext& pc) final; - void endOfStream(framework::EndOfStreamContext& ec) override; - - private: - bool mPrintDigits = false; - bool mIsOutputOnFile = false; - std::string mOutputFileName = ""; - std::ofstream mOsFile; - - int mOrbit; - int mBc; - long mDigitsReceived; - - ExecutionTimer mExTimer; - }; +class DumpDigitsTask : public framework::Task +{ + public: + DumpDigitsTask() = default; + ~DumpDigitsTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + void endOfStream(framework::EndOfStreamContext& ec) override; + + private: + bool mPrintDigits = false; + bool mIsOutputOnFile = false; + std::string mOutputFileName = ""; + std::ofstream mOsFile; + + int mOrbit; + int mBc; + long mDigitsReceived; + + ExecutionTimer mExTimer; +}; o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec = "HMP/DIGITS"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h index 7f88a76aa0f50..d516068394d50 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/PedestalsCalculationSpec.h @@ -8,7 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. - #ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ #define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_DATADECODERSPEC_H_ @@ -25,35 +24,35 @@ namespace o2 namespace hmpid { - class PedestalsCalculationTask : public framework::Task - { - public: - PedestalsCalculationTask() = default; - ~PedestalsCalculationTask() override = default; - void init(framework::InitContext& ic) final; - void run(framework::ProcessingContext& pc) final; - void decodeTF(framework::ProcessingContext& pc); - void decodeReadout(framework::ProcessingContext& pc); - void decodeRawFile(framework::ProcessingContext& pc); - void endOfStream(framework::EndOfStreamContext& ec) override; - - private: - void recordPedInCcdb(); - - private: - HmpidDecodeRawMem *mDeco; - long mTotalDigits; - long mTotalFrames; - std::string mPedestalsBasePath; - float mSigmaCut; - std::string mPedestalTag; - - o2::ccdb::CcdbApi mDBapi; - std::map mDbMetadata; // can be empty - bool mWriteToDB; - - ExecutionTimer mExTimer; - }; +class PedestalsCalculationTask : public framework::Task +{ + public: + PedestalsCalculationTask() = default; + ~PedestalsCalculationTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + void decodeTF(framework::ProcessingContext& pc); + void decodeReadout(framework::ProcessingContext& pc); + void decodeRawFile(framework::ProcessingContext& pc); + void endOfStream(framework::EndOfStreamContext& ec) override; + + private: + void recordPedInCcdb(); + + private: + HmpidDecodeRawMem* mDeco; + long mTotalDigits; + long mTotalFrames; + std::string mPedestalsBasePath; + float mSigmaCut; + std::string mPedestalTag; + + o2::ccdb::CcdbApi mDBapi; + std::map mDbMetadata; // can be empty + bool mWriteToDB; + + ExecutionTimer mExTimer; +}; o2::framework::DataProcessorSpec getPedestalsCalculationSpec(std::string inputSpec = "TF:HMP/RAWDATA"); //o2::framework::DataProcessorSpec getDecodingSpec(); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h index fab72e3185f12..d6d69d1433562 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/ReadRawFileSpec.h @@ -8,7 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. - #ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_READRAWFILESPEC_H_ #define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_READRAWFILESPEC_H_ @@ -23,20 +22,20 @@ namespace o2 namespace hmpid { - class RawFileReaderTask : public framework::Task - { - public: - RawFileReaderTask() = default; - ~RawFileReaderTask() override = default; - void init(framework::InitContext& ic) final; - void run(framework::ProcessingContext& pc) final; - - private: - std::ifstream mInputFile{}; ///< input file - bool mPrint = false; ///< print debug messages - - ExecutionTimer mExTimer; - }; +class RawFileReaderTask : public framework::Task +{ + public: + RawFileReaderTask() = default; + ~RawFileReaderTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + + private: + std::ifstream mInputFile{}; ///< input file + bool mPrint = false; ///< print debug messages + + ExecutionTimer mExTimer; +}; o2::framework::DataProcessorSpec getReadRawFileSpec(std::string inputSpec = "HMP/RAWDATA"); diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h index 7290acf943a39..b9fa00d63d4bc 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromDigitsSpec.h @@ -8,7 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. - #ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMDIGITS_H_ #define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMDIGITS_H_ @@ -25,29 +24,29 @@ namespace o2 namespace hmpid { - class WriteRawFromDigitsTask : public framework::Task - { - public: - WriteRawFromDigitsTask() = default; - ~WriteRawFromDigitsTask() override = default; - void init(framework::InitContext& ic) final; - void run(framework::ProcessingContext& pc) final; - void endOfStream(framework::EndOfStreamContext& ec) override; - - private: - // static bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); - std::string mBaseFileName = ""; - std::vector mDigits; - bool mSkipEmpty = false; - bool mFixedPacketLenght = false; - bool mOrderTheEvents = true; - long mDigitsReceived; - long mFramesReceived; - bool mIsTheStremClosed = false; - HmpidCoder *mCod; - - ExecutionTimer mExTimer; - }; +class WriteRawFromDigitsTask : public framework::Task +{ + public: + WriteRawFromDigitsTask() = default; + ~WriteRawFromDigitsTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + void endOfStream(framework::EndOfStreamContext& ec) override; + + private: + // static bool eventEquipPadsComparision(o2::hmpid::Digit d1, o2::hmpid::Digit d2); + std::string mBaseFileName = ""; + std::vector mDigits; + bool mSkipEmpty = false; + bool mFixedPacketLenght = false; + bool mOrderTheEvents = true; + long mDigitsReceived; + long mFramesReceived; + bool mIsTheStremClosed = false; + HmpidCoder* mCod; + + ExecutionTimer mExTimer; +}; o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec = "HMP/DIGITS"); From 6b1be223febc7a941a3cd003c527d8f9608e62c9 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 15 Feb 2021 11:18:18 +0100 Subject: [PATCH 190/208] Fix clang-format 2 --- Detectors/HMPID/base/src/Cluster.cxx | 2 +- Detectors/HMPID/base/src/Digit.cxx | 107 ++++----- Detectors/HMPID/base/src/Geo.cxx | 25 +-- .../HMPID/reconstruction/src/Clusterer.cxx | 1 - .../reconstruction/src/HmpidDecodeRawFile.cxx | 31 ++- .../reconstruction/src/HmpidDecodeRawMem.cxx | 47 ++-- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 209 ++++++++---------- .../reconstruction/src/HmpidEquipment.cxx | 5 +- .../HMPID/simulation/src/HMPIDDigitizer.cxx | 2 +- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 122 +++++----- .../HMPID/workflow/src/DataDecoderSpec.cxx | 96 ++++---- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 26 ++- .../workflow/src/PedestalsCalculationSpec.cxx | 144 ++++++------ .../HMPID/workflow/src/ReadRawFileSpec.cxx | 10 +- .../workflow/src/WriteRawFromDigitsSpec.cxx | 11 +- .../workflow/src/dump-digits-workflow.cxx | 4 +- .../workflow/src/raw-to-digits-workflow.cxx | 1 - .../src/raw-to-pedestals-workflow.cxx | 1 - .../workflow/src/read-raw-file-workflow.cxx | 14 +- .../src/write-raw-from-digits-workflow.cxx | 5 +- .../src/write-root-from-digits-workflow.cxx | 1 - 21 files changed, 407 insertions(+), 457 deletions(-) diff --git a/Detectors/HMPID/base/src/Cluster.cxx b/Detectors/HMPID/base/src/Cluster.cxx index 05770b85e1ffd..1b5197b33d0c0 100644 --- a/Detectors/HMPID/base/src/Cluster.cxx +++ b/Detectors/HMPID/base/src/Cluster.cxx @@ -17,7 +17,7 @@ using namespace o2::hmpid; ClassImp(o2::hmpid::Cluster); -Cluster::Cluster(Int_t chamber, Int_t size, Int_t NlocMax, Double_t QRaw, Double_t Q, Double_t X, Double_t Y) +Cluster::Cluster(Int_t chamber, Int_t size, Int_t NlocMax, Double_t QRaw, Double_t Q, Double_t X, Double_t Y) : mChamber(chamber), mSize(size), mNlocMax(NlocMax), mQRaw(QRaw), mQ(Q), mX(X), mY(Y) { } diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 6e5d03a3f6fc1..71567580a6963 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -20,27 +20,27 @@ using namespace o2::hmpid; ClassImp(o2::hmpid::Digit); // ----- Constructors ------------ - Digit::Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge) +Digit::Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge) { mBc = bc; mOrbit = orbit; - mQ = charge; + mQ = charge; mPad = Abs(chamber, photo, x, y); } - Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int column, int dilogic, int channel) +Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int column, int dilogic, int channel) { mBc = bc; mOrbit = orbit; - mQ = charge; + mQ = charge; mPad = Equipment2Pad(equipment, column, dilogic, channel); } - Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, int y) +Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, int y) { mBc = bc; mOrbit = orbit; - mQ = charge; + mQ = charge; mPad = Absolute2Pad(module, x, y); } @@ -48,55 +48,56 @@ ClassImp(o2::hmpid::Digit); uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) { // Check the input data - if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || - Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return -1; + if (Equi < 0 || Equi >= Geo::MAXEQUIPMENTS || Colu < 0 || Colu >= Geo::N_COLUMNS || + Dilo < 0 || Dilo >= Geo::N_DILOGICS || Chan < 0 || Chan >= Geo::N_CHANNELS) + return -1; - int chan2y[6]={3,2,4,1,5,0}; // y coordinate translation for a channel address (index position) for even chamber + int chan2y[6] = {3, 2, 4, 1, 5, 0}; // y coordinate translation for a channel address (index position) for even chamber bool isEven = (Equi % Geo::EQUIPMENTSPERMODULE) == 0 ? true : false; // Calculate the odd/even of geometry - int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module + int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module // Calculate the x,y photo cathode relative coords For Odd equipment int pc = (Colu / Geo::N_COLXSEGMENT) * 2 + 1; // col [0..23] -> [1,3,5] int px = Geo::MAXXPHOTO - ((Dilo * Geo::DILOPADSROWS) + (Chan / Geo::DILOPADSCOLS)); int py = (Colu % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS + chan2y[Chan % Geo::DILOPADSCOLS]; - if(isEven) { + if (isEven) { pc = 5 - pc; py = Geo::MAXYPHOTO - py; } - return Abs(ch,pc,px,py); // Pack the coords into the PadID word + return Abs(ch, pc, px, py); // Pack the coords into the PadID word } -void Digit::Pad2Equipment(uint32_t pad, int *Equi, int *Colu, int *Dilo, int *Chan) +void Digit::Pad2Equipment(uint32_t pad, int* Equi, int* Colu, int* Dilo, int* Chan) { int ch, ph, px, py; - int y2chan[6]={5,3,1,0,2,4}; + int y2chan[6] = {5, 3, 1, 0, 2, 4}; Pad2Photo(pad, &ch, &ph, &px, &py); // Unpak the pad ID in the photo cathode coords bool isEven = (ph % 2) == 0 ? true : false; - int eq = ch * Geo::EQUIPMENTSPERMODULE +1; + int eq = ch * Geo::EQUIPMENTSPERMODULE + 1; px = Geo::MAXXPHOTO - px; // revert the X coord - if(isEven) { - eq--; // Correct the equipment number + if (isEven) { + eq--; // Correct the equipment number py = Geo::MAXYPHOTO - py; // revert the Y coord - ph = 5 - ph; // revert the photo cathode index [0,2,4] -> [5,3,1] + ph = 5 - ph; // revert the photo cathode index [0,2,4] -> [5,3,1] } - *Dilo = px / Geo::DILOPADSROWS; // Calculate the Dilogic x [0..79] -> dil [0..9] - *Colu = ((ph / 2) * Geo::N_COLXSEGMENT) + (py / Geo::DILOPADSCOLS); // calculate the column (ph [1,3,5], y [0..47]) -> col [0..23] + *Dilo = px / Geo::DILOPADSROWS; // Calculate the Dilogic x [0..79] -> dil [0..9] + *Colu = ((ph / 2) * Geo::N_COLXSEGMENT) + (py / Geo::DILOPADSCOLS); // calculate the column (ph [1,3,5], y [0..47]) -> col [0..23] *Chan = ((px % Geo::DILOPADSROWS) * Geo::DILOPADSCOLS) + y2chan[py % Geo::DILOPADSCOLS]; *Equi = eq; return; } -void Digit::Absolute2Equipment(int Module, int x, int y, int *Equi, int *Colu, int *Dilo, int *Chan) +void Digit::Absolute2Equipment(int Module, int x, int y, int* Equi, int* Colu, int* Dilo, int* Chan) { uint32_t pad = Absolute2Pad(Module, x, y); Pad2Equipment(pad, Equi, Colu, Dilo, Chan); return; } -void Digit::Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int *Module, int *x, int *y) +void Digit::Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int* Module, int* x, int* y) { uint32_t pad = Equipment2Pad(Equi, Colu, Dilo, Chan); Pad2Absolute(pad, Module, x, y); @@ -105,29 +106,29 @@ void Digit::Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int *Modu uint32_t Digit::Absolute2Pad(int Module, int x, int y) { - int ph = (y/Geo::N_PHOTOCATODSY)*2+((x >= Geo::HALFXROWS ) ? 1 : 0); - int px = x % Geo::HALFXROWS; - int py = y % Geo::N_PHOTOCATODSY; - return Abs(Module,ph,px,py); + int ph = (y / Geo::N_PHOTOCATODSY) * 2 + ((x >= Geo::HALFXROWS) ? 1 : 0); + int px = x % Geo::HALFXROWS; + int py = y % Geo::N_PHOTOCATODSY; + return Abs(Module, ph, px, py); } -void Digit::Pad2Absolute(uint32_t pad, int *Module, int *x, int *y) +void Digit::Pad2Absolute(uint32_t pad, int* Module, int* x, int* y) { *Module = A2C(pad); int ph = A2P(pad); - int px = A2X(pad); - int py = A2Y(pad); + int px = A2X(pad); + int py = A2Y(pad); *x = px + ((ph % 2 == 1) ? Geo::HALFXROWS : 0); *y = ((ph >> 1) * Geo::N_PHOTOCATODSY) + py; return; } -void Digit::Pad2Photo(uint32_t pad, int *chamber, int *photo, int *x, int *y) +void Digit::Pad2Photo(uint32_t pad, int* chamber, int* photo, int* x, int* y) { *chamber = A2C(pad); *photo = A2P(pad); - *x = A2X(pad); - *y = A2Y(pad); + *x = A2X(pad); + *y = A2Y(pad); return; } @@ -207,7 +208,6 @@ float Digit::IntPartMathiX(float x, int pad) return o2::hmpid::Param::K4x() * (TMath::ATan(ux2) - TMath::ATan(ux1)); } - Double_t Digit::IntPartMathiY(Double_t y, int pad) { // Integration of Mathieson. @@ -231,20 +231,20 @@ float Digit::InMathieson(float localX, float localY, int pad) // Time conversion functions double Digit::OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) { - return( BC * o2::constants::lhc::LHCBunchSpacingNS + Orbit * o2::constants::lhc::LHCOrbitNS); + return (BC * o2::constants::lhc::LHCBunchSpacingNS + Orbit * o2::constants::lhc::LHCOrbitNS); } uint32_t Digit::TimeNsToOrbit(double TimeNs) { - return(TimeNs / o2::constants::lhc::LHCOrbitNS); + return (TimeNs / o2::constants::lhc::LHCOrbitNS); } uint16_t Digit::TimeNsToBc(double TimeNs) { - return(std::fmod(TimeNs , o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); + return (std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); } -void Digit::TimeNsToOrbitBc(double TimeNs, uint32_t &Orbit, uint16_t &Bc) +void Digit::TimeNsToOrbitBc(double TimeNs, uint32_t& Orbit, uint16_t& Bc) { Orbit = TimeNsToOrbit(TimeNs); Bc = TimeNsToBc(TimeNs); @@ -254,37 +254,38 @@ void Digit::TimeNsToOrbitBc(double TimeNs, uint32_t &Orbit, uint16_t &Bc) // Functions to manage Digit vectors // Function for order digits (Event,Chamber,Photo,x,y) -bool Digit::eventEquipPadsComp(Digit &d1, Digit &d2) +bool Digit::eventEquipPadsComp(Digit& d1, Digit& d2) { - uint64_t t1,t2; + uint64_t t1, t2; t1 = d1.getTriggerID(); t2 = d2.getTriggerID(); - if (t1 < t2) return true; - if (t2 < t1) return false; - if (d1.getPadID() < d2.getPadID()) return true; + if (t1 < t2) + return true; + if (t2 < t1) + return false; + if (d1.getPadID() < d2.getPadID()) + return true; return false; }; -std::vector* Digit::extractDigitsPerEvent(std::vector &Digits, uint64_t EventID) +std::vector* Digit::extractDigitsPerEvent(std::vector& Digits, uint64_t EventID) { std::vector* subVector = new std::vector(); - for(const auto & digit : Digits) { - if(digit.getTriggerID() == EventID) { - subVector->push_back(digit); + for (const auto& digit : Digits) { + if (digit.getTriggerID() == EventID) { + subVector->push_back(digit); } } - return(subVector); + return (subVector); }; -std::vector* Digit::extractEvents(std::vector &Digits) +std::vector* Digit::extractEvents(std::vector& Digits) { std::vector* subVector = new std::vector(); - for(const auto & digit : Digits) { - if(find(subVector->begin(), subVector->end(), digit.getTriggerID()) == subVector->end()) { + for (const auto& digit : Digits) { + if (find(subVector->begin(), subVector->end(), digit.getTriggerID()) == subVector->end()) { subVector->push_back(digit.getTriggerID()); } } - return(subVector); + return (subVector); }; - - diff --git a/Detectors/HMPID/base/src/Geo.cxx b/Detectors/HMPID/base/src/Geo.cxx index f2c8ad232d3b2..aadd52a2de800 100644 --- a/Detectors/HMPID/base/src/Geo.cxx +++ b/Detectors/HMPID/base/src/Geo.cxx @@ -34,9 +34,9 @@ void Geo::Init() /// /// (0,0,0,0) Right Top (1,0,0,0) Left Bottom /// -void Geo::Module2Equipment(int Mod, int Row, int Col, int *Equi, int *Colu, int *Dilo, int *Chan) +void Geo::Module2Equipment(int Mod, int Row, int Col, int* Equi, int* Colu, int* Dilo, int* Chan) { -/* if (Row > MAXHALFXROWS) { + /* if (Row > MAXHALFXROWS) { *Equi = Mod * EQUIPMENTSPERMODULE + 1; Row = Row - HALFXROWS; } else { @@ -49,7 +49,7 @@ void Geo::Module2Equipment(int Mod, int Row, int Col, int *Equi, int *Colu, int *Chan = (Row % DILOPADSROWS) * DILOPADSCOLS + (Col % DILOPADSCOLS); return; */ - int y2a[6]={5,3,1,0,2,4}; + int y2a[6] = {5, 3, 1, 0, 2, 4}; int ch, ax, ay; if (ax > Geo::MAXHALFXROWS) { *Equi = ch * Geo::EQUIPMENTSPERMODULE + 1; @@ -73,9 +73,9 @@ void Geo::Module2Equipment(int Mod, int Row, int Col, int *Equi, int *Colu, int /// /// (0,0,0,0) Right Top (1,0,0,0) Left Bottom /// -void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Row, int *Col) +void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int* Mod, int* Row, int* Col) { -/* + /* *Mod = Equi / EQUIPMENTSPERMODULE; *Row = Dilo * DILOPADSROWS + Chan / DILOPADSROWS; @@ -88,20 +88,19 @@ void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int *Mod, int *Col = MAXYCOLS - *Col; } */ - if(Equi<0 || Equi >= Geo::MAXEQUIPMENTS || Colu<0 || Colu >= Geo::N_COLUMNS || - Dilo<0 || Dilo >= Geo::N_DILOGICS || Chan<0 || Chan >= Geo::N_CHANNELS ) return; + if (Equi < 0 || Equi >= Geo::MAXEQUIPMENTS || Colu < 0 || Colu >= Geo::N_COLUMNS || + Dilo < 0 || Dilo >= Geo::N_DILOGICS || Chan < 0 || Chan >= Geo::N_CHANNELS) + return; - int a2y[6]={3,2,4,1,5,0}; //pady for a given padress (for single DILOGIC chip) + int a2y[6] = {3, 2, 4, 1, 5, 0}; //pady for a given padress (for single DILOGIC chip) int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module int tmp = (23 - Colu) / Geo::N_COLXSEGMENT; - int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5-2*tmp : 2*tmp; // The PhotoCatode + int pc = (Equi % Geo::EQUIPMENTSPERMODULE) ? 5 - 2 * tmp : 2 * tmp; // The PhotoCatode int px = (Geo::N_DILOGICS - Dilo) * Geo::DILOPADSROWS - Chan / Geo::DILOPADSCOLS - 1; - tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23-Colu); - int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS)+a2y[Chan % Geo::DILOPADSCOLS]; + tmp = (Equi % Geo::EQUIPMENTSPERMODULE) ? Colu : (23 - Colu); + int py = Geo::DILOPADSCOLS * (tmp % Geo::DILOPADSROWS) + a2y[Chan % Geo::DILOPADSCOLS]; *Mod = ch; *Row = px; *Col = py; return; } - - diff --git a/Detectors/HMPID/reconstruction/src/Clusterer.cxx b/Detectors/HMPID/reconstruction/src/Clusterer.cxx index e543d99193290..4f55089365932 100644 --- a/Detectors/HMPID/reconstruction/src/Clusterer.cxx +++ b/Detectors/HMPID/reconstruction/src/Clusterer.cxx @@ -44,4 +44,3 @@ void Clusterer::process(std::vector const& digits, std::vector printf("Clusterer::process: "); timerProcess.Print(); } - diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx index f9b66f5eda0f1..0be71d2457a66 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawFile.cxx @@ -25,8 +25,7 @@ using namespace o2::hmpid; /// Constructor with the default HMPID equipments map at P2 /// @param[in] numOfEquipments : number of defined equipments [0..13] HmpidDecodeRawFile::HmpidDecodeRawFile(int numOfEquipments) - : - HmpidDecoder(numOfEquipments) + : HmpidDecoder(numOfEquipments) { fh = 0; } @@ -36,9 +35,8 @@ HmpidDecodeRawFile::HmpidDecodeRawFile(int numOfEquipments) /// @param[in] *EqIds : the pointer to the Equipments ID array /// @param[in] *CruIds : the pointer to the CRU ID array /// @param[in] *LinkIds : the pointer to the Link ID array -HmpidDecodeRawFile::HmpidDecodeRawFile(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) - : - HmpidDecoder(EqIds, CruIds, LinkIds, numOfEquipments) +HmpidDecodeRawFile::HmpidDecodeRawFile(int* EqIds, int* CruIds, int* LinkIds, int numOfEquipments) + : HmpidDecoder(EqIds, CruIds, LinkIds, numOfEquipments) { fh = 0; } @@ -55,9 +53,9 @@ HmpidDecodeRawFile::~HmpidDecodeRawFile() /// @returns True if the file is opened /// @throws TH_FILENOTEXISTS Thrown if the file doesn't exists /// @throws TH_OPENFILE Thrown if Fails to open the file -bool HmpidDecodeRawFile::setUpStream(void *FileName, long Size) +bool HmpidDecodeRawFile::setUpStream(void* FileName, long Size) { - strcpy(mInputFile, (const char*) FileName); + strcpy(mInputFile, (const char*)FileName); // files section ---- if (!fileExists(mInputFile)) { LOG(ERROR) << "The input file " << mInputFile << " does not exist at this time." << FairLogger::endl; @@ -71,7 +69,7 @@ bool HmpidDecodeRawFile::setUpStream(void *FileName, long Size) } mActualStreamPtr = 0; // sets the pointer to the Buffer - mEndStreamPtr = 0; //sets the End of buffer + mEndStreamPtr = 0; //sets the End of buffer mStartStreamPtr = 0; return (true); @@ -87,7 +85,7 @@ bool HmpidDecodeRawFile::setUpStream(void *FileName, long Size) /// @param[in] Size : not used /// @returns True if the file is opened /// @throws TH_WRONGFILELEN Thrown if the file doesn't contains enough words -bool HmpidDecodeRawFile::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) +bool HmpidDecodeRawFile::getBlockFromStream(uint32_t** streamPtr, uint32_t Size) { if (Size > MAXRAWFILEBUFFER) return (false); @@ -96,8 +94,8 @@ bool HmpidDecodeRawFile::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) throw TH_WRONGFILELEN; } Size = ((mFileBuffer[2] & 0x0000FFFF) / sizeof(int32_t)) - HEADERDIMENSION_W; - nr = fread(mFileBuffer+HEADERDIMENSION_W, sizeof(int32_t), Size, fh); - LOG(DEBUG) << " getBlockFromStream read " << nr << " of " << Size+HEADERDIMENSION_W << " words !" << FairLogger::endl; + nr = fread(mFileBuffer + HEADERDIMENSION_W, sizeof(int32_t), Size, fh); + LOG(DEBUG) << " getBlockFromStream read " << nr << " of " << Size + HEADERDIMENSION_W << " words !" << FairLogger::endl; if (nr != Size) { throw TH_WRONGFILELEN; } @@ -111,17 +109,17 @@ bool HmpidDecodeRawFile::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) /// Reads the Header from the file /// @param[in] **streamPtr : the pointer to the memory buffer /// @returns True if the header is read -bool HmpidDecodeRawFile::getHeaderFromStream(uint32_t **streamPtr) +bool HmpidDecodeRawFile::getHeaderFromStream(uint32_t** streamPtr) { bool flag = getBlockFromStream(streamPtr, RAWBLOCKDIMENSION_W); // reads the 8k block - mActualStreamPtr += HEADERDIMENSION_W; // Move forward for the first word + mActualStreamPtr += HEADERDIMENSION_W; // Move forward for the first word return (flag); } /// Read one word from the pre-load buffer /// @param[in] *word : the buffer for the read word /// @returns True every time -bool HmpidDecodeRawFile::getWordFromStream(uint32_t *word) +bool HmpidDecodeRawFile::getWordFromStream(uint32_t* word) { *word = *mActualStreamPtr; mActualStreamPtr++; @@ -137,7 +135,7 @@ bool HmpidDecodeRawFile::getWordFromStream(uint32_t *word) /// @param[in] dil : the dilogic [0..9] /// @param[in] ch : the channel [0..47] /// @param[in] charge : the value of the charge -void HmpidDecodeRawFile::setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) +void HmpidDecodeRawFile::setPad(HmpidEquipment* eq, int col, int dil, int ch, uint16_t charge) { eq->setPad(col, dil, ch, charge); return; @@ -146,7 +144,7 @@ void HmpidDecodeRawFile::setPad(HmpidEquipment *eq, int col, int dil, int ch, ui /// Checks if the file exists ! /// @param[in] *filewithpath : the File Name to check /// @returns True if the file exists -int HmpidDecodeRawFile::fileExists(char *filewithpath) +int HmpidDecodeRawFile::fileExists(char* filewithpath) { if (access(filewithpath, F_OK) != -1) { return (true); @@ -154,4 +152,3 @@ int HmpidDecodeRawFile::fileExists(char *filewithpath) return (false); } } - diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 5fabdd32190bf..47c0ccaf782ff 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -30,8 +30,7 @@ using namespace o2::hmpid; /// normally it is equal to 14 /// @param[in] numOfEquipments : the number of equipments to define [1..14] HmpidDecodeRawMem::HmpidDecodeRawMem(int numOfEquipments) - : - HmpidDecoder(numOfEquipments) + : HmpidDecoder(numOfEquipments) { } @@ -44,9 +43,8 @@ HmpidDecodeRawMem::HmpidDecodeRawMem(int numOfEquipments) /// @param[in] *EqIds : the pointer to the Equipments ID array /// @param[in] *CruIds : the pointer to the CRU ID array /// @param[in] *LinkIds : the pointer to the Link ID array -HmpidDecodeRawMem::HmpidDecodeRawMem(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) - : - HmpidDecoder(EqIds, CruIds, LinkIds, numOfEquipments) +HmpidDecodeRawMem::HmpidDecodeRawMem(int* EqIds, int* CruIds, int* LinkIds, int numOfEquipments) + : HmpidDecoder(EqIds, CruIds, LinkIds, numOfEquipments) { } @@ -64,7 +62,7 @@ HmpidDecodeRawMem::~HmpidDecodeRawMem() /// @throws TH_NULLBUFFERPOINTER Thrown if the pointer to the buffer is NULL /// @throws TH_BUFFEREMPTY Thrown if the buffer is empty /// @throws TH_WRONGBUFFERDIM Thrown if the buffer len is less then one header -bool HmpidDecodeRawMem::setUpStream(void *Buffer, long BufferLen) +bool HmpidDecodeRawMem::setUpStream(void* Buffer, long BufferLen) { long wordsBufferLen = BufferLen / (sizeof(int32_t) / sizeof(char)); // Converts the len in words if (Buffer == nullptr) { @@ -80,10 +78,10 @@ bool HmpidDecodeRawMem::setUpStream(void *Buffer, long BufferLen) throw TH_WRONGBUFFERDIM; } - mActualStreamPtr = (uint32_t*) Buffer; // sets the pointer to the Buffer - mEndStreamPtr = ((uint32_t*) Buffer) + wordsBufferLen; //sets the End of buffer - mStartStreamPtr = ((uint32_t*) Buffer); -// std::cout << " setUpStrem : StPtr=" << mStartStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << wordsBufferLen << std::endl; + mActualStreamPtr = (uint32_t*)Buffer; // sets the pointer to the Buffer + mEndStreamPtr = ((uint32_t*)Buffer) + wordsBufferLen; //sets the End of buffer + mStartStreamPtr = ((uint32_t*)Buffer); + // std::cout << " setUpStrem : StPtr=" << mStartStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << wordsBufferLen << std::endl; return (true); } @@ -92,15 +90,15 @@ bool HmpidDecodeRawMem::setUpStream(void *Buffer, long BufferLen) /// @param[in] Size : the dimension of the chunk (words) /// @returns True every time /// @throw TH_WRONGBUFFERDIM Buffer length shorter then the requested -bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) +bool HmpidDecodeRawMem::getBlockFromStream(uint32_t** streamPtr, uint32_t Size) { *streamPtr = mActualStreamPtr; mActualStreamPtr += Size; if (mActualStreamPtr > mEndStreamPtr) { -// std::cout << " getBlockFromStream : StPtr=" << mActualStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << Size << std::endl; -// std::cout << "Beccato " << std::endl; -// throw TH_WRONGBUFFERDIM; - return(false); + // std::cout << " getBlockFromStream : StPtr=" << mActualStreamPtr << " EndPtr=" << mEndStreamPtr << " Len=" << Size << std::endl; + // std::cout << "Beccato " << std::endl; + // throw TH_WRONGBUFFERDIM; + return (false); } return (true); } @@ -108,7 +106,7 @@ bool HmpidDecodeRawMem::getBlockFromStream(uint32_t **streamPtr, uint32_t Size) /// Gets the Header Block from the stream. /// @param[in] **streamPtr : the pointer to the memory buffer /// @returns True if the header is read -bool HmpidDecodeRawMem::getHeaderFromStream(uint32_t **streamPtr) +bool HmpidDecodeRawMem::getHeaderFromStream(uint32_t** streamPtr) { return (getBlockFromStream(streamPtr, mRDHSize)); } @@ -116,9 +114,9 @@ bool HmpidDecodeRawMem::getHeaderFromStream(uint32_t **streamPtr) /// Gets a Word from the stream. /// @param[in] *word : the buffer for the read word /// @returns True if the operation end well -bool HmpidDecodeRawMem::getWordFromStream(uint32_t *word) +bool HmpidDecodeRawMem::getWordFromStream(uint32_t* word) { - uint32_t *appo; + uint32_t* appo; *word = *mActualStreamPtr; return (getBlockFromStream(&appo, 1)); } @@ -132,7 +130,7 @@ bool HmpidDecodeRawMem::getWordFromStream(uint32_t *word) /// @param[in] dil : the dilogic [0..9] /// @param[in] ch : the channel [0..47] /// @param[in] charge : the value of the charge -void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) +void HmpidDecodeRawMem::setPad(HmpidEquipment* eq, int col, int dil, int ch, uint16_t charge) { eq->setPad(col, dil, ch, charge); return; @@ -146,8 +144,7 @@ void HmpidDecodeRawMem::setPad(HmpidEquipment *eq, int col, int dil, int ch, uin /// normally it is equal to 14 /// @param[in] numOfEquipments : the number of equipments to define [1..14] HmpidDecodeRawDigit::HmpidDecodeRawDigit(int numOfEquipments) - : - HmpidDecodeRawMem(numOfEquipments) + : HmpidDecodeRawMem(numOfEquipments) { } @@ -160,9 +157,8 @@ HmpidDecodeRawDigit::HmpidDecodeRawDigit(int numOfEquipments) /// @param[in] *EqIds : the pointer to the Equipments ID array /// @param[in] *CruIds : the pointer to the CRU ID array /// @param[in] *LinkIds : the pointer to the Link ID array -HmpidDecodeRawDigit::HmpidDecodeRawDigit(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) - : - HmpidDecodeRawMem(EqIds, CruIds, LinkIds, numOfEquipments) +HmpidDecodeRawDigit::HmpidDecodeRawDigit(int* EqIds, int* CruIds, int* LinkIds, int numOfEquipments) + : HmpidDecodeRawMem(EqIds, CruIds, LinkIds, numOfEquipments) { } @@ -180,11 +176,10 @@ HmpidDecodeRawDigit::~HmpidDecodeRawDigit() /// @param[in] dil : the dilogic [0..9] /// @param[in] ch : the channel [0..47] /// @param[in] charge : the value of the charge -void HmpidDecodeRawDigit::setPad(HmpidEquipment *eq, int col, int dil, int ch, uint16_t charge) +void HmpidDecodeRawDigit::setPad(HmpidEquipment* eq, int col, int dil, int ch, uint16_t charge) { eq->setPad(col, dil, ch, charge); mDigits.push_back(Digit(mHeBCDI, mHeORBIT, charge, eq->getEquipmentId(), col, dil, ch)); //std::cout << "DI " << mDigits.back() << " "< to EoE", - "Row Marker Wrong/Lost -> to EoE", "Row Marker reports an ERROR !", "Lost EoE Marker !", "Double EoE marker", - "Wrong size definition in EoE Marker", "Double Mark Word", "Wrong Size in Segment Marker", "Lost EoS Marker !", - "HMPID Header Errors" }; +char HmpidDecoder::sErrorDescription[MAXERRORS][MAXDESCRIPTIONLENGHT] = {"Word that I don't known !", + "Row Marker Word with 0 words", "Duplicated Pad Word !", "Row Marker Wrong/Lost -> to EoE", + "Row Marker Wrong/Lost -> to EoE", "Row Marker reports an ERROR !", "Lost EoE Marker !", "Double EoE marker", + "Wrong size definition in EoE Marker", "Double Mark Word", "Wrong Size in Segment Marker", "Lost EoS Marker !", + "HMPID Header Errors"}; /// HMPID Firmware Error Messages Definitions -char HmpidDecoder::sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT] = { "L0 Missing," - "L1 is received without L0", "L1A signal arrived before the L1 Latency", "L1A signal arrived after the L1 Latency", - "L1A is missing or L1 timeout", "L1A Message is missing or L1 Message" }; +char HmpidDecoder::sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT] = { + "L0 Missing," + "L1 is received without L0", + "L1A signal arrived before the L1 Latency", "L1A signal arrived after the L1 Latency", + "L1A is missing or L1 timeout", "L1A Message is missing or L1 Message"}; /// Constructor : accepts the number of equipments to define /// The mapping is the default at P2 @@ -48,9 +49,9 @@ char HmpidDecoder::sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT] HmpidDecoder::HmpidDecoder(int numOfEquipments) { // The standard definition of HMPID equipments at P2 - int EqIds[] = { 0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13 }; - int CruIds[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3 }; - int LinkIds[] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2 }; + int EqIds[] = {0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13}; + int CruIds[] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3}; + int LinkIds[] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2}; mNumberOfEquipments = numOfEquipments; for (int i = 0; i < mNumberOfEquipments; i++) { @@ -67,7 +68,7 @@ HmpidDecoder::HmpidDecoder(int numOfEquipments) /// @param[in] *EqIds : the pointer to the Equipments ID array /// @param[in] *CruIds : the pointer to the CRU ID array /// @param[in] *LinkIds : the pointer to the Link ID array -HmpidDecoder::HmpidDecoder(int *EqIds, int *CruIds, int *LinkIds, int numOfEquipments) +HmpidDecoder::HmpidDecoder(int* EqIds, int* CruIds, int* LinkIds, int numOfEquipments) { mNumberOfEquipments = numOfEquipments; for (int i = 0; i < mNumberOfEquipments; i++) { @@ -87,7 +88,7 @@ HmpidDecoder::~HmpidDecoder() void HmpidDecoder::init() { mRDHAcceptedVersion = 6; - mRDHSize = sizeof(o2::header::RAWDataHeaderV6) / sizeof(uint32_t); + mRDHSize = sizeof(o2::header::RAWDataHeaderV6) / sizeof(uint32_t); mVerbose = 0; mHeEvent = 0; @@ -126,7 +127,6 @@ void HmpidDecoder::init() for (int i = 0; i < mNumberOfEquipments; i++) { mTheEquipments[i]->init(); } - } /// Returns the Equipment Index (Pointer of the array) converting @@ -180,10 +180,9 @@ int HmpidDecoder::getEquipmentID(int CruId, int LinkId) /// @param[out] *p3 : third parameter extract (if it exists) /// @param[out] *p4 : fourth parameter extract (if it exists) /// @returns Type of Word : the type of word [0..4] (0 := undetect) -int HmpidDecoder::checkType(uint32_t wp, int *p1, int *p2, int *p3, int *p4) +int HmpidDecoder::checkType(uint32_t wp, int* p1, int* p2, int* p3, int* p4) { - if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 - || (wp & 0x0800ffff) == 0x080010A0) { + if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 || (wp & 0x0800ffff) == 0x080010A0) { *p2 = (wp & 0x03ff0000) >> 16; // Number of words of row *p1 = wp & 0x0000ffff; return (WTYPE_ROW); @@ -226,11 +225,10 @@ int HmpidDecoder::checkType(uint32_t wp, int *p1, int *p2, int *p3, int *p4) /// @param[out] *rowSize : the number of words of the row /// @param[out] *mark : the row marker /// @returns True if Row Marker is detected -bool HmpidDecoder::isRowMarker(uint32_t wp, int *Err, int *rowSize, int *mark) +bool HmpidDecoder::isRowMarker(uint32_t wp, int* Err, int* rowSize, int* mark) { - if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 - || (wp & 0x0800ffff) == 0x080010A0) { - *rowSize = (wp & 0x03ff0000) >> 16; // # Number of words of row + if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 || (wp & 0x0800ffff) == 0x080010A0) { + *rowSize = (wp & 0x03ff0000) >> 16; // # Number of words of row *mark = wp & 0x0000ffff; *Err = false; return (true); @@ -247,11 +245,11 @@ bool HmpidDecoder::isRowMarker(uint32_t wp, int *Err, int *rowSize, int *mark) /// @param[out] *Seg : the Segment number [1..3] /// @param[out] *mark : the Segment Marker /// @returns True if Segment Marker is detected -bool HmpidDecoder::isSegmentMarker(uint32_t wp, int *Err, int *segSize, int *Seg, int *mark) +bool HmpidDecoder::isSegmentMarker(uint32_t wp, int* Err, int* segSize, int* Seg, int* mark) { *Err = false; if ((wp & 0xfff00000) >> 20 == 0xAB0) { - *segSize = (wp & 0x000fff00) >> 8; // # Number of words of Segment + *segSize = (wp & 0x000fff00) >> 8; // # Number of words of Segment *mark = (wp & 0xfff00000) >> 20; *Seg = wp & 0x0000000F; @@ -274,20 +272,18 @@ bool HmpidDecoder::isSegmentMarker(uint32_t wp, int *Err, int *segSize, int *Seg /// @param[out] *Channel : the channel number [0..47] /// @param[out] *Charge : the value of Charge [0..4095] /// @returns True if PAD Word is detected -bool HmpidDecoder::isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Channel, int *Charge) +bool HmpidDecoder::isPadWord(uint32_t wp, int* Err, int* Col, int* Dilogic, int* Channel, int* Charge) { *Err = false; - if ( (wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 \ - || (wp & 0x0800ffff) == 0x080010A0 || (wp & 0x08000000) != 0) { // # ! this is a pad - return(false); + if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 || (wp & 0x0800ffff) == 0x080010A0 || (wp & 0x08000000) != 0) { // # ! this is a pad + return (false); } else { *Col = (wp & 0x07c00000) >> 22; *Dilogic = (wp & 0x003C0000) >> 18; *Channel = (wp & 0x0003F000) >> 12; *Charge = (wp & 0x00000FFF); if (*Dilogic > 10 || *Channel > 47 || *Dilogic < 1 || *Col > 24 || *Col < 1) { - LOG(WARNING) << " Wrong Pad values Col=" << *Col << " Dilogic="<< *Dilogic << \ - " Channel=" << *Channel << " Charge=" << *Charge; + LOG(WARNING) << " Wrong Pad values Col=" << *Col << " Dilogic=" << *Dilogic << " Channel=" << *Channel << " Charge=" << *Charge; *Err = true; } return (true); @@ -301,7 +297,7 @@ bool HmpidDecoder::isPadWord(uint32_t wp, int *Err, int *Col, int *Dilogic, int /// @param[out] *Dilogic : the dilogic number [1..10] /// @param[out] *Eoesize : the number of words for dilogic /// @returns True if EoE marker is detected -bool HmpidDecoder::isEoEmarker(uint32_t wp, int *Err, int *Col, int *Dilogic, int *Eoesize) +bool HmpidDecoder::isEoEmarker(uint32_t wp, int* Err, int* Col, int* Dilogic, int* Eoesize) { *Err = false; // #EX MASK Raul 0x3803FF80 # ex mask 0xF803FF80 - this is EoE marker 0586800B0 @@ -325,7 +321,7 @@ bool HmpidDecoder::isEoEmarker(uint32_t wp, int *Err, int *Col, int *Dilogic, in /// @param[in] ErrorField : the HMPID Error field /// @param[out] *outbuf : the output buffer that contains the error description /// @returns True if EoE marker is detected -bool HmpidDecoder::decodeHmpidError(int ErrorField, char *outbuf) +bool HmpidDecoder::decodeHmpidError(int ErrorField, char* outbuf) { int res = false; outbuf[0] = '\0'; @@ -351,10 +347,10 @@ bool HmpidDecoder::decodeHmpidError(int ErrorField, char *outbuf) /// @param[out] *EquipIndex : the Index to the Equipment Object Array [0..13] /// @returns True every time /// @throws TH_WRONGEQUIPINDEX Thrown if the Equipment Index is out of boundary (Equipment not recognized) -int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) +int HmpidDecoder::decodeHeader(uint32_t* streamPtrAdr, int* EquipIndex) { - uint32_t *buffer = streamPtrAdr; // Sets the pointer to buffer - o2::header::RAWDataHeaderV6 *hpt = (o2::header::RAWDataHeaderV6 *)buffer; + uint32_t* buffer = streamPtrAdr; // Sets the pointer to buffer + o2::header::RAWDataHeaderV6* hpt = (o2::header::RAWDataHeaderV6*)buffer; /* mHeFEEID = (buffer[0] & 0x000f0000) >> 16; @@ -406,35 +402,29 @@ int HmpidDecoder::decodeHeader(uint32_t *streamPtrAdr, int *EquipIndex) mPayloadTail = ((mHeOffsetNewPack - mHeMemorySize) / sizeof(uint32_t)); // ---- Event ID : Actualy based on ORBIT NUMBER and BC - mHeEvent = (mHeORBIT<<12) | mHeBCDI; + mHeEvent = (mHeORBIT << 12) | mHeBCDI; - LOG(DEBUG) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID <<\ - " HeMemorySize=" << mHeMemorySize << " HeOffsetNewPack=" << mHeOffsetNewPack; - LOG(DEBUG) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << \ - mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT; - LOG(DEBUG) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << \ - mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR; - LOG(DEBUG) << " EquIdx = "<<*EquipIndex<< " Event = "<< mHeEvent<< " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; + LOG(DEBUG) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID << " HeMemorySize=" << mHeMemorySize << " HeOffsetNewPack=" << mHeOffsetNewPack; + LOG(DEBUG) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT; + LOG(DEBUG) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR; + LOG(DEBUG) << " EquIdx = " << *EquipIndex << " Event = " << mHeEvent << " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; if (*EquipIndex == -1) { LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; throw TH_WRONGEQUIPINDEX; } - // std::cout << "HMPID ! Exit decode header" << std::endl; + // std::cout << "HMPID ! Exit decode header" << std::endl; return (true); } /// Updates some information related to the Event /// this function is called at the end of the event /// @param[in] *eq : the pointer to the Equipment Object -void HmpidDecoder::updateStatistics(HmpidEquipment *eq) +void HmpidDecoder::updateStatistics(HmpidEquipment* eq) { - eq->mPadsPerEventAverage = ((eq->mPadsPerEventAverage * (eq->mNumberOfEvents - 1)) + eq->mSampleNumber) - / (eq->mNumberOfEvents); - eq->mEventSizeAverage = ((eq->mEventSizeAverage * (eq->mNumberOfEvents - 1)) + eq->mEventSize) - / (eq->mNumberOfEvents); - eq->mBusyTimeAverage = ((eq->mBusyTimeAverage * eq->mBusyTimeSamples) + eq->mBusyTimeValue) - / (++(eq->mBusyTimeSamples)); + eq->mPadsPerEventAverage = ((eq->mPadsPerEventAverage * (eq->mNumberOfEvents - 1)) + eq->mSampleNumber) / (eq->mNumberOfEvents); + eq->mEventSizeAverage = ((eq->mEventSizeAverage * (eq->mNumberOfEvents - 1)) + eq->mEventSize) / (eq->mNumberOfEvents); + eq->mBusyTimeAverage = ((eq->mBusyTimeAverage * eq->mBusyTimeSamples) + eq->mBusyTimeValue) / (++(eq->mBusyTimeSamples)); if (eq->mSampleNumber == 0) eq->mNumberOfEmptyEvents += 1; if (eq->mErrorsCounter > 0) @@ -442,7 +432,7 @@ void HmpidDecoder::updateStatistics(HmpidEquipment *eq) eq->mTotalPads += eq->mSampleNumber; eq->mTotalErrors += eq->mErrorsCounter; - // std::cout << ">>>>.. end >>> "<mNumberOfEvents<<" :" <mEventSize<<","<< eq->mEventSizeAverage<< ", "<mEventNumber<<" "<>>>.. end >>> "<mNumberOfEvents<<" :" <mEventSize<<","<< eq->mEventSizeAverage<< ", "<mEventNumber<<" "<mEventNumber) { // Is a new event + HmpidEquipment* eq = mTheEquipments[EquipmentIndex]; + if (mHeEvent != eq->mEventNumber) { // Is a new event if (eq->mEventNumber != OUTRANGEEVENTNUMBER) { // skip the first - updateStatistics(eq); // update previous statistics + updateStatistics(eq); // update previous statistics } eq->mNumberOfEvents++; eq->mEventNumber = mHeEvent; eq->mBusyTimeValue = mHeBusy * 0.00000005; - eq->mEventSize = 0; // reset the event + eq->mEventSize = 0; // reset the event eq->mSampleNumber = 0; eq->mErrorsCounter = 0; } @@ -472,30 +462,28 @@ HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) dumpHmpidError(mHeHmpidError); eq->setError(ERR_HMPID); } - // std::cout << ".. end evaluateHeaderContents = " << eq->mEventNumber << std::endl; + // std::cout << ".. end evaluateHeaderContents = " << eq->mEventNumber << std::endl; return (eq); } -void HmpidDecoder::decodePage(uint32_t **streamBuf) +void HmpidDecoder::decodePage(uint32_t** streamBuf) { int equipmentIndex; try { getHeaderFromStream(streamBuf); - } - catch (int e) { + } catch (int e) { // The stream end ! LOG(DEBUG) << "End main decoding loop !"; throw TH_BUFFEREMPTY; } try { decodeHeader(*streamBuf, &equipmentIndex); - } - catch (int e) { + } catch (int e) { LOG(ERROR) << "Failed to decode the Header !"; throw TH_WRONGHEADER; } - HmpidEquipment *eq = evaluateHeaderContents(equipmentIndex); + HmpidEquipment* eq = evaluateHeaderContents(equipmentIndex); uint32_t wpprev = 0; uint32_t wp = 0; @@ -506,7 +494,7 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) bool isIt; int payIndex = 0; - while (payIndex < mNumberWordToRead) { //start the payload loop word by word + while (payIndex < mNumberWordToRead) { //start the payload loop word by word if (newOne == true) { wpprev = wp; if (!getWordFromStream(&wp)) { // end the stream @@ -539,14 +527,12 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) switch (p2) { case 0: // Empty column eq->setError(ERR_ROWMARKEMPTY); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKEMPTY] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKEMPTY] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; eq->mWillBeRowMarker = true; break; case 0x3FF: // Error in column eq->setError(ERR_ROWMARKERROR); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKERROR] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKERROR] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; eq->mWillBeRowMarker = true; break; case 0x3FE: // Masked column @@ -562,8 +548,7 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) } else { if (wp == wpprev) { eq->setError(ERR_DUPLICATEPAD); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; newOne = true; } else if (type == WTYPE_EOE) { // # Could be a EoE eq->mColumnCounter++; @@ -574,8 +559,7 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) } else if (type == WTYPE_PAD) { //# Could be a PAD eq->mColumnCounter++; eq->setError(ERR_ROWMARKLOST); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; eq->mWillBeRowMarker = false; eq->mWillBePad = true; newOne = true; @@ -586,8 +570,7 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) } else { eq->mColumnCounter++; eq->setError(ERR_ROWMARKLOST); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; eq->mWillBeRowMarker = false; eq->mWillBePad = true; newOne = true; @@ -600,9 +583,8 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) newOne = true; if (wp == wpprev) { eq->setError(ERR_DUPLICATEPAD); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; - } else if (p1 != (eq->mSegment * 8 + eq->mColumnCounter)) { // # Manage + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; + } else if (p1 != (eq->mSegment * 8 + eq->mColumnCounter)) { // # Manage // We try to recover the RowMarker misunderstanding isIt = isRowMarker(wp, &error, &p2, &p1); if (isIt == true && error == false) { @@ -611,8 +593,8 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) eq->mWillBeEoE = true; eq->mWillBePad = false; } else { - LOG(DEBUG) << "Equip=" << mEquipment << " Mismatch in column" << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << " Mismatch in column" + << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; eq->mColumnCounter = p1 % 8; } } else { @@ -635,24 +617,22 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) isIt = isPadWord(wp, &error, &p1, &p2, &p3, &p4); if (isIt == true && error == false) { type = WTYPE_PAD; - newOne = false; // # reprocess as pad + newOne = false; // # reprocess as pad } else { eq->setError(ERR_LOSTEOEMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; eq->mWillBeRowMarker = true; eq->mWillBePad = false; newOne = false; } - } else if (type == WTYPE_EOS) { // # We Lost the EoE ! + } else if (type == WTYPE_EOS) { // # We Lost the EoE ! eq->setError(ERR_LOSTEOEMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; eq->mWillBeSegmentMarker = true; eq->mWillBePad = false; newOne = false; } - } else if (eq->mWillBeEoE == true) { // # We expect a EoE + } else if (eq->mWillBeEoE == true) { // # We expect a EoE if (type == WTYPE_EOE) { eq->mWordsPerRowCounter++; eq->mWordsPerSegCounter++; @@ -665,7 +645,7 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) } eq->mWordsPerDilogicCounter = 0; if (p2 == 10) { - if (p1 % 8 != 0) { // # we expect the Row Marker + if (p1 % 8 != 0) { // # we expect the Row Marker eq->mWillBeRowMarker = true; } else { eq->mWillBeSegmentMarker = true; @@ -675,17 +655,15 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) } eq->mWillBeEoE = false; newOne = true; - } else if (type == WTYPE_EOS) { // We Lost the EoE ! + } else if (type == WTYPE_EOS) { // We Lost the EoE ! eq->setError(ERR_LOSTEOEMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; eq->mWillBeSegmentMarker = true; eq->mWillBeEoE = false; newOne = false; } else if (type == WTYPE_ROW) { //# We Lost the EoE ! eq->setError(ERR_LOSTEOEMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; eq->mWillBeRowMarker = true; eq->mWillBeEoE = false; newOne = false; @@ -701,8 +679,7 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) newOne = false; // # reprocess as EoE } else { eq->setError(ERR_LOSTEOEMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; eq->mWillBePad = true; eq->mWillBeEoE = false; newOne = false; @@ -711,8 +688,7 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) } else if (eq->mWillBeSegmentMarker == true) { // # We expect a EoSegment if (wpprev == wp) { eq->setError(ERR_DOUBLEMARKWORD); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEMARKWORD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEMARKWORD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; newOne = true; } else if (type == 2) { if (abs(eq->mWordsPerSegCounter - p2) > 5) { @@ -728,8 +704,7 @@ void HmpidDecoder::decodePage(uint32_t **streamBuf) newOne = true; } else { eq->setError(ERR_LOSTEOSMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOSMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << p1 << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOSMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; eq->mWillBeSegmentMarker = false; eq->mWillBeRowMarker = true; newOne = false; @@ -760,16 +735,15 @@ bool HmpidDecoder::decodeBuffer() int type; int equipmentIndex = -1; int isIt; - HmpidEquipment *eq; - uint32_t *streamBuf; + HmpidEquipment* eq; + uint32_t* streamBuf; LOG(DEBUG) << "Enter decoding !"; // Input Stream Main Loop while (true) { try { decodePage(&streamBuf); - } - catch (int e) { + } catch (int e) { LOG(DEBUG) << "End main buffer decoding loop !"; break; } @@ -784,26 +758,24 @@ bool HmpidDecoder::decodeBuffer() return (true); } -void HmpidDecoder::decodePageFast(uint32_t **streamBuf) +void HmpidDecoder::decodePageFast(uint32_t** streamBuf) { int equipmentIndex; try { getHeaderFromStream(streamBuf); - } - catch (int e) { + } catch (int e) { // The stream end ! LOG(INFO) << "End Fast Page decoding loop !"; throw TH_BUFFEREMPTY; } try { decodeHeader(*streamBuf, &equipmentIndex); - } - catch (int e) { + } catch (int e) { LOG(INFO) << "Failed to decode the Header !"; throw TH_WRONGHEADER; } - HmpidEquipment *eq = evaluateHeaderContents(equipmentIndex); + HmpidEquipment* eq = evaluateHeaderContents(equipmentIndex); uint32_t wpprev = 0; uint32_t wp = 0; @@ -812,17 +784,16 @@ void HmpidDecoder::decodePageFast(uint32_t **streamBuf) int pwer; int payIndex = 0; - while (payIndex < mNumberWordToRead) { //start the payload loop word by word + while (payIndex < mNumberWordToRead) { //start the payload loop word by word wpprev = wp; if (!getWordFromStream(&wp)) { // end the stream break; } if (wp == wpprev) { - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << \ - "[" << Column << "]"; + LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << Column << "]"; } else { - if( isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { - if( pwer != true) { + if (isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { + if (pwer != true) { setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); eq->mSampleNumber++; } @@ -848,15 +819,14 @@ bool HmpidDecoder::decodeBufferFast() mTheEquipments[i]->resetPadMap(); } - uint32_t *streamBuf; + uint32_t* streamBuf; LOG(INFO) << "Enter FAST decoding !"; // Input Stream Main Loop while (true) { try { decodePageFast(&streamBuf); - } - catch(int e) { + } catch (int e) { LOG(INFO) << " End Buffer Fast Decoding !"; break; } @@ -871,8 +841,6 @@ bool HmpidDecoder::decodeBufferFast() return (true); } - - // ========================================================= /// Getter method to extract Statistic Data in Digit Coords @@ -987,7 +955,6 @@ float HmpidDecoder::getAverageBusyTime(int EquipmId) // =================================================== // Methods to dump info - /// Prints on the standard output the table of decoding /// errors for one equipment /// @param[in] EquipmId : the HMPID EquipmentId [0..13] @@ -1054,9 +1021,9 @@ void HmpidDecoder::dumpHmpidError(int ErrorField) /// procedure /// @param[in] *summaryFileName : the name of the output file /// @throws TH_CREATEFILE Thrown if was not able to create the file -void HmpidDecoder::writeSummaryFile(char *summaryFileName) +void HmpidDecoder::writeSummaryFile(char* summaryFileName) { - FILE *fs = fopen(summaryFileName, "w"); + FILE* fs = fopen(summaryFileName, "w"); if (fs == 0) { printf("Error opening the file %s !\n", summaryFileName); throw TH_CREATEFILE; diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx index 9e92ac1151043..422b7874db23d 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx @@ -120,8 +120,8 @@ void HmpidEquipment::setError(int ErrType) void HmpidEquipment::setPad(int col, int dil, int cha, uint16_t charge) { mPadSamples[col][dil][cha]++; - mPadSum[col][dil][cha] += (double) charge; - mPadSquares[col][dil][cha] += (double) charge * (double) charge; + mPadSum[col][dil][cha] += (double)charge; + mPadSquares[col][dil][cha] += (double)charge * (double)charge; return; } @@ -136,4 +136,3 @@ int HmpidEquipment::getEquipmentId(int cru, int link) else return (-1); } - diff --git a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx index d24d67753f1e4..facfdb488a5f3 100644 --- a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx +++ b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx @@ -110,7 +110,7 @@ void HMPIDDigitizer::process(std::vector const& hits, std::v } } else { // create digit ... and register -// mDigits.emplace_back(mCurrentTriggerTime, pad, totalQ * fraction); + // mDigits.emplace_back(mCurrentTriggerTime, pad, totalQ * fraction); mDigits.emplace_back(mOrbit, mBc, pad, totalQ * fraction); mIndexForPad[pad] = mDigits.size() - 1; mInvolvedPads.emplace_back(pad); diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index 70e2cd91bcf73..8f6a0caae7c88 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -36,19 +36,19 @@ HmpidCoder::HmpidCoder(int numOfEquipments, bool skipEmptyEvents, bool fixedPack mFileName160 = ""; mFileName161 = ""; - mPailoadBufferDimPerEquipment = ((Geo::N_SEGMENTS * (Geo::N_COLXSEGMENT * (Geo::N_DILOGICS * (Geo::N_CHANNELS + 1) + 1) + 1)) + 10); + mPailoadBufferDimPerEquipment = ((Geo::N_SEGMENTS * (Geo::N_COLXSEGMENT * (Geo::N_DILOGICS * (Geo::N_CHANNELS + 1) + 1) + 1)) + 10); - for(int i=0;i 0) { + for (int j = 0; j < Geo::N_DILOGICS; j++) { + for (int k = 0; k < Geo::N_CHANNELS; k++) { + int idx = getEquipmentPadIndex(eq, ((s - 1) * Geo::N_COLXSEGMENT + (c - 1)), j, k); + if (padMap[idx] > 0) { pads[j]++; rowSize++; padsCount++; @@ -189,14 +189,13 @@ void HmpidCoder::fillTheOutputBuffer(uint32_t* padMap) int col = (s - 1) * Geo::N_COLXSEGMENT + c; for (int d = 1; d <= Geo::N_DILOGICS; d++) { for (int p = 0; p < Geo::N_CHANNELS; p++) { - int idx = getEquipmentPadIndex(eq, ((s-1)*Geo::N_COLXSEGMENT+(c-1)), (d-1), p); - if(padMap[idx] > 0) { - padWord = ((col << 22) & 0x07c00000) | ((d << 18) & 0x003C0000) | ((p << 12) & 0x0003F000) - | (padMap[idx] & 0x00000FFF); + int idx = getEquipmentPadIndex(eq, ((s - 1) * Geo::N_COLXSEGMENT + (c - 1)), (d - 1), p); + if (padMap[idx] > 0) { + padWord = ((col << 22) & 0x07c00000) | ((d << 18) & 0x003C0000) | ((p << 12) & 0x0003F000) | (padMap[idx] & 0x00000FFF); mPayloadBufferPtr[ptr++] = padWord; } } - eoeMarker = 0x08000080 | ((col << 22) & 0x07c00000) | (d << 18 & 0x003C0000) | (pads[d-1] & 0x0000007F); + eoeMarker = 0x08000080 | ((col << 22) & 0x07c00000) | (d << 18 & 0x003C0000) | (pads[d - 1] & 0x0000007F); mPayloadBufferPtr[ptr++] = eoeMarker; } } @@ -205,7 +204,7 @@ void HmpidCoder::fillTheOutputBuffer(uint32_t* padMap) mPayloadBufferPtr[ptr++] = segMarker; } - if(mSkipEmptyEvents && padsCount == 0) { // Sets the lenght of Events + if (mSkipEmptyEvents && padsCount == 0) { // Sets the lenght of Events mEventSizePerEquipment[eq] = 0; } else { mEventSizePerEquipment[eq] = ptr - startPtr; @@ -219,14 +218,15 @@ void HmpidCoder::writePaginatedEvent(uint32_t orbit, uint16_t bc) int nWordToRead; int count; int payloatPtr = 0; - if(orbit == 0 || bc == 0){ - std::cerr << "HmpidCoder [ERROR] : Bad Orbit/BCid number (ORBIT="<< orbit << " BCID=" << bc << ")" << std::endl; + if (orbit == 0 || bc == 0) { + std::cerr << "HmpidCoder [ERROR] : Bad Orbit/BCid number (ORBIT=" << orbit << " BCID=" << bc << ")" << std::endl; return; } for (int eq = 0; eq < mNumberOfEquipments; eq++) { int EventSize = mEventSizePerEquipment[eq]; - if(EventSize == 0) continue; // Skips the Events sized with 0 + if (EventSize == 0) + continue; // Skips the Events sized with 0 int EquipmentCounter = 0; int numOfPages = EventSize / PAYLOADMAXSPACE_W + 1; @@ -241,7 +241,7 @@ void HmpidCoder::writePaginatedEvent(uint32_t orbit, uint16_t bc) int nWordsTail = (mFixedPacketLenght) ? PAYLOADDIMENSION_W : ((count / 8 + 1) * 8); while (count < nWordsTail) - mEventBufferPtr[HEADERDIMENSION_W + count++] = 0; + mEventBufferPtr[HEADERDIMENSION_W + count++] = 0; uint32_t PackNum = mPacketCounterPerEquipment[eq]++; int PacketSize = writeHeader(mEventBufferPtr, nWordToRead, nWordsTail, mEqIds[eq], PackNum, bc, orbit, PageNum); @@ -251,8 +251,8 @@ void HmpidCoder::writePaginatedEvent(uint32_t orbit, uint16_t bc) return; } -int HmpidCoder::writeHeader(uint32_t *Buffer, uint32_t WordsToRead, uint32_t PayloadWords, - int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum) +int HmpidCoder::writeHeader(uint32_t* Buffer, uint32_t WordsToRead, uint32_t PayloadWords, + int Equip, uint32_t PackNum, uint32_t BCDI, uint32_t ORBIT, uint32_t PageNum) { uint32_t CruId, LinkId; uint32_t TType = 0; @@ -295,35 +295,35 @@ void HmpidCoder::codeDigitsChunk(bool flushBuffer) return; } -int HmpidCoder::addDigitsChunk(std::vector &digits) +int HmpidCoder::addDigitsChunk(std::vector& digits) { mDigits.insert(mDigits.end(), digits.begin(), digits.end()); - return(mDigits.size()); + return (mDigits.size()); } -void HmpidCoder::codeDigitsVector(std::vector &digits) +void HmpidCoder::codeDigitsVector(std::vector& digits) { codeEventChunkDigits(digits, true); return; } -void HmpidCoder::codeEventChunkDigits(std::vector &digits, bool flushVector) +void HmpidCoder::codeEventChunkDigits(std::vector& digits, bool flushVector) { - int eq,col,dil,cha,mo,x,y, idx; + int eq, col, dil, cha, mo, x, y, idx; uint32_t orbit = 0; uint16_t bc = 0; - int padsCount =0; + int padsCount = 0; int lastEventDigit = -1; mLastProcessedDigit = -1; - for(o2::hmpid::Digit d : digits) { + for (o2::hmpid::Digit d : digits) { orbit = d.getOrbit(); bc = d.getBC(); lastEventDigit++; - if(orbit != mPreviousOrbit || bc != mPreviousBc) { //the event is changed - if (mPreviousOrbit != 0 || mPreviousBc != 0 ) { // isn't the first ! + if (orbit != mPreviousOrbit || bc != mPreviousBc) { //the event is changed + if (mPreviousOrbit != 0 || mPreviousBc != 0) { // isn't the first ! fillTheOutputBuffer(mPadMap); writePaginatedEvent(mPreviousOrbit, mPreviousBc); mLastProcessedDigit = lastEventDigit; @@ -332,12 +332,12 @@ void HmpidCoder::codeEventChunkDigits(std::vector &digits, bool flushVect mPreviousOrbit = orbit; mPreviousBc = bc; } - Digit::Pad2Equipment(d.getPadID(),&eq, &col, &dil, &cha); // From Digit to Hardware coords - eq = mEqIds[eq]; // converts the Equipment Id in Cru/Link position ref - idx = getEquipmentPadIndex(eq, col, dil, cha); // finally to the unique padmap index + Digit::Pad2Equipment(d.getPadID(), &eq, &col, &dil, &cha); // From Digit to Hardware coords + eq = mEqIds[eq]; // converts the Equipment Id in Cru/Link position ref + idx = getEquipmentPadIndex(eq, col, dil, cha); // finally to the unique padmap index - if(mPadMap[idx] != 0) { // We already have the pad set - std::cerr << "HmpidCoder [ERROR] : Duplicated DIGIT ="<< d <<" ("< &digits, bool flushVect mPreviousBc = 0; mPadsCoded += padsCount; - if(flushVector) { + if (flushVector) { fillTheOutputBuffer(mPadMap); // Finalize the last event writePaginatedEvent(orbit, bc); digits.clear(); } else { - if(mLastProcessedDigit>=0) + if (mLastProcessedDigit >= 0) digits.erase(digits.begin(), digits.begin() + mLastProcessedDigit); } memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event @@ -365,16 +365,16 @@ void HmpidCoder::codeTest(int Events, uint16_t charge) uint16_t bc = 0; //uint32_t *mPadMap = (uint32_t *) std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); - int eq,col,dil,cha,mo,x,y, idx; + int eq, col, dil, cha, mo, x, y, idx; - for(int e=0; emDigits.clear(); decodeTF(pc); -// TODO: accept other types of Raw Streams ... -// decodeReadout(pc); -// decodeRawFile(pc); + // TODO: accept other types of Raw Streams ... + // decodeReadout(pc); + // decodeRawFile(pc); mExTimer.elapseMes("... Decoding... Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); return; @@ -89,43 +89,43 @@ void DataDecoderTask::run(framework::ProcessingContext& pc) void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) { // Records the statistics - float avgEventSize;//[o2::hmpid::Geo::MAXEQUIPMENTS]; - float avgBusyTime;//[o2::hmpid::Geo::MAXEQUIPMENTS]; - float numOfSamples;//[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - float sumOfCharges;//[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; - float squareOfCharges;//[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + float avgEventSize; //[o2::hmpid::Geo::MAXEQUIPMENTS]; + float avgBusyTime; //[o2::hmpid::Geo::MAXEQUIPMENTS]; + float numOfSamples; //[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + float sumOfCharges; //[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; + float squareOfCharges; //[o2::hmpid::Geo::N_MODULES][o2::hmpid::Geo::N_YCOLS][o2::hmpid::Geo::N_XROWS]; float xb; float yb; TString filename = TString::Format("%s_stat.root", mRootStatFile.c_str()); LOG(INFO) << "Create the stat file " << filename.Data(); TFile mfileOut(TString::Format("%s", filename.Data()), "RECREATE"); - TTree *theObj[Geo::N_MODULES+1]; - for(int i=0; iBranch("x", &xb,"s"); - theObj[i]->Branch("y", &yb,"s"); - theObj[i]->Branch("Samples", &numOfSamples,"i"); - theObj[i]->Branch("Sum_of_charges", &sumOfCharges,"l"); - theObj[i]->Branch("Sum_of_square", &squareOfCharges,"l"); + theObj[i]->Branch("x", &xb, "s"); + theObj[i]->Branch("y", &yb, "s"); + theObj[i]->Branch("Samples", &numOfSamples, "i"); + theObj[i]->Branch("Sum_of_charges", &sumOfCharges, "l"); + theObj[i]->Branch("Sum_of_square", &squareOfCharges, "l"); } theObj[Geo::N_MODULES] = new TTree("o2hmp", "HMPID Data Decoding Statistic results"); - theObj[Geo::N_MODULES]->Branch("Average_Event_Size", &avgEventSize,"F"); - theObj[Geo::N_MODULES]->Branch("Average_Busy_Time", &avgBusyTime,"F"); + theObj[Geo::N_MODULES]->Branch("Average_Event_Size", &avgEventSize, "F"); + theObj[Geo::N_MODULES]->Branch("Average_Busy_Time", &avgBusyTime, "F"); char summaryFileName[254]; - sprintf(summaryFileName,"%s_stat.txt", mRootStatFile.c_str()); + sprintf(summaryFileName, "%s_stat.txt", mRootStatFile.c_str()); mDeco->writeSummaryFile(summaryFileName); int numEqui = mDeco->getNumberOfEquipments(); - for(int e=0;egetAverageEventSize(e); avgBusyTime = mDeco->getAverageBusyTime(e); theObj[Geo::N_MODULES]->Fill(); } - for(int m=0; m < o2::hmpid::Geo::N_MODULES; m++) - for(int y=0; y < o2::hmpid::Geo::N_YCOLS; y++) - for(int x=0; x < o2::hmpid::Geo::N_XROWS; x++ ) { + for (int m = 0; m < o2::hmpid::Geo::N_MODULES; m++) + for (int y = 0; y < o2::hmpid::Geo::N_YCOLS; y++) + for (int x = 0; x < o2::hmpid::Geo::N_XROWS; x++) { xb = x; yb = y; numOfSamples = mDeco->getPadSamples(m, x, y); @@ -134,7 +134,7 @@ void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) theObj[m]->Fill(); } - for(int i=0; i<=Geo::N_MODULES; i++) { + for (int i = 0; i <= Geo::N_MODULES; i++) { theObj[i]->Write(); } @@ -155,11 +155,11 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { mDeco->mDigits.clear(); - uint32_t *theBuffer = (uint32_t *)it.raw(); - mDeco->setUpStream(theBuffer, it.size()+it.offset()); + uint32_t* theBuffer = (uint32_t*)it.raw(); + mDeco->setUpStream(theBuffer, it.size() + it.offset()); mDeco->decodePageFast(&theBuffer); mTotalFrames++; - pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits);// + pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); // mTotalDigits += mDeco->mDigits.size(); LOG(DEBUG) << "Writing " << mDeco->mDigits.size() << "/" << mTotalDigits << " Digits ..."; } @@ -175,11 +175,11 @@ void DataDecoderTask::decodeReadout(framework::ProcessingContext& pc) // get the input buffer auto& inputs = pc.inputs(); DPLRawParser parser(inputs, o2::framework::select("readout:HMP/RAWDATA")); -// DPLRawParser parser(inputs, o2::framework::select("HMP/readout")); + // DPLRawParser parser(inputs, o2::framework::select("HMP/readout")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - uint32_t *theBuffer = (uint32_t *)it.raw(); - mDeco->setUpStream(theBuffer, it.size()+it.offset()); + uint32_t* theBuffer = (uint32_t*)it.raw(); + mDeco->setUpStream(theBuffer, it.size() + it.offset()); mDeco->decodePageFast(&theBuffer); } return; @@ -192,21 +192,21 @@ void DataDecoderTask::decodeRawFile(framework::ProcessingContext& pc) for (auto&& input : pc.inputs()) { if (input.spec->binding == "file") { - const header::DataHeader* header = o2::header::get(input.header); - if (!header) { - return; - } + const header::DataHeader* header = o2::header::get(input.header); + if (!header) { + return; + } - auto const* raw = input.payload; - size_t payloadSize = header->payloadSize; + auto const* raw = input.payload; + size_t payloadSize = header->payloadSize; - LOG(INFO) << " payloadSize=" << payloadSize; - if (payloadSize == 0) { - return; - } + LOG(INFO) << " payloadSize=" << payloadSize; + if (payloadSize == 0) { + return; + } - uint32_t *theBuffer = (uint32_t *)input.payload; - int pagesize = header->payloadSize; + uint32_t* theBuffer = (uint32_t*)input.payload; + int pagesize = header->payloadSize; mDeco->setUpStream(theBuffer, pagesize); mDeco->decodePageFast(&theBuffer); } @@ -217,13 +217,13 @@ void DataDecoderTask::decodeRawFile(framework::ProcessingContext& pc) //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) { - + std::vector inputs; inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); inputs.emplace_back("file", o2::framework::ConcreteDataTypeMatcher{"ROUT", "RAWDATA"}, o2::framework::Lifetime::Timeframe); -// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); -// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); -// inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + // inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); @@ -233,7 +233,7 @@ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) o2::framework::select(inputSpec.c_str()), outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"root-file", VariantType::String, "/tmp/hmpRawDecodeResults", {"Name of the Root file with the decoding results."}}} }; + Options{{"root-file", VariantType::String, "/tmp/hmpRawDecodeResults", {"Name of the Root file with the decoding results."}}}}; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index cf24fe0abca58..744cf32bfb92d 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -11,7 +11,7 @@ /// /// \file DatDecoderSpec.cxx -/// \author +/// \author /// /// \brief Implementation of a data processor to run the HMPID raw decoding /// @@ -61,14 +61,16 @@ void DumpDigitsTask::init(framework::InitContext& ic) mIsOutputOnFile = false; mOutputFileName = ic.options().get("out-file"); - if(mOutputFileName != "") { + if (mOutputFileName != "") { mOsFile.open(mOutputFileName, std::ios::out); if (mOsFile.is_open()) { mIsOutputOnFile = true; } } - if (mPrintDigits) std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - if (mIsOutputOnFile) mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + if (mPrintDigits) + std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; + if (mIsOutputOnFile) + mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; mOrbit = -1; mBc = -1; @@ -86,21 +88,22 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) LOG(DEBUG) << "The size of the vector =" << digits.size(); mDigitsReceived += digits.size(); if (mPrintDigits) { - for(o2::hmpid::Digit Dig : digits) { + for (o2::hmpid::Digit Dig : digits) { std::cout << Dig << std::endl; } } if (mIsOutputOnFile) { - for(o2::hmpid::Digit Dig : digits) { + for (o2::hmpid::Digit Dig : digits) { mOsFile << Dig << std::endl; - if(Dig.getOrbit() != mOrbit || Dig.getBC() != mBc) { - mOrbit = Dig.getOrbit(); mBc = Dig.getBC(); + if (Dig.getOrbit() != mOrbit || Dig.getBC() != mBc) { + mOrbit = Dig.getOrbit(); + mBc = Dig.getBC(); LOG(INFO) << "Event :" << mOrbit << " / " << mBc; } } } } - mExTimer.elapseMes( "... Dumping... Digits received = " + std::to_string(mDigitsReceived)); + mExTimer.elapseMes("... Dumping... Digits received = " + std::to_string(mDigitsReceived)); return; } @@ -117,20 +120,19 @@ void DumpDigitsTask::endOfStream(framework::EndOfStreamContext& ec) o2::framework::DataProcessorSpec getDumpDigitsSpec(std::string inputSpec) //o2::framework::DataPrecessorSpec getDecodingSpec() { - + std::vector inputs; inputs.emplace_back("digits", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); std::vector outputs; - return DataProcessorSpec{ "HMP-DigitsDump", inputs, outputs, AlgorithmSpec{adaptFromTask()}, Options{{"out-file", VariantType::String, "", {"name of the output file"}}, - {"print", VariantType::Bool, false, {"print digits (default false )"}}} }; + {"print", VariantType::Bool, false, {"print digits (default false )"}}}}; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx index 5a371618cc68f..40e2f1c4ea52d 100644 --- a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx +++ b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx @@ -11,7 +11,7 @@ /// /// \file DatDecoderSpec.cxx -/// \author +/// \author /// /// \brief Implementation of a data processor to run the HMPID raw decoding /// @@ -86,9 +86,9 @@ void PedestalsCalculationTask::init(framework::InitContext& ic) void PedestalsCalculationTask::run(framework::ProcessingContext& pc) { decodeTF(pc); -// TODO: accept other types of Raw Streams ... -// decodeReadout(pc); -// decodeRawFile(pc);ccdb + // TODO: accept other types of Raw Streams ... + // decodeReadout(pc); + // decodeRawFile(pc);ccdb mExTimer.elapseMes("Decoding... Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); return; @@ -107,84 +107,84 @@ void PedestalsCalculationTask::endOfStream(framework::EndOfStreamContext& ec) uint32_t Threshold; char padsFileName[1024]; - for(int e=0; egetAverageEventSize(e) == 0) continue; - sprintf(padsFileName, "%s_%d.dat", mPedestalsBasePath.c_str(), e ); - FILE *fpads = fopen( padsFileName, "w" ); + for (int e = 0; e < Geo::MAXEQUIPMENTS; e++) { + if (mDeco->getAverageEventSize(e) == 0) + continue; + sprintf(padsFileName, "%s_%d.dat", mPedestalsBasePath.c_str(), e); + FILE* fpads = fopen(padsFileName, "w"); // TODO: Add controls on the file open - for(int c=0; cgetChannelSamples(e, c, d, h); SumOfCharge = mDeco->getChannelSum(e, c, d, h); SumOfSquares = mDeco->getChannelSquare(e, c, d, h); - if(Samples > 0) { + if (Samples > 0) { Average = SumOfCharge / Samples; - Variance = sqrt( abs( (Samples * SumOfSquares) - (SumOfCharge * SumOfCharge) ) ) / Samples; + Variance = sqrt(abs((Samples * SumOfSquares) - (SumOfCharge * SumOfCharge))) / Samples; } else { Average = 0; Variance = 0; } - Pedestal = (uint32_t) Average; - Threshold = (uint32_t) (Variance * mSigmaCut + Average); + Pedestal = (uint32_t)Average; + Threshold = (uint32_t)(Variance * mSigmaCut + Average); Buffer = ((Threshold & 0x001FF) << 9) | (Pedestal & 0x001FF); fprintf(fpads, "%05X\n", Buffer); } - for(int h=48;h<64;h++) { + for (int h = 48; h < 64; h++) { fprintf(fpads, "%05X\n", 0); } } } - mExTimer.logMes("End write the equipment = " + std::to_string(e) ); + mExTimer.logMes("End write the equipment = " + std::to_string(e)); fprintf(fpads, "%05X\n", 0xA0A0A); fclose(fpads); } mExTimer.logMes("End Writing the pedestals ! Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); - if(mWriteToDB) - recordPedInCcdb(); + if (mWriteToDB) + recordPedInCcdb(); mExTimer.stop(); return; } - void PedestalsCalculationTask::recordPedInCcdb() { // create the root structure - LOG(INFO) << "Store Pedestals in ccdb " ; - - float xb,yb, ch; - double Samples,SumOfCharge,SumOfSquares,Average,Variance; + LOG(INFO) << "Store Pedestals in ccdb "; + float xb, yb, ch; + double Samples, SumOfCharge, SumOfSquares, Average, Variance; TObjArray aSigmas(Geo::N_MODULES); TObjArray aPedestals(Geo::N_MODULES); - for(int i=0; igetAverageEventSize(m*2) == 0 && mDeco->getAverageEventSize(m*2+1) == 0) continue; // If no events skip the chamber - TMatrixF *pS=(TMatrixF*)aSigmas.At(m); - TMatrixF *pP=(TMatrixF*)aPedestals.At(m); + for (int m = 0; m < o2::hmpid::Geo::N_MODULES; m++) { + if (mDeco->getAverageEventSize(m * 2) == 0 && mDeco->getAverageEventSize(m * 2 + 1) == 0) + continue; // If no events skip the chamber + TMatrixF* pS = (TMatrixF*)aSigmas.At(m); + TMatrixF* pP = (TMatrixF*)aPedestals.At(m); - for(int x=0; x < o2::hmpid::Geo::N_XROWS; x++ ) - for(int y=0; y < o2::hmpid::Geo::N_YCOLS; y++) { + for (int x = 0; x < o2::hmpid::Geo::N_XROWS; x++) + for (int y = 0; y < o2::hmpid::Geo::N_YCOLS; y++) { Samples = (double)mDeco->getPadSamples(m, x, y); SumOfCharge = mDeco->getPadSum(m, x, y); SumOfSquares = mDeco->getPadSquares(m, x, y); - if(Samples > 0) { - (*pP)(x,y) = SumOfCharge / Samples; - (*pS)(x,y) = sqrt( abs( (Samples * SumOfSquares) - (SumOfCharge * SumOfCharge) ) ) / Samples; + if (Samples > 0) { + (*pP)(x, y) = SumOfCharge / Samples; + (*pS)(x, y) = sqrt(abs((Samples * SumOfSquares) - (SumOfCharge * SumOfCharge))) / Samples; } else { - (*pP)(x,y) = 0; - (*pS)(x,y) = 0; + (*pP)(x, y) = 0; + (*pS)(x, y) = 0; } } } @@ -193,18 +193,20 @@ void PedestalsCalculationTask::recordPedInCcdb() uint64_t ms = tp.tv_sec * 1000 + tp.tv_usec / 1000; uint64_t minTimeStamp = ms; - uint64_t maxTimeStamp = ms+1; + uint64_t maxTimeStamp = ms + 1; - for(int i=0; igetAverageEventSize(i*2) == 0 && mDeco->getAverageEventSize(i*2+1) == 0) continue; // If no events skip the chamber - TString filename = TString::Format("HMP/Pedestals/%s/Mean_%d", mPedestalTag.c_str(),i); - mDbMetadata.emplace("Tag", mPedestalTag.c_str() ); + for (int i = 0; i < Geo::N_MODULES; i++) { + if (mDeco->getAverageEventSize(i * 2) == 0 && mDeco->getAverageEventSize(i * 2 + 1) == 0) + continue; // If no events skip the chamber + TString filename = TString::Format("HMP/Pedestals/%s/Mean_%d", mPedestalTag.c_str(), i); + mDbMetadata.emplace("Tag", mPedestalTag.c_str()); mDBapi.storeAsTFileAny(aPedestals.At(i), filename.Data(), mDbMetadata, minTimeStamp, maxTimeStamp); } - for(int i=0; igetAverageEventSize(i*2) == 0 && mDeco->getAverageEventSize(i*2+1) == 0) continue; // If no events skip the chamber - TString filename = TString::Format("HMP/Pedestals/%s/Sigma_%d", mPedestalTag.c_str(),i); - mDbMetadata.emplace("Tag", mPedestalTag.c_str() ); + for (int i = 0; i < Geo::N_MODULES; i++) { + if (mDeco->getAverageEventSize(i * 2) == 0 && mDeco->getAverageEventSize(i * 2 + 1) == 0) + continue; // If no events skip the chamber + TString filename = TString::Format("HMP/Pedestals/%s/Sigma_%d", mPedestalTag.c_str(), i); + mDbMetadata.emplace("Tag", mPedestalTag.c_str()); mDBapi.storeAsTFileAny(aSigmas.At(i), filename.Data(), mDbMetadata, minTimeStamp, maxTimeStamp); } return; @@ -220,8 +222,8 @@ void PedestalsCalculationTask::decodeTF(framework::ProcessingContext& pc) auto& inputs = pc.inputs(); DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - uint32_t *theBuffer = (uint32_t *)it.raw(); - mDeco->setUpStream(theBuffer, it.size()+it.offset()); + uint32_t* theBuffer = (uint32_t*)it.raw(); + mDeco->setUpStream(theBuffer, it.size() + it.offset()); mDeco->decodePageFast(&theBuffer); mTotalFrames++; } @@ -237,11 +239,11 @@ void PedestalsCalculationTask::decodeReadout(framework::ProcessingContext& pc) // get the input buffer auto& inputs = pc.inputs(); DPLRawParser parser(inputs, o2::framework::select("readout:HMP/RAWDATA")); -// DPLRawParser parser(inputs, o2::framework::select("HMP/readout")); + // DPLRawParser parser(inputs, o2::framework::select("HMP/readout")); for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - uint32_t *theBuffer = (uint32_t *)it.raw(); - mDeco->setUpStream(theBuffer, it.size()+it.offset()); + uint32_t* theBuffer = (uint32_t*)it.raw(); + mDeco->setUpStream(theBuffer, it.size() + it.offset()); mDeco->decodePageFast(&theBuffer); } return; @@ -254,21 +256,21 @@ void PedestalsCalculationTask::decodeRawFile(framework::ProcessingContext& pc) for (auto&& input : pc.inputs()) { if (input.spec->binding == "file") { - const header::DataHeader* header = o2::header::get(input.header); - if (!header) { - return; - } + const header::DataHeader* header = o2::header::get(input.header); + if (!header) { + return; + } - auto const* raw = input.payload; - size_t payloadSize = header->payloadSize; + auto const* raw = input.payload; + size_t payloadSize = header->payloadSize; - LOG(INFO) << " payloadSize=" << payloadSize; - if (payloadSize == 0) { - return; - } + LOG(INFO) << " payloadSize=" << payloadSize; + if (payloadSize == 0) { + return; + } - uint32_t *theBuffer = (uint32_t *)input.payload; - int pagesize = header->payloadSize; + uint32_t* theBuffer = (uint32_t*)input.payload; + int pagesize = header->payloadSize; mDeco->setUpStream(theBuffer, pagesize); mDeco->decodePageFast(&theBuffer); } @@ -279,16 +281,16 @@ void PedestalsCalculationTask::decodeRawFile(framework::ProcessingContext& pc) //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getPedestalsCalculationSpec(std::string inputSpec) { - + std::vector inputs; inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); inputs.emplace_back("file", o2::framework::ConcreteDataTypeMatcher{"ROUT", "RAWDATA"}, o2::framework::Lifetime::Timeframe); -// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); -// inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); -// inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + // inputs.emplace_back("readout", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); + // inputs.emplace_back("rawfile", o2::header::gDataOriginHMP, "RAWDATA", 0, Lifetime::Timeframe); std::vector outputs; -// outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); + // outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe); return DataProcessorSpec{ "HMP-DataDecoder", @@ -298,8 +300,8 @@ o2::framework::DataProcessorSpec getPedestalsCalculationSpec(std::string inputSp Options{{"files-basepath", VariantType::String, "/tmp/hmpPedThr", {"Name of the Base Path of Pedestals/Thresholds files."}}, {"use-ccdb", VariantType::Bool, false, {"Register the Pedestals/Threshold values into the CCDB"}}, {"ccdb-uri", VariantType::String, "http://ccdb-test.cern.ch:8080", {"URI for the CCDB access."}}, - {"pedestals-tag", VariantType::String, "Latest", {"The tag applied to this set of pedestals/threshold values"}}, - {"sigmacut", VariantType::Float, 4.0f, {"Sigma values for the Thresholds calculation."}} }}; + {"pedestals-tag", VariantType::String, "Latest", {"The tag applied to this set of pedestals/threshold values"}}, + {"sigmacut", VariantType::Float, 4.0f, {"Sigma values for the Thresholds calculation."}}}}; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx index 24bb0f751b6f3..88e54260ba274 100644 --- a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx +++ b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx @@ -8,7 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. - #include #include #include @@ -39,7 +38,6 @@ using namespace o2; using namespace o2::framework; using RDH = o2::header::RDHAny; - void RawFileReaderTask::init(framework::InitContext& ic) { LOG(INFO) << "Raw file reader init "; @@ -62,7 +60,6 @@ void RawFileReaderTask::init(framework::InitContext& ic) return; } - void RawFileReaderTask::run(framework::ProcessingContext& pc) { @@ -70,7 +67,7 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) char* outBuffer{nullptr}; size_t bufSize{0}; int numberOfFrames = 0; - LOG(INFO)<< "Sleep 1 sec for sync"; + LOG(INFO) << "Sleep 1 sec for sync"; sleep(1); while (true) { @@ -115,8 +112,8 @@ void RawFileReaderTask::run(framework::ProcessingContext& pc) break; // probably reached eof } bufSize = frameSize; // Set the buffer pointer - pc.outputs().snapshot(Output{"HMP","RAWDATA"}, outBuffer, bufSize); -//std::cout << mExTimer.mTimer.CpuTime() << " " << mExTimer.mLastLogTime << std::endl; + pc.outputs().snapshot(Output{"HMP", "RAWDATA"}, outBuffer, bufSize); + //std::cout << mExTimer.mTimer.CpuTime() << " " << mExTimer.mLastLogTime << std::endl; mExTimer.elapseMes("... Reading... Number of Pages = " + std::to_string(numberOfFrames)); } // while (true) @@ -142,4 +139,3 @@ o2::framework::DataProcessorSpec getReadRawFileSpec(std::string inputSpec) } // end namespace hmpid } // end namespace o2 - diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index 05d6a6680ee6f..717e3731bf390 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -9,7 +9,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. - #include #include #include @@ -85,7 +84,7 @@ void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) { for (auto const& ref : InputRecordWalker(pc.inputs())) { std::vector digits = pc.inputs().get>(ref); - if(mOrderTheEvents) { + if (mOrderTheEvents) { mDigits.insert(mDigits.end(), digits.begin(), digits.end()); } else { mCod->addDigitsChunk(digits); @@ -102,8 +101,8 @@ void WriteRawFromDigitsTask::run(framework::ProcessingContext& pc) void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) { mExTimer.logMes("Received an End Of Stream !"); - if(mOrderTheEvents) { -// sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); + if (mOrderTheEvents) { + // sort(mDigits.begin(), mDigits.end(), eventEquipPadsComparision); sort(mDigits.begin(), mDigits.end(), o2::hmpid::Digit::eventEquipPadsComp); mExTimer.logMes("We sort " + std::to_string(mDigits.size()) + " ! "); mCod->codeDigitsVector(mDigits); @@ -113,7 +112,7 @@ void WriteRawFromDigitsTask::endOfStream(framework::EndOfStreamContext& ec) mCod->closeOutputStream(); mCod->dumpResults(); - mExTimer.logMes( "Raw File created ! Digits received = " + std::to_string(mDigitsReceived) + " Frame received =" + std::to_string(mFramesReceived)); + mExTimer.logMes("Raw File created ! Digits received = " + std::to_string(mDigitsReceived) + " Frame received =" + std::to_string(mFramesReceived)); mExTimer.stop(); return; } @@ -125,7 +124,7 @@ o2::framework::DataProcessorSpec getWriteRawFromDigitsSpec(std::string inputSpec inputs.emplace_back("digits", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe); std::vector outputs; - + return DataProcessorSpec{ "HMP-WriteRawFromDigits", inputs, diff --git a/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx index 1b0936c00414a..c847a7b805f03 100644 --- a/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx @@ -47,9 +47,9 @@ WorkflowSpec defineDataProcessing(const ConfigContext&) WorkflowSpec specs; DataProcessorSpec consumer = o2::hmpid::getDumpDigitsSpec(); -// DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); + // DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); specs.push_back(consumer); -// specs.push_back(consumer); + // specs.push_back(consumer); return specs; } diff --git a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx index a674bd849cc62..25514761e14d9 100644 --- a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx @@ -8,7 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. - #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" #include "Framework/CallbackService.h" diff --git a/Detectors/HMPID/workflow/src/raw-to-pedestals-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-pedestals-workflow.cxx index 35fb51994bc9a..045d9253c9ebf 100644 --- a/Detectors/HMPID/workflow/src/raw-to-pedestals-workflow.cxx +++ b/Detectors/HMPID/workflow/src/raw-to-pedestals-workflow.cxx @@ -8,7 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. - #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" #include "Framework/CallbackService.h" diff --git a/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx b/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx index eba897b0aa2e7..e2f9c85155f37 100644 --- a/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx +++ b/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx @@ -16,7 +16,6 @@ #include "Framework/DispatchPolicy.h" #include "Framework/Task.h" - // customize dispatch policy, dispatch immediately what is ready void customize(std::vector& policies) { @@ -24,25 +23,24 @@ void customize(std::vector& policies) // we customize all devices to dispatch data immediately auto readerMatcher = [](auto const& spec) { // - // std::cout << "customize reader = " << spec.name << std::endl; -// std::cout << "PingReader" << std::endl; + // std::cout << "customize reader = " << spec.name << std::endl; + // std::cout << "PingReader" << std::endl; return true; -// return std::regex_match(spec.name.begin(), spec.name.end(), std::regex(".*-reader")); + // return std::regex_match(spec.name.begin(), spec.name.end(), std::regex(".*-reader")); }; auto triggerMatcher = [](auto const& query) { // a bit of a hack but we want this to be configurable from the command line, // however DispatchPolicy is inserted before all other setup. Triggering depending // on the global variable set from the command line option. If scheduled messages // are not triggered they are sent out at the end of the computation - // std::cout << "customize Trigger origin = " << query.origin << " description = " << query.description << std::endl; - // std::cout << "PingTrig" << std::endl; + // std::cout << "customize Trigger origin = " << query.origin << " description = " << query.description << std::endl; + // std::cout << "PingTrig" << std::endl; return true; -// return gDispatchTrigger.origin == query.origin && gDispatchTrigger.description == query.description; + // return gDispatchTrigger.origin == query.origin && gDispatchTrigger.description == query.description; }; policies.push_back({"pr-f-re", readerMatcher, DispatchOp::WhenReady, triggerMatcher}); } - #include "Framework/runDataProcessing.h" #include "HMPIDWorkflow/ReadRawFileSpec.h" diff --git a/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx index dda6d2a9ab76e..f9aaeea6b8fcd 100644 --- a/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx @@ -8,7 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. - #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" #include "Framework/CallbackService.h" @@ -38,9 +37,9 @@ WorkflowSpec defineDataProcessing(const ConfigContext&) WorkflowSpec specs; DataProcessorSpec consumer = o2::hmpid::getWriteRawFromDigitsSpec(); -// DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); + // DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); specs.push_back(consumer); -// specs.push_back(consumer); + // specs.push_back(consumer); return specs; } diff --git a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx index 12b4a8295a3bd..048574924ed50 100644 --- a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx @@ -8,7 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. - #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" #include "Framework/CallbackService.h" From afe486701236368f4f1340f035ac962b0a075ff4 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 15 Feb 2021 13:25:17 +0100 Subject: [PATCH 191/208] Add Remarks in Base Classes --- .../HMPID/base/include/HMPIDBase/Common.h | 38 ++- .../HMPID/base/include/HMPIDBase/Digit.h | 44 +++- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 6 + Detectors/HMPID/base/src/Digit.cxx | 230 +++++++++++++++--- Detectors/HMPID/base/src/Geo.cxx | 52 ++-- 5 files changed, 283 insertions(+), 87 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Common.h b/Detectors/HMPID/base/include/HMPIDBase/Common.h index 079fb272d482d..6df783514d4ac 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Common.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Common.h @@ -1,9 +1,18 @@ -/* - * Common.h - * - * Created on: 5 feb 2021 - * Author: fap - */ +// 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 Common.h +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 15/02/2021 #ifndef DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_COMMON_H_ #define DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_COMMON_H_ @@ -16,7 +25,10 @@ namespace o2 namespace hmpid { -// ------- Execution time functions +// ------- Execution time functions ------- + +/// \class ExecutionTimer +/// \brief HMPID Derived class for the Time of Workflows class ExecutionTimer { private: @@ -35,13 +47,19 @@ class ExecutionTimer ~ExecutionTimer(){}; + /// getElapseLogTime : returns the seconds for the elapsed log message + /// @return : the number of seconds for the elapsed logging Double_t getElapseLogTime() { return mElapseLogTime; }; + + /// setElapseLogTime : set the interval for the elapsed logging + /// @param[in] interval : the seconds of interval for elapsed logging void setElapseLogTime(Double_t interval) { mElapseLogTime = interval; return; }; + /// start : starts the timer void start() { mStartTime = mTimer.CpuTime(); @@ -50,12 +68,15 @@ class ExecutionTimer return; }; + /// stop : stops the timer void stop() { mTimer.Stop(); return; }; + /// logMes : Out a message on the LOG(INFO) with extra execution time info + /// @param[in] message : the message to print void logMes(std::string const message) { LOG(INFO) << message << " Execution time = " << (mTimer.CpuTime() - mStartTime); @@ -63,6 +84,9 @@ class ExecutionTimer return; }; + /// elapseMes : Out a message on the LOG(INFO) with extra execution time info + /// is the set interval was reached + /// @param[in] message : the message to print void elapseMes(std::string const message) { if (mTimer.CpuTime() - mLastLogTime > mElapseLogTime) { diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index f1f9bc23d08e5..28c44962ff89d 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -8,11 +8,16 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// +/// \file Digit.h +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 15/02/2021 + #ifndef DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_DIGIT_H_ #define DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_DIGIT_H_ #include - #include "CommonDataFormat/TimeStamp.h" #include "HMPIDBase/Hit.h" // for hit #include "HMPIDBase/Param.h" // for param @@ -24,12 +29,11 @@ namespace hmpid { /// \class Digit -/// \brief HMPID digit implementation -//using DigitBase = o2::dataformats::TimeStamp; +/// \brief HMPID Digit declaration class Digit { public: - // Conversion functions + // Coordinates Conversion Functions static inline uint32_t Abs(int ch, int pc, int x, int y) { return ch << 20 | pc << 16 | x << 8 | y; } static inline int DDL2C(int ddl) { return ddl >> 1; } //ddl -> chamber static inline int A2C(uint32_t pad) { return (pad & 0x00F00000) >> 20; } //abs pad -> chamber @@ -45,6 +49,10 @@ class Digit static void Absolute2Equipment(int Module, int x, int y, int* Equi, int* Colu, int* Dilo, int* Chan); static void Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int* Module, int* x, int* y); + // Trigger time Conversion Functions + static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) || BC); }; + static inline uint32_t EventIdToOrbit(uint64_t EventId) { return (EventId >> 12); }; + static inline uint16_t EventIdToBc(uint64_t EventId) { return (EventId & 0x0FFF); }; static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC); static uint32_t TimeNsToOrbit(double TimeNs); static uint16_t TimeNsToBc(double TimeNs); @@ -58,13 +66,14 @@ class Digit friend inline bool operator>=(const Digit& l, const Digit& r) { return !(l < r); }; friend inline bool operator!=(const Digit& l, const Digit& r) { return !(l == r); }; + // Digit ASCCI format Dump := [Chamber,PhotoCathod,X,Y]@(Orbit,BunchCrossing)=Charge friend std::ostream& operator<<(std::ostream& os, const Digit& d) { os << "[" << A2C(d.mPad) << "," << A2P(d.mPad) << "," << A2X(d.mPad) << "," << A2Y(d.mPad) << "]@(" << d.mOrbit << "," << d.mBc << ")=" << d.mQ; return os; }; - // Functions to manage Digit vectors + // Functions to manage Digit Vectors static bool eventEquipPadsComp(Digit& d1, Digit& d2); static std::vector* extractDigitsPerEvent(std::vector& Digits, uint64_t EventID); static std::vector* extractEvents(std::vector& Digits); @@ -76,11 +85,14 @@ class Digit Digit(uint16_t bc, uint32_t orbit, uint16_t, int equipment, int column, int dilogic, int channel); Digit(uint16_t bc, uint32_t orbit, uint16_t, int module, int x, int y); + // Getter & Setters uint16_t getCharge() const { return mQ; } + void setCharge(uint16_t Q) { mQ = Q; return; }; int getPadID() const { return mPad; } + void setPadID(uint32_t pad) { mPad = pad; return; }; uint32_t getOrbit() const { return mOrbit; } uint16_t getBC() const { return mBc; } - uint64_t getTriggerID() const { return ((mOrbit << 12) | mBc); } + uint64_t getTriggerID() const { return OrbitBcToEventId(mOrbit, mBc); } void setOrbit(uint32_t orbit) { mOrbit = orbit; @@ -97,25 +109,35 @@ class Digit mBc = (trigger & 0x0FFF); return; } + bool isValid() { return (mPad == 0xFFFFFFFF ? true : false); }; + void setInvalid() { mPad = 0xFFFFFFFF; return; }; - // convenience conversion to x-y pad coordinates + // convenience wrapper function for conversion to x-y pad coordinates int getPx() const { return A2X(mPad); } int getPy() const { return A2Y(mPad); } int getPhC() const { return A2P(mPad); } int getCh() const { return A2C(mPad); } + // Charge management functions static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); static float getFractionalContributionForPad(HitType const& hit, int somepad); - - // add charge to existing digit void addCharge(float q) { mQ += q; } + void subCharge(float q) { mQ -= q; } private: + // Members uint16_t mQ = 0; - uint32_t mPad = 0; // -1 indicates invalid digit uint16_t mBc = 0.; uint32_t mOrbit = 0; - + // The Pad Unique Id, code a pad inside one HMPID chamber. + // Bit Map : 0000.0000.cccc.pppp.xxxx.xxxx.yyyy.yyyy + // cccc := chamber [0..6] + // pppp := photo cathode [0..5] + // xxxx.xxxx := horizontal displacement [0..79] + // yyyy.yyyy := vertical displacement [0..47] + uint32_t mPad = 0; // 0xFFFFFFFF indicates invalid digit + + // Get the Geometric center of the pad static float LorsX(int pad) { return Param::LorsX(A2P(pad), A2X(pad)); } //center of the pad x, [cm] static float LorsY(int pad) { return Param::LorsY(A2P(pad), A2Y(pad)); } //center of the pad y, [cm] diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 60b70a7119f37..2f261da150491 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -8,6 +8,12 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// +/// \file Geo.h +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 15/02/2021 + #ifndef ALICEO2_HMPID_GEO_H #define ALICEO2_HMPID_GEO_H diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 71567580a6963..53300e506a44b 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -8,6 +8,16 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// +/// \file Digit.cxx +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to manage HMPID Digit data +/// \version 1.0 +/// \date 15/02/2021 + +/* ------ HISTORY --------- +*/ + #include "HMPIDBase/Digit.h" #include "HMPIDBase/Geo.h" #include "HMPIDBase/Param.h" @@ -19,7 +29,18 @@ using namespace o2::hmpid; ClassImp(o2::hmpid::Digit); -// ----- Constructors ------------ +// ============= Digit Class implementation ======= + +/// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC) +/// The mapping of the digit is in the Photo Cathod coords +/// (Chamber, PhotoCathod, X, Y) +/// @param[in] bc : the bunch crossing [0 .. 2^12-1] +/// @param[in] orbit : the orbit number [0 .. 2^32-1] +/// @param[in] chamber : the HMPID module [0 .. 6] +/// @param[in] photo : the photo cathode number [0 .. 5] (left-down to right-up) +/// @param[in] x : the horizontal in cathode displacement [0 .. 79] +/// @param[in] y : the vertical in cathode displacement [0 .. 47] +/// @param[in] charge : the value of the charge [0 .. 2^12-1] Digit::Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge) { mBc = bc; @@ -28,6 +49,16 @@ Digit::Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, mPad = Abs(chamber, photo, x, y); } +/// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC) +/// The mapping of the digit is in the Hardware coords +/// (Equipment, Column, Dilogic, Channel) +/// @param[in] bc : the bunch crossing [0 .. 2^12-1] +/// @param[in] orbit : the orbit number [0 .. 2^32-1] +/// @param[in] charge : the value of the charge [0 .. 2^12-1] +/// @param[in] equipment : the HMPID DDL link [0 .. 13] +/// @param[in] column : the readout column number [0 .. 23] +/// @param[in] dilogic : the displacement in the Dilogics chain [0 .. 9] +/// @param[in] channel : the number of gassiplexes channels [0 .. 47] Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int column, int dilogic, int channel) { mBc = bc; @@ -36,6 +67,15 @@ Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int co mPad = Equipment2Pad(equipment, column, dilogic, channel); } +/// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC) +/// The mapping of the digit is in the Logical coords +/// (Module, X, Y) +/// @param[in] bc : the bunch crossing [0 .. 2^12-1] +/// @param[in] orbit : the orbit number [0 .. 2^32-1] +/// @param[in] charge : the value of the charge [0 .. 2^12-1] +/// @param[in] module : the HMPID Module [0 .. 6] +/// @param[in] x : the horizontal in Module displacement [0 .. 159] +/// @param[in] y : the vertical in Module displacement [0 .. 143] Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, int y) { mBc = bc; @@ -44,7 +84,14 @@ Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, in mPad = Absolute2Pad(module, x, y); } -// ----- Coordinate Conversion ---- +// ----- Coordinate Conversion ----- + +/// Equipment2Pad : Converts the coords from Hardware to Digit Unique Id +/// @param[in] Equi : the equipment [0 .. 13] +/// @param[in] Colu : the readout column number [0 .. 23] +/// @param[in] Dilo : the displacement in the Dilogics chain [0 .. 9] +/// @param[in] Chan : the number of gassiplexes channels [0 .. 47] +/// @return uint32_t : the Digit Unique Id [0x00CPXXYY] uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) { // Check the input data @@ -68,6 +115,12 @@ uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) return Abs(ch, pc, px, py); // Pack the coords into the PadID word } +/// Pad2Equipment : Converts the Digit Unique Id to Hardware coords +/// @param[in] pad : the Digit Unique Id [0x00CPXXYY] +/// @param[out] Equi : the equipment [0 .. 13] +/// @param[out] Colu : the readout column number [0 .. 23] +/// @param[out] Dilo : the displacement in the Dilogics chain [0 .. 9] +/// @param[out] Chan : the number of gassiplexes channels [0 .. 47] void Digit::Pad2Equipment(uint32_t pad, int* Equi, int* Colu, int* Dilo, int* Chan) { int ch, ph, px, py; @@ -90,6 +143,14 @@ void Digit::Pad2Equipment(uint32_t pad, int* Equi, int* Colu, int* Dilo, int* Ch return; } +/// Absolute2Equipment : Converts the Module coords to Hardware coords +/// @param[in] Module : the HMPID Module number [0..6] +/// @param[in] x : the horizontal displacement [0..159] +/// @param[in] y : the vertical displacement [0..143] +/// @param[out] Equi : the equipment [0 .. 13] +/// @param[out] Colu : the readout column number [0 .. 23] +/// @param[out] Dilo : the displacement in the Dilogics chain [0 .. 9] +/// @param[out] Chan : the number of gassiplexes channels [0 .. 47] void Digit::Absolute2Equipment(int Module, int x, int y, int* Equi, int* Colu, int* Dilo, int* Chan) { uint32_t pad = Absolute2Pad(Module, x, y); @@ -97,6 +158,14 @@ void Digit::Absolute2Equipment(int Module, int x, int y, int* Equi, int* Colu, i return; } +/// Equipment2Absolute : Converts the Module coords to Hardware coords +/// @param[in] Equi : the equipment [0 .. 13] +/// @param[in] Colu : the readout column number [0 .. 23] +/// @param[in] Dilo : the displacement in the Dilogics chain [0 .. 9] +/// @param[in] Chan : the number of gassiplexes channels [0 .. 47] +/// @param[out] Module : the HMPID Module number [0..6] +/// @param[out] x : the horizontal displacement [0..159] +/// @param[out] y : the vertical displacement [0..143] void Digit::Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int* Module, int* x, int* y) { uint32_t pad = Equipment2Pad(Equi, Colu, Dilo, Chan); @@ -104,6 +173,11 @@ void Digit::Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int* Modu return; } +/// Absolute2Pad : Converts the Module coords in the Digit Unique Id +/// @param[in] Module : the HMPID Module number [0..6] +/// @param[in] x : the horizontal displacement [0..159] +/// @param[in] y : the vertical displacement [0..143] +/// @return uint32_t : the Digit Unique Id [0x00CPXXYY] uint32_t Digit::Absolute2Pad(int Module, int x, int y) { int ph = (y / Geo::N_PHOTOCATODSY) * 2 + ((x >= Geo::HALFXROWS) ? 1 : 0); @@ -112,6 +186,11 @@ uint32_t Digit::Absolute2Pad(int Module, int x, int y) return Abs(Module, ph, px, py); } +/// Pad2Absolute : Converts the the Digit Unique Id to Module coords +/// @param[in] pad : the Digit Unique Id [0x00CPXXYY] +/// @param[out] Module : the HMPID Module number [0..6] +/// @param[out] x : the horizontal displacement [0..159] +/// @param[out] y : the vertical displacement [0..143] void Digit::Pad2Absolute(uint32_t pad, int* Module, int* x, int* y) { *Module = A2C(pad); @@ -123,6 +202,12 @@ void Digit::Pad2Absolute(uint32_t pad, int* Module, int* x, int* y) return; } +/// Pad2Photo : Converts the the Digit Unique Id to Photo Cathode coords +/// @param[in] pad : the Digit Unique Id [0x00CPXXYY] +/// @param[out] chamber : the HMPID chamber number [0..6] +/// @param[out] photo : the photo cathode number [0..5] +/// @param[out] x : the horizontal displacement [0..79] +/// @param[out] y : the vertical displacement [0..47] void Digit::Pad2Photo(uint32_t pad, int* chamber, int* photo, int* x, int* y) { *chamber = A2C(pad); @@ -132,7 +217,14 @@ void Digit::Pad2Photo(uint32_t pad, int* chamber, int* photo, int* x, int* y) return; } -// ----- Getter Methods --------- +/// getPadAndTotalCharge : Extract all the info from the Hit structure +/// and returns they in the Photo Cathode coords +/// @param[in] hit : the HMPID Hit +/// @param[out] chamber : the HMPID chamber number [0..6] +/// @param[out] pc : the photo cathode number [0..5] +/// @param[out] px : the horizontal displacement [0..79] +/// @param[out] py : the vertical displacement [0..47] +/// @param[out] totalcharge : the charge of the hit [0..2^12-1] void Digit::getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge) { float localX; @@ -146,13 +238,17 @@ void Digit::getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& return; } +/// getFractionalContributionForPad : ... +/// +/// @param[in] hit : the HMPID Hit +/// @param[in] somepad : the Digit Unique Id [0x00CPXXYY] +/// @return : the fraction of the charge ... float Digit::getFractionalContributionForPad(HitType const& hit, int somepad) { float localX; float localY; - // chamber number is in detID - const auto chamber = hit.GetDetectorID(); + const auto chamber = hit.GetDetectorID(); // chamber number is in detID double tmp[3] = {hit.GetX(), hit.GetY(), hit.GetZ()}; // converting chamber id and hit coordiates to local coordinates Param::Instance()->Mars2Lors(chamber, tmp, localX, localY); @@ -160,11 +256,21 @@ float Digit::getFractionalContributionForPad(HitType const& hit, int somepad) return Digit::InMathieson(localX, localY, somepad); } +/// QdcTot : Samples total charge associated to a hit +/// +/// @param[in] e : hit energy [GeV] for mip Eloss for photon Etot +/// @param[in] time : ... +/// @param[in] pc : the photo cathode number [0..5] +/// @param[in] px : the horizontal displacement [0..79] +/// @param[in] py : the vertical displacement [0..47] +/// @param[out] localX : the horizontal displacement related to Anode Wires +/// @param[out] localY : the vertical displacement related to Anode Wires +/// @return : total QDC float Digit::QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY) { - // Samples total charge associated to a hit - // Arguments: e- hit energy [GeV] for mip Eloss for photon Etot - // Returns: total QDC + // + // Arguments: e- + // Returns: float Q = 0; if (time > 1.2e-6) { Q = 0; @@ -193,57 +299,94 @@ float Digit::QdcTot(float e, float time, int pc, int px, int py, float& localX, return Q; } -float Digit::IntPartMathiX(float x, int pad) +/// IntPartMathiX : Integration of Mathieson. +/// This is the answer to electrostatic problem of charge distrubution in MWPC +/// described elsewhere. (NIM A370(1988)602-603) +/// +/// @param[in] x : position of the center of Mathieson distribution +/// @param[in] pad : the Digit Unique Id [0x00CPXXYY] +/// @return : a charge fraction [0-1] imposed into the pad +Double_t Digit::IntPartMathiX(float x, int pad) { - // Integration of Mathieson. - // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603) - // Arguments: x,y- position of the center of Mathieson distribution - // Returns: a charge fraction [0-1] imposed into the pad - auto shift1 = -LorsX(pad) + 0.5 * Param::SizePadX(); - auto shift2 = -LorsX(pad) - 0.5 * Param::SizePadX(); + Double_t shift1 = -LorsX(pad) + 0.5 * o2::hmpid::Param::SizePadX(); + Double_t shift2 = -LorsX(pad) - 0.5 * o2::hmpid::Param::SizePadX(); - auto ux1 = Param::SqrtK3x() * TMath::TanH(Param::K2x() * (x + shift1) / Param::PitchAnodeCathode()); - auto ux2 = Param::SqrtK3x() * TMath::TanH(Param::K2x() * (x + shift2) / o2::hmpid::Param::PitchAnodeCathode()); + Double_t ux1 = o2::hmpid::Param::SqrtK3x() * TMath::TanH(o2::hmpid::Param::K2x() * (x + shift1) / o2::hmpid::Param::PitchAnodeCathode()); + Double_t ux2 = o2::hmpid::Param::SqrtK3x() * TMath::TanH(o2::hmpid::Param::K2x() * (x + shift2) / o2::hmpid::Param::PitchAnodeCathode()); return o2::hmpid::Param::K4x() * (TMath::ATan(ux2) - TMath::ATan(ux1)); } +/// IntPartMathiY : Integration of Mathieson. +/// This is the answer to electrostatic problem of charge distrubution in MWPC +/// described elsewhere. (NIM A370(1988)602-603) +/// +/// @param[in] y : position of the center of Mathieson distribution +/// @param[in] pad : the Digit Unique Id [0x00CPXXYY] +/// @return : a charge fraction [0-1] imposed into the pad Double_t Digit::IntPartMathiY(Double_t y, int pad) { - // Integration of Mathieson. - // This is the answer to electrostatic problem of charge distrubution in MWPC described elsewhere. (NIM A370(1988)602-603) - // Arguments: x,y- position of the center of Mathieson distribution - // Returns: a charge fraction [0-1] imposed into the pad Double_t shift1 = -LorsY(pad) + 0.5 * o2::hmpid::Param::SizePadY(); Double_t shift2 = -LorsY(pad) - 0.5 * o2::hmpid::Param::SizePadY(); - Double_t uy1 = Param::SqrtK3y() * TMath::TanH(Param::K2y() * (y + shift1) / Param::PitchAnodeCathode()); - Double_t uy2 = Param::SqrtK3y() * TMath::TanH(Param::K2y() * (y + shift2) / Param::PitchAnodeCathode()); + Double_t uy1 = o2::hmpid::Param::SqrtK3y() * TMath::TanH(o2::hmpid::Param::K2y() * (y + shift1) / o2::hmpid::Param::PitchAnodeCathode()); + Double_t uy2 = o2::hmpid::Param::SqrtK3y() * TMath::TanH(o2::hmpid::Param::K2y() * (y + shift2) / o2::hmpid::Param::PitchAnodeCathode()); - return Param::K4y() * (TMath::ATan(uy2) - TMath::ATan(uy1)); + return o2::hmpid::Param::K4y() * (TMath::ATan(uy2) - TMath::ATan(uy1)); } +/// InMathieson : Integration of Mathieson. +/// This is the answer to electrostatic problem of charge distrubution in MWPC +/// described elsewhere. (NIM A370(1988)602-603) +/// +/// @param[in] localX : X position of the center of Mathieson distribution +/// @param[in] localY : Y position of the center of Mathieson distribution +/// @param[in] pad : the Digit Unique Id [0x00CPXXYY] +/// @return : a charge fraction [0-1] imposed into the pad float Digit::InMathieson(float localX, float localY, int pad) { - return 4. * Digit::IntPartMathiX(localX, pad) * Digit::IntPartMathiY(localY, pad); + return 4. * IntPartMathiX(localX, pad) * IntPartMathiY(localY, pad); } -// Time conversion functions -double Digit::OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) +// ---- Time conversion functions ---- + +/// OrbitBcToTimeNs : Converts the Orbit,BC pair in absolute +/// nanoseconds time. +/// +/// @param[in] Orbit : the Orbit number [0..2^32-1] +/// @param[in] BC : the Bunch Crossing Number [0..2^12-1] +/// @return : the absolute time in nanoseconds +Double_t Digit::OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) { return (BC * o2::constants::lhc::LHCBunchSpacingNS + Orbit * o2::constants::lhc::LHCOrbitNS); } -uint32_t Digit::TimeNsToOrbit(double TimeNs) +/// TimeNsToOrbit : Extracts the Orbit number from the absolute +/// nanoseconds time. +/// +/// @param[in] TimeNs : the absolute nanoseconds time +/// @return : the Orbit number [0..2^32-1] +uint32_t Digit::TimeNsToOrbit(Double_t TimeNs) { return (TimeNs / o2::constants::lhc::LHCOrbitNS); } -uint16_t Digit::TimeNsToBc(double TimeNs) +/// TimeNsToBc : Extracts the Bunch Crossing number from the absolute +/// nanoseconds time. +/// +/// @param[in] TimeNs : the absolute nanoseconds time +/// @return : the Bunch Crossing number [0..2^12-1] +uint16_t Digit::TimeNsToBc(Double_t TimeNs) { return (std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); } +/// TimeNsToOrbitBc : Extracts the (Orbit,BC) pair from the absolute +/// nanoseconds time. +/// +/// @param[in] TimeNs : the absolute nanoseconds time +/// @param[out] Orbit : the Orbit number [0..2^32-1] +/// @param[out] Bc : the Bunch Crossing number [0..2^12-1] void Digit::TimeNsToOrbitBc(double TimeNs, uint32_t& Orbit, uint16_t& Bc) { Orbit = TimeNsToOrbit(TimeNs); @@ -251,9 +394,14 @@ void Digit::TimeNsToOrbitBc(double TimeNs, uint32_t& Orbit, uint16_t& Bc) return; } -// Functions to manage Digit vectors +// ---- Functions to manage Digit vectors ---- -// Function for order digits (Event,Chamber,Photo,x,y) +/// eventEquipPadsComp : Function for order digits (Event,Chamber,Photo,x,y) +/// to use in sort method function overload +/// @param[in] d1 : one Digit +/// @param[in] d2 : one Digit +/// @return : true if event of d1 comes before the event of d2, for +/// same events evaluates the position into the detector bool Digit::eventEquipPadsComp(Digit& d1, Digit& d2) { uint64_t t1, t2; @@ -268,6 +416,11 @@ bool Digit::eventEquipPadsComp(Digit& d1, Digit& d2) return false; }; +/// extractDigitsPerEvent : Function for select a sub vector of Digits of the +/// same event +/// @param[in] Digits : one vector of Digits +/// @param[in] EventID : the Trigger ID [ 0000.0000.0000.0000.0000.oooo.oooo.oooo.oooo.oooo.oooo.oooo.oooo.bbbb.bbbb.bbbb ] +/// @return : the subvector of Digits that have the same EventID std::vector* Digit::extractDigitsPerEvent(std::vector& Digits, uint64_t EventID) { std::vector* subVector = new std::vector(); @@ -279,13 +432,20 @@ std::vector* Digit::extractDigitsPerEvent(std::vector* Digit::extractEvents(std::vector& Digits) { - std::vector* subVector = new std::vector(); + std::vector* eventIds = new std::vector(); for (const auto& digit : Digits) { - if (find(subVector->begin(), subVector->end(), digit.getTriggerID()) == subVector->end()) { - subVector->push_back(digit.getTriggerID()); + if (find(eventIds->begin(), eventIds->end(), digit.getTriggerID()) == eventIds->end()) { + eventIds->push_back(digit.getTriggerID()); } } - return (subVector); + return (eventIds); }; + + +// -------- eof ----------- diff --git a/Detectors/HMPID/base/src/Geo.cxx b/Detectors/HMPID/base/src/Geo.cxx index aadd52a2de800..00cf35965671a 100644 --- a/Detectors/HMPID/base/src/Geo.cxx +++ b/Detectors/HMPID/base/src/Geo.cxx @@ -8,6 +8,12 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// +/// \file Geo.h +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 15/02/2021 + #include "HMPIDBase/Geo.h" #include "HMPIDBase/Param.h" #include "TGeoManager.h" @@ -21,6 +27,9 @@ using namespace o2::hmpid; //constexpr Bool_t Geo::FEAWITHMASKS[NSECTORS]; +// ============= Geo Class implementation ======= + +/// Init : void Geo::Init() { LOG(INFO) << "hmpid::Geo: Initialization of HMPID parameters"; @@ -34,21 +43,13 @@ void Geo::Init() /// /// (0,0,0,0) Right Top (1,0,0,0) Left Bottom /// + +/// Module2Equipment : Convert coordinates system +/// This was replaced with that defined in DIGIT class +/// (Module, Row, Col -> Equi, Colu, Dilo, Chan) +/// **** OBSOLETE **** void Geo::Module2Equipment(int Mod, int Row, int Col, int* Equi, int* Colu, int* Dilo, int* Chan) { - /* if (Row > MAXHALFXROWS) { - *Equi = Mod * EQUIPMENTSPERMODULE + 1; - Row = Row - HALFXROWS; - } else { - *Equi = Mod * EQUIPMENTSPERMODULE; - Row = MAXHALFXROWS - Row; - Col = MAXYCOLS - Col; - } - *Dilo = Row / DILOPADSROWS; - *Colu = Col / DILOPADSCOLS; - *Chan = (Row % DILOPADSROWS) * DILOPADSCOLS + (Col % DILOPADSCOLS); - return; -*/ int y2a[6] = {5, 3, 1, 0, 2, 4}; int ch, ax, ay; if (ax > Geo::MAXHALFXROWS) { @@ -65,29 +66,12 @@ void Geo::Module2Equipment(int Mod, int Row, int Col, int* Equi, int* Colu, int* return; } -/// Functions to translate coordinates : from Equipment,Col,Dilogic,Channel to Module,Col,Row -/// Digit coordinates " Mod,Row,Col := Mod = {0..6} Row = {0..159} Col = {0..143} -/// (0,0) Left Bottom -/// -/// Hardware coordinates Equ,Col,Dil,Cha := Equ = {0..13} Col = {0..23} Dil = {0..9} Cha = {0..47} -/// -/// (0,0,0,0) Right Top (1,0,0,0) Left Bottom -/// +/// Equipment2Module : Convert coordinates system +/// This was replaced with that defined in DIGIT class +/// (Equi, Colu, Dilo, Chan -> Module, Row, Col) +/// **** OBSOLETE **** void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int* Mod, int* Row, int* Col) { - /* - - *Mod = Equi / EQUIPMENTSPERMODULE; - *Row = Dilo * DILOPADSROWS + Chan / DILOPADSROWS; - *Col = (Colu * DILOPADSCOLS) + Chan % DILOPADSCOLS; - - if (Equi % EQUIPMENTSPERMODULE == 1) { - *Row += HALFXROWS; - } else { - *Row = MAXHALFXROWS - *Row; - *Col = MAXYCOLS - *Col; - } - */ if (Equi < 0 || Equi >= Geo::MAXEQUIPMENTS || Colu < 0 || Colu >= Geo::N_COLUMNS || Dilo < 0 || Dilo >= Geo::N_DILOGICS || Chan < 0 || Chan >= Geo::N_CHANNELS) return; From fea83780b3fb7c52ce567bc8abd01c4ccdbc58a7 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 15 Feb 2021 13:36:26 +0100 Subject: [PATCH 192/208] Add some remarks --- Detectors/HMPID/workflow/src/DataDecoderSpec.cxx | 13 +++++++------ Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx | 10 +++++----- .../HMPID/workflow/src/PedestalsCalculationSpec.cxx | 10 +++++----- Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx | 8 ++++++++ .../HMPID/workflow/src/WriteRawFromDigitsSpec.cxx | 8 ++++++++ .../HMPID/workflow/src/dump-digits-workflow.cxx | 8 ++------ .../workflow/src/raw-to-pedestals-workflow.cxx | 6 ++++++ .../HMPID/workflow/src/read-raw-file-workflow.cxx | 7 +++++++ .../workflow/src/write-raw-from-digits-workflow.cxx | 6 ++++++ .../src/write-root-from-digits-workflow.cxx | 6 ++++++ 10 files changed, 60 insertions(+), 22 deletions(-) diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 2571eed2011dc..63e2c718067bd 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -9,10 +9,10 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file DatDecoderSpec.cxx -/// \author -/// +/// \file DataDecoderSpec.cxx +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 01 feb 2021 /// \brief Implementation of a data processor to run the HMPID raw decoding /// @@ -165,9 +165,10 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) } return; } -//pc.outputs().make + //_________________________________________________________________________________________________ // the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow +// TODO: rearrange, test void DataDecoderTask::decodeReadout(framework::ProcessingContext& pc) { LOG(INFO) << "*********** In decode readout **************"; @@ -186,6 +187,7 @@ void DataDecoderTask::decodeReadout(framework::ProcessingContext& pc) } // the decodeReadout() function processes the messages generated by o2-mch-cru-page-reader-workflow +// TODO: rearrange, test void DataDecoderTask::decodeRawFile(framework::ProcessingContext& pc) { LOG(INFO) << "*********** In decode rawfile **************"; @@ -217,7 +219,6 @@ void DataDecoderTask::decodeRawFile(framework::ProcessingContext& pc) //_________________________________________________________________________________________________ o2::framework::DataProcessorSpec getDecodingSpec(std::string inputSpec) { - std::vector inputs; inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"HMP", "RAWDATA"}, o2::framework::Lifetime::Timeframe); inputs.emplace_back("file", o2::framework::ConcreteDataTypeMatcher{"ROUT", "RAWDATA"}, o2::framework::Lifetime::Timeframe); diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 744cf32bfb92d..73ba3093e6a38 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -9,11 +9,11 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file DatDecoderSpec.cxx -/// \author -/// -/// \brief Implementation of a data processor to run the HMPID raw decoding +/// \file DumpDigitsSpec.cxx +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 01 feb 2021 +/// \brief Implementation of a data processor to Dump o record a stream of Digits /// #include diff --git a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx index 40e2f1c4ea52d..53279dc476029 100644 --- a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx +++ b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx @@ -9,11 +9,11 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// -/// \file DatDecoderSpec.cxx -/// \author -/// -/// \brief Implementation of a data processor to run the HMPID raw decoding +/// \file PedestalsCalculationSpec.cxx +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 01 feb 2021 +/// \brief Implementation of a data processor to read a raw file and produce Pedestals/Threshold files /// #include diff --git a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx index 88e54260ba274..9f4e2cdef378d 100644 --- a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx +++ b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx @@ -8,6 +8,14 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// \file ReadRawFileSpec.cxx +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 01 feb 2021 +/// \brief Implementation of a data processor to read a raw file and produce Digits stream +/// + + #include #include #include diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index 717e3731bf390..9c38897b2e8e0 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -9,6 +9,14 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// \file WriteRawFromDigitsSpec.cxx +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 01 feb 2021 +/// \brief Implementation of a data processor to produce raw files from a Digits stream +/// + + #include #include #include diff --git a/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx index c847a7b805f03..a876d4844a8c4 100644 --- a/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/dump-digits-workflow.cxx @@ -9,13 +9,9 @@ // or submit itself to any jurisdiction. /// -/// \file raw-to-digits-workflow.cxx -/// \author Andrea Ferrero +/// \file dump-digits-workflow.cxx +/// \author Antonio Franco /// -/// \brief This is an executable that runs the decoding via DPL. -/// -/// This is an executable that takes a raw buffer from the Data Processing Layer, runs the decoding and sends the digits via the Data Processing Layer. -/// The decoder expects an input buffer in the format generated by o2-raw-file-reader-workflow /// #include "Framework/WorkflowSpec.h" diff --git a/Detectors/HMPID/workflow/src/raw-to-pedestals-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-pedestals-workflow.cxx index 045d9253c9ebf..c326f85169ccc 100644 --- a/Detectors/HMPID/workflow/src/raw-to-pedestals-workflow.cxx +++ b/Detectors/HMPID/workflow/src/raw-to-pedestals-workflow.cxx @@ -8,6 +8,12 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// \file raw-to-pedestals-workflow.cxx +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 01 feb 2021 +/// + #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" #include "Framework/CallbackService.h" diff --git a/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx b/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx index e2f9c85155f37..eb00e1f9b8922 100644 --- a/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx +++ b/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx @@ -8,6 +8,13 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// \file read-raw-file-workflow.cxx +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 01 feb 2021 +/// + + #include #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" diff --git a/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx index f9aaeea6b8fcd..92fe151bd6384 100644 --- a/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx @@ -8,6 +8,12 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// \file write-raw-from-digits-workflow.cxx +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 01 feb 2021 +/// + #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" #include "Framework/CallbackService.h" diff --git a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx index 048574924ed50..d623ef9f0ff56 100644 --- a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx @@ -8,6 +8,12 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// \file write-root-from-digits-workflow.cxx +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 01 feb 2021 +/// + #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" #include "Framework/CallbackService.h" From 9043117cedd37cc7e03eb518fee36767d527c57c Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 18 Feb 2021 11:10:20 +0100 Subject: [PATCH 193/208] Fix the return type of Digit::IntPartMathiX() method --- Detectors/HMPID/base/include/HMPIDBase/Digit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 28c44962ff89d..c15ba9e342c3b 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -144,7 +144,7 @@ class Digit // determines the total charge created by a hit // might modify the localX, localY coordiates associated to the hit static float QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY); - static float IntPartMathiX(float x, int pad); + static Double_t IntPartMathiX(float x, int pad); static Double_t IntPartMathiY(Double_t y, int pad); static float InMathieson(float localX, float localY, int pad); From 40d0bec956af90497a2506ac79736f2dce3aae08 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Fri, 19 Feb 2021 12:30:10 +0100 Subject: [PATCH 194/208] Fix Root Data Types --- .../HMPID/base/include/HMPIDBase/Digit.h | 8 +++---- .../HMPID/base/include/HMPIDBase/Param.h | 8 +++---- Detectors/HMPID/base/src/Digit.cxx | 22 +++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index c15ba9e342c3b..1a1f7e4bfade4 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -143,10 +143,10 @@ class Digit // determines the total charge created by a hit // might modify the localX, localY coordiates associated to the hit - static float QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY); - static Double_t IntPartMathiX(float x, int pad); - static Double_t IntPartMathiY(Double_t y, int pad); - static float InMathieson(float localX, float localY, int pad); + static Double_t QdcTot(Double_t e, Double_t time, Int_t pc, Int_t px, Int_t py, Double_t& localX, Double_t& localY); + static Double_t IntPartMathiX(Double_t x, Int_t pad); + static Double_t IntPartMathiY(Double_t y, Int_t pad); + static Double_t InMathieson(Double_t localX, Double_t localY, int pad); ClassDefNV(Digit, 2); }; diff --git a/Detectors/HMPID/base/include/HMPIDBase/Param.h b/Detectors/HMPID/base/include/HMPIDBase/Param.h index d8d74ad91504a..b49e753b778e7 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Param.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Param.h @@ -186,7 +186,7 @@ class Param static Int_t StackCount(Int_t pid, Int_t evt); //Counts stack particles of given sort in given event static void IdealPosition(Int_t iCh, TGeoHMatrix* m); //ideal position of given chamber //trasformation methodes - void Lors2Mars(Int_t c, float x, float y, double* m, Int_t pl = kPc) const + void Lors2Mars(Int_t c, double x, double y, double* m, Int_t pl = kPc) const { double z = 0; switch (pl) { @@ -203,20 +203,20 @@ class Param double l[3] = {x - mX, y - mY, z}; mM[c]->LocalToMaster(l, m); } - TVector3 Lors2Mars(Int_t c, float x, float y, Int_t pl = kPc) const + TVector3 Lors2Mars(Int_t c, double x, double y, Int_t pl = kPc) const { double m[3]; Lors2Mars(c, x, y, m, pl); return TVector3(m); } //MRS->LRS - void Mars2Lors(Int_t c, double* m, float& x, float& y) const + void Mars2Lors(Int_t c, double* m, double& x, double& y) const { double l[3]; mM[c]->MasterToLocal(m, l); x = l[0] + mX; y = l[1] + mY; } //MRS->LRS - void Mars2LorsVec(Int_t c, double* m, float& th, float& ph) const + void Mars2LorsVec(Int_t c, double* m, double& th, double& ph) const { double l[3]; mM[c]->MasterToLocalVect(m, l); diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 53300e506a44b..c8ad3de1ced30 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -227,8 +227,8 @@ void Digit::Pad2Photo(uint32_t pad, int* chamber, int* photo, int* x, int* y) /// @param[out] totalcharge : the charge of the hit [0..2^12-1] void Digit::getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge) { - float localX; - float localY; + double localX; + double localY; chamber = hit.GetDetectorID(); double tmp[3] = {hit.GetX(), hit.GetY(), hit.GetZ()}; Param::Instance()->Mars2Lors(chamber, tmp, localX, localY); @@ -245,8 +245,8 @@ void Digit::getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& /// @return : the fraction of the charge ... float Digit::getFractionalContributionForPad(HitType const& hit, int somepad) { - float localX; - float localY; + double localX; + double localY; const auto chamber = hit.GetDetectorID(); // chamber number is in detID double tmp[3] = {hit.GetX(), hit.GetY(), hit.GetZ()}; @@ -266,23 +266,23 @@ float Digit::getFractionalContributionForPad(HitType const& hit, int somepad) /// @param[out] localX : the horizontal displacement related to Anode Wires /// @param[out] localY : the vertical displacement related to Anode Wires /// @return : total QDC -float Digit::QdcTot(float e, float time, int pc, int px, int py, float& localX, float& localY) +Double_t Digit::QdcTot(Double_t e, Double_t time, Int_t pc, Int_t px, Int_t py, Double_t& localX, Double_t& localY) { // // Arguments: e- // Returns: - float Q = 0; + double Q = 0; if (time > 1.2e-6) { Q = 0; } if (py < 0) { return 0; } else { - float y = Param::LorsY(pc, py); + double y = Param::LorsY(pc, py); localY = ((y - localY) > 0) ? y - 0.2 : y + 0.2; //shift to the nearest anod wire - float x = (localX > 66.6) ? localX - 66.6 : localX; //sagita is for PC (0-64) and not for chamber - float qdcEle = 34.06311 + 0.2337070 * x + 5.807476e-3 * x * x - 2.956471e-04 * x * x * x + 2.310001e-06 * x * x * x * x; //reparametrised from DiMauro + double x = (localX > 66.6) ? localX - 66.6 : localX; //sagita is for PC (0-64) and not for chamber + double qdcEle = 34.06311 + 0.2337070 * x + 5.807476e-3 * x * x - 2.956471e-04 * x * x * x + 2.310001e-06 * x * x * x * x; //reparametrised from DiMauro int iNele = int((e / 26e-9) * 0.8); if (iNele < 1) { @@ -306,7 +306,7 @@ float Digit::QdcTot(float e, float time, int pc, int px, int py, float& localX, /// @param[in] x : position of the center of Mathieson distribution /// @param[in] pad : the Digit Unique Id [0x00CPXXYY] /// @return : a charge fraction [0-1] imposed into the pad -Double_t Digit::IntPartMathiX(float x, int pad) +Double_t Digit::IntPartMathiX(Double_t x, int pad) { Double_t shift1 = -LorsX(pad) + 0.5 * o2::hmpid::Param::SizePadX(); Double_t shift2 = -LorsX(pad) - 0.5 * o2::hmpid::Param::SizePadX(); @@ -343,7 +343,7 @@ Double_t Digit::IntPartMathiY(Double_t y, int pad) /// @param[in] localY : Y position of the center of Mathieson distribution /// @param[in] pad : the Digit Unique Id [0x00CPXXYY] /// @return : a charge fraction [0-1] imposed into the pad -float Digit::InMathieson(float localX, float localY, int pad) +Double_t Digit::InMathieson(Double_t localX, Double_t localY, Int_t pad) { return 4. * IntPartMathiX(localX, pad) * IntPartMathiY(localY, pad); } From 93af8dc4cfb10e328d71b5b3115b14005f51c2f3 Mon Sep 17 00:00:00 2001 From: Antonio Date: Sun, 21 Feb 2021 20:35:05 +0100 Subject: [PATCH 195/208] Fix for compilaton on CentOs 7 --- Detectors/HMPID/simulation/src/Detector.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/HMPID/simulation/src/Detector.cxx b/Detectors/HMPID/simulation/src/Detector.cxx index 86f22a867cf98..2e869c3cba6f7 100644 --- a/Detectors/HMPID/simulation/src/Detector.cxx +++ b/Detectors/HMPID/simulation/src/Detector.cxx @@ -74,7 +74,7 @@ bool Detector::ProcessHits(FairVolume* v) TString tmpname = volname; tmpname.Remove(0, 4); Int_t idch = tmpname.Atoi(); //retrieve the chamber number - Float_t xl, yl; + Double_t xl, yl; Param::Instance()->Mars2Lors(idch, x, xl, yl); //take LORS position AddHit(x[0], x[1], x[2], hitTime, etot, tid, idch); //HIT for photon, position at P, etot will be set to Q GenFee(etot); //generate feedback photons etot is modified in hit ctor to Q of hit @@ -112,7 +112,7 @@ bool Detector::ProcessHits(FairVolume* v) TString tmpname = volname; tmpname.Remove(0, 4); Int_t idch = tmpname.Atoi(); //retrieve the chamber number - Float_t xl, yl; + Double_t xl, yl; Param::Instance()->Mars2Lors(idch, out, xl, yl); //take LORS position if (eloss > 0) { // HIT for MIP, position near anod plane, eloss will be set to Q From ae31f90d41706976f1980b36f1cb337b853deeb2 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 22 Feb 2021 19:30:06 +0100 Subject: [PATCH 196/208] Fix the Clang errors --- .../HMPID/include/DataFormatsHMP/DataFormat.h | 5 ++--- Detectors/HMPID/base/include/HMPIDBase/Digit.h | 15 ++++++++++++--- Detectors/HMPID/base/src/Digit.cxx | 2 +- Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx | 1 - .../HMPID/workflow/src/read-raw-file-workflow.cxx | 1 - 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h b/DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h index ac6f3397e2829..7ca8a8f17e7d5 100644 --- a/DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h +++ b/DataFormats/Detectors/HMPID/include/DataFormatsHMP/DataFormat.h @@ -20,11 +20,10 @@ namespace o2 { namespace hmpid { - namespace raw { - /** generic word * +/** generic word * struct Word_t { uint32_t undefined : 31; @@ -41,6 +40,6 @@ namespace raw }; */ } // namespace raw -} // namespace tof +} // namespace hmpid } // namespace o2 #endif diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 1a1f7e4bfade4..4fe9c78d0e6a1 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -87,9 +87,15 @@ class Digit // Getter & Setters uint16_t getCharge() const { return mQ; } - void setCharge(uint16_t Q) { mQ = Q; return; }; + void setCharge(uint16_t Q) { + mQ = Q; + return; + }; int getPadID() const { return mPad; } - void setPadID(uint32_t pad) { mPad = pad; return; }; + void setPadID(uint32_t pad) { + mPad = pad; + return; + }; uint32_t getOrbit() const { return mOrbit; } uint16_t getBC() const { return mBc; } uint64_t getTriggerID() const { return OrbitBcToEventId(mOrbit, mBc); } @@ -110,7 +116,10 @@ class Digit return; } bool isValid() { return (mPad == 0xFFFFFFFF ? true : false); }; - void setInvalid() { mPad = 0xFFFFFFFF; return; }; + void setInvalid() { + mPad = 0xFFFFFFFF; + return; + }; // convenience wrapper function for conversion to x-y pad coordinates int getPx() const { return A2X(mPad); } diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index c8ad3de1ced30..748c92bdf7311 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -441,7 +441,7 @@ std::vector* Digit::extractEvents(std::vector& Digit std::vector* eventIds = new std::vector(); for (const auto& digit : Digits) { if (find(eventIds->begin(), eventIds->end(), digit.getTriggerID()) == eventIds->end()) { - eventIds->push_back(digit.getTriggerID()); + eventIds->push_back(digit.getTriggerID()); } } return (eventIds); diff --git a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx index 9f4e2cdef378d..970cf419d3448 100644 --- a/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx +++ b/Detectors/HMPID/workflow/src/ReadRawFileSpec.cxx @@ -15,7 +15,6 @@ /// \brief Implementation of a data processor to read a raw file and produce Digits stream /// - #include #include #include diff --git a/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx b/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx index eb00e1f9b8922..47e3447acb6ce 100644 --- a/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx +++ b/Detectors/HMPID/workflow/src/read-raw-file-workflow.cxx @@ -14,7 +14,6 @@ /// \date 01 feb 2021 /// - #include #include "Framework/WorkflowSpec.h" #include "Framework/DataSpecUtils.h" From 601689fa2a8b36d0e5eb8a93d08879d7552ea3fb Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Tue, 23 Feb 2021 08:26:16 +0100 Subject: [PATCH 197/208] Fix the git-Clang errors --- Detectors/HMPID/base/include/HMPIDBase/Digit.h | 9 ++++++--- Detectors/HMPID/base/src/Digit.cxx | 1 - Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 4fe9c78d0e6a1..e30fe18e30fa2 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -87,12 +87,14 @@ class Digit // Getter & Setters uint16_t getCharge() const { return mQ; } - void setCharge(uint16_t Q) { + void setCharge(uint16_t Q) + { mQ = Q; return; }; int getPadID() const { return mPad; } - void setPadID(uint32_t pad) { + void setPadID(uint32_t pad) + { mPad = pad; return; }; @@ -116,7 +118,8 @@ class Digit return; } bool isValid() { return (mPad == 0xFFFFFFFF ? true : false); }; - void setInvalid() { + void setInvalid() + { mPad = 0xFFFFFFFF; return; }; diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 748c92bdf7311..3f65f284d01d4 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -447,5 +447,4 @@ std::vector* Digit::extractEvents(std::vector& Digit return (eventIds); }; - // -------- eof ----------- diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index 9c38897b2e8e0..27254ba9c6cae 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -16,7 +16,6 @@ /// \brief Implementation of a data processor to produce raw files from a Digits stream /// - #include #include #include From 873d96936a1adc60f67457b7965f854217cf5e3f Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Wed, 24 Feb 2021 11:38:44 +0100 Subject: [PATCH 198/208] Fix Coding Convention Errors from Pull Request of Wed 24 Feb 2021, 07:48:08 UTC --- .../HMPID/base/include/HMPIDBase/Common.h | 2 +- Detectors/HMPID/base/src/Digit.cxx | 12 ++- Detectors/HMPID/base/src/Geo.cxx | 3 +- .../HMPIDReconstruction/HmpidDecodeRawMem.h | 21 +++-- .../HMPIDReconstruction/HmpidDecoder.h | 2 +- .../HMPIDReconstruction/HmpidEquipment.h | 2 +- .../reconstruction/src/HmpidDecodeRawMem.cxx | 8 +- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 79 ++++++++++++------- .../reconstruction/src/HmpidEquipment.cxx | 11 ++- .../include/HMPIDSimulation/HmpidCoder.h | 4 +- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 45 ++++++----- .../HMPID/workflow/src/DataDecoderSpec.cxx | 8 +- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 8 +- .../workflow/src/PedestalsCalculationSpec.cxx | 22 +++--- .../workflow/src/WriteRawFromDigitsSpec.cxx | 1 - 15 files changed, 131 insertions(+), 97 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Common.h b/Detectors/HMPID/base/include/HMPIDBase/Common.h index 6df783514d4ac..24c8f9806d4c9 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Common.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Common.h @@ -45,7 +45,7 @@ class ExecutionTimer mElapseLogTime = 10; // default 10 seconds }; - ~ExecutionTimer(){}; + ~ExecutionTimer() = default; /// getElapseLogTime : returns the seconds for the elapsed log message /// @return : the number of seconds for the elapsed logging diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 3f65f284d01d4..3c6d6ceba6416 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -96,8 +96,9 @@ uint32_t Digit::Equipment2Pad(int Equi, int Colu, int Dilo, int Chan) { // Check the input data if (Equi < 0 || Equi >= Geo::MAXEQUIPMENTS || Colu < 0 || Colu >= Geo::N_COLUMNS || - Dilo < 0 || Dilo >= Geo::N_DILOGICS || Chan < 0 || Chan >= Geo::N_CHANNELS) + Dilo < 0 || Dilo >= Geo::N_DILOGICS || Chan < 0 || Chan >= Geo::N_CHANNELS) { return -1; + } int chan2y[6] = {3, 2, 4, 1, 5, 0}; // y coordinate translation for a channel address (index position) for even chamber @@ -407,12 +408,15 @@ bool Digit::eventEquipPadsComp(Digit& d1, Digit& d2) uint64_t t1, t2; t1 = d1.getTriggerID(); t2 = d2.getTriggerID(); - if (t1 < t2) + if (t1 < t2) { return true; - if (t2 < t1) + } + if (t2 < t1) { return false; - if (d1.getPadID() < d2.getPadID()) + } + if (d1.getPadID() < d2.getPadID()) { return true; + } return false; }; diff --git a/Detectors/HMPID/base/src/Geo.cxx b/Detectors/HMPID/base/src/Geo.cxx index 00cf35965671a..5f2490e488a1c 100644 --- a/Detectors/HMPID/base/src/Geo.cxx +++ b/Detectors/HMPID/base/src/Geo.cxx @@ -73,8 +73,9 @@ void Geo::Module2Equipment(int Mod, int Row, int Col, int* Equi, int* Colu, int* void Geo::Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int* Mod, int* Row, int* Col) { if (Equi < 0 || Equi >= Geo::MAXEQUIPMENTS || Colu < 0 || Colu >= Geo::N_COLUMNS || - Dilo < 0 || Dilo >= Geo::N_DILOGICS || Chan < 0 || Chan >= Geo::N_CHANNELS) + Dilo < 0 || Dilo >= Geo::N_DILOGICS || Chan < 0 || Chan >= Geo::N_CHANNELS) { return; + } int a2y[6] = {3, 2, 4, 1, 5, 0}; //pady for a given padress (for single DILOGIC chip) int ch = Equi / Geo::EQUIPMENTSPERMODULE; // The Module diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h index ff66c5f15c953..edec37ba01e89 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecodeRawMem.h @@ -18,12 +18,11 @@ #ifndef COMMON_HMPIDDECODERAWMEM_H_ #define COMMON_HMPIDDECODERAWMEM_H_ -#include -#include -#include -#include -#include +#include +#include +#include #include +#include #include #include "HMPIDBase/Digit.h" @@ -42,13 +41,13 @@ class HmpidDecodeRawMem : public HmpidDecoder HmpidDecodeRawMem(int numOfEquipments); ~HmpidDecodeRawMem(); - bool setUpStream(void* Buffer, long BufferLen); + bool setUpStream(void* Buffer, long BufferLen) override; private: - bool getBlockFromStream(uint32_t** streamPtr, uint32_t Size); - bool getHeaderFromStream(uint32_t** streamPtr); - bool getWordFromStream(uint32_t* word); - void setPad(HmpidEquipment* eq, int col, int dil, int ch, uint16_t charge); + bool getBlockFromStream(uint32_t** streamPtr, uint32_t Size) override; + bool getHeaderFromStream(uint32_t** streamPtr) override; + bool getWordFromStream(uint32_t* word) override; + void setPad(HmpidEquipment* eq, int col, int dil, int ch, uint16_t charge) override; private: }; @@ -63,7 +62,7 @@ class HmpidDecodeRawDigit : public HmpidDecodeRawMem std::vector mDigits; private: - void setPad(HmpidEquipment* eq, int col, int dil, int ch, uint16_t charge); + void setPad(HmpidEquipment* eq, int col, int dil, int ch, uint16_t charge) override; }; } // namespace hmpid diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h index f1302656abe5d..abdf757b7c990 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidDecoder.h @@ -18,7 +18,7 @@ #define COMMON_HMPIDDECODER_H_ #include -#include +#include #include #include diff --git a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h index e6db8d4c83025..bf0bf74c1ec1a 100644 --- a/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h +++ b/Detectors/HMPID/reconstruction/include/HMPIDReconstruction/HmpidEquipment.h @@ -19,7 +19,7 @@ #define COMMON_HMPIDEQUIPMENT_H_ #include -#include +#include #include #include "HMPIDBase/Geo.h" diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx index 47c0ccaf782ff..760a18b6877c4 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecodeRawMem.cxx @@ -49,9 +49,7 @@ HmpidDecodeRawMem::HmpidDecodeRawMem(int* EqIds, int* CruIds, int* LinkIds, int } /// Destructor -HmpidDecodeRawMem::~HmpidDecodeRawMem() -{ -} +HmpidDecodeRawMem::~HmpidDecodeRawMem() = default; /// Setup the Input Stream with a Memory Pointer /// the buffer length is in byte, some controls are done @@ -163,9 +161,7 @@ HmpidDecodeRawDigit::HmpidDecodeRawDigit(int* EqIds, int* CruIds, int* LinkIds, } /// Destructor -HmpidDecodeRawDigit::~HmpidDecodeRawDigit() -{ -} +HmpidDecodeRawDigit::~HmpidDecodeRawDigit() = default; /// ----- Sets the Pad ! ------ /// this is an overloaded method. In this version the value of the charge diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 0d6f12d0ae268..b2df8dded8028 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -120,9 +120,9 @@ void HmpidDecoder::init() mHeORBIT = 0; mHeTType = 0; - mActualStreamPtr = 0; - mEndStreamPtr = 0; - mStartStreamPtr = 0; + mActualStreamPtr = nullptr; + mEndStreamPtr = nullptr; + mStartStreamPtr = nullptr; for (int i = 0; i < mNumberOfEquipments; i++) { mTheEquipments[i]->init(); @@ -425,10 +425,12 @@ void HmpidDecoder::updateStatistics(HmpidEquipment* eq) eq->mPadsPerEventAverage = ((eq->mPadsPerEventAverage * (eq->mNumberOfEvents - 1)) + eq->mSampleNumber) / (eq->mNumberOfEvents); eq->mEventSizeAverage = ((eq->mEventSizeAverage * (eq->mNumberOfEvents - 1)) + eq->mEventSize) / (eq->mNumberOfEvents); eq->mBusyTimeAverage = ((eq->mBusyTimeAverage * eq->mBusyTimeSamples) + eq->mBusyTimeValue) / (++(eq->mBusyTimeSamples)); - if (eq->mSampleNumber == 0) + if (eq->mSampleNumber == 0) { eq->mNumberOfEmptyEvents += 1; - if (eq->mErrorsCounter > 0) + } + if (eq->mErrorsCounter > 0) { eq->mNumberOfWrongEvents += 1; + } eq->mTotalPads += eq->mSampleNumber; eq->mTotalErrors += eq->mErrorsCounter; @@ -853,8 +855,9 @@ uint16_t HmpidDecoder::getPadSamples(int Module, int Row, int Column) int e, c, d, h; Digit::Absolute2Equipment(Module, Row, Column, &e, &c, &d, &h); int EqInd = getEquipmentIndex(e); - if (EqInd < 0) + if (EqInd < 0) { return (0); + } return (mTheEquipments[EqInd]->mPadSamples[c][d][h]); } @@ -868,8 +871,9 @@ double HmpidDecoder::getPadSum(int Module, int Row, int Column) int e, c, d, h; Digit::Absolute2Equipment(Module, Row, Column, &e, &c, &d, &h); int EqInd = getEquipmentIndex(e); - if (EqInd < 0) + if (EqInd < 0) { return (0); + } return (mTheEquipments[EqInd]->mPadSum[c][d][h]); } @@ -883,8 +887,9 @@ double HmpidDecoder::getPadSquares(int Module, int Row, int Column) int e, c, d, h; Digit::Absolute2Equipment(Module, Row, Column, &e, &c, &d, &h); int EqInd = getEquipmentIndex(e); - if (EqInd < 0) + if (EqInd < 0) { return (0); + } return (mTheEquipments[EqInd]->mPadSquares[c][d][h]); } @@ -897,8 +902,9 @@ double HmpidDecoder::getPadSquares(int Module, int Row, int Column) uint16_t HmpidDecoder::getChannelSamples(int EquipmId, int Column, int Dilogic, int Channel) { int EqInd = getEquipmentIndex(EquipmId); - if (EqInd < 0) + if (EqInd < 0) { return (0); + } return (mTheEquipments[EqInd]->mPadSamples[Column][Dilogic][Channel]); } @@ -911,8 +917,9 @@ uint16_t HmpidDecoder::getChannelSamples(int EquipmId, int Column, int Dilogic, double HmpidDecoder::getChannelSum(int EquipmId, int Column, int Dilogic, int Channel) { int EqInd = getEquipmentIndex(EquipmId); - if (EqInd < 0) + if (EqInd < 0) { return (0); + } return (mTheEquipments[EqInd]->mPadSum[Column][Dilogic][Channel]); } @@ -925,8 +932,9 @@ double HmpidDecoder::getChannelSum(int EquipmId, int Column, int Dilogic, int Ch double HmpidDecoder::getChannelSquare(int EquipmId, int Column, int Dilogic, int Channel) { int EqInd = getEquipmentIndex(EquipmId); - if (EqInd < 0) + if (EqInd < 0) { return (0); + } return (mTheEquipments[EqInd]->mPadSquares[Column][Dilogic][Channel]); } @@ -936,8 +944,9 @@ double HmpidDecoder::getChannelSquare(int EquipmId, int Column, int Dilogic, int float HmpidDecoder::getAverageEventSize(int EquipmId) { int EqInd = getEquipmentIndex(EquipmId); - if (EqInd < 0) + if (EqInd < 0) { return (0.0); + } return (mTheEquipments[EqInd]->mEventSizeAverage); } @@ -947,8 +956,9 @@ float HmpidDecoder::getAverageEventSize(int EquipmId) float HmpidDecoder::getAverageBusyTime(int EquipmId) { int EqInd = getEquipmentIndex(EquipmId); - if (EqInd < 0) + if (EqInd < 0) { return (0.0); + } return (mTheEquipments[EqInd]->mBusyTimeAverage); } @@ -961,9 +971,9 @@ float HmpidDecoder::getAverageBusyTime(int EquipmId) void HmpidDecoder::dumpErrors(int EquipmId) { int EqInd = getEquipmentIndex(EquipmId); - if (EqInd < 0) + if (EqInd < 0) { return; - + } std::cout << "Dump Errors for the Equipment = " << EquipmId << std::endl; for (int i = 0; i < MAXERRORS; i++) { std::cout << sErrorDescription[i] << " = " << mTheEquipments[EqInd]->mErrors[i] << std::endl; @@ -979,9 +989,9 @@ void HmpidDecoder::dumpErrors(int EquipmId) void HmpidDecoder::dumpPads(int EquipmId, int type) { int EqInd = getEquipmentIndex(EquipmId); - if (EqInd < 0) + if (EqInd < 0) { return; - + } int Module = EquipmId / 2; int StartRow = (EquipmId % 2 == 1) ? 80 : 0; int EndRow = (EquipmId % 2 == 1) ? 160 : 80; @@ -1024,68 +1034,79 @@ void HmpidDecoder::dumpHmpidError(int ErrorField) void HmpidDecoder::writeSummaryFile(char* summaryFileName) { FILE* fs = fopen(summaryFileName, "w"); - if (fs == 0) { + if (fs == nullptr) { printf("Error opening the file %s !\n", summaryFileName); throw TH_CREATEFILE; } fprintf(fs, "HMPID Readout Raw Data Decoding Summary File\n"); fprintf(fs, "Equipment Id\t"); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { fprintf(fs, "%d\t", mTheEquipments[i]->getEquipmentId()); + } fprintf(fs, "\n"); fprintf(fs, "Number of events\t"); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { fprintf(fs, "%d\t", mTheEquipments[i]->mNumberOfEvents); + } fprintf(fs, "\n"); fprintf(fs, "Average Event Size\t"); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { fprintf(fs, "%f\t", mTheEquipments[i]->mEventSizeAverage); + } fprintf(fs, "\n"); fprintf(fs, "Total pads\t"); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { fprintf(fs, "%d\t", mTheEquipments[i]->mTotalPads); + } fprintf(fs, "\n"); fprintf(fs, "Average pads per event\t"); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { fprintf(fs, "%f\t", mTheEquipments[i]->mPadsPerEventAverage); + } fprintf(fs, "\n"); fprintf(fs, "Busy Time average\t"); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { fprintf(fs, "%e\t", mTheEquipments[i]->mBusyTimeAverage); + } fprintf(fs, "\n"); fprintf(fs, "Event rate\t"); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { fprintf(fs, "%e\t", 1 / mTheEquipments[i]->mBusyTimeAverage); + } fprintf(fs, "\n"); fprintf(fs, "Number of Empty Events\t"); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { fprintf(fs, "%d\t", mTheEquipments[i]->mNumberOfEmptyEvents); + } fprintf(fs, "\n"); fprintf(fs, "-------------Errors--------------------\n"); fprintf(fs, "Wrong events\t"); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { fprintf(fs, "%d\t", mTheEquipments[i]->mNumberOfWrongEvents); + } fprintf(fs, "\n"); for (int j = 0; j < MAXERRORS; j++) { fprintf(fs, "%s\t", sErrorDescription[j]); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { fprintf(fs, "%d\t", mTheEquipments[i]->mErrors[j]); + } fprintf(fs, "\n"); } fprintf(fs, "Total errors\t"); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { fprintf(fs, "%d\t", mTheEquipments[i]->mTotalErrors); + } fprintf(fs, "\n"); fclose(fs); diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx index 422b7874db23d..3c4b1aea5dfb2 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx @@ -83,13 +83,15 @@ void HmpidEquipment::init() /// Resets the matrix that contains the results of the decoding void HmpidEquipment::resetPadMap() { - for (int r = 0; r < Geo::N_COLUMNS; r++) - for (int d = 0; d < Geo::N_DILOGICS; d++) + for (int r = 0; r < Geo::N_COLUMNS; r++) { + for (int d = 0; d < Geo::N_DILOGICS; d++) { for (int c = 0; c < Geo::N_CHANNELS; c++) { mPadSamples[r][d][c] = 0; mPadSum[r][d][c] = 0.0; mPadSquares[r][d][c] = 0.0; } + } + } return; } @@ -131,8 +133,9 @@ void HmpidEquipment::setPad(int col, int dil, int cha, uint16_t charge) /// @returns the Equipment Id int HmpidEquipment::getEquipmentId(int cru, int link) { - if (cru == mCruId && link == mLinkId) + if (cru == mCruId && link == mLinkId) { return (mEquipmentId); - else + } else { return (-1); + } } diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h index 6decec7a78df3..3f872eeca1d35 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder.h @@ -18,10 +18,10 @@ #define COMMON_HMPIDCODER_H_ #include -#include +#include #include #include -#include +#include #include #include diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index 8f6a0caae7c88..181814b1231c3 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -31,16 +31,16 @@ HmpidCoder::HmpidCoder(int numOfEquipments, bool skipEmptyEvents, bool fixedPack mOccupancyPercentage = 0; mRandomOccupancy = false; mRandomCharge = false; - mOutStream160 = NULL; - mOutStream161 = NULL; + mOutStream160 = nullptr; + mOutStream161 = nullptr; mFileName160 = ""; mFileName161 = ""; mPailoadBufferDimPerEquipment = ((Geo::N_SEGMENTS * (Geo::N_COLXSEGMENT * (Geo::N_DILOGICS * (Geo::N_CHANNELS + 1) + 1) + 1)) + 10); - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { mPacketCounterPerEquipment[i] = 0; - + } mPayloadBufferPtr = (uint32_t*)std::malloc(mNumberOfEquipments * sizeof(uint32_t) * mPailoadBufferDimPerEquipment); mEventBufferBasePtr = (uint32_t*)std::malloc(sizeof(uint32_t) * RAWBLOCKDIMENSION_W); mEventBufferPtr = mEventBufferBasePtr; @@ -61,7 +61,7 @@ HmpidCoder::~HmpidCoder() void HmpidCoder::reset() { - srand((unsigned)time(NULL)); + srand((unsigned)time(nullptr)); mPadsCoded = 0; mPacketsCoded = 0; mDigits.clear(); @@ -127,12 +127,13 @@ void HmpidCoder::codeRandomEvent(uint32_t orbit, uint16_t bc) void HmpidCoder::getEquipCoord(int Equi, uint32_t* CruId, uint32_t* LinkId) { - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { if (mEqIds[i] == Equi) { *CruId = mCruIds[i]; *LinkId = mLinkIds[i]; return; } + } *CruId = mCruIds[0]; *LinkId = mLinkIds[0]; return; @@ -167,8 +168,9 @@ void HmpidCoder::fillTheOutputBuffer(uint32_t* padMap) for (int c = 1; c <= Geo::N_COLXSEGMENT; c++) { // ---- Pre calculate the size of each column - for (int j = 0; j < Geo::N_DILOGICS; j++) + for (int j = 0; j < Geo::N_DILOGICS; j++) { pads[j] = 0; + } rowSize = 0; for (int j = 0; j < Geo::N_DILOGICS; j++) { for (int k = 0; k < Geo::N_CHANNELS; k++) { @@ -225,9 +227,9 @@ void HmpidCoder::writePaginatedEvent(uint32_t orbit, uint16_t bc) for (int eq = 0; eq < mNumberOfEquipments; eq++) { int EventSize = mEventSizePerEquipment[eq]; - if (EventSize == 0) + if (EventSize == 0) { continue; // Skips the Events sized with 0 - + } int EquipmentCounter = 0; int numOfPages = EventSize / PAYLOADMAXSPACE_W + 1; @@ -240,9 +242,9 @@ void HmpidCoder::writePaginatedEvent(uint32_t orbit, uint16_t bc) nWordToRead = count; int nWordsTail = (mFixedPacketLenght) ? PAYLOADDIMENSION_W : ((count / 8 + 1) * 8); - while (count < nWordsTail) + while (count < nWordsTail) { mEventBufferPtr[HEADERDIMENSION_W + count++] = 0; - + } uint32_t PackNum = mPacketCounterPerEquipment[eq]++; int PacketSize = writeHeader(mEventBufferPtr, nWordToRead, nWordsTail, mEqIds[eq], PackNum, bc, orbit, PageNum); savePacket(mFlpIds[eq], PacketSize); @@ -352,8 +354,9 @@ void HmpidCoder::codeEventChunkDigits(std::vector& digits, bool flushVect writePaginatedEvent(orbit, bc); digits.clear(); } else { - if (mLastProcessedDigit >= 0) + if (mLastProcessedDigit >= 0) { digits.erase(digits.begin(), digits.begin() + mLastProcessedDigit); + } } memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event return; @@ -371,13 +374,16 @@ void HmpidCoder::codeTest(int Events, uint16_t charge) orbit++; bc++; charge++; - for (eq = 0; eq < Geo::MAXEQUIPMENTS; eq++) - for (col = 0; col < Geo::N_COLUMNS; col++) - for (dil = 0; dil < Geo::N_DILOGICS; dil++) + for (eq = 0; eq < Geo::MAXEQUIPMENTS; eq++) { + for (col = 0; col < Geo::N_COLUMNS; col++) { + for (dil = 0; dil < Geo::N_DILOGICS; dil++) { for (cha = 0; cha < Geo::N_CHANNELS; cha++) { idx = getEquipmentPadIndex(eq, col, dil, cha); mPadMap[idx] = charge; } + } + } + } fillTheOutputBuffer(mPadMap); writePaginatedEvent(orbit, bc); memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); @@ -389,10 +395,11 @@ void HmpidCoder::codeTest(int Events, uint16_t charge) void HmpidCoder::savePacket(int Flp, int packetSize) { mPacketsCoded++; - if (Flp == 160) + if (Flp == 160) { fwrite(mEventBufferPtr, packetSize, sizeof(uint8_t), mOutStream160); - else + } else { fwrite(mEventBufferPtr, packetSize, sizeof(uint8_t), mOutStream161); + } return; } @@ -404,7 +411,7 @@ void HmpidCoder::openOutputStream(const char* OutputFileName) mOutStream160 = fopen(FileName, "wb"); if (mOutStream160 == 0) { LOG(ERROR) << "ERROR to open Output file " << FileName; - throw 0; + throw nullptr; } mFileName160 = FileName; @@ -412,7 +419,7 @@ void HmpidCoder::openOutputStream(const char* OutputFileName) mOutStream161 = fopen(FileName, "wb"); if (mOutStream161 == 0) { LOG(ERROR) << "ERROR to open Output file " << FileName; - throw 0; + throw nullptr; } mFileName161 = FileName; return; diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 63e2c718067bd..7e1e167610d96 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -1,4 +1,3 @@ -// draft // 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". @@ -123,8 +122,8 @@ void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) avgBusyTime = mDeco->getAverageBusyTime(e); theObj[Geo::N_MODULES]->Fill(); } - for (int m = 0; m < o2::hmpid::Geo::N_MODULES; m++) - for (int y = 0; y < o2::hmpid::Geo::N_YCOLS; y++) + for (int m = 0; m < o2::hmpid::Geo::N_MODULES; m++) { + for (int y = 0; y < o2::hmpid::Geo::N_YCOLS; y++) { for (int x = 0; x < o2::hmpid::Geo::N_XROWS; x++) { xb = x; yb = y; @@ -133,7 +132,8 @@ void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) squareOfCharges = mDeco->getPadSquares(m, x, y); theObj[m]->Fill(); } - + } + } for (int i = 0; i <= Geo::N_MODULES; i++) { theObj[i]->Write(); } diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 73ba3093e6a38..29dcef7150c28 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -1,4 +1,3 @@ -// draft // 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". @@ -67,11 +66,12 @@ void DumpDigitsTask::init(framework::InitContext& ic) mIsOutputOnFile = true; } } - if (mPrintDigits) + if (mPrintDigits) { std::cout << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - if (mIsOutputOnFile) + } + if (mIsOutputOnFile) { mOsFile << "--- HMP Digits : [Chamb,PhoCat,x,y]@(Orbit,BC)=Charge ---" << std::endl; - + } mOrbit = -1; mBc = -1; mDigitsReceived = 0; diff --git a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx index 53279dc476029..2a6baace87860 100644 --- a/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx +++ b/Detectors/HMPID/workflow/src/PedestalsCalculationSpec.cxx @@ -1,4 +1,3 @@ -// draft // 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". @@ -108,8 +107,9 @@ void PedestalsCalculationTask::endOfStream(framework::EndOfStreamContext& ec) char padsFileName[1024]; for (int e = 0; e < Geo::MAXEQUIPMENTS; e++) { - if (mDeco->getAverageEventSize(e) == 0) + if (mDeco->getAverageEventSize(e) == 0) { continue; + } sprintf(padsFileName, "%s_%d.dat", mPedestalsBasePath.c_str(), e); FILE* fpads = fopen(padsFileName, "w"); // TODO: Add controls on the file open @@ -143,9 +143,9 @@ void PedestalsCalculationTask::endOfStream(framework::EndOfStreamContext& ec) } mExTimer.logMes("End Writing the pedestals ! Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); - if (mWriteToDB) + if (mWriteToDB) { recordPedInCcdb(); - + } mExTimer.stop(); return; } @@ -168,12 +168,13 @@ void PedestalsCalculationTask::recordPedInCcdb() } for (int m = 0; m < o2::hmpid::Geo::N_MODULES; m++) { - if (mDeco->getAverageEventSize(m * 2) == 0 && mDeco->getAverageEventSize(m * 2 + 1) == 0) + if (mDeco->getAverageEventSize(m * 2) == 0 && mDeco->getAverageEventSize(m * 2 + 1) == 0) { continue; // If no events skip the chamber + } TMatrixF* pS = (TMatrixF*)aSigmas.At(m); TMatrixF* pP = (TMatrixF*)aPedestals.At(m); - for (int x = 0; x < o2::hmpid::Geo::N_XROWS; x++) + for (int x = 0; x < o2::hmpid::Geo::N_XROWS; x++) { for (int y = 0; y < o2::hmpid::Geo::N_YCOLS; y++) { Samples = (double)mDeco->getPadSamples(m, x, y); @@ -187,24 +188,27 @@ void PedestalsCalculationTask::recordPedInCcdb() (*pS)(x, y) = 0; } } + } } struct timeval tp; - gettimeofday(&tp, NULL); + gettimeofday(&tp, nullptr); uint64_t ms = tp.tv_sec * 1000 + tp.tv_usec / 1000; uint64_t minTimeStamp = ms; uint64_t maxTimeStamp = ms + 1; for (int i = 0; i < Geo::N_MODULES; i++) { - if (mDeco->getAverageEventSize(i * 2) == 0 && mDeco->getAverageEventSize(i * 2 + 1) == 0) + if (mDeco->getAverageEventSize(i * 2) == 0 && mDeco->getAverageEventSize(i * 2 + 1) == 0) { continue; // If no events skip the chamber + } TString filename = TString::Format("HMP/Pedestals/%s/Mean_%d", mPedestalTag.c_str(), i); mDbMetadata.emplace("Tag", mPedestalTag.c_str()); mDBapi.storeAsTFileAny(aPedestals.At(i), filename.Data(), mDbMetadata, minTimeStamp, maxTimeStamp); } for (int i = 0; i < Geo::N_MODULES; i++) { - if (mDeco->getAverageEventSize(i * 2) == 0 && mDeco->getAverageEventSize(i * 2 + 1) == 0) + if (mDeco->getAverageEventSize(i * 2) == 0 && mDeco->getAverageEventSize(i * 2 + 1) == 0) { continue; // If no events skip the chamber + } TString filename = TString::Format("HMP/Pedestals/%s/Sigma_%d", mPedestalTag.c_str(), i); mDbMetadata.emplace("Tag", mPedestalTag.c_str()); mDBapi.storeAsTFileAny(aSigmas.At(i), filename.Data(), mDbMetadata, minTimeStamp, maxTimeStamp); diff --git a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx index 27254ba9c6cae..a66df17c87fe1 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromDigitsSpec.cxx @@ -1,4 +1,3 @@ -// V0.1 // 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". From c80a9ad21c660441598e89476c2b95aecd7d4b13 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Wed, 24 Feb 2021 21:06:30 +0100 Subject: [PATCH 199/208] Fix coding - Wed 24 Feb 2021, 15:21:40 UTC --- Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx | 3 ++- Detectors/HMPID/simulation/src/HmpidCoder.cxx | 4 ++-- Detectors/HMPID/workflow/src/ClusterizerSpec.cxx | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx index 3c4b1aea5dfb2..d6c8896e872a1 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx @@ -98,8 +98,9 @@ void HmpidEquipment::resetPadMap() /// Resets the decoding errors statistics void HmpidEquipment::resetErrors() { - for (int i = 0; i < MAXERRORS; i++) + for (int i = 0; i < MAXERRORS; i++) { mErrors[i] = 0; + } return; } diff --git a/Detectors/HMPID/simulation/src/HmpidCoder.cxx b/Detectors/HMPID/simulation/src/HmpidCoder.cxx index 181814b1231c3..676fea54b93d9 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder.cxx @@ -409,7 +409,7 @@ void HmpidCoder::openOutputStream(const char* OutputFileName) char FileName[512]; sprintf(FileName, "%s%d%s", OutputFileName, 160, ".dat"); mOutStream160 = fopen(FileName, "wb"); - if (mOutStream160 == 0) { + if (mOutStream160 == nullptr) { LOG(ERROR) << "ERROR to open Output file " << FileName; throw nullptr; } @@ -417,7 +417,7 @@ void HmpidCoder::openOutputStream(const char* OutputFileName) sprintf(FileName, "%s%d%s", OutputFileName, 161, ".dat"); mOutStream161 = fopen(FileName, "wb"); - if (mOutStream161 == 0) { + if (mOutStream161 == nullptr) { LOG(ERROR) << "ERROR to open Output file " << FileName; throw nullptr; } diff --git a/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx b/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx index 3e39b04b16cba..4ff75082477a8 100644 --- a/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx +++ b/Detectors/HMPID/workflow/src/ClusterizerSpec.cxx @@ -95,9 +95,9 @@ o2::framework::DataProcessorSpec getHMPIDClusterizerSpec(bool useMC) { std::vector inputs; inputs.emplace_back("hmpiddigits", "HMP", "DIGITS", 0, Lifetime::Timeframe); - if (useMC) + if (useMC) { inputs.emplace_back("hmpiddigitlabels", "HMP", "DIGITSMCTR", 0, Lifetime::Timeframe); - + } return DataProcessorSpec{ "HMPClusterer", inputs, From c7dcb0ded956e3b04cbe9305601561abd458f091 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Mon, 1 Mar 2021 17:09:48 +0100 Subject: [PATCH 200/208] Add the Write Raw from Root Digits --- .../HMPID/base/include/HMPIDBase/Digit.h | 16 +- Detectors/HMPID/base/src/Digit.cxx | 20 +- .../HMPID/reconstruction/src/HmpidDecoder.cxx | 53 ++-- Detectors/HMPID/simulation/CMakeLists.txt | 6 +- .../include/HMPIDSimulation/HmpidCoder2.h | 121 ++++++++ .../HMPID/simulation/src/HMPIDDigitizer.cxx | 8 +- .../simulation/src/HMPIDSimulationLinkDef.h | 1 + .../HMPID/simulation/src/HmpidCoder2.cxx | 258 ++++++++++++++++++ Detectors/HMPID/workflow/CMakeLists.txt | 6 + Detectors/HMPID/workflow/README.md | 32 +++ .../HMPIDWorkflow/WriteRawFromRootSpec.h | 59 ++++ .../HMPID/workflow/src/DataDecoderSpec.cxx | 11 +- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 4 +- .../workflow/src/WriteRawFromRootSpec.cxx | 179 ++++++++++++ .../src/write-raw-from-root-workflow.cxx | 51 ++++ .../src/write-root-from-digits-workflow.cxx | 6 +- 16 files changed, 796 insertions(+), 35 deletions(-) create mode 100644 Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h create mode 100644 Detectors/HMPID/simulation/src/HmpidCoder2.cxx create mode 100644 Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h create mode 100644 Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx create mode 100644 Detectors/HMPID/workflow/src/write-raw-from-root-workflow.cxx diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index e30fe18e30fa2..7fcf96a8e4527 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -50,7 +50,7 @@ class Digit static void Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int* Module, int* x, int* y); // Trigger time Conversion Functions - static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) || BC); }; + static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) | (0x0FFF & BC)); }; static inline uint32_t EventIdToOrbit(uint64_t EventId) { return (EventId >> 12); }; static inline uint16_t EventIdToBc(uint64_t EventId) { return (EventId & 0x0FFF); }; static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC); @@ -80,10 +80,10 @@ class Digit public: Digit() = default; - Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad){}; + Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge); Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge); - Digit(uint16_t bc, uint32_t orbit, uint16_t, int equipment, int column, int dilogic, int channel); - Digit(uint16_t bc, uint32_t orbit, uint16_t, int module, int x, int y); + Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int column, int dilogic, int channel); + Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, int y); // Getter & Setters uint16_t getCharge() const { return mQ; } @@ -133,7 +133,13 @@ class Digit // Charge management functions static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); static float getFractionalContributionForPad(HitType const& hit, int somepad); - void addCharge(float q) { mQ += q; } + void addCharge(float q) + { + mQ += q; + if (mQ > 0x0FFF) { + mQ = 0x0FFF; + } + } void subCharge(float q) { mQ -= q; } private: diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 3c6d6ceba6416..994ee07e30e99 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -30,6 +30,20 @@ using namespace o2::hmpid; ClassImp(o2::hmpid::Digit); // ============= Digit Class implementation ======= +/// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC) +/// The mapping of the digit is in the Photo Cathod coords +/// (Chamber, PhotoCathod, X, Y) +/// @param[in] bc : the bunch crossing [0 .. 2^12-1] +/// @param[in] orbit : the orbit number [0 .. 2^32-1] +/// @param[in] pad : the Digit Unique Id [0x00CPXXYY] +/// @param[in] charge : the value of the charge [0 .. 2^12-1] +Digit::Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) +{ + mBc = bc; + mOrbit = orbit; + mQ = charge > 0x0FFF ? 0x0FFF : charge; + mPad = pad; +} /// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC) /// The mapping of the digit is in the Photo Cathod coords @@ -45,7 +59,7 @@ Digit::Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, { mBc = bc; mOrbit = orbit; - mQ = charge; + mQ = charge > 0x0FFF ? 0x0FFF : charge; mPad = Abs(chamber, photo, x, y); } @@ -63,7 +77,7 @@ Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int co { mBc = bc; mOrbit = orbit; - mQ = charge; + mQ = charge > 0x0FFF ? 0x0FFF : charge; mPad = Equipment2Pad(equipment, column, dilogic, channel); } @@ -80,7 +94,7 @@ Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, in { mBc = bc; mOrbit = orbit; - mQ = charge; + mQ = charge > 0x0FFF ? 0x0FFF : charge; mPad = Absolute2Pad(module, x, y); } diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index b2df8dded8028..e0328b632da96 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -12,7 +12,7 @@ /// \file HmpidDecoder.cxx /// \author Antonio Franco - INFN Bari /// \brief Base Class to decode HMPID Raw Data stream -/// \version 1.0 +/// \version 1.1 /// \date 17/11/2020 /* ------ HISTORY --------- @@ -84,7 +84,7 @@ HmpidDecoder::~HmpidDecoder() } } -/// Resets to 0 all the class members +/// Init all the members variables. void HmpidDecoder::init() { mRDHAcceptedVersion = 6; @@ -182,7 +182,7 @@ int HmpidDecoder::getEquipmentID(int CruId, int LinkId) /// @returns Type of Word : the type of word [0..4] (0 := undetect) int HmpidDecoder::checkType(uint32_t wp, int* p1, int* p2, int* p3, int* p4) { - if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 || (wp & 0x0800ffff) == 0x080010A0) { + if ((wp & 0x0000ffff) == 0x000036A8 || (wp & 0x0000ffff) == 0x000032A8 || (wp & 0x0000ffff) == 0x000030A0 || (wp & 0x0800ffff) == 0x080010A0) { *p2 = (wp & 0x03ff0000) >> 16; // Number of words of row *p1 = wp & 0x0000ffff; return (WTYPE_ROW); @@ -252,7 +252,6 @@ bool HmpidDecoder::isSegmentMarker(uint32_t wp, int* Err, int* segSize, int* Seg *segSize = (wp & 0x000fff00) >> 8; // # Number of words of Segment *mark = (wp & 0xfff00000) >> 20; *Seg = wp & 0x0000000F; - if (*Seg > 3 || *Seg < 1) { LOG(INFO) << " Wrong segment Marker Word, bad Number of segment" << *Seg << "!"; *Err = true; @@ -275,19 +274,27 @@ bool HmpidDecoder::isSegmentMarker(uint32_t wp, int* Err, int* segSize, int* Seg bool HmpidDecoder::isPadWord(uint32_t wp, int* Err, int* Col, int* Dilogic, int* Channel, int* Charge) { *Err = false; - if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 || (wp & 0x0800ffff) == 0x080010A0 || (wp & 0x08000000) != 0) { // # ! this is a pad + // if ((wp & 0x08000000) != 0) { + if ((wp & 0x08000000) != 0) { return (false); + } + *Col = (wp & 0x07c00000) >> 22; + *Dilogic = (wp & 0x003C0000) >> 18; + *Channel = (wp & 0x0003F000) >> 12; + *Charge = (wp & 0x00000FFF); + + if ((wp & 0x0ffff) == 0x036A8 || (wp & 0x0ffff) == 0x032A8 || (wp & 0x0ffff) == 0x030A0 || (wp & 0x0ffff) == 0x010A0) { // # ! this is a pad + if (*Dilogic > 10 || *Channel > 47 || *Dilogic < 1 || *Col > 24 || *Col < 1) { + return (false); + } } else { - *Col = (wp & 0x07c00000) >> 22; - *Dilogic = (wp & 0x003C0000) >> 18; - *Channel = (wp & 0x0003F000) >> 12; - *Charge = (wp & 0x00000FFF); if (*Dilogic > 10 || *Channel > 47 || *Dilogic < 1 || *Col > 24 || *Col < 1) { - LOG(WARNING) << " Wrong Pad values Col=" << *Col << " Dilogic=" << *Dilogic << " Channel=" << *Channel << " Charge=" << *Charge; + // LOG(WARNING) << " Wrong Pad values Col=" << *Col << " Dilogic=" << *Dilogic << " Channel=" << *Channel << " Charge=" << *Charge << " wp:0x" << std::hex << wp << std::dec; *Err = true; + return (false); } - return (true); } + return (true); } /// Checks if is a EoE Marker and extracts the Column, Dilogic and the size @@ -434,7 +441,7 @@ void HmpidDecoder::updateStatistics(HmpidEquipment* eq) eq->mTotalPads += eq->mSampleNumber; eq->mTotalErrors += eq->mErrorsCounter; - // std::cout << ">>>>.. end >>> "<mNumberOfEvents<<" :" <mEventSize<<","<< eq->mEventSizeAverage<< ", "<mEventNumber<<" "<>>updateStatistics() >>> "<< eq->getEquipmentId() << "="<< eq->mNumberOfEvents<<" :" << eq->mEventSize <<","<< eq->mTotalPads << ", " << eq->mSampleNumber << std::endl; return; } @@ -468,6 +475,11 @@ HmpidEquipment* HmpidDecoder::evaluateHeaderContents(int EquipmentIndex) return (eq); } +/// --------------- Decode One Page from Data Buffer --------------- +/// Read the stream, decode the contents and store resuls. +/// ATTENTION : Assumes that the input stream was set +/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header +/// @param[in] streamBuf : the pointer to the Pointer of the Stream Buffer void HmpidDecoder::decodePage(uint32_t** streamBuf) { int equipmentIndex; @@ -502,7 +514,6 @@ void HmpidDecoder::decodePage(uint32_t** streamBuf) if (!getWordFromStream(&wp)) { // end the stream break; } - type = checkType(wp, &p1, &p2, &p3, &p4); if (type == WTYPE_NONE) { if (eq->mWillBePad == true) { // try to recover the first pad ! @@ -520,7 +531,9 @@ void HmpidDecoder::decodePage(uint32_t** streamBuf) continue; } } - + if (mEquipment == 8) { + LOG(INFO) << "Event" << eq->mEventNumber << " >" << std::hex << wp << std::dec << "<" << type; + } if (eq->mWillBeRowMarker == true) { // #shoud be a Row Marker if (type == WTYPE_ROW) { eq->mColumnCounter++; @@ -601,6 +614,9 @@ void HmpidDecoder::decodePage(uint32_t** streamBuf) } } else { setPad(eq, p1 - 1, p2 - 1, p3, p4); + if (mEquipment == 8) { + LOG(INFO) << "Event" << eq->mEventNumber << " >" << p1 - 1 << "," << p2 - 1 << "," << p3 << "," << p4; + } eq->mWordsPerDilogicCounter++; eq->mSampleNumber++; if (p3 == 47) { @@ -760,6 +776,11 @@ bool HmpidDecoder::decodeBuffer() return (true); } +/// --------- Decode One Page from Data Buffer with Fast Decoding -------- +/// Read the stream, decode the contents and store resuls. +/// ATTENTION : Assumes that the input stream was set +/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header +/// @param[in] streamBuf : the pointer to the Pointer of the Stream Buffer void HmpidDecoder::decodePageFast(uint32_t** streamBuf) { int equipmentIndex; @@ -776,15 +797,12 @@ void HmpidDecoder::decodePageFast(uint32_t** streamBuf) LOG(INFO) << "Failed to decode the Header !"; throw TH_WRONGHEADER; } - HmpidEquipment* eq = evaluateHeaderContents(equipmentIndex); - uint32_t wpprev = 0; uint32_t wp = 0; int newOne = true; int Column, Dilogic, Channel, Charge; int pwer; - int payIndex = 0; while (payIndex < mNumberWordToRead) { //start the payload loop word by word wpprev = wp; @@ -820,7 +838,6 @@ bool HmpidDecoder::decodeBufferFast() mTheEquipments[i]->init(); mTheEquipments[i]->resetPadMap(); } - uint32_t* streamBuf; LOG(INFO) << "Enter FAST decoding !"; diff --git a/Detectors/HMPID/simulation/CMakeLists.txt b/Detectors/HMPID/simulation/CMakeLists.txt index 639816aa14992..181cb2ad1d2ed 100644 --- a/Detectors/HMPID/simulation/CMakeLists.txt +++ b/Detectors/HMPID/simulation/CMakeLists.txt @@ -10,11 +10,15 @@ o2_add_library(HMPIDSimulation SOURCES src/Detector.cxx src/HMPIDDigitizer.cxx src/HmpidCoder.cxx - PUBLIC_LINK_LIBRARIES O2::HMPIDBase) + SOURCES src/HmpidCoder2.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDBase + O2::DetectorsRaw + ROOT::Physics) o2_target_root_dictionary(HMPIDSimulation HEADERS include/HMPIDSimulation/Detector.h include/HMPIDSimulation/HmpidCoder.h + include/HMPIDSimulation/HmpidCoder2.h include/HMPIDSimulation/HMPIDDigitizer.h) diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h new file mode 100644 index 0000000000000..18709d726cc49 --- /dev/null +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h @@ -0,0 +1,121 @@ +// 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 HmpidCoder.h +/// \author Antonio Franco - INFN Bari +/// \brief Base Class to code HMPID Raw Data file +/// + +#ifndef COMMON_HMPIDCODER2_H_ +#define COMMON_HMPIDCODER2_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include "Headers/RAWDataHeader.h" +#include "CommonDataFormat/InteractionRecord.h" +#include "DetectorsRaw/HBFUtils.h" +#include "DetectorsRaw/RawFileWriter.h" + +#include "FairLogger.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDBase/Digit.h" + +// ---- RDH 6 standard dimension ------- +#define RAWBLOCKDIMENSION_W 2048 +#define HEADERDIMENSION_W 16 +#define PAYLOADDIMENSION_W 2032 +#define PAYLOADMAXSPACE_W 2028 + +// ---- CHARGE CONSTANTS ----- +#define CHARGE_CONST 150 +#define CHARGE_RAND_MAX 400 + +using namespace o2::raw; + +namespace o2 +{ + +namespace hmpid +{ + +class HmpidCoder2 +{ + public: + int mVerbose; + int mNumberOfEquipments; + + RawFileWriter mWriter{"HMP", false}; + + private: + // The standard definition of HMPID equipments at P2 + const int mEqIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13}; + const int mCruIds[Geo::MAXEQUIPMENTS] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3}; + const int mLinkIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2}; + const int mFlpIds[Geo::MAXEQUIPMENTS] = {160, 160, 160, 160, 160, 160, 160, 160, 161, 161, 161, 161, 161, 161}; + + char mFileName160[512]; + char mFileName161[512]; + uint32_t* mPayloadBufferPtr; + int mEventSizePerEquipment[Geo::MAXEQUIPMENTS]; + int mEventPadsPerEquipment[Geo::MAXEQUIPMENTS]; + int mPailoadBufferDimPerEquipment; + uint32_t* mPadMap; + long mPadsCoded; + bool mSkipEmptyEvents; + + public: + HmpidCoder2(int numOfEquipments); + virtual ~HmpidCoder2(); + + void setVerbosity(int Level) + { + mVerbose = Level; + }; + int getVerbosity() + { + return (mVerbose); + }; + int getNumberOfEquipments() + { + return (mNumberOfEquipments); + }; + void setSkipEmptyEvents(bool Skip) + { + mSkipEmptyEvents = Skip; + } + bool getSkipEmptyEvents() + { + return (mSkipEmptyEvents); + } + + void openOutputStream(const char* OutputFileName, bool perFlpFile = false); + void closeOutputStream(); + + void codeEventChunkDigits(std::vector& digits); + void dumpResults(); + + private: + void getEquipCoord(int Equi, uint32_t* CruId, uint32_t* LinkId); + int getEquipmentPadIndex(int eq, int col, int dil, int cha); + void fillTheOutputBuffer(uint32_t* padMap); + void writePaginatedEvent(uint32_t orbit, uint16_t bc); +}; + +} // namespace hmpid +} // namespace o2 + +#endif /* COMMON_HMPIDCODER_H_ */ diff --git a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx index facfdb488a5f3..0b8e04fc52a6b 100644 --- a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx +++ b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx @@ -31,12 +31,14 @@ void HMPIDDigitizer::zeroSuppress(std::vector const& digits, s int index = 0; for (auto& digit : digits) { if (digit.getCharge() >= getThreshold(digit)) { + // if(digit.getPx() < 80 && digit.getPy() < 48) { newdigits.push_back(digit); if (newlabels) { // copy the labels to the new place with the right new index newlabels->addElements(newdigits.size() - 1, labels.getLabels(index)); } + // } } index++; } @@ -75,11 +77,15 @@ void HMPIDDigitizer::process(std::vector const& hits, std::v int counter = 0; for (int nx = -1; nx <= 1; ++nx) { for (int ny = -1; ny <= 1; ++ny) { + if ((px + nx) < 0 || (px + nx) > 79 || (py + ny) < 0 || (py + ny) > 47) { + LOG(INFO) << ">> Pad out the PhotoCathod boundary. Excluded :" << px << " " << py << " :" << nx << "," << ny; + continue; + } allpads[counter] = Param::Abs(chamber, pc, px + nx, py + ny); counter++; } } - + // LOG(INFO) << "." << px << " " << py ; for (auto& pad : allpads) { auto iter = mIndexForPad.find(pad); int index = -1; diff --git a/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h b/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h index 5367c5bcb20e1..866728f3baad5 100644 --- a/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h +++ b/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h @@ -18,5 +18,6 @@ #pragma link C++ class o2::base::DetImpl < o2::hmpid::Detector> + ; #pragma link C++ class o2::hmpid::HMPIDDigitizer + ; #pragma link C++ class o2::hmpid::HmpidCoder + ; +#pragma link C++ class o2::hmpid::HmpidCoder2 + ; #endif diff --git a/Detectors/HMPID/simulation/src/HmpidCoder2.cxx b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx new file mode 100644 index 0000000000000..1a8c08e6afc46 --- /dev/null +++ b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx @@ -0,0 +1,258 @@ +// 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 HmpidCoder.cxx +/// \author Antonio Franco - INFN Bari +/// \brief Base Class for coding HMPID Raw Data File +/// \version 1.0 +/// \date 24 feb 2021 + +#include + +#include "Headers/RAWDataHeader.h" +#include "CommonDataFormat/InteractionRecord.h" +#include "DetectorsRaw/HBFUtils.h" +#include "DetectorsRaw/RawFileWriter.h" + +#include "HMPIDBase/Digit.h" +#include "HMPIDSimulation/HmpidCoder2.h" + +using namespace o2::raw; +using namespace o2::hmpid; +using namespace o2::header; + +/// HMPID Raw Coder Constructor +/// @param[in] numOfEquipments : number of Equipments +HmpidCoder2::HmpidCoder2(int numOfEquipments) +{ + mPadsCoded = 0; + mNumberOfEquipments = numOfEquipments; + mVerbose = 0; + mSkipEmptyEvents = true; + mPailoadBufferDimPerEquipment = ((Geo::N_SEGMENTS * (Geo::N_COLXSEGMENT * (Geo::N_DILOGICS * (Geo::N_CHANNELS + 1) + 1) + 1)) + 10); + mPayloadBufferPtr = (uint32_t*)std::malloc(mNumberOfEquipments * sizeof(uint32_t) * mPailoadBufferDimPerEquipment); + mPadMap = (uint32_t*)std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); + // TODO: Add memory allocation error check + +} + +/// HMPID Raw Coder +HmpidCoder2::~HmpidCoder2() +{ + // TODO Auto-generated destructor stub + std::free(mPayloadBufferPtr); + std::free(mPadMap); +} + +/// getEquipCoord() : converts the EquipmentID in CRU,Link couple +/// @param[in] Equi : the HMPID Equipment ID [0..13] +/// @param[out] CruId : the FLP CRU number [0..3] +/// @param[ou] LinkId : the FLP Linkk number [0..3] +void HmpidCoder2::getEquipCoord(int Equi, uint32_t* CruId, uint32_t* LinkId) +{ + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { + if (mEqIds[i] == Equi) { + *CruId = mCruIds[i]; + *LinkId = mLinkIds[i]; + return; + } + } + *CruId = mCruIds[0]; + *LinkId = mLinkIds[0]; + return; +} + +/// constexpr to accelerate the coordinates changing +constexpr int p1() { return (Geo::N_SEGMENTS * Geo::N_COLXSEGMENT * Geo::N_DILOGICS * Geo::N_CHANNELS); } +constexpr int p2() { return (Geo::N_DILOGICS * Geo::N_CHANNELS); } + +/// getEquipmentPadIndex() : converts the (Equipment, Column, Dilogic, Channel) +/// coordinate into a unique PadIndex value used to address the PADs array +/// @param[in] eq : the HMPID Equipment ID [0..13] +/// @param[in] col : the Equipment Column [0..23] +/// @param[in] dil : the Dilogic [0..9] +/// @param[in] cha : the Channel [0..47] +/// @returns The PAD index value [0..161279] +int HmpidCoder2::getEquipmentPadIndex(int eq, int col, int dil, int cha) +{ + return (eq * p1() + col * p2() + dil * Geo::N_CHANNELS + cha); +} + +/// Scans the PADs array and fill the Output buffer with the RawFile structure +/// a two step algorithm... +/// @param[in] padMap : poiter to the PADs map array +void HmpidCoder2::fillTheOutputBuffer(uint32_t* padMap) +{ + uint32_t rowMarker, segMarker, eoeMarker, padWord; + uint32_t rowSize; + uint32_t ptr = 0; + int pads[Geo::MAXEQUIPMENTS]; + int padsCount; + int segSize; + + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { + mEventSizePerEquipment[i] = 0; + } + + for (int eq = 0; eq < mNumberOfEquipments; eq++) { + int startPtr = ptr; + padsCount = 0; + for (int s = 1; s <= Geo::N_SEGMENTS; s++) { + segSize = 0; + for (int c = 1; c <= Geo::N_COLXSEGMENT; c++) { + // ---- Pre-calculate the size of each column + for (int j = 0; j < Geo::N_DILOGICS; j++) { + pads[j] = 0; + } + rowSize = 0; + for (int j = 0; j < Geo::N_DILOGICS; j++) { + for (int k = 0; k < Geo::N_CHANNELS; k++) { + int idx = getEquipmentPadIndex(eq, ((s - 1) * Geo::N_COLXSEGMENT + (c - 1)), j, k); + if (padMap[idx] > 0) { + pads[j]++; + rowSize++; + padsCount++; + } + } + } + rowSize += Geo::N_DILOGICS; + segSize += (rowSize + 1); + rowMarker = 0x000036A8 | ((rowSize << 16) & 0x03ff0000); + + // ---- fills the Payload Buffer + mPayloadBufferPtr[ptr++] = rowMarker; + int col = (s - 1) * Geo::N_COLXSEGMENT + c; + for (int d = 1; d <= Geo::N_DILOGICS; d++) { + for (int p = 0; p < Geo::N_CHANNELS; p++) { + int idx = getEquipmentPadIndex(eq, ((s - 1) * Geo::N_COLXSEGMENT + (c - 1)), (d - 1), p); + if (padMap[idx] > 0) { + padWord = ((col << 22) & 0x07c00000) | ((d << 18) & 0x003C0000) | ((p << 12) & 0x0003F000) | (padMap[idx] & 0x00000FFF); + mPayloadBufferPtr[ptr++] = padWord; + } + } + eoeMarker = 0x08000080 | ((col << 22) & 0x07c00000) | (d << 18 & 0x003C0000) | (pads[d - 1] & 0x0000007F); + mPayloadBufferPtr[ptr++] = eoeMarker; + } + } + segSize += 1; + segMarker = 0xAB000000 | ((segSize << 8) & 0x000fff00) | (s & 0x0000000F); + mPayloadBufferPtr[ptr++] = segMarker; + } + mPadsCoded += padsCount; + mEventPadsPerEquipment[eq] = padsCount; + mEventSizePerEquipment[eq] = ptr - startPtr; + } + return; +} + +/// Add a chunk of data in the Output buffer to the RawWriter +/// setting the CRU,Link coordinates and the Trigger Info +/// One or more Pages will be created for each equipment +/// +/// @param[in] orbit : the Trigger ORBIT value +/// @param[in] bc : the Trigger BC value +void HmpidCoder2::writePaginatedEvent(uint32_t orbit, uint16_t bc) +{ + uint32_t* ptrStartEquipment = mPayloadBufferPtr; + for (int eq = 0; eq < mNumberOfEquipments; eq++) { + int EventSize = mEventSizePerEquipment[eq]; + LOG(DEBUG) << "writePaginatedEvent() Eq=" << eq << " Size:" << EventSize << " Pads:" << mEventPadsPerEquipment[eq] << " Orbit:" << orbit << " BC:" << bc; + if (EventSize == 0 && mSkipEmptyEvents) { + continue; // Skips the Events sized with 0 + } + mWriter.addData(mEqIds[eq], mCruIds[eq], mLinkIds[eq], 0, {bc, orbit}, gsl::span(reinterpret_cast(ptrStartEquipment), EventSize * sizeof(uint32_t))); + ptrStartEquipment += EventSize; + } + return; +} + +/// Analyze a Digits Vector and setup the PADs array +/// with the charge value, then fills the output buffer +/// and forward it to the RawWriter object +/// +/// NOTE: this version take the Trigger info from the first +/// digit in the vector. We ASSUME that the vector contains +/// one and only one event !!!! +/// @param[in] digits : the vector of Digit structures +void HmpidCoder2::codeEventChunkDigits(std::vector& digits) +{ + int eq, col, dil, cha, mo, x, y, idx; + uint32_t orbit = 0; + uint16_t bc = 0; + + int padsCount = 0; + if(digits.size() == 0) return; // the vector is empty ! + + orbit = digits[0].getOrbit(); + bc = digits[0].getBC(); + LOG(INFO) << "Manage chunk Orbit :" << orbit << " BC:" << bc; + for (o2::hmpid::Digit d : digits) { + Digit::Pad2Equipment(d.getPadID(), &eq, &col, &dil, &cha); // From Digit to Hardware coords + eq = mEqIds[eq]; // converts the Equipment Id in Cru/Link position ref + idx = getEquipmentPadIndex(eq, col, dil, cha); // finally to the unique padmap index + if (mPadMap[idx] != 0) { // We already have the pad set + std::cerr << "HmpidCoder [ERROR] : Duplicated DIGIT =" << d << " (" << eq << "," << col << "," << dil << "," << cha << ")" << std::endl; + } else { + mPadMap[idx] = d.getCharge(); + padsCount++; + } + } + fillTheOutputBuffer(mPadMap); // Fill the Buffer for all Equipments per Event + writePaginatedEvent(orbit, bc); + memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event + return; +} + +/// Create the Raw File/Files for the output. +/// Also registers the links in the RawWriter object +/// +/// @param[in] OutputFileName : the Path/Prefix name for the raw files +/// @param[in] perFlpFile : if true a couple of files will be created, one for each +/// HMPID FLPs +void HmpidCoder2::openOutputStream(const char* OutputFileName, bool perFlpFile) +{ + if (perFlpFile) { + sprintf(mFileName160, "%s_%d%s", OutputFileName, 160, ".raw"); + sprintf(mFileName161, "%s_%d%s", OutputFileName, 161, ".raw"); + } else { + sprintf(mFileName160, "%s%s", OutputFileName, ".raw"); + sprintf(mFileName161, "%s%s", OutputFileName, ".raw"); + } + RAWDataHeader rdh; // by default, v6 is used currently. + for (int eq = 0; eq < mNumberOfEquipments; eq++) { + rdh.feeId = mEqIds[eq]; + rdh.cruID = mCruIds[eq]; + rdh.linkID = mLinkIds[eq]; + rdh.endPointID = 0; + if(mFlpIds[eq] == 160) { + mWriter.registerLink(rdh, mFileName160); + } else { + mWriter.registerLink(rdh, mFileName161); + } + } + return; +} + +/// Close and flush the output streams. +void HmpidCoder2::closeOutputStream() +{ + mWriter.close(); + return; +} + +/// Dumps the results of the last coding +void HmpidCoder2::dumpResults() +{ + std::cout << " **** HMPID RawFile Coder : results ****" << std::endl; + std::cout << " Created files : " << mFileName160 << " ," << mFileName161 << std::endl; + std::cout << " Number of Pads coded : " << mPadsCoded << std::endl; + std::cout << " ----------------------------------------" << std::endl; +} diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index d71773ee8c3aa..1c171fbef864d 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -15,6 +15,7 @@ o2_add_library(HMPIDWorkflow src/DumpDigitsSpec.cxx src/ReadRawFileSpec.cxx src/WriteRawFromDigitsSpec.cxx + src/WriteRawFromRootSpec.cxx src/PedestalsCalculationSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::CCDB @@ -58,4 +59,9 @@ o2_add_executable(raw-to-pedestals-workflow COMPONENT_NAME hmpid SOURCES src/raw-to-pedestals-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) + +o2_add_executable(write-raw-from-root-workflow + COMPONENT_NAME hmpid + SOURCES src/write-raw-from-root-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) \ No newline at end of file diff --git a/Detectors/HMPID/workflow/README.md b/Detectors/HMPID/workflow/README.md index ce60e40341411..82cee2b72db44 100644 --- a/Detectors/HMPID/workflow/README.md +++ b/Detectors/HMPID/workflow/README.md @@ -114,6 +114,38 @@ Example [O2Suite/latest-o2] ~/Downloads/provaRec $> o2-hmpid-read-raw-file-workflow --raw-file test_full_flp1.raw -b | o2-hmpid-raw-to-digits-workflow -b | o2-hmpid-write-root-from-digits-workflow -b ``` +### o2-hmpid-write-raw-from-root-workflow +Write raw files with the digits information contained in a root file + +``` +o2-hmpid-write-raw-from-root-workflow +``` + +Data processor options: HMP-WriteRawFromRootFile: + +``` + --out-file arg (=hmpidRaw) prefix name of the output raw file + --in-file arg (=simulation.root) name of the input sim root file + --per-flp-file produce one raw file per FLPs (suffix 160 and 161) + --dump-digits out the digits in a ASCII file named /tmp/hmpDumpDigits.dat + --skip-empty skip empty events (not yet implemented) +``` + +Example + +``` +[O2Suite/latest-o2] ~/Downloads/provaRec $>o2-sim-serial -m HMP -n 20 -e TGeant4 -g pythia8hi +[O2Suite/latest-o2] ~/Downloads/provaRec $>o2-sim-digitizer-workflow --onlyDet HMP +[O2Suite/latest-o2] ~/Downloads/provaRec $>o2-hmpid-write-raw-from-root-workflow --in-file hmpiddigits.root --out-file hmpRawFromRoot --dump-digits -b +``` + +in order to verify the write, the inverse decoding of raw file + +``` +[O2Suite/latest-o2] ~/Downloads/provaRec $>o2-hmpid-read-raw-file-workflow --raw-file hmpRawFromRoot.raw -b | o2-hmpid-raw-to-digits-workflow -b | o2-hmpid-dump-digits-workflow --out-file /tmp/hmpDumpDigitsVerify.dat +``` + + ### o2-hmpid-raw-to-pedestals-workflow Write the Pedestals/Threshold files for the readout and registers Mean and Sigma in the CCDB diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h new file mode 100644 index 0000000000000..03e8bd3282e5b --- /dev/null +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h @@ -0,0 +1,59 @@ +// 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. + +#ifndef DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMROOT_H_ +#define DETECTORS_HMPID_WORKFLOW_INCLUDE_HMPIDWORKFLOW_WRITERAWFROMROOT_H_ + +#include +#include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" +#include "DetectorsRaw/HBFUtils.h" +#include "DetectorsRaw/RawFileWriter.h" + +#include "HMPIDBase/Common.h" +#include "HMPIDBase/Digit.h" +#include "HMPIDSimulation/HmpidCoder2.h" + +namespace o2 +{ +namespace hmpid +{ + +class WriteRawFromRootTask : public framework::Task +{ + public: + WriteRawFromRootTask() = default; + ~WriteRawFromRootTask() override = default; + void init(framework::InitContext& ic) final; + void run(framework::ProcessingContext& pc) final; + void endOfStream(framework::EndOfStreamContext& ec) override; + + private: + void readRootFile(); + std::string mBaseFileName = ""; + std::string mBaseRootFileName = ""; + bool mSkipEmpty = false; + bool mDumpDigits = false; + bool mPerFlpFile = false; + + std::vector mDigits; + long mDigitsReceived; + int mEventsReceived; + HmpidCoder2* mCod; + ExecutionTimer mExTimer; + TTree* mDigTree; +}; + +o2::framework::DataProcessorSpec getWriteRawFromRootSpec(std::string inputSpec = "HMP/DIGITS"); + +} // end namespace hmpid +} // end namespace o2 + +#endif diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 7e1e167610d96..02a8142ad4b46 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -113,10 +113,17 @@ void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) theObj[Geo::N_MODULES]->Branch("Average_Event_Size", &avgEventSize, "F"); theObj[Geo::N_MODULES]->Branch("Average_Busy_Time", &avgBusyTime, "F"); + // Update the Stat for the Decoding + int numEqui = mDeco->getNumberOfEquipments(); + // cycle in order to update info for the last event + for (int i = 0; i < numEqui; i++) { + if (mDeco->mTheEquipments[i]->mNumberOfEvents > 0) { + mDeco->updateStatistics(mDeco->mTheEquipments[i]); + } + } char summaryFileName[254]; sprintf(summaryFileName, "%s_stat.txt", mRootStatFile.c_str()); mDeco->writeSummaryFile(summaryFileName); - int numEqui = mDeco->getNumberOfEquipments(); for (int e = 0; e < numEqui; e++) { avgEventSize = mDeco->getAverageEventSize(e); avgBusyTime = mDeco->getAverageBusyTime(e); @@ -161,7 +168,7 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) mTotalFrames++; pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); // mTotalDigits += mDeco->mDigits.size(); - LOG(DEBUG) << "Writing " << mDeco->mDigits.size() << "/" << mTotalDigits << " Digits ..."; + //LOG(INFO) << "Writing " << mDeco->mDigits.size() << "/" << mTotalDigits << " Digits ..."; } return; } diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 29dcef7150c28..5de9d2a74b2c9 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -98,12 +98,12 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) if (Dig.getOrbit() != mOrbit || Dig.getBC() != mBc) { mOrbit = Dig.getOrbit(); mBc = Dig.getBC(); - LOG(INFO) << "Event :" << mOrbit << " / " << mBc; + // LOG(INFO) << "Event :" << mOrbit << " / " << mBc; } } } } - mExTimer.elapseMes("... Dumping... Digits received = " + std::to_string(mDigitsReceived)); + mExTimer.elapseMes("... Dumping Digits received = " + std::to_string(mDigitsReceived)); return; } diff --git a/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx new file mode 100644 index 0000000000000..a02931c8dc005 --- /dev/null +++ b/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx @@ -0,0 +1,179 @@ +// 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 WriteRawFromDigitsSpec.cxx +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 01 feb 2021 +/// \brief Implementation of a data processor to produce raw files from a Digits stream +/// + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Framework/CallbackService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/ControlService.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Lifetime.h" +#include "Framework/Output.h" +#include "Framework/Task.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Logger.h" +#include "Framework/InputRecordWalker.h" + +#include "TFile.h" +#include "TTree.h" + + +#include "Headers/RAWDataHeader.h" +#include "DetectorsRaw/RDHUtils.h" +#include "DPLUtils/DPLRawParser.h" + +#include "HMPIDBase/Digit.h" +#include "HMPIDBase/Geo.h" +#include "HMPIDSimulation/HmpidCoder2.h" +#include "HMPIDWorkflow/WriteRawFromRootSpec.h" + +namespace o2 +{ +namespace hmpid +{ + +using namespace o2; +using namespace o2::framework; +using RDH = o2::header::RDHAny; + +//======================= +// Data decoder +void WriteRawFromRootTask::init(framework::InitContext& ic) +{ + LOG(INFO) << "[HMPID Write Raw File From Root sim Digits vector - init()]"; + mBaseFileName = ic.options().get("out-file"); + mBaseRootFileName = ic.options().get("in-file"); + mSkipEmpty = ic.options().get("skip-empty"); + mDigitsReceived = 0; + mEventsReceived = 0; + mDumpDigits = ic.options().get("dump-digits"); + mPerFlpFile = ic.options().get("per-flp-file"); + + mCod = new HmpidCoder2(Geo::MAXEQUIPMENTS); +// mCod->reset(); + mCod->openOutputStream(mBaseFileName.c_str(), mPerFlpFile); + + TFile* fdig = TFile::Open(mBaseRootFileName.data()); + assert(fdig != nullptr); + LOG(INFO) << " Open Root digits file " << mBaseRootFileName.data(); + mDigTree = (TTree*)fdig->Get("o2sim"); + + mExTimer.start(); + return; +} + + +void WriteRawFromRootTask::readRootFile() +{ + std::vector digitsPerEvent; + std::vector digits,*hmpBCDataPtr = &digits; +// std::vector digitsCh, *ft0ChDataPtr = &digitsCh; + + mDigTree->SetBranchAddress("HMPDigit", &hmpBCDataPtr); + // digTree->SetBranchAddress("FT0DIGITSCH", &ft0ChDataPtr); + + uint32_t old_orbit = ~0; + uint32_t old_bc = ~0; + + LOG(INFO) << "Number of entries in the simulation file :" << mDigTree->GetEntries(); + for (int ient = 0; ient < mDigTree->GetEntries(); ient++) { + mDigTree->GetEntry(ient); + int nbc = digits.size(); + if (nbc == 0) + continue; // exit for empty + + sort(digits.begin(), digits.end(), o2::hmpid::Digit::eventEquipPadsComp); + if (mDumpDigits) { + std::ofstream dumpfile; + dumpfile.open("/tmp/hmpDumpDigits.dat"); + for (int i = 0; i < nbc; i++) { + dumpfile << digits[i] << std::endl; + } + dumpfile.close(); + } + + // sort(digits.begin(), digits.end(), o2::hmpid::Digit::eventEquipPadsComp); + LOG(INFO) << "For the entry = " << ient << " there are " << nbc << " BCs stored."; + + old_orbit = digits[0].getOrbit(); + old_bc = digits[0].getBC(); + mEventsReceived++; + LOG(INFO) << "Orbit = " << old_orbit << " BC " << old_bc; + for (int i = 0; i < nbc; i++) { + if (digits[i].getOrbit() != old_orbit || digits[i].getBC() != old_bc) { // the event is finished + mCod->codeEventChunkDigits(digitsPerEvent); + digitsPerEvent.clear(); + old_orbit = digits[i].getOrbit(); + old_bc = digits[i].getBC(); + mEventsReceived++; + LOG(INFO) << "Orbit = " << old_orbit << " BC " << old_bc; + } + digitsPerEvent.push_back(digits[i]); + } + if (digitsPerEvent.size() > 0) { + mCod->codeEventChunkDigits(digitsPerEvent); + } + mDigitsReceived += nbc; + } +} + +void WriteRawFromRootTask::run(framework::ProcessingContext& pc) +{ + readRootFile(); + + mExTimer.logMes("End Of Job !"); + mCod->closeOutputStream(); + mCod->dumpResults(); + mExTimer.logMes("Raw File created ! Digits = " + std::to_string(mDigitsReceived) + " for Events =" + std::to_string(mEventsReceived)); + mExTimer.stop(); + + pc.services().get().readyToQuit(framework::QuitRequest::Me); + return; +} + +void WriteRawFromRootTask::endOfStream(framework::EndOfStreamContext& ec) +{ + return; +} + +//_________________________________________________________________________________________________ +o2::framework::DataProcessorSpec getWriteRawFromRootSpec(std::string inputSpec) +{ + std::vector inputs; + std::vector outputs; + + return DataProcessorSpec{ + "HMP-WriteRawFromRootFile", + inputs, + outputs, + AlgorithmSpec{adaptFromTask()}, + Options{{"out-file", VariantType::String, "hmpidRaw", {"name of the output file"}}, + {"in-file", VariantType::String, "simulation.root", {"name of the input sim root file"}}, + {"per-flp-file", VariantType::Bool, false, {"produce one raw file per FLPs"}}, + {"dump-digits", VariantType::Bool, false, {"out the digits file in /tmp/hmpDumpDigits.dat"}}, + {"skip-empty", VariantType::Bool, false, {"skip empty events"}}}}; +} + +} // namespace hmpid +} // end namespace o2 diff --git a/Detectors/HMPID/workflow/src/write-raw-from-root-workflow.cxx b/Detectors/HMPID/workflow/src/write-raw-from-root-workflow.cxx new file mode 100644 index 0000000000000..5bc64e9442c0b --- /dev/null +++ b/Detectors/HMPID/workflow/src/write-raw-from-root-workflow.cxx @@ -0,0 +1,51 @@ +// 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 write-raw-from-root-workflow.cxx +/// \author Antonio Franco - INFN Bari +/// \version 1.0 +/// \date 01 feb 2021 +/// + +#include "Framework/WorkflowSpec.h" +#include "Framework/DataSpecUtils.h" +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/Task.h" +#include "Framework/CompletionPolicy.h" +#include "Framework/CompletionPolicyHelpers.h" +#include "Framework/DispatchPolicy.h" + +// customize the completion policy +void customize(std::vector& policies) +{ + using o2::framework::CompletionPolicy; + using o2::framework::CompletionPolicyHelpers; + policies.push_back(CompletionPolicyHelpers::defineByName("digit-hmpid-write", CompletionPolicy::CompletionOp::Consume)); +} + +#include "Framework/runDataProcessing.h" + +#include "HMPIDWorkflow/WriteRawFromRootSpec.h" + +using namespace o2; +using namespace o2::framework; + +WorkflowSpec defineDataProcessing(const ConfigContext&) +{ + WorkflowSpec specs; + + DataProcessorSpec consumer = o2::hmpid::getWriteRawFromRootSpec(); + // DataProcessorSpec consumer = o2::hmpid::getDecodingSpec(); + specs.push_back(consumer); + // specs.push_back(consumer); + + return specs; +} diff --git a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx index d623ef9f0ff56..d7b696923d934 100644 --- a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx @@ -8,7 +8,7 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// \file write-root-from-digits-workflow.cxx +/// \file write-root-from-digit-workflow.cxx /// \author Antonio Franco - INFN Bari /// \version 1.0 /// \date 01 feb 2021 @@ -33,7 +33,7 @@ void customize(std::vector& policies) #include "Framework/runDataProcessing.h" -#include "HMPIDWorkflow/WriteRootFromDigitsSpec.h" +#include "HMPIDWorkflow/WriteRawFromDigitsSpec.h" using namespace o2; using namespace o2::framework; @@ -42,7 +42,7 @@ WorkflowSpec defineDataProcessing(const ConfigContext&) { WorkflowSpec specs; - DataProcessorSpec consumer = o2::hmpid::getWriteRootFromDigitSpec(); + DataProcessorSpec consumer = o2::hmpid::getWriteRawFromDigitsSpec(); specs.push_back(consumer); return specs; } From 12a5d2c3a1873af35904e108571146884219655d Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Wed, 3 Mar 2021 17:03:27 +0100 Subject: [PATCH 201/208] Version 0.4 - Simulation workflow complete --- Detectors/HMPID/base/CMakeLists.txt | 1 + Detectors/HMPID/base/include/HMPIDBase/Geo.h | 83 ++++++++++++ Detectors/HMPID/base/src/Digit.cxx | 4 +- Detectors/HMPID/base/src/HMPIDBaseLinkDef.h | 2 + .../include/HMPIDSimulation/HMPIDDigitizer.h | 8 +- .../include/HMPIDSimulation/HmpidCoder2.h | 29 ++-- .../HMPID/simulation/src/HMPIDDigitizer.cxx | 4 +- .../HMPID/simulation/src/HmpidCoder2.cxx | 119 +++++++++++----- Detectors/HMPID/workflow/README.md | 19 ++- .../HMPIDWorkflow/WriteRawFromRootSpec.h | 3 + .../HMPIDWorkflow/WriteRootFromDigitsSpec.h | 3 +- .../workflow/src/WriteRawFromRootSpec.cxx | 127 +++++++++++------- .../src/write-root-from-digits-workflow.cxx | 16 ++- .../src/HMPIDDigitWriterSpec.h | 2 + .../src/HMPIDDigitizerSpec.cxx | 12 +- 15 files changed, 325 insertions(+), 107 deletions(-) diff --git a/Detectors/HMPID/base/CMakeLists.txt b/Detectors/HMPID/base/CMakeLists.txt index 579e279202b51..2bab4f0230f37 100644 --- a/Detectors/HMPID/base/CMakeLists.txt +++ b/Detectors/HMPID/base/CMakeLists.txt @@ -16,5 +16,6 @@ o2_add_library(HMPIDBase o2_target_root_dictionary(HMPIDBase HEADERS include/HMPIDBase/Param.h include/HMPIDBase/Digit.h + include/HMPIDBase/Trigger.h include/HMPIDBase/Cluster.h include/HMPIDBase/Geo.h) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 2f261da150491..48de982482d32 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -133,6 +133,89 @@ class Geo ClassDefNV(Geo, 1); }; + +class ReadOut { + public: + struct LinkAddr { + uint8_t Fee; + uint8_t Cru; + uint8_t Lnk; + uint8_t Flp; + }; + union Lnk { + LinkAddr Id; + uint32_t LinkUId; + }; + static constexpr Lnk mEq[Geo::MAXEQUIPMENTS] = {{ 0, 0, 0, 160}, + { 1, 0, 1, 160}, + { 2, 0, 2, 160}, + { 3, 0, 3, 160}, + { 4, 1, 0, 160}, + { 5, 1, 1, 160}, + { 8, 1, 2, 160}, + { 9, 1, 3, 160}, + { 6, 2, 0, 161}, + { 7, 2, 1, 161}, + {10, 2, 2, 161}, + {11, 3, 0, 161}, + {12, 3, 1, 161}, + {13, 3, 2, 161}}; + + static inline int FeeId(unsigned int idx) { return (idx>Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Fee; }; + static inline int CruId(unsigned int idx) { return (idx>Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Cru; }; + static inline int LnkId(unsigned int idx) { return (idx>Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Lnk; }; + static inline int FlpId(unsigned int idx) { return (idx>Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Flp; }; + static inline uint32_t UniqueId(unsigned int idx) { return (idx>Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].LinkUId; }; + + static unsigned int searchIdx(int FeeId) + { + for(int i=0;i + ; #pragma link C++ class o2::hmpid::Geo + ; +#pragma link C++ class o2::hmpid::Trigger + ; +#pragma link C++ class vector < o2::hmpid::Trigger> + ; #endif diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h index 8ef8b579773bb..92643e54a56a4 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h @@ -12,6 +12,7 @@ #define DETECTORS_HMPID_SIMULATION_INCLUDE_HMPIDSIMULATION_HMPIDDIGITIZER_H_ #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Trigger.h" #include "HMPIDSimulation/Detector.h" // for the hit #include "SimulationDataFormat/MCTruthContainer.h" #include "SimulationDataFormat/MCCompLabel.h" @@ -44,12 +45,12 @@ class HMPIDDigitizer // for the first trigger no busy check necessary mCurrentTriggerTime = timeNS; mReadoutCounter++; - Digit::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, mBc); + Trigger::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, mBc); return true; } else { if ((timeNS - mCurrentTriggerTime) > BUSYTIME) { mCurrentTriggerTime = timeNS; - Digit::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, mBc); + Trigger::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, mBc); mReadoutCounter++; return true; } else { @@ -58,6 +59,9 @@ class HMPIDDigitizer } } + uint32_t getOrbit() { return mOrbit; }; + uint16_t getBc() { return mBc; }; + void setEventID(int eventID) { mEventID = eventID; } void setSrcID(int sID) { mSrcID = sID; } diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h index 18709d726cc49..c60ac4cf81105 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h @@ -33,6 +33,8 @@ #include "FairLogger.h" #include "HMPIDBase/Geo.h" #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Trigger.h" + // ---- RDH 6 standard dimension ------- #define RAWBLOCKDIMENSION_W 2048 @@ -62,20 +64,27 @@ class HmpidCoder2 private: // The standard definition of HMPID equipments at P2 - const int mEqIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13}; - const int mCruIds[Geo::MAXEQUIPMENTS] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3}; - const int mLinkIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2}; - const int mFlpIds[Geo::MAXEQUIPMENTS] = {160, 160, 160, 160, 160, 160, 160, 160, 161, 161, 161, 161, 161, 161}; +// const int mEqIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13}; +// const int mCruIds[Geo::MAXEQUIPMENTS] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3}; +// const int mLinkIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2}; +// const int mFlpIds[Geo::MAXEQUIPMENTS] = {160, 160, 160, 160, 160, 160, 160, 160, 161, 161, 161, 161, 161, 161}; - char mFileName160[512]; - char mFileName161[512]; + char mFileName[1024]; uint32_t* mPayloadBufferPtr; + uint32_t* mPadMap; int mEventSizePerEquipment[Geo::MAXEQUIPMENTS]; int mEventPadsPerEquipment[Geo::MAXEQUIPMENTS]; int mPailoadBufferDimPerEquipment; - uint32_t* mPadMap; long mPadsCoded; bool mSkipEmptyEvents; + std::unique_ptr mUPayloadBufferPtr; + std::unique_ptr mUPadMap; + + LinkSubSpec_t mTheRFWLinks[Geo::MAXEQUIPMENTS]; + + int mBusyTime; + int mHmpidErrorFlag; + int mHmpidFrwVersion; public: HmpidCoder2(int numOfEquipments); @@ -101,11 +110,14 @@ class HmpidCoder2 { return (mSkipEmptyEvents); } + o2::raw::RawFileWriter& getWriter() { return mWriter; } - void openOutputStream(const char* OutputFileName, bool perFlpFile = false); + void setDetectorSpecificFields(float BusyTime = 0.001, int Error = 0, int Version = 9); + void openOutputStream(const char* OutputFileName, bool perLinkFile = false, bool perFlpFile = false); void closeOutputStream(); void codeEventChunkDigits(std::vector& digits); + void codeEventChunkDigits(std::vector& digits, Trigger ir); void dumpResults(); private: @@ -113,6 +125,7 @@ class HmpidCoder2 int getEquipmentPadIndex(int eq, int col, int dil, int cha); void fillTheOutputBuffer(uint32_t* padMap); void writePaginatedEvent(uint32_t orbit, uint16_t bc); + void setRDHFields(int eq = -1); }; } // namespace hmpid diff --git a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx index 0b8e04fc52a6b..3f1f6d77aca6a 100644 --- a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx +++ b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx @@ -10,6 +10,7 @@ #include "HMPIDSimulation/HMPIDDigitizer.h" #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Trigger.h" #include "Framework/Logger.h" @@ -33,7 +34,6 @@ void HMPIDDigitizer::zeroSuppress(std::vector const& digits, s if (digit.getCharge() >= getThreshold(digit)) { // if(digit.getPx() < 80 && digit.getPy() < 48) { newdigits.push_back(digit); - if (newlabels) { // copy the labels to the new place with the right new index newlabels->addElements(newdigits.size() - 1, labels.getLabels(index)); @@ -117,7 +117,7 @@ void HMPIDDigitizer::process(std::vector const& hits, std::v } else { // create digit ... and register // mDigits.emplace_back(mCurrentTriggerTime, pad, totalQ * fraction); - mDigits.emplace_back(mOrbit, mBc, pad, totalQ * fraction); + mDigits.emplace_back(mBc, mOrbit, pad, totalQ * fraction); mIndexForPad[pad] = mDigits.size() - 1; mInvolvedPads.emplace_back(pad); diff --git a/Detectors/HMPID/simulation/src/HmpidCoder2.cxx b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx index 1a8c08e6afc46..7aba77dab5038 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder2.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx @@ -16,11 +16,14 @@ /// \date 24 feb 2021 #include +#include +#include #include "Headers/RAWDataHeader.h" #include "CommonDataFormat/InteractionRecord.h" #include "DetectorsRaw/HBFUtils.h" #include "DetectorsRaw/RawFileWriter.h" +#include "DataFormatsParameters/GRPObject.h" #include "HMPIDBase/Digit.h" #include "HMPIDSimulation/HmpidCoder2.h" @@ -38,21 +41,21 @@ HmpidCoder2::HmpidCoder2(int numOfEquipments) mVerbose = 0; mSkipEmptyEvents = true; mPailoadBufferDimPerEquipment = ((Geo::N_SEGMENTS * (Geo::N_COLXSEGMENT * (Geo::N_DILOGICS * (Geo::N_CHANNELS + 1) + 1) + 1)) + 10); - mPayloadBufferPtr = (uint32_t*)std::malloc(mNumberOfEquipments * sizeof(uint32_t) * mPailoadBufferDimPerEquipment); - mPadMap = (uint32_t*)std::malloc(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); - // TODO: Add memory allocation error check - + auto UPayloadBufferPtr = std::make_unique(sizeof(uint32_t)*mNumberOfEquipments * mPailoadBufferDimPerEquipment); + auto UPadMap = std::make_unique( sizeof(uint32_t)*Geo::N_HMPIDTOTALPADS); + mPayloadBufferPtr = UPayloadBufferPtr.get(); + mPadMap = UPadMap.get(); + mBusyTime = 20000; // 1 milli sec + mHmpidErrorFlag = 0; + mHmpidFrwVersion = 9; } /// HMPID Raw Coder HmpidCoder2::~HmpidCoder2() { - // TODO Auto-generated destructor stub - std::free(mPayloadBufferPtr); - std::free(mPadMap); } -/// getEquipCoord() : converts the EquipmentID in CRU,Link couple +/* / getEquipCoord() : converts the EquipmentID in CRU,Link couple /// @param[in] Equi : the HMPID Equipment ID [0..13] /// @param[out] CruId : the FLP CRU number [0..3] /// @param[ou] LinkId : the FLP Linkk number [0..3] @@ -69,6 +72,40 @@ void HmpidCoder2::getEquipCoord(int Equi, uint32_t* CruId, uint32_t* LinkId) *LinkId = mLinkIds[0]; return; } +*/ + +/// setDetectorSpecificFields() : sets the HMPID parameters for the next +/// raw file writes +/// @param[in] BusyTime : busy time in milliseconds +/// @param[in] Error : the Error field +/// @param[in] Version : the Firmware Version [def. 9] +void HmpidCoder2::setDetectorSpecificFields(float BusyTime, int Error, int Version) +{ + uint32_t busy = (uint32_t)(BusyTime / 0.00000005); + mBusyTime = busy; + mHmpidErrorFlag = Error; + mHmpidFrwVersion = Version; + return; +} + +/// setRDHFields() : sets the HMPID RDH Field for the next +/// raw file writes +/// @param[in] eq : the HMPID Equipment ID [0..13] if == -1 -> all +void HmpidCoder2::setRDHFields(int eq) +{ + int st,en; + uint32_t wr = (mBusyTime << 9) | ((mHmpidErrorFlag & 0x01F) << 4) | (mHmpidFrwVersion & 0x0F); + st = (eq < 0 || eq >= Geo::MAXEQUIPMENTS) ? 0 : eq; + en = (eq < 0 || eq >= Geo::MAXEQUIPMENTS) ? Geo::MAXEQUIPMENTS : eq+1; + for(int l=st; l 0 || !mSkipEmptyEvents) { // Skips the Events with 0 Pads + mWriter.addData(ReadOut::FeeId(eq), ReadOut::CruId(eq), ReadOut::LnkId(eq), 0, {bc, orbit}, gsl::span(reinterpret_cast(ptrStartEquipment), EventSize * sizeof(uint32_t))); + // We fill the fields ! + // TODO: we can fill the detector field with Simulated Data + setDetectorSpecificFields(0.000001 * EventSize); + setRDHFields(eq); } - mWriter.addData(mEqIds[eq], mCruIds[eq], mLinkIds[eq], 0, {bc, orbit}, gsl::span(reinterpret_cast(ptrStartEquipment), EventSize * sizeof(uint32_t))); ptrStartEquipment += EventSize; } return; @@ -183,20 +223,30 @@ void HmpidCoder2::writePaginatedEvent(uint32_t orbit, uint16_t bc) /// one and only one event !!!! /// @param[in] digits : the vector of Digit structures void HmpidCoder2::codeEventChunkDigits(std::vector& digits) +{ + if(digits.size() == 0) return; // the vector is empty ! + codeEventChunkDigits(digits, Trigger{digits[0].getBC(), digits[0].getOrbit()}); + return; +} + +/// Analyze a Digits Vector and setup the PADs array +/// with the charge value, then fills the output buffer +/// and forward it to the RawWriter object +/// +/// NOTE: the vector could be empty! +/// @param[in] digits : the vector of Digit structures +/// @param[in] ir : the Interaction Record structure +void HmpidCoder2::codeEventChunkDigits(std::vector& digits, Trigger ir) { int eq, col, dil, cha, mo, x, y, idx; - uint32_t orbit = 0; - uint16_t bc = 0; + uint32_t orbit = ir.getOrbit(); + uint16_t bc = ir.getBc(); int padsCount = 0; - if(digits.size() == 0) return; // the vector is empty ! - - orbit = digits[0].getOrbit(); - bc = digits[0].getBC(); - LOG(INFO) << "Manage chunk Orbit :" << orbit << " BC:" << bc; + LOG(INFO) << "Manage chunk Orbit :" << orbit << " BC:" << bc << " Digits size:" << digits.size(); for (o2::hmpid::Digit d : digits) { Digit::Pad2Equipment(d.getPadID(), &eq, &col, &dil, &cha); // From Digit to Hardware coords - eq = mEqIds[eq]; // converts the Equipment Id in Cru/Link position ref + eq = ReadOut::FeeId(eq); // converts the Equipment Id in Cru/Link position ref idx = getEquipmentPadIndex(eq, col, dil, cha); // finally to the unique padmap index if (mPadMap[idx] != 0) { // We already have the pad set std::cerr << "HmpidCoder [ERROR] : Duplicated DIGIT =" << d << " (" << eq << "," << col << "," << dil << "," << cha << ")" << std::endl; @@ -207,7 +257,7 @@ void HmpidCoder2::codeEventChunkDigits(std::vector& digits) } fillTheOutputBuffer(mPadMap); // Fill the Buffer for all Equipments per Event writePaginatedEvent(orbit, bc); - memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event + std::memset(mPadMap, 0, sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); // Update for the new event return; } @@ -217,26 +267,25 @@ void HmpidCoder2::codeEventChunkDigits(std::vector& digits) /// @param[in] OutputFileName : the Path/Prefix name for the raw files /// @param[in] perFlpFile : if true a couple of files will be created, one for each /// HMPID FLPs -void HmpidCoder2::openOutputStream(const char* OutputFileName, bool perFlpFile) +void HmpidCoder2::openOutputStream(const char* OutputFileName, bool perLinkFile, bool perFlpFile) { - if (perFlpFile) { - sprintf(mFileName160, "%s_%d%s", OutputFileName, 160, ".raw"); - sprintf(mFileName161, "%s_%d%s", OutputFileName, 161, ".raw"); - } else { - sprintf(mFileName160, "%s%s", OutputFileName, ".raw"); - sprintf(mFileName161, "%s%s", OutputFileName, ".raw"); - } RAWDataHeader rdh; // by default, v6 is used currently. for (int eq = 0; eq < mNumberOfEquipments; eq++) { - rdh.feeId = mEqIds[eq]; - rdh.cruID = mCruIds[eq]; - rdh.linkID = mLinkIds[eq]; + rdh.feeId = ReadOut::FeeId(eq); + rdh.cruID = ReadOut::CruId(eq); + rdh.linkID = ReadOut::LnkId(eq); rdh.endPointID = 0; - if(mFlpIds[eq] == 160) { - mWriter.registerLink(rdh, mFileName160); + + if(perLinkFile) { + sprintf(mFileName, "%s_L%d%s", OutputFileName, ReadOut::FeeId(eq), ".raw"); + } else if(perFlpFile) { + sprintf(mFileName, "%s_%d%s", OutputFileName, ReadOut::FlpId(eq), ".raw"); } else { - mWriter.registerLink(rdh, mFileName161); + sprintf(mFileName, "%s%s", OutputFileName, ".raw"); } + mWriter.registerLink(rdh, mFileName); // register the link + LinkSubSpec_t ap = RDHUtils::getSubSpec(ReadOut::CruId(eq), ReadOut::LnkId(eq), 0, ReadOut::FeeId(eq)); + mTheRFWLinks[eq] = ap; // Store the RawFileWriter Link ID } return; } @@ -252,7 +301,7 @@ void HmpidCoder2::closeOutputStream() void HmpidCoder2::dumpResults() { std::cout << " **** HMPID RawFile Coder : results ****" << std::endl; - std::cout << " Created files : " << mFileName160 << " ," << mFileName161 << std::endl; + std::cout << " Created files : " << mFileName << std::endl; std::cout << " Number of Pads coded : " << mPadsCoded << std::endl; std::cout << " ----------------------------------------" << std::endl; } diff --git a/Detectors/HMPID/workflow/README.md b/Detectors/HMPID/workflow/README.md index 82cee2b72db44..20e0c87b307ec 100644 --- a/Detectors/HMPID/workflow/README.md +++ b/Detectors/HMPID/workflow/README.md @@ -2,7 +2,7 @@ \page refHMPworkflow HMP workflow /doxy --> -# DPL workflows for the HMPID v.0.3 +# DPL workflows for the HMPID v.0.4 ## HMPID DPL processors @@ -124,11 +124,16 @@ o2-hmpid-write-raw-from-root-workflow Data processor options: HMP-WriteRawFromRootFile: ``` - --out-file arg (=hmpidRaw) prefix name of the output raw file - --in-file arg (=simulation.root) name of the input sim root file - --per-flp-file produce one raw file per FLPs (suffix 160 and 161) - --dump-digits out the digits in a ASCII file named /tmp/hmpDumpDigits.dat - --skip-empty skip empty events (not yet implemented) + --hmp-raw-outdir arg (=./) base dir for output file + --hmp-raw-outfile arg (=hmpReadOut) base name for output file + --hmp-raw-perlink produce one file per link + --hmp-raw-perflp produce one raw file per FLPs + --in-file arg (=hmpiddigits.root) name of the input sim root file + --dump-digits out the digits file in /tmp/hmpDumpDigits.dat + --hmp-skip-empty skip empty events + --start-value-enumeration arg (=0) initial value for the enumeration + --end-value-enumeration arg (=-1) final value for the enumeration + --step-value-enumeration arg (=1) step between one value and the other ``` Example @@ -136,7 +141,7 @@ Example ``` [O2Suite/latest-o2] ~/Downloads/provaRec $>o2-sim-serial -m HMP -n 20 -e TGeant4 -g pythia8hi [O2Suite/latest-o2] ~/Downloads/provaRec $>o2-sim-digitizer-workflow --onlyDet HMP -[O2Suite/latest-o2] ~/Downloads/provaRec $>o2-hmpid-write-raw-from-root-workflow --in-file hmpiddigits.root --out-file hmpRawFromRoot --dump-digits -b +[O2Suite/latest-o2] ~/Downloads/provaRec $>o2-hmpid-write-raw-from-root-workflow --in-file hmpiddigits.root --hmp-raw-outfile hmpRawFromRoot --dump-digits -b ``` in order to verify the write, the inverse decoding of raw file diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h index 03e8bd3282e5b..8c2706776eff3 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h @@ -19,6 +19,7 @@ #include "HMPIDBase/Common.h" #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Trigger.h" #include "HMPIDSimulation/HmpidCoder2.h" namespace o2 @@ -38,10 +39,12 @@ class WriteRawFromRootTask : public framework::Task private: void readRootFile(); std::string mBaseFileName = ""; + std::string mDirectoryName = ""; std::string mBaseRootFileName = ""; bool mSkipEmpty = false; bool mDumpDigits = false; bool mPerFlpFile = false; + bool mPerLink = false; std::vector mDigits; long mDigitsReceived; diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h index d0cb20ac56b2c..d10e07b1046f5 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h @@ -15,6 +15,7 @@ #include "DPLUtils/MakeRootTreeWriterSpec.h" #include "Framework/InputSpec.h" #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Trigger.h" #include "SimulationDataFormat/MCTruthContainer.h" #include "SimulationDataFormat/MCCompLabel.h" @@ -30,7 +31,7 @@ o2::framework::DataProcessorSpec getWriteRootFromDigitSpec(bool mctruth = false) { using InputSpec = framework::InputSpec; using MakeRootTreeWriterSpec = framework::MakeRootTreeWriterSpec; - return MakeRootTreeWriterSpec("HMPDigitWriter", + return MakeRootTreeWriterSpec("HMPRootFileWriter", "hmpiddigits.root", "o2sim", -1, diff --git a/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx index a02931c8dc005..5fb109fe71690 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx @@ -24,6 +24,7 @@ #include #include +#include "Framework/DataRefUtils.h" #include "Framework/CallbackService.h" #include "Framework/ConfigParamRegistry.h" #include "Framework/ControlService.h" @@ -34,16 +35,19 @@ #include "Framework/WorkflowSpec.h" #include "Framework/Logger.h" #include "Framework/InputRecordWalker.h" +#include "DataFormatsParameters/GRPObject.h" +#include "DetectorsCommonDataFormats/NameConf.h" #include "TFile.h" #include "TTree.h" - +#include #include "Headers/RAWDataHeader.h" #include "DetectorsRaw/RDHUtils.h" #include "DPLUtils/DPLRawParser.h" #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Trigger.h" #include "HMPIDBase/Geo.h" #include "HMPIDSimulation/HmpidCoder2.h" #include "HMPIDWorkflow/WriteRawFromRootSpec.h" @@ -61,24 +65,43 @@ using RDH = o2::header::RDHAny; // Data decoder void WriteRawFromRootTask::init(framework::InitContext& ic) { - LOG(INFO) << "[HMPID Write Raw File From Root sim Digits vector - init()]"; - mBaseFileName = ic.options().get("out-file"); - mBaseRootFileName = ic.options().get("in-file"); - mSkipEmpty = ic.options().get("skip-empty"); + LOG(INFO) << "HMPID Write Raw File From Root sim Digits vector - init()"; mDigitsReceived = 0; mEventsReceived = 0; - mDumpDigits = ic.options().get("dump-digits"); - mPerFlpFile = ic.options().get("per-flp-file"); + mBaseRootFileName = ic.options().get("in-file"); + mBaseFileName = ic.options().get("hmp-raw-outfile"); + mDirectoryName = ic.options().get("hmp-raw-outdir"); + mPerLink = ic.options().get("hmp-raw-perlink"); + mPerFlpFile = ic.options().get("hmp-raw-perflp"); + mDumpDigits = ic.options().get("dump-digits"); // Debug flags + mSkipEmpty = ic.options().get("hmp-skip-empty"); + + // Arrange Files path + if (gSystem->AccessPathName(mDirectoryName.c_str())) { + if (gSystem->mkdir(mDirectoryName.c_str(), kTRUE)) { + LOG(FATAL) << "could not create output directory " << mDirectoryName; + } else { + LOG(INFO) << "created output directory " << mDirectoryName; + } + } + std::string fullFName = o2::utils::concat_string(mDirectoryName, "/", mBaseFileName); + // Setup the Coder mCod = new HmpidCoder2(Geo::MAXEQUIPMENTS); -// mCod->reset(); - mCod->openOutputStream(mBaseFileName.c_str(), mPerFlpFile); + mCod->setSkipEmptyEvents(mSkipEmpty); + mCod->openOutputStream(fullFName.c_str(), mPerLink, mPerFlpFile); + std::string inputGRP = o2::base::NameConf::getGRPFileName(); + std::unique_ptr grp{o2::parameters::GRPObject::loadFrom(inputGRP)}; + mCod->getWriter().setContinuousReadout(grp->isDetContinuousReadOut(o2::detectors::DetID::HMP)); // must be set explicitly + // Open the ROOT file TFile* fdig = TFile::Open(mBaseRootFileName.data()); assert(fdig != nullptr); - LOG(INFO) << " Open Root digits file " << mBaseRootFileName.data(); + LOG(INFO) << "Open Root digits file " << mBaseRootFileName.data(); mDigTree = (TTree*)fdig->Get("o2sim"); + // Ready to operate + mCod->getWriter().writeConfFile("HMP", "RAWDATA", o2::utils::concat_string(mDirectoryName, '/', "HMPraw.cfg")); mExTimer.start(); return; } @@ -88,23 +111,34 @@ void WriteRawFromRootTask::readRootFile() { std::vector digitsPerEvent; std::vector digits,*hmpBCDataPtr = &digits; -// std::vector digitsCh, *ft0ChDataPtr = &digitsCh; - - mDigTree->SetBranchAddress("HMPDigit", &hmpBCDataPtr); - // digTree->SetBranchAddress("FT0DIGITSCH", &ft0ChDataPtr); + std::vector interactions, *interactionsPtr = &interactions; - uint32_t old_orbit = ~0; - uint32_t old_bc = ~0; + // Keeps the Interactions ! + mDigTree->SetBranchAddress("InteractionRecords", &interactionsPtr); + LOG(DEBUG) << "Number of Interaction Records vectors in the simulation file :" << mDigTree->GetEntries(); + for (int ient = 0; ient < mDigTree->GetEntries(); ient++) { + mDigTree->GetEntry(ient); + LOG(INFO) << "Interactions records in simulation :" << interactions.size(); + for (auto a : interactions) { + LOG(DEBUG) << a; + } + } + sort(interactions.begin(), interactions.end()); // Sort interactions in ascending order + int trigPointer = 0; + mDigTree->SetBranchAddress("HMPDigit", &hmpBCDataPtr); LOG(INFO) << "Number of entries in the simulation file :" << mDigTree->GetEntries(); + + // Loops in the Entry of ROOT Branch for (int ient = 0; ient < mDigTree->GetEntries(); ient++) { mDigTree->GetEntry(ient); int nbc = digits.size(); - if (nbc == 0) - continue; // exit for empty - + if (nbc == 0) { // exit for empty + LOG(INFO) << "The Entry :" << ient << " doesn't have digits !"; + continue; + } sort(digits.begin(), digits.end(), o2::hmpid::Digit::eventEquipPadsComp); - if (mDumpDigits) { + if (mDumpDigits) { // we wand the dump of digits ? std::ofstream dumpfile; dumpfile.open("/tmp/hmpDumpDigits.dat"); for (int i = 0; i < nbc; i++) { @@ -112,42 +146,40 @@ void WriteRawFromRootTask::readRootFile() } dumpfile.close(); } - - // sort(digits.begin(), digits.end(), o2::hmpid::Digit::eventEquipPadsComp); - LOG(INFO) << "For the entry = " << ient << " there are " << nbc << " BCs stored."; - - old_orbit = digits[0].getOrbit(); - old_bc = digits[0].getBC(); - mEventsReceived++; - LOG(INFO) << "Orbit = " << old_orbit << " BC " << old_bc; - for (int i = 0; i < nbc; i++) { - if (digits[i].getOrbit() != old_orbit || digits[i].getBC() != old_bc) { // the event is finished - mCod->codeEventChunkDigits(digitsPerEvent); - digitsPerEvent.clear(); - old_orbit = digits[i].getOrbit(); - old_bc = digits[i].getBC(); - mEventsReceived++; - LOG(INFO) << "Orbit = " << old_orbit << " BC " << old_bc; + // ready to operate + LOG(INFO) << "For the entry = " << ient << " there are " << nbc << " DIGITS stored."; + for(int i=0; i < nbc; i++) { + if(digits[i].getOrbit() != interactions[trigPointer].getOrbit() || digits[i].getBC() != interactions[trigPointer].getBc()) { + do { + mEventsReceived++; + LOG(DEBUG) << "Orbit =" << interactions[trigPointer].getOrbit() << " BC =" << interactions[trigPointer].getBc(); + mCod->codeEventChunkDigits(digitsPerEvent, interactions[trigPointer]); + digitsPerEvent.clear(); + trigPointer++; + } while ((digits[i].getOrbit() != interactions[trigPointer].getOrbit() || digits[i].getBC() != interactions[trigPointer].getBc()) && trigPointer < interactions.size()); + if(trigPointer == interactions.size()) { + LOG(WARNING) << "Digits without Interaction Record !!! ABORT" ; + break; + } } digitsPerEvent.push_back(digits[i]); } - if (digitsPerEvent.size() > 0) { - mCod->codeEventChunkDigits(digitsPerEvent); - } + mEventsReceived++; + LOG(DEBUG) << "Orbit =" << interactions[trigPointer].getOrbit() << " BC =" << interactions[trigPointer].getBc(); + mCod->codeEventChunkDigits(digitsPerEvent, interactions[trigPointer]); mDigitsReceived += nbc; } + mExTimer.logMes("End of Write raw file Job !"); + return; } void WriteRawFromRootTask::run(framework::ProcessingContext& pc) { readRootFile(); - - mExTimer.logMes("End Of Job !"); mCod->closeOutputStream(); mCod->dumpResults(); mExTimer.logMes("Raw File created ! Digits = " + std::to_string(mDigitsReceived) + " for Events =" + std::to_string(mEventsReceived)); mExTimer.stop(); - pc.services().get().readyToQuit(framework::QuitRequest::Me); return; } @@ -168,11 +200,14 @@ o2::framework::DataProcessorSpec getWriteRawFromRootSpec(std::string inputSpec) inputs, outputs, AlgorithmSpec{adaptFromTask()}, - Options{{"out-file", VariantType::String, "hmpidRaw", {"name of the output file"}}, - {"in-file", VariantType::String, "simulation.root", {"name of the input sim root file"}}, - {"per-flp-file", VariantType::Bool, false, {"produce one raw file per FLPs"}}, + Options{{"hmp-raw-outdir", VariantType::String, "./", {"base dir for output file"}}, + {"hmp-raw-outfile", VariantType::String, "hmpReadOut", {"base name for output file"}}, + {"hmp-raw-perlink", VariantType::Bool, false, {"produce one file per link"}}, + {"hmp-raw-perflp", VariantType::Bool, false, {"produce one raw file per FLPs"}}, + {"in-file", VariantType::String, "hmpiddigits.root", {"name of the input sim root file"}}, + // {"configKeyValues", VariantType::String, "", {"comma-separated configKeyValues"}}, {"dump-digits", VariantType::Bool, false, {"out the digits file in /tmp/hmpDumpDigits.dat"}}, - {"skip-empty", VariantType::Bool, false, {"skip empty events"}}}}; + {"hmp-skip-empty", VariantType::Bool, false, {"skip empty events"}}}}; } } // namespace hmpid diff --git a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx index d7b696923d934..baf79ed7f7c77 100644 --- a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx @@ -22,6 +22,9 @@ #include "Framework/CompletionPolicy.h" #include "Framework/CompletionPolicyHelpers.h" #include "Framework/DispatchPolicy.h" +#include "CommonUtils/ConfigurableParam.h" +#include "Framework/ConfigParamSpec.h" +#include "Framework/Variant.h" // customize the completion policy void customize(std::vector& policies) @@ -31,6 +34,13 @@ void customize(std::vector& policies) policies.push_back(CompletionPolicyHelpers::defineByName("digit-root-write", CompletionPolicy::CompletionOp::Consume)); } +void customize(std::vector& workflowOptions) +{ + using o2::framework::ConfigParamSpec; + std::string keyvaluehelp("Semicolon separated key=value strings ..."); + workflowOptions.push_back(ConfigParamSpec{"configKeyValues", o2::framework::VariantType::String, "", {keyvaluehelp}}); +} + #include "Framework/runDataProcessing.h" #include "HMPIDWorkflow/WriteRawFromDigitsSpec.h" @@ -38,11 +48,15 @@ void customize(std::vector& policies) using namespace o2; using namespace o2::framework; -WorkflowSpec defineDataProcessing(const ConfigContext&) + +WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) { WorkflowSpec specs; + o2::conf::ConfigurableParam::updateFromString(configcontext.options().get("configKeyValues")); DataProcessorSpec consumer = o2::hmpid::getWriteRawFromDigitsSpec(); specs.push_back(consumer); return specs; } + + diff --git a/Steer/DigitizerWorkflow/src/HMPIDDigitWriterSpec.h b/Steer/DigitizerWorkflow/src/HMPIDDigitWriterSpec.h index 4d66a83fddd82..66c2875f48d3e 100644 --- a/Steer/DigitizerWorkflow/src/HMPIDDigitWriterSpec.h +++ b/Steer/DigitizerWorkflow/src/HMPIDDigitWriterSpec.h @@ -15,6 +15,7 @@ #include "DPLUtils/MakeRootTreeWriterSpec.h" #include "Framework/InputSpec.h" #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Trigger.h" #include "SimulationDataFormat/MCTruthContainer.h" #include "SimulationDataFormat/MCCompLabel.h" @@ -35,6 +36,7 @@ o2::framework::DataProcessorSpec getHMPIDDigitWriterSpec(bool mctruth = true) "o2sim", 1, BranchDefinition>{InputSpec{"digitinput", "HMP", "DIGITS"}, "HMPDigit"}, + BranchDefinition>{InputSpec{"interactionrecods", "HMP", "INTRECORDS"}, "InteractionRecords"}, BranchDefinition>{InputSpec{"labelinput", "HMP", "DIGITLBL"}, "HMPDigitLabels", mctruth ? 1 : 0})(); } diff --git a/Steer/DigitizerWorkflow/src/HMPIDDigitizerSpec.cxx b/Steer/DigitizerWorkflow/src/HMPIDDigitizerSpec.cxx index 61d298248687f..874650ea55e72 100644 --- a/Steer/DigitizerWorkflow/src/HMPIDDigitizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/HMPIDDigitizerSpec.cxx @@ -23,6 +23,7 @@ #include "Framework/Task.h" #include "DataFormatsParameters/GRPObject.h" #include "HMPIDBase/Digit.h" +#include "HMPIDBase/Trigger.h" #include "HMPIDSimulation/HMPIDDigitizer.h" #include "HMPIDSimulation/Detector.h" #include "DetectorsBase/BaseDPLDigitizer.h" @@ -61,7 +62,6 @@ class HMPIDDPLDigitizerTask : public o2::base::BaseDPLDigitizer context->initSimChains(o2::detectors::DetID::HMP, mSimChains); auto& irecords = context->getEventRecords(); - for (auto& record : irecords) { LOG(INFO) << "HMPID TIME RECEIVED " << record.getTimeNS(); } @@ -69,6 +69,7 @@ class HMPIDDPLDigitizerTask : public o2::base::BaseDPLDigitizer auto& eventParts = context->getEventParts(); std::vector digitsAccum; // accumulator for digits o2::dataformats::MCTruthContainer labelAccum; // timeframe accumulator for labels + mIntRecord.clear(); auto flushDigitsAndLabels = [this, &digitsAccum, &labelAccum]() { // flush previous buffer @@ -84,13 +85,11 @@ class HMPIDDPLDigitizerTask : public o2::base::BaseDPLDigitizer // loop over all composite collisions given from context // (aka loop over all the interaction records) for (int collID = 0; collID < irecords.size(); ++collID) { - // try to start new readout cycle by setting the trigger time auto triggeraccepted = mDigitizer.setTriggerTime(irecords[collID].getTimeNS()); if (triggeraccepted) { flushDigitsAndLabels(); // flush previous readout cycle } - auto withinactivetime = mDigitizer.setEventTime(irecords[collID].getTimeNS()); if (withinactivetime) { // for each collision, loop over the constituents event and source IDs @@ -110,6 +109,10 @@ class HMPIDDPLDigitizerTask : public o2::base::BaseDPLDigitizer mDigitizer.process(hits, mDigits); } + // save info for the triggers accepted + LOG(INFO) << "Trigger Orbit :" << mDigitizer.getOrbit() << " BC:" << mDigitizer.getBc(); + mIntRecord.push_back(o2::hmpid::Trigger(mDigitizer.getBc(), mDigitizer.getOrbit())); + } else { LOG(INFO) << "COLLISION " << collID << "FALLS WITHIN A DEAD TIME"; } @@ -119,6 +122,7 @@ class HMPIDDPLDigitizerTask : public o2::base::BaseDPLDigitizer // send out to next stage pc.outputs().snapshot(Output{"HMP", "DIGITS", 0, Lifetime::Timeframe}, digitsAccum); + pc.outputs().snapshot(Output{"HMP", "INTRECORDS", 0, Lifetime::Timeframe}, mIntRecord); if (pc.outputs().isAllowed({"HMP", "DIGITLBL", 0})) { pc.outputs().snapshot(Output{"HMP", "DIGITLBL", 0, Lifetime::Timeframe}, labelAccum); } @@ -135,6 +139,7 @@ class HMPIDDPLDigitizerTask : public o2::base::BaseDPLDigitizer std::vector mSimChains; std::vector mDigits; o2::dataformats::MCTruthContainer mLabels; // labels which get filled + std::vector mIntRecord; // RS: at the moment using hardcoded flag for continuous readout o2::parameters::GRPObject::ROMode mROMode = o2::parameters::GRPObject::CONTINUOUS; // readout mode @@ -149,6 +154,7 @@ o2::framework::DataProcessorSpec getHMPIDDigitizerSpec(int channel, bool mctruth // options that can be used for this processor (here: input file names where to take the hits) std::vector outputs; outputs.emplace_back("HMP", "DIGITS", 0, Lifetime::Timeframe); + outputs.emplace_back("HMP", "INTRECORDS", 0, Lifetime::Timeframe); if (mctruth) { outputs.emplace_back("HMP", "DIGITLBL", 0, Lifetime::Timeframe); } From fdb3ac9f38472b4bc28e0a638add58ba147dd7ee Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Wed, 3 Mar 2021 17:06:08 +0100 Subject: [PATCH 202/208] Stage changes --- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 111 +++++++++--------- .../HMPID/base/include/HMPIDBase/Trigger.h | 101 ++++++++++++++++ Detectors/HMPID/base/src/Digit.cxx | 2 +- .../include/HMPIDSimulation/HmpidCoder2.h | 11 +- .../HMPID/simulation/src/HmpidCoder2.cxx | 23 ++-- .../workflow/src/WriteRawFromRootSpec.cxx | 14 +-- .../src/write-root-from-digits-workflow.cxx | 3 - 7 files changed, 182 insertions(+), 83 deletions(-) create mode 100644 Detectors/HMPID/base/include/HMPIDBase/Trigger.h diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 48de982482d32..c1f9fb658b0f0 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -134,65 +134,66 @@ class Geo ClassDefNV(Geo, 1); }; -class ReadOut { - public: - struct LinkAddr { - uint8_t Fee; - uint8_t Cru; - uint8_t Lnk; - uint8_t Flp; - }; - union Lnk { - LinkAddr Id; - uint32_t LinkUId; - }; - static constexpr Lnk mEq[Geo::MAXEQUIPMENTS] = {{ 0, 0, 0, 160}, - { 1, 0, 1, 160}, - { 2, 0, 2, 160}, - { 3, 0, 3, 160}, - { 4, 1, 0, 160}, - { 5, 1, 1, 160}, - { 8, 1, 2, 160}, - { 9, 1, 3, 160}, - { 6, 2, 0, 161}, - { 7, 2, 1, 161}, - {10, 2, 2, 161}, - {11, 3, 0, 161}, - {12, 3, 1, 161}, - {13, 3, 2, 161}}; - - static inline int FeeId(unsigned int idx) { return (idx>Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Fee; }; - static inline int CruId(unsigned int idx) { return (idx>Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Cru; }; - static inline int LnkId(unsigned int idx) { return (idx>Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Lnk; }; - static inline int FlpId(unsigned int idx) { return (idx>Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Flp; }; - static inline uint32_t UniqueId(unsigned int idx) { return (idx>Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].LinkUId; }; - - static unsigned int searchIdx(int FeeId) - { - for(int i=0;i Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Fee; }; + static inline int CruId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Cru; }; + static inline int LnkId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Lnk; }; + static inline int FlpId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Flp; }; + static inline uint32_t UniqueId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].LinkUId; }; + + static unsigned int searchIdx(int FeeId) + { + for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { + if (FeeId == mEq[i].Id.Fee) { + return (i); } - return(-1); } - static unsigned int searchIdx(int CruId, int LnkId) - { - for(int i=0;i +#include "TMath.h" +#include "CommonDataFormat/TimeStamp.h" +#include "CommonConstants/LHCConstants.h" + + +namespace o2 +{ +namespace hmpid +{ + +/// \class Trigger +/// \brief HMPID Trigger declaration +class Trigger +{ + public: + // Trigger time Conversion Functions + static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) | (0x0FFF & BC)); }; + static inline uint32_t EventIdToOrbit(uint64_t EventId) { return (EventId >> 12); }; + static inline uint16_t EventIdToBc(uint64_t EventId) { return (EventId & 0x0FFF); }; + static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) { return (BC * o2::constants::lhc::LHCBunchSpacingNS + Orbit * o2::constants::lhc::LHCOrbitNS);}; + static uint32_t TimeNsToOrbit(double TimeNs) { return (uint32_t)(TimeNs/o2::constants::lhc::LHCOrbitNS);}; + static uint16_t TimeNsToBc(double TimeNs) { return (uint16_t)(std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS);}; + static void TimeNsToOrbitBc(double TimeNs, uint32_t& Orbit, uint16_t& Bc) + { + Orbit = TimeNsToOrbit(TimeNs); + Bc = TimeNsToBc(TimeNs); + return; + }; + + // Operators definition ! + friend inline bool operator<(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit,l.mBc) < OrbitBcToEventId(r.mOrbit, r.mBc); }; + friend inline bool operator==(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit,l.mBc) == OrbitBcToEventId(r.mOrbit, r.mBc); }; + friend inline bool operator>(const Trigger& l, const Trigger& r) { return r < l; }; + friend inline bool operator<=(const Trigger& l, const Trigger& r) { return !(l > r); }; + friend inline bool operator>=(const Trigger& l, const Trigger& r) { return !(l < r); }; + friend inline bool operator!=(const Trigger& l, const Trigger& r) { return !(l == r); }; + + // Digit ASCII format (Orbit,BunchCrossing)[LHC Time nSec] + friend std::ostream& operator<<(std::ostream& os, const Trigger& d) + { + os << "(" << d.mOrbit << "," << d.mBc << ")[" << OrbitBcToTimeNs(d.mOrbit,d.mBc) << " ns]" ; + return os; + }; + + public: + Trigger() = default; + Trigger(uint16_t bc, uint32_t orbit) { + mBc = bc; + mOrbit = orbit; + }; + uint32_t getOrbit() const { return mOrbit; } + uint16_t getBc() const { return mBc; } + uint64_t getTriggerID() const { return OrbitBcToEventId(mOrbit, mBc); } + void setOrbit(uint32_t orbit) + { + mOrbit = orbit; + return; + } + void setBC(uint16_t bc) + { + mBc = bc; + return; + } + void setTriggerID(uint64_t trigger) + { + mOrbit = (trigger >> 12); + mBc = (trigger & 0x0FFF); + return; + } + private: + // Members + uint16_t mBc = 0.; + uint32_t mOrbit = 0; + + ClassDefNV(Trigger, 2); +}; + +} // namespace hmpid +} // namespace o2 + +#endif /* DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_TRIGGER_H_ */ diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index 2eee00051cb00..2711a642a2971 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -383,7 +383,7 @@ Double_t Digit::OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) /// @return : the Orbit number [0..2^32-1] uint32_t Digit::TimeNsToOrbit(Double_t TimeNs) { - return (uint32_t)(TimeNs/o2::constants::lhc::LHCOrbitNS); + return (uint32_t)(TimeNs / o2::constants::lhc::LHCOrbitNS); } /// TimeNsToBc : Extracts the Bunch Crossing number from the absolute diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h index c60ac4cf81105..876e63e629d19 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h @@ -35,7 +35,6 @@ #include "HMPIDBase/Digit.h" #include "HMPIDBase/Trigger.h" - // ---- RDH 6 standard dimension ------- #define RAWBLOCKDIMENSION_W 2048 #define HEADERDIMENSION_W 16 @@ -64,10 +63,10 @@ class HmpidCoder2 private: // The standard definition of HMPID equipments at P2 -// const int mEqIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13}; -// const int mCruIds[Geo::MAXEQUIPMENTS] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3}; -// const int mLinkIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2}; -// const int mFlpIds[Geo::MAXEQUIPMENTS] = {160, 160, 160, 160, 160, 160, 160, 160, 161, 161, 161, 161, 161, 161}; + // const int mEqIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13}; + // const int mCruIds[Geo::MAXEQUIPMENTS] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3}; + // const int mLinkIds[Geo::MAXEQUIPMENTS] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2}; + // const int mFlpIds[Geo::MAXEQUIPMENTS] = {160, 160, 160, 160, 160, 160, 160, 160, 161, 161, 161, 161, 161, 161}; char mFileName[1024]; uint32_t* mPayloadBufferPtr; @@ -113,7 +112,7 @@ class HmpidCoder2 o2::raw::RawFileWriter& getWriter() { return mWriter; } void setDetectorSpecificFields(float BusyTime = 0.001, int Error = 0, int Version = 9); - void openOutputStream(const char* OutputFileName, bool perLinkFile = false, bool perFlpFile = false); + void openOutputStream(const char* OutputFileName, bool perLinkFile = false, bool perFlpFile = false); void closeOutputStream(); void codeEventChunkDigits(std::vector& digits); diff --git a/Detectors/HMPID/simulation/src/HmpidCoder2.cxx b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx index 7aba77dab5038..d8fb67d5592f2 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder2.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx @@ -41,11 +41,11 @@ HmpidCoder2::HmpidCoder2(int numOfEquipments) mVerbose = 0; mSkipEmptyEvents = true; mPailoadBufferDimPerEquipment = ((Geo::N_SEGMENTS * (Geo::N_COLXSEGMENT * (Geo::N_DILOGICS * (Geo::N_CHANNELS + 1) + 1) + 1)) + 10); - auto UPayloadBufferPtr = std::make_unique(sizeof(uint32_t)*mNumberOfEquipments * mPailoadBufferDimPerEquipment); - auto UPadMap = std::make_unique( sizeof(uint32_t)*Geo::N_HMPIDTOTALPADS); + auto UPayloadBufferPtr = std::make_unique(sizeof(uint32_t) * mNumberOfEquipments * mPailoadBufferDimPerEquipment); + auto UPadMap = std::make_unique(sizeof(uint32_t) * Geo::N_HMPIDTOTALPADS); mPayloadBufferPtr = UPayloadBufferPtr.get(); mPadMap = UPadMap.get(); - mBusyTime = 20000; // 1 milli sec + mBusyTime = 20000; // 1 milli sec mHmpidErrorFlag = 0; mHmpidFrwVersion = 9; } @@ -93,14 +93,14 @@ void HmpidCoder2::setDetectorSpecificFields(float BusyTime, int Error, int Versi /// @param[in] eq : the HMPID Equipment ID [0..13] if == -1 -> all void HmpidCoder2::setRDHFields(int eq) { - int st,en; + int st, en; uint32_t wr = (mBusyTime << 9) | ((mHmpidErrorFlag & 0x01F) << 4) | (mHmpidFrwVersion & 0x0F); st = (eq < 0 || eq >= Geo::MAXEQUIPMENTS) ? 0 : eq; - en = (eq < 0 || eq >= Geo::MAXEQUIPMENTS) ? Geo::MAXEQUIPMENTS : eq+1; - for(int l=st; l= Geo::MAXEQUIPMENTS) ? Geo::MAXEQUIPMENTS : eq + 1; + for (int l = st; l < en; l++) { o2::raw::RawFileWriter::LinkData& link = mWriter.getLinkWithSubSpec(mTheRFWLinks[l]); - RDHAny *RDHptr = link.getLastRDH(); - if(RDHptr != nullptr) { + RDHAny* RDHptr = link.getLastRDH(); + if (RDHptr != nullptr) { o2::raw::RDHUtils::setDetectorField(RDHptr, wr); } } @@ -224,7 +224,8 @@ void HmpidCoder2::writePaginatedEvent(uint32_t orbit, uint16_t bc) /// @param[in] digits : the vector of Digit structures void HmpidCoder2::codeEventChunkDigits(std::vector& digits) { - if(digits.size() == 0) return; // the vector is empty ! + if (digits.size() == 0) + return; // the vector is empty ! codeEventChunkDigits(digits, Trigger{digits[0].getBC(), digits[0].getOrbit()}); return; } @@ -276,9 +277,9 @@ void HmpidCoder2::openOutputStream(const char* OutputFileName, bool perLinkFile, rdh.linkID = ReadOut::LnkId(eq); rdh.endPointID = 0; - if(perLinkFile) { + if (perLinkFile) { sprintf(mFileName, "%s_L%d%s", OutputFileName, ReadOut::FeeId(eq), ".raw"); - } else if(perFlpFile) { + } else if (perFlpFile) { sprintf(mFileName, "%s_%d%s", OutputFileName, ReadOut::FlpId(eq), ".raw"); } else { sprintf(mFileName, "%s%s", OutputFileName, ".raw"); diff --git a/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx index 5fb109fe71690..0188b00fee63c 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx @@ -133,12 +133,12 @@ void WriteRawFromRootTask::readRootFile() for (int ient = 0; ient < mDigTree->GetEntries(); ient++) { mDigTree->GetEntry(ient); int nbc = digits.size(); - if (nbc == 0) { // exit for empty + if (nbc == 0) { // exit for empty LOG(INFO) << "The Entry :" << ient << " doesn't have digits !"; continue; } sort(digits.begin(), digits.end(), o2::hmpid::Digit::eventEquipPadsComp); - if (mDumpDigits) { // we wand the dump of digits ? + if (mDumpDigits) { // we wand the dump of digits ? std::ofstream dumpfile; dumpfile.open("/tmp/hmpDumpDigits.dat"); for (int i = 0; i < nbc; i++) { @@ -148,8 +148,8 @@ void WriteRawFromRootTask::readRootFile() } // ready to operate LOG(INFO) << "For the entry = " << ient << " there are " << nbc << " DIGITS stored."; - for(int i=0; i < nbc; i++) { - if(digits[i].getOrbit() != interactions[trigPointer].getOrbit() || digits[i].getBC() != interactions[trigPointer].getBc()) { + for (int i = 0; i < nbc; i++) { + if (digits[i].getOrbit() != interactions[trigPointer].getOrbit() || digits[i].getBC() != interactions[trigPointer].getBc()) { do { mEventsReceived++; LOG(DEBUG) << "Orbit =" << interactions[trigPointer].getOrbit() << " BC =" << interactions[trigPointer].getBc(); @@ -157,8 +157,8 @@ void WriteRawFromRootTask::readRootFile() digitsPerEvent.clear(); trigPointer++; } while ((digits[i].getOrbit() != interactions[trigPointer].getOrbit() || digits[i].getBC() != interactions[trigPointer].getBc()) && trigPointer < interactions.size()); - if(trigPointer == interactions.size()) { - LOG(WARNING) << "Digits without Interaction Record !!! ABORT" ; + if (trigPointer == interactions.size()) { + LOG(WARNING) << "Digits without Interaction Record !!! ABORT"; break; } } @@ -205,7 +205,7 @@ o2::framework::DataProcessorSpec getWriteRawFromRootSpec(std::string inputSpec) {"hmp-raw-perlink", VariantType::Bool, false, {"produce one file per link"}}, {"hmp-raw-perflp", VariantType::Bool, false, {"produce one raw file per FLPs"}}, {"in-file", VariantType::String, "hmpiddigits.root", {"name of the input sim root file"}}, - // {"configKeyValues", VariantType::String, "", {"comma-separated configKeyValues"}}, + // {"configKeyValues", VariantType::String, "", {"comma-separated configKeyValues"}}, {"dump-digits", VariantType::Bool, false, {"out the digits file in /tmp/hmpDumpDigits.dat"}}, {"hmp-skip-empty", VariantType::Bool, false, {"skip empty events"}}}}; } diff --git a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx index baf79ed7f7c77..498e3778260b9 100644 --- a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx @@ -48,7 +48,6 @@ void customize(std::vector& workflowOptions) using namespace o2; using namespace o2::framework; - WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) { WorkflowSpec specs; @@ -58,5 +57,3 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) specs.push_back(consumer); return specs; } - - From d65c80e56465c6caefcf441647b3ae62ab89608a Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Wed, 3 Mar 2021 17:07:16 +0100 Subject: [PATCH 203/208] Fix not staged --- .../HMPID/base/include/HMPIDBase/Trigger.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Trigger.h b/Detectors/HMPID/base/include/HMPIDBase/Trigger.h index cdf854987885d..1515b3b3be161 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Trigger.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Trigger.h @@ -22,7 +22,6 @@ #include "CommonDataFormat/TimeStamp.h" #include "CommonConstants/LHCConstants.h" - namespace o2 { namespace hmpid @@ -37,9 +36,9 @@ class Trigger static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) | (0x0FFF & BC)); }; static inline uint32_t EventIdToOrbit(uint64_t EventId) { return (EventId >> 12); }; static inline uint16_t EventIdToBc(uint64_t EventId) { return (EventId & 0x0FFF); }; - static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) { return (BC * o2::constants::lhc::LHCBunchSpacingNS + Orbit * o2::constants::lhc::LHCOrbitNS);}; - static uint32_t TimeNsToOrbit(double TimeNs) { return (uint32_t)(TimeNs/o2::constants::lhc::LHCOrbitNS);}; - static uint16_t TimeNsToBc(double TimeNs) { return (uint16_t)(std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS);}; + static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) { return (BC * o2::constants::lhc::LHCBunchSpacingNS + Orbit * o2::constants::lhc::LHCOrbitNS); }; + static uint32_t TimeNsToOrbit(double TimeNs) { return (uint32_t)(TimeNs / o2::constants::lhc::LHCOrbitNS); }; + static uint16_t TimeNsToBc(double TimeNs) { return (uint16_t)(std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); }; static void TimeNsToOrbitBc(double TimeNs, uint32_t& Orbit, uint16_t& Bc) { Orbit = TimeNsToOrbit(TimeNs); @@ -48,8 +47,8 @@ class Trigger }; // Operators definition ! - friend inline bool operator<(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit,l.mBc) < OrbitBcToEventId(r.mOrbit, r.mBc); }; - friend inline bool operator==(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit,l.mBc) == OrbitBcToEventId(r.mOrbit, r.mBc); }; + friend inline bool operator<(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit, l.mBc) < OrbitBcToEventId(r.mOrbit, r.mBc); }; + friend inline bool operator==(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit, l.mBc) == OrbitBcToEventId(r.mOrbit, r.mBc); }; friend inline bool operator>(const Trigger& l, const Trigger& r) { return r < l; }; friend inline bool operator<=(const Trigger& l, const Trigger& r) { return !(l > r); }; friend inline bool operator>=(const Trigger& l, const Trigger& r) { return !(l < r); }; @@ -58,13 +57,14 @@ class Trigger // Digit ASCII format (Orbit,BunchCrossing)[LHC Time nSec] friend std::ostream& operator<<(std::ostream& os, const Trigger& d) { - os << "(" << d.mOrbit << "," << d.mBc << ")[" << OrbitBcToTimeNs(d.mOrbit,d.mBc) << " ns]" ; + os << "(" << d.mOrbit << "," << d.mBc << ")[" << OrbitBcToTimeNs(d.mOrbit, d.mBc) << " ns]"; return os; }; public: Trigger() = default; - Trigger(uint16_t bc, uint32_t orbit) { + Trigger(uint16_t bc, uint32_t orbit) + { mBc = bc; mOrbit = orbit; }; @@ -87,6 +87,7 @@ class Trigger mBc = (trigger & 0x0FFF); return; } + private: // Members uint16_t mBc = 0.; From 35991f26a690209f35821c89e4f3a526dcaff7b6 Mon Sep 17 00:00:00 2001 From: Antonio Franco Date: Thu, 4 Mar 2021 00:51:48 +0100 Subject: [PATCH 204/208] Fix all merge wit Dev diff --- Detectors/HMPID/base/CMakeLists.txt | 3 - .../HMPID/base/include/HMPIDBase/Digit.h | 15 - Detectors/HMPID/base/include/HMPIDBase/Geo.h | 118 --- Detectors/HMPID/base/src/Digit.cxx | 68 -- Detectors/HMPID/base/src/HMPIDBaseLinkDef.h | 3 - .../HMPID/reconstruction/src/HmpidDecoder.cxx | 811 ------------------ .../reconstruction/src/HmpidEquipment.cxx | 27 + Detectors/HMPID/simulation/CMakeLists.txt | 7 - .../include/HMPIDSimulation/HMPIDDigitizer.h | 8 - .../HMPID/simulation/src/HMPIDDigitizer.cxx | 4 - .../simulation/src/HMPIDSimulationLinkDef.h | 3 - Detectors/HMPID/workflow/CMakeLists.txt | 45 - Detectors/HMPID/workflow/README.md | 114 --- .../HMPIDWorkflow/WriteRootFromDigitsSpec.h | 19 - .../HMPID/workflow/src/DataDecoderSpec.cxx | 52 -- .../HMPID/workflow/src/DumpDigitsSpec.cxx | 9 - .../src/write-root-from-digits-workflow.cxx | 38 - 17 files changed, 27 insertions(+), 1317 deletions(-) diff --git a/Detectors/HMPID/base/CMakeLists.txt b/Detectors/HMPID/base/CMakeLists.txt index 1171434bb766c..2bab4f0230f37 100644 --- a/Detectors/HMPID/base/CMakeLists.txt +++ b/Detectors/HMPID/base/CMakeLists.txt @@ -16,9 +16,6 @@ o2_add_library(HMPIDBase o2_target_root_dictionary(HMPIDBase HEADERS include/HMPIDBase/Param.h include/HMPIDBase/Digit.h -<<<<<<< HEAD include/HMPIDBase/Trigger.h -======= ->>>>>>> refs/heads/dev include/HMPIDBase/Cluster.h include/HMPIDBase/Geo.h) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Digit.h b/Detectors/HMPID/base/include/HMPIDBase/Digit.h index 4a7f3f8603565..7fcf96a8e4527 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Digit.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Digit.h @@ -50,11 +50,7 @@ class Digit static void Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int* Module, int* x, int* y); // Trigger time Conversion Functions -<<<<<<< HEAD static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) | (0x0FFF & BC)); }; -======= - static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) || BC); }; ->>>>>>> refs/heads/dev static inline uint32_t EventIdToOrbit(uint64_t EventId) { return (EventId >> 12); }; static inline uint16_t EventIdToBc(uint64_t EventId) { return (EventId & 0x0FFF); }; static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC); @@ -84,17 +80,10 @@ class Digit public: Digit() = default; -<<<<<<< HEAD Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge); Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge); Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int column, int dilogic, int channel); Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, int y); -======= - Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad){}; - Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge); - Digit(uint16_t bc, uint32_t orbit, uint16_t, int equipment, int column, int dilogic, int channel); - Digit(uint16_t bc, uint32_t orbit, uint16_t, int module, int x, int y); ->>>>>>> refs/heads/dev // Getter & Setters uint16_t getCharge() const { return mQ; } @@ -144,7 +133,6 @@ class Digit // Charge management functions static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); static float getFractionalContributionForPad(HitType const& hit, int somepad); -<<<<<<< HEAD void addCharge(float q) { mQ += q; @@ -152,9 +140,6 @@ class Digit mQ = 0x0FFF; } } -======= - void addCharge(float q) { mQ += q; } ->>>>>>> refs/heads/dev void subCharge(float q) { mQ -= q; } private: diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 43f433b6cf049..0354eed4b682d 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -18,7 +18,6 @@ #define ALICEO2_HMPID_GEO_H #include -<<<<<<< HEAD namespace o2 { @@ -218,124 +217,7 @@ void ReadOut::Init() }; */ -======= -#include -namespace o2 -{ -namespace hmpid -{ - -/* ------------------ HMPID Detector Coordinate definition ------------------- - - 143 .-------------. .-------------. 0 ------.------ 23 - | | |.-----.-----.| | | <-- | - | | || | || | | 9 0 | - | | || 4 | 5 || | | Dil. | - ^ | | || | || | | | | ^ - | | | ||_____|_____|| | | | | | - | | | |.-----.-----.| | | | | | - Y | | || | || | | | - | | | || 2 | 3 || Column | n | n+1 | Column - | | | || | || | | | - | | ||_____|_____|| | | | | | - | | 47 ^ |.-----.-----.| | | | | | - | | | || | || V | | | | - | | Y || 0 | 1 || | Dil. | | - | | | || | || | 9 0 | | - | | 0 ||_____|_____|| | <-- | | - 0 .-------------. ------------- 23 ------.------ 0 - 0 --X--> 159 0 -X->79 - - Pad(Module,x,y) Pad(Chamber,PhotoCat,x,y) Pad(Equipment,Column,Dilogic,Channel) - - Equipment n - - 143 - ^ - | 46 40 34 28 22 16 10 04 - | 44 38 32 26 20 14 08 02 - 40 36 30 24 18 12 06 00 - y 43 37 31 25 19 13 07 01 - 45 39 33 27 21 15 09 03 - | 47 41 35 29 23 17 11 05 - | - - 0 - - - 0 --------- x ------> 79 - - For Equipment n : x = 79 - (Dilo * 8 + Chan / 8) - y = 143 - (Column * 6 + Chan % 6) - - --------------------------------------------------------------------------- */ -/// \class Geo -/// \brief HMPID detector geometry (only statics) -class Geo -{ - public: - // From AliTOFGeometry - // static void translate(Float_t* xyz, Float_t translationVector[3]); - // enum { - // // DAQ characteristics - // kNDDL = 4, // Number of DDL (Detector Data Link) per sector - // kNTRM = 12, // Number of TRM ( Readout Module) per DDL - // kNTdc = 15, // Number of Tdc (Time to Digital Converter) per TRM - // kNChain = 2, // Number of chains per TRM - // kNCrate = 72, // Number of Crates - // kNCh = 8 // Number of channels per Tdc - // }; - - // ---- HMPID geometry ------- - static constexpr int MAXEQUIPMENTS = 14; - static constexpr int N_SEGMENTS = 3; - static constexpr int N_COLXSEGMENT = 8; - static constexpr int N_COLUMNS = 24; - static constexpr int N_DILOGICS = 10; - static constexpr int N_CHANNELS = 48; - static constexpr int N_DILOCHANNELS = 64; - - static constexpr int N_MODULES = 7; - static constexpr int N_XROWS = 160; - static constexpr int N_YCOLS = 144; - - static constexpr int MAXYCOLS = 143; - static constexpr int MAXHALFXROWS = 79; - static constexpr int HALFXROWS = 80; - - static constexpr int DILOPADSCOLS = 6; - static constexpr int DILOPADSROWS = 8; - - static constexpr int EQUIPMENTSPERMODULE = 2; - - static constexpr int N_EQUIPMENTTOTALPADS = N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; - static constexpr int N_HMPIDTOTALPADS = MAXEQUIPMENTS * N_SEGMENTS * N_COLXSEGMENT * N_DILOGICS * N_CHANNELS; - - static constexpr int N_PHOTOCATODS = 6; - static constexpr int N_PHOTOCATODSX = 80; - static constexpr int N_PHOTOCATODSY = 48; - static constexpr int MAXXPHOTO = 79; - static constexpr int MAXYPHOTO = 47; - - static void Module2Equipment(int Mod, int Row, int Col, int* Equi, int* Colu, int* Dilo, int* Chan); - static void Equipment2Module(int Equi, int Colu, int Dilo, int Chan, int* Mod, int* Row, int* Col); - - // from - //static constexpr Bool_t FEAWITHMASKS[NSECTORS] = - // // TOF sectors with Nino masks: 0, 8, 9, 10, 16 - // {kTRUE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, - // kTRUE, kTRUE, kFALSE, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, kFALSE}; - //; // Selecting TOF sectors containing FEA cooling masks - - // static Float_t getCableLength(Int_t icrate, Int_t islot, Int_t ichain, Int_t itdc) { return CABLELENGTH[icrate][islot - 3][ichain][itdc / 3]; } - - private: - static void Init(); - - ClassDefNV(Geo, 1); -}; ->>>>>>> refs/heads/dev } // namespace hmpid } // namespace o2 diff --git a/Detectors/HMPID/base/src/Digit.cxx b/Detectors/HMPID/base/src/Digit.cxx index fa92ce19bdad8..2711a642a2971 100644 --- a/Detectors/HMPID/base/src/Digit.cxx +++ b/Detectors/HMPID/base/src/Digit.cxx @@ -30,7 +30,6 @@ using namespace o2::hmpid; ClassImp(o2::hmpid::Digit); // ============= Digit Class implementation ======= -<<<<<<< HEAD /// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC) /// The mapping of the digit is in the Photo Cathod coords /// (Chamber, PhotoCathod, X, Y) @@ -39,24 +38,9 @@ ClassImp(o2::hmpid::Digit); /// @param[in] pad : the Digit Unique Id [0x00CPXXYY] /// @param[in] charge : the value of the charge [0 .. 2^12-1] Digit::Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) -======= - -/// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC) -/// The mapping of the digit is in the Photo Cathod coords -/// (Chamber, PhotoCathod, X, Y) -/// @param[in] bc : the bunch crossing [0 .. 2^12-1] -/// @param[in] orbit : the orbit number [0 .. 2^32-1] -/// @param[in] chamber : the HMPID module [0 .. 6] -/// @param[in] photo : the photo cathode number [0 .. 5] (left-down to right-up) -/// @param[in] x : the horizontal in cathode displacement [0 .. 79] -/// @param[in] y : the vertical in cathode displacement [0 .. 47] -/// @param[in] charge : the value of the charge [0 .. 2^12-1] -Digit::Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge) ->>>>>>> refs/heads/dev { mBc = bc; mOrbit = orbit; -<<<<<<< HEAD mQ = charge > 0x0FFF ? 0x0FFF : charge; mPad = pad; } @@ -111,44 +95,6 @@ Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, in mBc = bc; mOrbit = orbit; mQ = charge > 0x0FFF ? 0x0FFF : charge; -======= - mQ = charge; - mPad = Abs(chamber, photo, x, y); -} - -/// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC) -/// The mapping of the digit is in the Hardware coords -/// (Equipment, Column, Dilogic, Channel) -/// @param[in] bc : the bunch crossing [0 .. 2^12-1] -/// @param[in] orbit : the orbit number [0 .. 2^32-1] -/// @param[in] charge : the value of the charge [0 .. 2^12-1] -/// @param[in] equipment : the HMPID DDL link [0 .. 13] -/// @param[in] column : the readout column number [0 .. 23] -/// @param[in] dilogic : the displacement in the Dilogics chain [0 .. 9] -/// @param[in] channel : the number of gassiplexes channels [0 .. 47] -Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int column, int dilogic, int channel) -{ - mBc = bc; - mOrbit = orbit; - mQ = charge; - mPad = Equipment2Pad(equipment, column, dilogic, channel); -} - -/// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC) -/// The mapping of the digit is in the Logical coords -/// (Module, X, Y) -/// @param[in] bc : the bunch crossing [0 .. 2^12-1] -/// @param[in] orbit : the orbit number [0 .. 2^32-1] -/// @param[in] charge : the value of the charge [0 .. 2^12-1] -/// @param[in] module : the HMPID Module [0 .. 6] -/// @param[in] x : the horizontal in Module displacement [0 .. 159] -/// @param[in] y : the vertical in Module displacement [0 .. 143] -Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, int y) -{ - mBc = bc; - mOrbit = orbit; - mQ = charge; ->>>>>>> refs/heads/dev mPad = Absolute2Pad(module, x, y); } @@ -437,7 +383,6 @@ Double_t Digit::OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) /// @return : the Orbit number [0..2^32-1] uint32_t Digit::TimeNsToOrbit(Double_t TimeNs) { -<<<<<<< HEAD return (uint32_t)(TimeNs / o2::constants::lhc::LHCOrbitNS); } @@ -449,19 +394,6 @@ uint32_t Digit::TimeNsToOrbit(Double_t TimeNs) uint16_t Digit::TimeNsToBc(Double_t TimeNs) { return (uint16_t)(std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); -======= - return (TimeNs / o2::constants::lhc::LHCOrbitNS); -} - -/// TimeNsToBc : Extracts the Bunch Crossing number from the absolute -/// nanoseconds time. -/// -/// @param[in] TimeNs : the absolute nanoseconds time -/// @return : the Bunch Crossing number [0..2^12-1] -uint16_t Digit::TimeNsToBc(Double_t TimeNs) -{ - return (std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); ->>>>>>> refs/heads/dev } /// TimeNsToOrbitBc : Extracts the (Orbit,BC) pair from the absolute diff --git a/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h b/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h index 2492a2593ad3c..462c67964ceed 100644 --- a/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h +++ b/Detectors/HMPID/base/src/HMPIDBaseLinkDef.h @@ -22,10 +22,7 @@ #pragma link C++ class o2::hmpid::HitType + ; #pragma link C++ class vector < o2::hmpid::HitType> + ; #pragma link C++ class o2::hmpid::Geo + ; -<<<<<<< HEAD #pragma link C++ class o2::hmpid::Trigger + ; #pragma link C++ class vector < o2::hmpid::Trigger> + ; -======= ->>>>>>> refs/heads/dev #endif diff --git a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx index 218a2a71aba90..4985d3b6e18f8 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidDecoder.cxx @@ -12,7 +12,6 @@ /// \file HmpidDecoder.cxx /// \author Antonio Franco - INFN Bari /// \brief Base Class to decode HMPID Raw Data stream -<<<<<<< HEAD /// \version 1.1 /// \date 17/11/2020 @@ -833,815 +832,6 @@ void HmpidDecoder::decodePageFast(uint32_t** streamBuf) /// ATTENTION : Assumes that the input stream was set /// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header bool HmpidDecoder::decodeBufferFast() -{ - // ---------resets the PAdMap----------- - for (int i = 0; i < mNumberOfEquipments; i++) { - mTheEquipments[i]->init(); - mTheEquipments[i]->resetPadMap(); - } -======= -/// \version 1.0 -/// \date 17/11/2020 - -/* ------ HISTORY --------- -*/ - -#include "Framework/Logger.h" -#include "Headers/RAWDataHeader.h" -#include "HMPIDReconstruction/HmpidDecoder.h" -#include "HMPIDBase/Digit.h" - -using namespace o2::hmpid; - -// ============= HmpidDecoder Class implementation ======= - -/// Decoding Error Messages Definitions -char HmpidDecoder::sErrorDescription[MAXERRORS][MAXDESCRIPTIONLENGHT] = {"Word that I don't known !", - "Row Marker Word with 0 words", "Duplicated Pad Word !", "Row Marker Wrong/Lost -> to EoE", - "Row Marker Wrong/Lost -> to EoE", "Row Marker reports an ERROR !", "Lost EoE Marker !", "Double EoE marker", - "Wrong size definition in EoE Marker", "Double Mark Word", "Wrong Size in Segment Marker", "Lost EoS Marker !", - "HMPID Header Errors"}; - -/// HMPID Firmware Error Messages Definitions -char HmpidDecoder::sHmpidErrorDescription[MAXHMPIDERRORS][MAXDESCRIPTIONLENGHT] = { - "L0 Missing," - "L1 is received without L0", - "L1A signal arrived before the L1 Latency", "L1A signal arrived after the L1 Latency", - "L1A is missing or L1 timeout", "L1A Message is missing or L1 Message"}; - -/// Constructor : accepts the number of equipments to define -/// The mapping is the default at P2 -/// Allocates instances for all defined equipments -/// normally it is equal to 14 -/// @param[in] numOfEquipments : the number of equipments to define [1..14] -HmpidDecoder::HmpidDecoder(int numOfEquipments) -{ - // The standard definition of HMPID equipments at P2 - int EqIds[] = {0, 1, 2, 3, 4, 5, 8, 9, 6, 7, 10, 11, 12, 13}; - int CruIds[] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3}; - int LinkIds[] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 0, 1, 2}; - - mNumberOfEquipments = numOfEquipments; - for (int i = 0; i < mNumberOfEquipments; i++) { - mTheEquipments[i] = new HmpidEquipment(EqIds[i], CruIds[i], LinkIds[i]); - } -} - -/// Constructor : accepts the number of equipments to define -/// and their complete address map -/// Allocates instances for all defined equipments -/// -/// The Address map is build from three array -/// @param[in] numOfEquipments : the number of equipments to define [1..14] -/// @param[in] *EqIds : the pointer to the Equipments ID array -/// @param[in] *CruIds : the pointer to the CRU ID array -/// @param[in] *LinkIds : the pointer to the Link ID array -HmpidDecoder::HmpidDecoder(int* EqIds, int* CruIds, int* LinkIds, int numOfEquipments) -{ - mNumberOfEquipments = numOfEquipments; - for (int i = 0; i < mNumberOfEquipments; i++) { - mTheEquipments[i] = new HmpidEquipment(EqIds[i], CruIds[i], LinkIds[i]); - } -} - -/// Destructor : remove the Equipments instances -HmpidDecoder::~HmpidDecoder() -{ - for (int i = 0; i < mNumberOfEquipments; i++) { - delete mTheEquipments[i]; - } -} - -/// Resets to 0 all the class members -void HmpidDecoder::init() -{ - mRDHAcceptedVersion = 6; - mRDHSize = sizeof(o2::header::RAWDataHeaderV6) / sizeof(uint32_t); - - mVerbose = 0; - mHeEvent = 0; - mHeBusy = 0; - mNumberWordToRead = 0; - mPayloadTail = 0; - - mHeFEEID = 0; - mHeSize = 0; - mHeVer = 0; - mHePrior = 0; - mHeStop = 0; - mHePages = 0; - mEquipment = 0; - - mHeOffsetNewPack = 0; - mHeMemorySize = 0; - - mHeDetectorID = 0; - mHeDW = 0; - mHeCruID = 0; - mHePackNum = 0; - mHePAR = 0; - mHePageNum = 0; - mHeLinkNum = 0; - mHeFirmwareVersion = 0; - mHeHmpidError = 0; - mHeBCDI = 0; - mHeORBIT = 0; - mHeTType = 0; - - mActualStreamPtr = nullptr; - mEndStreamPtr = nullptr; - mStartStreamPtr = nullptr; - - for (int i = 0; i < mNumberOfEquipments; i++) { - mTheEquipments[i]->init(); - } -} - -/// Returns the Equipment Index (Pointer of the array) converting -/// the FLP hardware coords (CRU_Id and Link_Id) -/// @param[in] CruId : the CRU ID [0..3] -> FLP 160 = [0,1] FLP 161 = [2,3] -/// @param[in] LinkId : the Link ID [0..3] -/// @returns EquipmentIndex : the index in the Equipment array [0..13] (-1 := error) -int HmpidDecoder::getEquipmentIndex(int CruId, int LinkId) -{ - for (int i = 0; i < mNumberOfEquipments; i++) { - if (mTheEquipments[i]->getEquipmentId(CruId, LinkId) != -1) { - return (i); - } - } - return (-1); -} - -/// Returns the Equipment Index (Pointer of the array) converting -/// the Equipment_ID (Firmaware defined Id AKA FFEID) -/// @param[in] EquipmentId : the Equipment ID [0..13] -/// @returns EquipmentIndex : the index in the Equipment array [0..13] (-1 := error) -int HmpidDecoder::getEquipmentIndex(int EquipmentId) -{ - for (int i = 0; i < mNumberOfEquipments; i++) { - if (mTheEquipments[i]->getEquipmentId() == EquipmentId) { - return (i); - } - } - return (-1); -} - -/// Returns the Equipment_ID converting the FLP hardware coords -/// @param[in] CruId : the CRU ID [0..3] -> FLP 160 = [0,1] FLP 161 = [2,3] -/// @param[in] LinkId : the Link ID [0..3] -/// @returns EquipmentID : the ID of the Equipment [0..13] (-1 := error) -int HmpidDecoder::getEquipmentID(int CruId, int LinkId) -{ - for (int i = 0; i < mNumberOfEquipments; i++) { - if (mTheEquipments[i]->getEquipmentId(CruId, LinkId) != -1) { - return (mTheEquipments[i]->getEquipmentId()); - } - } - return (-1); -} - -/// Scans the BitMap of Raw Data File word and detect the type -/// and the parameters -/// @param[in] wp : the word to analyze -/// @param[out] *p1 : first parameter extract (if it exists) -/// @param[out] *p2 : second parameter extract (if it exists) -/// @param[out] *p3 : third parameter extract (if it exists) -/// @param[out] *p4 : fourth parameter extract (if it exists) -/// @returns Type of Word : the type of word [0..4] (0 := undetect) -int HmpidDecoder::checkType(uint32_t wp, int* p1, int* p2, int* p3, int* p4) -{ - if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 || (wp & 0x0800ffff) == 0x080010A0) { - *p2 = (wp & 0x03ff0000) >> 16; // Number of words of row - *p1 = wp & 0x0000ffff; - return (WTYPE_ROW); - } - if ((wp & 0xfff00000) >> 20 == 0xAB0) { - *p2 = (wp & 0x000fff00) >> 8; // Number of words of Segment - *p1 = (wp & 0xfff00000) >> 20; - *p3 = wp & 0x0000000F; - if (*p3 < 4 && *p3 > 0) { - return (WTYPE_EOS); - } - } - // #EX MASK Raul 0x3803FF80 # ex mask 0xF803FF80 - this is EoE marker 0586800B0 - if ((wp & 0x0803FF80) == 0x08000080) { - *p1 = (wp & 0x07c00000) >> 22; - *p2 = (wp & 0x003C0000) >> 18; - *p3 = (wp & 0x0000007F); - if (*p1 < 25 && *p2 < 11) { - return (WTYPE_EOE); - } - } - if ((wp & 0x08000000) == 0) { // # this is a pad - // PAD:0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value - *p1 = (wp & 0x07c00000) >> 22; - *p2 = (wp & 0x003C0000) >> 18; - *p3 = (wp & 0x0003F000) >> 12; - *p4 = (wp & 0x00000FFF); - if (*p1 > 0 && *p1 < 25 && *p2 > 0 && *p2 < 11 && *p3 < 48) { - return (WTYPE_PAD); - } - } else { - return (WTYPE_NONE); - } - return (WTYPE_NONE); -} - -/// Checks if is a Raw Marker and extract the Row Size -/// @param[in] wp : the word to check -/// @param[out] *Err : true if an error is detected -/// @param[out] *rowSize : the number of words of the row -/// @param[out] *mark : the row marker -/// @returns True if Row Marker is detected -bool HmpidDecoder::isRowMarker(uint32_t wp, int* Err, int* rowSize, int* mark) -{ - if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 || (wp & 0x0800ffff) == 0x080010A0) { - *rowSize = (wp & 0x03ff0000) >> 16; // # Number of words of row - *mark = wp & 0x0000ffff; - *Err = false; - return (true); - } else { - *Err = true; - return (false); - } -} - -/// Checks if is a Segment Marker and extracts the Segment number and the size -/// @param[in] wp : the word to check -/// @param[out] *Err : true if an error is detected -/// @param[out] *segSize : the number of words of the segment -/// @param[out] *Seg : the Segment number [1..3] -/// @param[out] *mark : the Segment Marker -/// @returns True if Segment Marker is detected -bool HmpidDecoder::isSegmentMarker(uint32_t wp, int* Err, int* segSize, int* Seg, int* mark) -{ - *Err = false; - if ((wp & 0xfff00000) >> 20 == 0xAB0) { - *segSize = (wp & 0x000fff00) >> 8; // # Number of words of Segment - *mark = (wp & 0xfff00000) >> 20; - *Seg = wp & 0x0000000F; - - if (*Seg > 3 || *Seg < 1) { - LOG(INFO) << " Wrong segment Marker Word, bad Number of segment" << *Seg << "!"; - *Err = true; - } - return (true); - } else { - return (false); - } -} - -/// Checks if is a PAD Word and extracts all the parameters -/// PAD map : 0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value -/// @param[in] wp : the word to check -/// @param[out] *Err : true if an error is detected -/// @param[out] *Col : the column number [1..24] -/// @param[out] *Dilogic : the dilogic number [1..10] -/// @param[out] *Channel : the channel number [0..47] -/// @param[out] *Charge : the value of Charge [0..4095] -/// @returns True if PAD Word is detected -bool HmpidDecoder::isPadWord(uint32_t wp, int* Err, int* Col, int* Dilogic, int* Channel, int* Charge) -{ - *Err = false; - if ((wp & 0x0000ffff) == 0x36A8 || (wp & 0x0000ffff) == 0x32A8 || (wp & 0x0000ffff) == 0x30A0 || (wp & 0x0800ffff) == 0x080010A0 || (wp & 0x08000000) != 0) { // # ! this is a pad - return (false); - } else { - *Col = (wp & 0x07c00000) >> 22; - *Dilogic = (wp & 0x003C0000) >> 18; - *Channel = (wp & 0x0003F000) >> 12; - *Charge = (wp & 0x00000FFF); - if (*Dilogic > 10 || *Channel > 47 || *Dilogic < 1 || *Col > 24 || *Col < 1) { - LOG(WARNING) << " Wrong Pad values Col=" << *Col << " Dilogic=" << *Dilogic << " Channel=" << *Channel << " Charge=" << *Charge; - *Err = true; - } - return (true); - } -} - -/// Checks if is a EoE Marker and extracts the Column, Dilogic and the size -/// @param[in] wp : the word to check -/// @param[out] *Err : true if an error is detected -/// @param[out] *Col : the column number [1..24] -/// @param[out] *Dilogic : the dilogic number [1..10] -/// @param[out] *Eoesize : the number of words for dilogic -/// @returns True if EoE marker is detected -bool HmpidDecoder::isEoEmarker(uint32_t wp, int* Err, int* Col, int* Dilogic, int* Eoesize) -{ - *Err = false; - // #EX MASK Raul 0x3803FF80 # ex mask 0xF803FF80 - this is EoE marker 0586800B0 - if ((wp & 0x0803FF80) == 0x08000080) { - *Col = (wp & 0x07c00000) >> 22; - *Dilogic = (wp & 0x003C0000) >> 18; - *Eoesize = (wp & 0x0000007F); - if (*Col > 24 || *Dilogic > 10) { - LOG(INFO) << " EoE size wrong definition. Col=" << *Col << " Dilogic=" << *Dilogic; - *Err = true; - } - return (true); - } else { - return (false); - } -} - -/// Decode the HMPID error BitMap field (5 bits) and returns true if there are -/// errors and in addition the concat string that contains the error messages -/// ATTENTION : the char * outbuf MUST point to a 250 bytes buffer -/// @param[in] ErrorField : the HMPID Error field -/// @param[out] *outbuf : the output buffer that contains the error description -/// @returns True if EoE marker is detected -bool HmpidDecoder::decodeHmpidError(int ErrorField, char* outbuf) -{ - int res = false; - outbuf[0] = '\0'; - for (int i = 0; i < MAXHMPIDERRORS; i++) { - if ((ErrorField & (0x01 << i)) != 0) { - res = true; - strcat(outbuf, sHmpidErrorDescription[i]); - } - } - return (res); -} - -/// This Decode the Raw Data Header, returns the EquipmentIndex -/// that is obtained with the FLP hardware coords -/// -/// ATTENTION : the 'EquipIndex' parameter and the mEquipment member -/// are different data: the first is the pointer in the Equipments instances -/// array, the second is the FEE_ID number -/// -/// The EVENT_NUMBER : actually is calculated from the ORBIT number -/// -/// @param[in] *streamPtrAdr : the pointer to the Header buffer -/// @param[out] *EquipIndex : the Index to the Equipment Object Array [0..13] -/// @returns True every time -/// @throws TH_WRONGEQUIPINDEX Thrown if the Equipment Index is out of boundary (Equipment not recognized) -int HmpidDecoder::decodeHeader(uint32_t* streamPtrAdr, int* EquipIndex) -{ - uint32_t* buffer = streamPtrAdr; // Sets the pointer to buffer - o2::header::RAWDataHeaderV6* hpt = (o2::header::RAWDataHeaderV6*)buffer; - - /* - mHeFEEID = (buffer[0] & 0x000f0000) >> 16; - mHeSize = (buffer[0] & 0x0000ff00) >> 8; - mHeVer = (buffer[0] & 0x000000ff); - mHePrior = (buffer[1] & 0x000000FF); - mHeDetectorID = (buffer[1] & 0x0000FF00) >> 8; - mHeOffsetNewPack = (buffer[2] & 0x0000FFFF); - mHeMemorySize = (buffer[2] & 0xffff0000) >> 16; - mHeDW = (buffer[3] & 0xF0000000) >> 24; - mHeCruID = (buffer[3] & 0x0FF0000) >> 16; - mHePackNum = (buffer[3] & 0x0000FF00) >> 8; - mHeLinkNum = (buffer[3] & 0x000000FF); - mHeBCDI = (buffer[4] & 0x00000FFF); - mHeORBIT = buffer[5]; - mHeTType = buffer[8]; - mHePageNum = (buffer[9] & 0x0000FFFF); - mHeStop = (buffer[9] & 0x00ff0000) >> 16; - mHeBusy = (buffer[12] & 0xfffffe00) >> 9; - mHeFirmwareVersion = buffer[12] & 0x0000000f; - mHeHmpidError = (buffer[12] & 0x000001F0) >> 4; - mHePAR = buffer[13] & 0x0000FFFF; - */ - mHeFEEID = hpt->feeId; - mHeSize = hpt->headerSize; - mHeVer = hpt->version; - mHePrior = hpt->priority; - mHeDetectorID = hpt->sourceID; - mHeOffsetNewPack = hpt->offsetToNext; - mHeMemorySize = hpt->memorySize; - mHeDW = hpt->endPointID; - mHeCruID = hpt->cruID; - mHePackNum = hpt->packetCounter; - mHeLinkNum = hpt->linkID; - mHeBCDI = hpt->bunchCrossing; - mHeORBIT = hpt->orbit; - mHeTType = hpt->triggerType; - mHePageNum = hpt->pageCnt; - mHeStop = hpt->stop; - mHeBusy = (hpt->detectorField & 0xfffffe00) >> 9; - mHeFirmwareVersion = hpt->detectorField & 0x0000000f; - mHeHmpidError = (hpt->detectorField & 0x000001F0) >> 4; - mHePAR = hpt->detectorPAR; - - *EquipIndex = getEquipmentIndex(mHeCruID, mHeLinkNum); - // mEquipment = (*EquipIndex != -1) ? mTheEquipments[*EquipIndex]->getEquipmentId() : -1; - mEquipment = mHeFEEID & 0x000F; - mNumberWordToRead = ((mHeMemorySize - mHeSize) / sizeof(uint32_t)); - mPayloadTail = ((mHeOffsetNewPack - mHeMemorySize) / sizeof(uint32_t)); - - // ---- Event ID : Actualy based on ORBIT NUMBER and BC - mHeEvent = (mHeORBIT << 12) | mHeBCDI; - - LOG(DEBUG) << "FEE-ID=" << mHeFEEID << " HeSize=" << mHeSize << " HePrior=" << mHePrior << " Det.Id=" << mHeDetectorID << " HeMemorySize=" << mHeMemorySize << " HeOffsetNewPack=" << mHeOffsetNewPack; - LOG(DEBUG) << " Equipment=" << mEquipment << " PakCounter=" << mHePackNum << " Link=" << mHeLinkNum << " CruID=" << mHeCruID << " DW=" << mHeDW << " BC=" << mHeBCDI << " ORBIT=" << mHeORBIT; - LOG(DEBUG) << " TType=" << mHeTType << " HeStop=" << mHeStop << " PagesCounter=" << mHePageNum << " FirmVersion=" << mHeFirmwareVersion << " BusyTime=" << mHeBusy << " Error=" << mHeHmpidError << " PAR=" << mHePAR; - LOG(DEBUG) << " EquIdx = " << *EquipIndex << " Event = " << mHeEvent << " Payload : Words to read=" << mNumberWordToRead << " PailoadTail=" << mPayloadTail; - - if (*EquipIndex == -1) { - LOG(ERROR) << "ERROR ! Bad equipment Number: " << mEquipment; - throw TH_WRONGEQUIPINDEX; - } - // std::cout << "HMPID ! Exit decode header" << std::endl; - return (true); -} - -/// Updates some information related to the Event -/// this function is called at the end of the event -/// @param[in] *eq : the pointer to the Equipment Object -void HmpidDecoder::updateStatistics(HmpidEquipment* eq) -{ - eq->mPadsPerEventAverage = ((eq->mPadsPerEventAverage * (eq->mNumberOfEvents - 1)) + eq->mSampleNumber) / (eq->mNumberOfEvents); - eq->mEventSizeAverage = ((eq->mEventSizeAverage * (eq->mNumberOfEvents - 1)) + eq->mEventSize) / (eq->mNumberOfEvents); - eq->mBusyTimeAverage = ((eq->mBusyTimeAverage * eq->mBusyTimeSamples) + eq->mBusyTimeValue) / (++(eq->mBusyTimeSamples)); - if (eq->mSampleNumber == 0) { - eq->mNumberOfEmptyEvents += 1; - } - if (eq->mErrorsCounter > 0) { - eq->mNumberOfWrongEvents += 1; - } - eq->mTotalPads += eq->mSampleNumber; - eq->mTotalErrors += eq->mErrorsCounter; - - // std::cout << ">>>>.. end >>> "<mNumberOfEvents<<" :" <mEventSize<<","<< eq->mEventSizeAverage<< ", "<mEventNumber<<" "<mEventNumber) { // Is a new event - if (eq->mEventNumber != OUTRANGEEVENTNUMBER) { // skip the first - updateStatistics(eq); // update previous statistics - } - eq->mNumberOfEvents++; - eq->mEventNumber = mHeEvent; - eq->mBusyTimeValue = mHeBusy * 0.00000005; - eq->mEventSize = 0; // reset the event - eq->mSampleNumber = 0; - eq->mErrorsCounter = 0; - } - eq->mEventSize += mNumberWordToRead * sizeof(uint32_t); // Calculate the size in bytes - if (mHeHmpidError != 0) { - LOG(INFO) << "HMPID Header reports an error : " << mHeHmpidError; - dumpHmpidError(mHeHmpidError); - eq->setError(ERR_HMPID); - } - // std::cout << ".. end evaluateHeaderContents = " << eq->mEventNumber << std::endl; - return (eq); -} - -void HmpidDecoder::decodePage(uint32_t** streamBuf) -{ - int equipmentIndex; - try { - getHeaderFromStream(streamBuf); - } catch (int e) { - // The stream end ! - LOG(DEBUG) << "End main decoding loop !"; - throw TH_BUFFEREMPTY; - } - try { - decodeHeader(*streamBuf, &equipmentIndex); - } catch (int e) { - LOG(ERROR) << "Failed to decode the Header !"; - throw TH_WRONGHEADER; - } - - HmpidEquipment* eq = evaluateHeaderContents(equipmentIndex); - - uint32_t wpprev = 0; - uint32_t wp = 0; - int newOne = true; - int p1, p2, p3, p4; - int error; - int type; - bool isIt; - - int payIndex = 0; - while (payIndex < mNumberWordToRead) { //start the payload loop word by word - if (newOne == true) { - wpprev = wp; - if (!getWordFromStream(&wp)) { // end the stream - break; - } - - type = checkType(wp, &p1, &p2, &p3, &p4); - if (type == WTYPE_NONE) { - if (eq->mWillBePad == true) { // try to recover the first pad ! - type = checkType((wp & 0xF7FFFFFF), &p1, &p2, &p3, &p4); - if (type == WTYPE_PAD && p3 == 0 && eq->mWordsPerDilogicCounter == 0) { - newOne = false; // # reprocess as pad - continue; - } - } - eq->setError(ERR_NOTKNOWN); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_NOTKNOWN] << " [" << wp << "]"; - eq->mWordsPerRowCounter++; - eq->mWordsPerSegCounter++; - payIndex++; - continue; - } - } - - if (eq->mWillBeRowMarker == true) { // #shoud be a Row Marker - if (type == WTYPE_ROW) { - eq->mColumnCounter++; - eq->mWordsPerSegCounter++; - eq->mRowSize = p2; - switch (p2) { - case 0: // Empty column - eq->setError(ERR_ROWMARKEMPTY); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKEMPTY] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - eq->mWillBeRowMarker = true; - break; - case 0x3FF: // Error in column - eq->setError(ERR_ROWMARKERROR); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKERROR] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - eq->mWillBeRowMarker = true; - break; - case 0x3FE: // Masked column - LOG(INFO) << "Equip=" << mEquipment << "The column=" << (eq->mSegment) * 8 + eq->mColumnCounter << " is Masked !"; - eq->mWillBeRowMarker = true; - break; - default: - eq->mWillBeRowMarker = false; - eq->mWillBePad = true; - break; - } - newOne = true; - } else { - if (wp == wpprev) { - eq->setError(ERR_DUPLICATEPAD); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - newOne = true; - } else if (type == WTYPE_EOE) { // # Could be a EoE - eq->mColumnCounter++; - eq->setError(ERR_ROWMARKWRONG); - eq->mWillBeRowMarker = false; - eq->mWillBePad = true; - newOne = true; - } else if (type == WTYPE_PAD) { //# Could be a PAD - eq->mColumnCounter++; - eq->setError(ERR_ROWMARKLOST); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - eq->mWillBeRowMarker = false; - eq->mWillBePad = true; - newOne = true; - } else if (type == WTYPE_EOS) { // # Could be a EoS - eq->mWillBeRowMarker = false; - eq->mWillBeSegmentMarker = true; - newOne = false; - } else { - eq->mColumnCounter++; - eq->setError(ERR_ROWMARKLOST); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_ROWMARKLOST] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - eq->mWillBeRowMarker = false; - eq->mWillBePad = true; - newOne = true; - } - } - } else if (eq->mWillBePad == true) { // # We expect a pad - //# PAD:0000.0ccc.ccdd.ddnn.nnnn.vvvv.vvvv.vvvv :: c=col,d=dilo,n=chan,v=value - // c = 1..24 d = 1..10 n = 0..47 - if (type == WTYPE_PAD) { - newOne = true; - if (wp == wpprev) { - eq->setError(ERR_DUPLICATEPAD); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - } else if (p1 != (eq->mSegment * 8 + eq->mColumnCounter)) { // # Manage - // We try to recover the RowMarker misunderstanding - isIt = isRowMarker(wp, &error, &p2, &p1); - if (isIt == true && error == false) { - type = WTYPE_ROW; - newOne = false; - eq->mWillBeEoE = true; - eq->mWillBePad = false; - } else { - LOG(DEBUG) << "Equip=" << mEquipment << " Mismatch in column" - << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - eq->mColumnCounter = p1 % 8; - } - } else { - setPad(eq, p1 - 1, p2 - 1, p3, p4); - eq->mWordsPerDilogicCounter++; - eq->mSampleNumber++; - if (p3 == 47) { - eq->mWillBeEoE = true; - eq->mWillBePad = false; - } - } - eq->mWordsPerRowCounter++; - eq->mWordsPerSegCounter++; - } else if (type == WTYPE_EOE) { //# the pads are end ok - eq->mWillBeEoE = true; - eq->mWillBePad = false; - newOne = false; - } else if (type == WTYPE_ROW) { // # We Lost the EoE ! - // We try to recover the PAD misunderstanding - isIt = isPadWord(wp, &error, &p1, &p2, &p3, &p4); - if (isIt == true && error == false) { - type = WTYPE_PAD; - newOne = false; // # reprocess as pad - } else { - eq->setError(ERR_LOSTEOEMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - eq->mWillBeRowMarker = true; - eq->mWillBePad = false; - newOne = false; - } - } else if (type == WTYPE_EOS) { // # We Lost the EoE ! - eq->setError(ERR_LOSTEOEMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - eq->mWillBeSegmentMarker = true; - eq->mWillBePad = false; - newOne = false; - } - } else if (eq->mWillBeEoE == true) { // # We expect a EoE - if (type == WTYPE_EOE) { - eq->mWordsPerRowCounter++; - eq->mWordsPerSegCounter++; - if (wpprev == wp) { - eq->setError(ERR_DOUBLEEOEMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEEOEMARK] << " col=" << p1; - } else if (p3 != eq->mWordsPerDilogicCounter) { - eq->setError(ERR_WRONGSIZEINEOE); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZEINEOE] << " col=" << p1; - } - eq->mWordsPerDilogicCounter = 0; - if (p2 == 10) { - if (p1 % 8 != 0) { // # we expect the Row Marker - eq->mWillBeRowMarker = true; - } else { - eq->mWillBeSegmentMarker = true; - } - } else { - eq->mWillBePad = true; - } - eq->mWillBeEoE = false; - newOne = true; - } else if (type == WTYPE_EOS) { // We Lost the EoE ! - eq->setError(ERR_LOSTEOEMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - eq->mWillBeSegmentMarker = true; - eq->mWillBeEoE = false; - newOne = false; - } else if (type == WTYPE_ROW) { //# We Lost the EoE ! - eq->setError(ERR_LOSTEOEMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - eq->mWillBeRowMarker = true; - eq->mWillBeEoE = false; - newOne = false; - } else if (type == WTYPE_PAD) { // # We Lost the EoE ! - int typb, p1b, p2b, p3b, p4b; - typb = checkType((wp | 0x08000000), &p1b, &p2b, &p3b, &p4b); - if (typb == WTYPE_EOE && p3b == 48) { - type = typb; - p1 = p1b; - p2 = p2b; - p3 = p3b; - p4 = p4b; - newOne = false; // # reprocess as EoE - } else { - eq->setError(ERR_LOSTEOEMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOEMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - eq->mWillBePad = true; - eq->mWillBeEoE = false; - newOne = false; - } - } - } else if (eq->mWillBeSegmentMarker == true) { // # We expect a EoSegment - if (wpprev == wp) { - eq->setError(ERR_DOUBLEMARKWORD); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DOUBLEMARKWORD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - newOne = true; - } else if (type == 2) { - if (abs(eq->mWordsPerSegCounter - p2) > 5) { - eq->setError(ERR_WRONGSIZESEGMENTMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_WRONGSIZESEGMENTMARK] << " Seg=" << p2; - } - eq->mWordsPerSegCounter = 0; - eq->mWordsPerRowCounter = 0; - eq->mColumnCounter = 0; - eq->mSegment = p3 % 3; - eq->mWillBeRowMarker = true; - eq->mWillBeSegmentMarker = false; - newOne = true; - } else { - eq->setError(ERR_LOSTEOSMARK); - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_LOSTEOSMARK] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << p1 << "]"; - eq->mWillBeSegmentMarker = false; - eq->mWillBeRowMarker = true; - newOne = false; - } - } - if (newOne) { - payIndex += 1; - } - } - for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail - getWordFromStream(&wp); - } -} - -/// --------------- Read Raw Data Buffer --------------- -/// Read the stream, decode the contents and store resuls. -/// ATTENTION : Assumes that the input stream was set -/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header -bool HmpidDecoder::decodeBuffer() -{ - // ---------resets the PAdMap----------- - for (int i = 0; i < mNumberOfEquipments; i++) { - mTheEquipments[i]->init(); - mTheEquipments[i]->resetPadMap(); - mTheEquipments[i]->resetErrors(); - } - - int type; - int equipmentIndex = -1; - int isIt; - HmpidEquipment* eq; - uint32_t* streamBuf; - LOG(DEBUG) << "Enter decoding !"; - - // Input Stream Main Loop - while (true) { - try { - decodePage(&streamBuf); - } catch (int e) { - LOG(DEBUG) << "End main buffer decoding loop !"; - break; - } - } // this is the end of stream - - // cycle in order to update info for the last event - for (int i = 0; i < mNumberOfEquipments; i++) { - if (mTheEquipments[i]->mNumberOfEvents > 0) { - updateStatistics(mTheEquipments[i]); - } - } - return (true); -} - -void HmpidDecoder::decodePageFast(uint32_t** streamBuf) -{ - int equipmentIndex; - try { - getHeaderFromStream(streamBuf); - } catch (int e) { - // The stream end ! - LOG(INFO) << "End Fast Page decoding loop !"; - throw TH_BUFFEREMPTY; - } - try { - decodeHeader(*streamBuf, &equipmentIndex); - } catch (int e) { - LOG(INFO) << "Failed to decode the Header !"; - throw TH_WRONGHEADER; - } - - HmpidEquipment* eq = evaluateHeaderContents(equipmentIndex); - - uint32_t wpprev = 0; - uint32_t wp = 0; - int newOne = true; - int Column, Dilogic, Channel, Charge; - int pwer; - - int payIndex = 0; - while (payIndex < mNumberWordToRead) { //start the payload loop word by word - wpprev = wp; - if (!getWordFromStream(&wp)) { // end the stream - break; - } - if (wp == wpprev) { - LOG(DEBUG) << "Equip=" << mEquipment << sErrorDescription[ERR_DUPLICATEPAD] << " col=" << (eq->mSegment) * 8 + eq->mColumnCounter << "[" << Column << "]"; - } else { - if (isPadWord(wp, &pwer, &Column, &Dilogic, &Channel, &Charge) == true) { - if (pwer != true) { - setPad(eq, Column - 1, Dilogic - 1, Channel, Charge); - eq->mSampleNumber++; - } - } - } - payIndex += 1; - } - for (int i = 0; i < mPayloadTail; i++) { // move the pointer to skip the Payload Tail - getWordFromStream(&wp); - } - return; -} -/// ---------- Read Raw Data Buffer with Fast Decoding ---------- -/// Read the stream, decode the contents and store resuls. -/// Fast alghoritm : no parsing of control words ! -/// ATTENTION : Assumes that the input stream was set -/// @throws TH_WRONGHEADER Thrown if the Fails to decode the Header -bool HmpidDecoder::decodeBufferFast() { // ---------resets the PAdMap----------- for (int i = 0; i < mNumberOfEquipments; i++) { @@ -1649,7 +839,6 @@ bool HmpidDecoder::decodeBufferFast() mTheEquipments[i]->resetPadMap(); } ->>>>>>> refs/heads/dev uint32_t* streamBuf; LOG(INFO) << "Enter FAST decoding !"; diff --git a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx index d6c8896e872a1..32983f4545742 100644 --- a/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx +++ b/Detectors/HMPID/reconstruction/src/HmpidEquipment.cxx @@ -34,6 +34,33 @@ HmpidEquipment::HmpidEquipment(int Equipment, int Cru, int Link) mEquipmentId = Equipment; mCruId = Cru; mLinkId = Link; + mWordsPerRowCounter = 0; + mBusyTimeAverage = 0; + mBusyTimeSamples = 0; + mBusyTimeValue = 0; + mTotalErrors = 0; + mTotalPads = 0; + mNumberOfEmptyEvents = 0; + mNumberOfEvents = 0; + mNumberOfWrongEvents = 0; + mWordsPerDilogicCounter = 0; + mWordsPerRowCounter = 0; + mWordsPerSegCounter = 0; + mEventSizeAverage = 0; + mErrorsCounter = 0; + mEventNumber = 0; + mEventSize = 0; + mPadsPerEventAverage = 0; + mSegment = 0; + mWillBeEoE = false; + mWillBePad = false; + mWillBeRowMarker = false; + mWillBeSegmentMarker = false; + mSampleNumber = 0; + mEventSizeAverage = 0; + mColumnCounter = 0; + mRowSize = 0; + mErrorPadsPerEvent = 0; return; } diff --git a/Detectors/HMPID/simulation/CMakeLists.txt b/Detectors/HMPID/simulation/CMakeLists.txt index ed1f657c9f9e3..181cb2ad1d2ed 100644 --- a/Detectors/HMPID/simulation/CMakeLists.txt +++ b/Detectors/HMPID/simulation/CMakeLists.txt @@ -10,22 +10,15 @@ o2_add_library(HMPIDSimulation SOURCES src/Detector.cxx src/HMPIDDigitizer.cxx src/HmpidCoder.cxx -<<<<<<< HEAD SOURCES src/HmpidCoder2.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDBase O2::DetectorsRaw ROOT::Physics) -======= - PUBLIC_LINK_LIBRARIES O2::HMPIDBase) ->>>>>>> refs/heads/dev o2_target_root_dictionary(HMPIDSimulation HEADERS include/HMPIDSimulation/Detector.h include/HMPIDSimulation/HmpidCoder.h -<<<<<<< HEAD include/HMPIDSimulation/HmpidCoder2.h -======= ->>>>>>> refs/heads/dev include/HMPIDSimulation/HMPIDDigitizer.h) diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h index f1b7a84d2a650..92643e54a56a4 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HMPIDDigitizer.h @@ -45,20 +45,12 @@ class HMPIDDigitizer // for the first trigger no busy check necessary mCurrentTriggerTime = timeNS; mReadoutCounter++; -<<<<<<< HEAD Trigger::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, mBc); -======= - Digit::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, mBc); ->>>>>>> refs/heads/dev return true; } else { if ((timeNS - mCurrentTriggerTime) > BUSYTIME) { mCurrentTriggerTime = timeNS; -<<<<<<< HEAD Trigger::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, mBc); -======= - Digit::TimeNsToOrbitBc(mCurrentTriggerTime, mOrbit, mBc); ->>>>>>> refs/heads/dev mReadoutCounter++; return true; } else { diff --git a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx index 8a8df6e7bcedf..aff73f8c1ab37 100644 --- a/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx +++ b/Detectors/HMPID/simulation/src/HMPIDDigitizer.cxx @@ -119,11 +119,7 @@ void HMPIDDigitizer::process(std::vector const& hits, std::v } else { // create digit ... and register // mDigits.emplace_back(mCurrentTriggerTime, pad, totalQ * fraction); -<<<<<<< HEAD mDigits.emplace_back(mBc, mOrbit, pad, totalQ * fraction); -======= - mDigits.emplace_back(mOrbit, mBc, pad, totalQ * fraction); ->>>>>>> refs/heads/dev mIndexForPad[pad] = mDigits.size() - 1; mInvolvedPads.emplace_back(pad); diff --git a/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h b/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h index 258d90085dba8..866728f3baad5 100644 --- a/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h +++ b/Detectors/HMPID/simulation/src/HMPIDSimulationLinkDef.h @@ -18,9 +18,6 @@ #pragma link C++ class o2::base::DetImpl < o2::hmpid::Detector> + ; #pragma link C++ class o2::hmpid::HMPIDDigitizer + ; #pragma link C++ class o2::hmpid::HmpidCoder + ; -<<<<<<< HEAD #pragma link C++ class o2::hmpid::HmpidCoder2 + ; -======= ->>>>>>> refs/heads/dev #endif diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index c339c5eb3efe6..1c171fbef864d 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -15,7 +15,6 @@ o2_add_library(HMPIDWorkflow src/DumpDigitsSpec.cxx src/ReadRawFileSpec.cxx src/WriteRawFromDigitsSpec.cxx -<<<<<<< HEAD src/WriteRawFromRootSpec.cxx src/PedestalsCalculationSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework @@ -64,49 +63,5 @@ o2_add_executable(raw-to-pedestals-workflow o2_add_executable(write-raw-from-root-workflow COMPONENT_NAME hmpid SOURCES src/write-raw-from-root-workflow.cxx -======= - src/PedestalsCalculationSpec.cxx - PUBLIC_LINK_LIBRARIES O2::Framework - O2::CCDB - O2::DPLUtils - O2::DetectorsRaw - O2::HMPIDBase - O2::HMPIDSimulation - O2::HMPIDReconstruction) - -o2_add_executable(recoworkflow - COMPONENT_NAME hmpid - SOURCES src/HMPIDRecoWorkflow.cxx - PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) - -o2_add_executable(read-raw-file-workflow - COMPONENT_NAME hmpid - SOURCES src/read-raw-file-workflow.cxx - PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) - -o2_add_executable(raw-to-digits-workflow - COMPONENT_NAME hmpid - SOURCES src/raw-to-digits-workflow.cxx - PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) - -o2_add_executable(write-raw-from-digits-workflow - COMPONENT_NAME hmpid - SOURCES src/write-raw-from-digits-workflow.cxx - PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) - -o2_add_executable(dump-digits-workflow - COMPONENT_NAME hmpid - SOURCES src/dump-digits-workflow.cxx - PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) - -o2_add_executable(write-root-from-digits-workflow - COMPONENT_NAME hmpid - SOURCES src/write-root-from-digits-workflow.cxx - PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) - -o2_add_executable(raw-to-pedestals-workflow - COMPONENT_NAME hmpid - SOURCES src/raw-to-pedestals-workflow.cxx ->>>>>>> refs/heads/dev PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) \ No newline at end of file diff --git a/Detectors/HMPID/workflow/README.md b/Detectors/HMPID/workflow/README.md index ddec42ec94c2e..20e0c87b307ec 100644 --- a/Detectors/HMPID/workflow/README.md +++ b/Detectors/HMPID/workflow/README.md @@ -2,7 +2,6 @@ \page refHMPworkflow HMP workflow /doxy --> -<<<<<<< HEAD # DPL workflows for the HMPID v.0.4 ## HMPID DPL processors @@ -151,119 +150,6 @@ in order to verify the write, the inverse decoding of raw file [O2Suite/latest-o2] ~/Downloads/provaRec $>o2-hmpid-read-raw-file-workflow --raw-file hmpRawFromRoot.raw -b | o2-hmpid-raw-to-digits-workflow -b | o2-hmpid-dump-digits-workflow --out-file /tmp/hmpDumpDigitsVerify.dat ``` -======= -# DPL workflows for the HMPID v.0.3 - -## HMPID DPL processors - -* `hmpid-read-raw-file` reads data from ReadOut Raw File and outputs a stream of RDH6 pages as HMP/RAWDATA stream -* `hmpid-raw-to-digits` decodes the input raw pages stream (HMP/RAWDATA) and produces a vector of o2::hmpid::Digits (HMP/DIGITS) -* `hmpid-write-raw-from-digits` codes input o2::hmpid::Digits vector (HMP/DIGITS) into the binary HMPID raw file -* `hmpid-dump-digits` dumps the input o2::hmpid::Digits vector (HMP/DIGITS) to the stdout or in a ASCII file - -### Workflow example -The input is a HMPID rawfile and after the decoding the result is a reconstructed rawfile. - -``` - o2-hmpid-read-raw-file-workflow --raw-file test_full_flp1.raw -b | o2-hmpid-raw-to-digits-workflow -b | o2-hmpid-write-raw-from-digits-workflow --out-file /tmp/pippo -b -``` - -This reads the `test_full_flp1.raw` file and after the decodeing produce a couple of raw files in the /tmp/ folder that are prefixed with `pippo` - - - -### o2-hmpid-read-raw-file-workflow -Reads data from ReadOut Raw File and outputs a stream of RDH6 pages as HMP/RAWDATA stream. - -Display all options - -``` -o2-hmpid-read-raw-file-workflow --help full -``` - -Data processor options: HMP-ReadRawFile: - -``` ---raw-file arg Raw input file name -``` - -### o2-hmpid-raw-to-digits-workflow -Decodes the input raw pages stream (HMP/RAWDATA) and produces a vector of o2::hmpid::Digits (HMP/DIGITS). - -Display all options - -``` -o2-hmpid-raw-to-digits-workflow --help full -``` - -Data processor options: HMP-DataDecoder: - -``` - --root-file arg (=/tmp/hmpRawDecodeResults) - Name of the Root file with the decoding - results. -``` - - -### o2-hmpid-write-raw-from-digits-workflow -Codes input o2::hmpid::Digits vector (HMP/DIGITS) into the binary HMPID raw file. - -Display all options - -``` -o2-hmpid-write-raw-from-digits-workflow --help full -``` - -Data processor options: HMP-WriteRawFromDigits: - -``` - --out-file arg (=hmpidRaw) name prefix of the two output files - --order-events order the events in ascending time - --skip-empty skip empty events - --fixed-lenght fixed lenght packets = 8K bytes -``` - - -### o2-hmpid-dump-digits-workflow -Dumps the input o2::hmpid::Digits vector (HMP/DIGITS) to the stdout or in a ASCII file. - -Display all options - -``` -o2-hmpid-dump-digits-workflow --help full -``` - -Data processor options: HMP-DigitsDump: - -``` - --out-file arg name of the output file - --print print digits (default false ) -``` - - -### o2-hmpid-write-root-from-digits-workflow -Write the digit stream into a root formatted file - -``` -o2-hmpid-write-root-from-digit-workflow --help full -``` - -Data processor options: HMPDigitWriter: - -``` - --outfile arg (=hmpiddigits.root) Name of the output file - --treename arg (=o2sim) Name of tree - --treetitle arg (=o2sim) Title of tree - --nevents arg (=-1) Number of events to execute - --terminate arg (=process) Terminate the 'process' or 'workflow' -``` - -Example - -``` -[O2Suite/latest-o2] ~/Downloads/provaRec $> o2-hmpid-read-raw-file-workflow --raw-file test_full_flp1.raw -b | o2-hmpid-raw-to-digits-workflow -b | o2-hmpid-write-root-from-digits-workflow -b -``` ->>>>>>> refs/heads/dev ### o2-hmpid-raw-to-pedestals-workflow Write the Pedestals/Threshold files for the readout and registers Mean and Sigma in the CCDB diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h index 6b1b7901edfc4..d10e07b1046f5 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRootFromDigitsSpec.h @@ -15,7 +15,6 @@ #include "DPLUtils/MakeRootTreeWriterSpec.h" #include "Framework/InputSpec.h" #include "HMPIDBase/Digit.h" -<<<<<<< HEAD #include "HMPIDBase/Trigger.h" #include "SimulationDataFormat/MCTruthContainer.h" #include "SimulationDataFormat/MCCompLabel.h" @@ -33,24 +32,6 @@ o2::framework::DataProcessorSpec getWriteRootFromDigitSpec(bool mctruth = false) using InputSpec = framework::InputSpec; using MakeRootTreeWriterSpec = framework::MakeRootTreeWriterSpec; return MakeRootTreeWriterSpec("HMPRootFileWriter", -======= -#include "SimulationDataFormat/MCTruthContainer.h" -#include "SimulationDataFormat/MCCompLabel.h" - -namespace o2 -{ -namespace hmpid -{ - -template -using BranchDefinition = framework::MakeRootTreeWriterSpec::BranchDefinition; - -o2::framework::DataProcessorSpec getWriteRootFromDigitSpec(bool mctruth = false) -{ - using InputSpec = framework::InputSpec; - using MakeRootTreeWriterSpec = framework::MakeRootTreeWriterSpec; - return MakeRootTreeWriterSpec("HMPDigitWriter", ->>>>>>> refs/heads/dev "hmpiddigits.root", "o2sim", -1, diff --git a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx index 82c733f625f3c..02a8142ad4b46 100644 --- a/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx +++ b/Detectors/HMPID/workflow/src/DataDecoderSpec.cxx @@ -113,7 +113,6 @@ void DataDecoderTask::endOfStream(framework::EndOfStreamContext& ec) theObj[Geo::N_MODULES]->Branch("Average_Event_Size", &avgEventSize, "F"); theObj[Geo::N_MODULES]->Branch("Average_Busy_Time", &avgBusyTime, "F"); -<<<<<<< HEAD // Update the Stat for the Decoding int numEqui = mDeco->getNumberOfEquipments(); // cycle in order to update info for the last event @@ -170,57 +169,6 @@ void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); // mTotalDigits += mDeco->mDigits.size(); //LOG(INFO) << "Writing " << mDeco->mDigits.size() << "/" << mTotalDigits << " Digits ..."; -======= - char summaryFileName[254]; - sprintf(summaryFileName, "%s_stat.txt", mRootStatFile.c_str()); - mDeco->writeSummaryFile(summaryFileName); - int numEqui = mDeco->getNumberOfEquipments(); - for (int e = 0; e < numEqui; e++) { - avgEventSize = mDeco->getAverageEventSize(e); - avgBusyTime = mDeco->getAverageBusyTime(e); - theObj[Geo::N_MODULES]->Fill(); - } - for (int m = 0; m < o2::hmpid::Geo::N_MODULES; m++) { - for (int y = 0; y < o2::hmpid::Geo::N_YCOLS; y++) { - for (int x = 0; x < o2::hmpid::Geo::N_XROWS; x++) { - xb = x; - yb = y; - numOfSamples = mDeco->getPadSamples(m, x, y); - sumOfCharges = mDeco->getPadSum(m, x, y); - squareOfCharges = mDeco->getPadSquares(m, x, y); - theObj[m]->Fill(); - } - } - } - for (int i = 0; i <= Geo::N_MODULES; i++) { - theObj[i]->Write(); - } - - mExTimer.logMes("End the Decoding ! Digits decoded = " + std::to_string(mTotalDigits) + " Frames received = " + std::to_string(mTotalFrames)); - mExTimer.stop(); - //ec.services().get().endOfStream(); - // ec.services().get().readyToQuit(framework::QuitRequest::Me); - return; -} -//_________________________________________________________________________________________________ -// the decodeTF() function processes the the messages generated by the (sub)TimeFrame builder -void DataDecoderTask::decodeTF(framework::ProcessingContext& pc) -{ - LOG(DEBUG) << "*********** In decodeTF **************"; - - // get the input buffer - auto& inputs = pc.inputs(); - DPLRawParser parser(inputs, o2::framework::select("TF:HMP/RAWDATA")); - for (auto it = parser.begin(), end = parser.end(); it != end; ++it) { - mDeco->mDigits.clear(); - uint32_t* theBuffer = (uint32_t*)it.raw(); - mDeco->setUpStream(theBuffer, it.size() + it.offset()); - mDeco->decodePageFast(&theBuffer); - mTotalFrames++; - pc.outputs().snapshot(o2::framework::Output{"HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe}, mDeco->mDigits); // - mTotalDigits += mDeco->mDigits.size(); - LOG(DEBUG) << "Writing " << mDeco->mDigits.size() << "/" << mTotalDigits << " Digits ..."; ->>>>>>> refs/heads/dev } return; } diff --git a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx index 2192fa496bd64..5de9d2a74b2c9 100644 --- a/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx +++ b/Detectors/HMPID/workflow/src/DumpDigitsSpec.cxx @@ -98,21 +98,12 @@ void DumpDigitsTask::run(framework::ProcessingContext& pc) if (Dig.getOrbit() != mOrbit || Dig.getBC() != mBc) { mOrbit = Dig.getOrbit(); mBc = Dig.getBC(); -<<<<<<< HEAD // LOG(INFO) << "Event :" << mOrbit << " / " << mBc; } } } } mExTimer.elapseMes("... Dumping Digits received = " + std::to_string(mDigitsReceived)); -======= - LOG(INFO) << "Event :" << mOrbit << " / " << mBc; - } - } - } - } - mExTimer.elapseMes("... Dumping... Digits received = " + std::to_string(mDigitsReceived)); ->>>>>>> refs/heads/dev return; } diff --git a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx index 306d979a0d336..498e3778260b9 100644 --- a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx @@ -8,7 +8,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -<<<<<<< HEAD /// \file write-root-from-digit-workflow.cxx /// \author Antonio Franco - INFN Bari /// \version 1.0 @@ -55,43 +54,6 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) o2::conf::ConfigurableParam::updateFromString(configcontext.options().get("configKeyValues")); DataProcessorSpec consumer = o2::hmpid::getWriteRawFromDigitsSpec(); -======= -/// \file write-root-from-digits-workflow.cxx -/// \author Antonio Franco - INFN Bari -/// \version 1.0 -/// \date 01 feb 2021 -/// - -#include "Framework/WorkflowSpec.h" -#include "Framework/DataSpecUtils.h" -#include "Framework/CallbackService.h" -#include "Framework/ControlService.h" -#include "Framework/Task.h" -#include "Framework/CompletionPolicy.h" -#include "Framework/CompletionPolicyHelpers.h" -#include "Framework/DispatchPolicy.h" - -// customize the completion policy -void customize(std::vector& policies) -{ - using o2::framework::CompletionPolicy; - using o2::framework::CompletionPolicyHelpers; - policies.push_back(CompletionPolicyHelpers::defineByName("digit-root-write", CompletionPolicy::CompletionOp::Consume)); -} - -#include "Framework/runDataProcessing.h" - -#include "HMPIDWorkflow/WriteRootFromDigitsSpec.h" - -using namespace o2; -using namespace o2::framework; - -WorkflowSpec defineDataProcessing(const ConfigContext&) -{ - WorkflowSpec specs; - - DataProcessorSpec consumer = o2::hmpid::getWriteRootFromDigitSpec(); ->>>>>>> refs/heads/dev specs.push_back(consumer); return specs; } From 102cb8f01d3365dcf760b73b4080c3d9d15e4ebb Mon Sep 17 00:00:00 2001 From: Antonio FRANCO Date: Thu, 4 Mar 2021 10:16:28 +0100 Subject: [PATCH 205/208] Fix - clang --- .../include/HMPIDSimulation/HmpidCoder2.h | 1 - .../HMPID/simulation/src/HmpidCoder2.cxx | 21 +------------------ 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h index 876e63e629d19..0bf91f44e59f7 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h @@ -120,7 +120,6 @@ class HmpidCoder2 void dumpResults(); private: - void getEquipCoord(int Equi, uint32_t* CruId, uint32_t* LinkId); int getEquipmentPadIndex(int eq, int col, int dil, int cha); void fillTheOutputBuffer(uint32_t* padMap); void writePaginatedEvent(uint32_t orbit, uint16_t bc); diff --git a/Detectors/HMPID/simulation/src/HmpidCoder2.cxx b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx index d8fb67d5592f2..4852433db9b74 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder2.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx @@ -55,25 +55,6 @@ HmpidCoder2::~HmpidCoder2() { } -/* / getEquipCoord() : converts the EquipmentID in CRU,Link couple -/// @param[in] Equi : the HMPID Equipment ID [0..13] -/// @param[out] CruId : the FLP CRU number [0..3] -/// @param[ou] LinkId : the FLP Linkk number [0..3] -void HmpidCoder2::getEquipCoord(int Equi, uint32_t* CruId, uint32_t* LinkId) -{ - for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) { - if (mEqIds[i] == Equi) { - *CruId = mCruIds[i]; - *LinkId = mLinkIds[i]; - return; - } - } - *CruId = mCruIds[0]; - *LinkId = mLinkIds[0]; - return; -} -*/ - /// setDetectorSpecificFields() : sets the HMPID parameters for the next /// raw file writes /// @param[in] BusyTime : busy time in milliseconds @@ -250,7 +231,7 @@ void HmpidCoder2::codeEventChunkDigits(std::vector& digits, Trigger ir) eq = ReadOut::FeeId(eq); // converts the Equipment Id in Cru/Link position ref idx = getEquipmentPadIndex(eq, col, dil, cha); // finally to the unique padmap index if (mPadMap[idx] != 0) { // We already have the pad set - std::cerr << "HmpidCoder [ERROR] : Duplicated DIGIT =" << d << " (" << eq << "," << col << "," << dil << "," << cha << ")" << std::endl; + LOG(WARNING) << "Duplicated DIGIT =" << d << " (" << eq << "," << col << "," << dil << "," << cha << ")"; } else { mPadMap[idx] = d.getCharge(); padsCount++; From c7cf8627cadd4da97ee2e9d2c3a7090b8e3a55f9 Mon Sep 17 00:00:00 2001 From: Antonio FRANCO Date: Thu, 4 Mar 2021 14:36:51 +0100 Subject: [PATCH 206/208] Clang-format apply --- Detectors/HMPID/base/include/HMPIDBase/Geo.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Detectors/HMPID/base/include/HMPIDBase/Geo.h b/Detectors/HMPID/base/include/HMPIDBase/Geo.h index 0354eed4b682d..c1f9fb658b0f0 100644 --- a/Detectors/HMPID/base/include/HMPIDBase/Geo.h +++ b/Detectors/HMPID/base/include/HMPIDBase/Geo.h @@ -217,7 +217,6 @@ void ReadOut::Init() }; */ - } // namespace hmpid } // namespace o2 From 283bbca2c244ca231d3f2c49b9e7cd76c4080909 Mon Sep 17 00:00:00 2001 From: Antonio FRANCO Date: Thu, 4 Mar 2021 15:10:55 +0100 Subject: [PATCH 207/208] Clang fix --- Detectors/HMPID/simulation/src/HmpidCoder2.cxx | 2 +- Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Detectors/HMPID/simulation/src/HmpidCoder2.cxx b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx index 4852433db9b74..84626142b2448 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder2.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx @@ -230,7 +230,7 @@ void HmpidCoder2::codeEventChunkDigits(std::vector& digits, Trigger ir) Digit::Pad2Equipment(d.getPadID(), &eq, &col, &dil, &cha); // From Digit to Hardware coords eq = ReadOut::FeeId(eq); // converts the Equipment Id in Cru/Link position ref idx = getEquipmentPadIndex(eq, col, dil, cha); // finally to the unique padmap index - if (mPadMap[idx] != 0) { // We already have the pad set + if (mPadMap[idx] != 0) { // We already have the pad set LOG(WARNING) << "Duplicated DIGIT =" << d << " (" << eq << "," << col << "," << dil << "," << cha << ")"; } else { mPadMap[idx] = d.getCharge(); diff --git a/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx index 0188b00fee63c..b904c0188ab7e 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx @@ -106,11 +106,10 @@ void WriteRawFromRootTask::init(framework::InitContext& ic) return; } - void WriteRawFromRootTask::readRootFile() { std::vector digitsPerEvent; - std::vector digits,*hmpBCDataPtr = &digits; + std::vector digits, *hmpBCDataPtr = &digits; std::vector interactions, *interactionsPtr = &interactions; // Keeps the Interactions ! From aa17112e9ccf8840dcbade2bbfa4668166974562 Mon Sep 17 00:00:00 2001 From: Antonio FRANCO Date: Mon, 8 Mar 2021 08:17:48 +0100 Subject: [PATCH 208/208] Last commit - close branch --- .../include/HMPIDSimulation/HmpidCoder2.h | 2 +- Detectors/HMPID/simulation/src/HmpidCoder2.cxx | 11 +++++++---- Detectors/HMPID/workflow/CMakeLists.txt | 16 ++++++++-------- .../include/HMPIDWorkflow/WriteRawFromRootSpec.h | 3 +-- .../HMPID/workflow/src/WriteRawFromRootSpec.cxx | 7 +++---- ...t-workflow.cxx => digits-to-raw-workflow.cxx} | 0 ...ow.cxx => digitstream-to-digits-workflow.cxx} | 4 +++- ...kflow.cxx => digitstream-to-raw-workflow.cxx} | 0 ...kflow.cxx => raw-to-digitstream-workflow.cxx} | 0 9 files changed, 23 insertions(+), 20 deletions(-) rename Detectors/HMPID/workflow/src/{write-raw-from-root-workflow.cxx => digits-to-raw-workflow.cxx} (100%) rename Detectors/HMPID/workflow/src/{write-root-from-digits-workflow.cxx => digitstream-to-digits-workflow.cxx} (93%) rename Detectors/HMPID/workflow/src/{write-raw-from-digits-workflow.cxx => digitstream-to-raw-workflow.cxx} (100%) rename Detectors/HMPID/workflow/src/{raw-to-digits-workflow.cxx => raw-to-digitstream-workflow.cxx} (100%) diff --git a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h index 0bf91f44e59f7..09015bf2c9b68 100644 --- a/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h +++ b/Detectors/HMPID/simulation/include/HMPIDSimulation/HmpidCoder2.h @@ -112,7 +112,7 @@ class HmpidCoder2 o2::raw::RawFileWriter& getWriter() { return mWriter; } void setDetectorSpecificFields(float BusyTime = 0.001, int Error = 0, int Version = 9); - void openOutputStream(const char* OutputFileName, bool perLinkFile = false, bool perFlpFile = false); + void openOutputStream(const char* OutputFileName, std::string perFile); void closeOutputStream(); void codeEventChunkDigits(std::vector& digits); diff --git a/Detectors/HMPID/simulation/src/HmpidCoder2.cxx b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx index 84626142b2448..b021890098fa9 100644 --- a/Detectors/HMPID/simulation/src/HmpidCoder2.cxx +++ b/Detectors/HMPID/simulation/src/HmpidCoder2.cxx @@ -249,7 +249,7 @@ void HmpidCoder2::codeEventChunkDigits(std::vector& digits, Trigger ir) /// @param[in] OutputFileName : the Path/Prefix name for the raw files /// @param[in] perFlpFile : if true a couple of files will be created, one for each /// HMPID FLPs -void HmpidCoder2::openOutputStream(const char* OutputFileName, bool perLinkFile, bool perFlpFile) +void HmpidCoder2::openOutputStream(const char* OutputFileName, std::string perFile) { RAWDataHeader rdh; // by default, v6 is used currently. for (int eq = 0; eq < mNumberOfEquipments; eq++) { @@ -258,13 +258,16 @@ void HmpidCoder2::openOutputStream(const char* OutputFileName, bool perLinkFile, rdh.linkID = ReadOut::LnkId(eq); rdh.endPointID = 0; - if (perLinkFile) { + if (perFile == "link") { sprintf(mFileName, "%s_L%d%s", OutputFileName, ReadOut::FeeId(eq), ".raw"); - } else if (perFlpFile) { + } else if (perFile == "flp") { sprintf(mFileName, "%s_%d%s", OutputFileName, ReadOut::FlpId(eq), ".raw"); - } else { + } else if (perFile == "all") { sprintf(mFileName, "%s%s", OutputFileName, ".raw"); + } else { + throw std::runtime_error(fmt::format("unknown raw file grouping option {}", perFile)); } + mWriter.registerLink(rdh, mFileName); // register the link LinkSubSpec_t ap = RDHUtils::getSubSpec(ReadOut::CruId(eq), ReadOut::LnkId(eq), 0, ReadOut::FeeId(eq)); mTheRFWLinks[eq] = ap; // Store the RawFileWriter Link ID diff --git a/Detectors/HMPID/workflow/CMakeLists.txt b/Detectors/HMPID/workflow/CMakeLists.txt index 1c171fbef864d..66c3bc963d33c 100644 --- a/Detectors/HMPID/workflow/CMakeLists.txt +++ b/Detectors/HMPID/workflow/CMakeLists.txt @@ -35,14 +35,14 @@ o2_add_executable(read-raw-file-workflow SOURCES src/read-raw-file-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) -o2_add_executable(raw-to-digits-workflow +o2_add_executable(raw-to-digitstream-workflow COMPONENT_NAME hmpid - SOURCES src/raw-to-digits-workflow.cxx + SOURCES src/raw-to-digitstream-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) -o2_add_executable(write-raw-from-digits-workflow +o2_add_executable(digitstream-to-raw-workflow COMPONENT_NAME hmpid - SOURCES src/write-raw-from-digits-workflow.cxx + SOURCES src/digitstream-to-raw-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) o2_add_executable(dump-digits-workflow @@ -50,9 +50,9 @@ o2_add_executable(dump-digits-workflow SOURCES src/dump-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) -o2_add_executable(write-root-from-digits-workflow +o2_add_executable(digitstream-to-digits-workflow COMPONENT_NAME hmpid - SOURCES src/write-root-from-digits-workflow.cxx + SOURCES src/digitstream-to-digits-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) o2_add_executable(raw-to-pedestals-workflow @@ -60,8 +60,8 @@ o2_add_executable(raw-to-pedestals-workflow SOURCES src/raw-to-pedestals-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) -o2_add_executable(write-raw-from-root-workflow +o2_add_executable(digits-to-raw-workflow COMPONENT_NAME hmpid - SOURCES src/write-raw-from-root-workflow.cxx + SOURCES src/digits-to-raw-workflow.cxx PUBLIC_LINK_LIBRARIES O2::HMPIDWorkflow) \ No newline at end of file diff --git a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h index 8c2706776eff3..1f47fc2b2c76f 100644 --- a/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h +++ b/Detectors/HMPID/workflow/include/HMPIDWorkflow/WriteRawFromRootSpec.h @@ -43,8 +43,7 @@ class WriteRawFromRootTask : public framework::Task std::string mBaseRootFileName = ""; bool mSkipEmpty = false; bool mDumpDigits = false; - bool mPerFlpFile = false; - bool mPerLink = false; + std::string mPerFile = "all"; std::vector mDigits; long mDigitsReceived; diff --git a/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx b/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx index b904c0188ab7e..cc2264b8bcc35 100644 --- a/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx +++ b/Detectors/HMPID/workflow/src/WriteRawFromRootSpec.cxx @@ -71,8 +71,7 @@ void WriteRawFromRootTask::init(framework::InitContext& ic) mBaseRootFileName = ic.options().get("in-file"); mBaseFileName = ic.options().get("hmp-raw-outfile"); mDirectoryName = ic.options().get("hmp-raw-outdir"); - mPerLink = ic.options().get("hmp-raw-perlink"); - mPerFlpFile = ic.options().get("hmp-raw-perflp"); + mPerFile = ic.options().get("hmp-file-for"); mDumpDigits = ic.options().get("dump-digits"); // Debug flags mSkipEmpty = ic.options().get("hmp-skip-empty"); @@ -89,7 +88,7 @@ void WriteRawFromRootTask::init(framework::InitContext& ic) // Setup the Coder mCod = new HmpidCoder2(Geo::MAXEQUIPMENTS); mCod->setSkipEmptyEvents(mSkipEmpty); - mCod->openOutputStream(fullFName.c_str(), mPerLink, mPerFlpFile); + mCod->openOutputStream(fullFName.c_str(), mPerFile); std::string inputGRP = o2::base::NameConf::getGRPFileName(); std::unique_ptr grp{o2::parameters::GRPObject::loadFrom(inputGRP)}; mCod->getWriter().setContinuousReadout(grp->isDetContinuousReadOut(o2::detectors::DetID::HMP)); // must be set explicitly @@ -201,7 +200,7 @@ o2::framework::DataProcessorSpec getWriteRawFromRootSpec(std::string inputSpec) AlgorithmSpec{adaptFromTask()}, Options{{"hmp-raw-outdir", VariantType::String, "./", {"base dir for output file"}}, {"hmp-raw-outfile", VariantType::String, "hmpReadOut", {"base name for output file"}}, - {"hmp-raw-perlink", VariantType::Bool, false, {"produce one file per link"}}, + {"hmp-file-for", VariantType::String, "all", {"produce single file per: all, flp, link"}}, {"hmp-raw-perflp", VariantType::Bool, false, {"produce one raw file per FLPs"}}, {"in-file", VariantType::String, "hmpiddigits.root", {"name of the input sim root file"}}, // {"configKeyValues", VariantType::String, "", {"comma-separated configKeyValues"}}, diff --git a/Detectors/HMPID/workflow/src/write-raw-from-root-workflow.cxx b/Detectors/HMPID/workflow/src/digits-to-raw-workflow.cxx similarity index 100% rename from Detectors/HMPID/workflow/src/write-raw-from-root-workflow.cxx rename to Detectors/HMPID/workflow/src/digits-to-raw-workflow.cxx diff --git a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/digitstream-to-digits-workflow.cxx similarity index 93% rename from Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx rename to Detectors/HMPID/workflow/src/digitstream-to-digits-workflow.cxx index 498e3778260b9..5708e04d0aac1 100644 --- a/Detectors/HMPID/workflow/src/write-root-from-digits-workflow.cxx +++ b/Detectors/HMPID/workflow/src/digitstream-to-digits-workflow.cxx @@ -26,6 +26,8 @@ #include "Framework/ConfigParamSpec.h" #include "Framework/Variant.h" +#include "HMPIDWorkflow/WriteRootFromDigitsSpec.h" + // customize the completion policy void customize(std::vector& policies) { @@ -53,7 +55,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) WorkflowSpec specs; o2::conf::ConfigurableParam::updateFromString(configcontext.options().get("configKeyValues")); - DataProcessorSpec consumer = o2::hmpid::getWriteRawFromDigitsSpec(); + DataProcessorSpec consumer = o2::hmpid::getWriteRootFromDigitSpec();// getWriteRawFromDigitsSpec(); specs.push_back(consumer); return specs; } diff --git a/Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx b/Detectors/HMPID/workflow/src/digitstream-to-raw-workflow.cxx similarity index 100% rename from Detectors/HMPID/workflow/src/write-raw-from-digits-workflow.cxx rename to Detectors/HMPID/workflow/src/digitstream-to-raw-workflow.cxx diff --git a/Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx b/Detectors/HMPID/workflow/src/raw-to-digitstream-workflow.cxx similarity index 100% rename from Detectors/HMPID/workflow/src/raw-to-digits-workflow.cxx rename to Detectors/HMPID/workflow/src/raw-to-digitstream-workflow.cxx