]>
Commit | Line | Data |
---|---|---|
8dda6345 | 1 | #include "TTree.h" |
2 | #include "TObjArray.h" | |
3 | #include "TObjString.h" | |
4 | #include "TString.h" | |
5 | #include "TGrid.h" | |
6 | #include "TLeaf.h" | |
7 | #include "TError.h" | |
8 | #include "TFile.h" | |
9 | ||
10 | void DisableBranches(TTree* tree) | |
11 | { | |
12 | TObjArray* list = tree->GetListOfLeaves(); | |
13 | TIter next(list); | |
14 | TLeaf* leaf; | |
15 | ||
16 | TObjArray branchesToKeep; | |
17 | branchesToKeep.SetOwner(kTRUE); | |
18 | ||
19 | branchesToKeep.Add(new TObjString("rawevent")); | |
20 | branchesToKeep.Add(new TObjString("MUON")); | |
21 | branchesToKeep.Add(new TObjString("Common")); | |
22 | branchesToKeep.Add(new TObjString("TRG")); | |
23 | branchesToKeep.Add(new TObjString("T0")); | |
24 | branchesToKeep.Add(new TObjString("VZERO")); | |
25 | branchesToKeep.Add(new TObjString("ZDC")); | |
26 | branchesToKeep.Add(new TObjString("ITSSPD")); | |
27 | ||
28 | TIter nit(&branchesToKeep); | |
29 | ||
30 | tree->SetBranchStatus("*",0); | |
31 | ||
32 | Bool_t on(kTRUE); | |
33 | ||
34 | while ( ( leaf = static_cast<TLeaf*>(next()) ) ) | |
35 | { | |
36 | TString name(leaf->GetName()); | |
37 | if (!name.BeginsWith("f") && name != "rawevent" ) | |
38 | { | |
39 | TObjString* str; | |
40 | ||
41 | nit.Reset(); | |
42 | ||
43 | on = kFALSE; | |
44 | ||
45 | while ( ( str = static_cast<TObjString*>(nit()) ) ) | |
46 | { | |
47 | if ( name.BeginsWith(str->String()) ) | |
48 | { | |
49 | on = kTRUE; | |
50 | } | |
51 | } | |
52 | } | |
53 | if ( on ) | |
54 | { | |
55 | leaf->GetBranch()->SetStatus(1); | |
56 | } | |
57 | } | |
58 | } | |
59 | ||
60 | int FILTER_RAWMUON(const char* from, const char* to) | |
61 | { | |
62 | TString sinputfile(from); | |
63 | ||
64 | if (sinputfile.BeginsWith("alien://")) | |
65 | { | |
66 | if (!gGrid) | |
67 | { | |
68 | TGrid::Connect("alien://"); | |
69 | } | |
70 | if (!gGrid) | |
71 | { | |
72 | Error("FILTER_RAWMUON","Cannot connect to Grid !"); | |
73 | return -1; | |
74 | } | |
75 | } | |
76 | ||
77 | TFile* rawFile = TFile::Open(from); | |
78 | ||
79 | TTree *rawTree=(TTree *)rawFile->Get("RAW"); | |
80 | if(!rawTree) | |
81 | { | |
82 | Error("FILTER_RAWMUON","Error getting RAW tree from file %s",from); | |
83 | return -2; | |
84 | } | |
85 | ||
86 | TString snewfile(to); | |
87 | ||
88 | DisableBranches(rawTree); | |
89 | ||
90 | TFile* newfile = new TFile(snewfile.Data(),"recreate"); | |
91 | ||
92 | TTree* newTree = rawTree->CloneTree(); | |
93 | ||
94 | newTree->Print(); | |
95 | ||
96 | newTree->AutoSave(); | |
97 | ||
98 | newfile->Close(); | |
99 | ||
100 | delete newfile; | |
101 | ||
102 | delete rawFile; | |
103 | ||
104 | return 0; | |
105 | } |