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

RawBlockId.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawBlockId.cxx,v 1.13 2005/08/26 19:04:53 rhatcher Exp $
00003 //
00004 // RawBlockId
00005 //
00006 // RawBlockId encapsulates raw block-ids
00007 //
00008 // Author:  R. Hatcher 2001.04.12
00009 //
00011 
00012 #include "RawData/RawBlockId.h"
00013 
00014 #include "RawData/RawBlockRegistry.h"
00015 #include "RawData/RawBlockProxy.h"
00016 
00017 #include "MessageService/MsgService.h"
00018 //CVSID("$Id: RawBlockId.cxx,v 1.13 2005/08/26 19:04:53 rhatcher Exp $");
00019 
00020 #include <iomanip>
00021 #include <string>
00022 
00023 #ifndef ASSERT_H
00024 #include <cassert>
00025 #define ASSERT_H
00026 #endif
00027 
00028 ClassImp(RawBlockId)
00029 
00030 //_____________________________________________________________________________
00031 std::ostream& operator<<(std::ostream& os, const RawBlockId& rbid) 
00032 { return rbid.FormatToOStream(os); }
00033 
00034 //_____________________________________________________________________________
00035 RawBlockId::RawBlockId(Int_t major, Int_t minor, Bool_t isDCS,
00036                        Detector::Detector_t detector,
00037                        SimFlag::SimFlag_t simflag)
00038    : fEncoded(0)
00039 {
00040    // Normal ctor
00041 
00042    Int_t cmptSimFlag = SimFlag::Compact(simflag);
00043 
00044    fEncoded = 
00045       ((cmptSimFlag << shiftRawBlkIdCSimFlag) & maskRawBlkIdCSimFlag) |
00046       ((   detector << shiftRawBlkIdDetector) & maskRawBlkIdDetector) |
00047       ((isDCS) ? maskRawBlkIdIsDCS : 0)                               |
00048       ((         major << shiftRawBlkIdMajor) & maskRawBlkIdMajor)    |
00049       ((         minor << shiftRawBlkIdMinor) & maskRawBlkIdMinor);
00050 
00051 }
00052 
00053 //_____________________________________________________________________________
00054 const Char_t* RawBlockId::AsString(Option_t *option) const
00055 {
00056    // Return unpacked RawBlockId as a string
00057    // User should copy result because it points to a 
00058    // statically allocated string.
00059    // Internally uses a circular list of buffers to avoid problems
00060    // using AsString multiple times in a cout-like situation.
00061 
00062    const int nbuffers = 8;  // use a circular list of strings
00063    static char newstring[nbuffers][128];
00064    static int ibuffer = nbuffers;
00065    ibuffer = (ibuffer+1)%nbuffers;  // each time move to next buffer
00066 
00067    switch (option[0]) {
00068    case 'c':
00069       // compact rendering "DCS:225;225(F+D)"
00070       sprintf(newstring[ibuffer],"%3s:%3.3d;%3.3d(%1.1s+%1.1s)"
00071               ,(IsDCS() ? "DCS" : "DAQ")
00072               ,GetMajor(),GetMinor()
00073               ,Detector::AsString(GetDetector())
00074               ,SimFlag::AsString(GetSimFlag())
00075               );
00076       break;
00077    default:
00078       // expanded rendering "DCS:RawDigitDataBlock;225(Far+Data)"
00079       sprintf(newstring[ibuffer],"%3s:%s;%3.3d(%s+%s)"
00080               ,(IsDCS() ? "DCS" : "DAQ")
00081               ,GetMajorAsString(),GetMinor()
00082               ,Detector::AsString(GetDetector())
00083               ,SimFlag::AsString(GetSimFlag())
00084               );
00085       break;
00086    }
00087    
00088    return newstring[ibuffer];
00089 }
00090 
00091 //_____________________________________________________________________________
00092 const Char_t* RawBlockId::GetMajorAsString() const
00093 {
00094    // Return major id # expanded as a string
00095 
00096    RawBlockRegistry& rbr = RawBlockRegistry::Instance();
00097    RawBlockProxy*    rbp = rbr.LookUp(IsDCS(),GetMajor());
00098 
00099    static char unknownstring[128];
00100 
00101    if (rbp) {
00102       return rbp->GetName();
00103    } 
00104    else {
00105       sprintf(unknownstring,"Unknown%3sBlock0x%2.2x",
00106               (IsDCS() ? "DCS" : "DAQ"),GetMajor());
00107       return unknownstring;
00108    }
00109 
00110 }
00111 
00112 //_____________________________________________________________________________
00113 void RawBlockId::Print(Option_t *option) const
00114 {
00115    // Print the (decoded) value
00116    FormatToOStream(cout,option);
00117 }
00118 
00119 //_____________________________________________________________________________
00120 std::ostream& RawBlockId::FormatToOStream(std::ostream& os,
00121                                           Option_t *option) const
00122 {
00123    if (os.good()) {
00124       if (os.tie()) os.tie()->flush(); // instead of opfx
00125       os << AsString(option);
00126    }
00127    // instead of os.osfx()
00128    if (os.flags() & std::ios::unitbuf) os.flush();
00129    return os;
00130 }
00131 
00132 
00133 //_____________________________________________________________________________

Generated on Sat Nov 21 22:47:28 2009 for loon by  doxygen 1.3.9.1