| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DaqCrate.cc

Go to the documentation of this file.
00001 /*
00002  *  DaqCrate.cc
00003  *  DaqEvent
00004  *
00005  *  Created by Simon Patton on 81/1610.
00006  *  Copyright 2010 DayaBay Collaboration. All rights reserved.
00007  *
00008  */
00009 #include "Event/DaqCrate.h"
00010 
00011 #include "DaqReadoutFormat/ByteBuffer.h"
00012 #include "DaqReadoutFormat/RomData.h"
00013 #include "CbltReadoutFormat/CbltTraits.h"
00014 #include "Event/DaqPmtCrate.h"
00015 #include "Event/DaqLtb.h"
00016 #include "EventReadoutFormat/EventHeader.h"
00017 #include "EventReadoutFormat/EventTraits.h"
00018 #include "EventReadoutFormat/RomFragment.h"
00019 #include "EventReadoutFormat/RomHeader.h"
00020 #include "LtbReadoutFormat/LtbReadout.h"
00021 
00022 using DayaBay::DaqCrate;
00023 using DayaBay::DaqPmtCrate;
00024 using DayaBay::DaqLtb;
00025 using DayaBay::DaqLtbFrame;
00026 using DayaBay::Detector;
00027 using DybDaq::ByteBuffer;
00028 using DybDaq::CbltTraits;
00029 using DybDaq::EventHeader;
00030 using DybDaq::EventReadout;
00031 using DybDaq::EventTraits;
00032 using DybDaq::LtbReadout;
00033 using DybDaq::RomData;
00034 using DybDaq::RomFragment;
00035 using DybDaq::RomHeader;
00036 
00037 static DetectorId::DetectorId_t convertDetector(unsigned int daqDetectorId)
00038 {
00039     // Convert detector definition from DAQ to Offline convention 
00040     switch(daqDetectorId){
00041     case 1:
00042         return DetectorId::kAD1;
00043     case 2:
00044         return DetectorId::kAD2;
00045     case 3:
00046         return DetectorId::kAD3;
00047     case 4:
00048         return DetectorId::kAD4;
00049     case 5:
00050         return DetectorId::kIWS;
00051     case 6:
00052         return DetectorId::kOWS;
00053     case 7:
00054         return DetectorId::kRPC;
00055     default:
00056         break;
00057     }
00058     return DetectorId::kUnknown;
00059 }
00060 
00061 static unsigned int convertDetectorId(DetectorId::DetectorId_t detectorId)
00062 {
00063     // Convert detector definition from Offline convention to DAQ
00064     switch(detectorId){
00065     case DetectorId::kAD1:
00066         return 1;
00067     case DetectorId::kAD2:
00068         return 2;
00069     case DetectorId::kAD3:
00070         return 3;
00071     case DetectorId::kAD4:
00072         return 4;
00073     case DetectorId::kIWS:
00074         return 5;
00075     case DetectorId::kOWS:
00076         return 6;
00077     case DetectorId::kRPC:
00078         return 7;
00079     default:
00080         break;
00081     }
00082     return 0;
00083 }
00084 
00085 static Site::Site_t convertSite(unsigned int daqSiteId)
00086 {
00087     // Convert site definition from DAQ to Offline convention 
00088     switch(daqSiteId){
00089     case 1:
00090         return Site::kDayaBay;
00091     case 2:
00092         return Site::kLingAo;
00093     case 3:
00094         return Site::kFar;
00095     case 4:
00096         return Site::kMid;
00097     case 6:
00098         return Site::kSAB;
00099     default:
00100         break;
00101     }
00102     return Site::kUnknown;
00103 }
00104 
00105 DaqCrate::DaqCrate(const Detector& detector,
00106                    const unsigned int run,
00107                    const unsigned int event) :
00108     m_detector(0),
00109     m_eventReadout(new EventReadout(convertSite(detector.site()),
00110                                     convertDetectorId(detector.detectorId()),
00111                                     run,
00112                                     event,
00113                                     0, // Normal data type
00114                                     false,
00115                                     false,
00116                                     false,
00117                                     CbltTraits::defaultTraits(),
00118                                     EventTraits::defaultTraits())),
00119     m_ltb(0) {
00120 }
00121 
00122 DaqCrate::DaqCrate(const EventReadout* eventReadout) :
00123     m_detector(0),
00124     m_eventReadout(const_cast<EventReadout*>(eventReadout)),
00125     m_ltb(0) {
00126 }
00127 
00128 DaqCrate::DaqCrate(const DaqCrate& crate):
00129     m_detector(0),
00130     m_eventReadout(0),
00131     m_ltb(0) {
00132     const EventReadout& readout = crate.eventReadout();
00133     // WARNING: NExt line will fail to work if EventReadout is not ByteBuffer based.
00134     m_eventReadout = new EventReadout(readout);
00135 }
00136 
00137 DaqCrate::~DaqCrate() {
00138     flushCache();
00139 }
00140 
00141 DaqCrate& DaqCrate::operator=(const DaqCrate& rhs) {
00142   if (this != &rhs) {
00143       flushCache();
00144       m_detector = 0;
00145       m_eventReadout = new EventReadout(rhs.eventReadout());
00146       m_ltb = 0;
00147   }
00148   return *this;
00149 }
00150 
00151 void DaqCrate::flushCache() {
00152     if (0 != m_ltb) {
00153         delete m_ltb;
00154     }
00155     if (0 != m_eventReadout) {
00156         delete m_eventReadout;
00157     }
00158     if (0 != m_detector) {
00159         delete m_detector;
00160     }
00161 }
00162 
00163 const DaqPmtCrate* DaqCrate::asPmtCrate() const {
00164     return dynamic_cast<const DaqPmtCrate*>(this);
00165 }
00166 
00167 unsigned int DaqCrate::eventNumber() const {
00168     return m_eventReadout->header().event();
00169 }
00170 
00171 const DybDaq::EventReadout& DaqCrate::eventReadout() const {
00172     return *m_eventReadout;
00173 }
00174 
00175 unsigned int DaqCrate::localTriggerNumber() const {
00176     const DaqLtb& localTriggerBoard = ltb();
00177     return localTriggerBoard.localTriggerNumber();
00178 }
00179 
00180 unsigned int DaqCrate::runNumber() const {
00181     return m_eventReadout->header().run();
00182 }
00183 
00184 const TimeStamp& DaqCrate::triggerTime() const {
00185     const DaqLtbFrame& frame = firstLtbFrame();
00186     return frame.triggerTime();
00187 }
00188 
00189 DayaBay::Trigger::TriggerType_t DaqCrate::triggerType() const {
00190     const DaqLtbFrame& frame = firstLtbFrame();
00191     // TODO: Chek whether this should be the sum of all frames?
00192     return frame.triggerType();
00193 }
00194 
00195 const Detector& DaqCrate::detector() const {
00196     if (0 == m_detector) {
00197         const EventHeader& header = m_eventReadout->header();
00198         Detector** detector = const_cast<Detector**>(&m_detector);
00199         *(detector) = new Detector(convertSite(header.site()),
00200                                    convertDetector(header.detector()));
00201 
00202     }
00203     return *m_detector;
00204 }
00205 
00206 const DaqLtbFrame& DaqCrate::firstLtbFrame() const {
00207     const DaqLtb& crateLtb = ltb();
00208     return crateLtb.firstFrame();
00209 }
00210 
00211 const DaqLtb& DaqCrate::ltb() const {
00212     if ( 0 == m_ltb) {
00213         if (0 == m_eventReadout) {
00214             return *((DaqLtb*)0);
00215         }
00216         const EventReadout::RomFragmentPtrList& fragments = m_eventReadout->romFragments();
00217         EventReadout::RomFragmentPtrList::const_iterator fragment = fragments.begin();
00218         unsigned int ltbModuleType = m_eventReadout->header().eventTraits().moduleType(EventTraits::kLtbModule);
00219         while((ltbModuleType != ((*fragment)->header().moduleType()))
00220               && fragment != fragments.end()) {
00221             ++fragment;
00222         }
00223         if (fragment == fragments.end()) {
00224             return *((DaqLtb*)0);
00225         }
00226         const RomData& romData = (*fragment)->unwrappedData();
00227         const DaqLtb** ltb = const_cast<const DaqLtb**>(&m_ltb);
00228         *(ltb) = new DaqLtb(dynamic_cast<const LtbReadout&>(romData),
00229                             detector());
00230     }
00231     return *m_ltb;
00232 }
00233 
00234 bool DaqCrate::addLtb(const DaqLtb* ltb,
00235                       const unsigned int slot) {
00236     if (0 != m_ltb) {
00237         return false;
00238     }
00239     m_ltb = ltb;
00240     eventReadout().addReadout(ltb->ltbReadout(),
00241                               slot);
00242     return true;
00243 }
00244 
00245 DybDaq::EventReadout& DaqCrate::eventReadout() {
00246     return *m_eventReadout;
00247 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:24:28 2011 for DaqEvent by doxygen 1.4.7