Skip to content

Commit

Permalink
Merge pull request #397 from JeffersonLab/nbrei_deprecate_compatibility
Browse files Browse the repository at this point in the history
Deprecate Compatibility/ headers
  • Loading branch information
nathanwbrei authored Jan 2, 2025
2 parents a41c730 + 83c187f commit e583654
Show file tree
Hide file tree
Showing 28 changed files with 1,294 additions and 1,208 deletions.
6 changes: 5 additions & 1 deletion src/libraries/JANA/CLI/JVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@

#include <JANA/JVersion.h>


namespace jana::cli::jversion {
[[deprecated("Use JANA/JVersion.h instead")]]
constexpr static int header_is_deprecated = 0;
constexpr static int warn_about_header_deprecation = header_is_deprecated;
}
9 changes: 6 additions & 3 deletions src/libraries/JANA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ set(JANA2_SOURCES

Calibrations/JCalibration.cc
Calibrations/JCalibrationFile.cc
Calibrations/JLargeCalibration.cc
Calibrations/JResource.cc

Geometry/JGeometryManager.cc
Geometry/JGeometryXML.cc

CLI/JBenchmarker.cc
CLI/JSignalHandler.cc
CLI/JMain.cc

Compatibility/JStreamLog.cc
Compatibility/JStreamLogBuffer.cc
Compatibility/JGeometryManager.cc
Compatibility/JGeometryXML.cc
)

if (${USE_PODIO})
Expand Down Expand Up @@ -125,6 +126,7 @@ file(GLOB jana_services_headers "Services/*.h*")
file(GLOB jana_streaming_headers "Streaming/*.h*")
file(GLOB jana_utils_headers "Utils/*.h*")
file(GLOB jana_calibs_headers "Calibrations/*.h*")
file(GLOB jana_geometry_headers "Geometry/*.h*")
file(GLOB jana_cli_headers "CLI/*.h*")
file(GLOB jana_compat_headers "Compatibility/*.h*")
file(GLOB jana_podio_headers "Podio/*.h*")
Expand All @@ -137,6 +139,7 @@ install(FILES ${jana_services_headers} DESTINATION include/JANA/Services)
install(FILES ${jana_streaming_headers} DESTINATION include/JANA/Streaming)
install(FILES ${jana_utils_headers} DESTINATION include/JANA/Utils)
install(FILES ${jana_calibs_headers} DESTINATION include/JANA/Calibrations)
install(FILES ${jana_geometry_headers} DESTINATION include/JANA/Geometry)
install(FILES ${jana_cli_headers} DESTINATION include/JANA/CLI)
install(FILES ${jana_compat_headers} DESTINATION include/JANA/Compatibility)
install(FILES ${jana_component_headers} DESTINATION include/JANA/Components)
Expand Down
4 changes: 3 additions & 1 deletion src/libraries/JANA/Calibrations/JCalibration.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

// Copyright 2020, Jefferson Science Associates, LLC.

// Copyright 2007-2025, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.
// Author: David Lawrence

#include <JANA/JLogger.h>
#include "JCalibration.h"
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/JANA/Calibrations/JCalibration.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// Copyright 2020, Jefferson Science Associates, LLC.
// Copyright 2007-2025, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.
// Author: David Lawrence

#pragma once
#include <JANA/JException.h>
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/JANA/Calibrations/JCalibrationCCDB.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2020, Jefferson Science Associates, LLC.

// Copyright 2020-2025, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/JANA/Calibrations/JCalibrationFile.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// Copyright 2020, Jefferson Science Associates, LLC.
// Copyright 2012-2025, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.
// Author: David Lawrence

#include "JCalibrationFile.h"
#include <JANA/JLogger.h>
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/JANA/Calibrations/JCalibrationFile.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// Copyright 2020, Jefferson Science Associates, LLC.
// Copyright 2012-2025, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.
// Author: David Lawrence

#pragma once
#include "JCalibration.h"
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/JANA/Calibrations/JCalibrationGenerator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// Copyright 2020, Jefferson Science Associates, LLC.
// Copyright 2007-2025, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.
// Author: David Lawrence

#pragma once
#include <stdint.h>
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/JANA/Calibrations/JCalibrationGeneratorCCDB.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2020, Jefferson Science Associates, LLC.

// Copyright 2020-2025, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.

#pragma once
Expand Down
25 changes: 16 additions & 9 deletions src/libraries/JANA/Calibrations/JCalibrationManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2020, Jefferson Science Associates, LLC.

