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

RawBeamMonBlock.cxx

Go to the documentation of this file.
00001 // $Id: RawBeamMonBlock.cxx,v 1.13 2005/11/10 23:02:36 bv Exp $
00002 
00003 #include "RawBeamMonBlock.h"
00004 #include "RawBeamData.h"
00005 #include "RawBlockRegistry.h"
00006 REGISTERRAWBLOCK(RawBeamMonBlock,kMdBlockBeamMonPayload,1);
00007 
00008 #include <OnlineUtil/rawBlockIds.h>
00009 #include <OnlineUtil/rawBeamDataBlockLayout.h>
00010 
00011 //UInt_t RawBeamMonBlock::fgDebugFlags = 0;
00012 
00013 #include <ostream>
00014 #include <cassert>
00015 
00016 using namespace std;
00017 
00018 RawBeamMonBlock::RawBeamMonBlock() : RawDataBlock()
00019 {
00020     fEarliest = 0;
00021     fDevices.clear();
00022 }
00023 
00024 RawBeamMonBlock::RawBeamMonBlock(const Int_t *block)
00025    : RawDataBlock(block)
00026 {
00027     fEarliest = 0;
00028     fDevices.clear();
00029 }
00030 
00031 RawBeamMonBlock::~RawBeamMonBlock()
00032 {
00033     // delete any RawBeamData objects created!
00034     map<string,RawBeamData*>::iterator it, done = fDevices.end();
00035     for (it = fDevices.begin(); it != done; ++it) {
00036         if (it->second) delete it->second;
00037         it->second = 0;
00038     }
00039 }
00040 
00041 RawBeamMonBlock::RawBeamMonBlock(const RawBeamMonBlock &rhs)
00042     : RawDataBlock(rhs)
00043 {
00044     fEarliest = rhs.fEarliest;
00045     fDevices.clear();
00046 }
00047 
00048 RawBeamMonBlock& RawBeamMonBlock::operator=(const RawBeamMonBlock& rhs)
00049 {
00050     if (this == &rhs) return *this;
00051     RawDataBlock::operator=(rhs);
00052     fEarliest = rhs.fEarliest;
00053     fDevices.clear();
00054     return *this;
00055 }
00056 
00057 
00058 void RawBeamMonBlock::SetFiltered(bool filter)
00059 {
00060     fEarliest = filter ? 0 : -1;
00061     fDevices.clear();
00062 }
00063 
00064 void RawBeamMonBlock::Unpacker() const
00065 {
00066     const int* end = fRawBlock + fRawBlock[pld_indx_size];
00067     const int ndevs_tot = fRawBlock[pld_indx_num_devices];
00068 
00069     int ndevs = 0;
00070 
00071     for (int* data = fRawBlock+pld_indx_data_start;
00072          data < end;
00073          data += pld_nvalues_offset + data[pld_nvalues_offset] + 1, ++ndevs) {
00074         
00075         RawBeamData* rbd = new RawBeamData(data);
00076 
00077         if (fEarliest >= 0) {
00078             double t = rbd->GetSeconds() + rbd->GetMsecs()/1000.0;
00079             if (fEarliest < 1 || (t > 1 && t < fEarliest)) fEarliest = t;
00080         }
00081         
00082         string name = rbd->GetName();
00083         fDevices[name] = rbd;
00084     }
00085     assert (ndevs == ndevs_tot);
00086 
00087     if (fEarliest < 0) return;
00088 
00089     // Implement filter - this doesn't touch the underlying data, just
00090     // how it is mapped.
00091     map<string,RawBeamData*> newmap;
00092     map<string,RawBeamData*>::iterator it, done = fDevices.end();
00093     for (it = fDevices.begin(); it != done; ++it) {
00094         double t = it->second->GetSeconds() + it->second->GetMsecs()/1000.0;
00095         if (t - fEarliest > 1.0) {
00096             delete it->second;
00097             it->second = 0;
00098         }
00099         else newmap[it->first] = it->second;
00100     }
00101 
00102     fDevices.clear();
00103     fDevices = newmap;
00104 }
00105 
00106 std::vector<string> RawBeamMonBlock::GetNames() const
00107 {
00108     if (0 == fDevices.size()) this->Unpacker();
00109 
00110     vector<string> res;
00111     map<string,RawBeamData*>::iterator it, done = fDevices.end();
00112     for (it=fDevices.begin(); it != done; ++it) {
00113         res.push_back(it->first);
00114     }
00115     return res;
00116 }
00117 
00118 const RawBeamData* RawBeamMonBlock::operator[](string device_name) const
00119 {
00120     if (0 == fDevices.size()) this->Unpacker();
00121 
00122     map<string,RawBeamData*>::iterator it = fDevices.find(device_name);
00123     if (it == fDevices.end()) return 0;
00124 
00125     return it->second;
00126 }
00127 
00128 
00129 ostream& RawBeamMonBlock::FormatToOStream(ostream& os, Option_t *option) const
00130 {
00131     if (0 == fDevices.size()) this->Unpacker();
00132     RawDataBlock::FormatToOStream(os,option);
00133     if (option[0] == 'X') return os;
00134     
00135     vector<string> names = this->GetNames();
00136     os << names.size() << " devices:\n";
00137     
00138     for (size_t ind = 0; ind < names.size(); ++ind) {
00139         string name = names[ind];
00140         const RawBeamData* rbd = (*this)[name];
00141         if (!rbd) {
00142             os << name << " has no data!!!\a\n";
00143             continue;
00144         }
00145         os.precision(20);
00146         os << name << " @ " << rbd->GetSeconds() << "." << rbd->GetMsecs() << endl;
00147         size_t ndata = rbd->GetDataLength();
00148         const double* data = rbd->GetData();
00149         for (size_t ind2 = 0; ind2 < ndata; ++ind2)
00150             os << "\t" << ind2 << ": " << data[ind2] << endl;
00151     }
00152 
00153     return os;
00154 }
00155 
00156 int RawBeamMonBlock::TclkTriggerEvent() const
00157 {
00158     return fRawBlock[pld_indx_clbk_event];
00159 }
00160 
00161 int RawBeamMonBlock::TclkTriggerDelay() const
00162 {
00163     return fRawBlock[pld_indx_clbk_delay];
00164 }
00165 
00166 
00167 ClassImp(RawBeamMonBlock)

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