// @(#)root/proof:$Id$
// Author: G. Ganis March 2008

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TProofLite
#define ROOT_TProofLite


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TProofLite                                                           //
//                                                                      //
// This class starts a PROOF session on the local machine: no daemons,  //
// client and master merged, communications via UNIX-like sockets.      //
// By default the number of workers started is NumberOfCores+1; a       //
// different number can be forced on construction.                      //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TProof
#include "TProof.h"
#endif

class TDSet;
class TList;
class TQueryResultManager;
class TDataSetManager;
class TProofLockPath;
class TProofMgr;
class TProofQueryResult;
class TServerSocket;
class TSelector;
class TPMERegexp;

class TProofLite : public TProof {

friend class TProofPlayerLite;

private:
   Int_t    fNWorkers;    // Number of workers
   TString  fSandbox;     // PROOF sandbox root dir
   TString  fCacheDir;    // Directory containing cache of user files
   TString  fQueryDir;    // Directory containing query results and status
   TString  fDataSetDir;  // Directory containing info about known data sets
   TString  fSockPath;    // UNIX socket path for communication with workers
   TServerSocket *fServSock; // Server socket to accept call backs
   Bool_t   fForkStartup; // Startup N-1 workers forking the first worker

   TString  fVarExp;      // Internal variable to pass drawing options
   TString  fSelection;   // Internal variable to pass drawing options

   TProofLockPath *fCacheLock; // Cache dir locker
   TProofLockPath *fQueryLock; // Query dir locker
   TQueryResultManager *fQMgr; // Query-result manager

   TDataSetManager *fDataSetManager; // Dataset manager
   TDataSetManagerFile *fDataSetStgRepo; // Dataset manager for staging requests

   TPMERegexp *fReInvalid;  // Regular expression matching invalid dataset URIs

   static Int_t fgWrksMax; // Max number of workers

   TProofLite(const TProofLite &);        // not implemented
   void operator=(const TProofLite &);    // idem

   Int_t CleanupSandbox();
   Int_t CreateSandbox();
   void FindUniqueSlaves();
   void  NotifyStartUp(const char *action, Int_t done, Int_t tot);
   Int_t SetProofServEnv(const char *ord);
   Int_t InitDataSetManager();

   void  ResolveKeywords(TString &s, const char *ord, const char *logfile);

   void  SendInputDataFile();
   void  ShowDataDir(const char *dirname);

protected:
   TProofLite() : TProof() { } // For derived classes to use

   Int_t CreateSymLinks(TList *files);
   Int_t Init(const char *masterurl, const char *conffile,
               const char *confdir, Int_t loglevel,
               const char *alias = 0);
   TProofQueryResult *MakeQueryResult(Long64_t nent, const char *opt,
                                      Long64_t fst, TDSet *dset,
                                      const char *selec);
   void SetQueryRunning(TProofQueryResult *pq);
   Int_t SetupWorkers(Int_t opt = 0, TList *wrks = 0);
   Int_t CopyMacroToCache(const char *macro, Int_t headerRequired = 0,
                          TSelector **selector = 0, Int_t opt = 0);

public:
   TProofLite(const char *masterurl, const char *conffile = kPROOF_ConfFile,
              const char *confdir = kPROOF_ConfDir, Int_t loglevel = 0,
              const char *alias = 0, TProofMgr *mgr = 0);
   virtual ~TProofLite();

   void Print(Option_t *option="") const;

   Long64_t DrawSelect(TDSet *dset, const char *varexp,
                       const char *selection = "",
                       Option_t *option = "", Long64_t nentries = -1,
                       Long64_t firstentry = 0);
   Long64_t Process(TDSet *dset, const char *sel, Option_t *o = "",
                    Long64_t nent = -1, Long64_t fst = 0);
   Long64_t Process(TFileCollection *fc, const char *sel, Option_t *o = "",
                    Long64_t nent = -1, Long64_t fst = 0)
                    { return TProof::Process(fc, sel, o, nent, fst); }
   Long64_t Process(const char *dsname, const char *sel, Option_t *o = "",
                    Long64_t nent = -1, Long64_t fst = 0, TObject *enl = 0)
                    { return TProof::Process(dsname, sel, o, nent, fst, enl); }
   Long64_t Process(const char *sel, Long64_t nent, Option_t *o = "")
                    { return TProof::Process(sel, nent, o); }
   // Process via TSelector
   Long64_t Process(TDSet *dset, TSelector *sel, Option_t *o = "",
                    Long64_t nent = -1, Long64_t fst = 0)
                    { return TProof::Process(dset, sel, o, nent, fst); }
   Long64_t Process(TFileCollection *fc, TSelector *sel, Option_t *o = "",
                    Long64_t nent = -1, Long64_t fst = 0)
                    { return TProof::Process(fc, sel, o, nent, fst); }
   Long64_t Process(const char *dsname, TSelector *sel, Option_t *o = "",
                    Long64_t nent = -1, Long64_t fst = 0, TObject *enl = 0)
                    { return TProof::Process(dsname, sel, o, nent, fst, enl); }
   Long64_t Process(TSelector* sel, Long64_t nent, Option_t *o = "")
                    { return TProof::Process(sel, nent, o); }

   // Cache management
   void  ShowCache(Bool_t all = kFALSE);
   void  ClearCache(const char *file = 0);
   Int_t Load(const char *macro, Bool_t notOnClient = kFALSE, Bool_t uniqueOnly = kTRUE,
              TList *wrks = 0);

   // Data management
   void ShowData();

   // Query management
   TList *GetListOfQueries(Option_t *opt = "");
   Int_t Remove(const char *ref, Bool_t all);

