TOP=../..
include $(TOP)/configure/CONFIG
#----------------------------------------
#  ADD MACRO DEFINITIONS AFTER THIS LINE

#----------------------------------------------------
#  Optimization of db files using dbst (DEFAULT: NO)
#DB_OPT = YES

#----------------------------------------------------
# Create and install (or just install)
# databases, templates, substitutions like this

DB_INSTALLS += $(EVENT)/db/EvrPmc.db
#DB_INSTALLS += $(EVENT)/db/EvrPci.db
DB_INSTALLS += $(EVENT)/db/Pattern.db
#DB_INSTALLS += $(EVENT)/db/PCI-trig.db
DB_INSTALLS += $(EVENT)/db/PMC-trig.db
DB_INSTALLS += $(EVENT)/db/VME-trig.db
DB_INSTALLS += $(EVENT)/db/VME-TTB-trig.db
DB_INSTALLS += $(EVENT)/db/Bsa.db

# scondam: 25-Sept-2015: Added ACF for XTCAV SLED Upgrade commissioning. Temporary.
DB_INSTALLS += xtcav.acf

# Measurement and calculation for ASTA IOC-AS01-RF01
DB += IOC-AS01-RF01.db
DB += IOC-AS01-RF01llrf.db
DB += IOC-AS01-RF01access.db

# Measurement and calculation for LCLS XTCAV IOC-DMP1-RF01
DB += IOC-DMP1-RF01.db
DB += IOC-DMP1-RF01llrf.db
DB += IOC-DMP1-RF01access.db

# Measurement and calculation for LCLS KLY DIAG IOC-IN20-RF03
DB += IOC-IN20-RF03.db
DB += IOC-IN20-RF03llrf.db
DB += IOC-IN20-RF03access.db

# Measurement and calculation for LCLS KLY DIAG IOC-IN20-RF05
DB += IOC-IN20-RF05.db
DB += IOC-IN20-RF05llrf.db
DB += IOC-IN20-RF05access.db

# Measurement and calculation for LCLS KLY DIAG IOC-LI24-RF01
DB += IOC-LI24-RF01.db
DB += IOC-LI24-RF01llrf.db
DB += IOC-LI24-RF01access.db

# Measurement and calculation for LCLS KLY DIAG IOC-LI24-RF02
DB += IOC-LI24-RF02.db
DB += IOC-LI24-RF02llrf.db
DB += IOC-LI24-RF02access.db

# Measurement and calculation for LCLS KLY DIAG IOC-LI24-RF03
DB += IOC-LI24-RF03.db
DB += IOC-LI24-RF03llrf.db
DB += IOC-LI24-RF03access.db

# Measurement and calculation for FACET XTCAV IOC-LI20-RF01
DB += IOC-LI20-RF01.db
DB += IOC-LI20-RF01llrf.db
DB += IOC-LI20-RF01access.db

# Measurement and calculation for LCLS IN20 RF04 IOC-IN20-RF04
DB += IOC-IN20-RF04.db
DB += IOC-IN20-RF04llrf.db
DB += IOC-IN20-RF04access.db

# Measurement and calculation for LCLS IN20 RF06 IOC-IN20-RF06
DB += IOC-IN20-RF06.db
DB += IOC-IN20-RF06llrf.db
DB += IOC-IN20-RF06access.db

# Measurement and calculation for Coherent Laser 1 and Diagnostics Coherenet Laser 2 PAD IOC-IN20-RF02
DB += IOC-IN20-RF02.db
DB += IOC-IN20-RF02llrf.db
DB += IOC-IN20-RF02access.db

# Measurement and calculation for LCLS IN20 IOC-IN20-RF01
DB += IOC-LI21-RF01.db
DB += IOC-LI21-RF01llrf.db
DB += IOC-LI21-RF01access.db

# LCLS BSA and Timing
DB += lclsPattern.db

# ASTA BSA and Timing
DB += astaPattern.db

# FACET BSA and Timing
DB += facetPattern.db

# EVR, BSA, Trigger related databases
DB += IOC-IN20-RF01evr.db
# scondam: 15-Aug-2016: Use standard Bsa.db file - wean off event module databases bsaPHASEdef.db and bsaAMPLEdef.db
DB += IOC-IN20-RF01-bsa.db
DB += IOC-IN20-RF01trig.db

