]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/corrs/MoveCorrections.C
Fixed references from PWG2 -> PWGLF - very efficiently done using ETags.
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / corrs / MoveCorrections.C
1 /** 
2  * 
3  * 
4  * @param fname 
5  * @param n 
6  * 
7  * @return 
8  * @ingroup pwglf_forward_scripts_corr
9  */
10 Bool_t
11 Backup(const TString& fname, Int_t n=10)
12 {
13   TString fn(fname); fn.Append(Form(".%d", n));
14   if (!gSystem->AccessPathName(fn.Data())) {
15     Error("Backup", "Last possible backup slot (%d) filled for %s", 
16           n, fname.Data());
17     return false;
18   }
19
20   for (Int_t i=n-1; i >= 0; i--) { 
21     TString fi(fname); 
22     if (i > 0) fi.Append(Form(".%d", i));
23     if (gSystem->AccessPathName(fi.Data())) continue;
24
25     TString fb(fname); fb.Append(Form(".%d", i+1));
26
27     if (gSystem->Rename(fi.Data(), fb.Data())) { 
28       Error("Backup", "Failed to backup %s to %s", fi.Data(), fb.Data());
29       return false;
30     }
31   }
32   return true;
33 }
34
35
36 /** 
37  * 
38  * 
39  * @param what 
40  * 
41  * @return 
42  * @ingroup pwglf_forward_scripts_corr
43  */
44 Bool_t
45 MoveWhat(UInt_t what) 
46 {
47   TString nWhat;
48   switch (what) {
49   case AliForwardCorrectionManager::kSecondaryMap:    
50     nWhat = "secondary map";    break;
51   case AliForwardCorrectionManager::kDoubleHit:       
52     nWhat = "double hit";       break;
53   case AliForwardCorrectionManager::kVertexBias:      
54     nWhat = "vertex bias";      break;
55   case AliForwardCorrectionManager::kMergingEfficiency:
56     nWhat = "merging efficiency";break;
57   case AliForwardCorrectionManager::kELossFits:       
58     nWhat = "energy loss fits";  break;
59   }
60   Info("MakeWhat", " Copying %s corrections", nWhat.Data());
61
62   AliForwardCorrectionManager& mgr = AliForwardCorrectionManager::Instance();
63   TString dir = gSystem->ExpandPathName(mgr.GetFileDir(what));
64
65   // Make the directory if it doesn't exist
66   if (gSystem->AccessPathName(dir.Data())) {
67     Info("MakeWhat", " Making directory %s ... ", dir.Data());
68     if (gSystem->mkdir(dir.Data(), true)) {
69       Error("MakeWhat", "couldn't make directory %s", dir.Data());
70       return false;
71     }
72   }
73
74   TString pattern = mgr.GetFileName(what, 1, 900, 5, false);
75   pattern.ReplaceAll("0900GeV", "[0-9]+GeV");
76   pattern.ReplaceAll("pp", "[a-zA-Z]+");
77   pattern.ReplaceAll("p5kG", "[pm][0-9]+kG");
78   pattern.ReplaceAll("real", "[a-zA-Z]+");
79   
80   TPRegexp regex(pattern);
81  
82   TSystemDirectory sysdir(".", ".");
83   TIter            next(sysdir.GetListOfFiles());
84   TSystemFile*     file = 0;
85   while ((file = static_cast<TSystemFile*>(next()))) {
86     if (file->IsDirectory()) continue;
87     TString fname(file->GetName());
88  
89     if (!regex.Match(fname)) continue;
90
91     // Info("MakeWhat", "  match: %s", fname.Data());
92     TString to(gSystem->ConcatFileName(dir.Data(), fname.Data()));
93     
94     if (!Backup(to)) return false;
95
96     Info("MakeWhat", "  copying %s\n               to %s", 
97          fname.Data(), to.Data());
98     if (gSystem->CopyFile(fname.Data(), to.Data(), false)) {
99       Error("MakeWhat", "Failed to copy %s to %s", fname.Data(), to.Data());
100       return false;
101     }
102   }
103   return true;
104 }
105 /** 
106  * 
107  * 
108  * @param sec 
109  * @param dbl 
110  * @param vtx 
111  * @param merge 
112  * @param eloss 
113  * @ingroup pwglf_forward_scripts_corr
114  */
115 void
116 MoveCorrections(bool sec=true, 
117                 bool dbl=true, 
118                 bool vtx=true,
119                 bool merge=true,
120                 bool eloss=true)
121 {
122   Info("MoveCorrections", "Loadingl libraries ...");
123   gROOT->Macro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C");
124
125   Info("MoveCorrections", "Moving selected corrections ...");
126   if (sec)   MoveWhat(AliForwardCorrectionManager::kSecondaryMap);
127   if (dbl)   MoveWhat(AliForwardCorrectionManager::kDoubleHit);
128   if (vtx)   MoveWhat(AliForwardCorrectionManager::kVertexBias);
129   if (merge) MoveWhat(AliForwardCorrectionManager::kMergingEfficiency);
130   if (eloss) MoveWhat(AliForwardCorrectionManager::kELossFits);       
131
132 }
133