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