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

In This Package:

SimHeaderCnv.cc

Go to the documentation of this file.
00001 #include "SimHeaderCnv.h"
00002 #include "PerBaseEvent/HeaderObjectCnv.h"
00003 
00004 #include "PerSimEvent/PerSimHitHeader.h"
00005 #include "Event/SimHitHeader.h"
00006 
00007 #include "PerSimEvent/PerSimUnobservableStatistics.h"
00008 #include "Event/SimUnobservableStatisticsHeader.h"
00009 
00010 using namespace DayaBay;
00011 using namespace std;
00012 
00013 SimHeaderCnv::SimHeaderCnv(ISvcLocator* svc)
00014     : RootIOTypedCnv<PerSimHeader,SimHeader>("PerSimHeader",
00015                                              classID(),svc)
00016 {
00017     // set maximum number of warnings of "no particle history to save"
00018     m_maxNoPHtoS = 10;
00019     m_NoPHtoSmsgs=  0;
00020 
00021     m_pruneSimHits = false;
00022     char* foo = getenv("NUWA_PRUNESIMHITS");
00023     if (foo) {
00024         m_pruneSimHits = true;
00025     }
00026 }
00027 
00028 SimHeaderCnv::~SimHeaderCnv()
00029 {
00030 }
00031 
00032 
00033 StatusCode SimHeaderCnv::PerToTran(const PerSimHeader& perobj,
00034                                    DayaBay::SimHeader& tranobj)
00035 {
00036     StatusCode sc = HeaderObjectCnv::toTran(perobj,tranobj);
00037     if (sc.isFailure()) return sc;
00038 
00039     MsgStream log(msgSvc(), "SimHeaderCnv::PerToTran");
00040 
00041     // Convert the historian part
00042     vector<SimTrack*> timap;
00043     const PerSimParticleHistory* pph = perobj.history;
00044     if (!pph) {
00045         log << MSG::DEBUG
00046             << "No particle history in persistent object." << endreq;
00047         tranobj.setParticleHistory(0);
00048     }
00049     else {
00050         SimParticleHistory* ph = convert(timap,tranobj,*pph);
00051         if (ph) {
00052             tranobj.setParticleHistory(ph);
00053         }
00054         else {
00055             log << MSG::ERROR
00056                 << "Failed to convert the SimParticleHistory" << endreq;
00057         }
00058     }
00059 
00060     if (perobj.hits) { // Convert the Hits part
00061         const PerSimHitHeader::phc_map& pcolmap = perobj.hits->hitCollections;
00062 
00063         log << MSG::DEBUG << "Reading " << pcolmap.size() << " hit collections" << endreq;
00064 
00065         SimHitHeader* shit_header = new SimHitHeader;
00066         shit_header->setHeader(&tranobj);
00067         tranobj.setHits(shit_header);
00068 
00069         PerSimHitHeader::phc_map::const_iterator it, done = pcolmap.end();
00070         for (it = pcolmap.begin(); it != done; ++it) {
00071             int detectorID = it->first;
00072             const PerSimHitCollection* phc = it->second;
00073             SimHitCollection* hc = convert(timap,*phc);
00074             hc->setHeader(shit_header);
00075             shit_header->addHitCollection(hc);
00076 
00077             DayaBay::Detector det((short)detectorID);
00078             log << MSG::DEBUG << "Reading " << phc->hits.size() 
00079                 << " hits for detector " << det.detName()
00080                 << " ("
00081                 << detectorID 
00082                 << ")"
00083                 << endreq;
00084         }
00085     }
00086     else {
00087         log << MSG::DEBUG << "No persistent hits to convert" << endreq;
00088     }
00089 
00090     { // Convert the stats part
00091         const PerSimUnobservableStatistics* pstat = perobj.stats;
00092         if (!pstat) {
00093             log << MSG::DEBUG
00094                 << "No unobservable statistics in persistent object." << endreq;
00095             tranobj.setUnobservableStatistics(0);
00096         }
00097         else {
00098             SimUnobservableStatisticsHeader* stat = convert(*pstat);
00099             tranobj.setUnobservableStatistics(stat);
00100         }
00101     }
00102 
00103     return StatusCode::SUCCESS;
00104 }
00105 
00106 StatusCode SimHeaderCnv::TranToPer(const DayaBay::SimHeader& tranobj,
00107                                    PerSimHeader& perobj)
00108 {
00109     StatusCode sc = HeaderObjectCnv::toPer(tranobj,perobj);
00110     if (sc.isFailure()) return sc;
00111 
00112     MsgStream log(msgSvc(), "SimHeaderCnv::TranToPer");
00113 
00114     map<const SimTrack*,int> trackMap;
00115 
00116     { // Convert the historian part
00117         const SimParticleHistory* ph = tranobj.particleHistory();
00118         delete perobj.history;
00119         if (!ph) {
00120           m_NoPHtoSmsgs += 1;
00121           if ( m_NoPHtoSmsgs < m_maxNoPHtoS ) {
00122             log << MSG::WARNING
00123                 << "No Particle history to save" << endreq;
00124           }
00125           if ( m_NoPHtoSmsgs == m_maxNoPHtoS ) {
00126             log << MSG::WARNING
00127                 << "No Particle history to save. Additional warnings will be suppressed. " << endreq;
00128           }
00129           
00130             perobj.history = 0;
00131         }
00132         else {
00133             PerSimParticleHistory* pph = convert(trackMap,*ph);
00134             perobj.history = pph;
00135         }
00136     }
00137 
00138     { // Convert the Hits part
00139         if (perobj.hits) {
00140             delete perobj.hits;
00141             perobj.hits = 0;
00142         }
00143         perobj.hits = new PerSimHitHeader();
00144         PerSimHitHeader::phc_map& phcolmap = perobj.hits->hitCollections;
00145         if (m_pruneSimHits) {
00146             static int count = 0; 
00147             ++count;
00148             if (count<10) {
00149                 log << MSG::INFO << "Not saving SimHits, will say " << 10-count << " more times" << endreq;
00150             }
00151         }
00152         else {
00153             const SimHitHeader* header = tranobj.hits();
00154             if (!header) {
00155                 static int count = 0; 
00156                 if (count++ < 10) {
00157                     log << MSG::WARNING << "No Hit Header (I will say it " 
00158                         << 10 - count << " times again)" << endreq;
00159                 }
00160             }
00161             else {
00162                 const SimHitHeader::hc_map& colmap = header->hitCollection();
00163                 
00164                 log << MSG::DEBUG << "Saving " << colmap.size() << " hit collections" << endreq;
00165                 
00166                 SimHitHeader::hc_map::const_iterator it, done = colmap.end();
00167                 for (it = colmap.begin(); it != done; ++it) {
00168                     int detectorID = it->first;
00169                     static int nUnknownDet = 0;
00170                     if( detectorID == DetectorId::kUnknown ) {
00171                         nUnknownDet++;
00172                         if( nUnknownDet<10 ) {
00173                             log << MSG::WARNING << "No hit should be from unknown detector (I will say it "
00174                                 << 10 - nUnknownDet << " times again)" << endreq;
00175                         }
00176                     } 
00177                     else {
00178                         const SimHitCollection* hc = it->second;
00179                         PerSimHitCollection* phc = convert(trackMap,*hc);
00180                         phcolmap[detectorID] = phc;
00181                         DayaBay::Detector det((short)detectorID);
00182                         log << MSG::DEBUG << "Saving " << phc->hits.size() 
00183                             << " hits for detector " << det.detName()
00184                             << " ("
00185                             << detectorID 
00186                             << ")"
00187                             << endreq;
00188                     }
00189                 }
00190             }
00191         }
00192         log << MSG::DEBUG << "Saving " << phcolmap.size() << " hit collections" << endreq;
00193     }    
00194 
00195     { // Convert the stats part
00196         const SimUnobservableStatisticsHeader* stat = tranobj.unobservableStatistics();
00197         if (!stat) {
00198             log << MSG::DEBUG
00199                 << "No unobservable statistics" << endreq;
00200         }
00201         else {
00202             PerSimUnobservableStatistics* pstat = convert(*stat);
00203             delete perobj.stats;
00204             perobj.stats = pstat;
00205         }
00206     }
00207 
00208     return StatusCode::SUCCESS;
00209 }
00210 
00211 
00212     
00213 StatusCode SimHeaderCnv::fillRepRefs(IOpaqueAddress*, DataObject* dobj)
00214 {
00215     MsgStream log(msgSvc(), "SimHeaderCnv::fillRepRefs");
00216     SimHeader* sh = dynamic_cast<SimHeader*>(dobj);
00217 
00218     log << MSG::DEBUG
00219         << "Saving links to " << sh->inputHeaders().size() 
00220         << " input headers" << endreq;
00221 
00222     StatusCode sc = HeaderObjectCnv::fillPer(m_rioSvc,*sh,*m_perOutObj);
00223     if (sc.isFailure()) {
00224         log << MSG::ERROR << "Failed to fill HeaderObject part" << endreq;
00225         return sc;
00226     }
00227 
00228     // ... fill SimHeader part...
00229     return sc;
00230 }
00231 
00232 StatusCode SimHeaderCnv::fillObjRefs(IOpaqueAddress*, DataObject* dobj)
00233 {
00234     MsgStream log(msgSvc(), "SimHeaderCnv::fillObjRefs");
00235     HeaderObject* hobj = dynamic_cast<HeaderObject*>(dobj);
00236     StatusCode sc = HeaderObjectCnv::fillTran(m_rioSvc,*m_perInObj,*hobj);
00237     if (sc.isFailure()) {
00238         log << MSG::ERROR << "Failed to fill HeaderObject part" << endreq;
00239         return sc;
00240     }
00241 
00242     log << MSG::DEBUG
00243         << "Restored links to " << hobj->inputHeaders().size() 
00244         << " input headers" << endreq;
00245 
00246     // ... fill SimHeader part...
00247 
00248     DayaBay::SimHeader* sh = dynamic_cast<DayaBay::SimHeader*>(hobj);
00249     relate(*sh);
00250 
00251     return sc;
00252 }
00253 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:35:44 2011 for PerSimEvent by doxygen 1.4.7