|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +/// \file onTheFlyDetectorGeometryProvider.cxx |
| 13 | +/// |
| 14 | +/// \brief Reader and and provider of the detector geometry for on-the-fly simulation |
| 15 | +/// |
| 16 | +/// \author Nicolò Jacazio <nicolo.jacazio@cern.ch>, Universita del Piemonte Orientale (IT) |
| 17 | +/// |
| 18 | + |
| 19 | +#include "ALICE3/Core/FastTracker.h" |
| 20 | + |
| 21 | +#include <CCDB/BasicCCDBManager.h> |
| 22 | +#include <Framework/AnalysisTask.h> |
| 23 | +#include <Framework/runDataProcessing.h> |
| 24 | + |
| 25 | +#include <map> |
| 26 | +#include <string> |
| 27 | +#include <vector> |
| 28 | + |
| 29 | +struct OnTheFlyDetectorGeometryProvider { |
| 30 | + |
| 31 | + o2::framework::Configurable<std::vector<std::string>> detectorConfiguration{"detectorConfiguration", |
| 32 | + std::vector<std::string>{"$O2PHYSICS_ROOT/share/alice3/a3geometry_v3.ini"}, |
| 33 | + "Paths of the detector geometry configuration files"}; |
| 34 | + o2::framework::Service<o2::ccdb::BasicCCDBManager> ccdb; |
| 35 | + void init(o2::framework::InitContext&) |
| 36 | + { |
| 37 | + ccdb->setURL("http://alice-ccdb.cern.ch"); |
| 38 | + ccdb->setTimestamp(-1); |
| 39 | + } |
| 40 | + void run(o2::framework::ProcessingContext& pc) |
| 41 | + { |
| 42 | + o2::fastsim::GeometryContainer geometryContainer; // Checking that the geometry files can be accessed and loaded |
| 43 | + LOG(info) << "On-the-fly detector geometry provider running."; |
| 44 | + if (detectorConfiguration.value.empty()) { |
| 45 | + LOG(fatal) << "No detector configuration files provided."; |
| 46 | + return; |
| 47 | + } |
| 48 | + int idx = 0; |
| 49 | + for (auto& configFile : detectorConfiguration.value) { |
| 50 | + LOG(info) << "Loading detector geometry from configuration file: " << configFile; |
| 51 | + // If the filename starts with ccdb: then take the file from the ccdb |
| 52 | + if (configFile.rfind("ccdb:", 0) == 0) { |
| 53 | + std::string ccdbPath = configFile.substr(5); // remove "ccdb:" prefix |
| 54 | + const std::string outPath = "/tmp/DetGeo/"; |
| 55 | + configFile = Form("%s/%s/snapshot.root", outPath.c_str(), ccdbPath.c_str()); |
| 56 | + std::ifstream checkFile(configFile); // Check if file already exists |
| 57 | + if (!checkFile.is_open()) { // File does not exist, retrieve from CCDB |
| 58 | + LOG(info) << " --- CCDB source detected for detector geometry " << configFile; |
| 59 | + std::map<std::string, std::string> metadata; |
| 60 | + ccdb->getCCDBAccessor().retrieveBlob(ccdbPath, outPath, metadata, 1); |
| 61 | + LOG(info) << " --- Now retrieving geometry configuration from CCDB to: " << configFile; |
| 62 | + } else { // File exists, proceed to load |
| 63 | + LOG(info) << " --- Geometry configuration file already exists: " << configFile << ". Skipping download."; |
| 64 | + checkFile.close(); |
| 65 | + } |
| 66 | + detectorConfiguration.value[idx] = configFile; // Update the filename to the local file |
| 67 | + } |
| 68 | + geometryContainer.addEntry(configFile); |
| 69 | + idx++; |
| 70 | + } |
| 71 | + pc.services().get<o2::framework::ControlService>().endOfStream(); |
| 72 | + pc.services().get<o2::framework::ControlService>().readyToQuit(o2::framework::QuitRequest::Me); |
| 73 | + } |
| 74 | +}; |
| 75 | + |
| 76 | +// #define VERIFY_ALICE3 |
| 77 | +#ifdef VERIFY_ALICE3 |
| 78 | +struct OnTheFlyDetectorGeometryUser { |
| 79 | + void init(o2::framework::InitContext& initContext) |
| 80 | + { |
| 81 | + o2::fastsim::GeometryContainer geometryContainer; // Checking that the configuration can be inherited |
| 82 | + geometryContainer.init(initContext); |
| 83 | + } |
| 84 | + void run(o2::framework::ProcessingContext& pc) |
| 85 | + { |
| 86 | + pc.services().get<o2::framework::ControlService>().endOfStream(); |
| 87 | + pc.services().get<o2::framework::ControlService>().readyToQuit(o2::framework::QuitRequest::Me); |
| 88 | + } |
| 89 | +}; |
| 90 | +#endif |
| 91 | + |
| 92 | +o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& cfgc) |
| 93 | +{ |
| 94 | + o2::framework::WorkflowSpec spec; |
| 95 | + spec.push_back(adaptAnalysisTask<OnTheFlyDetectorGeometryProvider>(cfgc)); |
| 96 | +#ifdef VERIFY_ALICE3 |
| 97 | + spec.push_back(adaptAnalysisTask<OnTheFlyDetectorGeometryUser>(cfgc)); |
| 98 | +#endif |
| 99 | + return spec; |
| 100 | +} |
0 commit comments