diff --git a/PortSnippet.py b/PortSnippet.py new file mode 100644 index 0000000..bb62f06 --- /dev/null +++ b/PortSnippet.py @@ -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("true|false)\"") + re_OfficialRunNumbers = re.compile("OfficialRunNumbers=\"(?Ptrue|false)\"") + re_NumberOfEvents = re.compile("NumberOfEvents=\"(?P\d+)\"") + + re_mastersnippet = re.compile(".+?)\"") + re_include_version = re.compile("version=\"(?P.+?)\"") + + # 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 += "{0}\n".format(match_RunInfoPublish.group("RunInfoPublish")) + + match_OfficialRunNumbers = re_OfficialRunNumbers.search(line) + if match_OfficialRunNumbers: + output_snippet_text += "{0}\n".format(match_OfficialRunNumbers.group("OfficialRunNumbers")) + + match_NumberOfEvents = re_NumberOfEvents.search(line) + #if match_NumberOfEvents: + # output_snippet_text += "{0}\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 += "\n".format(include_file, include_version) + elif re_mastersnippet.search(line): + output_snippet_text += "\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)) diff --git a/example_snippet.xml b/example_snippet.xml new file mode 100644 index 0000000..13db24f --- /dev/null +++ b/example_snippet.xml @@ -0,0 +1,71 @@ + + +true +true + + 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) + + + + + + + + + + +700&3%701&3%702&3%703&3%704&3%705&3%706&3%707&3%708&3%709&3%710&3%711&3%712&3%713&3%714&3%715&3%716&3%1100&3%1102&3%1104&3%1106&3%1108&3%1110&3%1112&3%1114&3%1116&3%717&3%720&3%721&3%1118&3%1120&3%1122&3%724&3%725&3%726&3%727&3%728&3%729&3%730&3%731&3% + + +http://hcalmon.cms:9945 + + diff --git a/installation/build.xml b/installation/build.xml index 665592b..353a52d 100755 --- a/installation/build.xml +++ b/installation/build.xml @@ -33,6 +33,14 @@ + + @@ -44,8 +52,11 @@ srcdir="${fm.src}" destdir="${fm.classes}" failonerror="true" - nowarn="true"> - + nowarn="true"> + + + + diff --git a/src/rcms/fm/app/level1/HCALEventHandler.java b/src/rcms/fm/app/level1/HCALEventHandler.java index 59c4e6e..a7caff1 100755 --- a/src/rcms/fm/app/level1/HCALEventHandler.java +++ b/src/rcms/fm/app/level1/HCALEventHandler.java @@ -2227,7 +2227,8 @@ public void run() { List watchedPartitions = new ArrayList(); //All watchedPartitions (LV2 names) List AlarmerPamNames = new ArrayList(); //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 partitionStatusMap = new HashMap(); // e.g. , HashMap partitionMessageMap = new HashMap(); // e.g. , @@ -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 @@ -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 @@ -2682,4 +2683,4 @@ public String getProperty(QualifiedResource QR, String name ) throws Exception } throw new Exception("Property "+name+" not found"); } -} \ No newline at end of file +} diff --git a/src/rcms/fm/app/level1/HCALFunctionManager.java b/src/rcms/fm/app/level1/HCALFunctionManager.java index bd718e9..7842aee 100755 --- a/src/rcms/fm/app/level1/HCALFunctionManager.java +++ b/src/rcms/fm/app/level1/HCALFunctionManager.java @@ -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. diff --git a/src/rcms/fm/app/level1/HCALParameters.java b/src/rcms/fm/app/level1/HCALParameters.java index da68d43..f351647 100755 --- a/src/rcms/fm/app/level1/HCALParameters.java +++ b/src/rcms/fm/app/level1/HCALParameters.java @@ -73,7 +73,8 @@ public synchronized void initializeParameters() throws ParameterException { this.put( new FunctionManagerParameter ("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 ("CONFIGURED_WITH_TPG_KEY" , new StringT("not set") , FunctionManagerParameter.Exported.READONLY) ); // Configuration information for l0: Trigger key at last configure this.put( new FunctionManagerParameter ("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 ("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 ("HCAL_ALARMER_URL" , new StringT("not set") , FunctionManagerParameter.Exported.READONLY) ); // Configuration information for l0: FED enable mask at last configure + this.put( new FunctionManagerParameter ("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 ("USE_PRIMARY_TCDS" , new BooleanT(true) , FunctionManagerParameter.Exported.READONLY) ); // Switch for using the secondary TCDS system this.put( new FunctionManagerParameter ("HCAL_RUNINFOPUBLISH" , new BooleanT(true) , FunctionManagerParameter.Exported.READONLY) ); // Switch for publishing RunInfo @@ -113,6 +114,11 @@ public synchronized void initializeParameters() throws ParameterException { this.put( new FunctionManagerParameter> ("MASKED_RESOURCES" , new VectorT() ) ); // List of masked resources this.put( new FunctionManagerParameter> ("MASK_SUMMARY" , new VectorT() ) ); // Summary of masked FMs for user understandability this.put( new FunctionManagerParameter> ("EMPTY_FMS" , new VectorT() ) ); // LV2 FMs without XDAQs + + //this.put( new FunctionManagerParameter> ("TEST_VECTORT_STRINGT", new VectorT())); + //this.put( new FunctionManagerParameter> ("TEST_VECTORT_INTEGERT", new VectorT())); + //this.put( new FunctionManagerParameter> ("TEST_MAPT_STRINGT", new MapT())); + //this.put( new FunctionManagerParameter> ("TEST_MAPT_INTEGERT", new MapT())); } public static HCALParameters getInstance() { diff --git a/src/rcms/fm/app/level1/HCALlevelOneEventHandler.java b/src/rcms/fm/app/level1/HCALlevelOneEventHandler.java index 6e5a9f8..37d7035 100755 --- a/src/rcms/fm/app/level1/HCALlevelOneEventHandler.java +++ b/src/rcms/fm/app/level1/HCALlevelOneEventHandler.java @@ -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"; @@ -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 ); diff --git a/src/rcms/fm/app/level1/HCALxmlHandler.java b/src/rcms/fm/app/level1/HCALxmlHandler.java index 466e0f6..062b2bf 100644 --- a/src/rcms/fm/app/level1/HCALxmlHandler.java +++ b/src/rcms/fm/app/level1/HCALxmlHandler.java @@ -1,6 +1,7 @@ package rcms.fm.app.level1; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.StringReader; import java.util.List; @@ -44,10 +45,23 @@ import rcms.fm.fw.user.UserActionException; import rcms.fm.fw.parameter.FunctionManagerParameter; +import rcms.fm.fw.parameter.type.ParameterType; +import rcms.fm.fw.parameter.type.ParameterTypeFactory; import rcms.fm.fw.parameter.ParameterSet; import rcms.fm.fw.parameter.type.StringT; -import rcms.fm.fw.parameter.type.IntegerT; import rcms.fm.fw.parameter.type.BooleanT; +import rcms.fm.fw.parameter.type.ByteT; +import rcms.fm.fw.parameter.type.DateT; +import rcms.fm.fw.parameter.type.DoubleT; +import rcms.fm.fw.parameter.type.FloatT; +import rcms.fm.fw.parameter.type.IntegerT; +import rcms.fm.fw.parameter.type.LongT; +import rcms.fm.fw.parameter.type.MapT; +import rcms.fm.fw.parameter.type.ShortT; +import rcms.fm.fw.parameter.type.StringT; +import rcms.fm.fw.parameter.type.StructT; +import rcms.fm.fw.parameter.type.UnsignedIntegerT; +import rcms.fm.fw.parameter.type.UnsignedShortT; import rcms.fm.fw.parameter.type.VectorT; import rcms.fm.fw.parameter.type.ByteT; import rcms.fm.fw.parameter.type.DateT; @@ -58,11 +72,17 @@ import rcms.fm.fw.parameter.type.UnsignedIntegerT; import rcms.fm.fw.parameter.type.UnsignedShortT; import rcms.fm.fw.parameter.type.MapT; +import rcms.fm.fw.parameter.util.JsonUtil; import rcms.fm.resource.QualifiedResource; import rcms.resourceservice.db.resource.fm.FunctionManagerResource; import rcms.util.logger.RCMSLogger; +//import com.google.gson.Gson; +//import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Field; /** * @author John Hakala * @@ -476,123 +496,273 @@ public void parseMasterSnippet(String selectedRun, String CfgCVSBasePath) throws // Fill parameters from MasterSnippet public void parseMasterSnippet(String selectedRun, String CfgCVSBasePath,String PartitionName) throws UserActionException{ - try{ - logger.info("[HCAL " + functionManager.FMname + "]: Welcome to parseMasterSnippet. Mastersnippet file=" + selectedRun + "; PartitionName= "+PartitionName); - // Get ControlSequences from mastersnippet - docBuilder = docBuilderFactory.newDocumentBuilder(); - Document masterSnippet = docBuilder.parse(new File(CfgCVSBasePath + selectedRun + "/pro")); - - masterSnippet.getDocumentElement().normalize(); - Element masterSnippetElement = masterSnippet.getDocumentElement(); + logger.info("[HCAL " + functionManager.FMname + "]: Welcome to parseMasterSnippet(" + selectedRun + ", " + CfgCVSBasePath + " )"); + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setXIncludeAware(true); // This is needed for xi:include to work + factory.setNamespaceAware(true); + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + String masterUriActual = CfgCVSBasePath + selectedRun + "/pro"; + String masterUriSystem = CfgCVSBasePath + "/master.xml"; // This is needed for relative resolution of includes to be based on CfgCVSBasePath, rather than the working directory + InputSource masterInputSource = new InputSource(new FileInputStream(masterUriActual)); + Document masterSnippet = docBuilder.parse(masterInputSource.getByteStream(), masterUriSystem); + masterSnippet.getDocumentElement().normalize(); + + Element masterSnippetElement = masterSnippet.getDocumentElement(); + NodeList elements = masterSnippetElement.getChildNodes(); + NodeList listOfTags = masterSnippetElement.getChildNodes(); + + + // Look for common master snippet and, if present, parse first + String commonMasterSnippetFile = ""; + for (int iNode = 0; iNode < elements.getLength(); iNode++) { + if (elements.item(iNode).getNodeType() == Node.ELEMENT_NODE) { + if (elements.item(iNode).getNodeName() == "CommonMasterSnippet") { + // Check that it has not already been set + if (commonMasterSnippetFile != "") { + String errMessage = "[HCAL " + functionManager.FMname + "] parseMasterSnippet: Found multiple instances of CommonMasterSnippet. Only one is allowed."; + throw new UserActionException(errMessage); + } + commonMasterSnippetFile = ((Element)elements.item(iNode)).getAttributes().getNamedItem("file").getNodeValue(); + } + } + } + + if (commonMasterSnippetFile != "") { + if(PartitionName==""){ + logger.info("[HCAL " + functionManager.FMname + "]: Parsing the common master snippet from " + commonMasterSnippetFile + "."); + }else{ + logger.info("[HCAL " + functionManager.FMname + "]: Parsing the common master snippet from " + commonMasterSnippetFile + " for Partition="+PartitionName+" ."); + } + this.parseMasterSnippet(commonMasterSnippetFile,CfgCVSBasePath,PartitionName); + logger.info("[HCAL " + functionManager.FMname + "]: Done parsing the common mastersnippet. Continue to parse the main one."); + } + + //Validate partition attribute input if LV1 is parsing the mastersnippet + if (!functionManager.containerFMChildren.isEmpty()){ + //Masked FM children should be valid input. Use containerAllFMChildren instead of containerFMChildren + List allFMlists = functionManager.containerAllFMChildren.getQualifiedResourceList(); + ArrayList ValidPartitionNames = new ArrayList(); + for (QualifiedResource FMqr: allFMlists){ + // FM name = HCAL_PartitionName + ValidPartitionNames.add(FMqr.getName().substring(5)); + ValidPartitionNames.add(FMqr.getName()); + } - NodeList listOfTags = masterSnippetElement.getChildNodes(); - String commonMasterSnippetFile = ""; for(int i =0;i< listOfTags.getLength();i++){ if( listOfTags.item(i).getNodeType()== Node.ELEMENT_NODE){ - if (listOfTags.item(i).getNodeName() == "CommonMasterSnippet") { - if (commonMasterSnippetFile != "") { - String errMessage = "[HCAL " + functionManager.FMname + "] parseMasterSnippet: Found multiple instances of CommonMasterSnippet. Only one is allowed."; - throw new UserActionException(errMessage); + Element iElement = (Element) listOfTags.item(i); + if(iElement.hasAttribute("Partition")){ + String ElementName = iElement.getNodeName(); + String ElementPartition = iElement.getAttributes().getNamedItem("Partition").getNodeValue(); + String[] ElementPartitionArray = ElementPartition.split(";"); + for(String partitionName:ElementPartitionArray){ + if(! ValidPartitionNames.contains(partitionName)){ + String errMessage = "[HCAL"+functionManager.FMname+"] parseMasterSnippet: Found invalid Partition="+partitionName+" in this tag "+ElementName+".\n Valid partition names are:"+ ValidPartitionNames.toString(); + functionManager.goToError(errMessage); + } + } + if(ElementName.equals("CfgScript")){ + String errMessage = "[HCAL"+functionManager.FMname+"] parseMasterSnippet: Found Partition attribute in CfgScript. This is not allowed. Please try to set the same partition-specific setting via snippet." ; + functionManager.goToError(errMessage); } - commonMasterSnippetFile = ((Element)listOfTags.item(i)).getAttributes().getNamedItem("file").getNodeValue(); } } } - if (commonMasterSnippetFile != "") { - if(PartitionName==""){ - logger.info("[HCAL " + functionManager.FMname + "]: Parsing the common master snippet from " + commonMasterSnippetFile + "."); - }else{ - logger.info("[HCAL " + functionManager.FMname + "]: Parsing the common master snippet from " + commonMasterSnippetFile + " for Partition="+PartitionName+" ."); - } - this.parseMasterSnippet(commonMasterSnippetFile,CfgCVSBasePath,PartitionName); - logger.info("[HCAL " + functionManager.FMname + "]: Done parsing the common mastersnippet. Continue to parse the main one."); - } - - //Validate partition attribute input if LV1 is parsing the mastersnippet - if (!functionManager.containerFMChildren.isEmpty()){ - //Masked FM children should be valid input. Use containerAllFMChildren instead of containerFMChildren - List allFMlists = functionManager.containerAllFMChildren.getQualifiedResourceList(); - ArrayList ValidPartitionNames = new ArrayList(); - for (QualifiedResource FMqr: allFMlists){ - // FM name = HCAL_PartitionName - ValidPartitionNames.add(FMqr.getName().substring(5)); - ValidPartitionNames.add(FMqr.getName()); + } + for(int i =0;i< listOfTags.getLength();i++){ + if( listOfTags.item(i).getNodeType()== Node.ELEMENT_NODE){ + Element iElement = (Element) listOfTags.item(i); + //Remove the partition attributed elements if we are parsing for all partition + if(PartitionName=="" && iElement.hasAttribute("Partition")){ + iElement.getParentNode().removeChild(iElement); + logger.info("[HCAL "+functionManager.FMname+" ] removing this node:"+ iElement.getNodeName()+" because it is partition specific."); } - - for(int i =0;i< listOfTags.getLength();i++){ - if( listOfTags.item(i).getNodeType()== Node.ELEMENT_NODE){ - Element iElement = (Element) listOfTags.item(i); - if(iElement.hasAttribute("Partition")){ - String ElementName = iElement.getNodeName(); + if(PartitionName!=""){ + //Remove the non-partition elements if we are parsing for some partition + if(!iElement.hasAttribute("Partition")){ + iElement.getParentNode().removeChild(iElement); + logger.info("[HCAL "+functionManager.FMname+" ] removing this node:"+ iElement.getNodeName()+" because it is not partition specific."); + } + //Remove the partition elements that are for other partitions + if(iElement.hasAttribute("Partition")){ String ElementPartition = iElement.getAttributes().getNamedItem("Partition").getNodeValue(); - String[] ElementPartitionArray = ElementPartition.split(";"); - for(String partitionName:ElementPartitionArray){ - if(! ValidPartitionNames.contains(partitionName)){ - String errMessage = "[HCAL"+functionManager.FMname+"] parseMasterSnippet: Found invalid Partition="+partitionName+" in this tag "+ElementName+".\n Valid partition names are:"+ ValidPartitionNames.toString(); - functionManager.goToError(errMessage); - } + if(!ElementPartition.contains(PartitionName)){ + iElement.getParentNode().removeChild(iElement); + logger.info("[HCAL "+functionManager.FMname+" ] removing this node:"+ iElement.getNodeName()+" because "+ElementPartition+" do not contain "+PartitionName); } - if(ElementName.equals("CfgScript")){ - String errMessage = "[HCAL"+functionManager.FMname+"] parseMasterSnippet: Found Partition attribute in CfgScript. This is not allowed. Please try to set the same partition-specific setting via snippet." ; - functionManager.goToError(errMessage); + } + } + } + } + masterSnippet.getDocumentElement().normalize(); + + + // Parse parameters from main file + for (int iNode = 0; iNode < elements.getLength(); iNode++) { + if (elements.item(iNode).getNodeType() == Node.ELEMENT_NODE) { + Element parameterElement = (Element)elements.item(iNode); + + String parameterName = parameterElement.getNodeName(); + if (parameterName == "CommonMasterSnippet" || parameterName == "mastersnippet" ) { + continue; + } + logger.info("HCAL " + functionManager.FMname + "]: Found parameter " + parameterName); + + // Require that the parameter is declared in HCALParameters.java + if (!functionManager.getHCALparameterSet().contains(parameterName)) { + String errMessage = "[HCAL " + functionManager.FMname + "] parseMasterSnippetTest: Invalid parameter found in master snippet! No such Parameter name = " + parameterName + "."; + throw new UserActionException(errMessage); + } + + // Parameter::getType() returns, e.g., rcms.fm.fw.parameter.type.StringT + String[] parameterTypeLong = functionManager.getHCALparameterSet().get(parameterName).getType().getName().split("\\."); + String parameterType = parameterTypeLong[parameterTypeLong.length - 1]; + String parameterValue = parameterElement.getTextContent(); + + // Truncate parameter value + if (parameterValue.length()>=1000){ + parameterValue = parameterValue.substring(0, Math.min(parameterValue.length(), 1000)); + logger.info("[HCAL " + functionManager.FMname + "]: Parsing parameter " + parameterName + ", type=" + parameterType + ", value(truncated)=" + parameterValue); + }else{ + logger.info("[HCAL " + functionManager.FMname + "]: Parsing parameter " + parameterName + ", type=" + parameterType + ", value=" + parameterValue); + } + + switch (parameterType) { + case "BooleanT": + { + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new BooleanT(parameterValue))); + break; + } + case "ByteT": + { + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new ByteT(parameterValue))); + break; + } + case "DateT": + { + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new DateT(parameterValue))); + break; + } + case "DoubleT ": + { + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new DoubleT(parameterValue))); + break; + } + case "FloatT": + { + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new FloatT(parameterValue))); + break; + } + case "IntegerT": + { + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new IntegerT(parameterValue))); + break; + } + case "LongT": + { + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new LongT(parameterValue))); + break; + } + case "ShortT": + { + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new ShortT(parameterValue))); + break; + } + case "StringT": + { + if (parameterName.equals("HCAL_CFGSCRIPT")) { + String oldString = ((StringT)functionManager.getHCALparameterSet().get(parameterName).getValue()).getString(); + if (oldString.equals("not set")) { + oldString = ""; } + String newString = oldString + parameterValue; + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new StringT(newString))); + } else { + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new StringT(parameterValue))); } + break; } - } - } - for(int i =0;i< listOfTags.getLength();i++){ - if( listOfTags.item(i).getNodeType()== Node.ELEMENT_NODE){ - Element iElement = (Element) listOfTags.item(i); - //Remove the partition attributed elements if we are parsing for all partition - if(PartitionName=="" && iElement.hasAttribute("Partition")){ - iElement.getParentNode().removeChild(iElement); - logger.info("[HCAL "+functionManager.FMname+" ] removing this node:"+ iElement.getNodeName()+" because it is partition specific."); + case "UnsignedIntegerT": + { + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new UnsignedIntegerT(parameterValue))); + break; } - if(PartitionName!=""){ - //Remove the non-partition elements if we are parsing for some partition - if(!iElement.hasAttribute("Partition")){ - iElement.getParentNode().removeChild(iElement); - logger.info("[HCAL "+functionManager.FMname+" ] removing this node:"+ iElement.getNodeName()+" because it is not partition specific."); - } - //Remove the partition elements that are for other partitions - if(iElement.hasAttribute("Partition")){ - String ElementPartition = iElement.getAttributes().getNamedItem("Partition").getNodeValue(); - if(!ElementPartition.contains(PartitionName)){ - iElement.getParentNode().removeChild(iElement); - logger.info("[HCAL "+functionManager.FMname+" ] removing this node:"+ iElement.getNodeName()+" because "+ElementPartition+" do not contain "+PartitionName); + case "UnsignedShortT": + { + functionManager.getHCALparameterSet().put(new FunctionManagerParameter(parameterName, new UnsignedShortT(parameterValue))); + break; + } + // VectorT and MapT parsing use JsonUtil from the rcms framework, as suggested by Hannes. + // The type is inferred from the content: Double, Integer, String, Boolean. + case "VectorT": + { + Object parsedVector = JsonUtil.decode(parameterValue); + //logger.info("[HCAL " + functionManager.FMname + "]: Result of parsing vector is " + parsedVector); + if (parsedVector instanceof ArrayList) { + //Only allow vector of double,integer,string,boolean for now. + for (Object entry : (ArrayList)parsedVector) { + if (entry instanceof Double) { + ((VectorT)functionManager.getHCALparameterSet().get(parameterName).getValue()).add(new DoubleT((Double)entry)); + } else if (entry instanceof Integer) { + ((VectorT)functionManager.getHCALparameterSet().get(parameterName).getValue()).add(new IntegerT((Integer)entry)); + } else if (entry instanceof Boolean) { + ((VectorT)functionManager.getHCALparameterSet().get(parameterName).getValue()).add(new BooleanT((Boolean)entry)); + } else if (entry instanceof String) { + ((VectorT)functionManager.getHCALparameterSet().get(parameterName).getValue()).add(new StringT((String)entry)); + } else { + String errMessage = "[HCAL " + functionManager.FMname + "] parseMasterSnippet: Parameter " + parameterName + " was not parsed into a vector of Double, Integer, String, or Boolean."; + throw new UserActionException(errMessage); } - } + } + // The following code unfortunately doesn't work: HCALParameters::run() starts throwing a `failed to update` error, somewhere in HCALParameters::getClonedParameterSet(). We suspect it's due to the wildcard ?, but don't understand why. + //VectorT tmpVectorT = new VectorT((ArrayList)parsedVector); + //functionManager.getHCALparameterSet().put(new FunctionManagerParameter>(parameterName, tmpVectorT)); + } else { + String errMessage = "[HCAL " + functionManager.FMname + "] parseMasterSnippet: parsed vector failed instanceof ArrayList. Parsed result = " + parsedVector; + throw new UserActionException(errMessage); + } + break; } - } - } - masterSnippet.getDocumentElement().normalize(); - - for(int i =0;i< listOfTags.getLength();i++){ - if( listOfTags.item(i).getNodeType()== Node.ELEMENT_NODE){ - Element iElement = (Element) listOfTags.item(i); - String iTagName = iElement.getNodeName(); - Boolean isValidTag = Arrays.asList(ValidMasterSnippetTags).contains( iTagName ); - - if(isValidTag){ - if (iTagName == "FMParameter") { - SetHCALFMParameter(iElement); + case "MapT": + { + Object parsedMap = JsonUtil.decode(parameterValue); + //logger.info("[HCAL " + functionManager.FMname + "]: Result of parsing map is " + parsedMap); + if (parsedMap instanceof HashMap) { + MapT tmpMapT = MapT.createFromMap((HashMap)parsedMap); + functionManager.getHCALparameterSet().put(new FunctionManagerParameter>(parameterName, tmpMapT)); } else { - //Parse all parameters if no PartitionName is specified - if(!iElement.hasAttribute("Partition") ){ - logger.info("[HCAL "+functionManager.FMname+" ] parseMasterSnippet: parsing TagName = "+ iTagName +" with no partition attribute"); - } - else{ - logger.info("[HCAL "+functionManager.FMname+" ] parseMasterSnippet: parsing TagName = "+ iTagName +" with partition= "+PartitionName); - } - NodeList iNodeList = masterSnippetElement.getElementsByTagName( iTagName ); - SetHCALParameterFromTagName( iTagName , iNodeList, CfgCVSBasePath); + String errMessage = "[HCAL " + functionManager.FMname + "] parseMasterSnippet: parsed map failed instanceof HashMap. Parsed result = " + parsedMap; + throw new UserActionException(errMessage); } + break; + } + + default: + { + String errMessage="[David log HCAL " + functionManager.FMname + "] Error in master snippet parsing: for parameter " + parameterName + ", parameter type " + parameterType + " is not supported."; + throw new UserActionException(errMessage); } } } - } - catch ( DOMException | ParserConfigurationException | SAXException | IOException e) { - String errMessage = "[HCAL " + functionManager.FMname + "]: Got a error when parsing masterSnippet:: "; + } + + // Print test parameters + //if (functionManager.getHCALparameterSet().contains("TEST_VECTORT_STRINGT")) { + // logger.info("[HCAL " + functionManager.FMname + "] Printing test parameter TEST_VECTORT_STRINGT: " + functionManager.getHCALparameterSet().get("TEST_VECTORT_STRINGT").getValue()); + //} + //if (functionManager.getHCALparameterSet().contains("TEST_VECTORT_INTEGERT")) { + // logger.info("[HCAL " + functionManager.FMname + "] Printing test parameter TEST_VECTORT_INTEGERT: " + //functionManager.getHCALparameterSet().get("TEST_VECTORT_INTEGERT").getValue()); + //} + //if (functionManager.getHCALparameterSet().contains("TEST_MAPT_STRINGT")) { + // logger.info("[HCAL " + functionManager.FMname + "] Printing test parameter TEST_MAPT_STRINGT: " + //functionManager.getHCALparameterSet().get("TEST_MAPT_STRINGT").getValue()); + //} + //if (functionManager.getHCALparameterSet().contains("TEST_MAPT_INTEGERT")) { + // logger.info("[HCAL " + functionManager.FMname + "] Printing test parameter TEST_MAPT_INTEGERT: " + //functionManager.getHCALparameterSet().get("TEST_MAPT_INTEGERT").getValue()); + //} + + } catch ( DOMException | ParserConfigurationException | SAXException | IOException e) { + String errMessage="[HCAL " + functionManager.FMname + "]: Got an error when parsing masterSnippet" ; functionManager.goToError(errMessage,e); throw new UserActionException(e.getMessage()); } @@ -752,12 +922,6 @@ public void SetHCALParameterFromTagName(String TagName, NodeList NodeListOfTagNa String ControlSequence = getIncludeFiles( NodeListOfTagName, CfgCVSBasePath ,TagName ); functionManager.getHCALparameterSet().put(new FunctionManagerParameter(HCALParameter ,new StringT(ControlSequence))); } - if(TagName.equals("AlarmerURL")){ - functionManager.alarmerURL = getTagTextContent(NodeListOfTagName, TagName ); - } - if(TagName.equals("AlarmerStatus")) { - functionManager.alarmerPartition = getTagAttribute(NodeListOfTagName,TagName,"partition" ); - } if(TagName.equals("FMSettings")){ // Place holder to trying to set NumberOfEvents from Mastersnippet String StringNumberOfEvents = getTagAttribute(NodeListOfTagName, TagName,"NumberOfEvents"); @@ -797,16 +961,11 @@ public void SetHCALParameterFromTagName(String TagName, NodeList NodeListOfTagNa functionManager.getHCALparameterSet().put(new FunctionManagerParameter("FED_ENABLE_MASK",new StringT(tmpFedEnableMask))); } } - if(TagName.equals("DQM_TASK")){ - String dqmtask = getTagTextContent( NodeListOfTagName, TagName); - functionManager.getHCALparameterSet().put(new FunctionManagerParameter("DQM_TASK",new StringT(dqmtask))); - } } catch (UserActionException e) { // Warn when found more than one tag name in mastersnippet functionManager.goToError(e.getMessage()); } } - public boolean hasDefaultValue(String pam, String def_value){ String present_value = ((StringT)functionManager.getHCALparameterSet().get(pam).getValue()).getString(); //logger.info("[Martin log HCAL "+functionManager.FMname+"] the present value of "+pam+" is "+present_value);