]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/CalibMacros/CPass1/merge.byComponent.C
Adding the CPass0 macros and scripts as first version of the CPass1
[u/mrichter/AliRoot.git] / PWGPP / CalibMacros / CPass1 / merge.byComponent.C
1 //___________________________________________________________________
2
3 void merge(TString component, const Char_t *inputstring)
4 {
5
6   /* load libs */
7   gROOT->Macro("LoadLibraries.C");
8   TH1::AddDirectory(0);
9
10   /* copy only */
11   if (component == "COPY") {
12     CopyCPass(inputstring, "AliESDfriends_v1.root");
13     return;
14   }
15   
16   /* merge component */
17   MergeCPass(inputstring, component);
18   
19 }
20
21 //___________________________________________________________________
22
23 void MergeCPass(const Char_t *list, TString component)
24 {
25   AliFileMerger merger;
26   /* select what to merge */
27   if (component == "ALL")
28     merger.AddReject("esdFriend");
29   else
30     merger.AddAccept(component.Data());
31   /* merge */
32   merger.IterTXT(list, "CalibObjects.root", kFALSE);
33   /* notify */
34   gSystem->Exec(Form("touch %s_merge_done", component.Data()));
35   return;
36 }
37
38 //___________________________________________________________________
39
40 void CopyCPass(const char *searchdir, const char *pattern, Int_t timeOut=10)
41 {
42
43   gSystem->Setenv("XRDCLIENTMAXWAIT",Form("%d",timeOut));
44   gEnv->SetValue("XNet.RequestTimeout", timeOut);
45   gEnv->SetValue("XNet.ConnectTimeout", timeOut);
46   gEnv->SetValue("XNet.TransactionTimeout", timeOut);
47   TFile::SetOpenTimeout(timeOut);
48
49   TGrid::Connect("alien");
50
51   TString filelist;
52   TString command;
53   command = Form("find %s/ %s", searchdir, pattern);
54   cerr<<"command: "<<command<<endl;
55   TGridResult *res = gGrid->Command(command);
56   if (!res) return;
57   TIter nextmap(res);
58   TMap *map = 0;
59
60   ofstream outputFile;
61   outputFile.open(Form("calib.list"));
62   Int_t counter=0;
63
64   while((map=(TMap*)nextmap()))
65   {
66     TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("turl"));
67     if (!objs || !objs->GetString().Length())
68     {
69       delete res;
70       break;
71     }
72
73     TString src=Form("%s",objs->GetString().Data());
74     TString dst=src;
75     dst.ReplaceAll("alien:///","");
76     dst.ReplaceAll("/","_");
77     TTimeStamp s1;
78     Bool_t result = TFile::Cp(src.Data(),dst.Data(),kTRUE);
79     TTimeStamp s2;
80     AliSysInfo::AddStamp(dst.Data(),counter, result);
81     if (result)
82     {
83       counter++;
84       outputFile << dst.Data()<< endl;
85     }
86   }
87   cout<<counter<<" files copied!"<<endl;
88
89   outputFile.close();
90   gSystem->Exec("touch copy_done");
91   return;
92 }
93