25 var ARTDAQConfigurationAPI = ARTDAQConfigurationAPI || {};
27 if (typeof ConfigurationAPI ==
'undefined')
28 alert(
'ERROR: ConfigurationAPI is undefined! Must include ConfigurationAPI.js before ARTDAQConfigurationAPI.js');
43 ARTDAQConfigurationAPI.NODE_TYPE_READER = 0;
44 ARTDAQConfigurationAPI.NODE_TYPE_BUILDER = 1;
45 ARTDAQConfigurationAPI.NODE_TYPE_LOGGER = 2;
46 ARTDAQConfigurationAPI.NODE_TYPE_DISPATCHER = 3;
47 ARTDAQConfigurationAPI.NODE_TYPE_MONITOR = 4;
48 ARTDAQConfigurationAPI.NODE_TYPE_ROUTER = 5;
49 ARTDAQConfigurationAPI.NODE_TYPE_SUPERVISOR = 6;
50 ARTDAQConfigurationAPI.NODE_TYPES = [
"reader",
"builder",
51 "logger",
"dispatcher",
"monitor",
"router",
"artdaqSupervisor"];
52 ARTDAQConfigurationAPI.NODE_SHORT_TYPE_NAMES = [
"Reader",
"Builder",
53 "Logger",
"Dispatcher",
"Monitor",
"Router",
"ARTDAQSupervisor"];
54 ARTDAQConfigurationAPI.NODE_FULL_TYPE_NAMES = [
"Board Reader",
"Event Builder",
55 "Data Logger",
"Dispatcher",
"Monitor",
"Routing Master",
"ARTDAQ Supervisor"];
56 ARTDAQConfigurationAPI.NODE_TYPE_ACRONYM = [
"BR",
"EB",
57 "DL",
"Di",
"Mo",
"RM",
"AS"];
58 ARTDAQConfigurationAPI.NODE_TYPE_BASE_TABLE = [
"ARTDAQBoardReaderTable",
"ARTDAQEventBuilderTable",
59 "ARTDAQDataLoggerTable",
"ARTDAQDispatcherTable",
60 "ARTDAQMonitorTable",
"ARTDAQRoutingMasterTable",
"ARTDAQSupervisorTable"];
61 ARTDAQConfigurationAPI.DAQ_PARAMETER_TABLE =
"ARTDAQDaqParameterTable";
62 ARTDAQConfigurationAPI.DAQ_METRIC_TABLE =
"ARTDAQMetricTable";
64 ARTDAQConfigurationAPI.NULL_SUBSYSTEM =
"nullDestinationSubsystem";
75 ARTDAQConfigurationAPI.getTypeIndex =
function(typeName)
77 Debug.log(
"getTypeIndex " + typeName);
78 t = typeName == ARTDAQConfigurationAPI.NODE_TYPES[ARTDAQConfigurationAPI.NODE_TYPE_READER] ? ARTDAQConfigurationAPI.NODE_TYPE_READER:
79 (typeName == ARTDAQConfigurationAPI.NODE_TYPES[ARTDAQConfigurationAPI.NODE_TYPE_BUILDER] ? ARTDAQConfigurationAPI.NODE_TYPE_BUILDER:
80 (typeName == ARTDAQConfigurationAPI.NODE_TYPES[ARTDAQConfigurationAPI.NODE_TYPE_LOGGER] ? ARTDAQConfigurationAPI.NODE_TYPE_LOGGER:
81 (typeName == ARTDAQConfigurationAPI.NODE_TYPES[ARTDAQConfigurationAPI.NODE_TYPE_DISPATCHER] ? ARTDAQConfigurationAPI.NODE_TYPE_DISPATCHER:
82 (typeName == ARTDAQConfigurationAPI.NODE_TYPES[ARTDAQConfigurationAPI.NODE_TYPE_ROUTER] ? ARTDAQConfigurationAPI.NODE_TYPE_ROUTER:
83 (typeName == ARTDAQConfigurationAPI.NODE_TYPES[ARTDAQConfigurationAPI.NODE_TYPE_SUPERVISOR] ? ARTDAQConfigurationAPI.NODE_TYPE_SUPERVISOR:
84 (typeName == ARTDAQConfigurationAPI.NODE_TYPES[ARTDAQConfigurationAPI.NODE_TYPE_MONITOR] ? ARTDAQConfigurationAPI.NODE_TYPE_MONITOR:-1))))));
88 Debug.log(
"Illegal type name " + typeName +
89 ". Tell admins how you got here!", Debug.HIGH_PRIORITY);
97 ARTDAQConfigurationAPI.getTypeName =
function(typeIndex)
101 if(ARTDAQConfigurationAPI.NODE_TYPES[typeIndex] === undefined)
103 Debug.log(
"Illegal type index " + typeIndex +
104 ". Tell admins how you got here!", Debug.HIGH_PRIORITY);
107 return ARTDAQConfigurationAPI.NODE_TYPES[typeIndex];
112 ARTDAQConfigurationAPI.getShortTypeName =
function(typeIndex)
116 if(ARTDAQConfigurationAPI.NODE_SHORT_TYPE_NAMES[typeIndex] === undefined)
118 Debug.log(
"Illegal type index " + typeIndex +
119 ". Tell admins how you got here!", Debug.HIGH_PRIORITY);
122 return ARTDAQConfigurationAPI.NODE_SHORT_TYPE_NAMES[typeIndex];
127 ARTDAQConfigurationAPI.getFullTypeName =
function(typeIndex)
131 if(ARTDAQConfigurationAPI.NODE_FULL_TYPE_NAMES[typeIndex] === undefined)
133 Debug.log(
"Illegal type index " + typeIndex +
134 ". Tell admins how you got here!", Debug.HIGH_PRIORITY);
137 return ARTDAQConfigurationAPI.NODE_FULL_TYPE_NAMES[typeIndex];
157 ARTDAQConfigurationAPI.getArtdaqNodes =
function(responseHandler,
160 var modifiedTablesListStr =
"";
161 for(var i=0;modifiedTables && i<modifiedTables.length;++i)
163 if(i) modifiedTablesListStr +=
",";
164 modifiedTablesListStr += modifiedTables[i].tableName +
"," +
165 modifiedTables[i].tableVersion;
169 DesktopContent.XMLHttpRequest(
"Request?RequestType=getArtdaqNodes",
170 "modifiedTables=" + modifiedTablesListStr,
173 var errArr = DesktopContent.getXMLRequestErrors(req);
175 for(var i=0;i<errArr.length;++i)
177 errStr += (i?
"\n\n":
"") + errArr[i];
178 Debug.log(
"Error: " + errArr[i], Debug.HIGH_PRIORITY);
181 responseHandler(localExtractActiveArtdaqNodes(req));
189 function localExtractActiveArtdaqNodes(req)
191 Debug.log(
"localExtractActiveArtdaqNodes");
231 var types = ARTDAQConfigurationAPI.NODE_TYPES;
237 retObj.nodeCount = 0;
239 var artdaqSupervisor = DesktopContent.getXMLNode(
241 types[ARTDAQConfigurationAPI.NODE_TYPE_SUPERVISOR]);
247 for(i=0;i<types.length;++i)
249 Debug.log(
"Extracting " + types[i]);
251 retObj[types[i]] = {};
253 if(i == ARTDAQConfigurationAPI.NODE_TYPE_SUPERVISOR)
259 var artdaqSupervisorName = artdaqSupervisor.getAttribute(
'value');
261 retObj[types[i]][artdaqSupervisorName] = {
262 "status" : DesktopContent.getXMLValue(artdaqSupervisor,
263 types[i] +
"-status") | 0,
264 "contextAddress" : DesktopContent.getXMLValue(artdaqSupervisor,
265 types[i] +
"-contextAddress"),
266 "contextPort" : DesktopContent.getXMLValue(artdaqSupervisor,
267 types[i] +
"-contextPort"),
272 var nodes = artdaqSupervisor.getElementsByTagName(
274 var statuses = artdaqSupervisor.getElementsByTagName(
275 types[i] +
"-status");
276 var hostnames = artdaqSupervisor.getElementsByTagName(
277 types[i] +
"-hostname");
278 var subsystemIds = artdaqSupervisor.getElementsByTagName(
279 types[i] +
"-subsystem");
282 for(j=0;j<nodes.length;++j)
284 var multiNodeString = nodes[j].getElementsByTagName(types[i] +
"-multinode");
285 var nodeFixedWidth = nodes[j].getElementsByTagName(types[i] +
"-nodefixedwidth");
286 var hostArrayString = nodes[j].getElementsByTagName(types[i] +
"-hostarray");
287 var hostFixedWidth = nodes[j].getElementsByTagName(types[i] +
"-hostfixedwidth");
289 console.log(
"parameters",multiNodeString,
290 nodeFixedWidth,hostArrayString,hostFixedWidth);
292 var nodeName = nodes[j].getAttribute(
'value');
293 retObj[types[i]][nodeName] =
295 "status": statuses[j].getAttribute(
'value') | 0,
296 "hostname": hostnames[j].getAttribute(
'value'),
297 "subsystemId": subsystemIds[j].getAttribute(
'value') | 0,
300 if(multiNodeString.length)
301 retObj[types[i]][nodeName].multiNodeString = multiNodeString[0].getAttribute(
'value');
304 if(nodeFixedWidth.length)
305 retObj[types[i]][nodeName].nodeFixedWidth = nodeFixedWidth[0].getAttribute(
'value') | 0;
308 if(hostArrayString.length)
309 retObj[types[i]][nodeName].hostArrayString = hostArrayString[0].getAttribute(
'value');
312 if(hostFixedWidth.length)
313 retObj[types[i]][nodeName].hostFixedWidth = hostFixedWidth[0].getAttribute(
'value') | 0;
317 Debug.log(
"Extracted " +
321 retObj.nodeCount += nodes.length;
326 retObj.subsystems = {};
327 var subsystems = artdaqSupervisor.getElementsByTagName(
"subsystem");
328 var subsystemIds = artdaqSupervisor.getElementsByTagName(
329 "subsystem" +
"-id");
330 var subsystemSourcesCount = artdaqSupervisor.getElementsByTagName(
331 "subsystem" +
"-sourcesCount");
332 var subsystemDestination = artdaqSupervisor.getElementsByTagName(
333 "subsystem" +
"-destination");
335 for(j=0;j<subsystems.length;++j)
337 retObj.subsystems[subsystemIds[j].getAttribute(
'value') | 0 ] =
339 "label": subsystems[j].getAttribute(
'value'),
340 "sourcesCount": subsystemSourcesCount[j].getAttribute(
'value'),
341 "destinationId": (subsystemDestination[j].getAttribute(
'value') | 0) ,
348 Debug.log(
"No artdaq Supervisor found (or there were more than one conflicting). You can manually setup one artdaq Supervisor in the Configuration Tree, " +
349 "or it will be created for you the first time you save your artdaq node configuration.", Debug.WARN_PRIORITY);
351 Debug.log(
"Total nodes extracted " +
354 if(retObj.nodeCount == 0)
355 Debug.log(
"Successful node extraction, but no artdaq nodes found!", Debug.WARN_PRIORITY);
360 Debug.log(
"Error extracting active artdaq nodes: " + e, Debug.HIGH_PRIORITY);
383 ARTDAQConfigurationAPI.saveArtdaqNodes =
function(nodesObject, subsystemsObject, responseHandler,
386 console.log(
"nodesObject",nodesObject);
387 console.log(
"subsystemsObject",subsystemsObject);
389 var modifiedTablesListStr =
"";
390 for(var i=0;modifiedTables && i<modifiedTables.length;++i)
392 if(i) modifiedTablesListStr +=
",";
393 modifiedTablesListStr += modifiedTables[i].tableName +
"," +
394 modifiedTables[i].tableVersion;
398 var subsystemString =
"";
400 for(var i in nodesObject)
402 if(i == ARTDAQConfigurationAPI.NODE_TYPES[ARTDAQConfigurationAPI.NODE_TYPE_SUPERVISOR])
405 nodeString += encodeURIComponent(i) +
":";
406 for(var j in nodesObject[i])
408 nodeString += encodeURIComponent(j) +
"=";
411 nodeString += encodeURIComponent(nodesObject[i][j].originalName === undefined?
"":nodesObject[i][j].originalName) +
",";
413 nodeString += (nodesObject[i][j].status?1:0) +
",";
414 nodeString += encodeURIComponent(nodesObject[i][j].hostname) +
",";
415 nodeString += encodeURIComponent(nodesObject[i][j].subsystemName) +
"";
418 if(nodesObject[i][j].nodeArrString)
419 nodeString +=
"," + encodeURIComponent(nodesObject[i][j].nodeArrString);
420 if(nodesObject[i][j].nodeNameFixedWidth)
421 nodeString +=
"," + encodeURIComponent(
"nnfw," + nodesObject[i][j].nodeNameFixedWidth);
422 if(nodesObject[i][j].hostnameArrString)
423 nodeString +=
"," + encodeURIComponent(nodesObject[i][j].hostnameArrString);
424 if(nodesObject[i][j].hostnameFixedWidth)
425 nodeString +=
"," + encodeURIComponent(
"hnfw," + nodesObject[i][j].hostnameFixedWidth);
431 for(var i in subsystemsObject)
433 subsystemString += encodeURIComponent(i) +
":";
434 subsystemString += encodeURIComponent(subsystemsObject[i].destinationName);
435 subsystemString +=
";";
438 console.log(
"nodeString",nodeString);
439 console.log(
"subsystemStr",subsystemString);
442 DesktopContent.XMLHttpRequest(
"Request?RequestType=saveArtdaqNodes",
443 "modifiedTables=" + modifiedTablesListStr +
444 "&nodeString=" + nodeString +
445 "&subsystemString=" + subsystemString,
448 console.log(
"response",req);
450 var errArr = DesktopContent.getXMLRequestErrors(req);
452 for(var i=0;i<errArr.length;++i)
454 errStr += (i?
"\n\n":
"") + errArr[i];
455 Debug.log(
"Error: " + errArr[i], Debug.HIGH_PRIORITY);
458 if(errArr.length)
return;
460 responseHandler(req);