Project
Loading...
Searching...
No Matches
digi2raw.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include <boost/program_options.hpp>
16#include <filesystem>
17#include <TFile.h>
18#include <TStopwatch.h>
19#include "Framework/Logger.h"
20#include <string>
21#include <iomanip>
28#include "ZDCBase/Constants.h"
36
38
39namespace bpo = boost::program_options;
40
41void digi2raw(const std::string& inpName, const std::string& outDir, int verbosity, const std::string& fileFor, uint32_t rdhV = 7, bool enablePadding = false,
42 const std::string& ccdbHost = "", int superPageSizeInB = 1024 * 1024);
43
44int main(int argc, char** argv)
45{
46 bpo::variables_map vm;
47 bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
48 "Convert ZDC digits to CRU raw data\n");
49 bpo::options_description opt_hidden("");
50 bpo::options_description opt_all;
51 bpo::positional_options_description opt_pos;
52
53 try {
54 auto add_option = opt_general.add_options();
55 add_option("help,h", "Print this help message");
56 add_option("verbosity,v", bpo::value<int>()->default_value(0), "verbosity level");
57 // add_option("input-file,i", bpo::value<std::string>()->default_value(o2::base::NameConf::getDigitsFileName(o2::detectors::DetID::ZDC)),"input ZDC digits file"); // why not used?
58 add_option("input-file,i", bpo::value<std::string>()->default_value("zdcdigits.root"), "input ZDC digits file");
59 add_option("file-for,f", bpo::value<std::string>()->default_value("all"), "single file per: all,flp,cruendpoint,link");
60 add_option("output-dir,o", bpo::value<std::string>()->default_value("./"), "output directory for raw data");
61 uint32_t defRDH = o2::raw::RDHUtils::getVersion<o2::header::RAWDataHeader>();
62 add_option("rdh-version,r", bpo::value<uint32_t>()->default_value(defRDH), "RDH version to use");
63 add_option("enable-padding", bpo::value<bool>()->default_value(false)->implicit_value(true), "enable GBT word padding to 128 bits even for RDH V7");
64 add_option("hbfutils-config,u", bpo::value<std::string>()->default_value(std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE)), "config file for HBFUtils (or none)");
65 add_option("configKeyValues", bpo::value<std::string>()->default_value(""), "comma-separated configKeyValues");
66
67 opt_all.add(opt_general).add(opt_hidden);
68 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
69
70 if (vm.count("help")) {
71 std::cout << opt_general << std::endl;
72 exit(0);
73 }
74
75 bpo::notify(vm);
76 } catch (bpo::error& e) {
77 std::cerr << "ERROR: " << e.what() << std::endl
78 << std::endl;
79 std::cerr << opt_general << std::endl;
80 exit(1);
81 } catch (std::exception& e) {
82 std::cerr << e.what() << ", application will now exit" << std::endl;
83 exit(2);
84 }
85 std::string confDig = vm["hbfutils-config"].as<std::string>();
86 if (!confDig.empty() && confDig != "none") {
88 }
89 o2::conf::ConfigurableParam::updateFromString(vm["configKeyValues"].as<std::string>());
90
91 std::string ccdbHost = o2::base::NameConf::getCCDBServer();
92 LOG(info) << "CCDB url " << ccdbHost;
93 digi2raw(vm["input-file"].as<std::string>(),
94 vm["output-dir"].as<std::string>(),
95 vm["verbosity"].as<int>(),
96 vm["file-for"].as<std::string>(),
97 vm["rdh-version"].as<uint32_t>(),
98 vm["enable-padding"].as<bool>(),
99 ccdbHost);
100
102
103 return 0;
104}
105
106void digi2raw(const std::string& inpName, const std::string& outDir, int verbosity, const std::string& fileFor, uint32_t rdhV, bool enablePadding, const std::string& ccdbHost, int superPageSizeInB)
107{
108 if (rdhV < 7 && !enablePadding) {
109 enablePadding = true;
110 LOG(info) << "padding is always ON for RDH version " << rdhV;
111 }
112 //std::string ccdbHost = "http://ccdb-test.cern.ch:8080";
114 mgr.setURL(ccdbHost);
115 /*long timeStamp = 0; // TIMESTAMP SHOULD NOT BE 0!
116 if (timeStamp == mgr.getTimestamp()) {
117 return;
118 }
119 mgr.setTimestamp(timeStamp);*/
120 auto moduleConfig = mgr.get<o2::zdc::ModuleConfig>(o2::zdc::CCDBPathConfigModule);
121 if (!moduleConfig) {
122 LOG(fatal) << "Cannot module configuratio for timestamp " << mgr.getTimestamp();
123 return;
124 }
125 LOG(info) << "Loaded module configuration for timestamp " << mgr.getTimestamp();
126
127 auto simCondition = mgr.get<o2::zdc::SimCondition>(o2::zdc::CCDBPathConfigSim);
128 if (!simCondition) {
129 LOG(fatal) << "Cannot get simulation configuration for timestamp " << mgr.getTimestamp();
130 return;
131 }
132 LOG(info) << "Loaded simulation configuration for timestamp " << mgr.getTimestamp();
133 simCondition->print();
134
135 LOG(info) << "RDHVersion " << rdhV << " padding: " << enablePadding;
136
137 const auto* ctx = o2::steer::DigitizationContext::loadFromFile("collisioncontext.root");
138 const auto& bcfill = ctx->getBunchFilling();
139 auto bf = ctx->getBunchFilling();
140 if (verbosity > 0) {
141 bf.print();
142 }
143 auto bp = bf.getPattern();
144
145 TStopwatch swTot;
146 swTot.Start();
147
149 d2r.setFileFor(fileFor);
150 d2r.setEnablePadding(enablePadding);
152 auto& wr = d2r.getWriter();
153 std::string inputGRP = o2::base::NameConf::getGRPFileName();
154 const auto grp = o2::parameters::GRPObject::loadFrom(inputGRP);
155 wr.setContinuousReadout(grp->isDetContinuousReadOut(o2::detectors::DetID::ZDC)); // must be set explicitly
156 wr.setSuperPageSize(superPageSizeInB);
157 wr.useRDHVersion(rdhV);
158 wr.useRDHDataFormat(enablePadding ? 0 : 2);
159 if (!enablePadding) { // CRU page alignment padding is used only if no GBT word padding is used
160 wr.setAlignmentSize(16);
161 wr.setAlignmentPaddingFiller(0xff);
162 }
164
165 std::string outDirName(outDir);
166 if (outDirName.back() != '/') {
167 outDirName += '/';
168 }
169
170 d2r.setModuleConfig(moduleConfig);
171 d2r.setSimCondition(simCondition);
172 d2r.emptyBunches(bp);
174 d2r.processDigits(outDirName, inpName);
175 wr.writeConfFile(wr.getOrigin().str, "RAWDATA", o2::utils::Str::concat_string(outDirName, wr.getOrigin().str, "raw.cfg"));
176 //
177 swTot.Stop();
178 swTot.Print();
179}
#define verbosity
Class to describe fired triggered and/or stored channels for the BC and to refer to channel data.
Header of the General Run Parameters object.
Definition of the Names Generator class.
Container class to store NTimeBinsPerBC ADC values of single ZDC channel.
converts digits to raw format
void digi2raw(const std::string &inpName, const std::string &outDir, int verbosity, const std::string &fileFor, uint32_t rdhV=7, bool enablePadding=false, const std::string &ccdbHost="", int superPageSizeInB=1024 *1024)
MC->raw conversion for ZDC.
Definition digi2raw.cxx:106
static std::string getGRPFileName(const std::string_view prefix=STANDARDSIMPREFIX)
Definition NameConf.cxx:58
static constexpr std::string_view DIGITIZATIONCONFIGFILE
Definition NameConf.h:89
static std::string getCCDBServer()
Definition NameConf.cxx:110
static BasicCCDBManager & instance()
static void updateFromFile(std::string const &, std::string const &paramsList="", bool unchangedOnly=false)
static void updateFromString(std::string const &)
static constexpr ID ZDC
Definition DetID.h:74
static GRPObject * loadFrom(const std::string &grpFileName="")
static DigitizationContext * loadFromFile(std::string_view filename="")
void setModuleConfig(const ModuleConfig *moduleConfig)
Definition Digits2Raw.h:43
void processDigits(const std::string &outDir, const std::string &fileDigitsName)
Prepare list of clean empty bunches for baseline evaluation.
o2::raw::RawFileWriter & getWriter()
Definition Digits2Raw.h:48
void setEnablePadding(bool v)
Definition Digits2Raw.h:63
void setFileFor(const std::string v)
Definition Digits2Raw.h:50
void setSimCondition(const SimCondition *SimCondition)
Definition Digits2Raw.h:45
void emptyBunches(std::bitset< 3564 > &bunchPattern)
void setVerbosity(int v)
Definition Digits2Raw.h:53
void assertOutputDirectory(std::string_view outDirName)
const std::string CCDBPathConfigSim
Definition Constants.h:218
const std::string CCDBPathConfigModule
Definition Constants.h:219
void print() const
Definition HBFUtils.h:134
static std::string concat_string(Ts const &... ts)
#define main
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"