]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONGMSSubprocessor.cxx
resolving new library dependency libAOD
[u/mrichter/AliRoot.git] / MUON / AliMUONGMSSubprocessor.cxx
CommitLineData
04aa997f 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// $Id$
3d1463c8 17
18//-----------------------------------------------------------------------------
04aa997f 19// Class AliMUONGMSSubprocessor
20// -----------------------------
21// The shuttle subprocessor for GMS data
22// Author: Ivana Hrivnacova, IPN Orsay
23// 16/09/2006
3d1463c8 24//-----------------------------------------------------------------------------
04aa997f 25
26#include "AliMUONGMSSubprocessor.h"
27#include "AliMUONPreprocessor.h"
2c1e4958 28#include "AliMpConstants.h"
04aa997f 29
2c1e4958 30#include "AliAlignObjMatrix.h"
d148dd1c 31#include "AliGeomManager.h"
04aa997f 32#include "AliCDBMetaData.h"
2c1e4958 33#include "AliCDBEntry.h"
04aa997f 34
35#include <TTimeStamp.h>
36#include <TFile.h>
2c1e4958 37#include <TArrayI.h>
04aa997f 38#include <TClonesArray.h>
d148dd1c 39#include <TGeoManager.h>
968ce98e 40#include <TObjString.h>
04aa997f 41#include <Riostream.h>
42
78649106 43/// \cond CLASSIMP
04aa997f 44ClassImp(AliMUONGMSSubprocessor)
78649106 45/// \endcond
04aa997f 46
923a4baf 47const Int_t AliMUONGMSSubprocessor::fgkSystem = AliPreprocessor::kDCS;
04aa997f 48const TString AliMUONGMSSubprocessor::fgkDataId = "GMS";
49const TString AliMUONGMSSubprocessor::fgkMatrixArrayName = "GMSarray";
50
968ce98e 51//______________________________________________________________________________
04aa997f 52AliMUONGMSSubprocessor::AliMUONGMSSubprocessor(AliMUONPreprocessor* master)
53 : AliMUONVSubprocessor(master, "GMS", "Upload GMS matrices to OCDB"),
789260b4 54 fTransformer(0)
04aa997f 55{
56/// Constructor
04aa997f 57}
58
968ce98e 59//______________________________________________________________________________
04aa997f 60AliMUONGMSSubprocessor::~AliMUONGMSSubprocessor()
61{
62/// Destructor
789260b4 63
64 delete fTransformer;
04aa997f 65}
66
968ce98e 67
68//
69// private methods
70//
71
72
789260b4 73//______________________________________________________________________________
6c870207 74Bool_t AliMUONGMSSubprocessor::Initialize(Int_t /*run*/,
789260b4 75 UInt_t /*startTime*/, UInt_t /*endTime*/)
76{
77/// Instantiate geometry transformer
78
79 if ( ! fTransformer ) {
80 fTransformer = new AliMUONGeometryTransformer();
81 fTransformer->CreateModules();
82 }
6c870207 83 return kTRUE;
789260b4 84}
85
968ce98e 86//______________________________________________________________________________
87UInt_t AliMUONGMSSubprocessor::ProcessFile(const TString& fileName)
04aa997f 88{
89/// Convert TGeoHMatrix to AliAlignObjMatrix and fill them into AliTestDataDCS object
90
f6e36ea4 91 Master()->Log(Form("Processing GMS file %s", fileName.Data()));
2c1e4958 92
04aa997f 93 // Open root file
968ce98e 94 TFile f(fileName.Data());
95 if ( ! f.IsOpen() ) {
f6e36ea4 96 Master()->Log(Form("Cannot open file %s",fileName.Data()));
d489129d 97 return 1;
968ce98e 98 }
04aa997f 99
100 // Get array with matrices
101 TClonesArray* array = (TClonesArray*)f.Get(fgkMatrixArrayName);
102 if ( ! array ) {
f6e36ea4 103 Master()->Log(Form("TClonesArray not found in file %s",fileName.Data()));
d489129d 104 return 2;
2c1e4958 105 }
106
107 // Array to store correspondance between the moduleId
108 // and its corresponding entry in the GMS array.
109 TArrayI moduleIdToGMSIndex;
110 moduleIdToGMSIndex.Set(AliMpConstants::NofGeomModules());
111 for (Int_t i=0; i<AliMpConstants::NofGeomModules(); i++){
112 moduleIdToGMSIndex[i]=-1;
113 }
04aa997f 114
d148dd1c 115 Bool_t useGlobalDelta = kTRUE;
116 // Get geometry from OCDB
117 AliCDBEntry* geoEntry = Master()->GetGeometryFromOCDB();
118 TGeoManager *lGeometry = 0x0;
119 if (geoEntry) {
120 lGeometry = (TGeoManager*) geoEntry->GetObject();
121 if (lGeometry) {
122 // Set Geometry
123 AliGeomManager::SetGeometry(lGeometry);
124 useGlobalDelta = kFALSE;
125 }
126 }
127
128 // Second transformer to convert GMS matrices local delta-transformation into
129 // ALICE alignment objects in the global delta convention
130 AliMUONGeometryTransformer *lTransformer = new AliMUONGeometryTransformer();
131
132 // Get mis alignment from reference run for GMS
133 AliCDBEntry* cdbEntry = Master()->GetFromOCDB("Align", "Baseline");
134 TClonesArray* refArray = 0x0;
135 if (cdbEntry) {
136 refArray = (TClonesArray*)cdbEntry->GetObject();
137 if (lGeometry && refArray) {
138 AliGeomManager::ApplyAlignObjsToGeom(*refArray);
139 lTransformer->LoadGeometryData();
140 }
141 }
142
04aa997f 143 // Convert matrices into Alice alignment objects
144 for (Int_t i=0; i<array->GetEntriesFast(); i++ ) {
145 TGeoHMatrix* matrix = (TGeoHMatrix*)array->At(i);
d148dd1c 146 printf("GMS local %i at %i \n",matrix->GetUniqueID(),i);
147 matrix->Print();
148 fTransformer->AddMisAlignModule(matrix->GetUniqueID(), *matrix, kTRUE);
149 lTransformer->AddMisAlignModule(matrix->GetUniqueID(), *matrix, useGlobalDelta);
2c1e4958 150 moduleIdToGMSIndex[matrix->GetUniqueID()]=i;
151 }
d148dd1c 152 // Store the GMS local delta-transformation
153 TClonesArray* data = const_cast< TClonesArray*>(fTransformer->GetMisAlignmentData());
04aa997f 154
155 //Now we have to store the final CDB file
f6e36ea4 156 Master()->Log("Storing GMS");
04aa997f 157 AliCDBMetaData metaData;
158 metaData.SetBeamPeriod(0);
159 metaData.SetResponsible("");
160 metaData.SetComment("This preprocessor fills GMS alignment objects.");
2c1e4958 161
d148dd1c 162 Bool_t result = Master()->Store("Align", "GMS", (TObject*)data, &metaData, 0, 0);
2c1e4958 163
164 // This section apply the GMS misalignments on top of the misalignments
165 // of the GMS reference run and stores the new misalignment array in the OCDB
d148dd1c 166
167 // Reset the geoemtry.
168 if (geoEntry) {
169 lGeometry = (TGeoManager*) geoEntry->GetObject();
170 }
171
172 if (lGeometry) {
173 TGeoManager::UnlockGeometry();
174 // Set Geometry
175 AliGeomManager::SetGeometry(lGeometry);
176 useGlobalDelta = kFALSE;
177 }
178
179 AliAlignObjMatrix* refAOMat = 0x0;
180 // First we need to get a copy of the local delta-transformations
181 TClonesArray* matLocalArray = new TClonesArray("TGeoHMatrix",200);
182 if (lGeometry && refArray) {
183 refArray->Sort(); // All Modules will be first then the DE
184 // Create new misalignment array
185 for (Int_t i=0; i<refArray->GetEntriesFast(); i++) {
186 refAOMat = (AliAlignObjMatrix*)refArray->At(i);
187 refAOMat->Print("");
188 TGeoHMatrix* reflMat = new((*matLocalArray)[i]) TGeoHMatrix();
189 refAOMat->GetLocalMatrix(*reflMat);
190 printf("ref misalignment local \n");
191 reflMat->Print();
192 }
193 }
2c1e4958 194
d148dd1c 195 AliAlignObjMatrix* newAOMat = 0x0;
196 // Get the GMS global delta-transformation
197 data = const_cast< TClonesArray*>(lTransformer->GetMisAlignmentData());
198 if (geoEntry && cdbEntry) {
199 if (lGeometry && refArray) {
2c1e4958 200 // Create new misalignment array
d148dd1c 201 TClonesArray* newArray = new TClonesArray("AliAlignObjMatrix", 200);
2c1e4958 202 for (Int_t i=0; i<refArray->GetEntriesFast(); i++) {
d148dd1c 203 refAOMat = (AliAlignObjMatrix*)refArray->At(i);
2c1e4958 204 TGeoHMatrix refMat;
205 refAOMat->GetMatrix(refMat);
d148dd1c 206 newAOMat = new((*newArray)[i]) AliAlignObjMatrix(*refAOMat); // Copy the reference misalignment object to the new array ...
2c1e4958 207 // Need the module containing this module or detection element
208 TString sName = refAOMat->GetSymName(); //Format "/MUON/GMx" or "/MUON/GMx/DEy"
209 Int_t iGM = sName.Index("GM");
210 Int_t iLS = sName.Last('/');
d148dd1c 211 if (iLS<iGM) { // This is a module
212 sName.Remove(0,iGM+2);
213 Int_t iMod = sName.Atoi();
214 if (moduleIdToGMSIndex[iMod]>=0) {
215 AliAlignObjMatrix* gmsAOMat = (AliAlignObjMatrix*)data->At(moduleIdToGMSIndex[iMod]);
216 TGeoHMatrix gmsMat;
217 gmsAOMat->GetMatrix(gmsMat);
218 printf("GMS global delta %i %i\n",iMod,moduleIdToGMSIndex[iMod]);
219 gmsMat.Print();
220 printf("ref misalignment \n");
221 refMat.Print();
222 refMat.MultiplyLeft(&gmsMat);
223 printf("new misalignment gms*ref\n");
224 refMat.Print();
225 }
226 else {
227 Master()->Log(Form("Missing GMS entry for module %d",iMod));
228 }
229 newAOMat->SetMatrix(refMat); // ... and set its matrix
230 }
231 else { // This is a module
232 newAOMat->SetLocalMatrix(*(TGeoHMatrix*)matLocalArray->At(i)); // ... and set its matrix
233 }
2c1e4958 234 }
235
236 //Now we have also to store this CDB file
237 TString sMDComment(cdbEntry->GetMetaData()->GetComment());
238 sMDComment += " GMS";
239 Master()->Log("Storing MisAlignment");
240 metaData.SetComment(sMDComment);
241
242 result = result && Master()->Store("Align", "Data", newArray, &metaData, 0, 1);
243 }
244 else {
d148dd1c 245 if (!refArray)
246 Master()->Log("Empty entry?");
247 if (!lGeometry)
248 Master()->Log("Couldn't find TGeoManager in the specified CDB entry?");
2c1e4958 249 }
250 }
251 else {
d148dd1c 252 if (!geoEntry)
253 Master()->Log("Could not get Geometry from OCDB! Will not add a new MUON/Align/Data entry!");
254 if (!cdbEntry)
255 Master()->Log("Could not get GMS reference misalignment from OCDB! Will not add a new MUON/Align/Data entry!");
2c1e4958 256 }
257 // Done with applying GMS misalignments on top of misalignment of reference run
258
04aa997f 259 // Clear MisAlignArray in transformer
d148dd1c 260 fTransformer->ClearMisAlignmentData();
2c1e4958 261
d489129d 262 return (result!=kTRUE);
968ce98e 263}
264
265//
266// public methods
267//
268
269
270//______________________________________________________________________________
271UInt_t AliMUONGMSSubprocessor::Process(TMap* /*dcsAliasMap*/)
272{
5ac93e67 273/// Process GMS alignment files.
274/// Return failure (0) in case procession of some file has failed
968ce98e 275
5ac93e67 276 UInt_t result = 1;
968ce98e 277 TList* sources = Master()->GetFileSources(fgkSystem, fgkDataId);
278 TIter next(sources);
279 TObjString* o(0x0);
280 while ( ( o = static_cast<TObjString*>(next()) ) ) {
281 TString fileName(Master()->GetFile(fgkSystem, fgkDataId, o->GetName()));
5ac93e67 282 result *= ProcessFile(fileName);
968ce98e 283 }
284 delete sources;
285
04aa997f 286 return result;
287}
288