00001 #include "SimTrigHeaderCnv.h"
00002 #include "PerBaseEvent/HeaderObjectCnv.h"
00003
00004
00005
00006
00007
00008
00009 #include <vector>
00010 #include <map>
00011
00012
00013 using namespace DayaBay;
00014 using namespace std;
00015
00016 SimTrigHeaderCnv::SimTrigHeaderCnv(ISvcLocator* svc)
00017 : RootIOTypedCnv<PerSimTrigHeader,SimTrigHeader>("PerSimTrigHeader",
00018 classID(),svc)
00019 {
00020 }
00021
00022 SimTrigHeaderCnv::~SimTrigHeaderCnv()
00023 {
00024 }
00025
00026 StatusCode SimTrigHeaderCnv::PerToTran(const PerSimTrigHeader& perobj,
00027 SimTrigHeader& tranobj )
00028 {
00029 MsgStream log(msgSvc(), "SimTrigHeaderCnv::PerToTran");
00030
00031 StatusCode sc = HeaderObjectCnv::toTran(perobj,tranobj);
00032 if (sc.isFailure()) return sc;
00033 DayaBay::SimTrigCommandHeader *tch = convert( *(perobj.commandHeader) );
00034 tch->setHeader(&tranobj);
00035 tranobj.setCommandHeader( tch );
00036
00037 return StatusCode::SUCCESS;
00038 }
00039
00040 StatusCode SimTrigHeaderCnv::TranToPer(const SimTrigHeader& tranobj,
00041 PerSimTrigHeader& perobj )
00042 {
00043 MsgStream log(msgSvc(), "SimTrigHeaderCnv::TranToPer");
00044
00045 StatusCode sc = HeaderObjectCnv::toPer(tranobj,perobj);
00046 if (sc.isFailure()) return sc;
00047
00048 delete perobj.commandHeader;
00049
00050 if( tranobj.commandHeader() != 0 ) {
00051 perobj.commandHeader = convert( *(tranobj.commandHeader()) );
00052 }
00053 return StatusCode::SUCCESS;
00054 }
00055
00056 StatusCode SimTrigHeaderCnv::fillRepRefs(IOpaqueAddress*, DataObject* dobj)
00057 {
00058 MsgStream log(msgSvc(), "SimTrigHeaderCnv::fillRepRefs");
00059 SimTrigHeader* th = dynamic_cast<SimTrigHeader*>(dobj);
00060
00061 log << MSG::DEBUG
00062 << "Saving links to " << th->inputHeaders().size()
00063 << " input headers" << endreq;
00064
00065 StatusCode sc = HeaderObjectCnv::fillPer(m_rioSvc,*th,*m_perOutObj);
00066 if (sc.isFailure()) {
00067 log << MSG::ERROR << "Failed to fill HeaderObject part" << endreq;
00068 return sc;
00069 }
00070
00071
00072 return sc;
00073 }
00074
00075 StatusCode SimTrigHeaderCnv::fillObjRefs(IOpaqueAddress*, DataObject* dobj)
00076 {
00077 MsgStream log(msgSvc(), "SimTrigHeaderCnv::fillObjRefs");
00078 HeaderObject* hobj = dynamic_cast<HeaderObject*>(dobj);
00079 StatusCode sc = HeaderObjectCnv::fillTran(m_rioSvc,*m_perInObj,*hobj);
00080 if (sc.isFailure()) {
00081 log << MSG::ERROR << "Failed to fill HeaderObject part" << endreq;
00082 return sc;
00083 }
00084
00085 log << MSG::DEBUG
00086 << "Restored links to " << hobj->inputHeaders().size()
00087 << " input headers" << endreq;
00088
00089
00090 return sc;
00091 }
00092
00093
00094
00095 PerSimTrigCommandHeader* SimTrigHeaderCnv::convert(const SimTrigCommandHeader& trigCH)
00096 {
00097 MsgStream log(msgSvc(), "SimTrigHeaderCnv::convet Header");
00098 PerSimTrigCommandHeader::PerComVector outCollVec;
00099 SimTrigCommandHeader::detCollMap inCollVec;
00100 inCollVec = trigCH.collections();
00101 SimTrigCommandHeader::detCollMap::iterator it;
00102 log << MSG::DEBUG <<"** Converting"
00103 << inCollVec.size()
00104 << " SimTrigCommandCollections."
00105 << endreq;
00106 for(it = inCollVec.begin(); it != inCollVec.end(); ++it){
00107 outCollVec.push_back( convert( *(it->second) ) );
00108 }
00109 return new PerSimTrigCommandHeader(outCollVec);
00110 }
00111
00112 PerSimTrigCommandCollection* SimTrigHeaderCnv::convert(const SimTrigCommandCollection& trigCC)
00113 {
00114 PerSimTrigCommandCollection::CommandVectors out_commands;
00115 SimTrigCommandCollection::CommandContainer in_commands = trigCC.commands();
00116 SimTrigCommandCollection::CommandContainer::iterator it;
00117 for(it = in_commands.begin(); it != in_commands.end(); ++it){
00118 out_commands.push_back(convert(**it));
00119 }
00120 short int det = (trigCC.detector()).siteDetPackedData();
00121 return new PerSimTrigCommandCollection(det,out_commands);
00122 }
00123
00124 PerSimTrigCommand* SimTrigHeaderCnv::convert(const DayaBay::SimTrigCommand& trigCom){
00125 const int cc = trigCom.clockCycle();
00126 const int type = trigCom.type();
00127 short int det = (trigCom.detector()).siteDetPackedData();
00128 const int nh = trigCom.nhit();
00129 const int esA = trigCom.esumAdc();
00130 const int esC = trigCom.esumComp();
00131 return new PerSimTrigCommand(cc,type,det,nh,esA,esC);
00132 }
00133
00134 DayaBay::SimTrigCommandHeader* SimTrigHeaderCnv::convert(const PerSimTrigCommandHeader& PerSimTrigCH){
00135
00136 SimTrigCommandHeader *out_header = new SimTrigCommandHeader();
00137
00138 PerSimTrigCommandHeader::PerComVector in_collection = PerSimTrigCH.commandCollections;
00139 PerSimTrigCommandHeader::PerComVector::iterator it;
00140 SimTrigCommandHeader::detCollMap out_collection;
00141
00142 for(it=in_collection.begin();it!=in_collection.end();++it){
00143 SimTrigCommandCollection *out_cc = convert(**it);
00144 out_header->addCollection(out_cc);
00145
00146
00147 }
00148 return out_header;
00149 }
00150
00151 DayaBay::SimTrigCommandCollection* SimTrigHeaderCnv::convert(const PerSimTrigCommandCollection& PerSimTrigCC){
00152 Detector det(PerSimTrigCC.detector);
00153 SimTrigCommandCollection::CommandContainer out_commands;
00154 PerSimTrigCommandCollection::CommandVectors in_commands = PerSimTrigCC.commands;
00155 PerSimTrigCommandCollection::CommandVectors::iterator it;
00156
00157 for(it = in_commands.begin(); it != in_commands.end(); ++it)
00158 {
00159 out_commands.push_back( convert(**it) );
00160 }
00161
00162 return new SimTrigCommandCollection(det,out_commands);
00163 }
00164
00165 DayaBay::SimTrigCommand* SimTrigHeaderCnv::convert(const PerSimTrigCommand& PerSimTrigCom){
00166 MsgStream log(msgSvc(), "SimTrigHeaderCnv::convet PerSimTrigCommand");
00167 Detector det(PerSimTrigCom.detector);
00168 Trigger::TriggerType_t ttype=(Trigger::TriggerType_t)PerSimTrigCom.type;
00169 SimTrigCommand *out_command = new SimTrigCommand(det,ttype,PerSimTrigCom.clockCycle,PerSimTrigCom.nhit,PerSimTrigCom.esumAdc,PerSimTrigCom.esumComp);
00170 log << MSG::VERBOSE <<"** Created"
00171 << *out_command << endreq;
00172 return out_command;
00173 }