LCOV - code coverage report
Current view: top level - MUON/MUONshuttle - AliMUONConfigSubprocessor.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 74 1.4 %
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             : #include "AliMUONConfigSubprocessor.h"
      19             : 
      20             : #include "AliCDBMetaData.h"
      21             : #include "AliCDBEntry.h"
      22             : #include "AliDAQ.h"
      23             : #include "AliLog.h"
      24             : #include "AliMUON2DMap.h"
      25             : #include "AliMUON2DStoreValidator.h"
      26             : #include "AliMUONCalibParamNF.h"
      27             : #include "AliMUONPreprocessor.h"
      28             : #include "AliMUONTrackerIO.h"
      29             : #include "AliMpConstants.h"
      30             : #include "AliMpDDLStore.h"
      31             : #include "TObjString.h"
      32             : #include <Riostream.h>
      33             : #include <TList.h>
      34             : #include <TObjString.h>
      35             : #include <TSystem.h>
      36             : #include <sstream>
      37             : 
      38             : //-----------------------------------------------------------------------------
      39             : /// \class AliMUONConfigSubprocessor
      40             : ///
      41             : /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK readout configuration.
      42             : ///
      43             : /// Configs are read in from an ascii file, with the format :               \n
      44             : ///---------------------------------------------------------------------------\n
      45             : /// BUS_PATCH MANU_ADDR
      46             : ///---------------------------------------------------------------------------\n
      47             : ///
      48             : /// \author L. Aphecetche
      49             : //-----------------------------------------------------------------------------
      50             : 
      51             : /// \cond CLASSIMP
      52          12 : ClassImp(AliMUONConfigSubprocessor)
      53             : /// \endcond
      54             : 
      55             : //_____________________________________________________________________________
      56             : AliMUONConfigSubprocessor::AliMUONConfigSubprocessor(AliMUONPreprocessor* master)
      57           0 : : AliMUONVSubprocessor(master,
      58             :                        "Config",
      59             :                        "Upload MUON Tracker readout configuration to OCDB"),
      60           0 : fConfig(0x0),
      61           0 : fConfigChanged(kFALSE)
      62           0 : {
      63             :   /// default ctor
      64           0 : }
      65             : 
      66             : //_____________________________________________________________________________
      67             : AliMUONConfigSubprocessor::~AliMUONConfigSubprocessor()
      68           0 : {
      69             :   /// dtor
      70           0 :   delete fConfig;
      71           0 : }
      72             : 
      73             : //_____________________________________________________________________________
      74             : Bool_t
      75             : AliMUONConfigSubprocessor::HasConfigChanged(const AliMUONVStore& newConfig) const
      76             : {
      77             :   /// Check whether the config changed. 
      78             :   /// Any error will return kTRUE to trig a config upload (safer way).
      79             :   
      80           0 :   AliCDBEntry* entry = Master()->GetFromOCDB("Calib","Config");
      81           0 :   if (!entry)
      82             :   {
      83           0 :     AliError("Could not get MUON/Calib/Config entry for current run ! That's not OK !");
      84           0 :     return kTRUE;
      85             :   }
      86           0 :   AliMUONVStore* oldConfig = dynamic_cast<AliMUONVStore*>(entry->GetObject());
      87           0 :   if (!oldConfig)
      88             :   {
      89           0 :     AliError("Could not get MUON/Calib/Config object for current run (wrong type ?) ! That's not OK !");
      90           0 :     return kTRUE;
      91             :   }
      92             :   
      93           0 :   if ( oldConfig->GetSize() != newConfig.GetSize() ) 
      94             :   {
      95           0 :     return kTRUE;
      96             :   }
      97             :   
      98           0 :   TIter next(oldConfig->CreateIterator());
      99             :   AliMUONVCalibParam* old;
     100             :   
     101           0 :   while ( ( old = static_cast<AliMUONVCalibParam*>(next()) ) )
     102             :   {
     103           0 :     Int_t detElemId = old->ID0();
     104           0 :     Int_t manuId = old->ID1();
     105             :     
     106           0 :     if ( ! newConfig.FindObject(detElemId,manuId) )
     107             :     {
     108             :       // not found in new. Configurations are different. Return right now.
     109           0 :       return kTRUE;
     110             :     }
     111           0 :   }
     112             :   
     113             :   // all tests OK. Configuration has not changed.
     114           0 :   return kFALSE;
     115           0 : }
     116             : 
     117             : 
     118             : //_____________________________________________________________________________
     119             : Bool_t 
     120             : AliMUONConfigSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
     121             : {
     122             :   /// When starting a new run, reads in the config ASCII files.
     123             :   
     124             :   const Int_t kSystem = AliMUONPreprocessor::kDAQ;
     125             :   const char* kIdConf = "CONFIG";
     126             : 
     127           0 :   delete fConfig;
     128           0 :   fConfig = new AliMUON2DMap(kTRUE);
     129             :   
     130           0 :   TList* sources = Master()->GetFileSources(kSystem,kIdConf);
     131           0 :   TIter nextConf(sources);
     132             :   Int_t nconf(0);
     133             :   Int_t nconfFiles(0);
     134             :   TObjString* o;
     135             :   
     136           0 :   while ( ( o = static_cast<TObjString*>(nextConf()) ) )
     137             :   {
     138           0 :     TString fileName(Master()->GetFile(kSystem,kIdConf,o->GetName()));
     139           0 :     Int_t ok = ReadConfigFile(fileName.Data());
     140           0 :     if (ok>0)
     141             :     {
     142           0 :       nconf += ok;
     143           0 :       ++nconfFiles;
     144           0 :     }
     145           0 :   }
     146             :   
     147           0 :   delete sources;
     148             :   
     149           0 :   if ( nconfFiles == 0 )
     150             :   {
     151           0 :     delete fConfig;
     152           0 :     fConfig = 0x0;
     153           0 :     fConfigChanged = kFALSE;
     154           0 :     AliInfo("No configuration files found for this run. That might be fine. Moving on...");
     155           0 :     return kTRUE;
     156             :   }
     157             : 
     158           0 :   fConfigChanged = HasConfigChanged(*fConfig);
     159             :   
     160           0 :   if (!fConfigChanged)
     161             :   {
     162           0 :     AliInfo("Will not upload the Configuration as it has not changed");
     163             :   }
     164             :   
     165           0 :   return kTRUE;
     166           0 : }
     167             : 
     168             : //_____________________________________________________________________________
     169             : UInt_t 
     170             : AliMUONConfigSubprocessor::Process(TMap* /*dcsAliasMap*/)
     171             : {
     172             :   /// Store the config into the CDB
     173             :   /// So far there is no way this sub processor can fail...
     174             :   
     175           0 :   if (!fConfig)
     176             :   {
     177           0 :     return 0;
     178             :   }
     179             :     
     180           0 :   if ( !fConfigChanged )
     181             :   {
     182           0 :     return 0;
     183             :   }
     184             :   
     185           0 :   Master()->Log("Storing readout configuration, as it has changed");
     186             :   
     187           0 :   AliCDBMetaData metaData;
     188           0 :         metaData.SetBeamPeriod(0);
     189           0 :         metaData.SetResponsible("MUON TRK");
     190           0 :   TString comment("Computed by AliMUONConfigSubprocessor $Id$");
     191           0 :   comment.ReplaceAll("$","");
     192           0 :         metaData.SetComment(comment.Data());
     193             :   
     194             :   Bool_t validToInfinity = kFALSE;
     195           0 :         Bool_t result = Master()->Store("Calib", "Config", fConfig, &metaData, 0, validToInfinity);
     196           0 :   return ( result != kTRUE ); // return 0 if everything is ok.
     197           0 : }
     198             : 
     199             : //_____________________________________________________________________________
     200             : Int_t
     201             : AliMUONConfigSubprocessor::ReadConfigFile(const char* filename)
     202             : {
     203             :   /// Read the configuration from an ASCII file.                              
     204             :   /// Format of that file is one line per manu :                              
     205             :   /// BUS_PATCH MANU_ADDR
     206             :   /// Return kFALSE if reading was not successfull.                           
     207             :   ///
     208             :   
     209           0 :   TString sFilename(gSystem->ExpandPathName(filename));
     210             :   
     211           0 :   Master()->Log(Form("Reading %s",sFilename.Data()));
     212             :   
     213           0 :   Int_t n = AliMUONTrackerIO::ReadConfig(sFilename.Data(),*fConfig);
     214             :   
     215           0 :   switch (n)
     216             :   {
     217             :     case -1:
     218           0 :       Master()->Log(Form("Could not open %s",sFilename.Data()));
     219             :       break;
     220             :   }
     221             :   
     222             :   return n;
     223           0 : }
     224             : 
     225             : 
     226             : //_____________________________________________________________________________
     227             : void
     228             : AliMUONConfigSubprocessor::Print(Option_t* opt) const
     229             : {
     230             :   /// ouput to screen
     231           0 :   if (fConfig) fConfig->Print("",opt);
     232           0 : }
     233             : 

Generated by: LCOV version 1.11