#!/usr/bin/env python """ The problem: One wants to hold an XML in CCDB. But 'add' command allows only to load tabled files. How to load the XML to the database? The solution: use python API to load such custom data to CCDB Suppose we want to store xml file content in CCDB we created the table with one string column and one row for it to create a test table use command: [shell]> ccdb mktbl /test/test_vars/custom_data -r 1 xml_data=string "#Store xml in ccdb" to check the table exists [shell]> ccdb info /test/test_vars/custom_data ** n.b. here are the commands I used to create the Translation table 2/19/2014 DL ** [shell]> ccdb mkdir Translation [shell]> ccdb mktbl /Translation/DAQ2detector -r 1 tt_xml=string "#Translation table from DAQ to detector coordinates" Now, how to add data... """ import ccdb import io if __name__ == "__main__": #create CCDB api class provider = ccdb.AlchemyProvider() # this class has all CCDB manipulation functions provider.connect("mysql://ccdb_user@hallddb.jlab.org/ccdb") # use usual connection string to connect to database #provider.connect("sqlite:////group/halld/Users/jrsteven/2022-cpp/ccdb.sqlite") # use usual connection string to connect to database provider.authentication.current_user_name = "somov" # to have a name in logs #read file xml_content = io.open("tt.xml", "r").read() #prepare content #create_assignment accepts tabled data #rows and columns number must correspond to table definition tabled_data = [[xml_content]] #add data to database provider.create_assignment( data=tabled_data, path="/Translation/DAQ2detector", variation_name="default", min_run=120000, max_run=129999, #max_run=ccdb.INFINITE_RUN, #comment="Corrections to RunPeriod-2019-01, with fixed TAGM TDC channel") #comment="Initial RunPeriod-2019-11 for TRD and TOF2, with fixed TAGM TDC channel") # chanages to CCDB in Feb 2023 #comment="RunPeriod-2023-01 with rocfdc11 slot 3 reamining in slot 19, DIRC LED reference ADC moved and TAGM columns 85-90, 100, 102 swaps") # upload to CCDB in May 2023 #comment="RunPeriod-2021-08+ with TAGM columns 85-90, 100, 102 swaps") # 80129-99999 #comment="RunPeriod-2022-05-default with FMWPC and CTOF for CPP run") # 100000-100941 #comment="RunPeriod-2022-05++ move rocfdc11 slot 3 -> 19 for end of CPP and PrimEx") # 100942-119999 # upload to CCDB in March 2024 #comment="RunPeriod-2022-05-default with FMWPC and CTOF for CPP run + helicity bits") # 100000-100941 #comment="RunPeriod-2022-05++ move rocfdc11 slot 3 -> 19 for end of CPP + helicity bits") # 100942-109999 #comment="RunPeriod-2022-08-default initial PrimEx, rotated ST, helicity bits") # 110000-119999 #comment="RunPeriod-2023-01-default initial GlueX, rotated ST, helicity bits") # 120000-129999 comment="RunPeriod-2023-01-default add ECAL") # 120000-129999 #that is it. #check it with #[shell]> ccdb vers /test/test_vars/custom_data