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

RawConfigFilesBlock.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawConfigFilesBlock.cxx,v 1.9 2005/06/07 23:12:21 rhatcher Exp $
00003 // 
00004 // RawConfigFilesBlock 
00005 // 
00006 // RawConfigFilesBlock holds the ConfigFile info (for archival purposes)
00007 //
00008 // Author:  R. Hatcher 2002.05.07
00009 //
00011 
00012 #include "RawData/RawConfigFilesBlock.h"
00013 
00014 UInt_t RawConfigFilesBlock::fgDebugFlags = 0;
00015 
00016 #include "MessageService/MsgService.h"
00017 //CVSID("$Id: RawConfigFilesBlock.cxx,v 1.9 2005/06/07 23:12:21 rhatcher Exp $");
00018 #include "MessageService/MsgFormat.h"
00019 
00020 #include "RawData/RawBlockRegistry.h"
00021 REGISTERRAWBLOCK(RawConfigFilesBlock,kMdBlockConfigFiles,0);
00022 
00023 #include "RawData/littleendian_strings.h"
00024 #include <string.h>
00025 
00026 ClassImp(RawConfigFilesBlock)
00027 
00028 enum ERunStartBlkPos {
00029    indx_size      = 0,
00030    indx_checksum  = 1,
00031    indx_blockid   = 2,
00032    zzzz_last_v1   = indx_blockid+1,
00033    indx_run       = 3,
00034    indx_subrun    = 4,
00035    indx_runtype   = indx_subrun,
00036    indx_startsec  = 5,
00037    indx_startnsec = 6,
00038    zzzz_last      = 7
00039 };
00040 
00041 //____________________________________________________________________________
00042 RawConfigFilesBlock::RawConfigFilesBlock()
00043    : RawDataBlock(), fConfigFile(0)
00044 {
00045    // Default constructor
00046 }
00047 
00048 //____________________________________________________________________________
00049 RawConfigFilesBlock::RawConfigFilesBlock(const Int_t *block)
00050    : RawDataBlock(block), fConfigFile(0)
00051 {
00052    //  stored block format is:
00053    //---------------------
00054    //  0   # words in block
00055    //  1   checksum
00056    //  2   Block Id
00057    //-----
00058    //  3   run #
00059    //  4   {subrun#| run type}
00060    //  5   time (sec)
00061    //  6   time (nsec)
00062    //  7   comment string (padded to 4 char)
00063 
00064 }
00065 
00066 //____________________________________________________________________________
00067 RawConfigFilesBlock::RawConfigFilesBlock(const VldContext& vldc, Int_t run,
00068                                        Short_t subrun, Short_t runtype,
00069                                        const Char_t* comment)
00070    : RawDataBlock(), fConfigFile(0)
00071 {
00072    // Component ctor 
00073 
00074    UInt_t nwdc  = nwords_in_string(comment);
00075    fSize = zzzz_last + nwdc;
00076    if (fRawBlock) delete [] fRawBlock;
00077    fRawBlock = new Int_t [fSize];  
00078 
00079    fRawBlock[0] = fSize;
00080 // fRawBlock[1] = checksum... see below
00081  
00082    RawBlockRegistry& rbr = RawBlockRegistry::Instance();
00083    RawBlockProxy*    rbp = rbr.LookUp("RawConfigFilesBlock");
00084  
00085    Bool_t isDCS   = rbp->IsDCS();
00086    Int_t  majorId = rbp->GetMajorId();
00087    Int_t  minorId = 2;
00088    RawBlockId rbid(majorId,minorId,isDCS,
00089                    vldc.GetDetector(),vldc.GetSimFlag());
00090    fRawBlock[2] = rbid.GetEncoded();
00091  
00092    fRawBlock[indx_run]     = run;
00093    fRawBlock[indx_subrun]  = (subrun&0xffff)<<16 | (runtype&0xffff);
00094    fRawBlock[indx_startsec]     = vldc.GetTimeStamp().GetSec();
00095    fRawBlock[indx_startnsec]    = vldc.GetTimeStamp().GetNanoSec();
00096  
00097    fRawBlock[fSize-1] = 0; // ensure final '\0'
00098    pack_string_in_lel(fRawBlock+zzzz_last,comment);
00099 
00100    // fill checksum
00101    rdxsum_fill((long*)fRawBlock,0);
00102 }
00103 
00104 //____________________________________________________________________________
00105 RawConfigFilesBlock::~RawConfigFilesBlock()
00106 {
00107    // dtor
00108    if (fConfigFile) {
00109       delete [] fConfigFile;
00110       fConfigFile = 0;
00111    }
00112 }
00113 
00114 //____________________________________________________________________________
00115 RawConfigFilesBlock& RawConfigFilesBlock::operator=(const RawConfigFilesBlock& rhs)
00116 {
00117    // deep copy assignment 
00118   if (this != &rhs) {
00119     RawDataBlock::operator=(rhs);
00120     if (fConfigFile) { delete [] fConfigFile; fConfigFile = 0; }
00121   }
00122   return *this;
00123 }
00124 
00125 //____________________________________________________________________________
00126 VldTimeStamp RawConfigFilesBlock::GetTime() const
00127 {
00128    // get the trigger time
00129 
00130    if ( fSize >= zzzz_last )
00131       return VldTimeStamp(fRawBlock[indx_startsec],fRawBlock[indx_startnsec]);
00132  
00133    return VldTimeStamp((time_t)0,(Int_t)0);
00134 }
00135  
00136 //____________________________________________________________________________
00137 Int_t RawConfigFilesBlock::GetRun() const
00138 {
00139    // get the run number
00140 
00141    if ( fSize >= zzzz_last ) return fRawBlock[indx_run];
00142    return -1;
00143 }
00144  
00145 //____________________________________________________________________________
00146 Short_t RawConfigFilesBlock::GetSubRun() const
00147 {
00148    // get the subrun number
00149 
00150    if ( fSize >= zzzz_last ) 
00151       return (fRawBlock[indx_subrun]>>16)&0xffff;
00152    return -1;
00153 }
00154  
00155 //____________________________________________________________________________
00156 Short_t RawConfigFilesBlock::GetRunType() const
00157 {
00158    // get the run type
00159 
00160    if ( fSize >= zzzz_last ) 
00161       return fRawBlock[indx_runtype]&0xffff;
00162    return -1;
00163 }
00164 
00165 //____________________________________________________________________________
00166 VldContext RawConfigFilesBlock::GetVldContext() const
00167 {
00168    // build validity context
00169    RawBlockId rbid = GetBlockId();
00170    return VldContext(rbid.GetDetector(),rbid.GetSimFlag(),GetTime());
00171 }
00172 
00173 //____________________________________________________________________________
00174 const Char_t* RawConfigFilesBlock::GetConfigFile() const
00175 {
00176    // return the run config string
00177 
00178    if (!fConfigFile) {
00179 
00180       Int_t*       insitu = fRawBlock+zzzz_last;
00181 
00182       UInt_t nwd = (fRawBlock+fSize) - insitu;
00183       fConfigFile = unpack_lel_to_string(insitu,nwd);
00184 
00185       // replace non-printable, non-newline characters with blanks
00186       // leave final null (which should be there ... but make sure it is).
00187       int nchar = nwd*sizeof(Int_t)/sizeof(Char_t) - 1;
00188       fConfigFile[nchar] = '\0';
00189       for (int i=0; i<nchar; ++i) {
00190         Char_t c = fConfigFile[i];
00191         if ( !isprint(c) && '\n'!=c ) fConfigFile[i] = ' ';
00192       }
00193 
00194    }
00195    return fConfigFile;
00196 }
00197 
00198 //____________________________________________________________________________
00199 std::string RawConfigFilesBlock::GuessFileType() const
00200 {
00201    // guess the type of config file this might be
00202    // current version don't have this in any explicit form
00203 
00204   const Char_t* haystack = GetConfigFile();
00205   
00206   // newer blocks actually are tagged as to what file they are
00207   const Char_t* starttag = "<config name=\"";
00208   const Char_t* beginname = strstr(haystack,starttag);
00209   if (beginname) {
00210       beginname += strlen(starttag);  // move to after the opening double-quote
00211       const Char_t* endquote = strstr(beginname,"\""); // closing double-quotes
00212       if (endquote) {
00213           std::string configName = "";
00214           for (const Char_t* iptr = beginname; iptr<endquote; ++iptr)
00215               configName += *iptr;
00216           return configName;
00217       }
00218   }
00219 
00220   // didn't find the new indicator of the config name
00221   // resort to guessing ... bleh!
00222 
00223   // strstr returns 0 if substring is not found
00224   
00225   // these are empirically determined correlations between the
00226   // actual file type and some string uniquely found in them
00227   // NOTE: angerous because the files are subject to change, new ones
00228   // may need to be added.
00229 
00230   if (strstr(haystack,"dcp.config file"))             return "dcp.config";
00231   if (strstr(haystack,"vaClockPeriod"))               return "varc.config";
00232   if (strstr(haystack,"VME Access ModuleId"))         return "master.config";
00233   if (strstr(haystack,"Trigger Processor Config"))    return "tp.config";
00234   if (strstr(haystack,"config file for LI control"))  return "li.config";
00235   if (strstr(haystack,"<branches>"))                  return "daq.config";
00236   if (strstr(haystack,"ropConfig"))                   return "rop.config";
00237   if (strstr(haystack,"<timemaster>"))                return "tpc.config";
00238   if (strstr(haystack,"pvicBrpNode"))                 return "pvic.config";
00239   if (strstr(haystack,"planemap>"))                   return "detector.config";
00240   if (strstr(haystack,"brpHost"))                     return "brp.config";
00241   if (strstr(haystack,"<Pedestal>"))                  return "runType.config";
00242   if (strstr(haystack,"<runstats>"))                  return "runtimes.config";
00243   if (strstr(haystack,"<fileConfig>"))                return "dcp.config";
00244   if (strstr(haystack,"<startTimes>"))                return "liStartTimes.config";
00245 
00246   return "undetermined.config";
00247   
00248 }
00249 
00250 //____________________________________________________________________________
00251 std::ostream& RawConfigFilesBlock::FormatToOStream(std::ostream& os, 
00252                                                    Option_t *option) const
00253 {
00254    RawDataBlock::FormatToOStream(os,option);
00255    if (option[0] == 'X') return os;
00256    
00257    // additional block specific formatted output is done here
00258 
00259    os << "Time " << GetTime().AsString("c") << endl;
00260    os << " Run " << GetRun()
00261       << " SubRun " << GetSubRun()
00262       << " RunType " << GetRunType() << endl;
00263    os << " GuessFileType: '" << GuessFileType() << "'" << endl;
00264    const Char_t* cfg = GetConfigFile();
00265    const Char_t* linestart = " | ";
00266    os << linestart;
00267    while (*cfg != '\0') {
00268       os << *cfg;
00269       if (*cfg == '\n' && *(cfg+1) != '\0') os << linestart;
00270       ++cfg;
00271    }
00272    os << endl;
00273 
00274    return os;
00275 }
00276 
00277 //____________________________________________________________________________

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