17#include <TMethodCall.h>
18#include <TStopwatch.h>
21#include "TMethodCall.h"
50#include <boost/interprocess/sync/named_semaphore.hpp>
90 DetID::mask_t detmask,
bool cosmic,
int postprocess,
bool useMC,
bool loadTPCCalib)
91 : mDataRequest(dr), mGRPGeomRequest(ggrec), mMPsrc{srcMP}, mDetMask{detmask}, mCosmic(cosmic), mPostProcessing(postprocess), mUseMC(useMC), mLoadTPCCalib(loadTPCCalib)
105 std::string mIniParFile{};
106 bool mUseIniParErrors =
true;
108 bool mIgnoreCCDBAlignment =
false;
109 bool mCosmic =
false;
110 bool mLoadTPCCalib =
false;
112 int mPostProcessing = 0;
115 std::unique_ptr<Controller> mController;
116 std::shared_ptr<DataRequest> mDataRequest;
117 std::shared_ptr<o2::base::GRPGeomRequest> mGRPGeomRequest;
118 std::string mConfMacro{};
119 std::unique_ptr<TMethodCall> mUsrConfMethod;
120 std::unique_ptr<o2::trd::TrackletTransformer> mTRDTransformer;
121 std::unique_ptr<o2::utils::TreeStreamRedirector> mDBGOut;
122 std::unique_ptr<o2::gpu::GPUParam> mTPCParam;
137 int dbg = ic.
options().
get<
int>(
"debug-output");
139 mController = std::make_unique<Controller>(mDetMask, mMPsrc, mCosmic, mUseMC, mLane);
141 mController->setDebugOutputLevel(dbg);
144 mConfMacro = ic.
options().
get<std::string>(
"config-macro");
145 if (!mConfMacro.empty()) {
146 if (!std::filesystem::exists(mConfMacro)) {
147 LOG(fatal) <<
"Requested user macro " << mConfMacro <<
" does not exist";
149 std::string tmpmacro = mConfMacro +
"+";
150 TString cmd = gSystem->GetMakeSharedLib();
151 cmd +=
" -O0 -g -ggdb";
154 boost::interprocess::named_semaphore* sem =
nullptr;
155 std::string semhashedstring{};
156 std::hash<std::string> hasher;
157 semhashedstring =
"align_macro_" +
std::to_string(hasher(mConfMacro)).substr(0, 16);
159 sem =
new boost::interprocess::named_semaphore(boost::interprocess::open_or_create_t{}, semhashedstring.c_str(), 1);
160 }
catch (std::exception e) {
161 LOGP(error,
"Exception occurred during {} compilation semaphore setup", tmpmacro);
167 gSystem->SetMakeSharedLib(cmd.Data());
168 auto res = gROOT->LoadMacro(tmpmacro.c_str());
171 if (sem->try_wait()) {
173 boost::interprocess::named_semaphore::remove(semhashedstring.c_str());
177 LOG(fatal) <<
"Failed to load user macro " << tmpmacro;
180 std::filesystem::path mpth(mConfMacro);
181 mConfMacro = mpth.stem();
182 mUsrConfMethod = std::make_unique<TMethodCall>();
183 mUsrConfMethod->InitWithPrototype(mConfMacro.c_str(),
"o2::align::Controller*, int");
185 mIgnoreCCDBAlignment = ic.
options().
get<
bool>(
"ignore-ccdb-alignment");
186 if (!mPostProcessing) {
188 mTPCCorrMapsLoader.
init(ic);
190 if (GTrackID::includesDet(
DetID::TRD, mMPsrc)) {
193 mTRDTransformer->setApplyXOR();
195 auto prevShift = mTRDTransformer->isShiftApplied();
196 if (getenv(
"ALIEN_JDL_LPMPRODUCTIONTYPE") && std::strcmp(getenv(
"ALIEN_JDL_LPMPRODUCTIONTYPE"),
"MC") == 0) {
198 mTRDTransformer->setApplyShift(
false);
200 LOGP(info,
"Old TRD shift : {} new : {}", prevShift, mTRDTransformer->isShiftApplied());
201 mController->setTRDTransformer(mTRDTransformer.get());
203 mController->setAllowAfterburnerTracks(ic.
options().
get<
bool>(
"allow-afterburner-tracks"));
206 mIniParFile = ic.
options().
get<std::string>(
"initial-params-file");
207 mUseIniParErrors = !ic.
options().
get<
bool>(
"ignore-initial-params-errors");
208 if (mPostProcessing && !(mPostProcessing !=
GenPedeFiles) && (mIniParFile.empty() || mIniParFile ==
"none")) {
209 LOGP(warn,
"Postprocessing {} is requested but the initial-params-file is not provided", mPostProcessing);
218 if (mController->getDebugOutputLevel()) {
219 mDBGOut = std::make_unique<o2::utils::TreeStreamRedirector>(fmt::format(
"mpDebug_{}_{:08d}_{:010d}.root", mLane, tinfo.runNumber, tinfo.tfCounter).c_str(),
"recreate");
220 mController->setDebugStream(mDBGOut.get());
222 if (!mIgnoreCCDBAlignment) {
225 if (alg && !alg->empty()) {
228 gGeoManager->RefreshPhysicalNodes(
false);
231 LOG(warn) <<
"CCDB alignment is NOT applied to ideal geometry";
233 if (!mController->getInitGeomDone()) {
234 mController->initDetectors();
236 if (mTRDTransformer) {
237 mTRDTransformer->init();
240 if (!(mIniParFile.empty() || mIniParFile ==
"none")) {
241 mController->readParameters(mIniParFile, mUseIniParErrors);
242 mController->applyAlignmentFromMPSol();
246 if (mUsrConfMethod) {
247 int dummyPar = 0, ret = -1;
249 const void* args[2] = {&tmpPtr, &dummyPar};
250 mUsrConfMethod->Execute(
nullptr, args, 2, &ret);
252 LOG(fatal) <<
"Execution of user method config method " << mConfMacro <<
" failed with " << ret;
258 if (GTrackID::includesDet(
DetID::TRD, mMPsrc) && mTRDTransformer) {
263 static float prevField = 1e-6;
265 if (prevField != newField) {
266 prevField = newField;
270 mController->setTPCParam(mTPCParam.get());
276 bool updateMaps =
false;
281 mController->setTPCCorrMaps(&mTPCCorrMapsLoader);
283 LOGP(info,
"Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
303 LOG(info) <<
"cluster dictionary updated";
309 LOG(info) <<
"CalVdriftExB object has been updated";
325 if (mPostProcessing) {
326 updateTimeDependentParams(pc);
327 if (mController->getInstanceID() == 0) {
329 mController->addAutoConstraints();
330 mController->checkConstraints();
333 mController->writeCalibrationResults();
340 updateTimeDependentParams(pc);
341 mController->setRecoContainer(&recoData);
344 mController->processCosmic();
346 mController->process();
355 if (!mPostProcessing) {
356 LOGP(info,
"Barrel alignment data pereparation total timing: Cpu: {:.3e} Real: {:.3e} s in {} slots, instance {}", mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1, inst);
357 mController->closeMPRecOutput();
358 mController->closeMilleOutput();
359 mController->closeResidOutput();
363 LOG(info) <<
"Writing millepede control files";
364 if (!mPostProcessing) {
365 mController->terminate();
367 mController->addAutoConstraints();
368 mController->genPedeSteerFile();
369 mController->getStat().print();
371 mController->writeLabeledPedeResults();
379 std::vector<OutputSpec> outputs;
380 auto dataRequest = std::make_shared<DataRequest>();
381 bool loadTPCCalib =
false;
384 ConfigParamSpec{
"allow-afterburner-tracks", VariantType::Bool,
false, {
"allow using ITS-TPC afterburner tracks"}},
385 ConfigParamSpec{
"ignore-ccdb-alignment", VariantType::Bool,
false, {
"do not aplly CCDB alignment to ideal geometry"}},
386 ConfigParamSpec{
"initial-params-file", VariantType::String,
"", {
"initial parameters file"}},
387 ConfigParamSpec{
"config-macro", VariantType::String,
"", {
"configuration macro with signature (o2::align::Controller*, int) to execute from init"}},
388 ConfigParamSpec{
"ignore-initial-params-errors", VariantType::Bool,
false, {
"ignore initial params (if any) errors for precondition"}},
389 ConfigParamSpec{
"debug-output", VariantType::Int, 0, {
"produce debugging output root files"}}};
391 dataRequest->requestTracks(
src, useMC);
392 dataRequest->requestClusters(
src,
false, skipDetClusters);
393 dataRequest->requestPrimaryVertices(useMC);
394 if (GTrackID::includesDet(
DetID::TRD, srcMP)) {
395 dataRequest->inputs.emplace_back(
"calvdexb",
"TRD",
"CALVDRIFTEXB", 0, Lifetime::Condition,
ccdbParamSpec(
"TRD/Calib/CalVdriftExB"));
398 dataRequest->requestCoscmicTracks(useMC);
406 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(
true,
420 AlgorithmSpec{adaptFromTask<BarrelAlignmentSpec>(srcMP, dataRequest, ccdbRequest, sclOpts, dets, enableCosmic, postprocess, useMC, loadTPCCalib)},
Configuration file for global alignment.
Steering class for the global alignment.
Helper class to access load maps from CCDB.
Definition of the GeometryManager class.
Helper for geometry and GRP related CCDB requests.
Header of the General Run Parameters object.
Global index for barrel track: provides provenance (detectors combination), index in respective array...
Definition of the Names Generator class.
Wrapper container for different reconstructed object types.
Helper class to extract VDrift from different sources.
void init(InitContext &ic) final
~BarrelAlignmentSpec() override=default
BarrelAlignmentSpec(GTrackID::mask_t srcMP, std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > ggrec, const o2::tpc::CorrectionMapsLoaderGloOpts &tpcOpt, DetID::mask_t detmask, bool cosmic, int postprocess, bool useMC, bool loadTPCCalib)
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
void endOfStream(framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void run(ProcessingContext &pc) final
void checkUpdates(o2::framework::ProcessingContext &pc)
auto getAlignment(o2::detectors::DetID det) const
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static bool applyAlignment(const std::vector< o2::detectors::AlignParam > &algPars)
misalign geometry with alignment objects from the array, optionaly check overlaps
GPUd() value_type estimateLTFast(o2 static GPUd() float estimateLTIncrement(const o2 PropagatorImpl * Instance(bool uninitialized=false)
void printKeyValues(bool showProv=true, bool useLogger=false, bool withPadding=true, bool showHash=true) const final
static const AlignConfig & Instance()
Static class with identifiers, bitmasks and names for ALICE detectors.
static constexpr ID First
static constexpr ID Last
if extra detectors added, update this !!!
T get(const char *key) const
ServiceRegistryRef services()
ServiceRegistryRef services()
ConfigParamRegistry const & options()
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
void setLumiScaleType(int32_t v)
void setLumiScaleMode(int32_t v)
void setCheckCTPIDCConsistency(bool v)
void extractCCDBInputs(o2::framework::ProcessingContext &pc)
void updateVDrift(float vdriftCorr, float vdrifRef, float driftTimeOffset=0)
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, std::vector< o2::framework::ConfigParamSpec > &options, const CorrectionMapsLoaderGloOpts &gloOpts)
void init(o2::framework::InitContext &ic)
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, bool laser=true, bool itstpcTgl=true)
void extractCCDBInputs(o2::framework::ProcessingContext &pc, bool laser=true, bool itstpcTgl=true)
const VDriftCorrFact & getVDriftObject() const
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
static std::string_view getSourceName(Source s)
framework::DataProcessorSpec getBarrelAlignmentSpec(o2::dataformats::GlobalTrackID::mask_t srcMP, o2::dataformats::GlobalTrackID::mask_t src, o2::detectors::DetID::mask_t dets, o2::detectors::DetID::mask_t skipDetClusters, bool enableCosmic, int postproc, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts &sclOpts)
create a processor spec
Defining PrimaryVertex explicitly as messageable.
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
@ Me
Only quit this data processor.
std::vector< ConfigParamSpec > Options
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
void collectData(o2::framework::ProcessingContext &pc, const DataRequest &request)
int lumiType
what estimator to used for corrections scaling: 0: no scaling, 1: CTP, 2: IDC
bool checkCTPIDCconsistency
int lumiMode
what corrections method to use: 0: classical scaling, 1: Using of the derivative map,...
float refTimeOffset
additive time offset reference (\mus)
float refVDrift
reference vdrift for which factor was extracted
float getTimeOffset() const
float timeOffsetCorr
additive time offset correction (\mus)
float corrFact
drift velocity correction factor (multiplicative)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"