1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 // Class AliMUONGMSSubprocessor
20 // -----------------------------
21 // The shuttle subprocessor for GMS data
22 // Author: Ivana Hrivnacova, IPN Orsay
24 //-----------------------------------------------------------------------------
26 #include "AliMUONGMSSubprocessor.h"
27 #include "AliMUONPreprocessor.h"
28 #include "AliMpConstants.h"
30 #include "AliAlignObjMatrix.h"
31 #include "AliGeomManager.h"
32 #include "AliCDBMetaData.h"
33 #include "AliCDBEntry.h"
35 #include <TTimeStamp.h>
38 #include <TClonesArray.h>
39 #include <TGeoManager.h>
40 #include <TObjString.h>
41 #include <Riostream.h>
44 ClassImp(AliMUONGMSSubprocessor)
47 const Int_t AliMUONGMSSubprocessor::fgkSystem = AliPreprocessor::kDCS;
48 const TString AliMUONGMSSubprocessor::fgkDataId = "GMS";
49 const TString AliMUONGMSSubprocessor::fgkMatrixArrayName = "GMSarray";
51 //______________________________________________________________________________
52 AliMUONGMSSubprocessor::AliMUONGMSSubprocessor(AliMUONPreprocessor* master)
53 : AliMUONVSubprocessor(master, "GMS", "Upload GMS matrices to OCDB"),
59 //______________________________________________________________________________
60 AliMUONGMSSubprocessor::~AliMUONGMSSubprocessor()
73 //______________________________________________________________________________
74 Bool_t AliMUONGMSSubprocessor::Initialize(Int_t /*run*/,
75 UInt_t /*startTime*/, UInt_t /*endTime*/)
77 /// Instantiate geometry transformer
79 if ( ! fTransformer ) {
80 fTransformer = new AliMUONGeometryTransformer();
81 fTransformer->CreateModules();
86 //______________________________________________________________________________
87 UInt_t AliMUONGMSSubprocessor::ProcessFile(const TString& fileName)
89 /// Convert TGeoHMatrix to AliAlignObjMatrix and fill them into AliTestDataDCS object
91 Master()->Log(Form("Processing GMS file %s", fileName.Data()));
94 TFile f(fileName.Data());
96 Master()->Log(Form("Cannot open file %s",fileName.Data()));
100 // Get array with matrices
101 TClonesArray* array = (TClonesArray*)f.Get(fgkMatrixArrayName);
103 Master()->Log(Form("TClonesArray not found in file %s",fileName.Data()));
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;
115 Bool_t useGlobalDelta = kTRUE;
116 // Get geometry from OCDB
117 AliCDBEntry* geoEntry = Master()->GetGeometryFromOCDB();
118 TGeoManager *lGeometry = 0x0;
120 lGeometry = (TGeoManager*) geoEntry->GetObject();
123 AliGeomManager::SetGeometry(lGeometry);
124 useGlobalDelta = kFALSE;
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();
132 // Get mis alignment from reference run for GMS
133 AliCDBEntry* cdbEntry = Master()->GetFromOCDB("Align", "Baseline");
134 TClonesArray* refArray = 0x0;
136 refArray = (TClonesArray*)cdbEntry->GetObject();
137 if (lGeometry && refArray) {
138 AliGeomManager::ApplyAlignObjsToGeom(*refArray);
139 lTransformer->LoadGeometryData();
143 // Convert matrices into Alice alignment objects
144 for (Int_t i=0; i<array->GetEntriesFast(); i++ ) {
145 TGeoHMatrix* matrix = (TGeoHMatrix*)array->At(i);
146 printf("GMS local %i at %i \n",matrix->GetUniqueID(),i);
148 fTransformer->AddMisAlignModule(matrix->GetUniqueID(), *matrix, kTRUE);
149 lTransformer->AddMisAlignModule(matrix->GetUniqueID(), *matrix, useGlobalDelta);
150 moduleIdToGMSIndex[matrix->GetUniqueID()]=i;
152 // Store the GMS local delta-transformation
153 TClonesArray* data = const_cast< TClonesArray*>(fTransformer->GetMisAlignmentData());
155 //Now we have to store the final CDB file
156 Master()->Log("Storing GMS");
157 AliCDBMetaData metaData;
158 metaData.SetBeamPeriod(0);
159 metaData.SetResponsible("");
160 metaData.SetComment("This preprocessor fills GMS alignment objects.");
162 Bool_t result = Master()->Store("Align", "GMS", (TObject*)data, &metaData, 0, 0);
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
167 // Reset the geoemtry.
169 lGeometry = (TGeoManager*) geoEntry->GetObject();
173 TGeoManager::UnlockGeometry();
175 AliGeomManager::SetGeometry(lGeometry);
176 useGlobalDelta = kFALSE;
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);
188 TGeoHMatrix* reflMat = new((*matLocalArray)[i]) TGeoHMatrix();
189 refAOMat->GetLocalMatrix(*reflMat);
190 printf("ref misalignment local \n");
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) {
200 // Create new misalignment array
201 TClonesArray* newArray = new TClonesArray("AliAlignObjMatrix", 200);
202 for (Int_t i=0; i<refArray->GetEntriesFast(); i++) {
203 refAOMat = (AliAlignObjMatrix*)refArray->At(i);
205 refAOMat->GetMatrix(refMat);
206 newAOMat = new((*newArray)[i]) AliAlignObjMatrix(*refAOMat); // Copy the reference misalignment object to the new array ...
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('/');
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]);
217 gmsAOMat->GetMatrix(gmsMat);
218 printf("GMS global delta %i %i\n",iMod,moduleIdToGMSIndex[iMod]);
220 printf("ref misalignment \n");
222 refMat.MultiplyLeft(&gmsMat);
223 printf("new misalignment gms*ref\n");
227 Master()->Log(Form("Missing GMS entry for module %d",iMod));
229 newAOMat->SetMatrix(refMat); // ... and set its matrix
231 else { // This is a module
232 newAOMat->SetLocalMatrix(*(TGeoHMatrix*)matLocalArray->At(i)); // ... and set its matrix
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);
242 result = result && Master()->Store("Align", "Data", newArray, &metaData, 0, 1);
246 Master()->Log("Empty entry?");
248 Master()->Log("Couldn't find TGeoManager in the specified CDB entry?");
253 Master()->Log("Could not get Geometry from OCDB! Will not add a new MUON/Align/Data entry!");
255 Master()->Log("Could not get GMS reference misalignment from OCDB! Will not add a new MUON/Align/Data entry!");
257 // Done with applying GMS misalignments on top of misalignment of reference run
259 // Clear MisAlignArray in transformer
260 fTransformer->ClearMisAlignmentData();
262 return (result!=kTRUE);
270 //______________________________________________________________________________
271 UInt_t AliMUONGMSSubprocessor::Process(TMap* /*dcsAliasMap*/)
273 /// Process GMS alignment files.
274 /// Return failure (0) in case procession of some file has failed
277 TList* sources = Master()->GetFileSources(fgkSystem, fgkDataId);
280 while ( ( o = static_cast<TObjString*>(next()) ) ) {
281 TString fileName(Master()->GetFile(fgkSystem, fgkDataId, o->GetName()));
282 result *= ProcessFile(fileName);