2 void mergeByComponent(TString component,
3 const Char_t* fileList="calib.list",
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" )
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
21 printf("Executing mergeByComponent.C\n");
22 gROOT->Macro("$ALICE_ROOT/PWGPP/CalibMacros/CPass1/LoadLibraries.C");
25 Int_t fileDownloadTimeOut=10;
28 if (component == "COPY") {
29 if (!apath || ! apattern){
30 printf("Alien find path or pattern not specified");
33 CopyCPass(fileList, localFileList, fileDownloadTimeOut);
36 /* make file list only */
37 if (component == "MAKEALIENLIST") {
38 if (!apath || ! apattern){
39 printf("Alien find path or pattern not specified");
42 MakeFileList(apath, apattern, fileList);
47 MergeCPass(fileList, component, mergedFileName);
50 //___________________________________________________________________
52 void MergeCPass(const Char_t *list, TString component, TString outputFileName="CalibObjects.root")
54 //AliTPCcalibTimeGain::SetMergeEntriesCut(2000000);
55 //AliTPCcalibGainMult::SetMergeEntriesCut(2000000);
56 //AliTPCcalibAlign::SetMergeEntriesCut(10000000);
57 //AliTPCcalibTracks::SetMergeEntriesCut(10000000);
58 //AliTPCcalibTime::SetResHistoMergeCut(10000000);
60 /* select what to merge */
61 merger.SetNoTrees(kFALSE);
62 if (component == "ALL")
63 merger.AddReject("esdFriend");
65 merger.AddAccept(component.Data());
67 merger.IterTXT(list, outputFileName.Data(), kFALSE);
69 gSystem->Exec(Form("touch %s_merge_done", component.Data()));
73 //___________________________________________________________________
74 void MakeFileList(const char *searchdir, const char *pattern, const char* outputFileName="calib.list", Int_t timeOut=10)
76 gSystem->Setenv("XRDCLIENTMAXWAIT",Form("%d",timeOut));
77 gEnv->SetValue("XNet.RequestTimeout", timeOut);
78 gEnv->SetValue("XNet.ConnectTimeout", timeOut);
79 gEnv->SetValue("XNet.TransactionTimeout", timeOut);
80 TFile::SetOpenTimeout(timeOut);
82 TGrid::Connect("alien");
85 command = Form("find %s/ %s", searchdir, pattern);
86 cerr<<"command: "<<command<<endl;
87 TGridResult *res = gGrid->Command(command);
93 outputFile.open(Form(outputFileName));
95 while((map=(TMap*)nextmap()))
97 TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("turl"));
98 if (!objs || !objs->GetString().Length())
104 TString src=Form("%s",objs->GetString().Data());
105 outputFile << src.Data()<< endl;
111 //___________________________________________________________________
112 void CopyCPass(const char* alienFileList="alien.list", const char* outputFileList="local.list", Int_t timeOut=10)
114 //copy all the alien files to local
115 gSystem->Setenv("XRDCLIENTMAXWAIT",Form("%d",timeOut));
116 gEnv->SetValue("XNet.RequestTimeout", timeOut);
117 gEnv->SetValue("XNet.ConnectTimeout", timeOut);
118 gEnv->SetValue("XNet.TransactionTimeout", timeOut);
119 TFile::SetOpenTimeout(timeOut);
121 TGrid::Connect("alien");
124 inputFile.open(alienFileList);
126 outputFile.open(Form(outputFileList));
128 if (!inputFile.is_open())
130 printf("input file %s not found! exiting...\n",alienFileList);
135 while( inputFile.good())
138 src.ReadLine(inputFile);
139 if (src.IsNull()) continue;
141 dst.ReplaceAll("alien:///","");
142 dst.ReplaceAll("/","_");
143 Bool_t result = TFile::Cp(src.Data(),dst.Data(),kTRUE);
144 AliSysInfo::AddStamp(dst.Data(),counter, result);
147 outputFile << dst.Data()<< endl;
151 cout<<counter<<" files copied!"<<endl;
155 gSystem->Exec("touch copy_done");