00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #include "RawData/RawChannelId.h"
00014 #include "TBuffer.h"
00015 #include "TClass.h"
00016 #include <cassert>
00017 #include <iomanip>
00018 using namespace std;
00019
00020 #include "MessageService/MsgService.h"
00021 CVSID("$Id: RawChannelId.cxx,v 1.37 2005/08/26 19:04:53 rhatcher Exp $");
00022
00023 ClassImp(RawChannelId)
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 const UInt_t bitsChAdd = 13;
00049 const UInt_t bitsCrate = 6;
00050
00051 const UInt_t maskRCIDVersion = 0x80000000;
00052 const UInt_t maskChAdd = 0x00001fff;
00053 const UInt_t shiftChAdd = 0;
00054 const UInt_t maskCrate = 0x0007e000;
00055 const UInt_t shiftCrate = 13;
00056 const UInt_t maskElec = 0x00180000;
00057 const UInt_t shiftElec = 19;
00058 const UInt_t maskPedMode = 0x00200000;
00059 const UInt_t maskSparsMode = 0x00400000;
00060 const UInt_t maskComMode = 0x00800000;
00061 const UInt_t maskDetector = 0x0F000000;
00062 const UInt_t shiftDetector = 24;
00063
00064 const UInt_t zeroChAdd = ~maskChAdd;
00065 const UInt_t zeroCrate = ~maskCrate;
00066 const UInt_t zeroElec = ~maskElec;
00067 const UInt_t zeroModeBits = ~(maskPedMode|maskSparsMode|maskComMode);
00068 const UInt_t zeroDetector = ~maskDetector;
00069
00070 const UInt_t bitsQieMinderCh = 5;
00071 const UInt_t bitsQieMasterCh = 3;
00072 const UInt_t bitsQieGeoAddr = 5;
00073 const UInt_t maskQieMinderCh = 0x001f;
00074 const UInt_t maskQieMasterCh = 0x0007;
00075 const UInt_t maskQieGeoAddr = 0x001f;
00076 const UInt_t shiftQieMinderCh = 0;
00077 const UInt_t shiftQieMasterCh = shiftQieMinderCh + bitsQieMinderCh;
00078 const UInt_t shiftQieGeoAddr = shiftQieMasterCh + bitsQieMasterCh;
00079
00080 const UInt_t zeroQieGeoAddr = ~(maskQieGeoAddr <<shiftQieGeoAddr );
00081 const UInt_t zeroQieMasterCh = ~(maskQieMasterCh<<shiftQieMasterCh);
00082 const UInt_t zeroQieMinderCh = ~(maskQieMinderCh<<shiftQieMinderCh);
00083
00084 const UInt_t bitsVaVaChannel = 5;
00085 const UInt_t bitsVaVaChip = 2;
00086 const UInt_t bitsVaAdcSel = 1;
00087 const UInt_t bitsVaVmm = 3;
00088 const UInt_t bitsVaVarcId = 2;
00089 const UInt_t bitsVaVfb = 4;
00090 const UInt_t maskVaVaChannel = 0x001f;
00091 const UInt_t maskVaVaChip = 0x0003;
00092 const UInt_t maskVaAdcSel = 0x0001;
00093 const UInt_t maskVaVmm = 0x0007;
00094 const UInt_t maskVaVarcId = 0x0003;
00095 const UInt_t maskVaVfb = 0x000f;
00096
00097 const UInt_t shiftVaVaChannel = 0;
00098 const UInt_t shiftVaVaChip = shiftVaVaChannel + bitsVaVaChannel;
00099 const UInt_t shiftVaAdcSel = shiftVaVaChip + bitsVaVaChip;
00100 const UInt_t shiftVaVmm = shiftVaAdcSel + bitsVaAdcSel;
00101 const UInt_t shiftVaVarcId = shiftVaVmm + bitsVaVmm;
00102 const UInt_t shiftVaVfb = shiftVaAdcSel;
00103
00104 const UInt_t zeroVaVarcId = ~(maskVaVarcId <<shiftVaVarcId );
00105 const UInt_t zeroVaVmm = ~(maskVaVmm <<shiftVaVmm );
00106 const UInt_t zeroVaAdcSel = ~(maskVaAdcSel <<shiftVaAdcSel );
00107 const UInt_t zeroVaVaChip = ~(maskVaVaChip <<shiftVaVaChip );
00108 const UInt_t zeroVaVaChannel = ~(maskVaVaChannel<<shiftVaVaChannel);
00109 const UInt_t zeroVaVfb = ~(maskVaVfb <<shiftVaVfb );
00110
00111 const UShort_t badUShort = 0xffff;
00112
00113
00114 std::ostream& operator<<(std::ostream& os, const RawChannelId& rcid)
00115 { return rcid.FormatToOStream(os); }
00116
00117
00118 RawChannelId::RawChannelId(Detector::Detector_t detector,
00119 ElecType::Elec_t etype,
00120 UInt_t crate, UInt_t chadd)
00121 : fEncoded(0)
00122 {
00123
00124
00125
00126 Init(detector,etype,crate,chadd);
00127 }
00128
00129
00130 RawChannelId::RawChannelId(Detector::Detector_t detector,
00131 ElecType::Elec_t etype,
00132 UInt_t crate, UInt_t geoaddr,
00133 UInt_t masterChan, UInt_t minderChan)
00134 : fEncoded(0)
00135 {
00136
00137
00138
00139 if (ElecType::kQIE != etype) {
00140 MSG("RawData",Msg::kWarning)
00141 << "RawChannelId QIE ctor was passed "
00142 << ElecType::AsString(etype) << " etype,"
00143 << endl
00144 << " probably due to extra pedmode,commonmode args."
00145 << endl
00146 << " no doubt this will end in tears..."
00147 << endl;
00148 assert(0);
00149 }
00150 if ( geoaddr > maskQieGeoAddr ) {
00151 MSG("RawData",Msg::kWarning)
00152 << "RawChannelId QIE ctor was passed geoAddr 0x"
00153 << hex << geoaddr << dec
00154 << " which is larger then the expected max of 0x"
00155 << hex << maskQieGeoAddr << dec
00156 << endl
00157 << " probably due to extra pedmode,commonmode args."
00158 << endl
00159 << " no doubt this will end in tears..."
00160 << endl;
00161 assert(0);
00162 }
00163 UInt_t chadd = CalcChAdd(geoaddr,masterChan,minderChan);
00164 Init(detector,etype,crate,chadd);
00165 }
00166
00167
00168 RawChannelId::RawChannelId(Detector::Detector_t detector,
00169 ElecType::Elec_t etype,
00170 UInt_t crate, UInt_t varc, UInt_t vmm,
00171 UInt_t adcsel, UInt_t vachip, UInt_t vachan)
00172 : fEncoded(0)
00173 {
00174
00175
00176
00177 if (ElecType::kVA != etype) {
00178 MSG("RawData",Msg::kWarning)
00179 << "RawChannelId VA ctor was passed "
00180 << ElecType::AsString(etype) << " etype,"
00181 << endl
00182 << " probably due to extra pedmode,commonmode args."
00183 << endl
00184 << " no doubt this will end in tears..."
00185 << endl;
00186 assert(0);
00187 }
00188 UInt_t chadd = CalcChAdd(varc,vmm,adcsel,vachip,vachan);
00189 Init(detector,etype,crate,chadd);
00190 }
00191
00192
00193 RawChannelId::RawChannelId(Detector::Detector_t detector,
00194 UInt_t crateinfo, UInt_t chadd)
00195 : fEncoded(0)
00196 {
00197
00198 SetDetector(detector);
00199 const UInt_t maskCrateInfo =
00200 maskComMode|maskSparsMode|maskPedMode|maskElec|maskCrate;
00201 fEncoded |= ( crateinfo << shiftCrate ) & maskCrateInfo;
00202 fEncoded |= ( chadd << shiftChAdd ) & maskChAdd;
00203
00204 }
00205
00206
00207 void RawChannelId::Init(Detector::Detector_t detector,
00208 ElecType::Elec_t etype,
00209 UInt_t crate, UInt_t chadd)
00210 {
00211
00212
00213 SetDetector(detector);
00214 SetElecType(etype);
00215 SetCrate(crate);
00216 SetChAdd(chadd);
00217 fEncoded &= zeroModeBits;
00218 }
00219
00220
00221 const char* RawChannelId::AsString(Option_t *option) const
00222 {
00223
00224
00225
00226
00227
00228 const int nbuffers = 8;
00229 static char newstring[nbuffers][80];
00230
00231 static int ibuffer = nbuffers;
00232 ibuffer = (ibuffer+1)%nbuffers;
00233
00234 char dchar = Detector::AsString(GetDetector())[0];
00235 ElecType::Elec_t elec = GetElecType();
00236 char echar = ElecType::AsString(elec)[0];
00237 char pchar = (GetPedMode()) ? 'P' : '-';
00238 char schar = (GetSparsMode()) ? 'S' : '-';
00239 char cchar = (GetCommonMode()) ? 'C' : '-';
00240 int crate = GetCrate();
00241 int chadd = GetChAdd();
00242
00243 string opt = option;
00244 bool extended = (opt.find("e") != string::npos);
00245 bool compact = (opt.find("c") != string::npos);
00246 bool crate_only = (opt.find("C") != string::npos);
00247 const char* efmt =
00248 "%c:%c%c%c%c:0x%2.2x:%4.4x";
00249
00250 if (crate_only) {
00251 const char* cratefmt = "%c:%c%c%c%c:0x%2.2x";
00252 sprintf(newstring[ibuffer],cratefmt,
00253 dchar,echar,pchar,schar,cchar,crate);
00254 }
00255 else
00256 if (extended) {
00257
00258 const char* efmtva =
00259 "%c:%c%c%c%c:0x%2.2x: varc %1d vmm %1d adcsel %1d chip %1d chan %2d";
00260 const char* efmtqie =
00261 "%c:%c%c%c%c:0x%2.2x: geoaddr %2d master %1d minder %2d";
00262 if (compact) {
00263 efmtva = "%c:%c%c%c%c:0x%2.2x:%1d-%1d-%1d-%1d-%2.2d";
00264 efmtqie = "%c:%c%c%c%c:0x%2.2x:%2.2d-%1d-%2.2d";
00265 }
00266 switch (elec) {
00267 case ElecType::kVA:
00268
00269 sprintf(newstring[ibuffer],efmtva,
00270 dchar,echar,pchar,schar,cchar,crate,
00271 GetVarcId(),GetVmm(),GetVaAdcSel(),
00272 GetVaChip(),GetVaChannel());
00273 break;
00274 case ElecType::kQIE:
00275
00276 sprintf(newstring[ibuffer],efmtqie,
00277 dchar,echar,pchar,schar,cchar,crate,
00278 GetGeographicAddress(),
00279 GetMasterChannel(),GetMinderChannel());
00280 break;
00281 default:
00282 sprintf(newstring[ibuffer],efmt,
00283 dchar,echar,pchar,schar,cchar,crate,chadd);
00284 break;
00285 }
00286 }
00287 else
00288 sprintf(newstring[ibuffer],efmt,
00289 dchar,echar,pchar,schar,cchar,crate,chadd);
00290
00291 return newstring[ibuffer];
00292 }
00293
00294
00295 Detector::Detector_t RawChannelId::GetDetector() const
00296 {
00297
00298
00299 if (! (fEncoded & maskRCIDVersion) ) ConvertToVersion2();
00300
00301 UInt_t bitField = ( fEncoded & maskDetector ) >> shiftDetector;
00302
00303 return (Detector::Detector_t) bitField;
00304 }
00305
00306
00307 ElecType::Elec_t RawChannelId::GetElecType() const
00308 {
00309
00310
00311 UInt_t bitField = ( fEncoded & maskElec ) >> shiftElec;
00312
00313 return (ElecType::Elec_t) bitField;
00314 }
00315
00316
00317 Bool_t RawChannelId::GetPedMode() const
00318 {
00319
00320 return (fEncoded & maskPedMode) ? 1 : 0 ;
00321 }
00322
00323
00324 Bool_t RawChannelId::GetSparsMode() const
00325 {
00326
00327 return (fEncoded & maskSparsMode) ? 1 : 0 ;
00328 }
00329
00330
00331 Bool_t RawChannelId::GetCommonMode() const
00332 {
00333
00334
00335 return (fEncoded & maskComMode) ? 1 : 0 ;
00336 }
00337
00338
00339 UShort_t RawChannelId::GetCrate() const
00340 {
00341
00342
00343 return ( fEncoded & maskCrate ) >> shiftCrate;
00344 }
00345
00346
00347 UShort_t RawChannelId::GetChAdd() const
00348 {
00349
00350
00351 return ( fEncoded & maskChAdd ) >> shiftChAdd;
00352 }
00353
00354
00355 UShort_t RawChannelId::GetGeographicAddress() const
00356 {
00357 if ( GetElecType() != ElecType::kQIE ) return badUShort;
00358
00359 return ( GetChAdd() >> shiftQieGeoAddr ) & maskQieGeoAddr;
00360 }
00361
00362
00363 UShort_t RawChannelId::GetMasterChannel() const
00364 {
00365 if ( GetElecType() != ElecType::kQIE ) return badUShort;
00366
00367 return ( GetChAdd() >> shiftQieMasterCh ) & maskQieMasterCh;
00368 }
00369
00370
00371 UShort_t RawChannelId::GetMinderChannel() const
00372 {
00373 if ( GetElecType() != ElecType::kQIE ) return badUShort;
00374
00375 return ( GetChAdd() >> shiftQieMinderCh ) & maskQieMinderCh;
00376 }
00377
00378
00379 UShort_t RawChannelId::GetVarcId() const
00380 {
00381 if ( GetElecType() != ElecType::kVA ) return badUShort;
00382
00383 return ( GetChAdd() >> shiftVaVarcId ) & maskVaVarcId;
00384 }
00385
00386
00387 UShort_t RawChannelId::GetVfb() const
00388 {
00389 if ( GetElecType() != ElecType::kVA ) return badUShort;
00390
00391 return ( GetChAdd() >> shiftVaVfb ) & maskVaVfb;
00392 }
00393
00394
00395 UShort_t RawChannelId::GetVmm() const
00396 {
00397 if ( GetElecType() != ElecType::kVA ) return badUShort;
00398
00399 return ( GetChAdd() >> shiftVaVmm ) & maskVaVmm;
00400 }
00401
00402
00403 UShort_t RawChannelId::GetVaAdcSel() const
00404 {
00405 if ( GetElecType() != ElecType::kVA ) return badUShort;
00406
00407 return ( GetChAdd() >> shiftVaAdcSel ) & maskVaAdcSel;
00408 }
00409
00410
00411 UShort_t RawChannelId::GetVaChip() const
00412 {
00413 if ( GetElecType() != ElecType::kVA ) return badUShort;
00414
00415 return ( GetChAdd() >> shiftVaVaChip ) & maskVaVaChip;
00416 }
00417
00418
00419 UShort_t RawChannelId::GetVaChannel() const
00420 {
00421 if ( GetElecType() != ElecType::kVA ) return badUShort;
00422
00423 return ( GetChAdd() >> shiftVaVaChannel ) & maskVaVaChannel;
00424 }
00425
00426
00427 void RawChannelId::Print(Option_t *option) const
00428 {
00429 FormatToOStream(cout,option);
00430
00431 }
00432
00433 std::ostream& RawChannelId::FormatToOStream(std::ostream& os,
00434 Option_t *option) const
00435 {
00436 if (os.good()) {
00437 if (os.tie()) os.tie()->flush();
00438 os << AsString(option);
00439 }
00440
00441 if (os.flags() & std::ios::unitbuf) os.flush();
00442 return os;
00443 }
00444
00445
00446
00447 Bool_t RawChannelId::IsSameChannel(const RawChannelId& other) const
00448 {
00449
00450
00451 return (fEncoded&zeroModeBits) == (other.fEncoded&zeroModeBits);
00452
00453 }
00454
00455
00456 Bool_t RawChannelId::IsSameCrate(const RawChannelId& other) const
00457 {
00458
00459
00460
00461
00462 const UInt_t zeroBits = zeroModeBits & ~( maskChAdd << shiftChAdd );
00463 UInt_t thischip = fEncoded & zeroBits;
00464 UInt_t thatchip = other.fEncoded & zeroBits;
00465
00466 return ( thischip == thatchip );
00467
00468 }
00469
00470
00471 Bool_t RawChannelId::IsSameVAChip(const RawChannelId& other) const
00472 {
00473
00474
00475 if ( GetElecType() != ElecType::kVA ||
00476 other.GetElecType() != ElecType::kVA ) {
00477 MSG("RawData",Msg::kInfo)
00478 << "RawChannelId::IsSameVAChip always fails if "
00479 << "the electronics are not VA" << endl;
00480 return false;
00481 }
00482
00483 const UInt_t zeroBits = zeroModeBits & zeroVaVaChannel;
00484 UInt_t thischip = fEncoded & zeroBits;
00485 UInt_t thatchip = other.fEncoded & zeroBits;
00486
00487 return ( thischip == thatchip );
00488
00489 }
00490
00491
00492 Bool_t RawChannelId::IsSameVfb(const RawChannelId& other) const
00493 {
00494
00495
00496 if ( GetElecType() != ElecType::kVA ||
00497 other.GetElecType() != ElecType::kVA ) {
00498 MSG("RawData",Msg::kInfo)
00499 << "RawChannelId::IsSameVfb always fails if "
00500 << "the electronics are not VA" << endl;
00501 return false;
00502 }
00503
00504 const UInt_t zeroBits = zeroModeBits & zeroVaVaChannel & zeroVaVaChip;
00505 UInt_t thischip = fEncoded & zeroBits;
00506 UInt_t thatchip = other.fEncoded & zeroBits;
00507
00508 return ( thischip == thatchip );
00509
00510 }
00511
00512
00513 Bool_t RawChannelId::IsSameMinder(const RawChannelId& other) const
00514 {
00515
00516
00517 if ( GetElecType() != ElecType::kQIE ||
00518 other.GetElecType() != ElecType::kQIE ) {
00519 MSG("RawData",Msg::kInfo)
00520 << "RawChannelId::IsSameMinder always fails if "
00521 << "the electronics are not QIE" << endl;
00522 return false;
00523 }
00524
00525 const UInt_t zeroBits = zeroModeBits & zeroQieMinderCh;
00526 UInt_t thischip = fEncoded & zeroBits;
00527 UInt_t thatchip = other.fEncoded & zeroBits;
00528
00529 return ( thischip == thatchip );
00530
00531 }
00532
00533
00534 Bool_t RawChannelId::IsNull() const
00535 {
00536
00537 return (fEncoded&~maskRCIDVersion) == (defaultRawChannelId&~maskRCIDVersion);
00538 }
00539
00540
00541 void RawChannelId::SetDetector(Detector::Detector_t detector)
00542 {
00543 fEncoded = (fEncoded & zeroDetector) |
00544 ( ( detector << shiftDetector ) & maskDetector );
00545
00546 if (shiftDetector == 24) fEncoded |= maskRCIDVersion;
00547 }
00548
00549
00550 void RawChannelId::SetElecType(ElecType::Elec_t etype)
00551 {
00552 fEncoded = (fEncoded & zeroElec) |
00553 ( ( etype << shiftElec ) & maskElec );
00554 }
00555
00556
00557 void RawChannelId::SetPedMode(Bool_t pedmode)
00558 {
00559 if (pedmode) {
00560 fEncoded |= maskPedMode;
00561 } else {
00562 fEncoded &= ~maskPedMode;
00563 }
00564 }
00565
00566
00567 void RawChannelId::SetSparsMode(Bool_t sparsmode)
00568 {
00569 if (sparsmode) {
00570 fEncoded |= maskSparsMode;
00571 } else {
00572 fEncoded &= ~maskSparsMode;
00573 }
00574 }
00575
00576
00577 void RawChannelId::SetCommonMode(Bool_t commonmode)
00578 {
00579 if (commonmode) {
00580 fEncoded |= maskComMode;
00581 } else {
00582 fEncoded &= ~maskComMode;
00583 }
00584 }
00585
00586
00587 void RawChannelId::SetModeBits(Bool_t commonmode, Bool_t sparsmode, Bool_t pedmode)
00588 {
00589 if (commonmode) {
00590 fEncoded |= maskComMode;
00591 } else {
00592 fEncoded &= ~maskComMode;
00593 }
00594 if (sparsmode) {
00595 fEncoded |= maskSparsMode;
00596 } else {
00597 fEncoded &= ~maskSparsMode;
00598 }
00599 if (pedmode) {
00600 fEncoded |= maskPedMode;
00601 } else {
00602 fEncoded &= ~maskPedMode;
00603 }
00604 }
00605
00606
00607 void RawChannelId::ClearModeBits()
00608 {
00609 fEncoded &= zeroModeBits;
00610 }
00611
00612
00613 void RawChannelId::SetCrate(const UInt_t crate)
00614 {
00615 fEncoded = (fEncoded & zeroCrate) |
00616 ( ( crate << shiftCrate ) & maskCrate );
00617 }
00618
00619
00620 void RawChannelId::SetChAdd(const UInt_t chadd)
00621 {
00622 fEncoded = (fEncoded & zeroChAdd) |
00623 ( ( chadd << shiftChAdd ) & maskChAdd );
00624 }
00625
00626
00627 void RawChannelId::SetGeographicAddress(UInt_t geoaddr)
00628 {
00629 if (!CheckElecType(ElecType::kQIE,"SetGeographicAddress")) return;
00630
00631 fEncoded = ( fEncoded & zeroQieGeoAddr ) |
00632 ( (geoaddr & maskQieGeoAddr) << shiftQieGeoAddr ) ;
00633 }
00634
00635
00636 void RawChannelId::SetMasterChannel(UInt_t master)
00637 {
00638 if (!CheckElecType(ElecType::kQIE,"SetMasterChannel")) return;
00639
00640 fEncoded = ( fEncoded & zeroQieMasterCh ) |
00641 ( (master & maskQieMasterCh) << shiftQieMasterCh ) ;
00642 }
00643
00644
00645 void RawChannelId::SetMinderChannel(UInt_t minder)
00646 {
00647 if (!CheckElecType(ElecType::kQIE,"SetMinderChannel")) return;
00648
00649 fEncoded = ( fEncoded & zeroQieMinderCh ) |
00650 ( (minder & maskQieMinderCh) << shiftQieMinderCh ) ;
00651 }
00652
00653
00654 void RawChannelId::SetVarcId(UInt_t varc)
00655 {
00656 if (!CheckElecType(ElecType::kVA,"SetVarcId")) return;
00657
00658 fEncoded = ( fEncoded & zeroVaVarcId ) |
00659 ( (varc & maskVaVarcId) << shiftVaVarcId ) ;
00660 }
00661
00662
00663 void RawChannelId::SetVmm(UInt_t vmm)
00664 {
00665 if (!CheckElecType(ElecType::kVA,"SetVmm")) return;
00666
00667 fEncoded = ( fEncoded & zeroVaVmm ) |
00668 ( (vmm & maskVaVmm) << shiftVaVmm ) ;
00669 }
00670
00671
00672 void RawChannelId::SetVaAdcSel(UInt_t adcsel)
00673 {
00674 if (!CheckElecType(ElecType::kVA,"SetVaAdcSel")) return;
00675
00676 fEncoded = ( fEncoded & zeroVaAdcSel ) |
00677 ( (adcsel & maskVaAdcSel) << shiftVaAdcSel ) ;
00678 }
00679
00680
00681 void RawChannelId::SetVaChip(UInt_t vachip)
00682 {
00683 if (!CheckElecType(ElecType::kVA,"SetVaChip")) return;
00684
00685 fEncoded = ( fEncoded & zeroVaVaChip ) |
00686 ( (vachip & maskVaVaChip) << shiftVaVaChip ) ;
00687 }
00688
00689
00690 void RawChannelId::SetVaChannel(UInt_t vachan)
00691 {
00692 if (!CheckElecType(ElecType::kVA,"SetVaChannel")) return;
00693
00694 fEncoded = ( fEncoded & zeroVaVaChannel ) |
00695 ( (vachan & maskVaVaChannel) << shiftVaVaChannel ) ;
00696 }
00697
00698
00699 Bool_t RawChannelId::CheckElecType(ElecType::Elec_t etype,
00700 const char* from)
00701 {
00702 if ( GetElecType() == etype ) return true;
00703
00704 MSG("Raw",Msg::kInfo)
00705 << "RawChannelId::" << from << " is NOP for non-"
00706 << ElecType::AsString(etype) << " electronics" << endl;
00707 return false;
00708 }
00709
00710
00711 Int_t RawChannelId::CalcChAdd(UInt_t geo, UInt_t master, UInt_t minder)
00712 {
00713
00714
00715 return
00716 (minder & maskQieMinderCh) << shiftQieMinderCh |
00717 (master & maskQieMasterCh) << shiftQieMasterCh |
00718 (geo & maskQieGeoAddr) << shiftQieGeoAddr;
00719 }
00720
00721
00722 Int_t RawChannelId::CalcChAdd(UInt_t varcid, UInt_t vmm, UInt_t adcsel,
00723 UInt_t vachip, UInt_t vachan)
00724 {
00725
00726
00727 return
00728 (vachan & maskVaVaChannel) << shiftVaVaChannel |
00729 (vachip & maskVaVaChip) << shiftVaVaChip |
00730 (adcsel & maskVaAdcSel) << shiftVaAdcSel |
00731 (vmm & maskVaVmm) << shiftVaVmm |
00732 (varcid & maskVaVarcId) << shiftVaVarcId;
00733 }
00734
00735
00736 void RawChannelId::DecompChAdd(UInt_t chadd, UInt_t& geo,
00737 UInt_t& master, UInt_t& minder)
00738 {
00739
00740
00741 geo = (chadd >> shiftQieGeoAddr) & maskQieGeoAddr;
00742 master = (chadd >> shiftQieMasterCh) & maskQieMasterCh;
00743 minder = (chadd >> shiftQieMinderCh) & maskQieMinderCh;
00744
00745 }
00746
00747
00748 void RawChannelId::DecompChAdd(UInt_t chadd, UInt_t& varcid, UInt_t& vmm,
00749 UInt_t& adcsel, UInt_t& vachip, UInt_t& vachan)
00750 {
00751
00752
00753 varcid = (chadd >> shiftVaVarcId) & maskVaVarcId;
00754 vmm = (chadd >> shiftVaVmm) & maskVaVmm;
00755 adcsel = (chadd >> shiftVaAdcSel) & maskVaAdcSel;
00756 vachip = (chadd >> shiftVaVaChip) & maskVaVaChip;
00757 vachan = (chadd >> shiftVaVaChannel) & maskVaVaChannel;
00758
00759 }
00760
00761
00762 void RawChannelId::ConvertToVersion2(Bool_t inStreamerRead) const
00763 {
00764 if (! ( fEncoded & maskRCIDVersion ) ) {
00765
00766
00767 if ( ! inStreamerRead && ( fEncoded != defaultRawChannelId ) )
00768 MSG("RawData",Msg::kError)
00769 <<"RawChannelId::ConvertToVersion2() called for encoded 0x"
00770 << hex << setw(8) << setfill('0') << fEncoded
00771 << setfill(' ') << dec
00772 << " at a time other than Streamer(). "
00773 << endl
00774 << " Please contact rhatcher@fnal.gov about this strange case"
00775 << endl;
00776 RawChannelId *nonconst = const_cast<RawChannelId*>(this);
00777 nonconst->fEncoded = ConvertEncodedToVersion2(fEncoded);
00778 }
00779 }
00780
00781
00782 UInt_t RawChannelId::ConvertEncodedToVersion2(UInt_t encoded)
00783 {
00784
00785
00786 if ( encoded & maskRCIDVersion ) return encoded;
00787 if ( encoded == defaultRawChannelId ) {
00788 encoded |= maskRCIDVersion;
00789 return encoded;
00790 }
00791
00792
00793
00794 UInt_t detector = ( encoded & maskDetector ) >> 23 ;
00795
00796 if ( ! detector ) detector = Detector::kNear;
00797
00798
00799 encoded = ( encoded & zeroDetector ) |
00800 ( ( detector << shiftDetector ) & maskDetector );
00801
00802 encoded |= maskRCIDVersion;
00803
00804 return encoded;
00805 }
00806
00807
00808 void RawChannelId::Streamer(TBuffer &R__b)
00809 {
00810
00811
00812
00813 if (R__b.IsReading()) {
00814 UInt_t R__s, R__c;
00815 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00816
00817
00818 RawChannelId::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
00819 if ( R__v > 1 ) return;
00820
00821
00822 ConvertToVersion2(true);
00823 }
00824 else {
00825 RawChannelId::Class()->WriteBuffer(R__b, this);
00826 }
00827 }
00828
00829