DB += IOC-IN20-RF02evr.db
# scondam: 15-Aug-2016: Use standard Bsa.db file - wean off event module databases bsaPHASEdef.db and bsaAMPLEdef.db
DB += IOC-IN20-RF02-bsa.db
DB += IOC-IN20-RF02trig.db

DB += IOC-AS01-RF01evr.db
DB += IOC-AS01-RF01bsa.db
DB += IOC-AS01-RF01trig.db

DB += IOC-DMP1-RF01evr.db
# scondam: 15-Aug-2016: Use standard Bsa.db file - wean off event module databases bsaPHASEdef.db and bsaAMPLEdef.db
DB += IOC-DMP1-RF01-bsa.db
DB += IOC-DMP1-RF01trig.db
DB += IOC-DMP1-RF01ip330.db

DB += IOC-LI20-RF01evr.db
DB += IOC-LI20-RF01bsa.db
DB += IOC-LI20-RF01trig.db

DB += IOC-IN20-RF03evr.db
# scondam: 10-Jun-2016: Use standard Bsa.db file - wean off event module databases bsaPHASEdef.db and bsaAMPLEdef.db
DB += IOC-IN20-RF03-bsa.db
DB += IOC-IN20-RF03trig.db

DB += IOC-IN20-RF05evr.db
# scondam: 10-Oct-2016: Use standard Bsa.db file - wean off event module databases bsaPHASEdef.db and bsaAMPLEdef.db
DB += IOC-IN20-RF05-bsa.db
DB += IOC-IN20-RF05trig.db

DB += IOC-IN20-RF04evr.db
# scondam: 15-Aug-2016: Use standard Bsa.db file - wean off event module databases bsaPHASEdef.db and bsaAMPLEdef.db
DB += IOC-IN20-RF04-bsa.db
DB += IOC-IN20-RF04trig.db

DB += IOC-IN20-RF06evr.db
# scondam: 15-Aug-2016: Use standard Bsa.db file - wean off event module databases bsaPHASEdef.db and bsaAMPLEdef.db
DB += IOC-IN20-RF06-bsa.db
DB += IOC-IN20-RF06trig.db

DB += IOC-LI24-RF01evr.db
# scondam: 15-Aug-2016: Use standard Bsa.db file - wean off event module databases bsaPHASEdef.db and bsaAMPLEdef.db
DB += IOC-LI24-RF01-bsa.db
DB += IOC-LI24-RF01trig.db

DB += IOC-LI24-RF02evr.db
# scondam: 25-Jul-2016: Use standard Bsa.db file - wean off event module databases bsaPHASEdef.db and bsaAMPLEdef.db
DB += IOC-LI24-RF02-bsa.db
DB += IOC-LI24-RF02trig.db

DB += IOC-LI24-RF03evr.db
# scondam: 25-Jul-2016: Use standard Bsa.db file - wean off event module databases bsaPHASEdef.db and bsaAMPLEdef.db
DB += IOC-LI24-RF03-bsa.db
DB += IOC-LI24-RF03trig.db

# B34 Lab Timing and Triggers
DB += IOC-B34-RF01evr.db
DB += IOC-B34-RF01trig.db

DB += llrffanout.db

DB += llrfCW.db
DB += llrfsimp.db

# For Diagnostics Laser PAD
DB += lsrdiag.db
DB += lsrphasediag.db
DB += lsrmatcalc.db

DB += llrfai.db
DB += llrfao.db
DB += llrfao_closed_loop.db
DB += llrflongout.db
DB += llrfcalcout.db
DB += llrfcalc.db
DB += llrfbi.db
DB += llrfbo.db
DB += llrfsub.db
DB += llrfsubsec.db
DB += llrfseq.db
DB += llrfmbbo.db
DB += llrfli.db
DB += llrffanout.db
#DB += llrffcom.db

DB += dbpllAutoAcquire.db

# Feedback database templates for LCLS IOC-IN20-RF01 
DB += llrfLI21.fdbk_template
DB += llrfLI21.l1x_template
DB += llrfIN20.ref_template
DB += llrfIN20.gbl_template
DB += llrfLI21.gbl_template
DB += llrfIN20.clk_template
DB += llrfIN20.pau_template
DB += llrfIN20.snc_template

