]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/CalibMacros/PassX/tag.C
d434fa632e42434a0eca1f60e161e37e9680ae8c
[u/mrichter/AliRoot.git] / ANALYSIS / CalibMacros / PassX / tag.C
1 void tag() {
2   const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
3
4   gSystem->Load("libNet.so");
5   gSystem->Load("libMonaLisa.so");
6   new TMonaLisaWriter(0, "GridAliRoot-tag.C", 0, 0, "global");
7
8   TString fESDFileName = "alien://";
9   fESDFileName += turl;
10   fESDFileName += "/AliESDs.root";  
11
12   TString fGUID = 0;
13   GetGUID(fGUID);
14
15   gEnv->Print();
16
17   TString fAliroot, fRoot, fGeant;
18   GetVersions(fAliroot,fRoot,fGeant);
19
20   UpdateTag(fAliroot,fRoot,fGeant,fESDFileName,fGUID);
21 }
22   
23 //_____________________________________//
24 GetVersions(TString &fAliroot, TString &froot, TString &fgeant) {
25   const char* fver = gSystem->Getenv("ALIEN_JDL_PACKAGES");
26   TString fS = fver;
27   Int_t fFirst = fS.First("#");
28
29   while(fFirst != -1) {
30     Int_t fTotalLength = fS.Length();
31     TString tmp = fS;
32     TString fS1 = fS(0,fFirst);
33     tmp = fS(fFirst+2,fTotalLength);
34     fS = tmp;
35
36     if(fS1.Contains("Root")) fAliroot = fS1;
37     if(fS1.Contains("ROOT")) froot = fS1;
38     if(fS1.Contains("GEANT")) fgeant = fS1;
39
40     if(tmp.Contains("Root")) fAliroot = tmp;
41     if(tmp.Contains("ROOT")) froot = tmp;
42     if(tmp.Contains("GEANT")) fgeant = tmp;
43     
44     fFirst = tmp.First("#");
45   }
46 }
47
48 //_____________________________________//
49 GetGUID(TString &guid) {
50   ofstream myfile ("guid.txt");
51   if (myfile.is_open()) {
52     TFile *f = TFile::Open("AliESDs.root","read");
53     if(f && !f->IsZombie() && f->IsOpen()) {
54       guid = f->GetUUID().AsString();
55       myfile << "AliESDs.root \t"<<f->GetUUID().AsString();
56       cout<<guid.Data()<<endl;
57       myfile.close();
58     }
59     else cout<<"Input file not found"<<endl;
60   }
61   else cout<<"Output file can't be created..."<<endl;
62 }
63
64
65 //_____________________________________//
66 Bool_t UpdateTag(TString faliroot, TString froot, TString fgeant, TString turl, TString guid) {
67   cout<<"> Updating tags...."<<endl;
68
69   const char * tagPattern = "tag.root";
70   // Open the working directory
71   void * dirp = gSystem->OpenDirectory(gSystem->pwd());
72   const char * name = 0x0;
73   // Add all files matching *pattern* to the chain
74   while((name = gSystem->GetDirEntry(dirp))) {
75     cout<<">>> Adding to chain file " << name << "...." << endl;
76     if (strstr(name,tagPattern)) {
77       TFile *f = TFile::Open(name,"read") ;
78  
79       AliRunTag *tag = 0x0;
80       AliEventTag *evTag = 0x0;
81       TTree *fTree = (TTree *)f->Get("T");
82       if (!fTree) { f->Close(); continue; }
83       fTree->SetBranchAddress("AliTAG",&tag);
84    
85       //Defining new tag objects
86       AliRunTag *newTag = 0x0;
87       TTree ttag("T","A Tree with event tags");
88       TBranch * btag = ttag.Branch("AliTAG", &newTag);
89       btag->SetCompressionLevel(9);
90       
91       cout<<">>>>> Found " << fTree->GetEntries() << " entries...." << endl;
92       for(Int_t iTagFiles = 0; iTagFiles < fTree->GetEntries(); iTagFiles++) {
93         fTree->GetEntry(iTagFiles);
94         newTag = new AliRunTag(*tag);
95         newTag->SetAlirootVersion(faliroot);
96         newTag->SetRootVersion(froot);
97         newTag->SetGeant3Version(fgeant);
98         TClonesArray *tagList = newTag->GetEventTags();
99         cout << "Found " << tagList->GetEntries() << " tags" << endl;
100         for(Int_t j = 0; j < tagList->GetEntries(); j++) {
101           evTag = (AliEventTag *) tagList->At(j);
102           evTag->SetTURL(turl);
103           evTag->SetGUID(guid);
104         }
105         ttag.Fill();
106
107         delete tag;
108         delete newTag;
109       }//tag file loop 
110       
111       TFile* ftag = TFile::Open(name, "recreate");
112       ftag->cd();
113       ttag.Write();
114       ftag->Close();
115
116     }//pattern check
117   }//directory loop
118   return kTRUE;
119 }
120