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;
53 //______________________________________________________________________________
54 const TString& AliMUONGMSSubprocessor::GetDataId()
57 static const TString kDataId = "GMS";
61 //______________________________________________________________________________
62 const TString& AliMUONGMSSubprocessor::GetMatrixArrayName()
64 /// The fixed matrix array name
65 static const TString kMatrixArrayName = "GMSarray";
66 return kMatrixArrayName;
73 //______________________________________________________________________________
74 AliMUONGMSSubprocessor::AliMUONGMSSubprocessor(AliMUONPreprocessor* master)
75 : AliMUONVSubprocessor(master, "GMS", "Upload GMS matrices to OCDB"),
81 //______________________________________________________________________________
82 AliMUONGMSSubprocessor::~AliMUONGMSSubprocessor()
94 //______________________________________________________________________________
95 Bool_t AliMUONGMSSubprocessor::Initialize(Int_t /*run*/,
96 UInt_t /*startTime*/, UInt_t /*endTime*/)
98 /// Instantiate geometry transformer
100 if ( ! fTransformer ) {
101 fTransformer = new AliMUONGeometryTransformer();
102 fTransformer->CreateModules();
107 //______________________________________________________________________________
108 UInt_t AliMUONGMSSubprocessor::ProcessFile(const TString& fileName)
110 /// Convert TGeoHMatrix to AliAlignObjMatrix and fill them into AliTestDataDCS object
112 Master()->Log(Form("Processing GMS file %s", fileName.Data()));
115 TFile f(fileName.Data());
116 if ( ! f.IsOpen() ) {
117 Master()->Log(Form("Cannot open file %s",fileName.Data()));
121 // Get array with matrices
122 TClonesArray* array = (TClonesArray*)f.Get(GetMatrixArrayName());
124 Master()->Log(Form("TClonesArray not found in file %s",fileName.Data()));
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;
136 Bool_t useGlobalDelta = kTRUE;
137 // Get geometry from OCDB
138 AliCDBEntry* geoEntry = Master()->GetGeometryFromOCDB();
139 TGeoManager *lGeometry = 0x0;
141 lGeometry = (TGeoManager*) geoEntry->GetObject();
144 AliGeomManager::SetGeometry(lGeometry);
145 useGlobalDelta = kFALSE;
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();
153 // Get mis alignment from reference run for GMS
154 AliCDBEntry* cdbEntry = Master()->GetFromOCDB("Align", "Baseline");
155 TClonesArray* refArray = 0x0;
157 refArray = (TClonesArray*)cdbEntry->GetObject();
158 if (lGeometry && refArray) {
159 AliGeomManager::ApplyAlignObjsToGeom(*refArray);
160 lTransformer->LoadGeometryData();
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);
169 fTransformer->AddMisAlignModule(matrix->GetUniqueID(), *matrix, kTRUE);
170 lTransformer->AddMisAlignModule(matrix->GetUniqueID(), *matrix, useGlobalDelta);
171 moduleIdToGMSIndex[matrix->GetUniqueID()]=i;
173 // Store the GMS local delta-transformation
174 TClonesArray* data = const_cast< TClonesArray*>(fTransformer->GetMisAlignmentData());
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.");
183 Bool_t result = Master()->Store("Align", "GMS", (TObject*)data, &metaData, 0, 0);
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
188 // Reset the geoemtry.
190 lGeometry = (TGeoManager*) geoEntry->GetObject();
194 TGeoManager::UnlockGeometry();
196 AliGeomManager::SetGeometry(lGeometry);
197 useGlobalDelta = kFALSE;
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);
209 TGeoHMatrix* reflMat = new((*matLocalArray)[i]) TGeoHMatrix();
210 refAOMat->GetLocalMatrix(*reflMat);
211 printf("ref misalignment local \n");
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);
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]);
238 gmsAOMat->GetMatrix(gmsMat);
239 printf("GMS global delta %i %i\n",iMod,moduleIdToGMSIndex[iMod]);
241 printf("ref misalignment \n");
243 refMat.MultiplyLeft(&gmsMat);
244 printf("new misalignment gms*ref\n");
248 Master()->Log(Form("Missing GMS entry for module %d",iMod));
250 newAOMat->SetMatrix(refMat); // ... and set its matrix
252 else { // This is a module
253 newAOMat->SetLocalMatrix(*(TGeoHMatrix*)matLocalArray->At(i)); // ... and set its matrix
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);
263 result = result && Master()->Store("Align", "Data", newArray, &metaData, 0, 1);
267 Master()->Log("Empty entry?");
269 Master()->Log("Couldn't find TGeoManager in the specified CDB entry?");
274 Master()->Log("Could not get Geometry from OCDB! Will not add a new MUON/Align/Data entry!");
276 Master()->Log("Could not get GMS reference misalignment from OCDB! Will not add a new MUON/Align/Data entry!");
278 // Done with applying GMS misalignments on top of misalignment of reference run
280 // Clear MisAlignArray in transformer
281 fTransformer->ClearMisAlignmentData();
283 return (result!=kTRUE);
291 //______________________________________________________________________________
292 UInt_t AliMUONGMSSubprocessor::Process(TMap* /*dcsAliasMap*/)
294 /// Process GMS alignment files.
295 /// Return failure (0) in case procession of some file has failed
298 TList* sources = Master()->GetFileSources(fgkSystem, GetDataId());
301 while ( ( o = static_cast<TObjString*>(next()) ) ) {
302 TString fileName(Master()->GetFile(fgkSystem, GetDataId(), o->GetName()));
303 result *= ProcessFile(fileName);