Skip to content

Commit 5682fab

Browse files
committed
Fetch models from CCDB or AliEn
1 parent 88ee20d commit 5682fab

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed
-632 KB
Binary file not shown.
-638 KB
Binary file not shown.

MC/config/common/external/generator/TPCLoopers.C

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <vector>
44
#include <fstream>
55
#include <rapidjson/document.h>
6+
#include "CCDB/BasicCCDBManager.h"
7+
#include "CCDB/CcdbApi.h"
68

79
// Static Ort::Env instance for multiple onnx model loading
810
static Ort::Env global_env(ORT_LOGGING_LEVEL_WARNING, "GlobalEnv");
@@ -377,6 +379,11 @@ class GenTPCLoopers : public Generator
377379
} // namespace eventgen
378380
} // namespace o2
379381

382+
// ONNX model files can be local, on AliEn or in the ALICE CCDB.
383+
// For local and alien files it is mandatory to provide the filenames, for the CCDB instead the
384+
// path to the object in the CCDB is sufficient. The model files will be downloaded locally.
385+
// Example of CCDB path: "ccdb:Users/n/name/test"
386+
// Example of alien path: "alien:///alice/cern.ch/user/n/name/test/test.onnx"
380387
FairGenerator *
381388
Generator_TPCLoopers(std::string model_pairs = "tpcloopmodel.onnx", std::string model_compton = "tpcloopmodelcompton.onnx",
382389
std::string poisson = "poisson.csv", std::string gauss = "gauss.csv", std::string scaler_pair = "scaler_pair.json",
@@ -390,6 +397,49 @@ FairGenerator *
390397
gauss = gSystem->ExpandPathName(gauss.c_str());
391398
scaler_pair = gSystem->ExpandPathName(scaler_pair.c_str());
392399
scaler_compton = gSystem->ExpandPathName(scaler_compton.c_str());
400+
const std::array<std::string, 2> models = {model_pairs, model_compton};
401+
const std::array<std::string, 2> local_names = {"WGANpair.onnx", "WGANcompton.onnx"};
402+
const std::array<bool, 2> isAlien = {models[0].starts_with("alien://"), models[1].starts_with("alien://")};
403+
const std::array<bool, 2> isCCDB = {models[0].starts_with("ccdb:"), models[1].starts_with("ccdb:")};
404+
if (std::any_of(isAlien.begin(), isAlien.end(), [](bool v) { return v; }))
405+
{
406+
TGrid::Connect("alien://");
407+
for (size_t i = 0; i < models.size(); ++i)
408+
{
409+
if (isAlien[i] && !TFile::Cp(models[i].c_str(), local_names[i].c_str()))
410+
{
411+
LOG(fatal) << "Error: Model file " << models[i] << " does not exist!";
412+
exit(1);
413+
}
414+
}
415+
}
416+
if (std::any_of(isCCDB.begin(), isCCDB.end(), [](bool v) { return v; }))
417+
{
418+
o2::ccdb::CcdbApi ccdb_api;
419+
ccdb_api.init("http://alice-ccdb.cern.ch");
420+
for (size_t i = 0; i < models.size(); ++i)
421+
{
422+
if (isCCDB[i])
423+
{
424+
auto model_path = models[i].substr(5);
425+
// Treat filename is provided in the CCDB path
426+
auto extension = model_path.find(".onnx");
427+
if (extension != std::string::npos)
428+
{
429+
auto last_slash = model_path.find_last_of('/');
430+
model_path = model_path.substr(0, last_slash);
431+
}
432+
std::map<std::string, std::string> filter;
433+
if(!ccdb_api.retrieveBlob(model_path, "./" , filter, o2::ccdb::getCurrentTimestamp(), false, local_names[i].c_str()))
434+
{
435+
LOG(fatal) << "Error: issues in retrieving " << model_path << " from CCDB!";
436+
exit(1);
437+
}
438+
}
439+
}
440+
}
441+
model_pairs = isAlien[0] || isCCDB[0] ? local_names[0] : model_pairs;
442+
model_compton = isAlien[1] || isCCDB[1] ? local_names[1] : model_compton;
393443
auto generator = new o2::eventgen::GenTPCLoopers(model_pairs, model_compton, poisson, gauss, scaler_pair, scaler_compton);
394444
generator->SetNLoopers(nloopers_pairs, nloopers_compton);
395445
generator->SetMultiplier(mult);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Example of tpc loopers generator with a poisson distribution of pairs and gaussian distribution of compton electrons
22
[GeneratorExternal]
33
fileName = ${O2DPG_MC_CONFIG_ROOT}/MC/config/common/external/generator/TPCLoopers.C
4-
funcName = Generator_TPCLoopers("${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/generatorWGAN_pair.onnx", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/generatorWGAN_compton.onnx", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/poisson_params.csv", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/gaussian_params.csv", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/ScalerPairParams.json", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/ScalerComptonParams.json")
4+
funcName = Generator_TPCLoopers("ccdb:Users/m/mgiacalo/WGAN_ExtGenPair", "ccdb:Users/m/mgiacalo/WGAN_ExtGenCompton", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/poisson_params.csv", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/gaussian_params.csv", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/ScalerPairParams.json", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/ScalerComptonParams.json")
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# Example of tpc loopers generator with a fixed number of pairs (10)
1+
# Example of tpc loopers generator with a fixed number of pairs and compton electrons (10)
2+
# Multiplier values are ignored in this case, but kept to 1 for consistency
23
#---> GeneratorTPCloopers
34
[GeneratorExternal]
45
fileName = ${O2DPG_MC_CONFIG_ROOT}/MC/config/common/external/generator/TPCLoopers.C
5-
funcName = Generator_TPCLoopers("${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/generatorWGAN_pair.onnx", "", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/ScalerPairParams.json",10)
6+
funcName = Generator_TPCLoopers("ccdb:Users/m/mgiacalo/WGAN_ExtGenPair", "ccdb:Users/m/mgiacalo/WGAN_ExtGenCompton", "", "", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/ScalerPairParams.json", "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/TPCloopers/ScalerComptonParams.json",{1.,1.}, 10,10)

0 commit comments

Comments
 (0)