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