Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

RawChannelId.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawChannelId.cxx,v 1.37 2005/08/26 19:04:53 rhatcher Exp $
00003 // 
00004 // RawChannelId 
00005 // 
00006 // RawChannelId is the base class for a channel # of a raw digit
00007 // (either QIE or Viking data)
00008 //
00009 // Author:  R. Hatcher 2000.04.19
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 // The details of the encoding are here out of normal sight
00029 //
00030 //       3         2         1
00031 //      10987654321098765432109876543210
00032 //      77776666555544443333222211110000
00033 //  QIE     ddddcspxeccccccgggggMMMmmmmm
00034 //  VA      ddddcspxeccccccvvmmmfCCccccc
00035 //                   |----||-----------|
00036 //                   crate channeladdr(chadd)
00037 //
00038 //  
00039 // All:  ddd:detector bits (0x01=near, 0x02=far, 0x04=caldet)
00040 //       x:special (see ElecTypes)
00041 //       c:common_mode, s=sparified, p:ped_subtracted
00042 //       e:{0=VA,1=QIE}, ccccc: crate #
00043 //
00044 // QIE:  ggggg:geographic, MMM=Master, mmmmm=minder
00045 //  VA:  vv=varc_id, mmm=VMM, a=AdcSel, CC=VA_chip, ccccc=VA_channel
00046 //
00047 
00048 const UInt_t  bitsChAdd        = 13;
00049 const UInt_t  bitsCrate        =  6;
00050 //                                 76543210
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    // Constructor from Chadd
00124    // Pack the crate, chadd and readout type into an encoded value
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    // Constructor from QIE components
00137    // Pack the crate, chadd and readout type into an encoded value
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    // Constructor from VA components
00175    // Pack the crate, chadd and readout type into an encoded value
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    // Constructor from CrateId (w/ mode bits) & Chadd
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    // Pack the crate, chadd and readout type into an encoded value
00212 
00213    SetDetector(detector);
00214    SetElecType(etype);
00215    SetCrate(crate);
00216    SetChAdd(chadd);
00217    fEncoded &= zeroModeBits;  // clear all the mode bits
00218 }
00219 
00220 //_____________________________________________________________________________
00221 const char*  RawChannelId::AsString(Option_t *option) const
00222 {
00223    // Return the unpacked RawChannelId as a string
00224    // User should copy result because it points to a
00225    // statically allocated string.  This is somewhat mitigated
00226    // by use of a circular buffer of strings.
00227 
00228    const int nbuffers = 8; // # of buffers in circular list
00229    static char newstring[nbuffers][80];
00230 
00231    static int ibuffer = nbuffers;
00232    ibuffer = (ibuffer+1)%nbuffers; // each call moves to next buffer
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       // expanded version, break out all components
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          // VA electronics -- break out components of ChAdd
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          // QIE electronics -- break out components of ChAdd
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(); // instead of opfx
00438       os << AsString(option);
00439    }
00440    // instead of os.osfx()
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    // compare two channel id's irrespective of ped/common/spars modes
00450    
00451    return (fEncoded&zeroModeBits) == (other.fEncoded&zeroModeBits);
00452 
00453 }
00454 
00455 //_____________________________________________________________________________
00456 Bool_t RawChannelId::IsSameCrate(const RawChannelId& other) const
00457 {
00458    // compare two channel id's for same crate
00459    // irrespective of ped/common/spars modes
00460    // (tests detector + electype + crate)
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    // compare for same VA chip-ness
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    // compare for same Vfb-ness
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    // compare for same Minder-ness
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    // test whether this is the nonsensical default value
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    // compute a ChAdd (channel address) based on QIE components
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    // compute a ChAdd (channel address) based on VA components
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    // decompose a ChAdd (channel address) based into QIE components
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    // decompose a ChAdd (channel address) based into VA components
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 { // VERY DANGEROUS!
00764   if (! ( fEncoded & maskRCIDVersion ) ) {
00765     // make some noise in cases other than streamer reading
00766     // and the default dummy case
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   // VERY DANGEROUS
00785   // conversion for version 1 having bad shift for detector component
00786   if ( encoded & maskRCIDVersion ) return encoded;  // do nothing
00787   if ( encoded == defaultRawChannelId ) {
00788     encoded |= maskRCIDVersion;
00789     return encoded;
00790   }
00791 
00792   // version 1 had the mask right but the shift wrong (23 instead of 24)
00793   // retrieve detector field as it was stored
00794   UInt_t detector = ( encoded & maskDetector ) >> 23 ;
00795   // if it is zero, then it probably was Near and got shifted away
00796   if ( ! detector ) detector = Detector::kNear;
00797   
00798   // store it as it should have been stored
00799   encoded = ( encoded & zeroDetector ) |
00800     ( ( detector << shiftDetector ) & maskDetector );
00801   // set the flag that we've done so
00802   encoded |= maskRCIDVersion;
00803   
00804   return encoded;
00805 }
00806 
00807 //_____________________________________________________________________________
00808 void RawChannelId::Streamer(TBuffer &R__b)
00809 {
00810   // Stream an object of class RawChannelId
00811   // for an update to version 2 internal structure of fEncoded
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     // Since all versions have written their data to file using automatic
00817     // schema option, we can read all versions back in this way
00818     RawChannelId::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
00819     if ( R__v > 1 ) return;
00820 
00821     // version 1 data needs to be converted
00822     ConvertToVersion2(true);
00823   }
00824   else {
00825     RawChannelId::Class()->WriteBuffer(R__b, this);
00826   }
00827 }
00828 
00829 //_____________________________________________________________________________

Generated on Mon Nov 23 05:28:09 2009 for loon by  doxygen 1.3.9.1