00001 #include <IORawData/CSCTFCommissioning/src/CSCTFFileReader.h> 00002 #include <errno.h> 00003 #include <string> 00004 00005 #include <DataFormats/FEDRawData/interface/FEDHeader.h> 00006 #include <DataFormats/FEDRawData/interface/FEDTrailer.h> 00007 #include <DataFormats/FEDRawData/interface/FEDNumbering.h> 00008 00009 #include <DataFormats/Provenance/interface/EventID.h> 00010 #include <DataFormats/Provenance/interface/Timestamp.h> 00011 #include <DataFormats/FEDRawData/interface/FEDRawData.h> 00012 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h> 00013 00014 #include <FWCore/ParameterSet/interface/ParameterSet.h> 00015 #include <IORawData/CSCTFCommissioning/src/FileReaderSP.h> 00016 #include <IORawData/CSCTFCommissioning/src/FileReaderSPNewFormat.h> 00017 00018 #include <string> 00019 #include <iosfwd> 00020 #include <iostream> 00021 #include <algorithm> 00022 00023 using namespace std; 00024 using namespace edm; 00025 00026 //FileReaderSP ___ddu; 00027 00028 CSCTFFileReader::CSCTFFileReader(const edm::ParameterSet& pset):DaqBaseReader() 00029 { 00030 // Following code is stolen from IORawData/DTCommissioning 00031 const std::string dataformat = pset.getUntrackedParameter<std::string>("dataFormat","TestBeam"); 00032 00033 if(dataformat == "TestBeam") 00034 { 00035 ___ddu = new FileReaderSP(); 00036 } 00037 if(dataformat == "Final") 00038 { 00039 ___ddu = new FileReaderSPNewFormat(); 00040 } 00041 00042 const std::string & filename = pset.getParameter<std::string>("fileName"); 00043 std::cout << "Opening File: " << filename << std::endl; 00044 ___ddu->openFile(filename.c_str()); 00045 } 00046 00047 CSCTFFileReader::~CSCTFFileReader() 00048 { 00049 delete ___ddu; 00050 } 00051 00052 bool CSCTFFileReader::fillRawData(edm::EventID& eID, edm::Timestamp& tstamp, FEDRawDataCollection*& data){ 00053 data = new FEDRawDataCollection(); 00054 00055 // Event buffer and its length 00056 size_t length=0; 00057 00058 // Read DDU record 00059 ___ddu->readNextEvent(); 00060 const unsigned short* dduBuf = reinterpret_cast<unsigned short*>(___ddu->data()); 00061 length = ___ddu->dataLength(); 00062 00063 if(!length) { 00064 delete data; data=0; 00065 return false; 00066 } 00067 00068 int runNumber = 0; // Unknown at the level of EMu local DAQ 00069 int eventNumber =((dduBuf[2])&0x0FFF) | ((dduBuf[3]&0x0FFF)<<12); // L1A Number 00070 eID = EventID(runNumber,eventNumber); 00071 00072 00073 unsigned short dccBuf[200000+4*4];//, *dccHeader=dccBuf, *dccTrailer=dccBuf+4*2+(length/2); 00074 memcpy(dccBuf,dduBuf,length); 00075 00076 // The FED ID 00077 FEDRawData& fedRawData = data->FEDData( FEDNumbering::getCSCFEDIds().first ); 00078 int newlength = 0; 00079 if(length%8) 00080 { 00081 newlength = length + (8-(length%8)); 00082 } 00083 else newlength = length; 00084 fedRawData.resize(newlength); 00085 00086 copy(reinterpret_cast<unsigned char*>(dccBuf), 00087 reinterpret_cast<unsigned char*>(dccBuf)+length, fedRawData.data()); 00088 00089 return true; 00090 } 00091