diff --git a/Common/TableProducer/PID/pidTPC.cxx b/Common/TableProducer/PID/pidTPC.cxx index ebb66f8934a..1cdc936a175 100644 --- a/Common/TableProducer/PID/pidTPC.cxx +++ b/Common/TableProducer/PID/pidTPC.cxx @@ -103,17 +103,17 @@ struct tpcPid { // TPC PID Response o2::pid::tpc::Response* response; + // CCDB accessor + Service ccdb; + // Network correction for TPC PID response OnnxModel network; - o2::ccdb::CcdbApi ccdbApi; std::map metadata; - std::map nullmetadata; std::map headers; std::vector speciesNetworkFlags = std::vector(9); std::string networkVersion; // Input parameters - Service ccdb; Configurable paramfile{"param-file", "", "Path to the parametrization object, if empty the parametrization is not taken from file"}; Configurable url{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; Configurable ccdbPath{"ccdbPath", "Analysis/PID/TPC/Response", "Path of the TPC parametrization on the CCDB"}; @@ -242,21 +242,18 @@ struct tpcPid { ccdb->setCaching(true); ccdb->setLocalObjectValidityChecking(); ccdb->setCreatedNotAfter(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); - ccdbApi.init(url); if (time != 0) { LOGP(info, "Initialising TPC PID response for fixed timestamp {} and reco pass {}:", time, recoPass.value); ccdb->setTimestamp(time); - response = ccdb->getSpecific(path, time, metadata); - headers = ccdbApi.retrieveHeaders(path, metadata, time); + response = ccdb->getSpecific(path, time, metadata, &headers); if (!response) { LOGF(warning, "Unable to find TPC parametrisation for specified pass name - falling back to latest object"); - response = ccdb->getForTimeStamp(path, time); - headers = ccdbApi.retrieveHeaders(path, metadata, time); - networkVersion = headers["NN-Version"]; + response = ccdb->getForTimeStamp(path, time, &headers); if (!response) { LOGF(fatal, "Unable to find any TPC object corresponding to timestamp {}!", time); } } + networkVersion = headers["NN-Version"]; LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << time << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"]; metadata["RecoPassName"] = headers["RecoPassName"]; // Force pass number for NN request to match retrieved BB response->PrintAll(); @@ -274,8 +271,7 @@ struct tpcPid { if (ccdbTimestamp > 0) { /// Fetching network for specific timestamp LOG(info) << "Fetching network for timestamp: " << ccdbTimestamp.value; - bool retrieveSuccess = ccdbApi.retrieveBlob(networkPathCCDB.value, ".", metadata, ccdbTimestamp.value, false, networkPathLocally.value); - headers = ccdbApi.retrieveHeaders(networkPathCCDB.value, metadata, ccdbTimestamp.value); + bool retrieveSuccess = ccdb->getCCDBAccessor().retrieveBlob(networkPathCCDB.value, ".", metadata, ccdbTimestamp.value, false, networkPathLocally.value, "", "", &headers); networkVersion = headers["NN-Version"]; if (retrieveSuccess) { network.initModel(networkPathLocally.value, enableNetworkOptimizations.value, networkSetNumThreads.value, strtoul(headers["Valid-From"].c_str(), NULL, 0), strtoul(headers["Valid-Until"].c_str(), NULL, 0)); @@ -318,17 +314,15 @@ struct tpcPid { } else { LOGP(info, "Retrieving TPC Response for timestamp {} and recoPass {}:", bc.timestamp(), recoPass.value); } - response = ccdb->getSpecific(ccdbPath.value, bc.timestamp(), metadata); - headers = ccdbApi.retrieveHeaders(ccdbPath.value, metadata, bc.timestamp()); - networkVersion = headers["NN-Version"]; + response = ccdb->getSpecific(ccdbPath.value, bc.timestamp(), metadata, &headers); if (!response) { LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", metadata["RecoPassName"]); - headers = ccdbApi.retrieveHeaders(ccdbPath.value, nullmetadata, bc.timestamp()); - response = ccdb->getForTimeStamp(ccdbPath.value, bc.timestamp()); + response = ccdb->getForTimeStamp(ccdbPath.value, bc.timestamp(), &headers); if (!response) { LOGP(fatal, "Could not find ANY TPC response object for the timestamp {}!", bc.timestamp()); } } + networkVersion = headers["NN-Version"]; LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << bc.timestamp() << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"]; metadata["RecoPassName"] = headers["RecoPassName"]; // Force pass number for NN request to match retrieved BB response->PrintAll(); @@ -336,14 +330,13 @@ struct tpcPid { if (bc.timestamp() < network.getValidityFrom() || bc.timestamp() > network.getValidityUntil()) { // fetches network only if the runnumbers change LOG(info) << "Fetching network for timestamp: " << bc.timestamp(); - bool retrieveSuccess = ccdbApi.retrieveBlob(networkPathCCDB.value, ".", metadata, bc.timestamp(), false, networkPathLocally.value); - headers = ccdbApi.retrieveHeaders(networkPathCCDB.value, metadata, bc.timestamp()); + bool retrieveSuccess = ccdb->getCCDBAccessor().retrieveBlob(networkPathCCDB.value, ".", metadata, bc.timestamp(), false, networkPathLocally.value, "", "", &headers); networkVersion = headers["NN-Version"]; if (retrieveSuccess) { network.initModel(networkPathLocally.value, enableNetworkOptimizations.value, networkSetNumThreads.value, strtoul(headers["Valid-From"].c_str(), NULL, 0), strtoul(headers["Valid-Until"].c_str(), NULL, 0)); std::vector dummyInput(network.getNumInputNodes(), 1.); network.evalModel(dummyInput); - LOGP(info, "Retrieved NN corrections for production tag {}, pass number {}, NN-Version number{}", headers["LPMProductionTag"], headers["RecoPassName"], headers["NN-Version"]); + LOGP(info, "Retrieved NN corrections for production tag {}, pass number {}, NN-Version number {}", headers["LPMProductionTag"], headers["RecoPassName"], headers["NN-Version"]); } else { LOG(fatal) << "No valid NN object found matching retrieved Bethe-Bloch parametrisation for pass " << metadata["RecoPassName"] << ". Please ensure that the requested pass has dedicated NN corrections available"; } @@ -553,12 +546,10 @@ struct tpcPid { } else { LOGP(info, "Retrieving TPC Response for timestamp {} and recoPass {}:", bc.timestamp(), recoPass.value); } - response = ccdb->getSpecific(ccdbPath.value, bc.timestamp(), metadata); - headers = ccdbApi.retrieveHeaders(ccdbPath.value, metadata, bc.timestamp()); + response = ccdb->getSpecific(ccdbPath.value, bc.timestamp(), metadata, &headers); if (!response) { LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", metadata["RecoPassName"]); - response = ccdb->getForTimeStamp(ccdbPath.value, bc.timestamp()); - headers = ccdbApi.retrieveHeaders(ccdbPath.value, nullmetadata, bc.timestamp()); + response = ccdb->getForTimeStamp(ccdbPath.value, bc.timestamp(), &headers); if (!response) { LOGP(fatal, "Could not find ANY TPC response object for the timestamp {}!", bc.timestamp()); } @@ -651,12 +642,11 @@ struct tpcPid { } else { LOGP(info, "Retrieving TPC Response for timestamp {} and recoPass {}:", bc.timestamp(), recoPass.value); } - response = ccdb->getSpecific(ccdbPath.value, bc.timestamp(), metadata); - headers = ccdbApi.retrieveHeaders(ccdbPath.value, metadata, bc.timestamp()); + response = ccdb->getSpecific(ccdbPath.value, bc.timestamp(), metadata, &headers); + if (!response) { LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", metadata["RecoPassName"]); - response = ccdb->getForTimeStamp(ccdbPath.value, bc.timestamp()); - headers = ccdbApi.retrieveHeaders(ccdbPath.value, nullmetadata, bc.timestamp()); + response = ccdb->getForTimeStamp(ccdbPath.value, bc.timestamp(), &headers); if (!response) { LOGP(fatal, "Could not find ANY TPC response object for the timestamp {}!", bc.timestamp()); } @@ -737,10 +727,10 @@ struct tpcPid { } else { LOGP(info, "Retrieving TPC Response for timestamp {} and recoPass {}:", bc.timestamp(), recoPass.value); } - response = ccdb->getSpecific(ccdbPath.value, bc.timestamp(), metadata); + response = ccdb->getSpecific(ccdbPath.value, bc.timestamp(), metadata, &headers); if (!response) { LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", metadata["RecoPassName"]); - response = ccdb->getForTimeStamp(ccdbPath.value, bc.timestamp()); + response = ccdb->getForTimeStamp(ccdbPath.value, bc.timestamp(), &headers); if (!response) { LOGP(fatal, "Could not find ANY TPC response object for the timestamp {}!", bc.timestamp()); } diff --git a/Common/TableProducer/PID/pidTPCService.cxx b/Common/TableProducer/PID/pidTPCService.cxx index 6ad86916c1f..974f29b2106 100644 --- a/Common/TableProducer/PID/pidTPCService.cxx +++ b/Common/TableProducer/PID/pidTPCService.cxx @@ -47,7 +47,6 @@ struct pidTpcService { // CCDB boilerplate declarations o2::framework::Configurable ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; Service ccdb; - o2::ccdb::CcdbApi ccdbApi; o2::aod::pid::pidTPCProducts products; o2::aod::pid::pidTPCConfigurables pidTPCopts; @@ -61,25 +60,24 @@ struct pidTpcService { ccdb->setCaching(true); ccdb->setLocalObjectValidityChecking(); ccdb->setCreatedNotAfter(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); - ccdbApi.init(ccdburl.value); // task-specific - pidTPC.init(ccdb, ccdbApi, initContext, pidTPCopts, metadataInfo); + pidTPC.init(ccdb, initContext, pidTPCopts, metadataInfo); } void processTracksIU(soa::Join const& collisions, soa::Join const& tracks, aod::BCsWithTimestamps const& bcs) { - pidTPC.process(ccdb, ccdbApi, bcs, collisions, tracks, static_cast(nullptr), products); + pidTPC.process(ccdb, bcs, collisions, tracks, static_cast(nullptr), products); } void processTracksMCIU(soa::Join const& collisions, soa::Join const& tracks, aod::BCsWithTimestamps const& bcs, aod::McParticles const&) { - pidTPC.process(ccdb, ccdbApi, bcs, collisions, tracks, static_cast(nullptr), products); + pidTPC.process(ccdb, bcs, collisions, tracks, static_cast(nullptr), products); } void processTracksIUWithTracksQA(soa::Join const& collisions, soa::Join const& tracks, aod::BCsWithTimestamps const& bcs, aod::TracksQAVersion const& tracksQA) { - pidTPC.process(ccdb, ccdbApi, bcs, collisions, tracks, tracksQA, products); + pidTPC.process(ccdb, bcs, collisions, tracks, tracksQA, products); } PROCESS_SWITCH(pidTpcService, processTracksIU, "Process TracksIU (Run 3)", true); diff --git a/Common/TableProducer/PID/pidTPCServiceRun2.cxx b/Common/TableProducer/PID/pidTPCServiceRun2.cxx index 184fb4eb6e0..642f3bf08b7 100644 --- a/Common/TableProducer/PID/pidTPCServiceRun2.cxx +++ b/Common/TableProducer/PID/pidTPCServiceRun2.cxx @@ -47,7 +47,6 @@ struct pidTpcServiceRun2 { // CCDB boilerplate declarations o2::framework::Configurable ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; Service ccdb; - o2::ccdb::CcdbApi ccdbApi; o2::aod::pid::pidTPCProducts products; o2::aod::pid::pidTPCConfigurables pidTPCopts; @@ -61,20 +60,19 @@ struct pidTpcServiceRun2 { ccdb->setCaching(true); ccdb->setLocalObjectValidityChecking(); ccdb->setCreatedNotAfter(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); - ccdbApi.init(ccdburl.value); // task-specific - pidTPC.init(ccdb, ccdbApi, initContext, pidTPCopts, metadataInfo); + pidTPC.init(ccdb, initContext, pidTPCopts, metadataInfo); } void processTracks(soa::Join const& collisions, soa::Join const& tracks, aod::BCsWithTimestamps const& bcs) { - pidTPC.process(ccdb, ccdbApi, bcs, collisions, tracks, static_cast(nullptr), products); + pidTPC.process(ccdb, bcs, collisions, tracks, static_cast(nullptr), products); } void processTracksMC(soa::Join const& collisions, soa::Join const& tracks, aod::BCsWithTimestamps const& bcs, aod::McParticles const&) { - pidTPC.process(ccdb, ccdbApi, bcs, collisions, tracks, static_cast(nullptr), products); + pidTPC.process(ccdb, bcs, collisions, tracks, static_cast(nullptr), products); } PROCESS_SWITCH(pidTpcServiceRun2, processTracks, "Process Tracks", true); diff --git a/Common/Tools/PID/pidTPCModule.h b/Common/Tools/PID/pidTPCModule.h index 721fd86f826..fb5d06c38a2 100644 --- a/Common/Tools/PID/pidTPCModule.h +++ b/Common/Tools/PID/pidTPCModule.h @@ -213,7 +213,6 @@ class pidTPCModule // Network correction for TPC PID response ml::OnnxModel network; std::map metadata; - std::map nullmetadata; std::map headers; std::vector speciesNetworkFlags = std::vector(9); std::string networkVersion; @@ -230,8 +229,8 @@ class pidTPCModule Str_dEdx_correction str_dedx_correction; //__________________________________________________ - template - void init(TCCDB& ccdb, TCCDBApi& ccdbApi, TContext& context, TpidTPCOpts const& external_pidtpcopts, TMetadataInfo const& metadataInfo) + template + void init(TCCDB& ccdb, TContext& context, TpidTPCOpts const& external_pidtpcopts, TMetadataInfo const& metadataInfo) { // read in configurations from the task where it's used pidTPCopts = external_pidtpcopts; @@ -373,17 +372,15 @@ class pidTPCModule if (time != 0) { LOGP(info, "Initialising TPC PID response for fixed timestamp {} and reco pass {}:", time, pidTPCopts.recoPass.value); ccdb->setTimestamp(time); - response = ccdb->template getSpecific(path, time, metadata); - headers = ccdbApi.retrieveHeaders(path, metadata, time); + response = ccdb->template getSpecific(path, time, metadata, &headers); if (!response) { LOGF(warning, "Unable to find TPC parametrisation for specified pass name - falling back to latest object"); - response = ccdb->template getForTimeStamp(path, time); - headers = ccdbApi.retrieveHeaders(path, metadata, time); - networkVersion = headers["NN-Version"]; + response = ccdb->template getForTimeStamp(path, time, &headers); if (!response) { LOGF(fatal, "Unable to find any TPC object corresponding to timestamp {}!", time); } } + networkVersion = headers["NN-Version"]; LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << time << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"]; metadata["RecoPassName"] = headers["RecoPassName"]; // Force pass number for NN request to match retrieved BB o2::parameters::GRPLHCIFData* grpo = ccdb->template getForTimeStamp(pidTPCopts.cfgPathGrpLhcIf.value, time); @@ -411,8 +408,7 @@ class pidTPCModule if (pidTPCopts.ccdbTimestamp > 0) { /// Fetching network for specific timestamp LOG(info) << "Fetching network for timestamp: " << pidTPCopts.ccdbTimestamp.value; - bool retrieveSuccess = ccdbApi.retrieveBlob(pidTPCopts.networkPathCCDB.value, ".", metadata, pidTPCopts.ccdbTimestamp.value, false, pidTPCopts.networkPathLocally.value); - headers = ccdbApi.retrieveHeaders(pidTPCopts.networkPathCCDB.value, metadata, pidTPCopts.ccdbTimestamp.value); + bool retrieveSuccess = ccdb->getCCDBAccessor().retrieveBlob(pidTPCopts.networkPathCCDB.value, ".", metadata, pidTPCopts.ccdbTimestamp.value, false, pidTPCopts.networkPathLocally.value, "", "", &headers); networkVersion = headers["NN-Version"]; if (retrieveSuccess) { network.initModel(pidTPCopts.networkPathLocally.value, pidTPCopts.enableNetworkOptimizations.value, pidTPCopts.networkSetNumThreads.value, strtoul(headers["Valid-From"].c_str(), NULL, 0), strtoul(headers["Valid-Until"].c_str(), NULL, 0)); @@ -443,8 +439,8 @@ class pidTPCModule } // end init //__________________________________________________ - template - std::vector createNetworkPrediction(TCCDB& ccdb, TCCDBApi& ccdbApi, soa::Join const& collisions, M const& mults, T const& tracks, B const& bcs, const size_t size) + template + std::vector createNetworkPrediction(TCCDB& ccdb, soa::Join const& collisions, M const& mults, T const& tracks, B const& bcs, const size_t size) { std::vector network_prediction; @@ -459,13 +455,11 @@ class pidTPCModule } else { LOGP(info, "Retrieving TPC Response for timestamp {} and recoPass {}:", bc.timestamp(), pidTPCopts.recoPass.value); } - response = ccdb->template getSpecific(pidTPCopts.ccdbPath.value, bc.timestamp(), metadata); - headers = ccdbApi.retrieveHeaders(pidTPCopts.ccdbPath.value, metadata, bc.timestamp()); + response = ccdb->template getSpecific(pidTPCopts.ccdbPath.value, bc.timestamp(), metadata, &headers); networkVersion = headers["NN-Version"]; if (!response) { LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", metadata["RecoPassName"]); - headers = ccdbApi.retrieveHeaders(pidTPCopts.ccdbPath.value, nullmetadata, bc.timestamp()); - response = ccdb->template getForTimeStamp(pidTPCopts.ccdbPath.value, bc.timestamp()); + response = ccdb->template getForTimeStamp(pidTPCopts.ccdbPath.value, bc.timestamp(), &headers); if (!response) { LOGP(fatal, "Could not find ANY TPC response object for the timestamp {}!", bc.timestamp()); } @@ -489,14 +483,13 @@ class pidTPCModule if (bc.timestamp() < network.getValidityFrom() || bc.timestamp() > network.getValidityUntil()) { // fetches network only if the runnumbers change LOG(info) << "Fetching network for timestamp: " << bc.timestamp(); - bool retrieveSuccess = ccdbApi.retrieveBlob(pidTPCopts.networkPathCCDB.value, ".", metadata, bc.timestamp(), false, pidTPCopts.networkPathLocally.value); - headers = ccdbApi.retrieveHeaders(pidTPCopts.networkPathCCDB.value, metadata, bc.timestamp()); + bool retrieveSuccess = ccdb->getCCDBAccessor().retrieveBlob(pidTPCopts.networkPathCCDB.value, ".", metadata, bc.timestamp(), false, pidTPCopts.networkPathLocally.value, "", "", &headers); networkVersion = headers["NN-Version"]; if (retrieveSuccess) { network.initModel(pidTPCopts.networkPathLocally.value, pidTPCopts.enableNetworkOptimizations.value, pidTPCopts.networkSetNumThreads.value, strtoul(headers["Valid-From"].c_str(), NULL, 0), strtoul(headers["Valid-Until"].c_str(), NULL, 0)); std::vector dummyInput(network.getNumInputNodes(), 1.); network.evalModel(dummyInput); - LOGP(info, "Retrieved NN corrections for production tag {}, pass number {}, NN-Version number{}", headers["LPMProductionTag"], headers["RecoPassName"], headers["NN-Version"]); + LOGP(info, "Retrieved NN corrections for production tag {}, pass number {}, NN-Version number {}", headers["LPMProductionTag"], headers["RecoPassName"], headers["NN-Version"]); } else { LOG(fatal) << "No valid NN object found matching retrieved Bethe-Bloch parametrisation for pass " << metadata["RecoPassName"] << ". Please ensure that the requested pass has dedicated NN corrections available"; } @@ -660,7 +653,7 @@ class pidTPCModule nSigma = (tpcSignal / expSignal - network_prediction[NumOutputNodesAsymmetricSigma * (count_tracks + tracksForNet_size * pid)]) / (network_prediction[NumOutputNodesAsymmetricSigma * (count_tracks + tracksForNet_size * pid)] - network_prediction[NumOutputNodesAsymmetricSigma * (count_tracks + tracksForNet_size * pid) + 2]); } } else { - LOGF(fatal, "Network output-dimensions incompatible!"); + LOGF(fatal, "Network output dimensions incompatible!"); } } else { nSigma = response->GetNumberOfSigmaMCTunedAtMultiplicity(multTPC, trk, pid, tpcSignal); @@ -672,8 +665,8 @@ class pidTPCModule }; //__________________________________________________ - template - void process(TCCDB& ccdb, TCCDBApi& ccdbApi, TBCs const& bcs, soa::Join const& cols, TTracks const& tracks, TTracksQA const& tracksQA, TProducts& products) + template + void process(TCCDB& ccdb, TBCs const& bcs, soa::Join const& cols, TTracks const& tracks, TTracksQA const& tracksQA, TProducts& products) { if (tracks.size() == 0) { return; // empty protection @@ -736,7 +729,7 @@ class pidTPCModule std::vector network_prediction; if (pidTPCopts.useNetworkCorrection) { - network_prediction = createNetworkPrediction(ccdb, ccdbApi, cols, pidmults, tracks, bcs, tracksForNet_size); + network_prediction = createNetworkPrediction(ccdb, cols, pidmults, tracks, bcs, tracksForNet_size); } uint64_t count_tracks = 0; @@ -866,12 +859,10 @@ class pidTPCModule } else { LOGP(info, "Retrieving TPC Response for timestamp {} and recoPass {}:", bc.timestamp(), pidTPCopts.recoPass.value); } - response = ccdb->template getSpecific(pidTPCopts.ccdbPath.value, bc.timestamp(), metadata); - headers = ccdbApi.retrieveHeaders(pidTPCopts.ccdbPath.value, metadata, bc.timestamp()); + response = ccdb->template getSpecific(pidTPCopts.ccdbPath.value, bc.timestamp(), metadata, &headers); if (!response) { LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", metadata["RecoPassName"]); - response = ccdb->template getForTimeStamp(pidTPCopts.ccdbPath.value, bc.timestamp()); - headers = ccdbApi.retrieveHeaders(pidTPCopts.ccdbPath.value, nullmetadata, bc.timestamp()); + response = ccdb->template getForTimeStamp(pidTPCopts.ccdbPath.value, bc.timestamp(), &headers); if (!response) { LOGP(fatal, "Could not find ANY TPC response object for the timestamp {}!", bc.timestamp()); }