// @(#)root/proof:$Id$
// Author: G. Ganis Mar 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_TQueryResultManager
#define ROOT_TQueryResultManager

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TQueryResultManager                                                  //
//                                                                      //
// This class manages the query-result area.                            //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TStopwatch
#include "TStopwatch.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif

class TList;
class TProof;
class TProofLockPath;
class TProofQueryResult;
class TQueryResult;
class TVirtualProofPlayer;

class TQueryResultManager : public TObject {

private:
   TString       fQueryDir;         //directory containing query results and status
   TString       fSessionTag;       //tag for the session
   TString       fSessionDir;       //directory containing session dependent files
   Int_t         fSeqNum;           //sequential number of last processed query
   Int_t         fDrawQueries;      //number of draw queries processed
   Int_t         fKeptQueries;      //number of queries fully in memory and in dir
   TList        *fQueries;          //list of TProofQueryResult objects
   TList        *fPreviousQueries;  //list of TProofQueryResult objects from previous sections
   TProofLockPath *fLock;           //dir locker
   FILE         *fLogFile;          //log file
   TStopwatch    fCompute;          //measures time spend processing a query on the master

   void          AddLogFile(TProofQueryResult *pq);

public:
   TQueryResultManager(const char *qdir, const char *stag, const char *sdir,
                       TProofLockPath *lck, FILE *logfile = 0);
   virtual ~TQueryResultManager();

   const char   *QueryDir() const { return fQueryDir.Data(); }
   Int_t         SeqNum() const { return fSeqNum; }
   Int_t         DrawQueries() const { return fDrawQueries; }
   Int_t         KeptQueries() const { return fKeptQueries; }
   TList        *Queries() const { return fQueries; }
   TList        *PreviousQueries() const { return fPreviousQueries; }

   void          IncrementSeqNum() { fSeqNum++; }
   void          IncrementDrawQueries() { fDrawQueries++; }

   Int_t         ApplyMaxQueries(Int_t mxq);
   Int_t         CleanupQueriesDir();
   Bool_t        FinalizeQuery(TProofQueryResult *pq,
                               TProof *proof, TVirtualProofPlayer *player);
   Float_t       GetCpuTime() { return fCompute.CpuTime(); }
   Float_t       GetRealTime() { return fCompute.RealTime(); }
   TProofQueryResult *LocateQuery(TString queryref, Int_t &qry, TString &qdir);
   void          RemoveQuery(TQueryResult *qr, Bool_t soft = kFALSE);
   void          RemoveQuery(const char *queryref, TList *otherlist = 0);
   void          ResetTime() { fCompute.Start(); }
   void          SaveQuery(TProofQueryResult *qr, const char *fout = 0);
   void          SaveQuery(TProofQueryResult *qr, Int_t mxq);

   Int_t         LockSession(const char *sessiontag, TProofLockPath **lck);
   Int_t         CleanupSession(const char *sessiontag);
   void          ScanPreviousQueries(const char *dir);

   ClassDef(TQueryResultManager,0)  //PROOF query result manager
};

#endif

 TQueryResultManager.h:1
 TQueryResultManager.h:2
 TQueryResultManager.h:3
 TQueryResultManager.h:4
 TQueryResultManager.h:5
 TQueryResultManager.h:6
 TQueryResultManager.h:7
 TQueryResultManager.h:8
 TQueryResultManager.h:9
 TQueryResultManager.h:10
 TQueryResultManager.h:11
 TQueryResultManager.h:12
 TQueryResultManager.h:13
 TQueryResultManager.h:14
 TQueryResultManager.h:15
 TQueryResultManager.h:16
 TQueryResultManager.h:17
 TQueryResultManager.h:18
 TQueryResultManager.h:19
 TQueryResultManager.h:20
 TQueryResultManager.h:21
 TQueryResultManager.h:22
 TQueryResultManager.h:23
 TQueryResultManager.h:24
 TQueryResultManager.h:25
 TQueryResultManager.h:26
 TQueryResultManager.h:27
 TQueryResultManager.h:28
 TQueryResultManager.h:29
 TQueryResultManager.h:30
 TQueryResultManager.h:31
 TQueryResultManager.h:32
 TQueryResultManager.h:33
 TQueryResultManager.h:34
 TQueryResultManager.h:35
 TQueryResultManager.h:36
 TQueryResultManager.h:37
 TQueryResultManager.h:38
 TQueryResultManager.h:39
 TQueryResultManager.h:40
 TQueryResultManager.h:41
 TQueryResultManager.h:42
 TQueryResultManager.h:43
 TQueryResultManager.h:44
 TQueryResultManager.h:45
 TQueryResultManager.h:46
 TQueryResultManager.h:47
 TQueryResultManager.h:48
 TQueryResultManager.h:49
 TQueryResultManager.h:50
 TQueryResultManager.h:51
 TQueryResultManager.h:52
 TQueryResultManager.h:53
 TQueryResultManager.h:54
 TQueryResultManager.h:55
 TQueryResultManager.h:56
 TQueryResultManager.h:57
 TQueryResultManager.h:58
 TQueryResultManager.h:59
 TQueryResultManager.h:60
 TQueryResultManager.h:61
 TQueryResultManager.h:62
 TQueryResultManager.h:63
 TQueryResultManager.h:64
 TQueryResultManager.h:65
 TQueryResultManager.h:66
 TQueryResultManager.h:67
 TQueryResultManager.h:68
 TQueryResultManager.h:69
 TQueryResultManager.h:70
 TQueryResultManager.h:71
 TQueryResultManager.h:72
 TQueryResultManager.h:73
 TQueryResultManager.h:74
 TQueryResultManager.h:75
 TQueryResultManager.h:76
 TQueryResultManager.h:77
 TQueryResultManager.h:78
 TQueryResultManager.h:79
 TQueryResultManager.h:80
 TQueryResultManager.h:81
 TQueryResultManager.h:82
 TQueryResultManager.h:83
 TQueryResultManager.h:84
 TQueryResultManager.h:85
 TQueryResultManager.h:86
 TQueryResultManager.h:87
 TQueryResultManager.h:88
 TQueryResultManager.h:89
 TQueryResultManager.h:90
 TQueryResultManager.h:91
 TQueryResultManager.h:92
 TQueryResultManager.h:93
 TQueryResultManager.h:94