Adding AliMUONCDB::ShowFaultyBusPatches method to make tracking of misbehaving buspat...
authorlaphecet <laphecet@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 24 Mar 2011 12:58:11 +0000 (12:58 +0000)
committerlaphecet <laphecet@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 24 Mar 2011 12:58:11 +0000 (12:58 +0000)
MUON/AliMUONCDB.cxx
MUON/AliMUONCDB.h
MUON/AliMUONTrackerConditionDataMaker.cxx
MUON/AliMUONTrackerData.cxx
MUON/AliMUONTrackerData.h

index 0c4e84a..0113ab7 100644 (file)
@@ -48,6 +48,7 @@
 #include "AliMUONRecoParam.h"
 #include "AliMUONRegionalTriggerConfig.h"
 #include "AliMUONRejectList.h"
+#include "AliMUONTrackerData.h"
 #include "AliMUONTrackerIO.h"
 #include "AliMUONTriggerEfficiencyCells.h"
 #include "AliMUONTriggerLut.h"
@@ -55,7 +56,6 @@
 #include "AliMUONVCalibParam.h"
 #include "AliMUONVStore.h"
 
-
 #include "AliMpCDB.h"
 #include "AliMpConstants.h"
 #include "AliMpDEStore.h"
@@ -81,6 +81,7 @@
 #include <Riostream.h>
 #include <TArrayI.h>
 #include <TClass.h>
+#include <TFile.h>
 #include <TH1F.h>
 #include <TList.h>
 #include <TMap.h>
@@ -93,6 +94,7 @@
 #include <TGeoGlobalMagField.h>
 #include <TClonesArray.h>
 #include <sstream>
+#include <set>
 
 namespace
 {
@@ -1645,3 +1647,166 @@ AliMUONCDB::ShowConfig(Bool_t withStatusMap)
   delete cd;
   delete statusMaker;  
 }
