13.7.1. Macro “relauncherFunctionFlowrateCInt.C

13.7.1.1. Objective

The goal of this macro is to show how to handle (in the most simple way) a C++-written function, compliant with the ROOT (CINT) format. This function has been presented, at least its equation (see Equation 4.1) and would be interfaced through the TCIntEval class in the Relauncher module (which means that we’ll use the function database from ROOT’s catalog, see Important modifications going from ROOT v5 to ROOT v6 for more explanations). As this class is usually considered not thread-safe, it can only be used with a TSequentialRun runner.

13.7.1.2. Macro

void flowrateModel(double *x, double *y)
{
    double drw = x[0], dr  = x[1];
    double dtu = x[2], dtl = x[3];
    double dhu = x[4], dhl = x[5];
    double dl  = x[6], dkw = x[7];

    double dnum = 2.0 * TMath::Pi() * dtu * ( dhu -dhl);
    double dlnronrw = TMath::Log( dr / drw);
    double dden = dlnronrw * ( 1.0 +  ( 2.0 * dl * dtu ) / ( dlnronrw * drw * drw * dkw) + dtu / dtl );

    y[0] = dnum / dden;
}

void relauncherFunctionFlowrateCInt(const string& figure="figure.png", const string& style="")
{
    // Create the TDataServer
    TDataServer *tds = new TDataServer("foo","test");
    tds->fileDataRead("flowrateUniformDesign.dat");

    // Get the attributes
    TAttribute *rw = tds->getAttribute("rw");
    TAttribute *r = tds->getAttribute("r");
    TAttribute *tu = tds->getAttribute("tu");
    TAttribute *tl = tds->getAttribute("tl");
    TAttribute *hu = tds->getAttribute("hu");
    TAttribute *hl = tds->getAttribute("hl");
    TAttribute *l = tds->getAttribute("l");
    TAttribute *kw = tds->getAttribute("kw");

    // Create the output attribute
    TAttribute *yhat = new TAttribute("yhat");

    // Constructing the code
    TCIntEval mycode("flowrateModel");    
    mycode.setInputs(8, rw, r, tu, tl, hu, hl, l, kw); // Adding the input attributes
    mycode.addOutput(yhat); // Adding the output attributes

    // Create the sequential runner
    TSequentialRun run(&mycode);
    run.startSlave(); //Start the master (necessary even for a sequential)
    if (run.onMaster())
    {
        TLauncher2 lanceur(tds, &run);

        // resolution
        lanceur.solverLoop();
        run.stopSlave(); // Stop the slaves (necessary even for a sequential)
    }

    // Draw the result
    TCanvas *can = new TCanvas("pouet","foo",1);
    tds->Draw("yhat:rw","","colZ");  
}

The first part of the macro is the definition of the flowrateModel function, already discussed throughout this documentation. The dataserver object is then created and filled using the database file and pointers to the corresponding input attributes are created, along with the new attribute for the output provided by the function. The following part is then specific to the Relauncher organisation: a TCIntEval object is created with the function as only argument. Both the input and output attributes are provided (here in a contracted way for input, but it could have been done one-by-one, as for output).

    // Constructing the code
    TCIntEval mycode("flowrateModel");    
    mycode.setInputs(8, rw, r, tu, tl, hu, hl, l, kw); // Adding the input attributes
    mycode.addOutput(yhat); // Adding the output attributes

The following part is the heart of the relauncher strategy: the assessor is provided to the chosen runner, which should always start the slaves (even in the case of a sequential one like here). On the main CPU, the master is created as well (with the dataserver and the runner) and the resolution is requested.

    // Create the sequential runner
    TSequentialRun run(&mycode);
    run.startSlave(); //Start the master (necessary even for a sequential)
    if (run.onMaster())
    {
        TLauncher2 lanceur(tds, &run);

        // resolution
        lanceur.solverLoop();
        run.stopSlave(); // Stop the slaves (necessary even for a sequential)
    }

Once this is done, the slaves are stopped and the results is displayed for cross-check in the following subsection.

13.7.1.3. Graph

../../_images/relauncherFunctionFlowrateCInt.png

Figure 13.46 Representation of the output as a function of the first input with a colZ option