]>
Commit | Line | Data |
---|---|---|
c5d00b61 | 1 | |
2 | void mergeByComponent(TString component, | |
3 | const Char_t* fileList="calib.list", | |
4 | const Char_t* apath=0, | |
5 | const Char_t* apattern=0, | |
6 | Int_t fileDownloadTimeOut=10, | |
7 | const Char_t* localFileList="calib.list", | |
8 | const Char_t* mergedFileName="CalibObjects.root" ) | |
9 | { | |
10 | // merging procedure | |
11 | // component can be COPY, MAKEALIENLIST, component name or ALL | |
12 | // ALL will merge the full file | |
13 | // selecting components will only merge the selected top level | |
14 | // objects in the file | |
15 | // COPY only copies the the alien files from fileList then | |
16 | // saves a list of local downloaded files in localFileList. | |
17 | // MAKEALIENLIST produces a list of files on alien, uses root | |
18 | // to connect in case alien_xx utilities are not available | |
19 | // liek on the alien nodes | |
20 | /* load libs */ | |
21 | printf("Executing MergeByComponent.C\n"); | |
22 | gROOT->Macro("$ALICE_ROOT/PWGPP/CalibMacros/CPass1/LoadLibraries.C"); | |
23 | TH1::AddDirectory(0); | |
24 | ||
25 | Int_t fileDownloadTimeOut=10; | |
26 | ||
27 | /* copy only */ | |
28 | if (component == "COPY") { | |
29 | if (!apath || ! apattern){ | |
30 | printf("Alien find path or pattern not specified"); | |
31 | exit(1); | |
32 | } | |
33 | CopyCPass(fileList, localFileList, fileDownloadTimeOut); | |
34 | return; | |
35 | } | |
36 | /* make file list only */ | |
37 | if (component == "MAKEALIENLIST") { | |
38 | if (!apath || ! apattern){ | |
39 | printf("Alien find path or pattern not specified"); | |
40 | exit(1); | |
41 | } | |
42 | MakeFileList(apath, apattern, fileList); | |
43 | return; | |
44 | } | |
45 | ||
46 | /* merge component */ | |
47 | MergeCPass(fileList, component, mergedFileName); | |
48 | } | |
49 | ||
50 | //___________________________________________________________________ | |
51 | ||
52 | void MergeCPass(const Char_t *list, TString component, TString outputFileName="CalibObjects.root") | |
53 | { | |
54 | AliFileMerger merger; | |
55 | /* select what to merge */ | |
56 | if (component == "ALL") | |
57 | merger.AddReject("esdFriend"); | |
58 | else | |
59 | merger.AddAccept(component.Data()); | |
60 | /* merge */ | |
61 | merger.IterTXT(list, outputFileName.Data(), kFALSE); | |
62 | /* notify */ | |
63 | gSystem->Exec(Form("touch %s_merge_done", component.Data())); | |
64 | return; | |
65 | } | |
66 | ||
67 | //___________________________________________________________________ | |
68 | void MakeFileList(const char *searchdir, const char *pattern, const char* outputFileName="calib.list", Int_t timeOut=10) | |
69 | { | |
70 | gSystem->Setenv("XRDCLIENTMAXWAIT",Form("%d",timeOut)); | |
71 | gEnv->SetValue("XNet.RequestTimeout", timeOut); | |
72 | gEnv->SetValue("XNet.ConnectTimeout", timeOut); | |
73 | gEnv->SetValue("XNet.TransactionTimeout", timeOut); | |
74 | TFile::SetOpenTimeout(timeOut); | |
75 | ||
76 | TGrid::Connect("alien"); | |
77 | ||
78 | TString command; | |
79 | command = Form("find %s/ %s", searchdir, pattern); | |
80 | cerr<<"command: "<<command<<endl; | |
81 | TGridResult *res = gGrid->Command(command); | |
82 | if (!res) return; | |
83 | TIter nextmap(res); | |
84 | TMap *map = 0; | |
85 | ||
86 | ofstream outputFile; | |
87 | outputFile.open(Form(outputFileName)); | |
88 | ||
89 | while((map=(TMap*)nextmap())) | |
90 | { | |
91 | TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("turl")); | |
92 | if (!objs || !objs->GetString().Length()) | |
93 | { | |
94 | delete res; | |
95 | break; | |
96 | } | |
97 | ||
98 | TString src=Form("%s",objs->GetString().Data()); | |
99 | outputFile << src.Data()<< endl; | |
100 | } | |
101 | outputFile.close(); | |
102 | return; | |
103 | } | |
104 | ||
105 | //___________________________________________________________________ | |
106 | void CopyCPass(const char* alienFileList="alien.list", const char* outputFileList="local.list", Int_t timeOut=10) | |
107 | { | |
108 | //copy all the alien files to local | |
109 | gSystem->Setenv("XRDCLIENTMAXWAIT",Form("%d",timeOut)); | |
110 | gEnv->SetValue("XNet.RequestTimeout", timeOut); | |
111 | gEnv->SetValue("XNet.ConnectTimeout", timeOut); | |
112 | gEnv->SetValue("XNet.TransactionTimeout", timeOut); | |
113 | TFile::SetOpenTimeout(timeOut); | |
114 | ||
115 | TGrid::Connect("alien"); | |
116 | ||
117 | ifstream inputFile; | |
118 | inputFile.open(alienFileList); | |
119 | ofstream outputFile; | |
120 | outputFile.open(Form(outputFileList)); | |
121 | ||
122 | if (!inputFile.is_open()) | |
123 | { | |
124 | printf("input file %s not found! exiting...\n",alienFileList); | |
125 | exit(1); | |
126 | } | |
127 | ||
128 | Int_t counter=0; | |
129 | while( inputFile.good()) | |
130 | { | |
131 | TString src(""); | |
132 | src.ReadLine(inputFile); | |
133 | if (src.IsNull()) continue; | |
134 | TString dst=src; | |
135 | dst.ReplaceAll("alien:///",""); | |
136 | dst.ReplaceAll("/","_"); | |
137 | Bool_t result = TFile::Cp(src.Data(),dst.Data(),kTRUE); | |
138 | AliSysInfo::AddStamp(dst.Data(),counter, result); | |
139 | if (result) | |
140 | { | |
141 | outputFile << dst.Data()<< endl; | |
142 | counter++; | |
143 | } | |
144 | } | |
145 | cout<<counter<<" files copied!"<<endl; | |
146 | ||
147 | inputFile.close(); | |
148 | outputFile.close(); | |
149 | gSystem->Exec("touch copy_done"); | |
150 | } | |
151 |