+
+//______________________________________________________________________________
+void AliMUONCDB::ReadIntegers(const char* filename, std::vector<int>& integers)
+{
+  /// Read integers from filename, where integers are either
+  /// separated by "," or by return carriage
+  ifstream in(gSystem->ExpandPathName(filename));
+  int i;
+  
+  std::set<int> runset;
+  
+  char line[10000];
+  
+  in.getline(line,10000,'\n');
+  
+  TString sline(line);
+  
+  if (sline.Contains(","))
+  {
+    TObjArray* a = sline.Tokenize(",");
+    TIter next(a);
+    TObjString* s;
+    while ( ( s = static_cast<TObjString*>(next()) ) )
+    {
+      runset.insert(s->String().Atoi());
+    }
+    delete a;
+  }
+  else
+  {
+    runset.insert(sline.Atoi());
+    
+    while ( in >> i )
+    {
+      runset.insert(i);
+    }
+  }
+  
+  for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it ) 
+  {
+    integers.push_back((*it)); 
+  }
+  
+  std::sort(integers.begin(),integers.end());
+}
+
+//______________________________________________________________________________
+void AliMUONCDB::ShowFaultyBusPatches(const char* runlist, double occLimit,
+                                      const char* outputBaseName,
+                                      const char* ocdbPath)
+{
+  /// Shows the list of bus patches above a given occupancy limit,
+  /// for each run in the runlist
+  
+  AliLog::GetRootLogger()->SetGlobalLogLevel(AliLog::kError);
+  
+  //  AliLog::SetPrintType(AliLog::kInfo,kFALSE);
+  //  AliLog::SetPrintType(AliLog::kWarning,kFALSE);
+  //  gErrorIgnoreLevel=kError; // to avoid all the TAlienFile::Open messages...
+  
+  AliCDBManager* man = AliCDBManager::Instance();
+  
+  man->SetDefaultStorage(ocdbPath);
+  
+  Bool_t first(kTRUE);
+  
+  std::vector<int> runnumbers;
+  
+  ReadIntegers(runlist,runnumbers);
+  
+  AliMUON2DMap bpValues(kFALSE);
+  
+  std::ofstream outfile(Form("%s.txt",outputBaseName));
+  
+  for ( unsigned int i = 0 ; i < runnumbers.size(); ++i )
+  {
+    int runNumber = runnumbers[i];
+    
+    man->SetRun(runNumber);
+    
+    if ( first ) 
+    {
+      AliMpCDB::LoadAll();  
+      first = kFALSE;
+    }
+    
+    AliCDBEntry* e = man->Get("MUON/Calib/OccupancyMap",runNumber);
+    
+    AliMUONVStore* occmap = static_cast<AliMUONVStore*>(e->GetObject());
+    
+    AliMUONTrackerData td("occ","occ",*occmap);
+    
+    TIter nextBP(AliMpDDLStore::Instance()->CreateBusPatchIterator());
+    AliMpBusPatch* bp;
+    std::set<int> buspatches;
+    Double_t sumn = 1000.0;
+    
+    while ( ( bp = static_cast<AliMpBusPatch*>(nextBP()) ) )
+    {      
+      Double_t occ = td.BusPatch(bp->GetId(),2);
+      
+      if (occ>occLimit) 
+      {
+        buspatches.insert(bp->GetId());
+        
+        AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(bpValues.FindObject(bp->GetId()));
+        
+        if (!param)
+        {
+          param = new AliMUONCalibParamND(5, 1, bp->GetId(), 0);
+          bpValues.Add(param);
+          
+          Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(bp->GetId());
+          AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
+          
+          Int_t nchannels(0);
+          
+          for ( Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu ) 
+          {
+            Int_t manuId = bp->GetManuId(imanu);
+            nchannels += de->NofChannelsInManu(manuId);
+          }
+          
+          param->SetValueAsDouble(0,2,sumn);
+          param->SetValueAsDouble(0,3,nchannels);
+          param->SetValueAsDouble(0,4,1);          
+        }
+        
+        Double_t sumw = sumn*(param->ValueAsDouble(0)/sumn+1.0/runnumbers.size());
+        Double_t sumw2 = 0.0; //(sumn-1)*ey*ey+sumw*sumw/sumn;
+        
+        param->SetValueAsDouble(0,0,sumw);
+        param->SetValueAsDouble(0,1,sumw2);
+        
+      }
+    }
+    
+    outfile << Form("RUN %09d",runNumber);
+    
+    for ( std::set<int>::const_iterator bit = buspatches.begin(); bit != buspatches.end(); ++bit )
+    {
+      outfile << Form(" %4d",*bit);
+    }
+    outfile << endl;
+  }
+  
+  outfile.close();
+  
+  const char* name = "BPfailureRate";
+  
+  AliMUONTrackerData* mpData = new AliMUONTrackerData(name,name,bpValues,2);
+  mpData->SetDimensionName(0,name);
+  
+  TFile f(Form("%s.root",outputBaseName),"recreate");
+  mpData->Write();
+  f.Close();
+  
+  cout << Form("Results are in %s.txt and %s.root",outputBaseName,outputBaseName) << endl;
+  
+  gSystem->Exec(Form("cat %s.txt",outputBaseName));
+  
+}
+
index f4ad60c..73145d9 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <TString.h>
 #include "AliCDBRunRange.h"
+#include <vector>
 
 class AliMUONVStore;
 class TMap;
@@ -57,10 +58,17 @@ namespace AliMUONCDB
   
   void Plot(const AliMUONVStore& store, const char* name, Int_t nbins=512);
 
+  void ReadIntegers(const char* filename, std::vector<int>& integers);
+
   void ShowConfig(Bool_t withStatusMap=kFALSE);
   
   void ShowCapacitances();
   
+  void ShowFaultyBusPatches(const char* runlist, 
+                            double occLimit=0.1,
+                            const char* outputBaseName="faulty.buspatches",
+                            const char* ocdbPath="raw://");
+  
   void WriteToCDB(const char* calibpath, TObject* object,
                   Int_t startRun, Int_t endRun, Bool_t defaultValues);
   void WriteToCDB(const char* calibpath, TObject* object,
index 868c2e3..4379f55 100644 (file)
@@ -100,15 +100,14 @@ fIsOwnerOfData(kTRUE)
   else
   {
     Int_t startOfValidity;
-  AliMUONVStore* store = CreateStore(runNumber,ocdbPath,type,startOfValidity);
+    AliMUONVStore* store = CreateStore(runNumber,ocdbPath,type,startOfValidity);
     AliDebug(1,Form("runNumber=%d ocdbPath=%s type=%s startOfValidity=%d store=%p",
                     runNumber,ocdbPath,type,startOfValidity,store));
     if ( store )
     {
       fData = CreateData(type,*store,startOfValidity);
-    }  
-    
-    delete store;
+    }
+    // we do not delete the store, as it's supposedly part of the OCDB cache...
   }
   
   AliCDBManager::Instance()->SetDefaultStorage(storage);
