|
||||
File indexing completed on 2025-01-18 10:17:34
0001 0002 // Copyright 2007-2025, Jefferson Science Associates, LLC. 0003 // Subject to the terms in the LICENSE file found in the top-level directory. 0004 // Author: David Lawrence 0005 0006 #include "JGeometryManager.h" 0007 0008 #include <JANA/JLogger.h> 0009 #include <JANA/Geometry/JGeometryXML.h> 0010 0011 0012 JGeometry *JGeometryManager::GetJGeometry(unsigned int run_number) { 0013 0014 /// Return a pointer a JGeometry object that is valid for the given run number. 0015 /// 0016 /// This first searches through the list of existing JGeometry objects created by 0017 /// this JApplication object to see if it already has the right one. If so, a pointer 0018 /// to it is returned. If not, a new JGeometry object is created and added to the 0019 /// internal list. Note that since we need to make sure the list is not modified 0020 /// by one thread while being searched by another, a mutex is locked while searching 0021 /// the list. It is <b>NOT</b> efficient to get the JGeometry object pointer every 0022 /// event. Factories should get a copy in their brun() callback and keep a local 0023 /// copy of the pointer for use in the evnt() callback. 0024 0025 // Lock mutex to keep list from being modified while we search it 0026 std::lock_guard<std::mutex> lock(m_mutex); 0027 0028 for (auto geometry : geometries) { 0029 if (geometry->GetRunMin() > (int) run_number) continue; 0030 if (geometry->GetRunMax() < (int) run_number) continue; 0031 return geometry; 0032 } 0033 0034 // JGeometry object for this run_number doesn't exist in our list. 0035 // Create a new one and add it to the list. 0036 // We need to create an object of the appropriate subclass of 0037 // JGeometry. This is determined by the first several characters 0038 // of the URL that specifies the calibration database location. 0039 // For now, only the JGeometryXML subclass exists so we'll 0040 // just make one of those and defer the heavier algorithm until 0041 // later. 0042 const char *url = getenv("JANA_GEOMETRY_URL"); 0043 if (!url) url = "file://./"; 0044 const char *context = getenv("JANA_GEOMETRY_CONTEXT"); 0045 if (!context) context = "default"; 0046 0047 // Decide what type of JGeometry object to create and instantiate it 0048 string url_str = url; 0049 string context_str = context; 0050 JGeometry *g = nullptr; 0051 0052 if (url_str.find("xmlfile://") == 0 || url_str.find("ccdb://") == 0) { 0053 g = new JGeometryXML(string(url), run_number, context); 0054 } 0055 /* 0056 else if (url_str.find("mysql:") == 0) { 0057 g = new JGeometryMYSQL(string(url), run_number, context); 0058 } 0059 */ 0060 if (g) { 0061 geometries.push_back(g); 0062 } 0063 else { 0064 jerr << "Cannot make JGeometry object for \"" << url_str << "\" (Don't know how!)" << std::endl; 0065 } 0066 return g; 0067 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |