Skip to content

Commit

Permalink
Merge pull request #12985 from jfernan2/added-DaqSource-emulator
Browse files Browse the repository at this point in the history
Added DaqSource emulator using DaqFakeReader
  • Loading branch information
davidlange6 committed Mar 22, 2016
2 parents 23c6506 + d10a155 commit 55097c5
Show file tree
Hide file tree
Showing 24 changed files with 2,207 additions and 0 deletions.
9 changes: 9 additions & 0 deletions IORawData/DTCommissioning/BuildFile.xml
@@ -0,0 +1,9 @@
<use name="FWCore/Framework"/>
<use name="FWCore/ParameterSet"/>
<use name="DataFormats/FEDRawData"/>
<use name="DataFormats/Provenance"/>
<use name="castor"/>
<flags EDM_PLUGIN="1"/>
<use name="xrootd"/>
<flags cppflags="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"/>
<lib name="XrdPosixPreload"/>
36 changes: 36 additions & 0 deletions IORawData/DTCommissioning/doc/DTCommissioning.doc
@@ -0,0 +1,36 @@
/*!
<!-- Substitute IORawData and DTCommissioning with the proper names! -->

\page IORawData_DTCommissioning Package IORawData/DTCommissioning
<center>
<small>
<a href=http://cmsdoc.cern.ch/swdev/viewcvs/viewcvs.cgi/CMSSW/IORawData/DTCommissioning/?cvsroot=CMSSW&only_with_tag=@CVS_TAG@>Source code (CVS tag: @CVS_TAG@)</a> -
<a href=http://cmsdoc.cern.ch/swdev/viewcvs/viewcvs.cgi/CMSSW/IORawData/DTCommissioning/.admin/developers?rev=HEAD&cvsroot=CMSSW&content-type=text/vnd.viewcvs-markup>Administrative privileges</a>
</small>
</center>


\section desc Description
<!-- Short description of what this package is supposed to provide -->
Special input source to read raw data files of DT commissioning, sector test and DT testbeam, and put them to the event.

\subsection interface Public interface
<!-- List the classes that are provided for use in other packages (if any) -->
None.

\subsection modules Modules
<!-- Describe modules implemented in this package and their parameter set -->
<!--FIXME: add explanation>

\subsection tests Unit tests and examples
<!-- Describe cppunit tests and example configuration files -->
- readFile.cfg : example cards to create a digi files reading the raw data from a raw file
- checkPool.cfg: example cards to read back the digi file created with readFile.cfg.

\section status Status and planned development
<!-- e.g. completed, stable, missing features -->
Completed, stable.

<hr>
Last updated: @DATE@ Author: Nicola Amapane
*/
11 changes: 11 additions & 0 deletions IORawData/DTCommissioning/doc/html/index.html
@@ -0,0 +1,11 @@
<! Template File - Modify as required.>
<! Use as an index to other html documents>
<! References to local pages should be relative to this directory>
<! This makes it easy for both users of the web project space and>
<! any others who might simply look at html files directly in the source code.>
<! e.g. href=page1.html or href=mysubdir/page2.html >
<html>
<body>
This Text Inserted from File doc/html/index.html
</body>
</html>
12 changes: 12 additions & 0 deletions IORawData/DTCommissioning/doc/html/overview.html
@@ -0,0 +1,12 @@
<! Template File - Modify as required.>
<! Use as a brief project description that appears on your main page>
<! Links are not encouraged from this section - use index.html for this>
This Text Inserted from File doc/html/overview.html
<table border=0 width=100%>
<tr>
<td align=center><b>Status :</b></td>
<td align=center>
Unknown
</td>
</tr>
</table>
12 changes: 12 additions & 0 deletions IORawData/DTCommissioning/plugins/BuildFile.xml
@@ -0,0 +1,12 @@
<library file="*.cc" name="IORawDataDTCommissioningPlugins">
<use name="FWCore/Framework"/>
<use name="FWCore/ParameterSet"/>
<use name="DataFormats/FEDRawData"/>
<use name="DataFormats/Provenance"/>
<use name="IORawData/DTCommissioning"/>
<use name="castor"/>
<flags EDM_PLUGIN="1"/>
<use name="xrootd"/>
<flags cppflags="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"/>
<lib name="XrdPosixPreload"/>
</library>
255 changes: 255 additions & 0 deletions IORawData/DTCommissioning/plugins/DTDDUFileReader.cc
@@ -0,0 +1,255 @@
/** \file
*
* $Date: 2010/03/12 10:04:19 $
* $Revision: 1.22 $
* \author M. Zanetti
*/


#include <IORawData/DTCommissioning/plugins/DTDDUFileReader.h>
#include <IORawData/DTCommissioning/plugins/DTFileReaderHelpers.h>

#include <DataFormats/FEDRawData/interface/FEDHeader.h>
#include <DataFormats/FEDRawData/interface/FEDTrailer.h>
#include <DataFormats/FEDRawData/interface/FEDNumbering.h>

#include "DataFormats/Provenance/interface/EventID.h"
#include <DataFormats/Provenance/interface/Timestamp.h>
#include <DataFormats/FEDRawData/interface/FEDRawData.h>
#include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h>

#include <FWCore/ParameterSet/interface/ParameterSet.h>
#include <FWCore/Utilities/interface/Exception.h>

#include <string>
#include <iosfwd>
#include <iostream>
#include <algorithm>

using namespace std;
using namespace edm;


DTDDUFileReader::DTDDUFileReader(const edm::ParameterSet& pset) :
runNumber(1), eventNumber(1) {

const string & filename = pset.getUntrackedParameter<string>("fileName");

readFromDMA = pset.getUntrackedParameter<bool>("readFromDMA",true);
numberOfHeaderWords = pset.getUntrackedParameter<int>("numberOfHeaderWords",10);
skipEvents = pset.getUntrackedParameter<int>("skipEvents",0);

inputFile.open(filename.c_str());
if( inputFile.fail() ) {
throw cms::Exception("InputFileMissing")
<< "[DTDDUFileReader]: the input file: " << filename <<" is not present";
} else {
cout << "DTDDUFileReader: DaqSource file '" << filename << "' was succesfully opened" << endl;
}

uint32_t runNumber_tmp=1;
inputFile.read(dataPointer<uint32_t>( &runNumber_tmp ), 4);
runNumber = runNumber_tmp;

inputFile.ignore(4*(numberOfHeaderWords-1));

if (skipEvents) {
cout<<""<<endl;
cout<<" Dear user, please be patient, "<<skipEvents<<" are being skipped .."<<endl;
cout<<""<<endl;
}

produces<FEDRawDataCollection>();
}


DTDDUFileReader::~DTDDUFileReader(){
inputFile.close();
}

int DTDDUFileReader::fillRawData(Event& e,
// Timestamp& tstamp,
FEDRawDataCollection*& data){
EventID eID = e.id();
data = new FEDRawDataCollection();

vector<uint64_t> eventData;
size_t estimatedEventDimension = 102400; // dimensione hardcoded
eventData.reserve(estimatedEventDimension);
uint64_t word = 0;

bool haederTag = false;
bool dataTag = true;
bool headerAlreadyFound = false;

int wordCount = 0;

// getting the data word by word from the file
// do it until you get the DDU trailer
while ( !isTrailer(word, dataTag, wordCount) ) {
//while ( !isTrailer(word) ) {

if (readFromDMA) {
int nread;
word = dmaUnpack(dataTag,nread);
if ( nread<=0 ) {
cout<<"[DTDDUFileReader]: ERROR! no more words and failed to get the trailer"<<endl;
delete data; data=0;
return false;
}
}

else {
int nread = inputFile.read(dataPointer<uint64_t>( &word ), dduWordLength);
dataTag = false;
if ( nread<=0 ) {
cout<<"[DTDDUFileReader]: ERROR! failed to get the trailer"<<endl;
delete data; data=0;
return false;
}
}

// get the DDU header
if (!headerAlreadyFound)
if ( isHeader(word,dataTag)) {
headerAlreadyFound=true;
haederTag=true;
}

// from now on fill the eventData with the ROS data
if (haederTag) {

if (readFromDMA) {
// swapping only the 8 byte words
if (dataTag) {
swap(word);
} // WARNING also the ddu status words have been swapped!
// Control the correct interpretation in DDUUnpacker
}

eventData.push_back(word);
wordCount++;
}

}

// FEDTrailer candidate(reinterpret_cast<const unsigned char*>(&word));
// cout<<"EventSize: pushed back "<<eventData.size()
// <<"; From trailer "<<candidate.lenght()<<endl;

// next event reading will start with meaningless trailer+header from DTLocalDAQ
// those will be skipped automatically when seeking for the DDU header
//if (eventData.size() > estimatedEventDimension) throw 2;

// Eventually skipping events
if ((int)eventNumber >= skipEvents) {

// Setting the Event ID
eID = EventID( runNumber, 1U, eventNumber);

// eventDataSize = (Number Of Words)* (Word Size)
int eventDataSize = eventData.size()*dduWordLength;


if ( dduID<770 || dduID > 775 ) {
cout<<"[DTDDUFileReader]: ERROR. DDU ID out of range. DDU id="<<dduID<<endl;
// The FED ID is always the first in the DT range
dduID = FEDNumbering::MINDTFEDID;
}
FEDRawData& fedRawData = data->FEDData( dduID );
fedRawData.resize(eventDataSize);

copy(reinterpret_cast<unsigned char*>(&eventData[0]),
reinterpret_cast<unsigned char*>(&eventData[0]) + eventDataSize, fedRawData.data());

}

return true;

}

