Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TProofOutputFile.h
Go to the documentation of this file.
1 // @(#)root/proof:$Id$
2 // Author: Long Tran-Thanh 14/09/07
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TProofOutputFile
13 #define ROOT_TProofOutputFile
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TProofOutputFile //
19 // //
20 // Small class to steer the merging of files produced on workers //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TNamed.h"
25 
26 class TCollection;
27 class TString;
28 class TList;
29 class TFile;
30 class TFileCollection;
31 class TFileMerger;
32 
33 class TProofOutputFile : public TNamed {
34 
35 friend class TProof;
36 friend class TProofPlayer;
37 friend class TProofPlayerRemote;
38 
39 public:
40  enum ERunType { kMerge = 1, // Type of run: merge or dataset creation
41  kDataset = 2};
42  enum ETypeOpt { kRemote = 1, // Merge from original copies
43  kLocal = 2, // Make local copies before merging
44  kCreate = 4, // Create dataset
45  kRegister = 8, // Register dataset
46  kOverwrite = 16, // Force dataset replacement during registration
47  kVerify = 32}; // Verify the registered dataset
48 
49 private:
50  TProofOutputFile(const TProofOutputFile&); // Not implemented
51  TProofOutputFile& operator=(const TProofOutputFile&); // Not implemented
52 
53  TString fDir; // name of the directory to be exported
54  TString fRawDir; // name of the local directory where to create the file
55  TString fFileName;
56  TString fOptionsAnchor; // options and anchor string including delimiters, e.g. "?myopts#myanchor"
57  TString fOutputFileName;
58  TString fWorkerOrdinal;
59  TString fLocalHost; // Host where the file was created
60  Bool_t fIsLocal; // kTRUE if the file is in the sandbox
61  Bool_t fMerged;
62  ERunType fRunType; // Type of run (see enum ERunType)
63  UInt_t fTypeOpt; // Option (see enum ETypeOpt)
64  Bool_t fMergeHistosOneGo; // If true merge histos in one go (argument to TFileMerger)
65 
66  TFileCollection *fDataSet; // Instance of the file collection in 'dataset' mode
67  TFileMerger *fMerger; // Instance of the file merger in 'merge' mode
68 
69  void Init(const char *path, const char *dsname);
70  void SetFileName(const char* name) { fFileName = name; }
71  void SetDir(const char* dir, Bool_t raw = kFALSE) { if (raw) { fRawDir = dir; } else { fDir = dir; } }
72  void SetMerged(Bool_t merged = kTRUE) { fMerged = merged; }
73  void SetWorkerOrdinal(const char* ordinal) { fWorkerOrdinal = ordinal; }
74 
75  void AddFile(TFileMerger *merger, const char *path);
76  void NotifyError(const char *errmsg);
77  void Unlink(const char *path);
78 
79 protected:
80 
81 public:
82  enum EStatusBits {
83  kOutputFileNameSet = BIT(16),
84  kRetrieve = BIT(17), // If set, the file is copied to the final destination via the client
85  kSwapFile = BIT(18) // Set when the represented file is the result of the automatic
86  // save-to-file functionality
87  };
88  TProofOutputFile() : fDir(), fRawDir(), fFileName(), fOptionsAnchor(), fOutputFileName(),
89  fWorkerOrdinal(), fLocalHost(), fIsLocal(kFALSE), fMerged(kFALSE),
90  fRunType(kMerge), fTypeOpt(kRemote), fMergeHistosOneGo(kFALSE),
91  fDataSet(0), fMerger(0) { }
92  TProofOutputFile(const char *path, const char *option = "M", const char *dsname = 0);
93  TProofOutputFile(const char *path, ERunType type, UInt_t opt = kRemote, const char *dsname = 0);
94  virtual ~TProofOutputFile();
95 
96  const char *GetDir(Bool_t raw = kFALSE) const { return (raw) ? fRawDir : fDir; }
97  TFileCollection *GetFileCollection();
98  TFileMerger *GetFileMerger(Bool_t local = kFALSE);
99  const char *GetFileName() const { return fFileName; }
100  const char *GetLocalHost() const { return fLocalHost; }
101  const char *GetOptionsAnchor() const { return fOptionsAnchor; }
102  const char *GetOutputFileName() const { return fOutputFileName; }
103  const char *GetWorkerOrdinal() const { return fWorkerOrdinal; }
104 
105  ERunType GetRunType() const { return fRunType; }
106  UInt_t GetTypeOpt() const { return fTypeOpt; }
107  Bool_t IsMerge() const { return (fRunType == kMerge) ? kTRUE : kFALSE; }
108  Bool_t IsMerged() const { return fMerged; }
109  Bool_t IsRegister() const { return ((fTypeOpt & kRegister) || (fTypeOpt & kVerify)) ? kTRUE : kFALSE; }
110 
111  Bool_t IsRetrieve() const { return (TestBit(TProofOutputFile::kRetrieve)) ? kTRUE : kFALSE; }
112  void SetRetrieve(Bool_t on = kTRUE) { if (on) { SetBit(TProofOutputFile::kRetrieve);
113  } else { ResetBit(TProofOutputFile::kRetrieve); }}
114 
115  Int_t AdoptFile(TFile *f); // Adopt a TFile already open
116  TFile* OpenFile(const char *opt); // Open a file with the specified name in fFileName1
117  Long64_t Merge(TCollection *list);
118  void Print(Option_t *option = "") const;
119  void SetOutputFileName(const char *name);
120  void ResetFileCollection() { fDataSet = 0; }
121 
122  static Int_t AssertDir(const char *dirpath);
123 
124  ClassDef(TProofOutputFile,5) // Wrapper class to steer the merging of files produced on workers
125 };
126 
127 #endif