2121#include < CCDB/BasicCCDBManager.h>
2222#include < Framework/AnalysisTask.h>
2323#include < Framework/HistogramRegistry.h>
24- #include < Framework/RunningWorkflowInfo.h>
2524#include < Framework/runDataProcessing.h>
2625
27- #include < filesystem>
2826#include < map>
2927#include < string>
3028#include < vector>
@@ -34,39 +32,9 @@ struct OnTheFlyDetectorGeometryProvider {
3432 o2::framework::Configurable<std::vector<std::string>> detectorConfiguration{" detectorConfiguration" ,
3533 std::vector<std::string>{" $O2PHYSICS_ROOT/share/alice3/a3geometry_v3.ini" },
3634 " Paths of the detector geometry configuration files" };
37- o2::framework::Configurable<std::string> flagFile{" flagFile" , " /tmp/OnTheFlyDetectorGeometryProvider.initialized" , " Not to change" };
3835 o2::framework::Service<o2::ccdb::BasicCCDBManager> ccdb;
39-
40- std::string accessFile (std::string filename, const std::string& ccdbOutPath)
41- {
42- if (filename.rfind (" ccdb:" , 0 ) == 0 ) {
43- std::string ccdbPath = filename.substr (5 ); // remove "ccdb:" prefix
44- filename = Form (" %s/%s/snapshot.root" , ccdbOutPath.c_str (), ccdbPath.c_str ());
45- std::ifstream checkFile (filename); // Check if file already exists
46- if (!checkFile.is_open ()) { // File does not exist, retrieve from CCDB
47- LOG (info) << " --- CCDB source detected for detector geometry " << filename;
48- std::map<std::string, std::string> metadata;
49- ccdb->getCCDBAccessor ().retrieveBlob (ccdbPath, ccdbOutPath, metadata, 1 );
50- LOG (info) << " --- Now retrieving geometry configuration from CCDB to: " << filename;
51- } else { // File exists, proceed to load
52- LOG (info) << " --- Geometry configuration file already exists: " << filename << " . Skipping download." ;
53- checkFile.close ();
54- }
55- }
56- return filename;
57- }
58- std::vector<std::string> mDownloadedLuts ; // Vector of the downloaded LUTs
5936 void init (o2::framework::InitContext&)
6037 {
61- const std::string mInitFlagFile = " /tmp/OnTheFlyDetectorGeometryProvider.initialized" ;
62- if (flagFile.value != mInitFlagFile ) {
63- LOG (fatal) << " The flagFile configurable should not be changed from its default value." ;
64- return ;
65- }
66- if (std::ifstream (mInitFlagFile ).good ()) {
67- std::filesystem::remove (mInitFlagFile );
68- }
69-
7038 ccdb->setURL (" http://alice-ccdb.cern.ch" );
7139 ccdb->setTimestamp (-1 );
7240 o2::fastsim::GeometryContainer geometryContainer; // Checking that the geometry files can be accessed and loaded
@@ -79,8 +47,23 @@ struct OnTheFlyDetectorGeometryProvider {
7947 for (std::string& configFile : detectorConfiguration.value ) {
8048 LOG (info) << " Loading detector geometry from configuration file: " << configFile;
8149 histos.add <TH1>(Form (" GeometryConfigFile_%d" , idx), configFile.c_str (), o2::framework::HistType::kTH1D , {{1 , 0 , 1 }})->Fill (0.5 );
82- configFile = accessFile (configFile, " /tmp/DetGeo/" ); // Handle the possibility that the file is on the CCDB
83- detectorConfiguration.value [idx] = configFile; // Update the filename to the local file (relevant only if the file was on CCDB)
50+ // If the filename starts with ccdb: then take the file from the ccdb
51+ if (configFile.rfind (" ccdb:" , 0 ) == 0 ) {
52+ std::string ccdbPath = configFile.substr (5 ); // remove "ccdb:" prefix
53+ const std::string outPath = " /tmp/DetGeo/" ;
54+ configFile = Form (" %s/%s/snapshot.root" , outPath.c_str (), ccdbPath.c_str ());
55+ std::ifstream checkFile (configFile); // Check if file already exists
56+ if (!checkFile.is_open ()) { // File does not exist, retrieve from CCDB
57+ LOG (info) << " --- CCDB source detected for detector geometry " << configFile;
58+ std::map<std::string, std::string> metadata;
59+ ccdb->getCCDBAccessor ().retrieveBlob (ccdbPath, outPath, metadata, 1 );
60+ LOG (info) << " --- Now retrieving geometry configuration from CCDB to: " << configFile;
61+ } else { // File exists, proceed to load
62+ LOG (info) << " --- Geometry configuration file already exists: " << configFile << " . Skipping download." ;
63+ checkFile.close ();
64+ }
65+ detectorConfiguration.value [idx] = configFile; // Update the filename to the local file
66+ }
8467 geometryContainer.addEntry (configFile);
8568 idx++;
8669 }
@@ -93,27 +76,8 @@ struct OnTheFlyDetectorGeometryProvider {
9376 if (std::abs (cfgBfield - mMagneticField ) > 1e-3 ) {
9477 LOG (fatal) << " Inconsistent magnetic field values between configurations 0 and " << icfg << " : " << mMagneticField << " vs " << cfgBfield;
9578 }
96- // Accessing the ccdb LUTs to check they are accessible and to cache them
97- const std::vector<std::string> particles = {" El" , " Mu" , " Pi" , " Ka" , " Pr" , " De" , " Tr" , " He" , " Al" };
98- for (const auto & particle : particles) {
99- const std::string name = geometryContainer.getValue (icfg, " global" , " lut" + particle, false );
100- if (!name.empty ()) {
101- const std::string downloaded = accessFile (name, " /tmp/LUTs/" );
102- if (downloaded != name) {
103- mDownloadedLuts .push_back (downloaded);
104- }
105- }
106- }
10779 }
108- // Adding a flag to the initContext to signal that the init process is done
109- std::ofstream initFlag (mInitFlagFile );
110- initFlag.close ();
11180 LOG (info) << " Initialization completed" ;
112-
113- if (std::ifstream (flagFile.value ).good ()) {
114- std::this_thread::sleep_for (std::chrono::seconds (10 ));
115- std::filesystem::remove (flagFile.value );
116- }
11781 }
11882
11983 void process (o2::aod::McCollisions const & mcCollisions, o2::aod::McParticles const & mcParticles)
0 commit comments