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) {}
100 std::string mIniParFile{};
101 bool mUseIniParErrors =
true;
103 bool mIgnoreCCDBAlignment =
false;
104 bool mCosmic =
false;
105 bool mLoadTPCCalib =
false;
107 int mPostProcessing = 0;
110 std::unique_ptr<Controller> mController;
111 std::shared_ptr<DataRequest> mDataRequest;
112 std::shared_ptr<o2::base::GRPGeomRequest> mGRPGeomRequest;
113 std::string mConfMacro{};
114 std::unique_ptr<TMethodCall> mUsrConfMethod;
115 std::unique_ptr<o2::trd::TrackletTransformer> mTRDTransformer;
116 std::unique_ptr<o2::utils::TreeStreamRedirector> mDBGOut;
117 std::unique_ptr<o2::gpu::GPUParam> mTPCParam;
133 int dbg = ic.
options().
get<
int>(
"debug-output");
135 mController = std::make_unique<Controller>(mDetMask, mMPsrc, mCosmic, mUseMC, mLane);
137 mController->setDebugOutputLevel(dbg);
140 mConfMacro = ic.
options().
get<std::string>(
"config-macro");
141 if (!mConfMacro.empty()) {
142 if (!std::filesystem::exists(mConfMacro)) {
143 LOG(fatal) <<
"Requested user macro " << mConfMacro <<
" does not exist";
145 std::string tmpmacro = mConfMacro +
"+";
146 TString cmd = gSystem->GetMakeSharedLib();
147 cmd +=
" -O0 -g -ggdb";
150 boost::interprocess::named_semaphore* sem =
nullptr;
151 std::string semhashedstring{};
152 std::hash<std::string> hasher;
153 semhashedstring =
"align_macro_" +
std::to_string(hasher(mConfMacro)).substr(0, 16);
155 sem =
new boost::interprocess::named_semaphore(boost::interprocess::open_or_create_t{}, semhashedstring.c_str(), 1);
156 }
catch (std::exception e) {
157 LOGP(error,
"Exception occurred during {} compilation semaphore setup", tmpmacro);
163 gSystem->SetMakeSharedLib(cmd.Data());
164 auto res = gROOT->LoadMacro(tmpmacro.c_str());
167 if (sem->try_wait()) {
169 boost::interprocess::named_semaphore::remove(semhashedstring.c_str());
173 LOG(fatal) <<
"Failed to load user macro " << tmpmacro;
176 std::filesystem::path mpth(mConfMacro);
177 mConfMacro = mpth.stem();
178 mUsrConfMethod = std::make_unique<TMethodCall>();
179 mUsrConfMethod->InitWithPrototype(mConfMacro.c_str(),
"o2::align::Controller*, int");
181 mIgnoreCCDBAlignment = ic.
options().
get<
bool>(
"ignore-ccdb-alignment");
182 if (!mPostProcessing) {
183 if (GTrackID::includesDet(
DetID::TRD, mMPsrc)) {
186 mTRDTransformer->setApplyXOR();
188 auto prevShift = mTRDTransformer->isShiftApplied();
189 if (getenv(
"ALIEN_JDL_LPMPRODUCTIONTYPE") && std::strcmp(getenv(
"ALIEN_JDL_LPMPRODUCTIONTYPE"),
"MC") == 0) {
191 mTRDTransformer->setApplyShift(
false);
193 LOGP(info,
"Old TRD shift : {} new : {}", prevShift, mTRDTransformer->isShiftApplied());
194 mController->setTRDTransformer(mTRDTransformer.get());
196 mController->setAllowAfterburnerTracks(ic.
options().
get<
bool>(
"allow-afterburner-tracks"));
199 mIniParFile = ic.
options().
get<std::string>(
"initial-params-file");
200 mUseIniParErrors = !ic.
options().
get<
bool>(
"ignore-initial-params-errors");
201 if (mPostProcessing && !(mPostProcessing !=
GenPedeFiles) && (mIniParFile.empty() || mIniParFile ==
"none")) {
202 LOGP(warn,
"Postprocessing {} is requested but the initial-params-file is not provided", mPostProcessing);
211 if (mController->getDebugOutputLevel()) {
212 mDBGOut = std::make_unique<o2::utils::TreeStreamRedirector>(fmt::format(
"mpDebug_{}_{:08d}_{:010d}.root", mLane, tinfo.runNumber, tinfo.tfCounter).c_str(),
"recreate");
213 mController->setDebugStream(mDBGOut.get());
215 if (!mIgnoreCCDBAlignment) {
218 if (alg && !alg->empty()) {
221 gGeoManager->RefreshPhysicalNodes(
false);
224 LOG(warn) <<
"CCDB alignment is NOT applied to ideal geometry";
226 if (!mController->getInitGeomDone()) {
227 mController->initDetectors();
229 if (mTRDTransformer) {
230 mTRDTransformer->init();
233 if (!(mIniParFile.empty() || mIniParFile ==
"none")) {
234 mController->readParameters(mIniParFile, mUseIniParErrors);
235 mController->applyAlignmentFromMPSol();
239 if (mUsrConfMethod) {
240 int dummyPar = 0, ret = -1;
242 const void* args[2] = {&tmpPtr, &dummyPar};
243 mUsrConfMethod->Execute(
nullptr, args, 2, &ret);
245 LOG(fatal) <<
"Execution of user method config method " << mConfMacro <<
" failed with " << ret;
251 if (GTrackID::includesDet(
DetID::TRD, mMPsrc) && mTRDTransformer) {
256 static float prevField = 1e-6;
258 if (prevField != newField) {
259 prevField = newField;
263 mController->setTPCParam(mTPCParam.get());
269 auto const&
raw = pc.
inputs().
get<
const char*>(
"corrMap");
270 mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw);
271 mController->setTPCCorrMaps(mTPCCorrMaps);
273 LOGP(info,
"Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
289 LOG(info) <<
"cluster dictionary updated";
295 LOG(info) <<
"CalVdriftExB object has been updated";
308 if (mPostProcessing) {
309 updateTimeDependentParams(pc);
310 if (mController->getInstanceID() == 0) {
312 mController->addAutoConstraints();
313 mController->checkConstraints();
316 mController->writeCalibrationResults();
323 updateTimeDependentParams(pc);
324 mController->setRecoContainer(&recoData);
327 mController->processCosmic();
329 mController->process();
338 if (!mPostProcessing) {
339 LOGP(info,
"Barrel alignment data pereparation total timing: Cpu: {:.3e} Real: {:.3e} s in {} slots, instance {}", mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1, inst);
340 mController->closeMPRecOutput();
341 mController->closeMilleOutput();
342 mController->closeResidOutput();
346 LOG(info) <<
"Writing millepede control files";
347 if (!mPostProcessing) {
348 mController->terminate();
350 mController->addAutoConstraints();
351 mController->genPedeSteerFile();
352 mController->getStat().print();
354 mController->writeLabeledPedeResults();
362 std::vector<OutputSpec> outputs;
363 auto dataRequest = std::make_shared<DataRequest>();
364 bool loadTPCCalib =
false;
367 ConfigParamSpec{
"allow-afterburner-tracks", VariantType::Bool,
false, {
"allow using ITS-TPC afterburner tracks"}},
368 ConfigParamSpec{
"ignore-ccdb-alignment", VariantType::Bool,
false, {
"do not aplly CCDB alignment to ideal geometry"}},
369 ConfigParamSpec{
"initial-params-file", VariantType::String,
"", {
"initial parameters file"}},
370 ConfigParamSpec{
"config-macro", VariantType::String,
"", {
"configuration macro with signature (o2::align::Controller*, int) to execute from init"}},
371 ConfigParamSpec{
"ignore-initial-params-errors", VariantType::Bool,
false, {
"ignore initial params (if any) errors for precondition"}},
372 ConfigParamSpec{
"debug-output", VariantType::Int, 0, {
"produce debugging output root files"}}};
374 dataRequest->requestTracks(
src, useMC);
375 dataRequest->requestClusters(
src,
false, skipDetClusters);
376 dataRequest->requestPrimaryVertices(useMC);
377 if (GTrackID::includesDet(
DetID::TRD, srcMP)) {
378 dataRequest->inputs.emplace_back(
"calvdexb",
"TRD",
"CALVDRIFTEXB", 0, Lifetime::Condition,
ccdbParamSpec(
"TRD/Calib/CalVdriftExB"));
381 dataRequest->requestCoscmicTracks(useMC);
389 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(
true,
403 AlgorithmSpec{adaptFromTask<BarrelAlignmentSpec>(srcMP, dataRequest, ccdbRequest, dets, enableCosmic, postprocess, useMC, loadTPCCalib)},
Configuration file for global alignment.
Steering class for the global alignment.
Definition of the GeometryManager class.
o2::raw::RawFileWriter * raw
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(GTrackID::mask_t srcMP, std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > ggrec, DetID::mask_t detmask, bool cosmic, int postprocess, bool useMC, bool loadTPCCalib)
~BarrelAlignmentSpec() override=default
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.
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)
constexpr o2::header::DataOrigin gDataOriginTPC
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)
create a processor spec
Defining ITS Vertex 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)
float refTimeOffset
additive time offset reference (\mus)
float refVDrift
reference vdrift for which factor was extracted
float timeOffsetCorr
additive time offset correction (\mus)
float corrFact
drift velocity correction factor (multiplicative)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"