   // Dataset handling
   Bool_t   RegisterDataSet(const char *dsName, TFileCollection *ds, const char *opt = "");
   Bool_t   ExistsDataSet(const char *uri);
   TMap    *GetDataSets(const char *uri = "", const char * = 0);
   void     ShowDataSets(const char *uri = "", const char * = 0);
   TFileCollection *GetDataSet(const char *uri, const char * = 0);
   Int_t    RemoveDataSet(const char *uri, const char * = 0);
   Bool_t   RequestStagingDataSet(const char *dataset);
   Bool_t   CancelStagingDataSet(const char *dataset);
   TFileCollection *GetStagingStatusDataSet(const char *dataset);
   Int_t    VerifyDataSet(const char *uri, const char * = 0);
   Int_t    SetDataSetTreeName( const char *dataset, const char *treename);
   void     ShowDataSetCache(const char *dataset = 0);
   void     ClearDataSetCache(const char *dataset = 0);

   // Browsing
   TTree *GetTreeHeader(TDSet *tdset);

   static Int_t GetNumberOfWorkers(const char *url = 0);

   ClassDef(TProofLite,0)  //PROOF-Lite control class
};

#endif
 TProofLite.h:1
 TProofLite.h:2
 TProofLite.h:3
 TProofLite.h:4
 TProofLite.h:5
 TProofLite.h:6
 TProofLite.h:7
 TProofLite.h:8
 TProofLite.h:9
 TProofLite.h:10
 TProofLite.h:11
 TProofLite.h:12
 TProofLite.h:13
 TProofLite.h:14
 TProofLite.h:15
 TProofLite.h:16
 TProofLite.h:17
 TProofLite.h:18
 TProofLite.h:19
 TProofLite.h:20
 TProofLite.h:21
 TProofLite.h:22
 TProofLite.h:23
 TProofLite.h:24
 TProofLite.h:25
 TProofLite.h:26
 TProofLite.h:27
 TProofLite.h:28
 TProofLite.h:29
 TProofLite.h:30
 TProofLite.h:31
 TProofLite.h:32
 TProofLite.h:33
 TProofLite.h:34
 TProofLite.h:35
 TProofLite.h:36
 TProofLite.h:37
 TProofLite.h:38
 TProofLite.h:39
 TProofLite.h:40
 TProofLite.h:41
 TProofLite.h:42
 TProofLite.h:43
 TProofLite.h:44
 TProofLite.h:45
 TProofLite.h:46
 TProofLite.h:47
 TProofLite.h:48
 TProofLite.h:49
 TProofLite.h:50
 TProofLite.h:51
 TProofLite.h:52
 TProofLite.h:53
 TProofLite.h:54
 TProofLite.h:55
 TProofLite.h:56
 TProofLite.h:57
 TProofLite.h:58
 TProofLite.h:59
 TProofLite.h:60
 TProofLite.h:61
 TProofLite.h:62
 TProofLite.h:63
 TProofLite.h:64
 TProofLite.h:65
 TProofLite.h:66
 TProofLite.h:67
 TProofLite.h:68
 TProofLite.h:69
 TProofLite.h:70
 TProofLite.h:71
 TProofLite.h:72
 TProofLite.h:73
 TProofLite.h:74
 TProofLite.h:75
 TProofLite.h:76
 TProofLite.h:77
 TProofLite.h:78
 TProofLite.h:79
 TProofLite.h:80
 TProofLite.h:81
 TProofLite.h:82
 TProofLite.h:83
 TProofLite.h:84
 TProofLite.h:85
 TProofLite.h:86
 TProofLite.h:87
 TProofLite.h:88
 TProofLite.h:89
 TProofLite.h:90
 TProofLite.h:91
 TProofLite.h:92
 TProofLite.h:93
 TProofLite.h:94
 TProofLite.h:95
 TProofLite.h:96
 TProofLite.h:97
 TProofLite.h:98
 TProofLite.h:99
 TProofLite.h:100
 TProofLite.h:101
 TProofLite.h:102
 TProofLite.h:103
 TProofLite.h:104
 TProofLite.h:105
 TProofLite.h:106
 TProofLite.h:107
 TProofLite.h:108
 TProofLite.h:109
 TProofLite.h:110
 TProofLite.h:111
 TProofLite.h:112
 TProofLite.h:113
 TProofLite.h:114
 TProofLite.h:115
 TProofLite.h:116
 TProofLite.h:117
 TProofLite.h:118
 TProofLite.h:119
 TProofLite.h:120
 TProofLite.h:121
 TProofLite.h:122
 TProofLite.h:123
 TProofLite.h:124
 TProofLite.h:125
 TProofLite.h:126
 TProofLite.h:127
 TProofLite.h:128
 TProofLite.h:129
 TProofLite.h:130
 TProofLite.h:131
 TProofLite.h:132
 TProofLite.h:133
 TProofLite.h:134
 TProofLite.h:135
 TProofLite.h:136
 TProofLite.h:137
 TProofLite.h:138
 TProofLite.h:139
 TProofLite.h:140
 TProofLite.h:141
 TProofLite.h:142
 TProofLite.h:143
 TProofLite.h:144
 TProofLite.h:145
 TProofLite.h:146
 TProofLite.h:147
 TProofLite.h:148
 TProofLite.h:149
 TProofLite.h:150
 TProofLite.h:151
 TProofLite.h:152
 TProofLite.h:153
 TProofLite.h:154
 TProofLite.h:155
 TProofLite.h:156
 TProofLite.h:157
 TProofLite.h:158
 TProofLite.h:159
 TProofLite.h:160
 TProofLite.h:161
 TProofLite.h:162
 TProofLite.h:163
 TProofLite.h:164
 TProofLite.h:165
 TProofLite.h:166
 TProofLite.h:167
 TProofLite.h:168
 TProofLite.h:169
 TProofLite.h:170
 TProofLite.h:171