]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONHVNamer.cxx
Initial classes for Lee Yang Zeroes from Naomi van der Kolk
[u/mrichter/AliRoot.git] / MUON / AliMUONHVNamer.cxx
CommitLineData
6b8b24d4 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 "AliMUONHVNamer.h"
19
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"
28
29#include "AliLog.h"
30#include "Riostream.h"
31#include "TMap.h"
32#include "TObjArray.h"
33#include "TObjString.h"
34#include "TString.h"
35#include "TSystem.h"
36
3d1463c8 37//-----------------------------------------------------------------------------
6b8b24d4 38/// \class AliMUONHVNamer
39///
40/// A utility class to manage HV DCS aliases names, in particular the
41/// two conventions used to number the detection elements within a detector.
42///
78649106 43/// \author: Laurent Aphecetche, Subatech
3d1463c8 44//-----------------------------------------------------------------------------
6b8b24d4 45
46/// \cond CLASSIMP
47ClassImp(AliMUONHVNamer)
48/// \endcond
49
50const char* AliMUONHVNamer::fgHVChannelSt345Pattern[] =
51{ "MchHvLvLeft/Chamber%02dLeft/Slat%02d.actual.vMon",
52 "MchHvLvRight/Chamber%02dRight/Slat%02d.actual.vMon"
53};
54
55const char* AliMUONHVNamer::fgHVChannelSt12Pattern[] =
56{
57 "MchHvLvLeft/Chamber%02dLeft/Quad%dSect%d.actual.vMon",
58 "MchHvLvRight/Chamber%02dRight/Quad%dSect%d.actual.vMon",
59};
b803d2f1 60
98cd9139 61const char* AliMUONHVNamer::fgHVSwitchSt345Pattern = "MchDE%04dsw%d.inValue";
6b8b24d4 62
63//_____________________________________________________________________________
64AliMUONHVNamer::AliMUONHVNamer()
65{
66 /// default ctor
67}
68
69//_____________________________________________________________________________
70AliMUONHVNamer::~AliMUONHVNamer()
71{
72 /// dtor
73}
74
b803d2f1 75//_____________________________________________________________________________
76void
77AliMUONHVNamer::AliasesAsLdif(const char* ldiffile) const
78{
79/// Export the aliases in LDIF format
80
81 ofstream out(ldiffile);
82
83 TObjArray* a = CompactAliases();
84
85 TIter next(a);
86 TObjString* s;
87
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
92 << "det: MCH" << endl
93 << "StrictRunOrder: 1" << endl
94 << "responsible: aphecetc@in2p3.fr" << endl
95 << "DCSHost: aldcs053.cern.ch" << endl
96 << "DCSPort: 4242" <<endl;
97
98 while ( ( s = (TObjString*)(next()) ) )
99 {
100 out << "DCSalias: " << s->String().Data() << endl;
101 }
102
103 out.close();
104
105 delete a;
106}
107
6b8b24d4 108//_____________________________________________________________________________
109TObjArray*
110AliMUONHVNamer::CompactAliases() const
111{
112 /// Generate a compact list of aliases, for Shuttle test
113 /// This one is completely hand-made, in contrast with GenerateAliases()
114 /// method
115
116 TObjArray* a = new TObjArray;
117 a->SetOwner(kTRUE);
118
119 // St 12 (HV Channels)
b803d2f1 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"));
6b8b24d4 124
125 // St345 (HV Channels)
126
b803d2f1 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"));
6b8b24d4 129
b803d2f1 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"));
6b8b24d4 132
133 // St345 (HV Switches)
134 AliMpDEIterator it;
135
136 it.First();
137
138 while (!it.IsDone())
139 {
140 Int_t detElemId = it.CurrentDEId();
141 if ( AliMpDEManager::GetStationType(detElemId) == AliMp::kStation345 )
142 {
b803d2f1 143 a->Add(new TObjString(Form("MchDE%04dsw[0..%d].inValue",detElemId,NumberOfPCBs(detElemId)-1)));
6b8b24d4 144 }
145 it.Next();
146 }
147 return a;
148}
149
150//_____________________________________________________________________________
151Int_t
152AliMUONHVNamer::DCS2DE(Int_t chamberId, Int_t side, Int_t dcsNumber) const
153{
154 /// Convert DCS "slat number" (old convention) to DE (new) convention.
155 ///
b803d2f1 156 /// \param chamberId : chamber number (starting at 0)
78649106 157 /// \param side : 0 for Left, 1 for Right
158 /// \param dcsNumber : slat number in DCS HV convention
6b8b24d4 159 ///
b803d2f1 160 /// note that dcsNumber should be >=0 and < number of DEs/2 in chamber
6b8b24d4 161
162 Int_t nofDE = AliMpDEManager::GetNofDEInChamber(chamberId);
163
164 Int_t half = nofDE/2;
38ca2128 165
b803d2f1 166 dcsNumber = half - dcsNumber;
38ca2128 167
6b8b24d4 168 Int_t quarter = nofDE/4;
169 Int_t threeQuarter = half + quarter;
170
171 Int_t de(-1);
172
173 if ( side == 0 ) // left
174 {
175 de = threeQuarter + 1 - dcsNumber;
176 }
177 else if ( side == 1 ) // right
178 {
179 if ( dcsNumber <= quarter )
180 {
181 de = dcsNumber + threeQuarter;
182 }
183 else
184 {
185 de = dcsNumber - quarter - 1;
186 }
187 }
188
189 return chamberId*100 + de;
190}
191
192//_____________________________________________________________________________
193Int_t
194AliMUONHVNamer::DetElemId2DCS(Int_t detElemId, Int_t& side) const
195{
196 /// Convert DE to DCS "slat number"
197 /// @see DCS2DE
198
b803d2f1 199 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
200 if ( chamberId < 0 )
6b8b24d4 201 {
202 AliDebug(1,Form("DetElemId %d invalid",detElemId));
203 return -1;
204 }
b803d2f1 205 Int_t dcsNumber = (detElemId-(chamberId+1)*100);
6b8b24d4 206
207 switch ( AliMpDEManager::GetStationType(detElemId) )
208 {
209 case AliMp::kStation1:
210 case AliMp::kStation2:
211 {
212 switch (dcsNumber)
213 {
214 case 0:
215 case 3:
216 side = 1; // right
6b8b24d4 217 break;
218 case 1:
219 case 2:
220 side = 0; // left
6b8b24d4 221 default:
222 break;
223 }
224 }
225 break;
226 case AliMp::kStation345:
227 {
b803d2f1 228 Int_t nofDE = AliMpDEManager::GetNofDEInChamber(chamberId);
6b8b24d4 229
230 Int_t quarter = nofDE/4;
231
232 Int_t half = nofDE/2;
233
234 Int_t threeQuarter = half + quarter;
235
236 side = -1;
237
238 if ( dcsNumber <= quarter )
239 {
240 dcsNumber += quarter + 1 ;
241 side = 1; // right
242 }
38ca2128 243 else if ( dcsNumber <= threeQuarter )
244 {
245 dcsNumber = ( threeQuarter - dcsNumber + 1 );
246 side = 0; // left
247 }
248 else if ( dcsNumber > threeQuarter )
249 {
250 dcsNumber = dcsNumber - threeQuarter;
251 side = 1; // right
252 }
253 else
254 {
255 AliFatal("oups");
256 }
257 // dcs convention change : numbering from top, not from bottom
b803d2f1 258 dcsNumber = half-dcsNumber;
6b8b24d4 259 }
38ca2128 260 break;
6b8b24d4 261 default:
262 break;
263 }
264 return dcsNumber;
265}
266
267//_____________________________________________________________________________
268const char*
269AliMUONHVNamer::DCSHVChannelName(Int_t detElemId, Int_t sector) const
270{
271 /// Return the alias name of the HV Channel for a given HV area
78649106 272 /// \param detElemId
273 /// \param sector = 0,1 or 2 for St12, and is unused for st345
6b8b24d4 274
b803d2f1 275 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
276 if ( chamberId < 0 ) return 0x0;
6b8b24d4 277
278 Int_t side(-1);
279 Int_t dcsNumber = DetElemId2DCS(detElemId,side);
280
281 switch (AliMpDEManager::GetStationType(detElemId))
282 {
283 case AliMp::kStation1:
284 case AliMp::kStation2:
b803d2f1 285 return Form(fgHVChannelSt12Pattern[side],chamberId,dcsNumber,sector);
6b8b24d4 286 break;
287 case AliMp::kStation345:
288 return Form(fgHVChannelSt345Pattern[side],chamberId,dcsNumber);
289 break;
290 default:
291 return 0x0;
292 break;
293 }
294}
295
296//_____________________________________________________________________________
297const char*
298AliMUONHVNamer::DCSHVSwitchName(Int_t detElemId, Int_t pcbNumber) const
299{
300 /// Return the alias name of the HV Switch for a given PCB
301 /// within a slat of St345
302
303 if (AliMpDEManager::GetStationType(detElemId) == AliMp::kStation345)
304 {
b803d2f1 305 return Form(fgHVSwitchSt345Pattern,detElemId,pcbNumber);
6b8b24d4 306 }
307 return 0x0;
308}
309
310//_____________________________________________________________________________
311Int_t
312AliMUONHVNamer::DetElemIdFromDCSAlias(const char* dcsAlias) const
313{
314 /// Converts the dcs alias to a detection element identifier
315 ///
316 /// dcsAlias has one of the following 2 forms :
317 ///
318 /// MchHvLv[Left|Right]/Chamber##[Left|Right]/Chamber##[Left|Right]Slat##.actual.vMon
319 ///
320 /// MchHvLv[Left|Right]/Chamber##[Left|Right]/Chamber##[Left|Right]Quad#Sect#.actual.vMon
321
322 TString sDcsAlias(dcsAlias);
323
324 int side(-1);
325
326 if ( sDcsAlias.Contains("Left") )
327 {
328 side = 0;
329 }
330 else if ( sDcsAlias.Contains("Right") )
331 {
332 side = 1;
333 }
334 else
335 {
336 return -2;
337 }
338
339 int n1(-1);
340 int n3(-1);
341 int n4(-1);
342 int detElemId(-1);
343
344 if ( sDcsAlias.Contains("Slat") )
345 {
346 sscanf(sDcsAlias.Data(),fgHVChannelSt345Pattern[side],&n1,&n3);
347 detElemId = DCS2DE(n1,side,n3);
348 }
349 else if ( sDcsAlias.Contains("Quad") )
350 {
351 sscanf(sDcsAlias.Data(),fgHVChannelSt12Pattern[side],&n1,&n3,&n4);
352 detElemId = n3-1;
353 }
354 else
355 {
356 return -3;
357 }
358
359 if ( !AliMpDEManager::IsValidDetElemId(detElemId) )
360 {
361 AliError(Form("Invalid aliasName %s",dcsAlias));
362 return -1;
363 }
364
365 return detElemId;
366}
367
368//_____________________________________________________________________________
369TObjArray*
370AliMUONHVNamer::GenerateAliases() const
371{
372 /// Generate DCS alias names, for MUON Tracker High Voltage system.
373 ///
374 /// We first generate aliases of HV channels :
375 ///
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
386 ///
387 /// then aliases of HV switches (only for St345) : 1 switch per PCB.
388 ///
389 /// Returns a TObjArray of TObjString(=alias name)
390
391 TObjArray* aliases = new TObjArray;
392 aliases->SetOwner(kTRUE);
393
394 AliMpDEIterator it;
395
396 it.First();
397
398 while (!it.IsDone())
399 {
400 Int_t detElemId = it.CurrentDEId();
401 switch ( AliMpDEManager::GetStationType(detElemId) )
402 {
403 case AliMp::kStation1:
404 case AliMp::kStation2:
405 for ( int sector = 0; sector < 3; ++sector)
406 {
407 aliases->Add(new TObjString(DCSHVChannelName(detElemId,sector)));
408 }
409 break;
410 case AliMp::kStation345:
411 aliases->Add(new TObjString(DCSHVChannelName(detElemId)));
412 for ( Int_t i = 0; i < NumberOfPCBs(detElemId); ++i )
413 {
414 aliases->Add(new TObjString(DCSHVSwitchName(detElemId,i)));
415 }
416 break;
417 default:
418 break;
419 }
420 it.Next();
421 }
422
423 return aliases;
424}
425
426//_____________________________________________________________________________
427Int_t
428AliMUONHVNamer::ManuId2PCBIndex(Int_t detElemId, Int_t manuId) const
429{
430 /// Returns the index of PCB (within a St345 slat) for a given manu number.
431 /// Returns -1 if (detElemId,manuId) is incorrect
432
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();
437 it->First();
438 AliMpPad pad = it->CurrentItem();
439
440 while ( !it->IsDone() && pad.GetLocation().GetFirst() != manuId )
441 {
442 it->Next();
443 pad = it->CurrentItem();
444 }
445
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());
450 return pcbIndex;
451}
452
453//_____________________________________________________________________________
454Int_t
d7fc09b9 455AliMUONHVNamer::ManuId2Sector(Int_t /*detElemId*/, Int_t /*manuId*/) const
6b8b24d4 456{
457 /// Return the HV-sector number (within a St12 quadrant) for a given manu number.
458
459 //FIXME: write me !
460 return 0;
461}
462
463//_____________________________________________________________________________
464Int_t
465AliMUONHVNamer::NumberOfPCBs(Int_t detElemId) const
466{
467 /// Returns the number of PCB in a given detection element
468 /// Only works for St345
469
470 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
471 if ( stationType != AliMp::kStation345 )
472 {
473 return 0;
474 }
475 else
476 {
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();
481 }
482}