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
DTNewROS8FileReader Class Reference

#include <DTNewROS8FileReader.h>

Inheritance diagram for DTNewROS8FileReader:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

virtual bool checkEndOfFile ()
 
 DTNewROS8FileReader (const edm::ParameterSet &pset)
 Constructor. More...
 
virtual int fillRawData (edm::Event &e, FEDRawDataCollection *&data)
 Generate and fill FED raw data for a full event. More...
 
virtual void produce (edm::Event &, edm::EventSetup const &)
 
virtual ~DTNewROS8FileReader ()
 Destructor. More...
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Attributes

edm::EventNumber_t eventNum
 
RawFile inputFile
 
edm::RunNumber_t runNumber
 

Static Private Attributes

static const int ros8WordLenght = 4
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Read DT ROS8 raw data files From DTROS8FileReader

Date:
2015/12/17

Definition at line 19 of file DTNewROS8FileReader.h.

Constructor & Destructor Documentation

DTNewROS8FileReader::DTNewROS8FileReader ( const edm::ParameterSet pset)

Constructor.

Definition at line 36 of file DTNewROS8FileReader.cc.

References Exception, RawFile::fail(), lut2db_cfg::filename, edm::ParameterSet::getUntrackedParameter(), inputFile, and RawFile::open().

36  :
37  runNumber(1), eventNum(0) {
38 
39  const string & filename = pset.getUntrackedParameter<string>("fileName");
40 
41  inputFile.open(filename.c_str());
42  if( inputFile.fail() ) {
43  throw cms::Exception("InputFileMissing")
44  << "DTNewROS8FileReader: the input file: " << filename <<" is not present";
45  }
46 
47  produces<FEDRawDataCollection>();
48 }
T getUntrackedParameter(std::string const &, T const &) const
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:29
bool fail()
It is not OK.
Definition: RawFile.cc:88
edm::EventNumber_t eventNum
tuple filename
Definition: lut2db_cfg.py:20
edm::RunNumber_t runNumber
DTNewROS8FileReader::~DTNewROS8FileReader ( )
virtual

Destructor.

Definition at line 51 of file DTNewROS8FileReader.cc.

References RawFile::close(), and inputFile.

51  {
52  inputFile.close();
53 }
int close()
Close file if necessary.
Definition: RawFile.cc:66

Member Function Documentation

bool DTNewROS8FileReader::checkEndOfFile ( )
virtual

Definition at line 196 of file DTNewROS8FileReader.cc.

References RawFile::eof(), and inputFile.

Referenced by fillRawData().

196  {
197 
198  bool retval=false;
199  if ( inputFile.eof() ) retval=true;
200  return retval;
201 
202 }
int eof()
Check end of file.
Definition: RawFile.cc:118
int DTNewROS8FileReader::fillRawData ( edm::Event e,
FEDRawDataCollection *&  data 
)
virtual

Generate and fill FED raw data for a full event.

Definition at line 56 of file DTNewROS8FileReader.cc.

References checkEndOfFile(), filterCSVwithJSON::copy, gather_cfg::cout, FEDRawData::data(), AlCaHLTBitMon_QueryRunRegistry::data, TauDecayModes::dec, eventNum, FEDRawDataCollection::FEDData(), i, edm::EventBase::id(), inputFile, FEDNumbering::MINDTFEDID, RawFile::read(), FEDRawData::resize(), ros8WordLenght, and runNumber.

Referenced by produce().

