Macro checking if the current $ALICE_ROOT creates a geometry different w.r.t. to...
[u/mrichter/AliRoot.git] / macros / DiffGeomBeforeTagging.C
1 #include "ARVersion.h"
2 #if !defined(__CINT__) || defined(__MAKECINT__)
3 #include "AliCDBManager.h"
4 #include "AliCDBStorage.h"
5 #include "AliCDBId.h"
6 #include "AliCDBMetaData.h"
7 #include "AliGeomManager.h"
8 #include "AliMC.h"
9 #include <TROOT.h>
10 #include "AliRun.h"
11 #include <TGeoManager.h>
12 #include <TString.h>
13 #include <TInterpreter.h>
14 #endif
15
16 Bool_t DiffGeometry(const char* recipient, const char* cdbUri="local://$ALICE_ROOT/OCDB", const char* cfgFile="$ALICE_ROOT/macros/Config.C"){
17         // Compare the geometry created in the current AliRoot with the one
18         // in the OCDB directory of the current aliroot. If they differ,
19         // warn the recipients to update the geometry in $ALICE_ROOT/OCDB
20         // before tagging and to consider updating it in the raw OCDB.
21         //
22         // Running this macro always before creating a release tag will
23         // allow to have in release tags OCDBs the geometry corresponding
24         // to their code.
25         //
26         // The recipient string is supposed to contain comma-separated 
27         // valid email addresses, at least the one of the librarian and
28         // probably also the one of the guy in charge of the geometry object.
29         //
30
31         // Uplaod the geometry from $ALICE_ROOT/OCDB and get the number of nodes
32         AliCDBManager* cdb = AliCDBManager::Instance();
33         cdb->SetDefaultStorage(cdbUri);
34         cdb->Get("GRP/Geometry/Data",0);
35         Int_t svnocdb_nnodes = gGeoManager->GetNNodes();
36         Printf("The geometry in OCDB has %d nodes",svnocdb_nnodes);
37         cdb->SetRun(0);
38
39         gGeoManager = 0;
40
41         // Create the geometry and get the number of nodes
42         if(!gSystem->AccessPathName("geometry.root")){
43                 Printf("Deleting existing \"geometry.root\"");
44                 gSystem->Exec("rm -rf geometry.root");
45         }
46
47         gROOT->LoadMacro(cfgFile);
48         gInterpreter->ProcessLine(gAlice->GetConfigFunction());
49         gAlice->GetMCApp()->Init();
50
51         if(!gGeoManager){
52                 Printf("Unable to produce a valid geometry to be put in the CDB!");
53                 return kFALSE;
54         }
55
56         if(gSystem->AccessPathName("geometry.root")){
57                 Printf("Did not find freshly written \"geometry.root\" file. Exiting ...");
58                 return kFALSE;
59         }
60
61         Printf("Reloading freshly written geometry.root file");
62         if (TGeoManager::IsLocked()) TGeoManager::UnlockGeometry();
63         AliGeomManager::LoadGeometry("geometry.root");
64
65         Int_t svncode_nnodes = gGeoManager->GetNNodes();
66         Printf("The generated geometry has %d nodes",svncode_nnodes);
67
68         // If the number of nodes differs, remove the geometry file from the local OCDB
69         // and replace it by calling the UpdateCDBIdealGeom.C macro
70         if (svncode_nnodes != svnocdb_nnodes){
71                 Printf("The geometry generated and the one in the current OCDB differ.");
72                 Printf("Remove \"$ALICE_ROOT/OCDB/GRP/Geometry/Data/Run0_999999999_v0_s0.root\".");
73                 Printf("and run $ALICE_ROOT/GRP/UpdateCDBIdealGeom.C(\"local://$ALICE_ROOT/OCDB\",%s)",cfgFile);
74
75                 // Get root and AliRoot versions
76                 const char* rootv = gROOT->GetVersion();
77                 TString av(ALIROOT_SVN_BRANCH);
78                 Int_t revnum = ALIROOT_SVN_REVISION;
79                 Printf("root version: %s.  AliRoot %s, revision number %d",rootv,av.Data(),revnum);
80
81                 // create and send mail
82                 TString subject(Form("AliRoot revision %d is about to be tagged and the geometry changed!",revnum));
83                 // mail body 
84                 TString bodyFileName("mailbody.txt");
85                // bodyFileName.Form("%s/mail.body", GetShuttleLogDir());
86                 gSystem->ExpandPathName(bodyFileName);
87
88                 ofstream mailBody;
89                 mailBody.open(bodyFileName, ofstream::out);
90
91                 if (!mailBody.is_open())
92                 {
93                         Printf("Could not open mail body file %s", bodyFileName.Data());
94                         return kFALSE;
95                 }
96
97                 TString recipients(recipient);
98
99                 TString body;
100                 body = Form("Dear AliRoot librarian or geometry expert,\n\n");
101                 body += Form("while tagging the current revision - r%d - the geometry produced by the code\n"
102                                 "appears to have changed w.r.t. to the one saved at the previous tag.\n\n"
103                                 "You should remove \"$ALICE_ROOT/OCDB/GRP/Geometry/Data/Run0_999999999_v0_s0.root\"\n"
104                                 "and run $ALICE_ROOT/GRP/UpdateCDBIdealGeom.C(\"local://$ALICE_ROOT/OCDB\",%s) "
105                                 "before tagging.\n\n"
106                                 "Also consider updating the raw geometry on the raw OCDB.\n\n"
107                                 "Je vous prie de bien vouloir croire en l'assurance de mes respectueuses et honorables salutations.",revnum,cfgFile);
108                 mailBody << body.Data();
109                 mailBody.close();
110
111                 Printf("Sending mail to \"%s\"",recipients.Data());
112                 if(recipients.CountChar(',')==0){
113                         TString mailCommand = Form("mail -s \"%s\" %s < %s",
114                                         subject.Data(),
115                                         recipients.Data(),
116                                         bodyFileName.Data());
117                 }else{
118                         TString cc(recipients);
119                         recipients.Remove(recipients.First(','));
120                         cc.Replace(0,cc.First(',')+1,"");
121                         TString mailCommand = Form("mail -s \"%s\" -c %s %s < %s",
122                                         subject.Data(),
123                                         cc.Data(),
124                                         recipients.Data(),
125                                         bodyFileName.Data());
126                 }
127
128                 Bool_t result = gSystem->Exec(mailCommand.Data());
129         }else{
130                 Printf("There are no changes between the geometry generated with current code and the one in the current OCDB.");
131         }
132 }
133