/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DybAbortEventAlg.cc
Go to the documentation of this file.
00001 
00002 #include "DybAbortEventAlg.h"
00003 #include "GaudiKernel/Incident.h" 
00004 #include "GaudiKernel/IIncidentSvc.h" 
00005 
00006 #include "Event/ReadoutHeader.h"
00007 
00008 using namespace std;
00009 using namespace DayaBay;
00010 
00011 
00012 DybAbortEventAlg::DybAbortEventAlg(const std::string& name, ISvcLocator* pSvcLocator)
00013     : GaudiAlgorithm(name,pSvcLocator)
00014 {
00015     declareProperty("Sites", m_siteMask=0xffffffff, 
00016                     "Bitmask of which sites to accept");
00017 
00018     declareProperty("Detectors", m_detectorMask=0xffffffff, 
00019                     "Bitmask of which detectors to accept");
00020 
00021     declareProperty("RequiredHeaders", m_requiredHeaders,
00022                     "List of TES locations of required header");
00023     
00024     declareProperty("RequireReadout", m_requireReadout,
00025                     "Require a ReadoutHeader to exist");
00026 
00027     declareProperty("Force", m_goth = false,
00028                     "Set true to abort all events");
00029 
00030 }
00031 
00032 DybAbortEventAlg::~DybAbortEventAlg()
00033 {
00034 }
00035 
00036 bool isin(const string& str, const vector<string>& lst) 
00037 {
00038     size_t siz = 0;
00039     siz = lst.size();
00040     if (!siz) return false;
00041     for (size_t ind=0; ind<siz; ++ind) {
00042         if (str == lst[ind]) return true;
00043     }
00044     return false;
00045 }
00046 
00047 StatusCode DybAbortEventAlg::initialize()
00048 {
00049     StatusCode sc = this->GaudiAlgorithm::initialize();
00050     if (sc.isFailure()) {
00051         error() << "GaudiAlgorithm failed to initialize" << endreq;
00052         return sc;
00053     }
00054 
00055     m_incidentSvc = svc<IIncidentSvc>("IncidentSvc",true);
00056 
00057     // Maybe add required readout path to list of required headers
00058     if (m_requireReadout.size()) {
00059         string ropath = ReadoutHeader::defaultLocation();
00060         if ("/Event/" == m_requireReadout.substr(0,7)) {
00061             ropath = m_requireReadout;
00062         }
00063         else {
00064             m_requireReadout = ropath;
00065         }
00066         if (! isin(ropath,m_requiredHeaders)) {
00067             m_requiredHeaders.push_back(ropath);
00068             debug () << "Adding path " << ropath << " to list of required headers" << endreq;
00069         }
00070     }
00071     
00072 
00073     // spew my configuration:
00074 
00075     if (m_goth) {
00076         info() << "Will always abort" << endreq;
00077         return StatusCode::SUCCESS;
00078     }
00079 
00080     if (m_requiredHeaders.size()) {
00081         info() << "Will abort if any of these are missing:\n";
00082         for (size_t ind=0; ind<m_requiredHeaders.size(); ++ind) {
00083             info() << "\t" << m_requiredHeaders[ind] << "\n";
00084         }
00085         info() << endreq;
00086 
00087         info() << "Required site mask: 0X" << hex << m_siteMask 
00088                << ", detector mask: 0X" << hex << m_detectorMask
00089                << endreq;
00090     }
00091     else {
00092         info() << "Nothing special required, I'll go to sleep" << endl;
00093     }
00094 
00095     return StatusCode::SUCCESS;
00096 }
00097 
00098 StatusCode DybAbortEventAlg::abort_event(const string& reason)
00099 {
00100     debug() << "Aborting current execution cycle due to " << reason << endreq;
00101     m_incidentSvc->fireIncident(Incident(name(),IncidentType::AbortEvent));
00102     return StatusCode::SUCCESS;
00103 }
00104 
00105 
00106 
00107 StatusCode DybAbortEventAlg::execute()
00108 {
00109     if (m_goth) {
00110         return abort_event("force option set");
00111     }
00112 
00113     if (0 == m_requiredHeaders.size()) { 
00114         return StatusCode::SUCCESS;
00115     }
00116 
00117     for (size_t ind=0; ind<m_requiredHeaders.size(); ++ind) {
00118         string loc = m_requiredHeaders[ind];
00119 
00120         if (! exist<DataObject>(loc)) {
00121             return abort_event("no object at: " + loc);
00122         }
00123 
00124         HeaderObject* ho = get<HeaderObject>(loc);
00125         if (!ho) {
00126             return abort_event("header not found: " + loc);
00127         }
00128 
00129         if (!ind) {             // first time through, check for matching site/det
00130             const Context& ctx = ho->context();
00131             Site::Site_t site = ctx.GetSite();
00132 
00133             if (! (site&m_siteMask)) {
00134                 return abort_event("failed to match site mask");
00135             }
00136 
00137             DetectorId::DetectorId_t det = ctx.GetDetId();
00138             int detmask = 0;
00139             if (det == DetectorId::kAll) {
00140                 detmask = 0xffffffff;
00141             }
00142             else {
00143                 detmask = 1 << det;
00144             }
00145             if (! (detmask&m_detectorMask)) {
00146                 return abort_event("failed to match detector mask");
00147             }
00148         }
00149 
00150         // maybe check for existing readout header with a readout/daqCrate payload
00151         if (m_requireReadout.size() && loc == m_requireReadout) {
00152             ReadoutHeader* roh = dynamic_cast<ReadoutHeader*>(ho);
00153             if (!roh) {
00154                 return abort_event("no readout header");
00155             }
00156             if ((!roh->readout()) && (!roh->daqCrate())) {
00157                 return abort_event("readout header with no payload");
00158             }
00159         }
00160     }
00161 
00162     return StatusCode::SUCCESS;
00163 }
00164 
00165 StatusCode DybAbortEventAlg::finalize()
00166 {
00167 
00168     return this->GaudiAlgorithm::finalize();
00169 }
00170 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:09:43 for DybAlg by doxygen 1.7.4