This folder contains the script called `create_sql_queries_for_experimental_data` that can be used to import experimental data into a MySQL database.
The script uses an input card containing the basic information about the measurement to be inserted and the experimental data itself.
It produces a set of MySQL queries that act on `laboratory`, `collaboration`, `experiment`, `observable_kinematic` and `observable_result` tables of the database `partons`.
For the three first tables, it is checked if the new data do not double the existing entries (in the case of repetition, the existing entries are used).
The script was written for and has been tested under GNU Awk 4.1.3.
Structure of the input card
---------------------------
The input card should follow the following structure (check `CLAS_ALU_asymmetries.dat` for an example):
1) provide measurement information (keep information in quotation marks where indicated):
```
LABORATORY "name"
COLLABORATION "name"
EXPERIMENT "year" "process" "type" "reference"
```
2) provide experimental points (as many as you want):
```
bin_index xB t Q2 Ebeam phi observable_name value stat- stat+ sys- sys+ err_tot
```
If you want to use single quotation marks, you must escape it, _e.g._ `"e\' + p\' + gamma"` instead of `"e' + p' + gamma"`.
printf("INSERT INTO laboratory(laboratory_name) SELECT * FROM (SELECT '%s') AS tmp WHERE NOT EXISTS (SELECT * FROM laboratory WHERE laboratory_name = '%s') LIMIT 1;\n",LABORATORY_NAME,LABORATORY_NAME)>>OUTPUT_FILE;
printf("SELECT laboratory_id INTO @last_laboratory_id FROM laboratory WHERE laboratory_name = '%s';\n",LABORATORY_NAME)>>OUTPUT_FILE;
LABORATORY_SET=1;
}
#collaboration name
elseif($1=="COLLABORATION"){
if(LABORATORY_SET==0){
print("Error: Laboratory name should be set prior collaboration name");
exit_now=1;
exit;
}
split($0,str_array,"\"");
COLLABORATION_NAME=str_array[2];
printf("INSERT INTO collaboration(collaboration_name, laboratory_id) SELECT * FROM (SELECT '%s', @last_laboratory_id) AS tmp WHERE NOT EXISTS (SELECT * FROM collaboration WHERE (collaboration_name = '%s' AND laboratory_id = @last_laboratory_id)) LIMIT 1;\n",COLLABORATION_NAME,COLLABORATION_NAME)>>OUTPUT_FILE;
printf("SELECT collaboration_id INTO @last_collaboration_id FROM collaboration WHERE (collaboration_name = '%s' AND laboratory_id = @last_laboratory_id);\n",COLLABORATION_NAME)>>OUTPUT_FILE;
COLLABORATION_SET=1;
}
#experiment
elseif($1=="EXPERIMENT"){
if(COLLABORATION_SET==0){
print("Error: Collaboration name should be set prior experiment information");
exit_now=1;
exit;
}
split($0,str_array,"\"");
EXPERIMENT_YEAR=str_array[2];
EXPERIMENT_PROCESS=str_array[4];
EXPERIMENT_TYPE=str_array[6];
EXPERIMENT_REFERENCE=str_array[8];
printf("INSERT INTO experiment(experiment_year, experiment_process, experiment_type, experiment_reference, collaboration_id) SELECT * FROM (SELECT '%s', '%s', '%s', '%s', @last_collaboration_id) AS tmp WHERE NOT EXISTS (SELECT * FROM experiment WHERE experiment_year = '%s' AND experiment_process = '%s' AND experiment_type = '%s' AND experiment_reference = '%s' AND collaboration_id = @last_collaboration_id) LIMIT 1;\n",EXPERIMENT_YEAR,EXPERIMENT_PROCESS,EXPERIMENT_TYPE,EXPERIMENT_REFERENCE,EXPERIMENT_YEAR,EXPERIMENT_PROCESS,EXPERIMENT_TYPE,EXPERIMENT_REFERENCE)>>OUTPUT_FILE;
printf("SELECT experiment_id INTO @last_experiment_id FROM experiment WHERE (experiment_year = '%s' AND experiment_process = '%s' AND experiment_type = '%s' AND experiment_reference = '%s' AND collaboration_id = @last_collaboration_id);\n",EXPERIMENT_YEAR,EXPERIMENT_PROCESS,EXPERIMENT_TYPE,EXPERIMENT_REFERENCE)>>OUTPUT_FILE;
EXPERIMENT_SET=1;
}
#points
else{
if(EXPERIMENT_SET==0){
print("Error: Experiment information should be set prior experiment data");
exit_now=1;
exit;
}
if($9<=0.||$10<=0.){
print("Error: One of statistic uncertainties <= 0");
exit_now=1;
exit;
}
if($11<0.||$12<0.){
print("Error: One of systematic uncertainties < 0");