CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes | Static Private Attributes
DTSpyReader Class Reference

#include <DTSpyReader.h>

Inheritance diagram for DTSpyReader:
DaqBaseReader

Public Member Functions

uint64_t dmaUnpack (const uint32_t *dmaData, bool &isData)
 pre-unpack the data if read via DMA More...
 
 DTSpyReader (const edm::ParameterSet &pset)
 Constructor. More...
 
virtual int fillRawData (edm::EventID &eID, edm::Timestamp &tstamp, FEDRawDataCollection *&data)
 Generate and fill FED raw data for a full event. More...
 
bool isHeader (uint64_t word, bool dataTag)
 check for a 64 bits word to be a DDU header More...
 
bool isTrailer (uint64_t word, bool dataTag, int wordCount)
 check for a 64 bits word to be a DDU trailer More...
 
void swap (uint64_t &word)
 swapping the lsBits with the msBits More...
 
virtual ~DTSpyReader ()
 Destructor. More...
 
- Public Member Functions inherited from DaqBaseReader
 DaqBaseReader ()
 
virtual void setRunNumber (edm::RunNumber_t runNumber)
 set the run number More...
 
virtual ~DaqBaseReader ()
 

Private Attributes

int dduID
 
bool debug
 
edm::EventNumber_t eventNumber
 
DTSpymySpy
 
edm::RunNumber_t runNumber
 

Static Private Attributes

static const int dduWordLength = 8
 

Detailed Description

Read DT ROS8 raw data files

Date:
2010/02/03 16:58:24
Revision:
1.4
Author
M. Zanetti - INFN Padova

Definition at line 23 of file DTSpyReader.h.

Constructor & Destructor Documentation

DTSpyReader::DTSpyReader ( const edm::ParameterSet pset)

Constructor.

connecting to XDAQ note ("0.0.0.0" = localhost)

Definition at line 33 of file DTSpyReader.cc.

References DTCtcp::Connect(), gather_cfg::cout, dduID, debug, edm::ParameterSet::getUntrackedParameter(), and mySpy.

33  :
34  runNumber(1), eventNumber(0) {
35 
36  // instatiating Sandro's spy (My name is Bond, Sandro Bond)
37  mySpy = new DTSpy();
38 
40  string connectionParameters = pset.getUntrackedParameter<string>("connectionParameters");
41  mySpy->Connect(connectionParameters.c_str(),10000);
42 
43  cout<<endl;
44  cout<<"DT Local DAQ online spy. Connected to IP "<<connectionParameters.c_str()
45  <<". Waiting for the data to be flushed"<<endl;
46  cout<<endl;
47 
48  debug = pset.getUntrackedParameter<bool>("debug",false);
49  dduID = pset.getUntrackedParameter<int32_t>("dduID",770); // NOT needed
50 }
T getUntrackedParameter(std::string const &, T const &) const
void Connect(const char *hostaddr, int port)
Definition: DTSpyHelper.cc:162
edm::EventNumber_t eventNumber
Definition: DTSpyReader.h:56
Definition: DTSpy.h:17
DTSpy * mySpy
Definition: DTSpyReader.h:53
edm::RunNumber_t runNumber
Definition: DTSpyReader.h:55
tuple cout
Definition: gather_cfg.py:121
DTSpyReader::~DTSpyReader ( )
virtual

Destructor.

Definition at line 53 of file DTSpyReader.cc.

References mySpy.

53  {
54  delete mySpy;
55 }
DTSpy * mySpy
Definition: DTSpyReader.h:53

Member Function Documentation

uint64_t DTSpyReader::dmaUnpack ( const uint32_t *  dmaData,
bool &  isData 
)

pre-unpack the data if read via DMA

Definition at line 141 of file DTSpyReader.cc.

Referenced by fillRawData().

