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