58  {
59  EventID eID = e.id();
60  data = new FEDRawDataCollection();
61 
62  try {
63  /* Structure of the DATA
64 
65  1.- NUMBER OF WORDS (it includes this word and the last counter)
66  2.- HEADER: 8 Words
67  Header word 0: run number
68  Header word 1: spill number
69  Header word 2: event number
70  Header word 3: reserved
71  Header word 4: ROS data offset
72  Header word 5: PU data offset
73  Header word 6: reserved
74  Header word 7: reserved
75  3.- ROS DATA ==> DECODE BY THE DTROS8Unpacker.cc in EventFilter
76  3.1 NUMBER OF ROS WORDS (it includes this counter)
77  3.2 Lock status Word
78  3.3 ROS DATA
79  3.3.1 ROS BOARD ID/ROS CHANNEL - 1 word
80  3.3.2 GLOBAL HEADER - 1 word
81  3.3.3 TDC Data Words - X words (depends on event)
82  3.3.4 GLOBAL TRAILER
83  4.- PU DATA (trigger) ==> DECODE BY THE DTROS8Unpacker.cc in EventFilter
84  Not always. If chamber is autotriggered doesn't have PU data except
85  the Number of PU words
86  4.1.- NUMBER OF WORDS (it includes this word, always present
87  even if there is not PU data)
88  4.2.- PATTERN UNIT ID - 1 word (data counter & PU-ID)
89  4.3.- DATA - X Words ?????
90  5.- NUMBER OF WORDS (include this word and the first counter)
91  */
92 
93 
94  if( checkEndOfFile() ) throw 1;
95 
96  // Number of words in the header, including the first word of header that is the number of words in the event
97  int numberEventHeadWords=8;
98 
99  //1.- Get the total NUMBER OF WORDs from the 1st word in the payload
100  int numberOfWords=0;
101  int nread = 0;
102  nread = inputFile.read(dataPointer<int>( &numberOfWords ), ros8WordLenght); // ros8WordLength=4
103  if ( nread<=0 ) throw 1;
104 
105  // inputFile.ignore(4*(numberEventHeadWords-1)); // Skip the header. The first word of header has been already read
106 
107  //2.- Get the HEADER ============================================================================
108  int datahead[numberEventHeadWords];
109  for(int iih=0;iih<numberEventHeadWords;iih++)
110  {
111  nread = inputFile.read(dataPointer<int>( &datahead[iih] ), ros8WordLenght);
112  }
113 
114  //3.- ROS DATA & 4.- PU DATA (Trigger) =======================================================
115  // Get the event data (all words but the header and the first and the last counter)
116  int numberOfDataWords=numberOfWords-numberEventHeadWords-2;
117  int* eventData = new int[numberOfDataWords];
118  nread = inputFile.read(dataPointer<int>( eventData ), numberOfDataWords * ros8WordLenght );
119  if ( nread<=0 ) throw 1;
120 
121  //5.- Get the total NUMBER OF WORDs from the last word in the payload
122  // Check that the event data size corresponds to the 1st word datum
123  int LastCounter=0;
124  nread=inputFile.read(dataPointer<int>( &LastCounter ), ros8WordLenght);
125  if ( nread<=0 ) throw 1;
126 
127  if ( LastCounter != numberOfWords ) {
128  cout << "[DTNewROS8FileReader]: word counter mismatch exception: "
129  << numberOfWords << " " << LastCounter << endl;
130  throw 99;
131  }
132 
133  //The first word in the header is the run number
134  runNumber= datahead[0];
135  cout << "[DTNewROS8FileReader]: Run Number: "<<dec<<runNumber<<endl;
136 
137  //The third word in the header is the event number (without any reset)
138  //eventNum= datahead[2]; //francos system
139  eventNum= datahead[1]; //linux system
140  //cout<<"ëventNum "<<dec<<eventNum<<endl;
141  if(eventNum<1)eventNum=1;// Event number must start at 1 but at TDCs it starts at cero,if not the program crashes
142  // files used for testing start in 1, but... just in case...
143 
144  eID = EventID(runNumber, 1U, eventNum);
145 
146  //cout << " EEEEE eID: " << eID << endl;
147  // Even if we have introducing the correct runNumber when running the runNumber appears always as =1
148 
149  int eventDataSize = numberOfDataWords * ros8WordLenght;
150  int adjustment = (eventDataSize/4)%2 == 1 ? 4 : 0;
151 
152  // The FED ID is always the first in the DT range
153  FEDRawData& fedRawData = data->FEDData( FEDNumbering::MINDTFEDID );
154  fedRawData.resize(eventDataSize+adjustment); // the size must be multiple of 8 bytes
155 
156  // Passing the data to the Event
157  copy(reinterpret_cast<unsigned char*>(eventData),
158  reinterpret_cast<unsigned char*>(eventData) + eventDataSize, fedRawData.data());
159 
160  // needed to get rid of memory leaks (?)
161  delete[] eventData;
162 
163  return true;
164 
165  }
166  catch( int i ) {
167 
168  if ( i == 1 ){
169  cout << "[DTNewROS8FileReader]: END OF FILE REACHED. "
170  << "No information read for the requested event" << endl;
171  delete data; data=0;
172  return false;
173  }
174  else {
175  cout << "[DTNewROS8FileReader]: PROBLEM WITH EVENT INFORMATION ON THE FILE. "
176  << "EVENT DATA READING FAILED code= " << i << endl;
177  delete data; data=0;
178  return false;
179  }
180 
181  }
182 
183 }
int i
Definition: DBlmapReader.cc:9
edm::EventNumber_t eventNum
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:94
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void resize(size_t newsize)
Definition: FEDRawData.cc:32
static const int ros8WordLenght
virtual bool checkEndOfFile()
edm::EventID id() const
Definition: EventBase.h:59
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
tuple cout
Definition: gather_cfg.py:145
edm::RunNumber_t runNumber
void DTNewROS8FileReader::produce ( edm::Event e,
edm::EventSetup const &  es 
)
virtual

Implements edm::EDProducer.

Definition at line 186 of file DTNewROS8FileReader.cc.

References fillRawData(), edm::Event::put(), and lumiPlot::rawdata.

186  {
187 
189  FEDRawDataCollection *fedcoll = 0;
190  fillRawData(e,fedcoll);
191  std::auto_ptr<FEDRawDataCollection> bare_product(fedcoll);
192  e.put(bare_product);
193 }
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
dictionary rawdata
Definition: lumiPlot.py:393
virtual int fillRawData(edm::Event &e, FEDRawDataCollection *&data)
Generate and fill FED raw data for a full event.

Member Data Documentation

edm::EventNumber_t DTNewROS8FileReader::eventNum
private

Definition at line 41 of file DTNewROS8FileReader.h.

Referenced by fillRawData().

RawFile DTNewROS8FileReader::inputFile
private
const int DTNewROS8FileReader::ros8WordLenght = 4
staticprivate

Definition at line 43 of file DTNewROS8FileReader.h.

Referenced by fillRawData().

edm::RunNumber_t DTNewROS8FileReader::runNumber
private

Definition at line 40 of file DTNewROS8FileReader.h.

Referenced by fillRawData().