1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONHVNamer.h"
20 #include "AliMpArea.h"
21 #include "AliMpDEIterator.h"
22 #include "AliMpDEManager.h"
23 #include "AliMpHelper.h"
24 #include "AliMpSegmentation.h"
25 #include "AliMpSlat.h"
26 #include "AliMpSlatSegmentation.h"
27 #include "AliMpVPadIterator.h"
30 #include "Riostream.h"
32 #include "TObjArray.h"
33 #include "TObjString.h"
39 /// \class AliMUONHVNamer
41 /// A utility class to manage HV DCS aliases names, in particular the
42 /// two conventions used to number the detection elements within a detector.
44 // Author: Laurent Aphecetche, Subatech
47 ClassImp(AliMUONHVNamer)
50 const char* AliMUONHVNamer::fgHVChannelSt345Pattern[] =
51 { "MchHvLvLeft/Chamber%02dLeft/Slat%02d.actual.vMon",
52 "MchHvLvRight/Chamber%02dRight/Slat%02d.actual.vMon"
55 const char* AliMUONHVNamer::fgHVChannelSt12Pattern[] =
57 "MchHvLvLeft/Chamber%02dLeft/Quad%dSect%d.actual.vMon",
58 "MchHvLvRight/Chamber%02dRight/Quad%dSect%d.actual.vMon",
61 const char* AliMUONHVNamer::fgHVSwitchSt345Pattern = "MchDE%dsw%d.inValue";
63 //_____________________________________________________________________________
64 AliMUONHVNamer::AliMUONHVNamer()
69 //_____________________________________________________________________________
70 AliMUONHVNamer::~AliMUONHVNamer()
75 //_____________________________________________________________________________
77 AliMUONHVNamer::CompactAliases() const
79 /// Generate a compact list of aliases, for Shuttle test
80 /// This one is completely hand-made, in contrast with GenerateAliases()
83 TObjArray* a = new TObjArray;
86 // St 12 (HV Channels)
87 a->Add(new TObjString("MchHvLvRight/Chamber[01..04]Right/Quad1Sect[1..3].actual.vMon"));
88 a->Add(new TObjString("MchHvLvLeft/Chamber[01..04]Left/Quad2Sect[1..3].actual.vMon"));
89 a->Add(new TObjString("MchHvLvLeft/Chamber[01..04]Left/Quad3Sect[1..3].actual.vMon"));
90 a->Add(new TObjString("MchHvLvRight/Chamber[01..04]Right/Quad4Sect[1..3].actual.vMon"));
92 // St345 (HV Channels)
94 a->Add(new TObjString("MchHvLvRight/Chamber[05..10]Right/Slat[01..09].actual.vMon"));
95 a->Add(new TObjString("MchHvLvLeft/Chamber[05..10]Left/Slat[01..09].actual.vMon"));
97 a->Add(new TObjString("MchHvLvRight/Chamber[07..10]Right/Slat[10..13].actual.vMon"));
98 a->Add(new TObjString("MchHvLvLeft/Chamber[07..10]Left/Slat[10..13].actual.vMon"));
100 // St345 (HV Switches)
107 Int_t detElemId = it.CurrentDEId();
108 if ( AliMpDEManager::GetStationType(detElemId) == AliMp::kStation345 )
110 a->Add(new TObjString(Form("MchDE%dsw[1..%d].inValue",detElemId,NumberOfPCBs(detElemId))));
117 //_____________________________________________________________________________
119 AliMUONHVNamer::DCS2DE(Int_t chamberId, Int_t side, Int_t dcsNumber) const
121 /// Convert DCS "slat number" (old convention) to DE (new) convention.
123 /// @param chamberId : chamber number (starting at 1)
124 /// @param side : 0 for Left, 1 for Right
125 /// @param dcsNumber : slat number in DCS HV convention
127 /// note that dcsNumber should be >=1 and <= number of DEs/2 in chamber
129 Int_t nofDE = AliMpDEManager::GetNofDEInChamber(chamberId);
131 Int_t half = nofDE/2;
133 dcsNumber = half + 1 - dcsNumber;
135 Int_t quarter = nofDE/4;
136 Int_t threeQuarter = half + quarter;
140 if ( side == 0 ) // left
142 de = threeQuarter + 1 - dcsNumber;
144 else if ( side == 1 ) // right
146 if ( dcsNumber <= quarter )
148 de = dcsNumber + threeQuarter;
152 de = dcsNumber - quarter - 1;
156 return chamberId*100 + de;
159 //_____________________________________________________________________________
161 AliMUONHVNamer::DetElemId2DCS(Int_t detElemId, Int_t& side) const
163 /// Convert DE to DCS "slat number"
166 Int_t chamberId = 1 + AliMpDEManager::GetChamberId(detElemId);
169 AliDebug(1,Form("DetElemId %d invalid",detElemId));
172 Int_t dcsNumber = (detElemId-chamberId*100);
174 switch ( AliMpDEManager::GetStationType(detElemId) )
176 case AliMp::kStation1:
177 case AliMp::kStation2:
195 case AliMp::kStation345:
197 Int_t nofDE = AliMpDEManager::GetNofDEInChamber(chamberId-1);
199 Int_t quarter = nofDE/4;
201 Int_t half = nofDE/2;
203 Int_t threeQuarter = half + quarter;
207 if ( dcsNumber <= quarter )
209 dcsNumber += quarter + 1 ;
212 else if ( dcsNumber <= threeQuarter )
214 dcsNumber = ( threeQuarter - dcsNumber + 1 );
217 else if ( dcsNumber > threeQuarter )
219 dcsNumber = dcsNumber - threeQuarter;
226 // dcs convention change : numbering from top, not from bottom
227 dcsNumber = half+1-dcsNumber;
236 //_____________________________________________________________________________
238 AliMUONHVNamer::DCSHVChannelName(Int_t detElemId, Int_t sector) const
240 /// Return the alias name of the HV Channel for a given HV area
241 /// @param sector=0,1 or 2 for St12, and is unused for st345
243 Int_t chamberId = 1 + AliMpDEManager::GetChamberId(detElemId);
244 if ( chamberId < 1 ) return 0x0;
247 Int_t dcsNumber = DetElemId2DCS(detElemId,side);
249 switch (AliMpDEManager::GetStationType(detElemId))
251 case AliMp::kStation1:
252 case AliMp::kStation2:
253 return Form(fgHVChannelSt12Pattern[side],chamberId,dcsNumber,sector+1);
255 case AliMp::kStation345:
256 return Form(fgHVChannelSt345Pattern[side],chamberId,dcsNumber);
264 //_____________________________________________________________________________
266 AliMUONHVNamer::DCSHVSwitchName(Int_t detElemId, Int_t pcbNumber) const
268 /// Return the alias name of the HV Switch for a given PCB
269 /// within a slat of St345
271 if (AliMpDEManager::GetStationType(detElemId) == AliMp::kStation345)
273 return Form(fgHVSwitchSt345Pattern,detElemId,pcbNumber+1);
278 //_____________________________________________________________________________
280 AliMUONHVNamer::DetElemIdFromDCSAlias(const char* dcsAlias) const
282 /// Converts the dcs alias to a detection element identifier
284 /// dcsAlias has one of the following 2 forms :
286 /// MchHvLv[Left|Right]/Chamber##[Left|Right]/Chamber##[Left|Right]Slat##.actual.vMon
288 /// MchHvLv[Left|Right]/Chamber##[Left|Right]/Chamber##[Left|Right]Quad#Sect#.actual.vMon
290 TString sDcsAlias(dcsAlias);
294 if ( sDcsAlias.Contains("Left") )
298 else if ( sDcsAlias.Contains("Right") )
312 if ( sDcsAlias.Contains("Slat") )
314 sscanf(sDcsAlias.Data(),fgHVChannelSt345Pattern[side],&n1,&n3);
315 detElemId = DCS2DE(n1,side,n3);
317 else if ( sDcsAlias.Contains("Quad") )
319 sscanf(sDcsAlias.Data(),fgHVChannelSt12Pattern[side],&n1,&n3,&n4);
327 if ( !AliMpDEManager::IsValidDetElemId(detElemId) )
329 AliError(Form("Invalid aliasName %s",dcsAlias));
336 //_____________________________________________________________________________
338 AliMUONHVNamer::GenerateAliases() const
340 /// Generate DCS alias names, for MUON Tracker High Voltage system.
342 /// We first generate aliases of HV channels :
344 /// St 1 ch 1 : 12 channels
345 /// ch 2 : 12 channels
346 /// St 2 ch 3 : 12 channels
347 /// ch 4 : 12 channels
348 /// St 3 ch 5 : 18 channels
349 /// ch 6 : 18 channels
350 /// St 4 ch 7 : 26 channels
351 /// ch 8 : 26 channels
352 /// St 5 ch 9 : 26 channels
353 /// ch 10 : 26 channels
355 /// then aliases of HV switches (only for St345) : 1 switch per PCB.
357 /// Returns a TObjArray of TObjString(=alias name)
359 TObjArray* aliases = new TObjArray;
360 aliases->SetOwner(kTRUE);
368 Int_t detElemId = it.CurrentDEId();
369 switch ( AliMpDEManager::GetStationType(detElemId) )
371 case AliMp::kStation1:
372 case AliMp::kStation2:
373 for ( int sector = 0; sector < 3; ++sector)
375 aliases->Add(new TObjString(DCSHVChannelName(detElemId,sector)));
378 case AliMp::kStation345:
379 aliases->Add(new TObjString(DCSHVChannelName(detElemId)));
380 for ( Int_t i = 0; i < NumberOfPCBs(detElemId); ++i )
382 aliases->Add(new TObjString(DCSHVSwitchName(detElemId,i)));
394 //_____________________________________________________________________________
396 AliMUONHVNamer::ManuId2PCBIndex(Int_t detElemId, Int_t manuId) const
398 /// Returns the index of PCB (within a St345 slat) for a given manu number.
399 /// Returns -1 if (detElemId,manuId) is incorrect
401 const AliMpSlatSegmentation* seg = static_cast<const AliMpSlatSegmentation*>
402 (AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId));
403 const AliMpSlat* slat = seg->Slat();
404 AliMpVPadIterator* it = seg->CreateIterator();
406 AliMpPad pad = it->CurrentItem();
408 while ( !it->IsDone() && pad.GetLocation().GetFirst() != manuId )
411 pad = it->CurrentItem();
414 Int_t pcbIndex = slat->FindPCBIndex(pad.Position().X()+slat->Position().X(),
415 pad.Position().Y()+slat->Position().Y());
416 // AliDebug(1,Form("pcbIndex %d",pcbIndex));
417 // StdoutToAliDebug(1,pad.Print());
421 //_____________________________________________________________________________
423 AliMUONHVNamer::ManuId2Sector(Int_t /*detElemId*/, Int_t /*manuId*/) const
425 /// Return the HV-sector number (within a St12 quadrant) for a given manu number.
431 //_____________________________________________________________________________
433 AliMUONHVNamer::NumberOfPCBs(Int_t detElemId) const
435 /// Returns the number of PCB in a given detection element
436 /// Only works for St345
438 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
439 if ( stationType != AliMp::kStation345 )
445 const AliMpSlatSegmentation* seg = static_cast<const AliMpSlatSegmentation*>
446 (AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0));
447 const AliMpSlat* slat = seg->Slat();
448 return slat->GetSize();