<div id="variable-inheritance"> <span id="index-0"></span><span id="id1"></span> <div > <div >In the previous chapter, we saw how to define a <a href="/wiki/display/ECFLOW/Glossary#term-variable"><em >variable</em></a> for a <a href="/wiki/display/ECFLOW/Glossary#term-task"><em >task</em></a>.</div> <div >When all the tasks of the same <a href="/wiki/display/ECFLOW/Glossary#term-family"><em >family</em></a> share the same variable value,</div> <div >the value could be defined at the family level.</div> <div >This is termed <a href="/wiki/display/ECFLOW/Glossary#term-variable-inheritance"><em >variable inheritance</em></a></div> </div> <div ><pre># Definition of the suite test. suite test edit ECF_INCLUDE "$HOME/course" edit ECF_HOME "$HOME/course" family f1 edit SLEEP 20 task t1 task t2 endfamily endsuite</pre> </div> <p>Or in python:</p> <div ><div ><pre><span >#!/usr/bin/env python2.5</span> <span >import</span> <span >os</span> <span >import</span> <span >ecflow</span> <span >def</span> <span >create_family_f1</span><span >():</span> <span >f1</span> <span >=</span> <span >ecflow</span><span >.</span><span >Family</span><span >(</span><span >"f1"</span><span >)</span> <span >f1</span><span >.</span><span >add_variable</span><span >(</span><span >"SLEEP"</span><span >,</span><span >20</span><span >)</span> <span >f1</span><span >.</span><span >add_task</span><span >(</span><span >"t1"</span><span >)</span> <span >f1</span><span >.</span><span >add_task</span><span >(</span><span >"t2"</span><span >)</span> <span >return</span> <span >f1</span> <span >defs</span> <span >=</span> <span >ecflow</span><span >.</span><span >Defs</span><span >(</span><span >"test.def"</span><span >)</span> <span >suite</span> <span >=</span> <span >defs</span><span >.</span><span >add_suite</span><span >(</span><span >"test"</span><span >)</span> <span >suite</span><span >.</span><span >add_variable</span><span >(</span><span >"ECF_INCLUDE"</span><span >,</span><span >os</span><span >.</span><span >getenv</span><span >(</span><span >"HOME"</span><span >)</span> <span >+</span> <span >"/course"</span><span >)</span> <span >suite</span><span >.</span><span >add_variable</span><span >(</span><span >"ECF_HOME "</span><span >,</span><span >os</span><span >.</span><span >getenv</span><span >(</span><span >"HOME"</span><span >)</span> <span >+</span> <span >"/course"</span><span >)</span> <span >suite</span><span >.</span><span >add_family</span><span >(</span> <span >create_family_f1</span><span >()</span> <span >)</span> </pre></div> </div> <div > <div >The <a href="/wiki/display/ECFLOW/Glossary#term-variable"><em >variable</em></a> could have been defined at the level of the <a href="/wiki/display/ECFLOW/Glossary#term-suite"><em >suite</em></a>,</div> <div >achieving the same results. Variables are inherited from the parent node.</div> <div >If a variable is redefined lower in the tree, it is said to be overridden.</div> <div >In this case the new definition is the one being used.</div> <div >It is possible to override generated variables.</div> <div >This is not recommended and you should understand all the consequences</div> <div >if you decide to do so.</div> </div> <p>Let us have a quiz. Consider the following suite:</p> <div ><pre>suite test edit SLEEP 100 family f1 edit SLEEP 80 task t1 task t2 edit SLEEP 9 family g1 edit SLEEP 89 task x1 edit SLEEP 10 task x2 endfamily endfamily family f2 task t1 task t2 edit SLEEP 77 family g2 task x1 edit SLEEP 12 task x2 endfamily endfamily endsuite</pre> </div> <p>What is the value of the <a href="/wiki/display/ECFLOW/Glossary#term-variable"><em >variable</em></a> SLEEP for:</p> <blockquote> <div><table border="1" > <colgroup> <col width="70%" /> <col width="30%" /> </colgroup> <thead valign="bottom"> <tr><th ><a href="/wiki/display/ECFLOW/Glossary#term-node"><em >node</em></a></th> <th >SLEEP</th> </tr> </thead> <tbody valign="top"> <tr><td>test/f1/t1</td> <td>?</td> </tr> <tr><td>/test/f1/t2</td> <td>?</td> </tr> <tr><td>/test/f1/g1/x1</td> <td>?</td> </tr> <tr><td>/test/f1/g1/x2</td> <td>?</td> </tr> <tr><td>/test/f2/t1</td> <td>?</td> </tr> <tr><td>/test/f2/t2</td> <td>?</td> </tr> <tr><td>/test/f2/g2/x1</td> <td>?</td> </tr> <tr><td>/test/f2/g2/x2</td> <td>?</td> </tr> </tbody> </table> </div></blockquote> </div> |