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