DCMSimulator.cpp
Go to the documentation of this file.
1 /*
2  * File: DCMSimulator.cpp
3  * Author: denis
4  *
5  * Created on January 31, 2012, 5:15 PM
6  */
7 
8 #ifdef NOVACMAKE
12 #else
13 #include "MockDataDAQ/DCMSimulator.h"
14 #include "MockDataDAQ/GlobalEventTime.h"
15 #include "MockDataDAQ/Configuration.h"
16 #endif
17 
18 #include "DAQDataFormats/FEBSimulator.h"
19 #include "DAQDataFormats/RawMicroSlice.h"
21 
22 // ART includes
24 
25 namespace mcdatadaq{
26 
27 //------------------------------------------------------------------------------
29  fDiblockNumber(diblock)
30  , fDCMNumber(dcm)
31  //, fMilliSlice(10000)
32  , fOutputMicroslicesFile(NULL)
33  , fOutputMillislicesFile(NULL)
34 {
36 
37  const daqdataformats::version_t nanoslice_version = config->getNanoSliceVersion();
38  /// Construct 64 front-end-boards
39  for(daqdataformats::link_id_t ifeb = 0; ifeb < 64; ifeb++){
40  fFrontEndBoards.push_back(new daqdataformats::FEBSimulator(ifeb, nanoslice_version));
41  }// end of loop over FEBs
42 
43  /// Setup the milliclice
44  fMilliSlice.setDetId(config->getDetector());
45  fMilliSlice.setDiblockId(diblock);
50 
51  /// Figure out the output file name for the MicroSlices for the DCM
52  std::stringstream final_file_name_microslices_addition;
53  final_file_name_microslices_addition<<"MicroSlices_Diblock"<<fDiblockNumber<<"_Dcmnum"<<fDCMNumber;
54  const std::string final_file_name_microslices = config->getFullFileName(final_file_name_microslices_addition.str());
55 
56  /// Open the file
57  fOutputMicroslicesFile = config->openFile(final_file_name_microslices);
58  /// Now we need to write DAQ Simulation version in the beginning of the file
60 
61  if(config->isProducingMilliSlices()){
62 
63  /// Figure out the output file name for the MilliSlices for the DCM
64  std::stringstream final_file_name_millislices_addition;
65  final_file_name_millislices_addition<<"MilliSlices_Diblock"<<fDiblockNumber<<"_Dcmnum"<<fDCMNumber;
66  const std::string final_file_name_millislices = config->getFullFileName(final_file_name_millislices_addition.str());
67 
68  /// Open the file
69  fOutputMillislicesFile = config->openFile(final_file_name_millislices);
70  /// Now we need to write DAQ Simulation version in the beginning of the file
72  }
73 
74 }// end of constructor
75 
76 
77 //------------------------------------------------------------------------------
79 
80  /// Delete 64 front-end-boards
81  for(uint32_t ifeb = 0; ifeb < fFrontEndBoards.size(); ifeb++){
82  delete fFrontEndBoards[ifeb];
83  }// end of loop over FEBs
84 
85  /// Close the MicroSlices file
87 
88  /// Close the Millislice file
90 }// end of destructor
91 
92 //------------------------------------------------------------------------------
94  const uint32_t simulated_time_stamp,
95  const uint32_t pulse_height){
96 
97  std::vector <uint32_t> data;
98  data.push_back(pulse_height);
99 
100  return generateNanoSlice(daqchannel, simulated_time_stamp, data);
101 
102 }// end of generateNanoSlice
103 
104 //------------------------------------------------------------------------------
106  const uint32_t simulated_time_stamp,
107  const std::vector<uint32_t>& data){
108 
111 
112  /// Front End Board number
113  const daqchannelmap::feb_t feb = cmap->Map()->getFEB(daqchannel);
114 
115  /// Pixel Number on the APD
116  const daqchannelmap::pixel_t pixel = cmap->Map()->getPixel(daqchannel);
117 
118  /// Need to advance by the time of the event
119  const GlobalEventTime* global_event_time = GlobalEventTime::getInstance();
120  const uint32_t simulated_hit_time_in_event = simulated_time_stamp + uint32_t(global_event_time->getGlobalEventTime());
121 
122  /// Get the right FEB simulator for the FEB
123  daqdataformats::FEBSimulator* feb_simulator = getFEBSimulator(feb);
124  /// Generate a nanoslice in that FEB
125  feb_simulator->generateNanoSlice(pixel, simulated_hit_time_in_event, data);
126 
127  /// Get that nanoslice
128  daqdataformats::RawNanoSlice* last_nanoslice_pointer = feb_simulator->getLastNanoSlice();
129 
130  /// The MicroSlice number corresponding to the nanoslice
131  const uint32_t microslice_number = simulated_time_stamp / config->getMicrosliceDT();
132 
133  /// Fill that MicroSlice with the nanoslice that we have just generated
134  fillMicroSlice(microslice_number, last_nanoslice_pointer);
135 
136  return true;
137 }
138 
139 //------------------------------------------------------------------------------
141 
142 //------------------------------------------------------------------------------
143 bool DCMSimulator::fillMicroSlice(const uint32_t microslice_number, daqdataformats::RawNanoSlice* nanoslice){
144 
145  /// Number of microslices created so far
146  const uint32_t number_of_created_microslices_in_event = fMicroSlice.size();
147 
148  /// Create new microslices if needed
149  for(uint32_t i_microslice = number_of_created_microslices_in_event; i_microslice <=microslice_number; i_microslice++){
150  RawMicroSlice_shrptr microslice(createMicroSlice(i_microslice));
151  fMicroSlice.push_back(microslice);
152 
153  }// end of creating new microslices if needed
154 
155  daqdataformats::RawMicroSlice* microslice = fMicroSlice[microslice_number].get();
156 
157  microslice->addNanoSlice(nanoslice->getBuffer());
158 
159  return true;
160 }// end of fillMicroSlice
161 
162 //------------------------------------------------------------------------------
164 
166 
168  const GlobalEventTime* global_event_time = GlobalEventTime::getInstance();
169  const unsigned long long microslice_time_in_event = config->getMicrosliceDT()*microslice_number + global_event_time->getGlobalEventTime();
170 
171  microslice->setMonteCarloFlag(true);
172  microslice->setTime(microslice_time_in_event);
173 
174  return microslice;
175 }// end of createMicroSlice
176 
177 
178 //------------------------------------------------------------------------------
180 
181  const GlobalEventTime* global_event_time = GlobalEventTime::getInstance();
182  fMilliSlice.setTimeStart(global_event_time->getGlobalEventTime());
183 
184  /// Add all microslices for the DCM into the millislice
185  for(uint32_t imicro = 0; imicro < fMicroSlice.size(); imicro++){
186  fMilliSlice.addMicroSlice(fMicroSlice[imicro]->getBuffer());
187  }/// end of adding microslices
188  /// Close MilliSlice
189  fMilliSlice.close();
190 
191  return &fMilliSlice;
192 }// end of fillMilliSlice
193 
194 //------------------------------------------------------------------------------
196 
198 
199  /// Loop over Microslices and write them out
200  for(uint32_t imicro = 0; imicro < fMicroSlice.size(); imicro++){
201  config->writeToFile(fOutputMicroslicesFile, *(fMicroSlice[imicro]));
202  }/// end of adding microslices
203 
204  return true;
205 
206 }// end of writeMicroSlices
207 
208 //------------------------------------------------------------------------------
210 
212 
213  if(!config->isProducingMilliSlices()) return true;
214 
216 }// end of writeMicroSlices
217 
218 //------------------------------------------------------------------------------
220 
221  // Next MilliSlice
222  fMilliSlice.getHeader()->setSliceSize(fMilliSlice.getHeader()->sizeofdata());
223  fMilliSlice.getHeader()->setMicrosliceNumber(0);
226 
227  fMicroSlice.clear();
228 
229  return true;
230 }// end of nextEvent
231 
232 }// end of namespace
unsigned long long getGlobalEventTime() const
GetGlobal Time.
bool generateNanoSlice(const daqchannelmap::dchan, const uint32_t time_stamp, const uint32_t pulse_height)
Generate NanoSlice with a given pixel, TimeStamp and PulseHeight.
diblock
print "ROW IS " print row
Definition: geo2elec.py:31
bool isProducingMilliSlices() const
Definition: Configuration.h:48
bool writeMicroSlices()
Write all MicroSlices into the output file.
uint32_t pixel_t
Type for physical pixel on APD.
bool setDCMId(const uint32_t a)
Definition: RawMilliSlice.h:81
boost::shared_ptr< daqdataformats::RawMicroSlice > RawMicroSlice_shrptr
Shared pointer.
Definition: DCMSimulator.h:26
bool writeMilliSlices()
Write MilliSlice into the output file.
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
bool setDestBuffID(const uint32_t a)
Definition: RawMilliSlice.h:84
FILE * openFile(const std::string file_name) const
Open file for binary write access.
Definition: config.py:1
bool close(const bool produce_crc=false)
bool setDiblockId(const uint32_t a)
Definition: RawMilliSlice.h:80
uint32_t link_id_t
Definition: FEBSimulator.h:8
const XML_Char const XML_Char * data
Definition: expat.h:268
uint32_t fDiblockNumber
Diblock number.
Definition: DCMSimulator.h:60
static Configuration * getInstance()
Method to obtain the class instance.
fclose(fg1)
daqdataformats::RawMilliSliceHeader * getHeader() const
Definition: RawMilliSlice.h:47
daqdataformats::RawMicroSlice * createMicroSlice(const uint32_t microslice_number)
Create a MicroSlice and put it in the vector.
~DCMSimulator()
Destructor.
bool setComplete(const bool a)
Definition: RawMilliSlice.h:90
bool setMonteCarloFlag(const bool a)
Definition: RawMilliSlice.h:98
Something conflicts with RandomNumberGenerator. Keep DAQSimulator.h include below Art Framework inclu...
bool fillMicroSlice(const uint32_t microslice_number, daqdataformats::RawNanoSlice *)
Fill MicroSlice with a given NanoSlice.
int getDetector() const
Get Detector ID.
uint32_t feb_t
Type for DCM link port. Counts from 0.
DCMSimulator(const daqchannelmap::diblock_t, const daqchannelmap::dcm_id_t)
Constructor.
FILE * fOutputMicroslicesFile
Output file with hte microslices from this DCM.
Definition: DCMSimulator.h:69
bool writeToFile(FILE *, const daqdataformats::RawDAQData &) const
Utility method of writing DAQ data into a file.
uint32_t dcm_id_t
Type for DCM number, counts from 1.
bool setTime(const uint64_t)
Set method for upper half of timing word.
pixel_t getPixel(dchan daqchan) const
Decode the pixel id from a dchan.
daqdataformats::version_t getNanoSliceVersion() const
Get NanoSlice version.
std::string getFullFileName(const std::string addition_to_file_name) const
Class to hold the MicroSlice data.
Definition: RawMicroSlice.h:48
bool setTimeStart(const uint64_t a)
Definition: RawMilliSlice.h:86
daqdataformats::FEBSimulator * getFEBSimulator(const daqchannelmap::feb_t)
Get the instance of the FEB Simulator for a given link ID on this DCM.
std::vector< daqdataformats::FEBSimulator * > fFrontEndBoards
All 64 FEBs on the DCM.
Definition: DCMSimulator.h:63
int32_t version_t
Definition: RawDAQData.h:72
void addNanoSlice(const void *nanoslice_buffer, const bool check_mc_flag=true)
bool writeDAQSimulatorVersionIntoFile(FILE *) const
Write Global DAQSimulator version into the input file.
uint32_t diblock_t
Type for diblocks and blocks.
static GlobalEventTime * getInstance()
Method to obtain the class instance.
uint32_t getMicrosliceDT() const
MicroSlice DT.
uint32_t fDCMNumber
DCM number in the diblock.
Definition: DCMSimulator.h:61
bool addMicroSlice(const void *microslice_buffer, const bool indexate=false, const bool check_mc_flag=false)
uint32_t getDestBuffID() const
Definition: RawMilliSlice.h:53
std::vector< RawMicroSlice_shrptr > fMicroSlice
Vector of all Microslices in the event.
Definition: DCMSimulator.h:65
uint32_t dchan
< DAQ Channel Map Package
daqdataformats::RawMilliSlice fMilliSlice
There is going to be 1 Millislice per event.
Definition: DCMSimulator.h:66
bool setMonteCarloFlag(const bool)
Get number of NanoSlices in the MicroSlice.
daqdataformats::RawMilliSlice * fillMilliSlice()
Fill MilliSlices out.
bool nextEvent()
Advance to next event. Advancing MilliSlice. Clearing MicroSlice vector.
bool setDetId(const uint32_t a)
Definition: RawMilliSlice.h:82
feb_t getFEB(dchan daqchan) const
Decode the feb id from a dchan.
enum BeamMode string