@@ -482,6 +481,7 @@ AliMUONTrackerConditionDataMaker::CreateStore(Int_t runNumber,
     if ( ocdb ) 
     {
       store = AliMUONCalibrationData::CreateOccupancyMap(runNumber,&startOfValidity);
+      if (store) store = static_cast<AliMUONVStore*>(store->Clone());
     }
     else
     {
index 4481d4f..a4b5190 100644 (file)
@@ -253,7 +253,7 @@ fNofEventsPerDDL(0x0)
 
 //_____________________________________________________________________________
 AliMUONTrackerData::AliMUONTrackerData(const char* name, const char* title,
-                                       const AliMUONVStore& deValues, Int_t val)
+                                       const AliMUONVStore& deOrBpValues, Int_t val)
 : AliMUONVTrackerData(name,title),
 fIsSingleEvent(kFALSE),
 fChannelValues(0x0),
@@ -278,26 +278,42 @@ fIsPCBLevelEnabled(kFALSE),
 fNofDDLs(0),
 fNofEventsPerDDL(0x0)
 {  
-  /// ctor with values at the detection element level
+  /// ctor with values at the detection element OR bus patch level
   /// In this case, we force fIsChannelLevelEnabled = fIsManuLevelEnabled = kFALSE
   /// ctor
   
-  if (deValues.GetSize()==0)
+  if (deOrBpValues.GetSize()==0)
   {
     AliFatal("Cannot create a tracker data from nothing in that case !");
   }
   
-  if ( val != 1 ) 
-  {
-    AliFatal("Wrong parameter. For DE, must be 1");
-  }
-  
   if ( !AliMpDDLStore::Instance(kFALSE) && !AliMpManuStore::Instance(kFALSE) )
   {
     AliError("Cannot work without (full) mapping");
     return;
   }
   
+  if ( val == 1 ) 
+  {
+    BuildFromDEStore(deOrBpValues);
+  }
+  else if ( val == 2 )
+  {
+    BuildFromBPStore(deOrBpValues);
+  }
+  else
+  {
+    AliFatal("Wrong parameter. Must be 1 or 2");
+  }
+  
+  
+}
+
+//_____________________________________________________________________________
+void AliMUONTrackerData::BuildFromDEStore(const AliMUONVStore& deValues)
+{
+  /// Fill internals from a store of values at the detection element level
+  
   TIter next(deValues.CreateIterator());
   AliMUONVCalibParam* m = static_cast<AliMUONVCalibParam*>(next());
   
@@ -326,7 +342,7 @@ fNofEventsPerDDL(0x0)
   while ( ( external = static_cast<AliMUONVCalibParam*>(next()) ) )
   {
     Int_t detElemId = external->ID0();
-
+    
     AliMpDetElement* mpde = AliMpDDLStore::Instance()->GetDetElement(detElemId,kFALSE);
     
     if (!mpde)
@@ -338,7 +354,7 @@ fNofEventsPerDDL(0x0)
     Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
     AliMUONVCalibParam* chamber = ChamberParam(chamberId,kTRUE);
     AliMUONVCalibParam* de = DetectionElementParam(detElemId,kTRUE);
-
+    
     AliMUONVCalibParam* wec = new AliMUONCalibParamND(external->Dimension()-1,1,detElemId,0,0);
     // as external, but without event count
     wec->SetValueAsDouble(0,0,external->ValueAsDouble(0,0));
@@ -383,7 +399,104 @@ fNofEventsPerDDL(0x0)
   }  
   
   UpdateNumberOfEvents(&nevents);
+}
+
+//_____________________________________________________________________________
+void AliMUONTrackerData::BuildFromBPStore(const AliMUONVStore& bpValues)
+{
+  /// Fill internals from a store of values at the bus patch level
+  
+  fIsBustPatchLevelEnabled = kTRUE;
+  
+  TIter next(bpValues.CreateIterator());
+  AliMUONVCalibParam* m = static_cast<AliMUONVCalibParam*>(next());
+  
+  Int_t dimension = ( m->Dimension() - fgkExtraDimension - fgkVirtualExtraDimension ) / 2;
+  
+  fDimension = External2Internal(dimension)+fgkExtraDimension;
+  
+  fDimensionNames = new TObjArray(fDimension+fgkVirtualExtraDimension);
+  fExternalDimensionNames = new TObjArray(dimension);
+  fExternalDimension = dimension;
+  fHistogramming = new Int_t[fExternalDimension];
+  memset(fHistogramming,0,fExternalDimension*sizeof(Int_t)); // histogramming is off by default. Use MakeHistogramForDimension to turn it on.
+  
+  fExternalDimensionNames->SetOwner(kTRUE);
+  fDimensionNames->SetOwner(kTRUE);  
+  fDimensionNames->AddAt(new TObjString("occ"),IndexOfOccupancyDimension());
+  fDimensionNames->AddAt(new TObjString("N"),IndexOfNumberDimension());
+  fDimensionNames->AddAt(new TObjString("n"),NumberOfDimensions()-fgkVirtualExtraDimension);
+  Clear();
+  TArrayI nevents(AliDAQ::NumberOfDdls("MUONTRK"));
+  AssertStores();
+  
+  next.Reset();
+  AliMUONVCalibParam* external;
+  
+  while ( ( external = static_cast<AliMUONVCalibParam*>(next()) ) )
+  {
+    Int_t busPatchId = external->ID0();
+    
+    AliMpBusPatch* mpbp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId,kFALSE);
+    
+    if (!mpbp)
+    {
+      AliError(Form("Got an invalid buspatchId (%d) from external store",busPatchId));
+      continue;
+    }
+    
+    Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
+    Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
+    AliMUONVCalibParam* chamber = ChamberParam(chamberId,kTRUE);
+    AliMUONVCalibParam* de = DetectionElementParam(detElemId,kTRUE);
+    AliMUONVCalibParam* bp = BusPatchParam(busPatchId,kTRUE);
+    
+    AliMUONVCalibParam* wec = new AliMUONCalibParamND(external->Dimension()-1,1,busPatchId,0,0);
+    // as external, but without event count
+    wec->SetValueAsDouble(0,0,external->ValueAsDouble(0,0));
+    wec->SetValueAsDouble(0,1,external->ValueAsDouble(0,1));
+    wec->SetValueAsDouble(0,2,external->ValueAsDouble(0,2));
+    wec->SetValueAsDouble(0,3,external->ValueAsDouble(0,3));
+    
+    Int_t n1 = bp->ValueAsInt(0,IndexOfNumberDimension());
+    Int_t n2 = external->ValueAsInt(0,IndexOfNumberDimension());
+    if  ( n1 != n2 )
+    {
+      AliError(Form("Incoherent number of dimensions for BP%d : %d vs %d",
+                    busPatchId,n1,n2));
+      continue;
+    }
+    
+    Int_t nevt = external->ValueAsInt(0,4);
+    
+    Int_t ddl = mpbp->GetDdlId();
+    
+    if ( nevents[ddl] == 0 ) 
+    {
+      nevents[ddl] = nevt;
+    }
+    else
+    {
+      if ( nevents.At(ddl) != nevt ) 
+      {
+        AliError(Form("Nevt mismatch for BP %5d  DDL %d : %d vs %d",
+                      busPatchId,ddl,nevents.At(ddl),nevt));
+        continue;
+      }
+    }
+    
+    for ( Int_t i = 0; i < wec->Dimension()-1; ++i ) 
+    {
+      bp->SetValueAsDouble(0,i,bp->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
+      
+      de->SetValueAsDouble(0,i,de->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
+      
+      chamber->SetValueAsDouble(0,i,chamber->ValueAsDouble(0,i) + wec->ValueAsDouble(0,i));
+    }    
+    delete wec;
+  }  
   
+  UpdateNumberOfEvents(&nevents);  
 }
 
 //_____________________________________________________________________________
index 784f298..80b8566 100644 (file)
@@ -33,7 +33,7 @@ public:
                      const AliMUONVStore& manuValues);
 
   AliMUONTrackerData(const char* name, const char* title,
-                     const AliMUONVStore& deValues, Int_t val);
+                     const AliMUONVStore& deOrBpValues, Int_t val);
 
   AliMUONTrackerData(const char* name, const char* title,
                      const AliMUONRejectList& rejectList);
@@ -142,6 +142,10 @@ public:
   
 private:
     
+  void BuildFromDEStore(const AliMUONVStore& deStore);
+
+  void BuildFromBPStore(const AliMUONVStore& bpStore);
+
   void FillHisto(Int_t detElemId, Int_t manuId, Int_t manuChannel,
                  Int_t dim, Double_t value);