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

Knot.cxx

Go to the documentation of this file.
00001 
00002 
00003 #include "Knot.h"
00004 #include "AcnetDevice.h"
00005 
00006 #include <TTree.h>
00007 
00008 #include <map>
00009 #include <string>
00010 #include <iostream>
00011 using namespace std;
00012 
00013 static string acnet2branchname(string n)
00014 {
00015     string out = "";
00016     for (size_t ind=0; ind<8 && ind<n.size(); ++ind) { 
00017         if (n[ind] == ':') continue;
00018         out.push_back(tolower(n[ind]));
00019     }
00020     out += ".";
00021     return out;
00022 }
00023 
00024 class KnotImp {
00025 public:
00026 
00027     TTree& fTree;
00028     int fCurrentEntry;
00029     Knot::DeviceMap fDeviceMap;
00030 
00031     KnotImp(TTree& tree) : fTree(tree), fCurrentEntry(-1) {}
00032     ~KnotImp() {
00033         Knot::DeviceMap::iterator it, done = fDeviceMap.end();
00034         for (it = fDeviceMap.begin(); it != done; ++it) {
00035             delete it->second;
00036             it->second = 0;
00037         }
00038     }
00039 
00040     const AcnetDevice* GetDevice(const char* devname) {
00041         Knot::DeviceMap::iterator it = fDeviceMap.find(devname);
00042         if (it != fDeviceMap.end()) return it->second;
00043 
00044         AcnetDevice* ad = new AcnetDevice(devname);
00045         fDeviceMap[devname] = ad;
00046 
00047         string dns = acnet2branchname(devname);
00048         //cerr << "Getting device " << devname << " as " << dns << endl;
00049         fTree.SetBranchStatus(dns.c_str(),1);
00050         fTree.SetBranchAddress(dns.c_str(),&fDeviceMap[devname]);
00051         if (fCurrentEntry >= 0)
00052             this->GetEntry(fCurrentEntry);
00053         return ad;
00054     }
00055 
00056     int GetEntry(int entry) {
00057         fCurrentEntry = entry;
00058         return fTree.GetEntry(entry);
00059     }
00060 };
00061 
00062 Knot::Knot(TTree& tree) : fImp(new KnotImp(tree)) {}
00063 Knot::Knot() : fImp(0) {}
00064 
00065 void Knot::SetTree(TTree& tree)
00066 {
00067     if (fImp) delete fImp; fImp = 0;
00068     fImp = new KnotImp(tree);
00069 }
00070 
00071 int Knot::GetSize()
00072 {
00073     if (!fImp) return -1;
00074     return fImp->fTree.GetEntries();
00075 }
00076 
00077 int Knot::GetEntry(int entry)
00078 {
00079     if (!fImp) return -1;
00080     return fImp->GetEntry(entry);
00081 }
00082 
00083 int Knot::GetEntryNumber()
00084 {
00085     if (!fImp) return -1;
00086     return fImp->fCurrentEntry;
00087 }
00088 const AcnetDevice* Knot::GetDevice(const char* name)
00089 {
00090     if (!fImp) return 0;
00091     return fImp->GetDevice(name);
00092 }
00093     
00094 const Knot::DeviceMap& Knot::GetDevices() const
00095 {
00096     return fImp->fDeviceMap;
00097 }

Generated on Mon Feb 15 11:06:50 2010 for loon by  doxygen 1.3.9.1