00001
00002
00003
00004
00005
00006
00007
00008
00010 #ifndef RAWBLOCKREGISTRY_H
00011 #define RAWBLOCKREGISTRY_H
00012
00013 #ifndef LIST
00014 #include <list>
00015 #define LIST
00016 #endif
00017 #ifndef RAWBLOCKPROXY_H
00018 #include "RawData/RawBlockProxy.h"
00019 #endif
00020
00021 #ifndef RAWBLOCKIDS_H
00022 #include "OnlineUtil/rawBlockIds.h"
00023 #endif
00024
00025 #include <iosfwd>
00026 #ifndef IOSTREAM
00027 #include <iostream>
00028 #endif
00029
00030 #include <cassert>
00031
00032 class RawDataBlock;
00033
00034 class RawBlockRegistry
00035 {
00036 friend std::ostream& operator<<(std::ostream& os, const RawBlockRegistry& rbr);
00037
00038 public:
00039
00040 typedef RawDataBlock (RawDataBlockCreator_t)(const char *name);
00041
00042 ~RawBlockRegistry();
00043
00044 static RawBlockRegistry& Instance();
00045 void Register(RawBlockProxy *rawBlockProxy);
00046 RawBlockProxy *LookUp(const char *name);
00047 RawBlockProxy *LookUp(bool isDCS, int majorId);
00048
00049 const std::list<RawBlockProxy*>& GetProxyList() const { return fRawBlockProxyTable; }
00050
00051 void Print(Option_t* ="") const { std::cout << Instance(); }
00052
00053 private:
00054
00055
00056 RawBlockRegistry();
00057 RawBlockRegistry(RawBlockRegistry& ) { abort(); }
00058 RawBlockRegistry& operator=(const RawBlockRegistry& rbr)
00059 { abort(); return const_cast<RawBlockRegistry&>(rbr); }
00060
00061 struct Cleaner {
00062 void ClassIsUsed() { };
00063 ~Cleaner() {
00064 if (RawBlockRegistry::fInstance!=0) {
00065 delete RawBlockRegistry::fInstance;
00066 RawBlockRegistry::fInstance = 0;
00067 }
00068 }
00069 };
00070 friend struct Cleaner;
00071
00072 private:
00073
00074 static RawBlockRegistry *fInstance;
00075 std::list<RawBlockProxy*> fRawBlockProxyTable;
00076 };
00077
00078
00080
00081
00082
00084 #define REGISTERRAWBLOCK(CLASS, MAJORID, ISDCS) \
00085 static class gs__Register__##CLASS##__ : public RawBlockProxy { \
00086 public: \
00087 gs__Register__##CLASS##__() { \
00088 fName = "" #CLASS ""; \
00089 fIsDCS = ISDCS; \
00090 const int majorMask = 0xffff; \
00091 fMajorId = MAJORID & majorMask; \
00092 assert((MAJORID & majorMask) == MAJORID); \
00093 RawBlockRegistry::Instance().Register(this); \
00094 } \
00095 RawDataBlock *CreateRawDataBlock(const Int_t* block) { \
00096 RawDataBlock *rdb = new CLASS(block); \
00097 return rdb; \
00098 } \
00099 } gs__module__##CLASS##__proxy__
00100
00101 #endif // RAWBLOCKREGISTRY_H