141  {
142 
143  uint32_t unpackedData[2] = {0, 0};
144  // adjust 4 32-bits words into 2 32-bits words
145  unpackedData[0] |= dmaData[3] & 0x3ffff;
146  unpackedData[0] |= (dmaData[2] << 18 ) & 0xfffc0000;
147  unpackedData[1] |= (dmaData[2] >> 14 ) & 0x0f;
148  unpackedData[1] |= (dmaData[1] << 4 ) & 0x3ffff0;
149  unpackedData[1] |= (dmaData[0] << 22 ) & 0xffc00000;
150 
151  isData = ( dmaData[0] >> 10 ) & 0x01;
152 
153  //printf ("Lower part: %x \n", unpackedData[0]);
154  //printf ("Upper part: %x \n", unpackedData[1]);
155 
156  // push_back to a 64 word
157  uint64_t dduWord = ( uint64_t(unpackedData[1]) << 32 ) | unpackedData[0];
158 
159  return dduWord;
160 }
unsigned long long uint64_t
Definition: Time.h:15
int DTSpyReader::fillRawData ( edm::EventID eID,
edm::Timestamp tstamp,
FEDRawDataCollection *&  data 
)
virtual

Generate and fill FED raw data for a full event.

Implements DaqBaseReader.

Definition at line 58 of file DTSpyReader.cc.

References filterCSVwithJSON::copy, gather_cfg::cout, FEDRawData::data(), dduID, dduWordLength, debug, dmaUnpack(), eventNumber, FEDRawDataCollection::FEDData(), DTSpy::getEventPointer(), DTSpy::getNextBuffer(), DTSpy::getRunNo(), isHeader(), isTrailer(), mySpy, FEDRawData::resize(), runNumber, DTSpy::setlastPointer(), and swap().

58  {
59 
60  // ask for a new buffer
62 
63  // get the pointer to the beginning of the buffer
64  const char * rawDTData = mySpy->getEventPointer();
65 
66  const uint32_t * rawDTData32 = reinterpret_cast<const uint32_t*>(rawDTData);
67 
68  // instantiate the FEDRawDataCollection
69  data = new FEDRawDataCollection();
70 
71  vector<uint64_t> eventData; uint64_t word = 0;
72  int wordCount = 0; int wordCountCheck = 0;
73 
74  bool headerTag = false; bool dataTag = true;
75 
76  // Advance at long-word steps until the trailer is reached.
77  // Skipped whatever else is in the buffer (e.g. another event..)
78  while ( !isTrailer(word, dataTag, wordCount) ) {
79 
80  // dma gets 4 32-bits words and create a 64 bit one
81  word = dmaUnpack(rawDTData32, dataTag);
82 
83  // look for the DDU header
84  if (isHeader(word,dataTag)) headerTag=true;
85 
86  // check whether the first word is a DDU header
87  if ( wordCountCheck > 0 && !headerTag && debug)
88  cout<<"[DTSpyReader]: WARNING: header still not found!!"<<endl;
89 
90  // from now on fill the eventData with the ROS data
91  if (headerTag) {
92 
93  // swapping only the 32 bits words
94  if (dataTag) swap(word);
95  // WARNING also the ddu status words have been swapped!
96  // Control the correct interpretation in DDUUnpacker
97 
98  eventData.push_back(word);
99  wordCount++;
100  }
101 
102  // advancing by 4 32-bits words
103  rawDTData32 += 4;
104 
105  // counting the total number of group of 128 bits (=4*32) in the buffer
106  wordCountCheck++;
107  }
108 
109  // Setting the Event ID
110  runNumber = mySpy->getRunNo();
111  eID = EventID( runNumber, 1U, eventNumber);
112 
113  // eventDataSize = (Number Of Words)* (Word Size)
114  int eventDataSize = eventData.size()*dduWordLength;
115 
116  if (debug) cout<<" DDU ID = "<<dduID<<endl;
117 
118  FEDRawData& fedRawData = data->FEDData( dduID );
119  fedRawData.resize(eventDataSize);
120 
121  copy(reinterpret_cast<unsigned char*>(&eventData[0]),
122  reinterpret_cast<unsigned char*>(&eventData[0]) + eventDataSize, fedRawData.data());
123 
124 
125  mySpy->setlastPointer( (char*) rawDTData32 );
126 
127  return true;
128 
129 }
static const int dduWordLength
Definition: DTSpyReader.h:61
edm::EventNumber_t eventNumber
Definition: DTSpyReader.h:56
const char * getEventPointer()
Definition: DTSpy.cc:83
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void resize(size_t newsize)
Definition: FEDRawData.cc:33
void swap(uint64_t &word)
swapping the lsBits with the msBits
Definition: DTSpyReader.cc:131
bool isTrailer(uint64_t word, bool dataTag, int wordCount)
check for a 64 bits word to be a DDU trailer
Definition: DTSpyReader.cc:176
unsigned long long uint64_t
Definition: Time.h:15
void setlastPointer(char *data)
Definition: DTSpy.cc:92
int getNextBuffer()
Definition: DTSpy.cc:39
DTSpy * mySpy
Definition: DTSpyReader.h:53
edm::RunNumber_t runNumber
Definition: DTSpyReader.h:55
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
bool isHeader(uint64_t word, bool dataTag)
check for a 64 bits word to be a DDU header
Definition: DTSpyReader.cc:162
tuple cout
Definition: gather_cfg.py:121
uint64_t dmaUnpack(const uint32_t *dmaData, bool &isData)
pre-unpack the data if read via DMA
Definition: DTSpyReader.cc:141
int getRunNo()
Definition: DTSpy.cc:76
bool DTSpyReader::isHeader ( uint64_t  word,
bool  dataTag 
)

