00001 var partition = -1; 00002 var onmonStarted = false; 00003 var hpainter; 00004 var lastUpdate = 0; 00005 00006 function openCanvasWindow( pad,width,height ) { 00007 var thisWindow = window.open( "/artdaq-runcontrol/viewer.html?pad=" + pad + "&partition=" + partition,"ROOT Pad Inspector","width=" + width + ", height=" + height ); 00008 } 00009 00010 function openConfigWindow( config ) { 00011 var thisWindow = window.open( "/artdaq-configuration/ConfigurationEditor.html?configs=" + config ); 00012 } 00013 00014 function updateGUI() { 00015 if ( hpainter == null ) hpainter = new JSROOT.HierarchyPainter( 'root','wd1div' ); 00016 hpainter.SetDisplay( "grid2x1",'wd0div' ); 00017 00018 hpainter.OpenRootFile( "/artdaq-runcontrol/P" + partition + "/artdaqdemo_onmon.root",function () { 00019 hpainter.displayAll( ["wf0","wf1"] ); 00020 00021 $( "#wd0div_grid_0" ).click( function () { 00022 openCanvasWindow( "wf0",$( this ).width( ),$( this ).height( ) ); 00023 } ); 00024 $( "#wd0div_grid_1" ).click( function () { 00025 openCanvasWindow( "wf1",$( this ).width( ),$( this ).height( ) ); 00026 } ); 00027 } ); 00028 }; 00029 00030 function manageButtons( state,running,systemRunning ) { 00031 var shutdownActive = $( "#shutdown" ).hasClass( "active" ) ? " active " : ""; 00032 var startedActive = $( "#started" ).hasClass( "active" ) ? " active" : ""; 00033 var initializedActive = $( "#initialized" ).hasClass( "active" ) ? " active" : ""; 00034 var runStartedActive = $( "#runStarted" ).hasClass( "active" ) ? " active" : ""; 00035 var runPausedActive = $( "#runPaused" ).hasClass( "active" ) ? " active" : ""; 00036 00037 var color = running ? "yellow" : "green"; 00038 var sdColor = color; 00039 if ( !systemRunning ) { color = "red"; } 00040 00041 switch ( state ) { 00042 case "Shutdown": 00043 color = systemRunning ? "yellow" : "green"; 00044 $( "#shutdown" ).html( "<span>System Shutdown</span>" ).attr( "class","animated blue visible" ); 00045 $( "#started" ).html( "<span>Boot System</span>" ).attr( "class","animated visible " + color + startedActive ); 00046 $( "#initialized" ).html( "<span></span>" ).attr( "class","animated red hidden" ); 00047 $( "#runStarted" ).html( "<span></span>" ).attr( "class","animated red hidden" ); 00048 $( "#runPaused" ).html( "<span></span>" ).attr( "class","animated red hidden" ); 00049 break; 00050 case "Started": 00051 $( "#shutdown" ).html( "<span>Shutdown System</span>" ).attr( "class","animated visible " + sdColor + shutdownActive ); 00052 $( "#started" ).html( "<span>System Booted</span>" ).attr( "class","animated blue visible" ); 00053 $( "#initialized" ).html( "<span>Initialize System</span>" ).attr( "class","animated visible " + color + initializedActive ); 00054 $( "#runStarted" ).html( "<span></span>" ).attr( "class","animated red hidden" ); 00055 $( "#runPaused" ).html( "<span></span>" ).attr( "class","animated red hidden" ); 00056 break; 00057 case "Initialized": 00058 $( "#shutdown" ).html( "<span>Shutdown System</span>" ).attr( "class","animated visible " + sdColor + shutdownActive ); 00059 $( "#started" ).html( "<span></span>" ).attr( "class","animated red hidden" ); 00060 $( "#initialized" ).html( "<span>System Initialized</span>" ).attr( "class","animated blue visible" ); 00061 $( "#runStarted" ).html( "<span>Start Run</span>" ).attr( "class","animated visible " + color + runStartedActive ); 00062 $( "#runPaused" ).html( "<span></span>" ).attr( "class","animated red hidden" ); 00063 break; 00064 case "Running": 00065 $( "#shutdown" ).html( "<span></span>" ).attr( "class","animated red hidden" ); 00066 $( "#started" ).html( "<span></span>" ).attr( "class","animated red hidden" ); 00067 $( "#initialized" ).html( "<span>End Run</span>" ).attr( "class","animated visible " + color + initializedActive ); 00068 $( "#runStarted" ).html( "<span>Running</span>" ).attr( "class","animated blue visible" ); 00069 $( "#runPaused" ).html( "<span>Pause Run</span>" ).attr( "class","animated visible " + color + runPausedActive ); 00070 break; 00071 case "Paused": 00072 $( "#shutdown" ).html( "<span>Shutdown System</span>" ).attr( "class","animated visible " + sdColor + shutdownActive ); 00073 $( "#started" ).html( "<span></span>" ).attr( "class","animated red hidden" ); 00074 $( "#initialized" ).html( "<span>Reinitialize System</span>" ).attr( "class","animated visible " + color + initializedActive ); 00075 $( "#runStarted" ).html( "<span>Resume Run</span>" ).attr( "class","animated visible " + color + runStartedActive ); 00076 $( "#runPaused" ).html( "<span>Run Paused</span>" ).attr( "class","animated blue visible" ); 00077 break; 00078 } 00079 00080 $( ".green.animated" ).hover( function () { 00081 $( this ).addClass( "active" ); 00082 },function () { $( this ).removeClass( "active" ); } ); 00083 00084 } 00085 00086 function update( dataJSON ) { 00087 var data = $.parseJSON( dataJSON ); 00088 partition = data.partition; 00089 $( "#partition" ).val( data.partition ); 00090 manageButtons( data.state,data.commandRunning,data.systemRunning ); 00091 00092 $( "#configs" ).val( data.config ); 00093 00094 var out = $("#systemOut")[0]; 00095 var err = $("#systemErr")[0]; 00096 var outAtBottom = out.scrollTop + out.clientHeight >= out.scrollHeight - 10; 00097 var errAtBottom = err.scrollTop + err.clientHeight >= err.scrollHeight - 10; 00098 $( "#systemOut" ).val( data.systemOutputBuffer ); 00099 $( "#systemErr" ).val( data.systemErrorBuffer ); 00100 if(outAtBottom) { out.scrollTop = out.scrollHeight }; 00101 if(errAtBottom) { err.scrollTop = err.scrollHeight }; 00102 00103 out = $("#commOut")[0]; 00104 err = $("#commErr")[0]; 00105 outAtBottom = out.scrollTop + out.clientHeight >= out.scrollHeight - 10; 00106 errAtBottom = err.scrollTop + err.clientHeight >= err.scrollHeight - 10; 00107 $( "#commOut" ).val( data.commandOutputBuffer ); 00108 $( "#commErr" ).val( data.commandErrorBuffer ); 00109 if(outAtBottom) { out.scrollTop = out.scrollHeight }; 00110 if(errAtBottom) { err.scrollTop = err.scrollHeight }; 00111 00112 if ( data.WFPlotsUpdated && $( "#monitoringEnabled" ).is( ":checked" ) ) { 00113 var updateDate = data.WFPlotsUpdated; 00114 if ( updateDate > lastUpdate ) { 00115 updateGUI( ); 00116 lastUpdate = updateDate; 00117 } 00118 } else { 00119 hpainter = null; 00120 $( "#wd0div" ).html( "" ); 00121 } 00122 00123 if((!onmonStarted) && data.okToStartOnMon) 00124 { 00125 Onmon("#onmonDiv", partition, "artdaq-runcontrol"); 00126 onmonStarted = true; 00127 } 00128 } 00129 00130 00131 function shutdownSystem() { 00132 if ( $( "#shutdown" ).is( ".green" ) ) { 00133 AjaxPost( "/artdaq-runcontrol/Shutdown",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update ); 00134 } 00135 } 00136 00137 function startSystem() { 00138 if ( $( "#started" ).is( ".green" ) ) { 00139 AjaxPost( "/artdaq-runcontrol/Start",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update ); 00140 } 00141 } 00142 00143 function initSystem() { 00144 if ( $( "#initialized" ).is( ".green" ) ) { 00145 if ( $( "#started" ).is( ".blue" ) ) { 00146 var verbosity = $( "#verbosity" ).is( ":checked" ); 00147 AjaxPost( "/artdaq-runcontrol/Init",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update ); 00148 } 00149 else { 00150 AjaxPost( "/artdaq-runcontrol/End",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update ); 00151 var number = parseInt( $( "#runNumber" ).val( ) ); 00152 $( "#runNumber" ).val( number + 1 ); 00153 } 00154 } 00155 } 00156 00157 function startRun() { 00158 if ( $( "#runStarted" ).is( ".green" ) ) { 00159 if ( $( "#runPaused" ).is( ".blue" ) ) { 00160 AjaxPost( "/artdaq-runcontrol/Resume",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update ); 00161 } else { 00162 AjaxPost( "/artdaq-runcontrol/Run",{ partition: $( "#partition" ).val( ), runNumber: $( "#runNumber" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update ); 00163 } 00164 } 00165 } 00166 00167 function pauseRun() { 00168 if ( $( "#runPaused" ).is( ".green" ) ) { 00169 AjaxPost( "/artdaq-runcontrol/Pause",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update ); 00170 } 00171 } 00172 00173 function getConfigs() { 00174 $.get( "/artdaq-configuration/NamedConfigs",function ( result ) { 00175 $( "#config" ).html( result ); 00176 } ); 00177 } 00178 00179 $( document ).ready( function () { 00180 $( "#shutdown" ).click( function () { 00181 shutdownSystem( ); 00182 } ); 00183 $( "#started" ).click( function () { 00184 startSystem( ); 00185 } ); 00186 $( "#initialized" ).click( function () { 00187 initSystem( ); 00188 } ); 00189 $( "#runStarted" ).click( function () { 00190 startRun( ); 00191 } ); 00192 $( "#runPaused" ).click( function () { 00193 pauseRun( ); 00194 } ); 00195 $( "#monitoringEnabled" ).change( function () { 00196 if ( $( "#monitoringEnabled" ).is( ":checked" ) ) { 00197 updateGUI( ); 00198 } 00199 } ); 00200 00201 getConfigs( ); 00202 $( "#editConfig" ).click( function () { 00203 var config = $( "#config" ).find( ":selected" ).val( ); 00204 openConfigWindow( config ); 00205 } ); 00206 00207 $( "#reloadConfigs" ).click( function () { 00208 getConfigs( ); 00209 } ); 00210 00211 setInterval( function () { AjaxGet( "/artdaq-runcontrol/P" + $( "#partition" ).val( ),update ); },1000 ); 00212 JSROOT.AssertPrerequisites( '2d;io;',updateGUI ); 00213 } ); 00214