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)
104 std::string mIniParFile{};
105 bool mUseIniParErrors =
true;
107 bool mIgnoreCCDBAlignment =
false;
108 bool mCosmic =
false;
109 bool mLoadTPCCalib =
false;
111 int mPostProcessing = 0;
114 std::unique_ptr<Controller> mController;
115 std::shared_ptr<DataRequest> mDataRequest;
116 std::shared_ptr<o2::base::GRPGeomRequest> mGRPGeomRequest;
117 std::string mConfMacro{};
118 std::unique_ptr<TMethodCall> mUsrConfMethod;
119 std::unique_ptr<o2::trd::TrackletTransformer> mTRDTransformer;
120 std::unique_ptr<o2::utils::TreeStreamRedirector> mDBGOut;
121 std::unique_ptr<o2::gpu::GPUParam> mTPCParam;
136 int dbg = ic.
options().
get<
int>(
"debug-output");
138 mController = std::make_unique<Controller>(mDetMask, mMPsrc, mCosmic, mUseMC, mLane);
140 mController->setDebugOutputLevel(dbg);
143 mConfMacro = ic.
options().
get<std::string>(
"config-macro");
144 if (!mConfMacro.empty()) {
145 if (!std::filesystem::exists(mConfMacro)) {
146 LOG(fatal) <<
"Requested user macro " << mConfMacro <<
" does not exist";
148 std::string tmpmacro = mConfMacro +
"+";
149 TString cmd = gSystem->GetMakeSharedLib();
150 cmd +=
" -O0 -g -ggdb";
153 boost::interprocess::named_semaphore* sem =
nullptr;
154 std::string semhashedstring{};
155 std::hash<std::string> hasher;
156 semhashedstring =
"align_macro_" +
std::to_string(hasher(mConfMacro)).substr(0, 16);
158 sem =
new boost::interprocess::named_semaphore(boost::interprocess::open_or_create_t{}, semhashedstring.c_str(), 1);
159 }
catch (std::exception e) {
160 LOGP(error,
"Exception occurred during {} compilation semaphore setup", tmpmacro);
166 gSystem->SetMakeSharedLib(cmd.Data());
167 auto res = gROOT->LoadMacro(tmpmacro.c_str());
170 if (sem->try_wait()) {
172 boost::interprocess::named_semaphore::remove(semhashedstring.c_str());
176 LOG(fatal) <<
"Failed to load user macro " << tmpmacro;
179 std::filesystem::path mpth(mConfMacro);
180 mConfMacro = mpth.stem();
181 mUsrConfMethod = std::make_unique<TMethodCall>();
182 mUsrConfMethod->InitWithPrototype(mConfMacro.c_str(),
"o2::align::Controller*, int");
184 mIgnoreCCDBAlignment = ic.
options().
get<
bool>(
"ignore-ccdb-alignment");
185 if (!mPostProcessing) {
187 mTPCCorrMapsLoader.
init(ic);
189 if (GTrackID::includesDet(
DetID::TRD, mMPsrc)) {
192 mTRDTransformer->setApplyXOR();
194 auto prevShift = mTRDTransformer->isShiftApplied();
195 if (getenv(
"ALIEN_JDL_LPMPRODUCTIONTYPE") && std::strcmp(getenv(
"ALIEN_JDL_LPMPRODUCTIONTYPE"),
"MC") == 0) {
197 mTRDTransformer->setApplyShift(
false);
199 LOGP(info,
"Old TRD shift : {} new : {}", prevShift, mTRDTransformer->isShiftApplied());
200 mController->setTRDTransformer(mTRDTransformer.get());
202 mController->setAllowAfterburnerTracks(ic.
options().
get<
bool>(
"allow-afterburner-tracks"));
205 mIniParFile = ic.
options().
get<std::string>(
"initial-params-file");
206 mUseIniParErrors = !ic.
options().
get<
bool>(
"ignore-initial-params-errors");
207 if (mPostProcessing && !(mPostProcessing !=
GenPedeFiles) && (mIniParFile.empty() || mIniParFile ==
"none")) {
208 LOGP(warn,
"Postprocessing {} is requested but the initial-params-file is not provided", mPostProcessing);
217 if (mController->getDebugOutputLevel()) {
218 mDBGOut = std::make_unique<o2::utils::TreeStreamRedirector>(fmt::format(
"mpDebug_{}_{:08d}_{:010d}.root", mLane, tinfo.runNumber, tinfo.tfCounter).c_str(),
"recreate");
219 mController->setDebugStream(mDBGOut.get());
221 if (!mIgnoreCCDBAlignment) {
224 if (alg && !alg->empty()) {
227 gGeoManager->RefreshPhysicalNodes(
false);
230 LOG(warn) <<
"CCDB alignment is NOT applied to ideal geometry";
232 if (!mController->getInitGeomDone()) {
233 mController->initDetectors();
235 if (mTRDTransformer) {
236 mTRDTransformer->init();
239 if (!(mIniParFile.empty() || mIniParFile ==
"none")) {
240 mController->readParameters(mIniParFile, mUseIniParErrors);
241 mController->applyAlignmentFromMPSol();
245 if (mUsrConfMethod) {
246 int dummyPar = 0, ret = -1;
248 const void* args[2] = {&tmpPtr, &dummyPar};
249 mUsrConfMethod->Execute(
nullptr, args, 2, &ret);
251 LOG(fatal) <<
"Execution of user method config method " << mConfMacro <<
" failed with " << ret;
257 if (GTrackID::includesDet(
DetID::TRD, mMPsrc) && mTRDTransformer) {
262 static float prevField = 1e-6;
264 if (prevField != newField) {
265 prevField = newField;
269 mController->setTPCParam(mTPCParam.get());
275 bool updateMaps =
false;
280 mController->setTPCCorrMaps(&mTPCCorrMapsLoader);
282 LOGP(info,
"Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
302 LOG(info) <<
"cluster dictionary updated";
308 LOG(info) <<
"CalVdriftExB object has been updated";
324 if (mPostProcessing) {
325 updateTimeDependentParams(pc);
326 if (mController->getInstanceID() == 0) {
328 mController->addAutoConstraints();
329 mController->checkConstraints();
332 mController->writeCalibrationResults();
339 updateTimeDependentParams(pc);
340 mController->setRecoContainer(&recoData);
343 mController->processCosmic();
345 mController->process();
354 if (!mPostProcessing) {
355 LOGP(info,
"Barrel alignment data pereparation total timing: Cpu: {:.3e} Real: {:.3e} s in {} slots, instance {}", mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1, inst);
356 mController->closeMPRecOutput();
357 mController->closeMilleOutput();
358 mController->closeResidOutput();
362 LOG(info) <<
"Writing millepede control files";
363 if (!mPostProcessing) {
364 mController->terminate();
366 mController->addAutoConstraints();
367 mController->genPedeSteerFile();
368 mController->getStat().print();
370 mController->writeLabeledPedeResults();
378 std::vector<OutputSpec> outputs;
379 auto dataRequest = std::make_shared<DataRequest>();
380 bool loadTPCCalib =
false;
383 ConfigParamSpec{
"allow-afterburner-tracks", VariantType::Bool,
false, {
"allow using ITS-TPC afterburner tracks"}},
384 ConfigParamSpec{
"ignore-ccdb-alignment", VariantType::Bool,
false, {
"do not aplly CCDB alignment to ideal geometry"}},
385 ConfigParamSpec{
"initial-params-file", VariantType::String,
"", {
"initial parameters file"}},
386 ConfigParamSpec{
"config-macro", VariantType::String,
"", {
"configuration macro with signature (o2::align::Controller*, int) to execute from init"}},
387 ConfigParamSpec{
"ignore-initial-params-errors", VariantType::Bool,
false, {
"ignore initial params (if any) errors for precondition"}},
388 ConfigParamSpec{
"debug-output", VariantType::Int, 0, {
"produce debugging output root files"}}};
390 dataRequest->requestTracks(
src, useMC);
391 dataRequest->requestClusters(
src,
false, skipDetClusters);
392 dataRequest->requestPrimaryVertices(useMC);
393 if (GTrackID::includesDet(
DetID::TRD, srcMP)) {
394 dataRequest->inputs.emplace_back(
"calvdexb",
"TRD",
"CALVDRIFTEXB", 0, Lifetime::Condition,
ccdbParamSpec(
"TRD/Calib/CalVdriftExB"));
397 dataRequest->requestCoscmicTracks(useMC);
405 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(
true,
419 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) 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 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)
recalculate inverse correction
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
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"