**************************************************************************/
// $Id$
+
+//-----------------------------------------------------------------------------
/// \class AliMUONPadStatusMapMaker
///
-/// Convert a pad status container into a pad status *map* container
+/// Convert a pad statuses into pad status maps.
///
/// A pad status is one 32-bits word describing whether this pad pedestal, gains
/// hv is correct or not.
/// If a pad is at a physical boundary, is will for sure have some bits at 1
/// (i.e. a non-existing neighbour is considered = bad).
///
-// author Laurent Aphecetche
+/// \author Laurent Aphecetche
+//-----------------------------------------------------------------------------
#include "AliMUONPadStatusMapMaker.h"
#include "AliLog.h"
#include "AliMUON2DMap.h"
-#include "AliMUONCalibParam1I.h"
-#include "AliMUONObjectPair.h"
-#include "AliMUONV2DStore.h"
+#include "AliMUONCalibParamNI.h"
+#include "AliMUONPadStatusMaker.h"
+#include "AliMUONVStore.h"
#include "AliMUONVCalibParam.h"
-#include "AliMUONVDataIterator.h"
-#include "AliMpArea.h"
#include "AliMpConstants.h"
-#include "AliMpDEManager.h"
-#include "AliMpPad.h"
-#include "AliMpSegmentation.h"
-#include "AliMpStationType.h"
-#include "AliMpVPadIterator.h"
-#include "AliMpVSegmentation.h"
#include <Riostream.h>
-#include <TMath.h>
-#include <TObjArray.h>
-#include <TStopwatch.h>
-#include <map>
-#include <utility>
+#include <TList.h>
+#include "AliCodeTimer.h"
+/// \cond CLASSIMP
ClassImp(AliMUONPadStatusMapMaker)
+/// \endcond
Int_t AliMUONPadStatusMapMaker::fgkSelfDead = 1;
-namespace
-{
- Bool_t IsZero(Double_t x)
- {
- return TMath::Abs(x) < AliMpConstants::LengthTolerance();
- }
-}
-
//_____________________________________________________________________________
-AliMUONPadStatusMapMaker::AliMUONPadStatusMapMaker()
+AliMUONPadStatusMapMaker::AliMUONPadStatusMapMaker(const AliMUONPadStatusMaker& padStatusMaker,
+ Int_t mask,
+ Bool_t deferredInitialization)
: TObject(),
-fStatus(0x0),
-fMask(0),
-fSegmentation(0x0),
-fTimerComputeStatusMap(0x0)
+fStatusMaker(padStatusMaker),
+fMask(mask),
+fStatusMap(new AliMUON2DMap(true))
{
/// ctor
-}
-
-//_____________________________________________________________________________
-AliMUONPadStatusMapMaker::~AliMUONPadStatusMapMaker()
-{
- /// dtor
- delete fTimerComputeStatusMap;
-}
-
-//_____________________________________________________________________________
-Int_t
-AliMUONPadStatusMapMaker::ComputeStatusMap(const TObjArray& neighbours,
- Int_t detElemId) const
-{
- /// Given a list of neighbours of one pad (which includes the pad itself)
- /// compute the status map (aka deadmap) for that pad.
-
- fTimerComputeStatusMap->Start(kFALSE);
-
- Int_t statusMap(0);
-
- //Compute the statusmap related to the status of neighbouring
- //pads. An invalid pad means "outside of edges".
- Int_t i(0);
- TIter next(&neighbours);
- AliMpPad* p;
-
- while ( ( p = static_cast<AliMpPad*>(next()) ) )
+ if (!deferredInitialization)
{
- Int_t status = 0;
- if ( !p->IsValid() )
- {
- status = -1;
- }
- else
+ AliCodeTimerAuto("Computing complete status map at once");
+ AliMUONVStore* neighboursStore = padStatusMaker.NeighboursStore();
+ AliMUONVCalibParam* param;
+ TIter next(neighboursStore->CreateIterator());
+ while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
{
- status = GetPadStatus(detElemId,*p);
+ Int_t detElemId = param->ID0();
+ Int_t manuId = param->ID1();
+ ComputeStatusMap(detElemId,manuId);
}
- if ( ( fMask==0 && status !=0 ) || ( (status & fMask) != 0 ) )
- {
- statusMap |= (1<<i);
- }
- ++i;
}
-
- fTimerComputeStatusMap->Stop();
- return statusMap;
-}
-
-//_____________________________________________________________________________
-Int_t
-AliMUONPadStatusMapMaker::GetPadStatus(Int_t detElemId,
- const AliMpPad& pad) const
-{
- /// Get the pad status
- Int_t manuId = pad.GetLocation().GetFirst();
- Int_t manuChannel = pad.GetLocation().GetSecond();
- AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->Get(detElemId,manuId));
- return param->ValueAsInt(manuChannel);
-}
-
-//_____________________________________________________________________________
-Bool_t
-AliMUONPadStatusMapMaker::IsValid(const AliMpPad& pad,
- const TVector2& shift) const
-{
- /// Whether pad.Position()+shift is within the detector
- TVector2 testPos = pad.Position() - pad.Dimensions() + shift;
- AliMpPad p = fSegmentation->PadByPosition(testPos,kFALSE);
- return p.IsValid();
}
//_____________________________________________________________________________
-AliMUONV2DStore*
-AliMUONPadStatusMapMaker::MakeEmptyPadStatusMap()
+AliMUONPadStatusMapMaker::~AliMUONPadStatusMapMaker()
{
- /// Make an empty (but complete) statusMap
-
- AliMUONCalibParam1I param(64,0);
-
- return AliMUON2DMap::Generate(param);
+ /// dtor
+ delete fStatusMap;
}
//_____________________________________________________________________________
-AliMUONV2DStore*
-AliMUONPadStatusMapMaker::MakePadStatusMap(const AliMUONV2DStore& status,
- Int_t mask)
+AliMUONVCalibParam*
+AliMUONPadStatusMapMaker::ComputeStatusMap(Int_t detElemId, Int_t manuId) const
{
- /// Given the status store for all pads, compute a status map store
- /// for all pads.
- /// @param mask is the status mask to be tested to tell if a pad is ok or not
-
- fStatus = &status;
- fMask = mask;
+ /// Compute the status map for a given manu, and add it to our internal
+ /// fStatusMap internal storage
- AliMpExMap chamberTimers(kTRUE);
- fTimerComputeStatusMap = new TStopwatch;
- fTimerComputeStatusMap->Start(kTRUE);
- fTimerComputeStatusMap->Stop();
-
- TStopwatch timer;
-
- timer.Start(kTRUE);
+ AliCodeTimerAuto("(Int_t,Int_t)")
+
+ AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),
+ detElemId,manuId,-1);
+
+ Bool_t ok = fStatusMap->Add(param);
+ if (!ok)
+ {
+ AliFatal(Form("Could not add manu %d of de %d",manuId,detElemId));
+ }
+
+ AliMUONVCalibParam* neighbours = fStatusMaker.Neighbours(detElemId,manuId);
- AliMUONV2DStore* statusMap = status.CloneEmpty();
+ AliMUONVCalibParam* statusParam = fStatusMaker.PadStatus(detElemId,manuId);
- AliMUONVDataIterator* it = status.Iterator();
- AliMUONObjectPair* pair;
+ Int_t n = neighbours->Dimension();
- while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next()) ) )
+ for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
{
- AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
-
- Int_t detElemId = ip->GetFirst();
-
- Int_t manuId = ip->GetSecond();
- Int_t chamber = AliMpDEManager::GetChamberId(detElemId);
-
- TStopwatch* chTimer = static_cast<TStopwatch*>(chamberTimers.GetValue(chamber));
- if (!chTimer)
- {
- chTimer = new TStopwatch;
- chTimer->Start(kTRUE);
- chTimer->Stop();
- chamberTimers.Add(chamber,chTimer);
- }
-
- chTimer->Start(kFALSE);
-
- const AliMpVSegmentation* seg =
- AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
- fSegmentation = seg;
-
- AliMUONVCalibParam* statusEntry = static_cast<AliMUONVCalibParam*>(pair->Second());
+ Int_t statusMap(0);
- AliMUONVCalibParam* statusMapEntry = static_cast<AliMUONVCalibParam*>
- (statusMap->Get(detElemId,manuId));
-
- if (!statusMapEntry)
+ Int_t x = neighbours->ValueAsIntFast(manuChannel,0);
+ if ( x < 0 )
{
- statusMapEntry = new AliMUONCalibParam1I(64,0);
- statusMap->Set(detElemId,manuId,statusMapEntry,false);
+ // channel is not a valid one (i.e. (manuId,manuChannel) is not an existing pad)
+ statusMap = -1;//fgkSelfDead;
+ continue;
}
-
- for ( Int_t manuChannel = 0; manuChannel < statusEntry->Size(); ++manuChannel )
+
+ for ( Int_t i = 0; i < n; ++i )
{
- // Loop over channels and for each channel loop on its immediate neighbours
- // to produce a statusMap word for this channel.
-
- AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
-
- Int_t statusMapValue(0);
-
- if ( pad.IsValid() )
+ // Compute the statusmap related to the status of neighbouring
+ // pads. An invalid pad means "outside of edges".
+
+ Int_t y = neighbours->ValueAsIntFast(manuChannel,i);
+ Int_t m,c;
+ neighbours->UnpackValue(y,m,c);
+ if ( c < 0 ) continue;
+ Int_t status = 0;
+ if ( !m )
{
- TObjArray neighbours;
- neighbours.SetOwner(kTRUE);
- fSegmentation->GetNeighbours(pad,neighbours,true,true);
- statusMapValue = ComputeStatusMap(neighbours,detElemId);
+ status = -1;
}
else
{
- statusMapValue = fgkSelfDead;
+ status = statusParam->ValueAsIntFast(c); //fStatusMaker.PadStatus(detElemId,m,c);
}
- statusMapEntry->SetValueAsInt(manuChannel,0,statusMapValue);
- }
- chTimer->Stop();
+ if ( ( fMask==0 && status !=0 ) || ( (status & fMask) != 0 ) )
+ {
+ statusMap |= (1<<i);
+ }
+ }
+ param->SetValueAsIntFast(manuChannel,0,statusMap);
}
+ return param;
+}
+
+//_____________________________________________________________________________
+Int_t
+AliMUONPadStatusMapMaker::StatusMap(Int_t detElemId, Int_t manuId,
+ Int_t manuChannel) const
+
+{
+ /// Get the pad status map
- delete it;
-
- TExMapIter cit = chamberTimers.GetIterator();
-
- Long_t key, value;
-
- while ( cit.Next(key,value) )
+ AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatusMap->FindObject(detElemId,manuId));
+ if (!param)
{
- TStopwatch* t = reinterpret_cast<TStopwatch*>(value);
- cout << Form("Chamber %2ld CPU time/manu %5.0f ms ",key,t->CpuTime()*1e3/t->Counter());
- t->Print();
+ // not yet computed, so do it now
+ param = ComputeStatusMap(detElemId,manuId);
}
-
- cout << "ComputeStatusMap timer : ";
- fTimerComputeStatusMap->Print();
- cout<< endl;
-
- cout << "MakePadStatusMap total timer : ";
- timer.Print();
- cout << endl;
-
- return statusMap;
+ return param->ValueAsInt(manuChannel);
}
-