# Shantha Condamoor: 16-Sept-2014
#   As of date, both Cohr Laser 1 and 2 use Vitara HW/J.Frisch feedback controls.
#   Do not setup Laser 1 or Laser 2 LLRF controls for Feedback.
#   Setup both the Laser PADs for Diagnostics only
# Feedback database templates for LCLS IOC-IN20-RF02
# DB += llrfIN20.lsr_68MHz_template
# DB += llrfIN20.lsr_119MHz_template
# DB += llrfIN20.pau2_template

# Feedback and pau database template for LCLS IOC-IN20-RF04/RF06. Moved to LLRF6 model in IOC-IN20-RF04/06 from LLRF4 model in IOC-IN20-RF01
DB += llrfIN20.tc0_template
DB += llrfIN20.pau4_template
DB += llrfIN20.pau6_template
DB += llrfIN20.fdbk_template
DB += llrfIN20.gnt_template
DB += llrfIN20.gnt_phas_template
DB += llrfIN20.l0a_template
DB += llrfIN20.l0b_template
DB += llrfIN20.bb_a_fb_template
DB += llrfIN20.bb_p_fb_template

# Feedback database templates for LCLS IOC-LI24-RF01
DB += llrfLI24.gbl_template
DB += llrfLI29.gbl_template
DB += llrfIN20.l2ref_template
DB += llrfLI24.l2_template
DB += llrfLI24.l2abstr_template
DB += llrfLI24.tc3_template
DB += llrfLI29.l3_template
DB += llrfLI29.l3abstr_template
DB += llrfLI30.l3_template
DB += llrfLI24.pau_template

# Feedback database templates for LCLS IOC-LI24-RF02
DB += llrfIN20.ph1_template
DB += llrfLI21.ph2_template
DB += llrfLI25.ph3_template
DB += llrfLI29.ph4_template
DB += llrfLI24.kly_ph_template
DB += llrfLI29.kly_ph_template

# Resonance Frequency Calculations for Phase Cavities - moved from sioc-sys0-rf02 to here
DB += dbResFreqPCAV.db

#DB_INSTALLS += lsr.acf
# THERE WILL BE .acf FILES HERE

# CW += IOC-IN20-RF01trig.cwConfig
# CW += IOC-LI24-RF01trig.cwConfig

# Feedback database template for ASTA
DB += llrfAS01.laser_68MHz_template
DB += llrfAS01.gun_template
DB += llrfAS01.reference_template
DB += llrfAS01.guntune_template
DB += llrfAS01.guntune_phase_template
DB += llrfAS01.pau_template
DB += llrfAS01.snc_template

# Toroid (Faraday Cup) for ASTA
DB += IOC-AS01-RF01adc.db

# Feedback database template for LCLS XTCAV
DB += llrfDMP1.xtcava_template
DB += llrfDMP1.pau_template
DB += llrfDMP1.snc_template

# Feedback database template for FACET XTCAV
DB += llrfLI20.xtcava_template
DB += llrfLI20.pau_template
DB += llrfLI20.snc_template

# Aliases for LCLS XTCAV IOC in DMP1
DB += aliasDMP1.db

# Aliases for LCLS Kly Diag IOCs in IN20 RF03 and RF05
DB += aliasIN20KlyDiag.db
DB += aliasIN20KlyDiag2.db

# Aliases for LCLS Kly Diag IOCs in LI24 RF02
DB += aliasLI24KlyDiag.db

DB += aliasIN20L0.db

# Aliases for LCLS Laser Diagnostics IOC in IN20 RF02
DB += aliasIN20LsrDiag.db

# Aliases for LCLS PCAV IOC in LI24 RF02
DB += aliasIN20PCAV.db

# Aliases for LCLS BSA rootname PVs for IOC in LI24 RF01
DB += aliasLI24RF01Bsa.db

# Aliases for LCLS BSA PVs in IN20 (LI21) RF01
DB += aliasIN20RF01Bsa.db

# Aliases for LCLS BSA rootname PVs for IOC in IN20 RF04
DB += aliasIN20RF04Bsa.db

# Aliases for LCLS BSA rootname PVs for IOC in IN20 RF06
DB += aliasIN20RF06Bsa.db

# Aliases for LCLS BSA rootname PVs for IOC in IN20 RF03 and RF05
DB += aliasIN20RF03Bsa.db
DB += aliasIN20RF05Bsa.db

# Aliases for LCLS BSA rootname PVs for IOC in IN20 RF02
DB += aliasIN20RF02Bsa.db

