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

RawBlockRegistry.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawBlockRegistry.cxx,v 1.9 2009/02/28 21:46:16 gmieg Exp $
00003 //
00004 // A place for the available RawBlocks to register themselves
00005 //
00006 // Initial    JobCModuleRegistry  by messier@huhepl.harvard.edu
00007 // Adapted to RawBlockRegistry    by rhatcher@fnal.gov (2001-04-13)
00008 //
00010 #include <cstring>
00011 
00012 #include "RawData/RawBlockRegistry.h"
00013 #include "MessageService/MsgService.h"
00014 CVSID("$Id: RawBlockRegistry.cxx,v 1.9 2009/02/28 21:46:16 gmieg Exp $");
00015 
00016 RawBlockRegistry* RawBlockRegistry::fInstance = 0;
00017 
00018 //......................................................................
00019 
00020 std::ostream& operator<<(std::ostream& os, const RawBlockRegistry& rbr) 
00021 {
00022    std::list<RawBlockProxy*>::const_iterator itrRawBlockProxyTable;
00023    os << "Registered Raw Blocks:\n";
00024    for (itrRawBlockProxyTable  = rbr.fRawBlockProxyTable.begin();
00025         itrRawBlockProxyTable != rbr.fRawBlockProxyTable.end();
00026         ++itrRawBlockProxyTable) {
00027       os << " " << (*(*itrRawBlockProxyTable)) << endl;
00028   }
00029   return os;
00030 }
00031 
00032 //......................................................................
00033 
00034 RawBlockRegistry::~RawBlockRegistry()
00035 {
00036    // dtor is NOT responsible for destroying elements of the list;
00037    // they are created statically and are thus automagically
00038    // destroyed when the process ends
00039 }
00040 
00041 //......................................................................
00042 
00043 void RawBlockRegistry::Register(RawBlockProxy *proxy)
00044 {
00045   const char* blockName    = proxy->GetName();
00046   bool        isDCS        = proxy->IsDCS();
00047   int         blockMajorId = proxy->GetMajorId();
00048   // Add the raw block to the table
00049   if (this->LookUp(blockName)) {
00050     MSG("RawData", Msg::kWarning) 
00051       << "A raw block named " << blockName << " is already registered!\n"
00052       << "Duplicate block names are not allowed!\n";
00053     return;
00054   }
00055   else {
00056     // Do insertions in alphabetical order
00057     std::list<RawBlockProxy*>::iterator itrRawBlockProxyTable;
00058     for (itrRawBlockProxyTable  = fRawBlockProxyTable.begin();
00059          itrRawBlockProxyTable != fRawBlockProxyTable.end();
00060          ++itrRawBlockProxyTable) {
00061       if (strcmp(blockName,(*itrRawBlockProxyTable)->GetName())<0) {
00062         break;
00063       }
00064     }
00065     fRawBlockProxyTable.insert(itrRawBlockProxyTable,proxy);
00066 
00067     const char* isDCSstring = (isDCS) ? "DCS" : "DAQ";
00068     MSG("RawData", Msg::kDebug) 
00069       << "Registered block " << blockName << " "
00070       << isDCSstring << " "
00071       << blockMajorId << " proxy @ "
00072       << proxy << "." << endl;
00073   }
00074 }
00075 
00076 //......................................................................
00077 
00078 RawBlockProxy* RawBlockRegistry::LookUp(const char *name)
00079 {
00080   // Check if its in table
00081   std::list<RawBlockProxy*>::iterator itrRawBlockProxyTable;
00082   for (itrRawBlockProxyTable  = fRawBlockProxyTable.begin();
00083        itrRawBlockProxyTable != fRawBlockProxyTable.end();
00084        ++itrRawBlockProxyTable) {
00085     if (strcmp(name,(*itrRawBlockProxyTable)->GetName())==0) {
00086       return (*itrRawBlockProxyTable);
00087     }
00088   }
00089   return 0;
00090 }
00091 
00092 //......................................................................
00093 
00094 RawBlockProxy* RawBlockRegistry::LookUp(bool isDCS, int majorId)
00095 {
00096   // Check if its in table
00097   std::list<RawBlockProxy*>::iterator itrRawBlockProxyTable;
00098   for (itrRawBlockProxyTable  = fRawBlockProxyTable.begin();
00099        itrRawBlockProxyTable != fRawBlockProxyTable.end();
00100        ++itrRawBlockProxyTable) {
00101     if ((*itrRawBlockProxyTable)->IsDCS()      == isDCS &&
00102         (*itrRawBlockProxyTable)->GetMajorId() == majorId  ) {
00103       return (*itrRawBlockProxyTable);
00104     }
00105   }
00106   return 0;
00107 }
00108 
00109 //......................................................................
00110 
00111 RawBlockRegistry::RawBlockRegistry()
00112 {
00113 //#define DEBUG_RAWDATA
00114 #ifdef DEBUG_RAWDATA
00115 #include <MessageService/MsgStream.h>
00116   // Setting this debug level at run time is too late in this case...
00117   MsgService::Instance()->GetStream("RawData")->SetLogLevel(Msg::kVerbose);
00118 #endif
00119 }
00120 
00121 //......................................................................
00122 
00123 RawBlockRegistry& RawBlockRegistry::Instance() 
00124 {
00125   if (fInstance==0) {
00126      static RawBlockRegistry::Cleaner c; // end-of-run clean up
00127      c.ClassIsUsed();
00128 
00129      fInstance = new RawBlockRegistry;
00130   }
00131   return *fInstance;
00132 }
00133 

Generated on Sat Nov 7 01:27:16 2009 for loon by  doxygen 1.3.9.1