17#ifndef ALICEO2_FIT_RAWREADERBASEFIT_H_
18#define ALICEO2_FIT_RAWREADERBASEFIT_H_
23#include <TStopwatch.h>
24#include <boost/program_options.hpp>
26#include <fmt/format.h>
45template <
typename DigitBlockFITtype,
typename DataBlockPMtype,
typename DataBlockTCMtype,
typename =
typename std::enable_if_t<DataBlockPMtype::sIsPadded == DataBlockTCMtype::sIsPadded>>
51 typedef typename LookupTable_t::Topo_t
Topo_t;
67 void setLUTpath(
const std::string& lutPath) { LookupTable_t::setLUTpath(lutPath); }
70 const char*
ptr,
int maxSize,
int splitID,
71 std::vector<char>& trailer, std::vector<char>& header)
const
75 void convertDigitsToRaw(
const std::string& outputDir,
const std::string& filenameDigits,
long timestamp = -1)
77 LOG(info) <<
"Converting Digits to Raw data...";
81 LOG(warning) <<
"Metric status is not specified, all bits will be randomly generated";
86 LookupTable_t::Instance(
nullptr, timestamp).printFullMap();
89 mMapTopo2FEEmetadata = LookupTable_t::Instance().template makeMapFEEmetadata<o2::header::RAWDataHeader, RDHUtils>();
91 std::string detName = LookupTable_t::sDetectorName;
93 std::string maskName{};
95 maskName += fmt::format(
"_{}",
mFlpName);
97 maskName += fmt::format(
"_cru{}_{}", RDHUtils::getCRUID(rdh), RDHUtils::getEndPointID(rdh));
99 maskName += fmt::format(
"_lnk{}_feeid{}", RDHUtils::getLinkID(rdh), RDHUtils::getFEEID(rdh));
101 throw std::runtime_error(
"invalid option provided for file grouping");
107 return outputFilename;
111 const auto& rdh = metadataPair.second;
112 const auto outputFilename = makeFilename(rdh);
113 mWriter.
registerLink(RDHUtils::getFEEID(rdh), RDHUtils::getCRUID(rdh), RDHUtils::getLinkID(rdh), RDHUtils::getEndPointID(rdh), outputFilename);
116 TFile* inputFile = TFile::Open(filenameDigits.c_str());
117 assert(inputFile !=
nullptr);
118 LOG(info) <<
"Source file: " << filenameDigits;
119 TTree* inputTree =
dynamic_cast<TTree*
>(inputFile->Get(
"o2sim"));
120 DigitBlockFIT_t::processDigitBlocks(inputTree, *
this);
127 for (
const auto& digitBlock : vecDigitBlock) {
133 const auto mapDataBlockPM = digitBlock.template decomposeDigits<DataBlockPM_t>(statusEmu);
137 for (
const auto& dataBlockPair : mapDataBlockPM) {
138 const auto& topo = dataBlockPair.first;
139 const auto& dataBlock = dataBlockPair.second;
142 LOG(warning) <<
"No CRU entry in map! Data block: ";
149 const auto& rdh = itRdh->second;
150 auto data = dataBlock.serialize();
151 mWriter.
addData(RDHUtils::getFEEID(rdh), RDHUtils::getCRUID(rdh), RDHUtils::getLinkID(rdh), RDHUtils::getEndPointID(rdh), dataBlock.getInteractionRecord(),
data);
157 const auto dataBlockPair = digitBlock.template decomposeDigits<DataBlockTCM_t>(statusEmu);
158 const auto& topo = dataBlockPair.first;
159 const auto& dataBlock = dataBlockPair.second;
162 LOG(warning) <<
"No CRU entry in map! Data block: ";
169 const auto& rdh = itRdh->second;
170 auto data = dataBlock.serialize();
171 mWriter.
addData(RDHUtils::getFEEID(rdh), RDHUtils::getCRUID(rdh), RDHUtils::getLinkID(rdh), RDHUtils::getEndPointID(rdh), dataBlock.getInteractionRecord(),
data);
174 static constexpr auto getDetID() {
return LookupTable_t::sDetID; };
203 mInputFile = vm[
"input-file"].as<std::string>();
204 mOutputDir = vm[
"output-dir"].as<std::string>();
205 mFileFor = vm[
"file-for"].as<std::string>();
206 mFlpName = vm[
"flp-name"].as<std::string>();
211 mConfDig = vm[
"hbfutils-config"].as<std::string>();
213 mCcdbPath = vm[
"ccdb-path"].as<std::string>();
223 auto add_option = opt_general.add_options();
225 add_option(
"verbosity,v", bpo::value<int>()->default_value(0),
"verbosity level");
226 add_option(
"input-file,i", bpo::value<std::string>()->default_value(defaultInputFilename),
"input digits file");
227 add_option(
"output-dir,o", bpo::value<std::string>()->default_value(
"./"),
"output directory for raw data");
228 add_option(
"flp-name", bpo::value<std::string>()->default_value(defaultFLP_name),
"single file per: all,flp,cru,link");
229 add_option(
"file-for,f", bpo::value<std::string>()->default_value(
"all"),
"single file per: all,flp,cruendpoint,link");
230 add_option(
"configKeyValues", bpo::value<std::string>()->default_value(
""),
"comma-separated configKeyValues");
232 uint32_t defRDH = o2::raw::RDHUtils::getVersion<o2::header::RAWDataHeader>();
233 add_option(
"rdh-version,r", bpo::value<uint32_t>()->default_value(defRDH),
"RDH version to use");
234 add_option(
"no-empty-hbf,e", bpo::value<bool>()->default_value(
false)->implicit_value(
true),
"do not create empty HBF pages (except for HBF starting TF)");
236 add_option(
"enable-padding", bpo::value<bool>()->default_value(
false)->implicit_value(
true),
"enable GBT word padding to 128 bits even for RDH V7");
237 add_option(
"ccdb-path", bpo::value<std::string>()->default_value(
""),
"CCDB url which contains LookupTable");
238 add_option(
"lut-path", bpo::value<std::string>()->default_value(
""),
"LookupTable path");
240 add_option(
"emu-rawdata-metrics", bpo::value<uint64_t>()->default_value(0),
"Raw data metric emulation, specify 1-byte status word with o2::fit::RawDataMetric::EStatusBits");
241 add_option(
"emu-rawdata-metrics-random", bpo::value<bool>()->default_value(
false)->implicit_value(
true),
"Raw data metric emulation, randomly specifies 1-byte status word with o2::fit::RawDataMetric::EStatusBits. If --emu-rawdata-metrics is not specified then all bits will be on and randomly will be taken");
247 LOG(info) <<
"padding is always ON for RDH version " <<
mRdhVersion;
259 uint32_t
mRdhVersion{o2::raw::RDHUtils::getVersion<o2::header::RAWDataHeader>()};
275template <
typename RawWriterFIT_Type>
310 rawWriter.setContinuousReadout(grp->isDetContinuousReadOut(RawWriterFIT_Type::getDetID()));
311 const int superPageSizeInB = 1024 * 1024;
312 rawWriter.setSuperPageSize(superPageSizeInB);
317 rawWriter.setAlignmentSize(16);
318 rawWriter.setAlignmentPaddingFiller(0xff);
330 if (outDirName.back() !=
'/') {
335 long startTime = hbfu.startTime > 0 ? hbfu.startTime : std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
340 rawWriter.writeConfFile(rawWriter.getOrigin().str,
"RAWDATA",
o2::utils::Str::concat_string(outDirName, rawWriter.getOrigin().str,
"raw.cfg"));
350 digitToRawDevice.
run();
Header of the General Run Parameters object.
std::string ccdbPath(const std::string badChannelType)
Definition of the Names Generator class.
Utility class to write detectors data to (multiple) raw data file(s) respecting CRU format.
static std::string getGRPFileName(const std::string_view prefix=STANDARDSIMPREFIX)
static constexpr std::string_view DIGITIZATIONCONFIGFILE
static const HBFUtils & Instance()
static void updateFromFile(std::string const &, std::string const ¶msList="", bool unchangedOnly=false)
static void updateFromString(std::string const &)
void setStatusEmu(MetricStatus_t statusEmu)
DigitBlockFITtype DigitBlockFIT_t
bool getFilePerLink() const
void convertDigitsToRaw(const std::string &outputDir, const std::string &filenameDigits, long timestamp=-1)
RawDataMetric::Status_t MetricStatus_t
o2::raw::RawFileWriter & getWriter()
void setFileFor(const std::string &fileFor)
void processDigitBlockPerTF(const std::vector< DigitBlockFIT_t > &vecDigitBlock)
MetricStatus_t mStatusEmu
void setLUTpath(const std::string &lutPath)
DataBlockPMtype DataBlockPM_t
void setVerbosity(int verbosityLevel)
std::map< Topo_t, o2::header::RAWDataHeader > mMapTopo2FEEmetadata
void setFlpName(const std::string &flpName)
LookupTable_t::Topo_t Topo_t
void setRandomEmu(bool isRandomStatusEmu)
DigitBlockFIT_t::LookupTable_t LookupTable_t
void setCCDBurl(const std::string &ccdbPath)
int carryOverMethod(const header::RDHAny *rdh, const gsl::span< char > data, const char *ptr, int maxSize, int splitID, std::vector< char > &trailer, std::vector< char > &header) const
static constexpr auto getDetID()
DataBlockTCMtype DataBlockTCM_t
o2::raw::RawFileWriter mWriter
static GRPObject * loadFrom(const std::string &grpFileName="")
void setCarryOverCallBack(const T *t)
void addData(uint16_t feeid, uint16_t cru, uint8_t lnk, uint8_t endpoint, const IR &ir, const gsl::span< char > data, bool preformatted=false, uint32_t trigger=0, uint32_t detField=0)
LinkData & registerLink(uint16_t fee, uint16_t cru, uint8_t link, uint8_t endpoint, std::string_view outFileName)
TFitResultPtr fit(const size_t nBins, const T *arr, const T xMin, const T xMax, TF1 &func, std::string_view option="")
void assertOutputDirectory(std::string_view outDirName)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static void configureExecOptions(OptionsDescription &opt_general, const std::string &defaultInputFilename, const std::string &defaultFLP_name)
typename RawDataMetric::Status_t MetricStatus_t
std::string mChannelMapPath
typename boost::program_options::options_description OptionsDescription
typename boost::program_options::variables_map VariablesMap
DigitToRawConfig(const VariablesMap &vm)
MetricStatus_t mMetricStatusEmu
std::string mConfigKeyValues
DigitToRawConfig()=default
void setFromExecOptions(const VariablesMap &vm)
void run(const DigitToRawConfig &cfg)
DigitToRawDevice(const DigitToRawConfig &config)
void configure(const DigitToRawConfig &cfg)
DigitToRawDevice()=default
static void digit2raw(const DigitToRawConfig &cfg)
RawWriterFIT_Type mRawWriterFIT
void setConfig(const DigitToRawConfig &config)
static Status_t getAllBitsActivated()
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"