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

CoilStatus.cxx

Go to the documentation of this file.
00001 //
00002 // Body for CoilStatus namespace so that CINT recognizes its existence
00003 //
00004 #include "CoilStatus.h"
00005 #include "TString.h"
00006 
00007 //_____________________________________________________________________________
00008 Int_t CoilStatus::FullMask()
00009 {
00010    return kBad|kReverse|kDegauss|kCalib|kBadCurrent|kDataGap;
00011 }
00012 //_____________________________________________________________________________
00013 Bool_t CoilStatus::Good(CoilStatus_t coilstatus)
00014 {
00015   if (coilstatus & kBad) {
00016     return false;
00017   } else {
00018     return true;
00019   }
00020 }
00021 //_____________________________________________________________________________
00022 const Char_t* CoilStatus::AsString(CoilStatus_t coilstatus)
00023 {
00024    switch (coilstatus) {
00025    case kOK:         return "OK";          break;
00026    case kBad:        return "Bad";         break;
00027    case kReverse:    return "Reverse";     break;
00028    case kDegauss:    return "Degauss";     break;
00029    case kCalib:      return "Calib";       break;
00030    case kBadCurrent: return "BadCurrent";  break;
00031    case kDataGap:    return "DataGap";     break;
00032    case kUnknown:    return "Unknown";     break;
00033    default:          return "?Unknown?";   break;
00034    }
00035 }
00036 
00037 
00038 //_____________________________________________________________________________
00039 Char_t* CoilStatus::MaskToString(Int_t mask)
00040 {
00041    // Return a mask of CoilStatus as a string
00042    //
00043    // We might want to get the .NOT.s of these as well, ie "Forward"
00044    //
00045    // Result is a pointer to a statically allocated string.
00046    // User should copy this into their own buffer before calling
00047    // this method again.
00048 
00049    static Char_t newstring[255] = "";
00050    
00051    Char_t* ptr = newstring;  // start at the beginning
00052 
00053    *ptr = 0; // start with nothing
00054    Int_t fullmask = CoilStatus::FullMask();
00055    
00056    // Since zero is all OK, trap for this, else parse set bits
00057    if (!mask) {
00058      const Char_t* toadd = CoilStatus::AsString((CoilStatus_t) mask);
00059      if (ptr != newstring) *ptr++ = ','; 
00060      strcpy(ptr,toadd); 
00061      ptr += strlen(toadd); 
00062    } else {
00063      for (Int_t i=0; i<32; i++) {
00064        CoilStatus::CoilStatus_t acoil = (CoilStatus::CoilStatus_t)(1<<i);
00065        if (mask & acoil & fullmask) {
00066          const Char_t* toadd = CoilStatus::AsString(acoil);
00067          if (ptr != newstring) *ptr++ = ',';
00068          strcpy(ptr,toadd);
00069          ptr += strlen(toadd);
00070        }
00071      }
00072    }
00073    *ptr++ = 0; // ensure trailing 0
00074 
00075    return newstring;
00076 }
00077 //_____________________________________________________________________________

Generated on Mon Feb 15 11:06:32 2010 for loon by  doxygen 1.3.9.1