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) || !ic.
options().
get<
bool>(
"apply-shift")) {
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) {
216 for (
auto id = DetID::First;
id <=
DetID::Last;
id++) {
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 = 1
e-6;
258 if (prevField != newField) {
259 prevField = newField;
260 if (mDetMask[DetID::TPC]) {
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 {}",
287 auto* its = mController->getDetector(o2::detectors::DetID::ITS);
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 dataRequest->setITSPerLayer(itsStag);
365 bool loadTPCCalib =
false;
369 ConfigParamSpec{
"allow-afterburner-tracks", VariantType::Bool,
false, {
"allow using ITS-TPC afterburner tracks"}},
370 ConfigParamSpec{
"ignore-ccdb-alignment", VariantType::Bool,
false, {
"do not aplly CCDB alignment to ideal geometry"}},
371 ConfigParamSpec{
"initial-params-file", VariantType::String,
"", {
"initial parameters file"}},
372 ConfigParamSpec{
"config-macro", VariantType::String,
"", {
"configuration macro with signature (o2::align::Controller*, int) to execute from init"}},
373 ConfigParamSpec{
"ignore-initial-params-errors", VariantType::Bool,
false, {
"ignore initial params (if any) errors for precondition"}},
374 ConfigParamSpec{
"debug-output", VariantType::Int, 0, {
"produce debugging output root files"}}};
376 dataRequest->requestTracks(
src, useMC);
377 dataRequest->requestClusters(
src,
false, skipDetClusters);
378 dataRequest->requestPrimaryVertices(useMC);
379 if (GTrackID::includesDet(DetID::TRD, srcMP)) {
380 dataRequest->inputs.emplace_back(
"calvdexb",
"TRD",
"CALVDRIFTEXB", 0, Lifetime::Condition,
ccdbParamSpec(
"TRD/Calib/CalVdriftExB"));
383 dataRequest->requestCoscmicTracks(useMC);
385 if (
src[DetID::TPC] && !skipDetClusters[DetID::TPC]) {
391 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(
true,
405 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
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
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...
char error[CURL_ERROR_SIZE]
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, bool keepPhysicalNodes=true)
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 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, bool itsStag)
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.
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"