ROOT logo

class AliAnalysisGrid;

//______________________________________________________________________________
void runFPexample(
         const char* runtype = "grid", // local, proof or grid
         const bool useRealData = true, // run the proof with data or MC
         const char *gridMode = "full", // Set the run mode (can be "full", "test", "offline", "submit" or "terminate"). Full & Test work for proof
         const char *taskname = "give_task_name_for_grid_analysis", // the unique name of our task *must be a valid c identifier*
         const Int_t gridRun = -1, // the run to analyse *must be set for grid mode*
         const char *gridDirData = "/alice/data/2010/LHC10d", // the location of the data for grid analysis
         const char *gridDirMC = "/alice/sim/LHC10f6a", // the location of the MC for grid analysis
         const Long64_t proofNentries = 2000000, // for local and proof mode, ignored in grid mode. Set to 1234567890 for all events.
         const Long64_t proofFirstEntry = 0, // for local and proof mode, ignored in grid mode
         )
{
    // check run type
    if(runtype != "local" && runtype != "proof" && runtype != "grid"){
        Printf("\n\tIncorrect run option, check first argument of run macro");
        Printf("\tint runtype = local, proof or grid\n");
        return;
    }
    Printf("%s analysis chosen", runtype);

    const bool bMCtruth = !useRealData;
    bool bMCphyssel = false;

    const char *proofRealDataSet = "/default/kimb/LHC10d_000126405";
    const char *proofMCDataSet = "/alice/sim/LHC11b1a_000118558";

    char *proofdataset;
    if (useRealData) {
      proofdataset = proofRealDataSet;
      bMCphyssel = false;
      Printf("Using REAL DATA (TM) for analysis");
    } else {
      proofdataset = proofMCDataSet;
      bMCphyssel = true;
      Printf("Using MC for analysis");
    }
    const char *proofcluster = "alice-caf.cern.ch"; // which proof cluster to use in proof mode

    // load libraries
    gSystem->Load("libCore.so");
    gSystem->Load("libGeom.so");
    gSystem->Load("libVMC.so");
    gSystem->Load("libPhysics.so");
    gSystem->Load("libTree.so");
    gSystem->Load("libSTEERBase.so");
    gSystem->Load("libESD.so");
    gSystem->Load("libAOD.so");
    gSystem->Load("libANALYSIS.so");
    gSystem->Load("libANALYSISalice.so");

    // add aliroot indlude path
    gROOT->ProcessLine(TString::Format(".include %s/include", gSystem->ExpandPathName("$ALICE_ROOT")));
    gROOT->SetStyle("Plain");

    // analysis manager
    AliAnalysisManager* mgr = new AliAnalysisManager(taskname);

    // create the alien handler and attach it to the manager
    AliAnalysisAlien *plugin = new AliAnalysisAlien();
    mgr->SetGridHandler(plugin);

    AliVEventHandler* esdH = new AliESDInputHandler();
    mgr->SetInputEventHandler(esdH);

    // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
    plugin->SetRunMode(gridMode);

    gROOT->LoadMacro("AddTaskFPexample.C");
    AddTaskFPexample(mgr, plugin, runtype, useRealData, taskname, gridRun);

    // Define alien work directory where all files will be copied. Relative to alien $HOME.
    plugin->SetGridWorkingDir(TString::Format("%s/%d/%s", taskname, gridRun, useRealData ? "data" : "sim").Data());

    // Declare alien output directory. Relative to working directory.
    plugin->SetGridOutputDir("output");

    // Declare the analysis source files names separated by blancs. To be compiled runtime
    // using ACLiC on the worker nodes.
    // the upload order matters on PROOF! if A.cxx depends on B.h then put B.cxx first (my experience)
    plugin->SetAnalysisSource("AliAnalysisTaskFirstPhysics.cxx AliAnalysisHistosVertex.cxx AliAnalysisTaskFPexample.cxx");

    // Declare all libraries (other than the default ones for the framework. These will be
    // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
    plugin->SetAdditionalLibs("AliAnalysisTaskFirstPhysics.h AliAnalysisTaskFirstPhysics.cxx AliAnalysisHistosVertex.h AliAnalysisHistosVertex.cxx AliAnalysisTaskFPexample.h AliAnalysisTaskFPexample.cxx");

    // Set versions of used packages
    plugin->SetAPIVersion("V1.1x");
    plugin->SetROOTVersion("v5-28-00c");
    plugin->SetAliROOTVersion("v4-21-22-AN");

    // Declare input data to be processed.

    // Method 1: Create automatically XML collections using alien 'find' command.
    // Define production directory LFN
    if (useRealData) {
      plugin->SetGridDataDir(gridDirData);
    } else {
      plugin->SetGridDataDir(gridDirMC);
    }

    // Set data search pattern
    if (useRealData) {
      plugin->SetDataPattern("*ESDs/pass2/*ESDs.root"); // CHECK LATEST PASS OF DATA SET IN ALIENSH
      plugin->SetRunPrefix("000");   // real data
    } else {
      plugin->SetDataPattern("*ESDs.root"); // THIS CHOOSES ALL PASSES
    }
    // ...then add run numbers to be considered
    plugin->AddRunNumber(gridRun);
    //plugin->SetNrunsPerMaster(1);
    plugin->SetOutputToRunNo();
    // comment out the next line when using the "terminate" option, unless
    // you want separate merged files for each run
    plugin->SetMergeViaJDL();

    // Method 2: Declare existing data files (raw collections, xml collections, root file)
    // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
    // XML collections added via this method can be combined with the first method if
    // the content is compatible (using or not tags)
    //   plugin->AddDataFile("tag.xml");
    //   plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");


    // Declare the output file names separated by blancs.
    // (can be like: file.root or file.root@ALICE::Niham::File)
    // To only save certain files, use SetDefaultOutputs(kFALSE), and then
    // SetOutputFiles("list.root other.filename") to choose which files to save
    plugin->SetDefaultOutputs(kFALSE);

    // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
    plugin->SetAnalysisMacro(TString::Format("%s_%d.C", taskname, gridRun).Data());

    // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
    if (useRealData) {
      plugin->SetSplitMaxInputFileNumber(100);
    } else {
      plugin->SetSplitMaxInputFileNumber(300);
    }

    // Optionally modify the executable name (default analysis.sh)
    plugin->SetExecutable(TString::Format("%s_%d.sh", taskname, gridRun).Data());

    // set number of test files to use in "test" mode
    plugin->SetNtestFiles(10);

    // Optionally resubmit threshold.
    plugin->SetMasterResubmitThreshold(90);

    // Optionally set time to live (default 30000 sec)
    plugin->SetTTL(30000);

    // Optionally set input format (default xml-single)
    plugin->SetInputFormat("xml-single");

    // Optionally modify the name of the generated JDL (default analysis.jdl)
    plugin->SetJDLName(TString::Format("%s_%d.jdl", taskname, gridRun).Data());

    // Optionally modify job price (default 1)
    plugin->SetPrice(1);

    // Optionally modify split mode (default 'se')
    plugin->SetSplitMode("se");

    // Proof cluster
    plugin->SetProofCluster(proofcluster);
    // Dataset to be used
    plugin->SetProofDataSet(proofdataset);
    // May need to reset proof. Supported modes: 0-no reset, 1-soft, 2-hard
    plugin->SetProofReset(0);
    // May limit number of workers
    plugin->SetNproofWorkers(0);
    // May limit the number of workers per slave
    // plugin->SetNproofWorkersPerSlave(1);
    // May use a specific version of root installed in proof
    plugin->SetRootVersionForProof("current");
    // May set the aliroot mode. Check http://aaf.cern.ch/node/83
    plugin->SetAliRootMode("default"); // Loads AF libs by default
    // May request ClearPackages (individual ClearPackage not supported)
    plugin->SetClearPackages(kFALSE);
    // Plugin test mode works only providing a file containing test file locations, used in "local" mode also
    plugin->SetFileForTestMode("files.txt"); // file should contain path name to a local directory containg *ESDs.root etc
    // Request connection to alien upon connection to grid
    plugin->SetProofConnectGrid(kFALSE);

    // mc event handler
    if (bMCtruth) {
        AliMCEventHandler* mchandler = new AliMCEventHandler();
        // Not reading track references
        mchandler->SetReadTR(kFALSE);
        mgr->SetMCtruthEventHandler(mchandler);
    }

    // === Physics Selection Task ===
    //
    // In SelectCollisionCandidate(), default is kMB, so the task UserExec()
    // function is only called for these events.
    // Options are:
    //    kMB             Minimum Bias trigger
    //    kMBNoTRD        Minimum bias trigger where the TRD is not read out
    //    kMUON           Muon trigger
    //    kHighMult       High-Multiplicity Trigger
    //    kUserDefined    For manually defined trigger selection
    //
    // Multiple options possible with the standard AND/OR operators && and ||
    // These all have the usual offline SPD or V0 selections performed.
    //
    // With a pointer to the physics selection object using physSelTask->GetPhysicsSelection(),
    // one can manually set the selected and background classes using:
    //    AddCollisionTriggerClass("+CINT1B-ABCE-NOPF-ALL")
    //    AddBGTriggerClass("+CINT1A-ABCE-NOPF-ALL");
    //
    // One can also specify multiple classes at once, or require a class to NOT
    // trigger, for e.g.
    //    AddBGTriggerClass("+CSMBA-ABCE-NOPF-ALL -CSMBB-ABCE-NOPF-ALL");
    //
    // NOTE that manually setting the physics selection overrides the standard
    // selection, so it must be done in completeness.
    //
    // ALTERNATIVELY, one can make the physics selection inside the task
    // UserExec().
    // For this case, comment out the task->SelectCol.... line,
    // and see AliBasicTask.cxx UserExec() function for details on this.

    gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
    AliPhysicsSelectionTask *physSelTask = AddTaskPhysicsSelection(bMCphyssel);
    if (!physSelTask) {
      Printf("no physSelTask");
      return;
    }
    //AliPhysicsSelection *physSel = physSelTask->GetPhysicsSelection();
    //physSel->AddCollisionTriggerClass("+CINT1B-ABCE-NOPF-ALL");// #3119 #769");

    // enable debug printouts
    mgr->SetDebugLevel(2);
    if (!mgr->InitAnalysis()) return;
    mgr->PrintStatus();

    // start analysis
    Printf("Starting Analysis....");
    mgr->StartAnalysis(runtype, proofNentries, proofFirstEntry);
}
 runFPexample.C:1
 runFPexample.C:2
 runFPexample.C:3
 runFPexample.C:4
 runFPexample.C:5
 runFPexample.C:6
 runFPexample.C:7
 runFPexample.C:8
 runFPexample.C:9
 runFPexample.C:10
 runFPexample.C:11
 runFPexample.C:12
 runFPexample.C:13
 runFPexample.C:14
 runFPexample.C:15
 runFPexample.C:16
 runFPexample.C:17
 runFPexample.C:18
 runFPexample.C:19
 runFPexample.C:20
 runFPexample.C:21
 runFPexample.C:22
 runFPexample.C:23
 runFPexample.C:24
 runFPexample.C:25
 runFPexample.C:26
 runFPexample.C:27
 runFPexample.C:28
 runFPexample.C:29
 runFPexample.C:30
 runFPexample.C:31
 runFPexample.C:32
 runFPexample.C:33
 runFPexample.C:34
 runFPexample.C:35
 runFPexample.C:36
 runFPexample.C:37
 runFPexample.C:38
 runFPexample.C:39
 runFPexample.C:40
 runFPexample.C:41
 runFPexample.C:42
 runFPexample.C:43
 runFPexample.C:44
 runFPexample.C:45
 runFPexample.C:46
 runFPexample.C:47
 runFPexample.C:48
 runFPexample.C:49
 runFPexample.C:50
 runFPexample.C:51
 runFPexample.C:52
 runFPexample.C:53
 runFPexample.C:54
 runFPexample.C:55
 runFPexample.C:56
 runFPexample.C:57
 runFPexample.C:58
 runFPexample.C:59
 runFPexample.C:60
 runFPexample.C:61
 runFPexample.C:62
 runFPexample.C:63
 runFPexample.C:64
 runFPexample.C:65
 runFPexample.C:66
 runFPexample.C:67
 runFPexample.C:68
 runFPexample.C:69
 runFPexample.C:70
 runFPexample.C:71
 runFPexample.C:72
 runFPexample.C:73
 runFPexample.C:74
 runFPexample.C:75
 runFPexample.C:76
 runFPexample.C:77
 runFPexample.C:78
 runFPexample.C:79
 runFPexample.C:80
 runFPexample.C:81
 runFPexample.C:82
 runFPexample.C:83
 runFPexample.C:84
 runFPexample.C:85
 runFPexample.C:86
 runFPexample.C:87
 runFPexample.C:88
 runFPexample.C:89
 runFPexample.C:90
 runFPexample.C:91
 runFPexample.C:92
 runFPexample.C:93
 runFPexample.C:94
 runFPexample.C:95
 runFPexample.C:96
 runFPexample.C:97
 runFPexample.C:98
 runFPexample.C:99
 runFPexample.C:100
 runFPexample.C:101
 runFPexample.C:102
 runFPexample.C:103
 runFPexample.C:104
 runFPexample.C:105
 runFPexample.C:106
 runFPexample.C:107
 runFPexample.C:108
 runFPexample.C:109
 runFPexample.C:110
 runFPexample.C:111
 runFPexample.C:112
 runFPexample.C:113
 runFPexample.C:114
 runFPexample.C:115
 runFPexample.C:116
 runFPexample.C:117
 runFPexample.C:118
 runFPexample.C:119
 runFPexample.C:120
 runFPexample.C:121
 runFPexample.C:122
 runFPexample.C:123
 runFPexample.C:124
 runFPexample.C:125
 runFPexample.C:126
 runFPexample.C:127
 runFPexample.C:128
 runFPexample.C:129
 runFPexample.C:130
 runFPexample.C:131
 runFPexample.C:132
 runFPexample.C:133
 runFPexample.C:134
 runFPexample.C:135
 runFPexample.C:136
 runFPexample.C:137
 runFPexample.C:138
 runFPexample.C:139
 runFPexample.C:140
 runFPexample.C:141
 runFPexample.C:142
 runFPexample.C:143
 runFPexample.C:144
 runFPexample.C:145
 runFPexample.C:146
 runFPexample.C:147
 runFPexample.C:148
 runFPexample.C:149
 runFPexample.C:150
 runFPexample.C:151
 runFPexample.C:152
 runFPexample.C:153
 runFPexample.C:154
 runFPexample.C:155
 runFPexample.C:156
 runFPexample.C:157
 runFPexample.C:158
 runFPexample.C:159
 runFPexample.C:160
 runFPexample.C:161
 runFPexample.C:162
 runFPexample.C:163
 runFPexample.C:164
 runFPexample.C:165
 runFPexample.C:166
 runFPexample.C:167
 runFPexample.C:168
 runFPexample.C:169
 runFPexample.C:170
 runFPexample.C:171
 runFPexample.C:172
 runFPexample.C:173
 runFPexample.C:174
 runFPexample.C:175
 runFPexample.C:176
 runFPexample.C:177
 runFPexample.C:178
 runFPexample.C:179
 runFPexample.C:180
 runFPexample.C:181
 runFPexample.C:182
 runFPexample.C:183
 runFPexample.C:184
 runFPexample.C:185
 runFPexample.C:186
 runFPexample.C:187
 runFPexample.C:188
 runFPexample.C:189
 runFPexample.C:190
 runFPexample.C:191
 runFPexample.C:192
 runFPexample.C:193
 runFPexample.C:194
 runFPexample.C:195
 runFPexample.C:196
 runFPexample.C:197
 runFPexample.C:198
 runFPexample.C:199
 runFPexample.C:200
 runFPexample.C:201
 runFPexample.C:202
 runFPexample.C:203
 runFPexample.C:204
 runFPexample.C:205
 runFPexample.C:206
 runFPexample.C:207
 runFPexample.C:208
 runFPexample.C:209
 runFPexample.C:210
 runFPexample.C:211
 runFPexample.C:212
 runFPexample.C:213
 runFPexample.C:214
 runFPexample.C:215
 runFPexample.C:216
 runFPexample.C:217
 runFPexample.C:218
 runFPexample.C:219
 runFPexample.C:220
 runFPexample.C:221
 runFPexample.C:222
 runFPexample.C:223
 runFPexample.C:224
 runFPexample.C:225
 runFPexample.C:226
 runFPexample.C:227
 runFPexample.C:228
 runFPexample.C:229
 runFPexample.C:230
 runFPexample.C:231
 runFPexample.C:232
 runFPexample.C:233
 runFPexample.C:234
 runFPexample.C:235
 runFPexample.C:236
 runFPexample.C:237
 runFPexample.C:238
 runFPexample.C:239
 runFPexample.C:240
 runFPexample.C:241
 runFPexample.C:242
 runFPexample.C:243
 runFPexample.C:244
 runFPexample.C:245
 runFPexample.C:246