]> Creatis software - clitk.git/blob - tests_dav/GateMergeManager.hh
copied gatemergemanager from gate-creatis
[clitk.git] / tests_dav / GateMergeManager.hh
1 /*----------------------
2    GATE version name: gate_v...
3
4    Copyright (C): OpenGATE Collaboration
5
6 This software is distributed under the terms
7 of the GNU Lesser General  Public Licence (LGPL)
8 See GATE/LICENSE.txt for further details
9 ----------------------*/
10
11
12 #ifndef GateMergeManager_h
13 #define GateMergeManager_h 1
14 #include <iostream>
15 #include <string>
16 #include <vector>
17 #include <TFile.h>
18 #include <TChain.h>
19 #include <cstdlib>
20
21 using namespace std;
22
23 class GateMergeManager
24 {
25 public:
26
27   GateMergeManager(bool fastMerge,int verboseLevel,bool forced,Long64_t maxRoot,string outDir){
28      m_verboseLevel = verboseLevel;
29      m_forced       =       forced;
30      m_maxRoot      =      maxRoot;
31      m_outDir       =       outDir;
32      m_CompLevel    =            1;
33      m_fastMerge    =    fastMerge;
34
35      //check if a .Gate directory can be found
36      if (!getenv("GC_DOT_GATE_DIR")) {
37         cout<<"Environment variable GC_DOT_GATE_DIR not set !"<<endl;
38         exit(1);
39      }
40      m_dir=getenv("GC_DOT_GATE_DIR");
41      if (m_dir.substr(m_dir.length()-1,m_dir.length())=="/") m_dir=m_dir+".Gate/";
42      else m_dir=m_dir+"/.Gate/";
43      ifstream dirstream(m_dir.c_str());
44      if (!dirstream) {
45         cout<<"Failed to open .Gate directory"<<endl;
46         exit(1);
47      }
48      dirstream.close();
49
50   };
51   ~GateMergeManager()
52   {
53    if (filearr) delete filearr;
54   }
55
56
57   void StartMerging(string splitfileName);
58   void ReadSplitFile(string splitfileName);
59   bool MergeTree(string name);
60   bool MergeGate(TChain* chain);
61   bool MergeSing(TChain* chain);
62   bool MergeCoin(TChain* chain);
63
64   // the cleanup after succesful merging
65   void StartCleaning(string splitfileName,bool test);
66
67   // the merging methods
68   void MergeRoot();
69
70 private:
71   void FastMergeRoot(); 
72   bool FastMergeGate(string name);
73   bool FastMergeSing(string name);
74   bool FastMergeCoin(string name); 
75   bool           m_forced;             // if to overwrite existing files
76   int      m_verboseLevel;  
77   TFile**         filearr;
78   Long64_t      m_maxRoot;             // maximum size of root output file
79   int         m_CompLevel;             // compression level for root output
80   string            m_dir;             // .Gate directory path 
81   string         m_outDir;             // where to save the output files
82   int            m_Nfiles;             // number of files to mergw
83   vector<int> m_lastEvents;            // latestevent from al files
84   vector<string> m_vRootFileNames;     // names of root files to merge
85   TFile*         m_RootTarget;         // root output file
86   string         m_RootTargetName;     // name of target i.e. root output file
87   bool           m_fastMerge;          // fast merge option, corrects the eventIDs locally
88 };
89
90
91 #endif