00001 #include "DataUtilities/DybArchiveList.h"
00002
00003 #include "src/TESDemoUse.h"
00004
00005 #include "GaudiKernel/IDataProviderSvc.h"
00006 #include "GaudiKernel/ISvcLocator.h"
00007
00008 #include "Event/TESDemoPositron.h"
00009 #include "Event/TESDemoNeutron.h"
00010 #include "Event/TESDemoAntiNeutrino.h"
00011
00012 using namespace DayaBay;
00013
00014 TESDemoUse::TESDemoUse( const std::string& name,
00015 ISvcLocator* pSvcLocator ) :
00016 GaudiAlgorithm(name,
00017 pSvcLocator)
00018 {
00019 declareProperty("PositronPath",
00020 m_positronPath="/Event/TESDemo/Positron",
00021 "Path from which to retrieve the Positron candidates");
00022 declareProperty("NeutronPath",
00023 m_neutronPath="/Event/TESDemo/Neutron",
00024 "Path from which to retrieve the Neutron candidates");
00025 declareProperty("AntiNeutrinoPath",
00026 m_antiNeutrinoPath="/Event/TESDemo/Anti-Neutrino",
00027 "Path, in the TES, into which the Anti-Neutrinos are stored");
00028 declareProperty("TimeWindow",
00029 m_window=0.00005,
00030 "The maximum time between Neutron and Positrion");
00031 }
00032
00033 StatusCode TESDemoUse::initialize() {
00034
00035 info() << "in initialize"
00036 << endreq;
00037 info() << m_positronPath
00038 << endreq;
00039 info() << m_neutronPath
00040 << endreq;
00041 info() << m_antiNeutrinoPath
00042 << endreq;
00043
00044 StatusCode status = service("EventDataArchiveSvc",
00045 p_archiveSvc);
00046 if (status.isFailure()) {
00047 Error("Service [EventDataArchiveSvc] not found",
00048 status);
00049 }
00050
00051 return StatusCode::SUCCESS;
00052
00053 }
00054
00055 StatusCode TESDemoUse::execute() {
00056
00057 SmartDataPtr<TESDemoNeutron> neutron(eventSvc(),
00058 m_neutronPath.value());
00059 if (0 == neutron) {
00060 return Print("No Neutron in this readout");
00061 }
00062
00063 SmartDataPtr<DybArchiveList> positrons(p_archiveSvc,
00064 m_positronPath.value());
00065 if (0 == positrons) {
00066 return Print("No Positrons have been found so far");
00067 }
00068
00069 if (positrons->empty()) {
00070 return Print("No Positrons are currently available");
00071 }
00072
00073 TESDemoAntiNeutrino::Container* antiNeutrinos = 0;
00074 bool searching = true;
00075 DybArchiveList::const_iterator finished = positrons->end();
00076 DybArchiveList::const_iterator iter = positrons->begin();
00077 while (searching &&
00078 finished != iter ) {
00079
00080 TESDemoPositron* positron = dynamic_cast<TESDemoPositron*>(*iter);
00081 if (0 == positron) {
00082 return Error("Positron archive does not contain correct type");
00083 }
00084
00085 double deltaTime = neutron->timeStamp().GetSeconds()
00086 - positron->timeStamp().GetSeconds();
00087 if (m_window.value() < deltaTime) {
00088 searching = false;
00089 } else {
00090 TESDemoAntiNeutrino* antiNeutrino =
00091 new TESDemoAntiNeutrino(positron,
00092 neutron);
00093
00094 if (0 == antiNeutrinos) {
00095 antiNeutrinos = new TESDemoAntiNeutrino::Container();
00096 }
00097 antiNeutrinos->add(antiNeutrino);
00098
00099 int positronId = positron->readout()->identifier();
00100 int neutronId = neutron->readout()->identifier();
00101 info() << "Stored one anti-neutrino built from readouts "
00102 << positronId
00103 << " and "
00104 << neutronId
00105 << endreq;
00106 }
00107 iter++;
00108 }
00109
00110 if (0 == antiNeutrinos) {
00111 info() << "No Anti-Neutrino candidates found"
00112 << endreq;
00113 return StatusCode::SUCCESS;
00114 } else {
00115 info() << "Time span of anti-neutrinos is:" << endreq;
00116 info() << " From: " << antiNeutrinos->earliest() << endreq;
00117 info() << " To: " << antiNeutrinos->latest() << endreq;
00118
00119 if (eventSvc()->registerObject(m_antiNeutrinoPath.value(),
00120 antiNeutrinos).isFailure()) {
00121 return Error("Failed to store anti-neutrinos in Event Store");
00122 }
00123 }
00124
00125 return StatusCode::SUCCESS;
00126 }
00127
00128 StatusCode TESDemoUse::finalize() {
00129
00130 info() << "in finalize"
00131 << endreq;
00132
00133 if (0 != p_archiveSvc) {
00134 p_archiveSvc->release();
00135 }
00136
00137 return StatusCode::SUCCESS;
00138
00139 }
00140
00141
00142