LCOV - code coverage report
Current view: top level - MUON/MUONshuttle - AliMUONGMSSubprocessor.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 135 0.7 %
Date: 2016-06-14 17:26:59 Functions: 1 11 9.1 %

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

Generated by: LCOV version 1.11