R/W DB

Under:

Below is mostly copied from Akio's page on how to read/write DB tables in a macro.

 FMS DB example

• Simple "how to Creating Offline DB Tables" from Dmitry 
    o Anyone in STAR should be able to read DB from RCAS machines
    o To write to DB, you need write permission to DB. Currently only Akio and Dmitry can write. Dmitry can add people as needed.
    o Only Dmitry can delete, or mark as de-activated DB entries.
    o For reading DB : unsetenv DB_ACCESS_MODE or setenv DB_ACCESS_MODE read
    o For writing DB : setenv DB_ACCESS_MODE write, and do not forget to unsetenv DB_ACCESS_MODE when done.

• STAR DB Broswer : Calibration DB , Geometry DB

• Look into other DB table definisions in $STAR/StDb/idl/*.idl 
    o Up to 3 dimensional array is supported 
    o Plus using one queue, DB can return array (ModuleID) of this table 
    o Thus 4 dimensional array (3 dim array in table + 1 module ID) used in fmsQTMap.idl (see below). 
    o Array is fixed length, but module ID can be variable length. 
    o For DB efficiencies, using big array block/blab is disfavored, and use small tables & moduleID is recomended.

• Edit Computing/Subsystem drupal page for documentation!

• To read/write into DB using macros 
       copy ~akio/dbServers.xml ~/
       unsetenv DB_SERVER_LOCAL_CONFIG

• For usual DB access through BFC/St_db_Maker 
      setenv DB_SERVER_LOCAL_CONFIG /afs/rhic.bnl.gov/star/packages/conf/dbLoadBalancerLocalConfig_BNL.xml

• Proposed tables and codes to read from and write into the database (examples are located at ~jgma/psudisk/fms/)
    o fmsPatchPanelMap.idl for FMS detector to patchpanel map
    Input file : qtmap2pp.txt
    Example root macro : fms_db_patchpanelmap.C 
       ** To read input file and write to DB
       root4star -q -b fms_db_patchpanelmap.C'("readtext writedb")'

      ** To read DB and write to text file
      root4star -q -b fms_db_patchpanelmap.C'("readdb writetext")'
      diff qtmap2pp.txt qtmap2pp.txt_dbout

    o fmsQTMap.idl for FMS patchpanel to QT map
    Input file for run8 : qtmap_run8.txt
    Input file for run9 : qtmap2009V1.txt
    Example root macro : fms_db_qtmap.C
       ** To read input file and write to DB for run8 (replace 2nd argument = 8 with 9 for run9)
       root4star -q -b fms_db_qtmap.C'("readtext writedb",8)'
       ** To read DB and write to text file for run8
       root4star -q -b fms_db_qtmap.C'("readdb writetext",8)'
       diff qtmap_run8.txt qtmap_run8.txt_dbout

    o fmsQTMap.idl for FPD,FMS,FHC detector to QT map
    For FMS, combine 2 DB tables (fmsPatchPanel & fmsQTMap) to create this table
    Root macro for FMS: fms_db_pp_qt_merge.C
       ** To read 2 maps from DB (fmsPatchPanel & fmsQTMap) and write fmsMap to DB for run8 (replace 2nd argument = 8 with 9 for run9)
       root4star -q -b fms_db_pp_qt_merge.C'("merge writedb",8)'
       ** To read fmsMap DB and write to text file for run8
       root4star -q -b fms_db_pp_qt_merge.C'("readdb writetext",8)'
       more fms_db_pp_qt_merge.txt

    Root macro For FPD : fpd_db_map.C

    o fmsChannelGeometry.idl for FPD,FMS,FHC detector basic numbers (id, type, Easr/West and North/south, # of row/column)
    Root macro : fms_db_ChannelGeometry.C

    o fmsDetectorPosition.idl for FPD,FMS,FHC detector position in STAR frame 
    Root macro : fms_db_detectorposition.C

    o fmsGain.idl/fmsGainCorrection.idl for FPD,FMS,FHC gain(detectorId, channel number, gain/gaincorr)
    Root macro : fms_db_fmsgain.C/fms_db_fmsgaincorr.C (they work in a similar way)        ** To read input gain file and write gain information to DB for run8 pp200 (the macro takes combined option of run8/run9 and dAu200/pp200)
       root4star -q -b fms_db_pp_fmsgain.C'("readtext writedb", "run8 pp200")'
       ** To read fmsGain DB and write to text file for run8 pp200
       root4star -q -b fms_db_fmsgain.C'("readdb writetext", "run8 pp200")'