# Aliases for LCLS BSA rootname PVs for IOC in LI24 RF02
DB += aliasLI24RF02Bsa.db

# Aliases for LCLS BSA rootname PVs for IOC in LI24 RF03
DB += aliasLI24RF03Bsa.db

# Aliases for LCLS BSA rootname PVs for IOC in DMP1 RF01
DB += aliasDMP1RF01Bsa.db

# Aliases for FACET BSA rootname PVs for IOC in LI20 RF01
DB += aliasLI20RF01Bsa.db

# Aliases for ASTA BSA rootname PVs for IOC in AS01 RF01
DB += aliasAS01RF01Bsa.db

DB_INSTALLS += $(PAU)/db/dbPau.db
DB_INSTALLS += $(PAU)/db/dbPauBeamcodeTimeslot.db
DB_INSTALLS += $(PAU)/db/dbPauPattern.db
DB_INSTALLS += $(PAU)/db/dbMux.db
DB_INSTALLS += $(PAU)/db/dbMuxDataSlot.db
DB_INSTALLS += $(PAU)/db/dbMuxOffset.db

DB_INSTALLS += $(PAU)/db/dbPau.template
DB_INSTALLS += $(PAU)/db/dbMux.template

# ========================================================
# Install databases from iocAdmin package
# These databases support IOC Health and Monitoring
# ========================================================
DB_INSTALLS += $(IOCADMIN)/db/iocAdminRTEMS.db
DB_INSTALLS += $(IOCADMIN)/db/iocAdminScanMon.db
DB_INSTALLS += $(IOCADMIN)/db/iocScanMonSum.db
DB_INSTALLS += $(IOCADMIN)/db/iocScanMon.db
IOCRELEASE_DB += iocRelease.db

# Install Database to support reading the status of the autosave package:
DB_INSTALLS += $(AUTOSAVE)/db/save_restoreStatus.db

include $(TOP)/configure/RULES
#----------------------------------------
#  ADD RULES AFTER THIS LINE

#----------------------------------------
#  ADD RULES AFTER THIS LINE
../O.Common/llrfPad.db: ../llrfPad.db.part ../llrf.db.part
	cat $^ > $@

%.fdbk_template: ../%.fdbk_substitutions ../llrf.fdbk_template
	$(RM) $@
	../buildtemplate $< $@

%.gun_template: ../%.gun_substitutions ../llrf.gun_template
	$(RM) $@
	../buildtemplate $< $@

%.gnt_template: ../%.gnt_substitutions ../llrf.gnt_template
	$(RM) $@
	../buildtemplate $< $@
	
%.guntune_template: ../%.guntune_substitutions ../llrf.guntune_template
	$(RM) $@
	../buildtemplate $< $@

%.gnt_phas_template: ../%.gnt_phas_substitutions ../llrf.gnt_phas_template
	$(RM) $@
	../buildtemplate $< $@
	
%.guntune_phase_template: ../%.guntune_phase_substitutions ../llrf.guntune_phase_template
	$(RM) $@
	../buildtemplate $< $@	

%.l0a_template: ../%.l0a_substitutions ../llrf.l0a_template
	$(RM) $@
	../buildtemplate $< $@

%.tc0_template: ../%.tc0_substitutions ../llrf.tc0_template
	$(RM) $@
	../buildtemplate $< $@

%.tc3_template: ../%.tc3_substitutions ../llrf.tc3_template
	$(RM) $@
	../buildtemplate $< $@

%.l1x_template: ../%.l1x_substitutions ../llrf.l1x_template
	$(RM) $@
	../buildtemplate $< $@

%.l0b_template: ../%.l0b_substitutions ../llrf.l0b_template
	$(RM) $@
	../buildtemplate $< $@

%.ref_template: ../%.ref_substitutions ../llrf.ref_template
	$(RM) $@
	../buildtemplate $< $@
	
%.reference_template: ../%.reference_substitutions ../llrf.reference_template
	$(RM) $@
	../buildtemplate $< $@	

%.lsr_68MHz_template: ../%.lsr_68MHz_substitutions ../llrf.lsr_68MHz_template
	$(RM) $@
	../buildtemplate $< $@

%.lsr_119MHz_template: ../%.lsr_119MHz_substitutions ../llrf.lsr_119MHz_template
	$(RM) $@
	../buildtemplate $< $@
	