// Copyright 2007-2025, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.
// Author: David Lawrence

#pragma once
#include <JANA/Calibrations/JCalibration.h>
Expand All @@ -10,12 +12,12 @@

#include <algorithm>
#include "JANA/Services/JParameterManager.h"
#include "JLargeCalibration.h"
#include "JResource.h"

class JCalibrationManager : public JService {

vector<JCalibration *> m_calibrations;
vector<JLargeCalibration *> m_resource_managers;
vector<JResource *> m_resource_managers;
vector<JCalibrationGenerator *> m_calibration_generators;

pthread_mutex_t m_calibration_mutex;
Expand Down Expand Up @@ -177,10 +179,9 @@ class JCalibrationManager : public JService {
return calib->Get(namepath, vals, event_number);
}

JResource* GetResource(unsigned int run_number = 0) {

JLargeCalibration *GetLargeCalibration(unsigned int run_number = 0) {

/// Return a pointer to the JLargeCalibration object for the specified run_number. If no run_number is given or a
/// Return a pointer to the JResource object for the specified run_number. If no run_number is given or a
/// value of 0 is given, then the first element from the list of resource managers is returned. If no managers
/// currently exist, one will be created using one of the following in order of precedence:
/// 1. JCalibration corresponding to given run number
Expand All @@ -196,9 +197,9 @@ class JCalibrationManager : public JService {
pthread_mutex_lock(&m_resource_manager_mutex);
if (m_resource_managers.empty()) {
if (m_calibrations.empty()) {
m_resource_managers.push_back(new JLargeCalibration(m_params, nullptr));
m_resource_managers.push_back(new JResource(m_params, nullptr));
} else {
m_resource_managers.push_back(new JLargeCalibration(m_params, m_calibrations[0]));
m_resource_managers.push_back(new JResource(m_params, m_calibrations[0]));
}
}
pthread_mutex_unlock(&m_resource_manager_mutex);
Expand All @@ -213,14 +214,20 @@ class JCalibrationManager : public JService {
}

// No resource manager exists for the JCalibration that corresponds to the given run_number. Create one.
JLargeCalibration *resource_manager = new JLargeCalibration(m_params, jcalib);
JResource *resource_manager = new JResource(m_params, jcalib);
pthread_mutex_lock(&m_resource_manager_mutex);
m_resource_managers.push_back(resource_manager);
pthread_mutex_unlock(&m_resource_manager_mutex);

return resource_manager;

}

[[deprecated("Replaced with GetResource()")]]
JResource *GetLargeCalibration(unsigned int run_number = 0) {
return GetResource(run_number);
}

};


178 changes: 9 additions & 169 deletions src/libraries/JANA/Calibrations/JLargeCalibration.h
Original file line number Diff line number Diff line change
@@ -1,173 +1,13 @@
// $Id$
//
// File: JLargeCalibration.h
// Created: Mon Oct 15 07:36:44 EDT 2012
// Creator: davidl (on Darwin eleanor.jlab.org 12.2.0 i386)
//

#pragma once
#include <string>

using std::string;

#include <JANA/Calibrations/JCalibrationFile.h>
#include <JANA/Services/JParameterManager.h>


/// The JLargeCalibration class is used to manage local resource files.
/// These would typically be larger files that are costly to download
/// every time the program is run. (i.e. if they come from the
/// JCalibration system.) Files are kept in a central location
/// on the local filesystem so only one copy needs to exist.
///
/// The JLargeCalibration constructor takes two arguments. The first
/// is a pointer to a JCalibration object. If not NULL, this is used
/// to retrieve the URL of the file's location on the web. This allows
/// the JLargeCalibration to automatically download the file if needed.
///
/// If no JCalibration object is supplied (i.e. it's NULL), then it will
/// simply look for a file with the specified namepath relative to the
/// root directory used to hold the resources. The root resource directory
/// can be specified multiple ways. These are, in order of precedence:
///
/// 1. Passed as second argument to the constructor
/// 2. Specified in JANA:RESOURCE_DIR configuration parameter
/// 3. Specified in JANA_RESOURCE_DIR environment variable
/// 4. Specified in JANA:RESOURCE_DEFAULT_PATH configuration parameter
/// 5. Create a user directory in /tmp called "resources"
///
/// Note that in nearly all instances, no second argument should
/// be passed to the constructor so that the value can be changed
/// via run time parameters.
///
/// Resource files can be of any format but if they are in an ASCII
/// format compatible with JCalibrationFile then the file can be
/// parsed using the Get(...) methods of JLargeCalibration which map
/// directly to those of JCalibrationFile.
///
/// To get the location of a resource on the local file system,
/// use the method:
///
/// string GetResource(string namepath);
///
/// This will return a string with the full path to the resource file on
/// the local file system. The call will automatically download
/// the resource and install it if it does not already exist locally.
/// The download location will be retrieved using the specified
/// namepath and the JCalibration object passed in to the constructor.
/// The calibration DB should have an entry for the namepath that is
/// a map of key-values with two options for how the URL is specified:
///
/// Option 1.) The DB provides a "URL_base" string and a "path"
/// string. These are combined to make the full URL, and the
/// "path" is appended to the resource_dir to generate the local
/// path. Alternatively, "URL_base" may be provided via the
/// JANA:RESOURCE_URL configuration parameter in which case it need
/// not be present in the calib DB. If the config. parameter is
/// supplied, it will be used instead of any "URL_base" values found
/// in the calib DB.
///
/// Option 2.) The DB provides a "URL" string only. This is used
/// as the full URL and as a key to the resources map to find
/// the local path. If none exists, this local path is taken
/// to be the namepath specified (appended to resource_dir).
///
/// Option 1. takes precedent. If either the "URL_base" or "path"
/// strings are present, then the other must be as well or an
/// exception is thrown. If neither is present, then the URL
/// string is checked and used. If it also does not exist, an
/// exception is thrown.
///
///
/// A text file named "resources" is maintained at the top level of
/// the resources directory tree to record what URLs have been
/// downloaded and where the files are stored. This file is necessary
/// if option 2 above is used to store URLs in the calibration DB,
/// but is only informational if option 1 is used. It is ignored
/// completely if no calibration database is used.
///
/// The templated Get(namepath, T vals [, event_number]) method will
/// first call the GetResource() method described above, but will
/// then use a JCalibrationFile object to parse the resource file,
/// filling the container passed in for "vals". See the documentation
/// for the JCalibration class for more info on the allowed types
/// for "vals".


class JLargeCalibration {
public:
JLargeCalibration(std::shared_ptr<JParameterManager> params, JCalibration *jcalib = NULL, string resource_dir = "");

virtual ~JLargeCalibration();

template<class T>
bool Get(string namepath, T &vals, int event_number = 0);

string GetResource(string namepath);

string GetLocalPathToResource(string namepath);

map<string, string> GetLocalResources(void) { return resources; }

JCalibration *GetJCalibration(void) { return jcalib; }

void GetResourceFromURL(const string &URL, const string &fullpath);

string Get_MD5(string fullpath);

protected:
// Copyright 2020-2025, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.
// Author: Nathan Brei

// Used to get URL of remote resource
JCalibration *jcalib;

// Keep list of namepaths in JCalibration
vector<string> calib_namepaths;

// Used to convert files to values in STL containers
JCalibrationFile *jcalibfile;

// Full path to top-most directory of resource files
string resource_dir;

// Map of URLs to namepaths for existing resources
// key is URL and value is relative path (which should
// be the same as the namepath)
map<string, string> resources;

void ReadResourceInfoFile(void);

void WriteResourceInfoFile(void);

// Argument for the external curl program in case it is used
string curl_args;

private:

// Holds user specified URL_base that superceeds any found
// in calib DB
bool overide_URL_base;
string URL_base;
bool check_md5;

};

//----------------------
// Get
//----------------------
template<class T>
bool JLargeCalibration::Get(string namepath, T &vals, int event_number) {
/// Get the specified resource and parse it, placing the values in the
/// specified "vals" container. This first calls GetResource(namepath)
/// to download the resource (if necessary) and then uses a
/// JCalibrationFile::Get() method to parse the file and fill the
/// "vals" container.

// Call to GetResource to (optionally) download and install resource file
string fullpath = GetResource(namepath);
string path = fullpath.substr(resource_dir.size() + 1); // chop off resource_dir + "/"
#pragma once
#include <JANA/Calibrations/JResource.h>

// Have JCalibrationFile parse the resource file
return jcalibfile->Get(path, vals, event_number);
namespace jana::calibrations::jlargecalibration {
[[deprecated("Use JANA/Calibrations/JResource.h instead")]]
constexpr static int header_is_deprecated = 0;
constexpr static int warn_about_header_deprecation = header_is_deprecated;
}


Loading

0 comments on commit e583654

Please sign in to comment.