// @(#)root/net:$Id$
// Author: Philippe Canal October 2011.

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

#ifndef ROOT_TParallelMergingFile
#define ROOT_TParallelMergingFile


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TParallelMergingFile                                                 //
//                                                                      //
// Specialization of TMemFile to connect to a parallel file merger.     //
// Upon a call to UploadAndReset, the content already written to the    //
// file is upload to the server and the object implementing the function//
// ResetAfterMerge (like TTree) are reset.                              //
// The parallel file merger will then collate the information coming    //
// from this client and any other client in to the file described by    //
// the filename of this object.                                         //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TMemFile
#include "TMemFile.h"
#endif
#ifndef ROOT_TMessage
#include "TMessage.h"
#endif
#ifndef ROOT_TUrl
#include "TUrl.h"
#endif


class TSocket;
class TArrayC;

class TParallelMergingFile : public TMemFile
{
private:
   TSocket *fSocket;         // Socket to the parallel file merger server.
   TUrl     fServerLocation; // Url of the server.
   Int_t    fServerIdx;      // Index of this socket/file on the server.
   Int_t    fServerVersion;  // Protocol version used by the server.
   TArrayC *fClassSent;      // Record which StreamerInfo we already sent.
   TMessage fMessage;

public:
   TParallelMergingFile(const char *filename, Option_t *option = "", const char *ftitle = "", Int_t compress = 1);
   ~TParallelMergingFile();

   virtual void   Close(Option_t *option="");
           Bool_t UploadAndReset();
   virtual Int_t  Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0);
   virtual Int_t  Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0) const;
   virtual void   WriteStreamerInfo();

   ClassDef(TParallelMergingFile,2);  // TFile specialization that will semi-automatically upload its content to a merging server.
};

#endif // ROOT_TParallelMergingFile
 TParallelMergingFile.h:1
 TParallelMergingFile.h:2
 TParallelMergingFile.h:3
 TParallelMergingFile.h:4
 TParallelMergingFile.h:5
 TParallelMergingFile.h:6
 TParallelMergingFile.h:7
 TParallelMergingFile.h:8
 TParallelMergingFile.h:9
 TParallelMergingFile.h:10
 TParallelMergingFile.h:11
 TParallelMergingFile.h:12
 TParallelMergingFile.h:13
 TParallelMergingFile.h:14
 TParallelMergingFile.h:15
 TParallelMergingFile.h:16
 TParallelMergingFile.h:17
 TParallelMergingFile.h:18
 TParallelMergingFile.h:19
 TParallelMergingFile.h:20
 TParallelMergingFile.h:21
 TParallelMergingFile.h:22
 TParallelMergingFile.h:23
 TParallelMergingFile.h:24
 TParallelMergingFile.h:25
 TParallelMergingFile.h:26
 TParallelMergingFile.h:27
 TParallelMergingFile.h:28
 TParallelMergingFile.h:29
 TParallelMergingFile.h:30
 TParallelMergingFile.h:31
 TParallelMergingFile.h:32
 TParallelMergingFile.h:33
 TParallelMergingFile.h:34
 TParallelMergingFile.h:35
 TParallelMergingFile.h:36
 TParallelMergingFile.h:37
 TParallelMergingFile.h:38
 TParallelMergingFile.h:39
 TParallelMergingFile.h:40
 TParallelMergingFile.h:41
 TParallelMergingFile.h:42
 TParallelMergingFile.h:43
 TParallelMergingFile.h:44
 TParallelMergingFile.h:45
 TParallelMergingFile.h:46
 TParallelMergingFile.h:47
 TParallelMergingFile.h:48
 TParallelMergingFile.h:49
 TParallelMergingFile.h:50
 TParallelMergingFile.h:51
 TParallelMergingFile.h:52
 TParallelMergingFile.h:53
 TParallelMergingFile.h:54
 TParallelMergingFile.h:55
 TParallelMergingFile.h:56
 TParallelMergingFile.h:57
 TParallelMergingFile.h:58
 TParallelMergingFile.h:59
 TParallelMergingFile.h:60
 TParallelMergingFile.h:61
 TParallelMergingFile.h:62
 TParallelMergingFile.h:63
 TParallelMergingFile.h:64
 TParallelMergingFile.h:65
 TParallelMergingFile.h:66
 TParallelMergingFile.h:67