]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGMSSubprocessor.cxx
In mapping:
[u/mrichter/AliRoot.git] / MUON / AliMUONGMSSubprocessor.cxx
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 "AliCDBMetaData.h"
32 #include "AliCDBEntry.h"
33
34 #include <TTimeStamp.h>
35 #include <TFile.h>
36 #include <TArrayI.h>
37 #include <TClonesArray.h>
38 #include <TObjString.h>
39 #include <Riostream.h>
40
41 /// \cond CLASSIMP
42 ClassImp(AliMUONGMSSubprocessor)
43 /// \endcond
44
45 const Int_t    AliMUONGMSSubprocessor::fgkSystem = AliPreprocessor::kDCS;
46 const TString  AliMUONGMSSubprocessor::fgkDataId = "GMS";
47 const TString  AliMUONGMSSubprocessor::fgkMatrixArrayName = "GMSarray";
48
49 //______________________________________________________________________________
50 AliMUONGMSSubprocessor::AliMUONGMSSubprocessor(AliMUONPreprocessor* master) 
51   : AliMUONVSubprocessor(master, "GMS", "Upload GMS matrices to OCDB"),
52     fTransformer(0)
53 {
54 /// Constructor
55 }
56
57 //______________________________________________________________________________
58 AliMUONGMSSubprocessor::~AliMUONGMSSubprocessor()
59 {
60 /// Destructor
61
62   delete fTransformer;
63 }
64
65
66 //
67 // private methods
68 //
69
70
71 //______________________________________________________________________________
72 Bool_t  AliMUONGMSSubprocessor::Initialize(Int_t /*run*/, 
73                                          UInt_t /*startTime*/, UInt_t /*endTime*/)
74 {
75 /// Instantiate geometry transformer
76
77   if ( ! fTransformer ) {
78     fTransformer = new AliMUONGeometryTransformer();
79     fTransformer->CreateModules();
80   }  
81   return kTRUE;
82 }                                           
83
84 //______________________________________________________________________________
85 UInt_t AliMUONGMSSubprocessor::ProcessFile(const TString& fileName)
86 {
87 /// Convert TGeoHMatrix to AliAlignObjMatrix and fill them into AliTestDataDCS object
88
89   Master()->Log(Form("Processing GMS file %s", fileName.Data()));
90   
91   // Open root file
92   TFile f(fileName.Data());
93   if ( ! f.IsOpen() ) {
94     Master()->Log(Form("Cannot open file %s",fileName.Data()));
95     return 1;
96   }  
97   
98   // Get array with matrices
99   TClonesArray* array = (TClonesArray*)f.Get(fgkMatrixArrayName);
100   if ( ! array ) {
101     Master()->Log(Form("TClonesArray not found in file %s",fileName.Data()));
102     return 2;
103   }    
104   
105   // Array to store correspondance between the moduleId 
106   // and its corresponding entry in the GMS array.
107   TArrayI moduleIdToGMSIndex;
108   moduleIdToGMSIndex.Set(AliMpConstants::NofGeomModules());
109   for (Int_t i=0; i<AliMpConstants::NofGeomModules(); i++){
110     moduleIdToGMSIndex[i]=-1;
111   }
112   
113   // Convert matrices into Alice alignment objects
114   for (Int_t i=0; i<array->GetEntriesFast(); i++ ) {
115     TGeoHMatrix* matrix = (TGeoHMatrix*)array->At(i);
116     fTransformer->AddMisAlignModule(matrix->GetUniqueID(), *matrix);
117     moduleIdToGMSIndex[matrix->GetUniqueID()]=i;
118   }
119   TObject* data = const_cast< TClonesArray*>(fTransformer->GetMisAlignmentData());
120   
121   //Now we have to store the final CDB file
122   Master()->Log("Storing GMS");
123   AliCDBMetaData metaData;
124   metaData.SetBeamPeriod(0);
125   metaData.SetResponsible("");
126   metaData.SetComment("This preprocessor fills GMS alignment objects.");
127   
128   Bool_t result = Master()->Store("Align", "GMS", data, &metaData, 0, 0);
129   
130   // This section apply the GMS misalignments on top of the misalignments 
131   // of the GMS reference run and stores the new misalignment array in the OCDB
132   
133   // Get mis alignment from reference run for GMS
134   AliCDBEntry* cdbEntry = Master()->GetFromOCDB("Align", "Baseline");
135   if (cdbEntry) {
136     TClonesArray* refArray = (TClonesArray*)cdbEntry->GetObject();
137     if (refArray) {
138       // Create new misalignment array
139       TClonesArray* newArray = new TClonesArray("AliAlignObjMatrix", 200);
140       for (Int_t i=0; i<refArray->GetEntriesFast(); i++) {
141         AliAlignObjMatrix* refAOMat = (AliAlignObjMatrix*)refArray->At(i);      
142         TGeoHMatrix refMat;
143         refAOMat->GetMatrix(refMat);
144         // Need the module containing this module or detection element
145         TString sName = refAOMat->GetSymName(); //Format "/MUON/GMx" or "/MUON/GMx/DEy"
146         Int_t iGM = sName.Index("GM");
147         Int_t iLS = sName.Last('/');
148         if (iLS>iGM) { // This is a detection element
149           sName.Remove(iLS,sName.Sizeof());
150         }
151         sName.Remove(0,iGM+2);
152         Int_t iMod = sName.Atoi();
153         if (moduleIdToGMSIndex[iMod]>=0) {
154           TGeoHMatrix* gmsMat = (TGeoHMatrix*)array->At(moduleIdToGMSIndex[iMod]);
155           refMat.MultiplyLeft(gmsMat);
156         }
157         else {
158           Master()->Log(Form("Missing GMS entry for module %d",iMod));
159         }
160         AliAlignObjMatrix* newAOMat = new((*newArray)[i]) AliAlignObjMatrix(*refAOMat); // Copy the reference misalignment object to the new array ...
161         newAOMat->SetMatrix(refMat); // ... and set its matrix
162       }
163       
164       //Now we have also to store this CDB file
165       TString sMDComment(cdbEntry->GetMetaData()->GetComment());
166       sMDComment += " GMS";
167       Master()->Log("Storing MisAlignment");
168       metaData.SetComment(sMDComment);
169       
170       result = result && Master()->Store("Align", "Data", newArray, &metaData, 0, 1);
171     }
172     else {
173       Master()->Log("Empty entry?");
174     }
175   }
176   else {
177     Master()->Log("Could not get GMS reference misalignment from OCDB! Will not add a new MUON/Align/Data entry!");    
178   }
179   // Done with applying GMS misalignments on top of misalignment of reference run
180   
181   // Clear MisAlignArray in transformer
182   fTransformer->ClearMisAlignmentData();
183   
184   return (result!=kTRUE);
185 }  
186
187 //
188 // public methods
189 //
190
191
192 //______________________________________________________________________________
193 UInt_t AliMUONGMSSubprocessor::Process(TMap* /*dcsAliasMap*/)
194 {
195 /// Process GMS alignment files.
196 /// Return failure (0) in case procession of some file has failed
197
198   UInt_t result = 1;
199   TList* sources = Master()->GetFileSources(fgkSystem, fgkDataId);
200   TIter next(sources);
201   TObjString* o(0x0);
202   while ( ( o = static_cast<TObjString*>(next()) ) ) {
203     TString fileName(Master()->GetFile(fgkSystem, fgkDataId, o->GetName()));
204     result *= ProcessFile(fileName);
205   }
206   delete sources;
207
208   return result;
209 }
210