]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONGMSSubprocessor.cxx
- Fix problem with EventSpecie when running online in DQM. The problem prevented...
[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
31edb2d7 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//
04aa997f 72
968ce98e 73//______________________________________________________________________________
04aa997f 74AliMUONGMSSubprocessor::AliMUONGMSSubprocessor(AliMUONPreprocessor* master)
75 : AliMUONVSubprocessor(master, "GMS", "Upload GMS matrices to OCDB"),
789260b4 76 fTransformer(0)
04aa997f 77{
78/// Constructor
04aa997f 79}
80
968ce98e 81//______________________________________________________________________________
04aa997f 82AliMUONGMSSubprocessor::~AliMUONGMSSubprocessor()
83{
84/// Destructor
789260b4 85
86 delete fTransformer;
04aa997f 87}
88
968ce98e 89
90//
91// private methods
92//
93
789260b4 94//______________________________________________________________________________
6c870207 95Bool_t AliMUONGMSSubprocessor::Initialize(Int_t /*run*/,
789260b4 96 UInt_t /*startTime*/, UInt_t /*endTime*/)
97{
98/// Instantiate geometry transformer
99
100 if ( ! fTransformer ) {
101 fTransformer = new AliMUONGeometryTransformer();
102 fTransformer->CreateModules();
103 }
6c870207 104 return kTRUE;
789260b4 105}
106
968ce98e 107//______________________________________________________________________________
108UInt_t AliMUONGMSSubprocessor::ProcessFile(const TString& fileName)
04aa997f 109{
110/// Convert TGeoHMatrix to AliAlignObjMatrix and fill them into AliTestDataDCS object
111
f6e36ea4 112 Master()->Log(Form("Processing GMS file %s", fileName.Data()));
2c1e4958 113
04aa997f 114 // Open root file
968ce98e 115 TFile f(fileName.Data());
116 if ( ! f.IsOpen() ) {
f6e36ea4 117 Master()->Log(Form("Cannot open file %s",fileName.Data()));
d489129d 118 return 1;
968ce98e 119 }
04aa997f 120
121 // Get array with matrices
31edb2d7 122 TClonesArray* array = (TClonesArray*)f.Get(GetMatrixArrayName());
04aa997f 123 if ( ! array ) {
f6e36ea4 124 Master()->Log(Form("TClonesArray not found in file %s",fileName.Data()));
d489129d 125 return 2;
2c1e4958 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 }
04aa997f 135
d148dd1c 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
04aa997f 164 // Convert matrices into Alice alignment objects
165 for (Int_t i=0; i<array->GetEntriesFast(); i++ ) {
166 TGeoHMatrix* matrix = (TGeoHMatrix*)array->At(i);
d148dd1c 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);
2c1e4958 171 moduleIdToGMSIndex[matrix->GetUniqueID()]=i;
172 }
d148dd1c 173 // Store the GMS local delta-transformation
174 TClonesArray* data = const_cast< TClonesArray*>(fTransformer->GetMisAlignmentData());
04aa997f 175
176 //Now we have to store the final CDB file
f6e36ea4 177 Master()->Log("Storing GMS");
04aa997f 178 AliCDBMetaData metaData;
179 metaData.SetBeamPeriod(0);
180 metaData.SetResponsible("");
181 metaData.SetComment("This preprocessor fills GMS alignment objects.");
2c1e4958 182
d148dd1c 183 Bool_t result = Master()->Store("Align", "GMS", (TObject*)data, &metaData, 0, 0);
2c1e4958 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
d148dd1c 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 }
2c1e4958 215
d148dd1c 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) {
2c1e4958 221 // Create new misalignment array
d148dd1c 222 TClonesArray* newArray = new TClonesArray("AliAlignObjMatrix", 200);
2c1e4958 223 for (Int_t i=0; i<refArray->GetEntriesFast(); i++) {
d148dd1c 224 refAOMat = (AliAlignObjMatrix*)refArray->At(i);
2c1e4958 225 TGeoHMatrix refMat;
226 refAOMat->GetMatrix(refMat);
d148dd1c 227 newAOMat = new((*newArray)[i]) AliAlignObjMatrix(*refAOMat); // Copy the reference misalignment object to the new array ...
2c1e4958 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('/');
d148dd1c 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 }
2c1e4958 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 {
d148dd1c 266 if (!refArray)
267 Master()->Log("Empty entry?");
268 if (!lGeometry)
269 Master()->Log("Couldn't find TGeoManager in the specified CDB entry?");
2c1e4958 270 }
271 }
272 else {
d148dd1c 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!");
2c1e4958 277 }
278 // Done with applying GMS misalignments on top of misalignment of reference run
279
04aa997f 280 // Clear MisAlignArray in transformer
d148dd1c 281 fTransformer->ClearMisAlignmentData();
2c1e4958 282
d489129d 283 return (result!=kTRUE);
968ce98e 284}
285
286//
287// public methods
288//
289
290
291//______________________________________________________________________________
292UInt_t AliMUONGMSSubprocessor::Process(TMap* /*dcsAliasMap*/)
293{
5ac93e67 294/// Process GMS alignment files.
295/// Return failure (0) in case procession of some file has failed
968ce98e 296
5ac93e67 297 UInt_t result = 1;
31edb2d7 298 TList* sources = Master()->GetFileSources(fgkSystem, GetDataId());
968ce98e 299 TIter next(sources);
300 TObjString* o(0x0);
301 while ( ( o = static_cast<TObjString*>(next()) ) ) {
31edb2d7 302 TString fileName(Master()->GetFile(fgkSystem, GetDataId(), o->GetName()));
5ac93e67 303 result *= ProcessFile(fileName);
968ce98e 304 }
305 delete sources;
306
04aa997f 307 return result;
308}
309