%.laser_68MHz_template: ../%.laser_68MHz_substitutions ../llrf.laser_68MHz_template
	$(RM) $@
	../buildtemplate $< $@	

%.gun_interim_template: ../%.gun_interim_substitutions ../llrf.gun_interim_template
	$(RM) $@
	../buildtemplate $< $@

%.l1s_interim_template: ../%.l1s_interim_substitutions ../llrf.l1s_interim_template
	$(RM) $@
	../buildtemplate $< $@

%.ph1_template: ../%.ph1_substitutions ../llrf.ph1_template
	$(RM) $@
	../buildtemplate $< $@

%.ph2_template: ../%.ph2_substitutions ../llrf.ph2_template
	$(RM) $@
	../buildtemplate $< $@

%.ph3_template: ../%.ph3_substitutions ../llrf.ph3_template
	$(RM) $@
	../buildtemplate $< $@

%.ph4_template: ../%.ph4_substitutions ../llrf.ph4_template
	$(RM) $@
	../buildtemplate $< $@

%.xtcava_template: ../%.xtcava_substitutions ../llrf.xtcava_template
	$(RM) $@
	../buildtemplate $< $@

%.kly_template: ../%.kly_substitutions ../llrf.kly_template
	$(RM) $@
	../buildtemplate $< $@

%.udpComm_kly_template: ../%.udpComm_kly_substitutions ../llrf.udpComm_kly_template
	$(RM) $@
	../buildtemplate $< $@

%.kly_ph_template: ../%.kly_ph_substitutions ../llrf.kly_ph_template
	$(RM) $@
	../buildtemplate $< $@

%.gbl_template: ../%.gbl_substitutions ../llrf.gbl_template
	$(RM) $@
	../buildtemplate $< $@

%.bb_p_fb_template: ../%.bb_p_fb_substitutions ../llrf.bb_p_fb_template
	$(RM) $@
	../buildtemplate $< $@

%.bb_a_fb_template: ../%.bb_a_fb_substitutions ../llrf.bb_a_fb_template
	$(RM) $@
	../buildtemplate $< $@

%.clk_template: ../%.clk_substitutions ../llrf.clk_template
	$(RM) $@
	../buildtemplate $< $@

%.l2ref_template: ../%.l2ref_substitutions ../llrf.l2ref_template
	$(RM) $@
	../buildtemplate $< $@

%.l2_template: ../%.l2_substitutions ../llrf.l2_template
	$(RM) $@
	../buildtemplate $< $@

%.l2abstr_template: ../%.l2abstr_substitutions ../llrf.l2abstr_template
	$(RM) $@
	../buildtemplate $< $@

%.l3_template: ../%.l3_substitutions ../llrf.l3_template
	$(RM) $@
	../buildtemplate $< $@

%.l3abstr_template: ../%.l3abstr_substitutions ../llrf.l3abstr_template
	$(RM) $@
	../buildtemplate $< $@

%.pau_template: ../%.pau_substitutions
	$(RM) @$
	../buildtemplate $< $@

%.pau2_template: ../%.pau2_substitutions
	$(RM) @$
	../buildtemplate $< $@

%.pau4_template: ../%.pau4_substitutions
	$(RM) @$
	../buildtemplate $< $@
	
%.pau6_template: ../%.pau6_substitutions
	$(RM) @$
	../buildtemplate $< $@	

%.snc_template: ../%.snc_substitutions
	$(RM) @$
	../buildtemplate $< $@

clean::
	$(RM) $(patsubst %.substitutions,%.template,$(wildcard *.substitutions))

vpath llrfPad.db ../O.Common

#To be used for final generation of displays

gen_trig_edl:
	create_edm_event_msi.py IOC-IN20-RF01trig.substitutions IOC-IN20-RF02trig.substitutions IOC-IN20-RF03trig.substitutions IOC-IN20-RF04trig.substitutions IOC-IN20-RF05trig.substitutions IOC-IN20-RF06trig.substitutions
	create_edm_event_msi.py IOC-LI24-RF01trig.substitutions	IOC-LI24-RF02trig.substitutions	IOC-LI24-RF03trig.substitutions
	create_edm_event_msi.py IOC-DMP1-RF01trig.substitutions
	create_edm_event_msi.py IOC-LI20-RF01trig.substitutions
	create_edm_event_msi.py IOC-AS01-RF01trig.substitutions


