AliPhysics  5e2c166 (5e2c166)
Tag.C
Go to the documentation of this file.
1 
8 //____________________________________________________________________
13 void Tag()
14 {
15  const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
16 
17  gSystem->Load("libNet");
18  // gSystem->Load("libMonaLisa");
19  // new TMonaLisaWriter(0, "GridAliRoot-tag.C", 0, 0, "global");
20 
21  TString fESDFileName = "alien://";
22  fESDFileName += turl;
23  fESDFileName += "/AliESDs.root";
24 
25  TString fGUID = 0;
26  GetGUID(fGUID);
27 
28  // gEnv->Print();
29 
30  TString fAliroot, fRoot, fGeant;
31  GetVersions(fAliroot,fRoot,fGeant);
32 
33  TString fPeriod, fPass, fName;
34  GetProductionInfo(fPeriod, fPass, fName);
35 
36  UpdateTag(fAliroot,fRoot,fGeant,fESDFileName,fGUID,fPeriod,fPass,fName);
37 }
38 
39 //____________________________________________________________________
47 void GetProductionInfo(TString &fPeriod, TString &fPass, TString &fName)
48 {
49  const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
50 
51  TString fS = turl;
52  TObjArray *fDirs = fS.Tokenize("/");
53 
54  for (int iter=0; iter<fDirs->GetEntries(); iter++) {
55  TString fDir = ((TObjString *) fDirs->At(iter))->String();
56 
57  if (fDir.Contains("LHC")) fPeriod = fDir;
58  if (fDir.Contains("pass")) fPass = fDir;
59  }
60  fName = fPeriod+"."+fPass;
61 }
62 
63 //____________________________________________________________________
71 void GetVersions(TString &fAliroot, TString &froot, TString &fgeant)
72 {
73  const char* fver = gSystem->Getenv("ALIEN_JDL_PACKAGES");
74  TString fS = fver;
75  Int_t fFirst = fS.First("#");
76 
77  while(fFirst != -1) {
78  Int_t fTotalLength = fS.Length();
79  TString tmp = fS;
80  TString fS1 = fS(0,fFirst);
81  tmp = fS(fFirst+2,fTotalLength);
82  fS = tmp;
83 
84  if(fS1.Contains("Root")) fAliroot = fS1;
85  if(fS1.Contains("ROOT")) froot = fS1;
86  if(fS1.Contains("GEANT")) fgeant = fS1;
87 
88  if(tmp.Contains("Root")) fAliroot = tmp;
89  if(tmp.Contains("ROOT")) froot = tmp;
90  if(tmp.Contains("GEANT")) fgeant = tmp;
91 
92  fFirst = tmp.First("#");
93  }
94 }
95 
96 //____________________________________________________________________
102 void GetGUID(TString &guid)
103 {
104  ofstream myfile ("guid.txt");
105  if (!myfile.is_open()) {
106  Warning("GetGUID", "Couldn't open guid.txt for writing");
107  return;
108  }
109 
110  TFile *f = TFile::Open("AliESDs.root","read");
111  if (!f || f->IsZombie() || !f->IsOpen()) {
112  Warning("GetGUID", "Input file AliESDs.root not found");
113  return;
114  }
115 
116  guid = f->GetUUID().AsString();
117  f->Close();
118  Info("", "Global Unique IDentifier: %s", guid.Data());
119 
120  myfile << "AliESDs.root \t"<< guid << std::endl;
121  myfile.close();
122 }
123 
124 
125 //____________________________________________________________________
141  TString froot,
142  TString fgeant,
143  TString turl,
144  TString guid,
145  TString fperiod,
146  TString fpass,
147  TString fname)
148 {
149  Info("", "Updating tags (%s,%s,%s,%s,%s,%s,%s,%s",
150  faliroot.Data(), froot.Data(), fgeant.Data(),
151  turl.Data(), guid.Data(), fperiod.Data(),
152  fpass.Data(),fname.Data());
153 
154  const TString tagPattern = "tag.root";
155 
156  // --- Open the working directory ----------------------------------
157  TSystemDirectory dir(".", gSystem->pwd());
158  TIter next(dir.GetListOfFiles());
159  TSystemFile* file = 0;
160 
161  // --- Add all files matching *pattern* to the chain ---------------
162  while ((file = static_cast<TSystemFile*>(next()))) {
163  TString name(file->GetName());
164  if (!name.Contains(tagPattern)) continue;
165 
166  // --- Open file matching pattern --------------------------------
167  TFile* f = TFile::Open(name,"read") ;
168  if (!f) {
169  continue;
170  }
171  Info("", "Updating tags in %s", name.Data());
172 
173  // --- Find the tree ---------------------------------------------
174  AliRunTag* tag = 0x0;
175  AliFileTag* flTag = 0x0;
176  TTree* fTree = (TTree *)f->Get("T");
177  if (!fTree) {
178  f->Close();
179  continue;
180  }
181  fTree->SetBranchAddress("AliTAG",&tag);
182 
183  // --- Defining new tag objects ----------------------------------
184  AliRunTag* newTag = 0x0;
185  TTree ttag("T","A Tree with event tags");
186  TBranch* btag = ttag.Branch("AliTAG", &newTag);
187  btag->SetCompressionLevel(9);
188  // --- disassociate the tree with underlying directory -----------
189  ttag.SetDirectory(0);
190 
191  Printf(">>>>> Found %d entries....",fTree->GetEntries());
192 
193  for (Int_t iTagFiles = 0; iTagFiles < fTree->GetEntries(); iTagFiles++) {
194  fTree->GetEntry(0);
195  newTag = new AliRunTag(*tag);
196  newTag->SetAlirootVersion(faliroot);
197  newTag->SetRootVersion(froot);
198  newTag->SetGeant3Version(fgeant);
199  newTag->SetLHCPeriod(fperiod);
200  newTag->SetReconstructionPass(fpass);
201  newTag->SetProductionName(fname);
202  Printf("Found %d file tags",newTag->GetNFiles());
203  for(Int_t j = 0; j < newTag->GetNFiles(); j++) {
204  flTag = (AliFileTag *) newTag->GetFileTag(j);
205  flTag->SetTURL(turl);
206  flTag->SetGUID(guid);
207  }
208  ttag.Fill();
209 
210  delete tag;
211  delete newTag;
212  }//tag file loop
213 
214  // --- Close the input file --------------------------------------
215  f->Close();
216 
217  // --- Overwrite the file ----------------------------------------
218  TFile* ftag = TFile::Open(name, "recreate");
219  ftag->cd();
220  ttag.Write();
221  ftag->Close();
222  Info("", "Overwrote %s with new tags", name.Data());
223  }//directory loop
224  return kTRUE;
225 }
226 
227 //
228 // EOF
229 //
TSystem * gSystem
void GetVersions(TString &fAliroot, TString &froot, TString &fgeant)
Definition: Tag.C:71
int Int_t
Definition: External.C:63
void GetGUID(TString &guid)
Definition: Tag.C:102
void Tag()
Definition: Tag.C:13
void GetProductionInfo(TString &fPeriod, TString &fPass, TString &fName)
Definition: Tag.C:47
TFile * file
TList with histograms for a given trigger.
bool Bool_t
Definition: External.C:53
Bool_t UpdateTag(TString faliroot, TString froot, TString fgeant, TString turl, TString guid, TString fperiod, TString fpass, TString fname)
Definition: Tag.C:140
TDirectoryFile * dir