]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/sim/Tag.C
Various updates for the production scripts
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / sim / Tag.C
1 //____________________________________________________________________
2 void Tag() 
3 {
4   const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
5
6   gSystem->Load("libNet.so");
7   //  gSystem->Load("libMonaLisa.so");
8   //  new TMonaLisaWriter(0, "GridAliRoot-tag.C", 0, 0, "global");
9   
10   TString fESDFileName = "alien://";
11   fESDFileName += turl;
12   fESDFileName += "/AliESDs.root";  
13
14   TString fGUID = 0;
15   GetGUID(fGUID);
16
17   // gEnv->Print();
18
19   TString fAliroot, fRoot, fGeant;
20   GetVersions(fAliroot,fRoot,fGeant);
21
22   TString fPeriod, fPass, fName;
23   GetProductionInfo(fPeriod, fPass, fName);
24
25   UpdateTag(fAliroot,fRoot,fGeant,fESDFileName,fGUID,fPeriod,fPass,fName);
26 }
27
28 //____________________________________________________________________
29 void GetProductionInfo(TString &fPeriod, TString &fPass, TString &fName) 
30 {
31   const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
32   
33   TString fS = turl;
34   TObjArray *fDirs = fS.Tokenize("/");
35   
36   for (int iter=0; iter<fDirs->GetEntries(); iter++) {
37     TString fDir = ((TObjString *) fDirs->At(iter))->String();
38
39     if (fDir.Contains("LHC")) fPeriod = fDir;
40     if (fDir.Contains("pass")) fPass = fDir;
41   }
42   fName = fPeriod+"."+fPass;
43 }
44   
45 //____________________________________________________________________
46 void GetVersions(TString &fAliroot, TString &froot, TString &fgeant) 
47 {
48   const char* fver = gSystem->Getenv("ALIEN_JDL_PACKAGES");
49   TString fS = fver;
50   Int_t fFirst = fS.First("#");
51
52   while(fFirst != -1) {
53     Int_t fTotalLength = fS.Length();
54     TString tmp = fS;
55     TString fS1 = fS(0,fFirst);
56     tmp = fS(fFirst+2,fTotalLength);
57     fS = tmp;
58
59     if(fS1.Contains("Root")) fAliroot = fS1;
60     if(fS1.Contains("ROOT")) froot = fS1;
61     if(fS1.Contains("GEANT")) fgeant = fS1;
62
63     if(tmp.Contains("Root")) fAliroot = tmp;
64     if(tmp.Contains("ROOT")) froot = tmp;
65     if(tmp.Contains("GEANT")) fgeant = tmp;
66     
67     fFirst = tmp.First("#");
68   }
69 }
70
71 //____________________________________________________________________
72 void GetGUID(TString &guid) 
73 {
74   ofstream myfile ("guid.txt");
75   if (!myfile.is_open()) {
76     Warning("GetGUID", "Couldn't open guid.txt for writing");
77     return;
78   }
79
80   TFile *f = TFile::Open("AliESDs.root","read");
81   if (!f || f->IsZombie() || !f->IsOpen()) {
82     Warning("GetGUID", "Input file AliESDs.root not found");
83     return;
84   }
85
86   guid = f->GetUUID().AsString();
87   f->Close();
88   Info("", "Global Unique IDentifier: %s", guid.Data());
89
90   myfile << "AliESDs.root \t"<< guid << std::endl;
91   myfile.close();
92 }
93
94
95 //____________________________________________________________________
96 Bool_t UpdateTag(TString faliroot, 
97                  TString froot, 
98                  TString fgeant, 
99                  TString turl, 
100                  TString guid,
101                  TString fperiod, 
102                  TString fpass, 
103                  TString fname) 
104 {
105   Info("", "Updating tags (%s,%s,%s,%s,%s,%s,%s,%s",
106        faliroot.Data(), froot.Data(), fgeant.Data(), 
107        turl.Data(), guid.Data(), fperiod.Data(), 
108        fpass.Data(),fname.Data());
109
110   const TString tagPattern = "tag.root";
111
112   // --- Open the working directory ----------------------------------
113   TSystemDirectory dir(".", gSystem->pwd());
114   TIter            next(dir.GetListOfFiles());
115   TSystemFile*     file = 0;
116
117   // --- Add all files matching *pattern* to the chain ---------------
118   while ((file = static_cast<TSystemFile*>(next()))) {
119     TString name(file->GetName());
120     if (!name.Contains(tagPattern)) continue;
121     
122     // --- Open file matching pattern --------------------------------
123     TFile*      f     = TFile::Open(name,"read") ;
124     if (!f) { 
125       continue;
126     }
127     Info("", "Updating tags in %s", name.Data());
128
129     // --- Find the tree ---------------------------------------------
130     AliRunTag*  tag   = 0x0;
131     AliFileTag* flTag = 0x0;
132     TTree*      fTree = (TTree *)f->Get("T");
133     if (!fTree) { 
134       f->Close(); 
135       continue; 
136     }
137     fTree->SetBranchAddress("AliTAG",&tag);
138    
139     // --- Defining new tag objects ----------------------------------
140     AliRunTag* newTag = 0x0;
141     TTree      ttag("T","A Tree with event tags");
142     TBranch*   btag = ttag.Branch("AliTAG", &newTag);
143     btag->SetCompressionLevel(9);
144     // --- disassociate the tree with underlying directory -----------
145     ttag.SetDirectory(0);
146       
147     Printf(">>>>> Found %d entries....",fTree->GetEntries());
148
149     for (Int_t iTagFiles = 0; iTagFiles < fTree->GetEntries(); iTagFiles++) {
150       fTree->GetEntry(0);
151       newTag = new AliRunTag(*tag);
152       newTag->SetAlirootVersion(faliroot);
153       newTag->SetRootVersion(froot);
154       newTag->SetGeant3Version(fgeant);
155       newTag->SetLHCPeriod(fperiod);
156       newTag->SetReconstructionPass(fpass);
157       newTag->SetProductionName(fname);
158       Printf("Found %d file tags",newTag->GetNFiles());
159       for(Int_t j = 0; j < newTag->GetNFiles(); j++) {
160         flTag = (AliFileTag *) newTag->GetFileTag(j);
161         flTag->SetTURL(turl);
162         flTag->SetGUID(guid);
163       }
164       ttag.Fill();
165
166       delete tag;
167       delete newTag;
168     }//tag file loop 
169     
170     // --- Close the input file --------------------------------------
171     f->Close();
172
173     // --- Overwrite the file ----------------------------------------
174     TFile* ftag = TFile::Open(name, "recreate");
175     ftag->cd();
176     ttag.Write();
177     ftag->Close();
178     Info("", "Overwrote %s with new tags", name.Data());
179   }//directory loop
180   return kTRUE;
181 }
182
183 // 
184 // EOF
185 //