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%04dsw%d.inValue";
63 //_____________________________________________________________________________
64 AliMUONHVNamer::AliMUONHVNamer()
69 //_____________________________________________________________________________
70 AliMUONHVNamer::~AliMUONHVNamer()
75 //_____________________________________________________________________________
77 AliMUONHVNamer::AliasesAsLdif(const char* ldiffile) const
79 /// Export the aliases in LDIF format
81 ofstream out(ldiffile);
83 TObjArray* a = CompactAliases();
88 // Some header. host name and port probably not up to date.
89 out << "#MCH config" << endl
90 << "dn: det=MCH,o=alice,dc=cern,dc=ch" << endl
91 << "objectClass: AliShuttleDetector" << endl
93 << "StrictRunOrder: 1" << endl
94 << "responsible: aphecetc@in2p3.fr" << endl
95 << "DCSHost: aldcs053.cern.ch" << endl
96 << "DCSPort: 4242" <<endl;
98 while ( ( s = (TObjString*)(next()) ) )
100 out << "DCSalias: " << s->String().Data() << endl;
108 //_____________________________________________________________________________
110 AliMUONHVNamer::CompactAliases() const
112 /// Generate a compact list of aliases, for Shuttle test
113 /// This one is completely hand-made, in contrast with GenerateAliases()
116 TObjArray* a = new TObjArray;
119 // St 12 (HV Channels)
120 a->Add(new TObjString("MchHvLvRight/Chamber[00..03]Right/Quad0Sect[0..2].actual.vMon"));
121 a->Add(new TObjString("MchHvLvLeft/Chamber[00..03]Left/Quad1Sect[0..2].actual.vMon"));
122 a->Add(new TObjString("MchHvLvLeft/Chamber[00..03]Left/Quad2Sect[0..2].actual.vMon"));
123 a->Add(new TObjString("MchHvLvRight/Chamber[00..03]Right/Quad3Sect[0..2].actual.vMon"));
125 // St345 (HV Channels)
127 a->Add(new TObjString("MchHvLvRight/Chamber[04..09]Right/Slat[00..08].actual.vMon"));
128 a->Add(new TObjString("MchHvLvLeft/Chamber[04..09]Left/Slat[00..08].actual.vMon"));
130 a->Add(new TObjString("MchHvLvRight/Chamber[06..09]Right/Slat[09..12].actual.vMon"));
131 a->Add(new TObjString("MchHvLvLeft/Chamber[06..09]Left/Slat[09..12].actual.vMon"));
133 // St345 (HV Switches)
140 Int_t detElemId = it.CurrentDEId();
141 if ( AliMpDEManager::GetStationType(detElemId) == AliMp::kStation345 )
143 a->Add(new TObjString(Form("MchDE%04dsw[0..%d].inValue",detElemId,NumberOfPCBs(detElemId)-1)));
150 //_____________________________________________________________________________
152 AliMUONHVNamer::DCS2DE(Int_t chamberId, Int_t side, Int_t dcsNumber) const
154 /// Convert DCS "slat number" (old convention) to DE (new) convention.
156 /// \param chamberId : chamber number (starting at 0)
157 /// \param side : 0 for Left, 1 for Right
158 /// \param dcsNumber : slat number in DCS HV convention
160 /// note that dcsNumber should be >=0 and < number of DEs/2 in chamber
162 Int_t nofDE = AliMpDEManager::GetNofDEInChamber(chamberId);
164 Int_t half = nofDE/2;
166 dcsNumber = half - dcsNumber;
168 Int_t quarter = nofDE/4;
169 Int_t threeQuarter = half + quarter;
173 if ( side == 0 ) // left
175 de = threeQuarter + 1 - dcsNumber;
177 else if ( side == 1 ) // right
179 if ( dcsNumber <= quarter )
181 de = dcsNumber + threeQuarter;
185 de = dcsNumber - quarter - 1;
189 return chamberId*100 + de;
192 //_____________________________________________________________________________
194 AliMUONHVNamer::DetElemId2DCS(Int_t detElemId, Int_t& side) const
196 /// Convert DE to DCS "slat number"
199 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
202 AliDebug(1,Form("DetElemId %d invalid",detElemId));
205 Int_t dcsNumber = (detElemId-(chamberId+1)*100);
207 switch ( AliMpDEManager::GetStationType(detElemId) )
209 case AliMp::kStation1:
210 case AliMp::kStation2:
226 case AliMp::kStation345:
228 Int_t nofDE = AliMpDEManager::GetNofDEInChamber(chamberId);
230 Int_t quarter = nofDE/4;
232 Int_t half = nofDE/2;
234 Int_t threeQuarter = half + quarter;
238 if ( dcsNumber <= quarter )
240 dcsNumber += quarter + 1 ;
243 else if ( dcsNumber <= threeQuarter )
245 dcsNumber = ( threeQuarter - dcsNumber + 1 );
248 else if ( dcsNumber > threeQuarter )
250 dcsNumber = dcsNumber - threeQuarter;
257 // dcs convention change : numbering from top, not from bottom
258 dcsNumber = half-dcsNumber;
267 //_____________________________________________________________________________
269 AliMUONHVNamer::DCSHVChannelName(Int_t detElemId, Int_t sector) const
271 /// Return the alias name of the HV Channel for a given HV area
273 /// \param sector = 0,1 or 2 for St12, and is unused for st345
275 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
276 if ( chamberId < 0 ) return 0x0;
279 Int_t dcsNumber = DetElemId2DCS(detElemId,side);
281 switch (AliMpDEManager::GetStationType(detElemId))
283 case AliMp::kStation1:
284 case AliMp::kStation2:
285 return Form(fgHVChannelSt12Pattern[side],chamberId,dcsNumber,sector);
287 case AliMp::kStation345:
288 return Form(fgHVChannelSt345Pattern[side],chamberId,dcsNumber);
296 //_____________________________________________________________________________
298 AliMUONHVNamer::DCSHVSwitchName(Int_t detElemId, Int_t pcbNumber) const
300 /// Return the alias name of the HV Switch for a given PCB
301 /// within a slat of St345
303 if (AliMpDEManager::GetStationType(detElemId) == AliMp::kStation345)
305 return Form(fgHVSwitchSt345Pattern,detElemId,pcbNumber);
310 //_____________________________________________________________________________
312 AliMUONHVNamer::DetElemIdFromDCSAlias(const char* dcsAlias) const
314 /// Converts the dcs alias to a detection element identifier
316 /// dcsAlias has one of the following 2 forms :
318 /// MchHvLv[Left|Right]/Chamber##[Left|Right]/Chamber##[Left|Right]Slat##.actual.vMon
320 /// MchHvLv[Left|Right]/Chamber##[Left|Right]/Chamber##[Left|Right]Quad#Sect#.actual.vMon
322 TString sDcsAlias(dcsAlias);
326 if ( sDcsAlias.Contains("Left") )
330 else if ( sDcsAlias.Contains("Right") )
344 if ( sDcsAlias.Contains("Slat") )
346 sscanf(sDcsAlias.Data(),fgHVChannelSt345Pattern[side],&n1,&n3);
347 detElemId = DCS2DE(n1,side,n3);
349 else if ( sDcsAlias.Contains("Quad") )
351 sscanf(sDcsAlias.Data(),fgHVChannelSt12Pattern[side],&n1,&n3,&n4);
359 if ( !AliMpDEManager::IsValidDetElemId(detElemId) )
361 AliError(Form("Invalid aliasName %s",dcsAlias));
368 //_____________________________________________________________________________
370 AliMUONHVNamer::GenerateAliases() const
372 /// Generate DCS alias names, for MUON Tracker High Voltage system.
374 /// We first generate aliases of HV channels :
376 /// St 1 ch 1 : 12 channels
377 /// ch 2 : 12 channels
378 /// St 2 ch 3 : 12 channels
379 /// ch 4 : 12 channels
380 /// St 3 ch 5 : 18 channels
381 /// ch 6 : 18 channels
382 /// St 4 ch 7 : 26 channels
383 /// ch 8 : 26 channels
384 /// St 5 ch 9 : 26 channels
385 /// ch 10 : 26 channels
387 /// then aliases of HV switches (only for St345) : 1 switch per PCB.
389 /// Returns a TObjArray of TObjString(=alias name)
391 TObjArray* aliases = new TObjArray;
392 aliases->SetOwner(kTRUE);
400 Int_t detElemId = it.CurrentDEId();
401 switch ( AliMpDEManager::GetStationType(detElemId) )
403 case AliMp::kStation1:
404 case AliMp::kStation2:
405 for ( int sector = 0; sector < 3; ++sector)
407 aliases->Add(new TObjString(DCSHVChannelName(detElemId,sector)));
410 case AliMp::kStation345:
411 aliases->Add(new TObjString(DCSHVChannelName(detElemId)));
412 for ( Int_t i = 0; i < NumberOfPCBs(detElemId); ++i )
414 aliases->Add(new TObjString(DCSHVSwitchName(detElemId,i)));
426 //_____________________________________________________________________________
428 AliMUONHVNamer::ManuId2PCBIndex(Int_t detElemId, Int_t manuId) const
430 /// Returns the index of PCB (within a St345 slat) for a given manu number.
431 /// Returns -1 if (detElemId,manuId) is incorrect
433 const AliMpSlatSegmentation* seg = static_cast<const AliMpSlatSegmentation*>
434 (AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId));
435 const AliMpSlat* slat = seg->Slat();
436 AliMpVPadIterator* it = seg->CreateIterator();
438 AliMpPad pad = it->CurrentItem();
440 while ( !it->IsDone() && pad.GetLocation().GetFirst() != manuId )
443 pad = it->CurrentItem();
446 Int_t pcbIndex = slat->FindPCBIndex(pad.Position().X()+slat->Position().X(),
447 pad.Position().Y()+slat->Position().Y());
448 // AliDebug(1,Form("pcbIndex %d",pcbIndex));
449 // StdoutToAliDebug(1,pad.Print());
453 //_____________________________________________________________________________
455 AliMUONHVNamer::ManuId2Sector(Int_t /*detElemId*/, Int_t /*manuId*/) const
457 /// Return the HV-sector number (within a St12 quadrant) for a given manu number.
463 //_____________________________________________________________________________
465 AliMUONHVNamer::NumberOfPCBs(Int_t detElemId) const
467 /// Returns the number of PCB in a given detection element
468 /// Only works for St345
470 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
471 if ( stationType != AliMp::kStation345 )
477 const AliMpSlatSegmentation* seg = static_cast<const AliMpSlatSegmentation*>
478 (AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0));
479 const AliMpSlat* slat = seg->Slat();
480 return slat->GetSize();