void DTDDUFileReader::produce(Event&e, EventSetup const&es){
edm::Handle<FEDRawDataCollection> rawdata;
FEDRawDataCollection *fedcoll = 0;
fillRawData(e,fedcoll);
std::auto_ptr<FEDRawDataCollection> bare_product(fedcoll);
e.put(bare_product);
}

void DTDDUFileReader::swap(uint64_t & word) {

twoNibble64* newWorld = reinterpret_cast<twoNibble64*>(&word);

uint32_t msBits_tmp = newWorld->msBits;
newWorld->msBits = newWorld->lsBits;
newWorld->lsBits = msBits_tmp;
}


uint64_t DTDDUFileReader::dmaUnpack(bool & isData, int & nread) {

uint64_t dduWord = 0;

uint32_t td[4];
// read 4 32-bits word from the file;
nread = inputFile.read(dataPointer<uint32_t>( &td[0] ), 4);
nread += inputFile.read(dataPointer<uint32_t>( &td[1] ), 4);
nread += inputFile.read(dataPointer<uint32_t>( &td[2] ), 4);
nread += inputFile.read(dataPointer<uint32_t>( &td[3] ), 4);

uint32_t data[2] = {0, 0};
// adjust 4 32-bits words into 2 32-bits words
data[0] |= td[3] & 0x3ffff;
data[0] |= (td[2] << 18 ) & 0xfffc0000;
data[1] |= (td[2] >> 14 ) & 0x0f;
data[1] |= (td[1] << 4 ) & 0x3ffff0;
data[1] |= (td[0] << 22 ) & 0xffc00000;

isData = ( td[0] >> 10 ) & 0x01;

// push_back to a 64 word
dduWord = (uint64_t(data[1]) << 32) | data[0];

return dduWord;
}

bool DTDDUFileReader::isHeader(uint64_t word, bool dataTag) {

bool it_is = false;
FEDHeader candidate(reinterpret_cast<const unsigned char*>(&word));
if ( candidate.check() ) {
// if ( candidate.check() && !dataTag) {
it_is = true;
dduID = candidate.sourceID();
eventNumber++;
}

return it_is;
}


bool DTDDUFileReader::isTrailer(uint64_t word, bool dataTag, int wordCount) {

bool it_is = false;
FEDTrailer candidate(reinterpret_cast<const unsigned char*>(&word));
if ( candidate.check() ) {
// if ( candidate.check() && !dataTag) {
//cout<<"[DTDDUFileReader] "<<wordCount<<" - "<<candidate.lenght()<<endl;
if ( wordCount == candidate.lenght())
it_is = true;
}

return it_is;
}


bool DTDDUFileReader::checkEndOfFile(){

bool retval=false;
if ( inputFile.eof() ) retval=true;
return retval;

}



0 comments on commit 55097c5

Please sign in to comment.