check for a 64 bits word to be a DDU header

Definition at line 162 of file DTSpyReader.cc.

References FEDHeader::check(), dduID, eventNumber, and FEDHeader::sourceID().

Referenced by fillRawData().

162  {
163 
164  bool it_is = false;
165  FEDHeader candidate(reinterpret_cast<const unsigned char*>(&word));
166  if ( candidate.check() ) {
167  // if ( candidate.check() && !dataTag) {
168  it_is = true;
169  dduID = candidate.sourceID();
170  eventNumber++;
171  }
172  return it_is;
173 }
edm::EventNumber_t eventNumber
Definition: DTSpyReader.h:56
bool DTSpyReader::isTrailer ( uint64_t  word,
bool  dataTag,
int  wordCount 
)

check for a 64 bits word to be a DDU trailer

Definition at line 176 of file DTSpyReader.cc.

References FEDTrailer::check(), and FEDTrailer::lenght().

Referenced by fillRawData().

176  {
177 
178  bool it_is = false;
179  FEDTrailer candidate(reinterpret_cast<const unsigned char*>(&word));
180  if ( candidate.check() ) {
181  // if ( candidate.check() && !dataTag) {
182  if ( wordCount == candidate.lenght())
183  it_is = true;
184  }
185  return it_is;
186 }
void DTSpyReader::swap ( uint64_t &  word)

swapping the lsBits with the msBits

Definition at line 131 of file DTSpyReader.cc.

References twoNibble64::lsBits, and twoNibble64::msBits.

Referenced by fillRawData().

131  {
132 
133  twoNibble64* newWorld = reinterpret_cast<twoNibble64*>(&word);
134 
135  uint32_t msBits_tmp = newWorld->msBits;
136  newWorld->msBits = newWorld->lsBits;
137  newWorld->lsBits = msBits_tmp;
138 }

Member Data Documentation

int DTSpyReader::dduID
private

Definition at line 59 of file DTSpyReader.h.

Referenced by DTSpyReader(), fillRawData(), and isHeader().

const int DTSpyReader::dduWordLength = 8
staticprivate

Definition at line 61 of file DTSpyReader.h.

Referenced by fillRawData().

bool DTSpyReader::debug
private

Definition at line 58 of file DTSpyReader.h.

Referenced by DTSpyReader(), and fillRawData().

edm::EventNumber_t DTSpyReader::eventNumber
private
DTSpy* DTSpyReader::mySpy
private

Definition at line 53 of file DTSpyReader.h.

Referenced by DTSpyReader(), fillRawData(), and ~DTSpyReader().

edm::RunNumber_t DTSpyReader::runNumber
private

Definition at line 55 of file DTSpyReader.h.

Referenced by fillRawData().