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

RawRunConfigBlock.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawRunConfigBlock.cxx,v 1.10 2004/04/05 20:09:02 bv Exp $
00003 // 
00004 // RawRunConfigBlock 
00005 // 
00006 // RawRunConfigBlock holds the Run (Prepare) Configuration info
00007 //
00008 // Author:  R. Hatcher 2002.02.26
00009 //
00011 
00012 #include "RawData/RawRunConfigBlock.h"
00013 
00014 UInt_t RawRunConfigBlock::fgDebugFlags = 0;
00015 
00016 #include "MessageService/MsgService.h"
00017 //CVSID("$Id: RawRunConfigBlock.cxx,v 1.10 2004/04/05 20:09:02 bv Exp $");
00018 #include "MessageService/MsgFormat.h"
00019 
00020 #include "RawData/RawBlockRegistry.h"
00021 REGISTERRAWBLOCK(RawRunConfigBlock,kMdBlockConfigRunPrepare,0);
00022 
00023 #include "RawData/littleendian_strings.h"
00024 
00025 ClassImp(RawRunConfigBlock)
00026 
00027 enum ERunStartBlkPos {
00028    indx_size      = 0,
00029    indx_checksum  = 1,
00030    indx_blockid   = 2,
00031    zzzz_last_v1   = indx_blockid+1,
00032    indx_run       = 3,
00033    indx_subrun    = 4,
00034    indx_runtype   = indx_subrun,
00035    indx_startsec  = 5,
00036    indx_startnsec = 6,
00037    zzzz_last      = 7
00038 };
00039 
00040 //____________________________________________________________________________
00041 RawRunConfigBlock::RawRunConfigBlock()
00042    : RawDataBlock(), fRunConfig(0)
00043 {
00044    // Default constructor
00045 }
00046 
00047 //____________________________________________________________________________
00048 RawRunConfigBlock::RawRunConfigBlock(const Int_t *block)
00049    : RawDataBlock(block), fRunConfig(0)
00050 {
00051    //  stored block format is:
00052    //---------------------
00053    //  0   # words in block
00054    //  1   checksum
00055    //  2   Block Id
00056    //-----
00057    //  3   run #
00058    //  4   {subrun#| run type}
00059    //  5   time (sec)
00060    //  6   time (nsec)
00061    //  7   comment string (padded to 4 char)
00062 
00063 }
00064 
00065 //____________________________________________________________________________
00066 RawRunConfigBlock::RawRunConfigBlock(const VldContext& vldc, Int_t run,
00067                                        Short_t subrun, Short_t runtype,
00068                                        const Char_t* comment)
00069    : RawDataBlock(), fRunConfig(0)
00070 {
00071    // Component ctor 
00072 
00073    UInt_t nwdc  = nwords_in_string(comment);
00074    fSize = zzzz_last + nwdc;
00075    if (fRawBlock) delete [] fRawBlock;
00076    fRawBlock = new Int_t [fSize];  
00077 
00078    fRawBlock[0] = fSize;
00079 // fRawBlock[1] = checksum... see below
00080  
00081    RawBlockRegistry& rbr = RawBlockRegistry::Instance();
00082    RawBlockProxy*    rbp = rbr.LookUp("RawRunConfigBlock");
00083  
00084    Bool_t isDCS   = rbp->IsDCS();
00085    Int_t  majorId = rbp->GetMajorId();
00086    Int_t  minorId = 2;
00087    RawBlockId rbid(majorId,minorId,isDCS,
00088                    vldc.GetDetector(),vldc.GetSimFlag());
00089    fRawBlock[2] = rbid.GetEncoded();
00090  
00091    fRawBlock[indx_run]     = run;
00092    fRawBlock[indx_subrun]  = (subrun&0xffff)<<16 | (runtype&0xffff);
00093    fRawBlock[indx_startsec]     = vldc.GetTimeStamp().GetSec();
00094    fRawBlock[indx_startnsec]    = vldc.GetTimeStamp().GetNanoSec();
00095  
00096    fRawBlock[fSize-1] = 0; // ensure final '\0'
00097    pack_string_in_lel(fRawBlock+zzzz_last,comment);
00098 
00099    // fill checksum
00100    rdxsum_fill((long*)fRawBlock,0);
00101 }
00102 
00103 //____________________________________________________________________________
00104 RawRunConfigBlock::~RawRunConfigBlock()
00105 {
00106    // dtor
00107    if (fRunConfig) {
00108       delete [] fRunConfig;
00109       fRunConfig = 0;
00110    }
00111 }
00112 
00113 //____________________________________________________________________________
00114 RawRunConfigBlock& RawRunConfigBlock::operator=(const RawRunConfigBlock& rhs)
00115 {
00116    // deep copy assignment 
00117   if (this != &rhs) {
00118     RawDataBlock::operator=(rhs);
00119     if (fRunConfig) { delete [] fRunConfig; fRunConfig = 0; }
00120   }
00121   return *this;
00122 }
00123 
00124 //____________________________________________________________________________
00125 VldTimeStamp RawRunConfigBlock::GetTime() const
00126 {
00127    // get the trigger time
00128 
00129    if ( fSize >= zzzz_last )
00130       return VldTimeStamp(fRawBlock[indx_startsec],fRawBlock[indx_startnsec]);
00131  
00132    return VldTimeStamp((time_t)0,(Int_t)0);
00133 }
00134  
00135 //____________________________________________________________________________
00136 Int_t RawRunConfigBlock::GetRun() const
00137 {
00138    // get the run number
00139 
00140    if ( fSize >= zzzz_last ) return fRawBlock[indx_run];
00141    return -1;
00142 }
00143  
00144 //____________________________________________________________________________
00145 Short_t RawRunConfigBlock::GetSubRun() const
00146 {
00147    // get the subrun number
00148 
00149    if ( fSize >= zzzz_last ) 
00150       return (fRawBlock[indx_subrun]>>16)&0xffff;
00151    return -1;
00152 }
00153  
00154 //____________________________________________________________________________
00155 Short_t RawRunConfigBlock::GetRunType() const
00156 {
00157    // get the run type
00158 
00159    if ( fSize >= zzzz_last ) 
00160       return fRawBlock[indx_runtype]&0xffff;
00161    return -1;
00162 }
00163 
00164 //____________________________________________________________________________
00165 VldContext RawRunConfigBlock::GetVldContext() const
00166 {
00167    // build validity context
00168    RawBlockId rbid = GetBlockId();
00169    return VldContext(rbid.GetDetector(),rbid.GetSimFlag(),GetTime());
00170 }
00171 
00172 //____________________________________________________________________________
00173 const Char_t* RawRunConfigBlock::GetRunConfig() const
00174 {
00175    // return the run config string
00176 
00177    if (!fRunConfig) {
00178 
00179       Int_t*       insitu = fRawBlock+zzzz_last;
00180 
00181       UInt_t nwd = (fRawBlock+fSize) - insitu;
00182       fRunConfig = unpack_lel_to_string(insitu,nwd);
00183 
00184       // replace non-printable, non-newline characters with blanks
00185       // leave final null (which should be there ... but make sure it is).
00186       int nchar = nwd*sizeof(Int_t)/sizeof(Char_t) - 1;
00187       fRunConfig[nchar] = '\0';
00188       for (int i=0; i<nchar; ++i) {
00189         Char_t c = fRunConfig[i];
00190         if ( !isprint(c) && '\n'!=c ) fRunConfig[i] = ' ';
00191       }
00192 
00193    }
00194    return fRunConfig;
00195 }
00196 
00197 //____________________________________________________________________________
00198 std::ostream& RawRunConfigBlock::FormatToOStream(std::ostream& os, 
00199                                                  Option_t *option) const
00200 {
00201    RawDataBlock::FormatToOStream(os,option);
00202    if (option[0] == 'X') return os;
00203    
00204    // additional block specific formatted output is done here
00205 
00206    os << "Time " << GetTime().AsString("c") << endl;
00207    os << " Run " << GetRun()
00208       << " SubRun " << GetSubRun()
00209       << " RunType " << GetRunType() << endl;
00210 //   os << "'" << GetRunConfig() << "'" << endl;
00211    const Char_t* cfg = GetRunConfig();
00212    const Char_t* linestart = " | ";
00213    os << linestart;
00214    while (*cfg != '\0') {
00215       os << *cfg;
00216       if (*cfg == '\n' && *(cfg+1) != '\0') os << linestart;
00217       ++cfg;
00218    }
00219    os << endl;
00220 
00221    return os;
00222 }
00223 
00224 //____________________________________________________________________________

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