CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Phase2TrackerDigiProducer.cc
Go to the documentation of this file.
16 #include <iostream>
17 #include <sstream>
18 #include <iomanip>
19 #include <ext/algorithm>
20 
21 using namespace std;
22 
23 namespace Phase2Tracker {
24 
26  runNumber_(0),
27  cabling_(0),
28  cacheId_(0)
29  {
30  // define product
31  produces< edm::DetSetVector<Phase2TrackerDigi> >("ProcessedRaw");
32  token_ = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("ProductLabel"));
33  }
34 
36  {
37  }
38 
40  {
41  }
42 
44  {
45  // fetch cabling from event setup
47  es.get<Phase2TrackerCablingRcd>().get( c );
48  cabling_ = c.product();
49  }
50 
52  {
53  }
54 
56  {
57  // empty vectors for the next event
58  proc_work_registry_.clear();
59  proc_work_digis_.clear();
60 
61  // Retrieve FEDRawData collection
63  event.getByToken( token_, buffers );
64 
65  // Analyze strip tracker FED buffers in data
66  size_t fedIndex;
67  for( fedIndex = Phase2Tracker::FED_ID_MIN; fedIndex < Phase2Tracker::CMS_FED_ID_MAX; ++fedIndex )
68  {
69  const FEDRawData& fed = buffers->FEDData(fedIndex);
70  if(fed.size()!=0)
71  {
72  // construct buffer
74  buffer = new Phase2Tracker::Phase2TrackerFEDBuffer(fed.data(),fed.size());
75 
76  #ifdef EDM_ML_DEBUG
77  std::ostringstream ss;
78  ss << " -------------------------------------------- " << endl;
79  ss << " buffer debug ------------------------------- " << endl;
80  ss << " -------------------------------------------- " << endl;
81  ss << " buffer size : " << buffer->bufferSize() << endl;
82  ss << " fed id : " << fedIndex << endl;
83  ss << " -------------------------------------------- " << endl;
84  ss << " tracker header debug ------------------------" << endl;
85  ss << " -------------------------------------------- " << endl;
86  LogTrace("Phase2TrackerDigiProducer") << ss.str(); ss.clear(); ss.str("");
87 
88  Phase2TrackerFEDHeader tr_header = buffer->trackerHeader();
89  ss << " Version : " << hex << setw(2) << (int) tr_header.getDataFormatVersion() << endl;
90  ss << " Mode : " << hex << setw(2) << tr_header.getDebugMode() << endl;
91  ss << " Type : " << hex << setw(2) << (int) tr_header.getEventType() << endl;
92  ss << " Readout : " << hex << setw(2) << tr_header.getReadoutMode() << endl;
93  ss << " Condition Data : " << ( tr_header.getConditionData() ? "Present" : "Absent") << "\n";
94  ss << " Data Type : " << ( tr_header.getDataType() ? "Real" : "Fake" ) << "\n";
95  ss << " Status : " << hex << setw(16)<< (int) tr_header.getGlibStatusCode() << endl;
96  ss << " FE stat : " ;
97  for(int i=15; i>=0; i--)
98  {
99  if((tr_header.frontendStatus())[i])
100  {
101  ss << "1";
102  }
103  else
104  {
105  ss << "0";
106  }
107  }
108  ss << endl;
109  ss << " Nr CBC : " << hex << setw(16)<< (int) tr_header.getNumberOfCBC() << endl;
110  ss << " CBC stat : ";
111  for(int i=0; i<tr_header.getNumberOfCBC(); i++)
112  {
113  ss << hex << setw(2) << (int) tr_header.CBCStatus()[i] << " ";
114  }
115  ss << endl;
116  LogTrace("Phase2TrackerDigiProducer") << ss.str(); ss.clear(); ss.str("");
117  ss << " -------------------------------------------- " << endl;
118  ss << " Payload ----------------------------------- " << endl;
119  ss << " -------------------------------------------- " << endl;
120  #endif
121 
122  // loop channels
123  int ichan = 0;
124  for ( int ife = 0; ife < MAX_FE_PER_FED; ife++ )
125  {
126  for ( int icbc = 0; icbc < MAX_CBC_PER_FE; icbc++ )
127  {
128  const Phase2TrackerFEDChannel& channel = buffer->channel(ichan);
129  if(channel.length() > 0)
130  {
131  // get fedid from cabling
132  const Phase2TrackerModule mod = cabling_->findFedCh(std::make_pair(fedIndex, ife));
133  uint32_t detid = mod.getDetid();
134  #ifdef EDM_ML_DEBUG
135  ss << dec << " id from cabling : " << detid << endl;
136  ss << dec << " reading channel : " << icbc << " on FE " << ife;
137  ss << dec << " with length : " << (int) channel.length() << endl;
138  #endif
139 
140  // container for this channel's digis
141  std::vector<Phase2TrackerDigi> stripsTop;
142  std::vector<Phase2TrackerDigi> stripsBottom;
143 
144  // unpacking data
146  while (unpacker.hasData())
147  {
148  if(unpacker.stripOn())
149  {
150  if (unpacker.stripIndex()%2)
151  {
152  stripsTop.push_back(Phase2TrackerDigi( (int) (STRIPS_PER_CBC*icbc + unpacker.stripIndex())/2, 0));
153  #ifdef EDM_ML_DEBUG
154  ss << "t";
155  #endif
156  }
157  else
158  {
159  stripsBottom.push_back(Phase2TrackerDigi( (int) (STRIPS_PER_CBC*icbc + unpacker.stripIndex())/2, 0));
160  #ifdef EDM_ML_DEBUG
161  ss << "b";
162  #endif
163  }
164  }
165  else
166  {
167  #ifdef EDM_ML_DEBUG
168  ss << "_";
169  #endif
170  }
171  unpacker++;
172  }
173  #ifdef EDM_ML_DEBUG
174  ss << endl;
175  LogTrace("Phase2TrackerDigiProducer") << ss.str(); ss.clear(); ss.str("");
176  #endif
177 
178  // store beginning and end of this digis for this detid and add this registry to the list
179  // and store data
180  Registry regItemTop(detid+1, STRIPS_PER_CBC*icbc/2, proc_work_digis_.size(), stripsTop.size());
181  proc_work_registry_.push_back(regItemTop);
182  proc_work_digis_.insert(proc_work_digis_.end(),stripsTop.begin(),stripsTop.end());
183  Registry regItemBottom(detid+2, STRIPS_PER_CBC*icbc/2, proc_work_digis_.size(), stripsBottom.size());
184  proc_work_registry_.push_back(regItemBottom);
185  proc_work_digis_.insert(proc_work_digis_.end(),stripsBottom.begin(),stripsBottom.end());
186  }
187  ichan ++;
188  }
189  } // end loop on channels
190  // store digis in edm collections
192  std::vector< edm::DetSet<Phase2TrackerDigi> > sorted_and_merged;
193 
195 
196  std::vector<Registry>::iterator it = proc_work_registry_.begin(), it2 = it+1, end = proc_work_registry_.end();
197  while (it < end)
198  {
199  sorted_and_merged.push_back( edm::DetSet<Phase2TrackerDigi>(it->detid) );
200  std::vector<Phase2TrackerDigi> & digis = sorted_and_merged.back().data;
201  // first count how many digis we have
202  size_t len = it->length;
203  for (it2 = it+1; (it2 != end) && (it2->detid == it->detid); ++it2) { len += it2->length; }
204  // reserve memory
205  digis.reserve(len);
206  // push them in
207  for (it2 = it+0; (it2 != end) && (it2->detid == it->detid); ++it2)
208  {
209  digis.insert( digis.end(), & proc_work_digis_[it2->index], & proc_work_digis_[it2->index + it2->length] );
210  }
211  it = it2;
212  }
213 
214  edm::DetSetVector<Phase2TrackerDigi> proc_raw_dsv( sorted_and_merged, true );
215  pr->swap( proc_raw_dsv );
216  std::auto_ptr< edm::DetSetVector<Phase2TrackerDigi> > pr_dsv(pr);
217  event.put( pr_dsv, "ProcessedRaw" );
218  delete buffer;
219  }
220  }
221  }
222 }
std::vector< uint8_t > CBCStatus() const
static const char runNumber_[]
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
const Phase2TrackerFEDChannel & channel(const uint8_t internalPhase2TrackerFEDChannelNum) const
const Phase2TrackerModule & findFedCh(std::pair< unsigned int, unsigned int > fedch) const
void reserve(size_t s)
Definition: DetSetVector.h:154
static const uint16_t CMS_FED_ID_MAX
Definition: utils.h:19
edm::EDGetTokenT< FEDRawDataCollection > token_
void swap(DetSetVector &other)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
std::vector< bool > frontendStatus() const
virtual void produce(edm::Event &, const edm::EventSetup &) override
uint32_t getDetid() const
static const int MAX_CBC_PER_FE
Definition: utils.h:25
std::vector< Phase2TrackerDigi > proc_work_digis_
#define end
Definition: vmac.h:37
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
#define LogTrace(id)
Phase2TrackerDigiProducer(const edm::ParameterSet &pset)
constructor
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
static const int STRIPS_PER_CBC
Definition: utils.h:26
static const uint16_t FED_ID_MIN
Definition: utils.h:17
Phase2TrackerFEDHeader trackerHeader() const
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
static const int MAX_FE_PER_FED
Definition: utils.h:24
Definition: Run.h:41