]>
Commit | Line | Data |
---|---|---|
ee275c29 | 1 | //____________________________________________________________________ |
2 | void Tag() | |
3 | { | |
f8b7a926 | 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 | ||
ee275c29 | 17 | // gEnv->Print(); |
f8b7a926 | 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 | ||
ee275c29 | 28 | //____________________________________________________________________ |
29 | void GetProductionInfo(TString &fPeriod, TString &fPass, TString &fName) | |
30 | { | |
f8b7a926 | 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 | ||
ee275c29 | 45 | //____________________________________________________________________ |
46 | void GetVersions(TString &fAliroot, TString &froot, TString &fgeant) | |
47 | { | |
f8b7a926 | 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 | ||
ee275c29 | 71 | //____________________________________________________________________ |
72 | void GetGUID(TString &guid) | |
73 | { | |
f8b7a926 | 74 | ofstream myfile ("guid.txt"); |
ee275c29 | 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; | |
f8b7a926 | 84 | } |
ee275c29 | 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(); | |
f8b7a926 | 92 | } |
93 | ||
94 | ||
ee275c29 | 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()); | |
f8b7a926 | 109 | |
110 | const TString tagPattern = "tag.root"; | |
ee275c29 | 111 | |
112 | // --- Open the working directory ---------------------------------- | |
f8b7a926 | 113 | TSystemDirectory dir(".", gSystem->pwd()); |
114 | TIter next(dir.GetListOfFiles()); | |
115 | TSystemFile* file = 0; | |
ee275c29 | 116 | |
117 | // --- Add all files matching *pattern* to the chain --------------- | |
f8b7a926 | 118 | while ((file = static_cast<TSystemFile*>(next()))) { |
119 | TString name(file->GetName()); | |
120 | if (!name.Contains(tagPattern)) continue; | |
121 | ||
ee275c29 | 122 | // --- Open file matching pattern -------------------------------- |
f8b7a926 | 123 | TFile* f = TFile::Open(name,"read") ; |
ee275c29 | 124 | if (!f) { |
125 | continue; | |
126 | } | |
127 | Info("", "Updating tags in %s", name.Data()); | |
128 | ||
129 | // --- Find the tree --------------------------------------------- | |
f8b7a926 | 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 | ||
ee275c29 | 139 | // --- Defining new tag objects ---------------------------------- |
f8b7a926 | 140 | AliRunTag* newTag = 0x0; |
141 | TTree ttag("T","A Tree with event tags"); | |
142 | TBranch* btag = ttag.Branch("AliTAG", &newTag); | |
143 | btag->SetCompressionLevel(9); | |
ee275c29 | 144 | // --- disassociate the tree with underlying directory ----------- |
145 | ttag.SetDirectory(0); | |
f8b7a926 | 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 | |
ee275c29 | 169 | |
170 | // --- Close the input file -------------------------------------- | |
171 | f->Close(); | |
f8b7a926 | 172 | |
ee275c29 | 173 | // --- Overwrite the file ---------------------------------------- |
f8b7a926 | 174 | TFile* ftag = TFile::Open(name, "recreate"); |
175 | ftag->cd(); | |
176 | ttag.Write(); | |
177 | ftag->Close(); | |
ee275c29 | 178 | Info("", "Overwrote %s with new tags", name.Data()); |
f8b7a926 | 179 | }//directory loop |
180 | return kTRUE; | |
181 | } | |
182 | ||
183 | // | |
184 | // EOF | |
185 | // |