File indexing completed on 2025-01-18 10:17:32
0001
0002
0003
0004
0005 #pragma once
0006
0007
0008
0009
0010 #if HAVE_CCDB
0011
0012 #include <string>
0013 #include <iostream>
0014 #include <memory>
0015
0016 #include <JANA/Calibrations/JCalibrationGenerator.h>
0017 #include <CCDB/CalibrationGenerator.h>
0018 #include <CCDB/Helpers/PathUtils.h>
0019 #include "JCalibrationCCDB.h"
0020
0021
0022 class JCalibrationGeneratorCCDB: public JCalibrationGenerator
0023 {
0024 public:
0025
0026
0027 JCalibrationGeneratorCCDB():
0028 mGenerator(new ccdb::CalibrationGenerator())
0029 {
0030 }
0031
0032
0033
0034 virtual ~JCalibrationGeneratorCCDB(){}
0035
0036
0037
0038
0039
0040
0041 const char* Description(){return "JCalibration using CCDB for MySQL and SQLite databases";}
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 double CheckOpenable(std::string url, int32_t run, std::string context)
0052 {
0053 #ifdef CCDB_DEBUG_OUTPUT
0054 jout<<"CCDB::janaccdb CheckOpenable "<<"url: '"<<url<<"' run: "<<run<< " context: "<<context<<std::endl;
0055 #endif
0056
0057 if(ccdb::CalibrationGenerator::CheckOpenable(url)) return 0.99;
0058 return 0.0;
0059 }
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 JCalibration* MakeJCalibration(std::string url, int32_t run, std::string context)
0070 {
0071 #ifdef CCDB_DEBUG_OUTPUT
0072 jout<<"CCDB::janaccdb MakeJCalibration "<<"url: '"<<url<<"' run: "<<run<< " context: '"<<context<<"'"<<std::endl;
0073 #endif
0074
0075
0076 string varition("default");
0077 time_t time = 0;
0078
0079
0080 ccdb::ContextParseResult parseResult = ccdb::PathUtils::ParseContext(context);
0081 if(parseResult.VariationIsParsed) varition = parseResult.Variation;
0082 if(parseResult.ConstantsTimeIsParsed) time = parseResult.ConstantsTime;
0083 #ifdef CCDB_PARSES_CONTEXT_RUN
0084 if(parseResult.RunNumberIsParsed)
0085 {
0086 run = parseResult.RunNumber;
0087 jout<<"CCDB::janaccdb (!) The run number for CCDB IS FORCED TO BE '"<< run<<"' (it was set through context) (!)"<<std::endl;
0088 }
0089 #endif
0090
0091
0092 ccdb::Calibration *calib = mGenerator->MakeCalibration(url,run,varition,time);
0093
0094
0095 return new JCalibrationCCDB(calib, url, run, context);
0096 }
0097
0098 private:
0099 std::auto_ptr<ccdb::CalibrationGenerator> mGenerator;
0100 };
0101
0102 #endif
0103
0104