]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/muondep/AccEffTemplates/tag.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWG / muondep / AccEffTemplates / tag.C
1 void tag() {
2   const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
3
4   gSystem->Load("libNet");
5   //  gSystem->Load("libMonaLisa");
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   TString fPeriod, fPass, fName;
21   GetProductionInfo(fPeriod, fPass, fName);
22
23   UpdateTag(fAliroot,fRoot,fGeant,fESDFileName,fGUID,fPeriod,fPass,fName);
24 }
25
26 //_____________________________________//
27 GetProductionInfo(TString &fPeriod, TString &fPass, TString &fName) {
28   const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
29   
30   TString fS = turl;
31   TObjArray *fDirs = fS.Tokenize("/");
32   
33   for (int iter=0; iter<fDirs->GetEntries(); iter++) {
34     TString fDir = ((TObjString *) fDirs->At(iter))->String();
35
36     if (fDir.Contains("LHC")) fPeriod = fDir;
37     if (fDir.Contains("pass")) fPass = fDir;
38   }
39   fName = fPeriod+"."+fPass;
40 }
41   
42 //_____________________________________//
43 GetVersions(TString &fAliroot, TString &froot, TString &fgeant) {
44   const char* fver = gSystem->Getenv("ALIEN_JDL_PACKAGES");
45   TString fS = fver;
46   Int_t fFirst = fS.First("#");
47
48   while(fFirst != -1) {
49     Int_t fTotalLength = fS.Length();
50     TString tmp = fS;
51     TString fS1 = fS(0,fFirst);
52     tmp = fS(fFirst+2,fTotalLength);
53     fS = tmp;
54
55     if(fS1.Contains("Root")) fAliroot = fS1;
56     if(fS1.Contains("ROOT")) froot = fS1;
57     if(fS1.Contains("GEANT")) fgeant = fS1;
58
59     if(tmp.Contains("Root")) fAliroot = tmp;
60     if(tmp.Contains("ROOT")) froot = tmp;
61     if(tmp.Contains("GEANT")) fgeant = tmp;
62     
63     fFirst = tmp.First("#");
64   }
65 }
66
67 //_____________________________________//
68 GetGUID(TString &guid) {
69   ofstream myfile ("guid.txt");
70   if (myfile.is_open()) {
71     TFile *f = TFile::Open("AliESDs.root","read");
72     if(f && !f->IsZombie() && f->IsOpen()) {
73       guid = f->GetUUID().AsString();
74       myfile << "AliESDs.root \t"<<f->GetUUID().AsString();
75       cout<<guid.Data()<<endl;
76       myfile.close();
77     }
78     else cout<<"Input file not found"<<endl;
79   }
80   else cout<<"Output file can't be created..."<<endl;
81 }
82
83
84 //_____________________________________//
85 Bool_t UpdateTag(TString faliroot, TString froot, TString fgeant, 
86                  TString turl, TString guid,
87                  TString fperiod, TString fpass, TString fname) {
88   cout<<"> Updating tags...."<<endl;
89
90   const char * tagPattern = "tag.root";
91   // Open the working directory
92   void * dirp = gSystem->OpenDirectory(gSystem->pwd());
93   const char * name = 0x0;
94   // Add all files matching *pattern* to the chain
95   while((name = gSystem->GetDirEntry(dirp))) {
96     cout<<">>> Adding to chain file " << name << "...." << endl;
97     if (strstr(name,tagPattern)) {
98       TFile *f = TFile::Open(name,"read") ;
99  
100       AliRunTag *tag = 0x0;
101       AliFileTag *flTag = 0x0;
102       TTree *fTree = (TTree *)f->Get("T");
103       if (!fTree) { f->Close(); continue; }
104       fTree->SetBranchAddress("AliTAG",&tag);
105    
106       //Defining new tag objects
107       AliRunTag *newTag = 0x0;
108       TTree ttag("T","A Tree with event tags");
109       TBranch * btag = ttag.Branch("AliTAG", &newTag);
110       btag->SetCompressionLevel(9);
111       
112       cout<<">>>>> Found " << fTree->GetEntries() << " entries...." << endl;
113       for(Int_t iTagFiles = 0; iTagFiles < fTree->GetEntries(); iTagFiles++) {
114         fTree->GetEntry(0);
115         newTag = new AliRunTag(*tag);
116         newTag->SetAlirootVersion(faliroot);
117         newTag->SetRootVersion(froot);
118         newTag->SetGeant3Version(fgeant);
119         newTag->SetLHCPeriod(fperiod);
120         newTag->SetReconstructionPass(fpass);
121         newTag->SetProductionName(fname);
122         cout << "Found " << newTag->GetNFiles() << " file tags" << endl;
123         for(Int_t j = 0; j < newTag->GetNFiles(); j++) {
124           flTag = (AliFileTag *) newTag->GetFileTag(j);
125           flTag->SetTURL(turl);
126           flTag->SetGUID(guid);
127         }
128         ttag.Fill();
129
130         delete tag;
131         delete newTag;
132       }//tag file loop 
133
134       TFile* ftag = TFile::Open(name, "recreate");
135       ftag->cd();
136       ttag.Write();
137       ftag->Close();
138
139     }//pattern check
140   }//directory loop
141   return kTRUE;
142 }
143