00001 #include "GaudiKernel/Bootstrap.h"
00002 #include "GaudiKernel/ISvcLocator.h"
00003 #include "GaudiKernel/IJobOptionsSvc.h"
00004 #include "RawDataCnv/EventManagement/Builder.h"
00005
00006 string Builder::m_confFile;
00007
00008 Builder::Builder()
00009 {
00010
00011
00012 m_buf = new uint32_t[32768];
00013
00014 if (!m_confFile.empty()) return;
00015 m_propMgr.declareProperty("RawDataCnvConfFile", m_confFile);
00016 m_propMgr.declareProperty("Status", m_status=0xFFFFFFFF);
00017
00018
00019 IJobOptionsSvc* jobSvc;
00020 Gaudi::svcLocator()->service("JobOptionsSvc", jobSvc);
00021 jobSvc->setMyProperties("Builder", &m_propMgr);
00022 }
00023
00024 Builder::~Builder() {
00025 delete m_buf;
00026 }
00027
00028 bool Builder::expect( ifstream &f, string msg, string fname )
00029 {
00030 string str;
00031 if( f.bad() )
00032 {
00033 cerr << "Error: file " << fname << " is bad" << endl;
00034 return false;
00035 }
00036 f >> str;
00037 if( str == msg )
00038 return true;
00039
00040 cerr << "Error: expected `" << msg << "|" << str <<"` in " << fname << endl;
00041 return false;
00042 }
00043
00044 bool Builder::expectInt( ifstream &f, string msg, string fname, uint32_t &val1, uint32_t &val2 )
00045 {
00046 if( !expect( f, msg, fname ) || f.bad() )
00047 return false;
00048 f >> val1 >> val2;
00049 return true;
00050 }
00051
00052 bool Builder::expectLong(ifstream &f, string msg, string fname, uint64_t &val)
00053 {
00054 if ( !expect(f, msg, fname) || f.bad() )
00055 return false;
00056 f >> val;
00057 return true;
00058 }
00059
00060 bool Builder::find( ifstream &f, string msg, string fname )
00061 {
00062 if ( f.bad() ) {
00063 cerr << "Error: file " << fname << " bad checked" << endl;
00064 return false;
00065 }
00066
00067 string str;
00068 while ( !f.eof() ) {
00069 f >> str;
00070 if ( str == msg ) return true;
00071 }
00072
00073 return false;
00074 }
00075
00076 void Builder::append2event(WriteRawEvent*& re, uint32_t source_id, uint32_t size)
00077 {
00078 uint32_t run_no = re->run_no();
00079 uint32_t lvl1_id = re->lvl1_id();
00080 uint32_t bc_id = 0;
00081
00082 eformat::write::ROBFragment* nrob = new eformat::write::ROBFragment(
00083 source_id,
00084 run_no,
00085 lvl1_id,
00086 bc_id,
00087 0,
00088 0,
00089 size,
00090 m_buf,
00091 0
00092 );
00093 if(m_status==0xFFFFFFFF){
00094 nrob->status(0, NULL);
00095 nrob->rod_status(0, NULL);
00096 }
00097 else{
00098 nrob->status(1, &m_status);
00099 nrob->rod_status(1, &m_status);
00100 }
00101
00102 eformat::write::ROSFragment* nros = new eformat::write::ROSFragment(
00103 source_id,
00104 run_no,
00105 lvl1_id,
00106 bc_id
00107 );
00108 if(m_status==0xFFFFFFFF) nros->status(0, NULL);
00109 else nros->status(1, &m_status);
00110
00111 eformat::write::SubDetectorFragment* nsd = new eformat::write::SubDetectorFragment(source_id);
00112 if(m_status==0xFFFFFFFF) nsd->status(0, NULL);
00113 else nsd->status(1, &m_status);
00114
00115 nros->append(nrob);
00116 nsd->append(nros);
00117 re->append(nsd);
00118 }