Skip to content
This repository has been archived by the owner on Mar 12, 2019. It is now read-only.

Simpler mastersnippet parsing #332

Open
wants to merge 34 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d4550d9
Add support for third party gson library
DryRun Dec 5, 2016
c7ee857
Have master snippet parsing directly map tag names to FM parameter na…
DryRun Dec 5, 2016
6b925fa
Adding FM parameter HCAL_ALARM_URL, replaces alarmerURL member variable
DryRun Dec 5, 2016
3235dcf
Adding FM parameter HCAL_ALARM_URL, replaces alarmerURL member variable
DryRun Dec 5, 2016
0635872
Adding FM parameter HCAL_ALARM_URL, replaces alarmerURL member variable
DryRun Dec 5, 2016
022e92d
Merging with master
DryRun Dec 5, 2016
f764aea
First working build of new parser, supporting XInclude, VectorT and MapT
DryRun Dec 12, 2016
e9e3ae5
functionManager.alarmerURL is now a FM parameter
DryRun Dec 12, 2016
e86204f
Add MapT support, plus some commented-out test parameters
DryRun Dec 12, 2016
caf4c3d
Fix misplaced parentheses
DryRun Dec 12, 2016
dd4dc20
Remove gson from build, but leave commented out stuff as reference
DryRun Dec 12, 2016
ce3a954
Clean up comments and abandoned code
DryRun Dec 12, 2016
7403a18
Add type resolution to VectorT parsing, to avoid HCALParameters::run(…
DryRun Dec 14, 2016
441f8ba
Remove test vector
DryRun Dec 16, 2016
f9113ed
Add script for porting snippets to new FMParameter-based format
DryRun Dec 19, 2016
65d77b8
Add example of new snippet format
DryRun Dec 19, 2016
6cd08df
Add support for concatenating rather than overwriting preexisting par…
DryRun Jan 25, 2017
7da0ebb
Remove conflict flag, add special behavior for HCAL_CFGSCRIPT
DryRun Jan 26, 2017
edef659
goToError when mastersnippet is a malformed XML
Jan 27, 2017
fc58112
Fast forward to master head
Mar 24, 2017
aa9e664
Merge branch 'integration' of https://github.com/HCALRunControl/level…
Jun 5, 2017
0f157a3
Fast forward and Resolve trivial conflicts
Aug 31, 2017
5c48b14
Add new MS entries, support python 2.6 format usage
Sep 8, 2017
eed08a5
Clean up alarmerURL
Sep 8, 2017
897b54f
Fix typo
Sep 8, 2017
be93b63
Do not support old Tags
Sep 8, 2017
79e0ca8
Add schema attribute
Sep 8, 2017
f694125
escape mastersnippet tag, uncomment SetHCALParameterFromTagName for now
Sep 8, 2017
9da0c6b
Fail gracefully if we fails to parse mastersnippet
Sep 8, 2017
86dce98
FastForward and resolve conflict from isNEventFromGUI
Nov 27, 2017
a3643a1
fast forward
Feb 26, 2018
1b00653
fast forward with LV2readMaster
Mar 26, 2018
93d15e0
Truncate long parameters
Mar 26, 2018
46660d2
remove number of events
Mar 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions PortSnippet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import os
import sys
import re

def PortSnippet(input_path, output_path):
# Define regexes for more complicated remappings
re_FMSettings = re.compile("<FMSettings")
re_RunInfoPublish = re.compile("RunInfoPublish=\"(?P<RunInfoPublish>true|false)\"")
re_OfficialRunNumbers = re.compile("OfficialRunNumbers=\"(?P<OfficialRunNumbers>true|false)\"")
re_NumberOfEvents = re.compile("NumberOfEvents=\"(?P<NumberOfEvents>\d+)\"")

re_mastersnippet = re.compile("<mastersnippet")
re_include = re.compile("<include")
re_include_file = re.compile("file=\"/(?P<file>.+?)\"")
re_include_version = re.compile("version=\"(?P<version>.+?)\"")

# Define a simple map for string.replaces
tag_mapping = {
"CfgScript":"HCAL_CFGSCRIPT",
"PIControlSingle":"HCAL_PICONTROL_SINGLE",
"PIControlMulti":"HCAL_PICONTROL_MULTI",
"ICIControlMulti":"HCAL_ICICONTROL_MULTI",
"ICIControlSingle":"HCAL_ICICONTROL_SINGLE",
"TCDSControl":"HCAL_ICICONTROL_MULTI",
"LPMControl":"HCAL_LPMCONTROL",
"FedEnableMask":"FED_ENABLE_MASK",
"AlarmerURL":"HCAL_ALARMER_URL",
}

input_snippet = open(input_path, 'r')
output_snippet_text = ""
for line in input_snippet:
# FMSettings
if re_FMSettings.search(line):
match_RunInfoPublish = re_RunInfoPublish.search(line)
if match_RunInfoPublish:
output_snippet_text += "<HCAL_RUNINFOPUBLISH>{0}</HCAL_RUNINFOPUBLISH>\n".format(match_RunInfoPublish.group("RunInfoPublish"))

match_OfficialRunNumbers = re_OfficialRunNumbers.search(line)
if match_OfficialRunNumbers:
output_snippet_text += "<OFFICIAL_RUN_NUMBERS>{0}</OFFICIAL_RUN_NUMBERS>\n".format(match_OfficialRunNumbers.group("OfficialRunNumbers"))

match_NumberOfEvents = re_NumberOfEvents.search(line)
#if match_NumberOfEvents:
# output_snippet_text += "<NUMBER_OF_EVENTS>{0}</NUMBER_OF_EVENTS>\n".format(match_NumberOfEvents.group("NumberOfEvents"))

# xi:includes
elif re_include.search(line):
match_include_file = re_include_file.search(line)
if not match_include_file:
raise ParsingError("Didn't find file in include line {0}".format(line))
include_file = match_include_file.group("file").replace("^/", "")
match_include_version = re_include_version.search(line)
if not match_include_version:
raise ParsingError("Didn't find version in include line {0}".format(line))
include_version = match_include_version.group("version")
output_snippet_text += "<xi:include parse=\"text\" href=\"{0}/{1}\"/>\n".format(include_file, include_version)
elif re_mastersnippet.search(line):
output_snippet_text += "<mastersnippet xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n"

# Tag replacements/nothing to change
else:
for input_tag, output_tag in tag_mapping.iteritems():
line = line.replace(input_tag, output_tag)
output_snippet_text += line
input_snippet.close()

output_snippet = open(output_path, 'w')
output_snippet.write(output_snippet_text)
output_snippet.close()

class ParsingError(Exception):
def __init__(self, arg):
self.args = arg


if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Convert snippets to FM parameter-centric format")
parser.add_argument("input_path", type=str, help="Input snippet path")
parser.add_argument("output_path", type=str, help="Output snippet path")
args = parser.parse_args()

try:
PortSnippet(args.input_path, args.output_path)
except ParsingError,e:
import time
print "Failed to parse snippet:"
print "".join(e.args)
sys.exit(1)

#os.system("diff {} {}".format(args.input_path, args.output_path))
os.system("cat {0}".format(args.output_path))
71 changes: 71 additions & 0 deletions example_snippet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<mastersnippet>
<CommonMasterSnippet file="Master/common_led.xml"/>
<HCAL_RUNINFOPUBLISH>true</HCAL_RUNINFOPUBLISH>
<OFFICIAL_RUN_NUMBERS>true</OFFICIAL_RUN_NUMBERS>
<HCAL_CFGSCRIPT>
include(/Common/Global.cfg:pro)
include(/Common/Connectivity.cfg:pro)

include(/DCC/Settings-GlobalRun.cfg:pro)
include(/DCC/Firmware.cfg:pro)

include(/HTR/Settings-GlobalRun.cfg:pro)
include(/HTR/Firmware.cfg:pro)

include(/TTCfanout/HcalSlave.cfg:pro)
include(/TTCfanout/HcalMaster.cfg:pro)
include(/TTCfanout/RCTMaster.cfg:pro)

include(/HLX/Settings.cfg:pro)
include(/SLB/Settings.cfg:pro)

include(/Trigger/Pedestal.cfg:pro)
include(/Trigger/Laser-OrbitGap.cfg:pro)

include(/Laser/uMNioQIE.cfg:pro)
include(/Laser/uMNioOrbitGap.cfg:pro)
include(/Laser/uMNioQIE-GlobalRun.cfg:pro)

include(/RBX/Settings-GlobalRun.cfg:pro)
include(/RBX/RBXlists.cfg:pro)
include(/RBX/Tags_oracle.cfg:pro)
include(/RBX/RBXstatus.cfg:pro)

include(/TechTrigProc/Firmware.cfg:pro)
include(/TechTrigProc/Settings-HO.cfg:pro)
include(/TechTrigProc/Settings-HF.cfg:pro)
include(/TechTrigProc/Settings-HBHE.cfg:pro)

include(/Other/TSManager.cfg:pro)
include(/Other/HcalWriter.cfg:pro)

include(/HTR/LUTs.cfg:pro)
include(/HTR/ZeroSuppression.cfg:pro)
#include(/HTR/SpecialZeroSuppression.cfg:pro)

include(/Lumi/Settings.cfg:pro)
include(/Lumi/Settings-GlobalRun.cfg:pro)

include(/TechTrigProc/Settings-HO-coinc-timeDiff.cfg:pro)

include(/uTCA/Global.cfg:pro)
include(/uTCA/uHTR.cfg:pro)
include(/uTCA/uHTR-GlobalRun.cfg:pro)
include(/uTCA/DTC.cfg:pro)
include(/uTCA/DTC-CDAQ.cfg:pro)

</HCAL_CFGSCRIPT>

<HCAL_PICONTROL></HCAL_PICONTROL>
<HCAL_TCDSCONTROL>
<xi:include parse="text" href=TCDS/BGo_global.cfg/pro/>
<xi:include parse="text" href=TCDS/global.cfg/pro/>
<xi:include parse="text" href=TCDS/BGo_CalibSequence.cfg/pro/>
</HCAL_TCDSCONTROL>

<FED_ENABLE_MASK>700&amp;3%701&amp;3%702&amp;3%703&amp;3%704&amp;3%705&amp;3%706&amp;3%707&amp;3%708&amp;3%709&amp;3%710&amp;3%711&amp;3%712&amp;3%713&amp;3%714&amp;3%715&amp;3%716&amp;3%1100&amp;3%1102&amp;3%1104&amp;3%1106&amp;3%1108&amp;3%1110&amp;3%1112&amp;3%1114&amp;3%1116&amp;3%717&amp;3%720&amp;3%721&amp;3%1118&amp;3%1120&amp;3%1122&amp;3%724&amp;3%725&amp;3%726&amp;3%727&amp;3%728&amp;3%729&amp;3%730&amp;3%731&amp;3%</FED_ENABLE_MASK>


<HCAL_ALARMER_URL>http://hcalmon.cms:9945</HCAL_ALARMER_URL>

</mastersnippet>
15 changes: 13 additions & 2 deletions installation/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
<pathelement location="${rcms.classes}"/>
</path>

<!--
<path id="ext.classpath">
<fileset dir="../ext/">
<include name="gson-2.8.0.jar"/>
</fileset>
</path>
-->

<!-- Compiles this StateMachine -->
<target name="compile" depends="clean">
<echo message="Compile this FunctionManager code" />
Expand All @@ -44,8 +52,11 @@
srcdir="${fm.src}"
destdir="${fm.classes}"
failonerror="true"
nowarn="true">
<classpath refid="rcms.classpath"/>
nowarn="true">
<classpath>
<!--<path refid="ext.classpath"/>-->
<path refid="rcms.classpath"/>
</classpath>
<compilerarg value="-Xlint"/>
</javac>
</target>
Expand Down
11 changes: 6 additions & 5 deletions src/rcms/fm/app/level1/HCALEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2227,7 +2227,8 @@ public void run() {
List<String> watchedPartitions = new ArrayList<String>(); //All watchedPartitions (LV2 names)
List<String> AlarmerPamNames = new ArrayList<String>(); //All alarmer pam Names
String FMstate = functionManager.getState().getStateString();
XDAQParameter NameQuery = new XDAQParameter(functionManager.alarmerURL,"hcalAlarmer",0);
String alarmerURL_str = ((StringT)functionManager.getHCALparameterSet().get("HCAL_ALARMER_URL").getValue()).getString();
XDAQParameter NameQuery = new XDAQParameter(alarmerURL_str,"hcalAlarmer",0);
HashMap<String,String> partitionStatusMap = new HashMap<String,String>(); // e.g. <HO,HO_Status>,<Laser,LASER_Status>
HashMap<String,String> partitionMessageMap = new HashMap<String,String>(); // e.g. <HO,HO_Message>,<Laser,LASER_Message>

Expand Down Expand Up @@ -2310,11 +2311,11 @@ public void run() {
stopAlarmerWatchThread = false;
try {
@SuppressWarnings("unused")
URL alarmerURL = new URL(functionManager.alarmerURL);
URL alarmerURL = new URL(((StringT)functionManager.getHCALparameterSet().get("HCAL_ALARMER_URL").getValue()).getString());
} catch (MalformedURLException e) {
// in case the URL is bogus, just don't run the thread
stopAlarmerWatchThread = true;
logger.warn("[HCAL " + functionManager.FMname + "] HCALEventHandler: alarmerWatchThread: value of alarmerURL is not valid: " + functionManager.alarmerURL + "; not checking alarmer status");
logger.warn("[HCAL " + functionManager.FMname + "] HCALEventHandler: alarmerWatchThread: value of alarmerURL is not valid: " + ((StringT)functionManager.getHCALparameterSet().get("HCAL_ALARMER_URL").getValue()).getString() + "; not checking alarmer status");
}

// poll alarmer status in the Running/RunningDegraded states every 30 sec to see if it is still OK/alive
Expand Down Expand Up @@ -2359,7 +2360,7 @@ public void run() {

// ask for the status of the HCAL alarmer
// ("http://hcalmon.cms:9945","hcalAlarmer",0);
XDAQParameter pam = new XDAQParameter(functionManager.alarmerURL,"hcalAlarmer",0);
XDAQParameter pam = new XDAQParameter(((StringT)functionManager.getHCALparameterSet().get("HCAL_ALARMER_URL").getValue()).getString(), "hcalAlarmer", 0);
// this does a lazy get. do we need to force the update before getting it?

// Get the status for each watched alarm
Expand Down Expand Up @@ -2682,4 +2683,4 @@ public String getProperty(QualifiedResource QR, String name ) throws Exception
}
throw new Exception("Property "+name+" not found");
}
}
}
3 changes: 0 additions & 3 deletions src/rcms/fm/app/level1/HCALFunctionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,6 @@ public class HCALFunctionManager extends UserFunctionManager {

public String rcmsStateListenerURL = "";

public String alarmerURL = "";

public String alarmerPartition = "";

public HCALFunctionManager() {
// any State Machine Implementation must provide the framework with some information about itself.
Expand Down
8 changes: 7 additions & 1 deletion src/rcms/fm/app/level1/HCALParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public synchronized void initializeParameters() throws ParameterException {
this.put( new FunctionManagerParameter<StringT> ("CONFIGURED_WITH_RUN_KEY" , new StringT("not set") , FunctionManagerParameter.Exported.READONLY) ); // Configuration information for l0: Global configuration key at last configure
this.put( new FunctionManagerParameter<StringT> ("CONFIGURED_WITH_TPG_KEY" , new StringT("not set") , FunctionManagerParameter.Exported.READONLY) ); // Configuration information for l0: Trigger key at last configure
this.put( new FunctionManagerParameter<StringT> ("CONFIGURED_WITH_FED_ENABLE_MASK" , new StringT("not set") , FunctionManagerParameter.Exported.READONLY) ); // Configuration information for l0: FED enable mask at last configure
this.put( new FunctionManagerParameter<StringT> ("DQM_TASK" , new StringT("pedestal"), FunctionManagerParameter.Exported.READONLY) ); // Used for Local Run to specify which DQM task to be run on this run
this.put( new FunctionManagerParameter<StringT> ("HCAL_ALARMER_URL" , new StringT("not set") , FunctionManagerParameter.Exported.READONLY) ); // Configuration information for l0: FED enable mask at last configure
this.put( new FunctionManagerParameter<StringT> ("DQM_TASK" , new StringT("pedestal") , FunctionManagerParameter.Exported.READONLY) ); // Used for Local Run to specify which DQM task to be run on this run

this.put( new FunctionManagerParameter<BooleanT> ("USE_PRIMARY_TCDS" , new BooleanT(true) , FunctionManagerParameter.Exported.READONLY) ); // Switch for using the secondary TCDS system
this.put( new FunctionManagerParameter<BooleanT> ("HCAL_RUNINFOPUBLISH" , new BooleanT(true) , FunctionManagerParameter.Exported.READONLY) ); // Switch for publishing RunInfo
Expand Down Expand Up @@ -113,6 +114,11 @@ public synchronized void initializeParameters() throws ParameterException {
this.put( new FunctionManagerParameter<VectorT<StringT>> ("MASKED_RESOURCES" , new VectorT<StringT>() ) ); // List of masked resources
this.put( new FunctionManagerParameter<VectorT<StringT>> ("MASK_SUMMARY" , new VectorT<StringT>() ) ); // Summary of masked FMs for user understandability
this.put( new FunctionManagerParameter<VectorT<StringT>> ("EMPTY_FMS" , new VectorT<StringT>() ) ); // LV2 FMs without XDAQs

//this.put( new FunctionManagerParameter<VectorT<StringT>> ("TEST_VECTORT_STRINGT", new VectorT<StringT>()));
//this.put( new FunctionManagerParameter<VectorT<IntegerT>> ("TEST_VECTORT_INTEGERT", new VectorT<IntegerT>()));
//this.put( new FunctionManagerParameter<MapT<StringT>> ("TEST_MAPT_STRINGT", new MapT<StringT>()));
//this.put( new FunctionManagerParameter<MapT<IntegerT>> ("TEST_MAPT_INTEGERT", new MapT<IntegerT>()));
}

public static HCALParameters getInstance() {
Expand Down
5 changes: 3 additions & 2 deletions src/rcms/fm/app/level1/HCALlevelOneEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,12 @@ public void configureAction(Object obj) throws UserActionException {
String LTCControlSequence = ((StringT)functionManager.getHCALparameterSet().get("HCAL_LTCCONTROL" ).getValue()).getString();
FedEnableMask = ((StringT)functionManager.getHCALparameterSet().get("FED_ENABLE_MASK" ).getValue()).getString();
String DQMtask = ((StringT)functionManager.getHCALparameterSet().get("DQM_TASK").getValue()).getString();
String alarmerURL = ((StringT)functionManager.getHCALparameterSet().get("HCAL_ALARMER_URL").getValue()).getString();
// Get the value of runinfopublish from the results of parseMasterSnippet
RunInfoPublish = ((BooleanT)functionManager.getHCALparameterSet().get("HCAL_RUNINFOPUBLISH").getValue()).getBoolean();
OfficialRunNumbers = ((BooleanT)functionManager.getHCALparameterSet().get("OFFICIAL_RUN_NUMBERS").getValue()).getBoolean();
TriggersToTake = ((IntegerT)functionManager.getHCALparameterSet().get("NUMBER_OF_EVENTS").getValue()).getInteger();

//Switch single/Multi partition
boolean isSinglePartition = ((BooleanT)functionManager.getHCALparameterSet().get("SINGLEPARTITION_MODE").getValue()).getBoolean();
String LPMControlSequence="not set";
Expand All @@ -822,8 +824,7 @@ public void configureAction(Object obj) throws UserActionException {
logger.debug("[HCAL LVL1 " + functionManager.FMname + "] The final PIControlSequence is like this: \n" +PIControlSequence );
logger.debug("[HCAL LVL1 " + functionManager.FMname + "] The final TTCciControlSequence is like this: \n" +TTCciControlSequence );
logger.debug("[HCAL LVL1 " + functionManager.FMname + "] The final LTCControlSequence is like this: \n" +LTCControlSequence );
logger.info("[HCAL LVL1 " + functionManager.FMname + "] The final AlarmerURL is " +functionManager.alarmerURL );
logger.info("[HCAL LVL1 " + functionManager.FMname + "] The final AlarmerPartition is " +functionManager.alarmerPartition );
logger.info("[HCAL LVL1 " + functionManager.FMname + "] The final AlarmerURL is " +alarmerURL );
logger.info("[HCAL LVL1 " + functionManager.FMname + "] The FED_ENABLE_MASK used by the level-1 is: " +FedEnableMask );
logger.info("[HCAL LVL1 " + functionManager.FMname + "] The RunInfoPublish value is : " +RunInfoPublish );
logger.info("[HCAL LVL1 " + functionManager.FMname + "] The OfficialRunNumbers value is : " +OfficialRunNumbers );
Expand Down
Loading