Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:32

0001 
0002 // Copyright 2020-2025, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 #pragma once
0006 
0007 // This entire file was copied from the CCDB 0.06 source
0008 // (janaccdb directory). The only modification was to wrap
0009 // the whole file in the #if HAVE_CCDB below.
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         /** @brief default ctor */
0027         JCalibrationGeneratorCCDB():
0028             mGenerator(new ccdb::CalibrationGenerator())
0029         {
0030         }
0031 
0032 
0033         /** @brief destructor */
0034         virtual ~JCalibrationGeneratorCCDB(){}
0035 
0036 
0037         /** @brief Get string indicating type of calibration this handles
0038          *
0039          * @return string with desctiption
0040          */
0041         const char* Description(){return "JCalibration using CCDB for MySQL and SQLite databases";}
0042 
0043 
0044         /** @brief  Test probability of opening the given calibration
0045          *
0046          * @parameter [in] url in form "mysql://username@pass:host:port database_name"
0047          * @parameter [in] run number
0048          * @parameter [in] name of the variation
0049          * @return 0.0 - not openable, 0.99 if openable
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         /** @brief MakeJCalibration
0063          *
0064          * @parameter [in] url in form "mysql://username@pass:host:port database_name"
0065          * @parameter [in] run number
0066          * @parameter [in] name of the variation
0067          * @return JCalibration pointer or null if error
0068          */
0069         JCalibration* MakeJCalibration(std::string url, int32_t run, std::string context) ///< Instantiate an JCalibration object
0070         {
0071             #ifdef CCDB_DEBUG_OUTPUT
0072             jout<<"CCDB::janaccdb MakeJCalibration "<<"url: '"<<url<<"' run: "<<run<< " context: '"<<context<<"'"<<std::endl;
0073             #endif
0074 
0075             //By default we have default variation and 0 time (means current time)
0076             string varition("default");
0077             time_t time = 0;
0078 
0079             //Parse context
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             //Get ccdb calibration object
0092             ccdb::Calibration *calib = mGenerator->MakeCalibration(url,run,varition,time);
0093 
0094             //Create jana calibration object from ccdb
0095             return new JCalibrationCCDB(calib, url, run, context);
0096         }
0097 
0098     private:
0099         std::auto_ptr<ccdb::CalibrationGenerator> mGenerator; ///CCDB calibration generator object
0100     };
0101 
0102 #endif // HAVE_CCDB
0103 
0104