200 static const std::map<VMEModuleType, const char *> VMEModuleTypeNames =
217 auto it = VMEModuleTypeNames.find(moduleType);
218 if (it != VMEModuleTypeNames.end())
228 return (((1 << numbits) - 1) & (word >> position));
231 template<
typename LF>
236 int a_numSection = -1,
237 int a_numStartEvent =-1
240 int maxEvents = a_numSection;
242 bool continueReading =
true;
253 TString rootfilename = filename;
254 rootfilename.ReplaceAll(
"mvmelst",
"root");
255 rootfilename.ReplaceAll(
"listfiles",
"data_root"); cout <<
"Root file name: " << rootfilename << endl;
256 TFile *rootfile =
new TFile(rootfilename,
"RECREATE");
257 TTree* dataTree =
new TTree(
"daqEvents",
"daqEvents",99,rootfile);
259 dataTree->Branch(
"events",&daqEv);
260 int sectionCounter = 0;
261 int eventCounter = 0;
263 int timeTickCounter = 0;
264 while (continueReading)
267 infile.read((
char *)§ionHeader,
sizeof(
u32));
268 u32 sectionType = (sectionHeader & LF::SectionTypeMask) >> LF::SectionTypeShift;
269 u32 sectionSize = (sectionHeader & LF::SectionSizeMask) >> LF::SectionSizeShift;
276 cout <<
"Config section of size " << sectionSize << endl;
277 infile.seekg(sectionSize *
sizeof(
u32), std::ifstream::cur);
282 if(eventNumber < a_numStartEvent)
284 infile.seekg(sectionSize *
sizeof(
u32), std::ifstream::cur);
294 cout <<
"Event " << counter << endl;
298 if (counter%10000==0)
300 cout <<
'\r' <<
"Processing event " << counter;
310 u32 eventType = (sectionHeader & LF::EventTypeMask) >> LF::EventTypeShift;
313 printf(
"Event section: eventHeader=0x%08x, eventType=%d, eventSize=%u\n",
314 sectionHeader, eventType, sectionSize);
316 u32 wordsLeft = sectionSize;
318 while (wordsLeft > 1)
321 infile.read((
char *)&subEventHeader,
sizeof(
u32));
323 if (subEventHeader ==0x87654321)
327 cout <<
"\tFill" << endl;
331 u32 moduleType = (subEventHeader & LF::ModuleTypeMask) >> LF::ModuleTypeShift;
332 u32 subEventSize = (subEventHeader & LF::SubEventSizeMask) >> LF::SubEventSizeShift;
337 printf(
" subEventHeader=0x%08x, moduleType=%u (%s), subEventSize=%u\n ",
341 if ((moduleType==4)||(moduleType==7)||(moduleType==8))
344 map < int , vector<MDPP16Event> > boardEvents;
346 map< int , vector<MDPP16ChargeData> > chargeData;
347 map < int , vector<MDPP16ChargeData> > peakChargeData;
349 map < int, vector<uint16_t> > timeData;
350 map < int, vector<uint16_t> > trigTime;
352 uint16_t extendTimeStamp = -1;
354 for (
u32 i=0; i<subEventSize; ++i)
358 u32 subEventData = 0x0;
359 infile.read((
char *)&subEventData,
sizeof(
u32));
362 printf(
" %2u = 0x%08x\n", i, subEventData);
363 if (subEventData == 0x00000000||subEventData ==0x87654321)
367 cout <<
"\tFill" << endl;
376 moduleID = (subEventData & LF::ModuleIDMask) >> LF::ModuleIDShift;
379 cout <<
"\tHeader" << endl;
395 if (writeZeros) chargeData[chan].push_back(dat);
396 else if (data!=0) chargeData[chan].push_back(dat);
397 else timeData[chan].pop_back();
399 else if(chan >= 16 && chan < 32)
401 timeData[chan%16].push_back(data);
403 else if (chan==32||chan==33)
405 trigTime[chan%16].push_back(data);
415 if (writeZeros) peakChargeData[chan%16].push_back(dat);
416 else if (chargeData[chan%16].size()==peakChargeData[chan%16].size()+1) peakChargeData[chan%16].push_back(dat);
420 cout <<
"\tData" << endl;
421 cout <<
"\t" << ov <<
"\t"
422 << chan <<
"\t" << data << endl;
431 cout <<
"\tExtended time stamp:\t" << extended << endl;
434 else if((sig&0xc)==0xc)
438 for (
auto& charges : chargeData )
443 ev.
addTimes(charges.first, timeData[charges.first]);
448 for (
int hit = 0; hit < charges.second.size(); hit++)
450 if (charges.second[hit].m_charge!=0 && timeData[charges.first][hit]!=0) numGoodHits++;
452 if (numGoodHits == charges.second.size())
455 ev.
addTimes(charges.first, timeData[charges.first]);
468 for(
auto& charges : peakChargeData )
472 for(
auto& trigChannel : trigTime )
474 for(
auto& time : trigChannel.second)
483 cout <<
"\tEnd of event" << endl;
484 cout <<
"\tTime:\t" <<
bitExtractor(subEventData, 30, 0) << endl;
488 daqEv->
m_modules[moduleID].push_back(ev);
493 daqEv->
m_modules[moduleID].push_back(ev);
494 if (optverbose) cout <<
"good event!" <<endl;
497 extendTimeStamp = -1;
500 peakChargeData.clear();
513 infile.read((
char *)&eventEndMarker,
sizeof(
u32));
516 printf(
" eventEndMarker=0x%08x\n", eventEndMarker);
522 if (hadEvent>0) dataTree->Fill();
523 if(maxEvents >0 && counter >= maxEvents)
525 continueReading =
false;
532 printf(
"Timetick\n");
536 printf(
"\nFound Listfile End section\n");
537 continueReading =
false;
538 auto currentFilePos = infile.tellg();
539 infile.seekg(0, std::ifstream::end);
540 auto endFilePos = infile.tellg();
541 if (currentFilePos != endFilePos)
543 cout <<
"Warning: " << (endFilePos - currentFilePos)
544 <<
" bytes left after Listfile End Section" << endl;
550 printf(
"Warning: Unknown section type %u of size %u, skipping...\n",
551 sectionType, sectionSize);
552 infile.seekg(sectionSize *
sizeof(
u32), std::ifstream::cur);
556 cout << counter <<
" events total" << endl;
578 int a_numSection = -1,
579 int a_numStartEvent =-1
585 const size_t bytesToRead = 4;
586 char fourCC[bytesToRead] = {};
588 infile.read(fourCC, bytesToRead);
589 static const char *
const FourCC =
"MVME";
591 if (std::strncmp(fourCC, FourCC, bytesToRead) == 0)
593 infile.read(
reinterpret_cast<char *
>(&fileVersion),
sizeof(fileVersion));
597 auto firstSectionOffset = ((fileVersion == 0)
601 infile.seekg(firstSectionOffset, std::ifstream::beg);
603 cout <<
"Detected listfile version " << fileVersion << endl;
611 process_listfile<listfile_v1>(infile, filename, optverbose,writeZeros,a_numSection, a_numStartEvent);
int bitExtractor(int word, int numbits, int position)
Definition: MesyDaqParsingSupport.h:227
int64_t s64
Definition: MesyDaqParsingSupport.h:38
uint64_t u64
Definition: MesyDaqParsingSupport.h:33
uint8_t u8
Definition: MesyDaqParsingSupport.h:30
int8_t s8
Definition: MesyDaqParsingSupport.h:35
void process_listfile(std::ifstream &infile, TString filename, bool optverbose, bool writeZeros, int a_numSection=-1, int a_numStartEvent=-1)
Definition: MesyDaqParsingSupport.h:232
int16_t s16
Definition: MesyDaqParsingSupport.h:36
uint16_t u16
Definition: MesyDaqParsingSupport.h:31
int32_t s32
Definition: MesyDaqParsingSupport.h:37
uint32_t u32
Definition: MesyDaqParsingSupport.h:32
Definition: MDPP16DataStructures.h:18
uint16_t m_charge
Definition: MDPP16DataStructures.h:24
bool m_pileUp
Definition: MDPP16DataStructures.h:22
bool m_overFlow
Definition: MDPP16DataStructures.h:23
Definition: MDPP16DataStructures.h:32
void setExtTimeStamp(uint16_t a_extTimeStamp)
set the ext time stamp for the event
Definition: MDPP16DataStructures.cpp:129
void addTrigTimeStamp(int a_channel, uint16_t a_trigTimeStamp)
set the trig0 time stamp for the event
Definition: MDPP16DataStructures.cpp:140
bool isGoodEvent()
Definition: MDPP16DataStructures.cpp:304
void setEndOfEventWord(uint32_t a_endWord)
sets the end of event word
Definition: MDPP16DataStructures.cpp:134
void addTimes(int a_channel, const vector< uint16_t > &a_times)
Definition: MDPP16DataStructures.cpp:90
void addCharges(int a_channel, const vector< MDPP16ChargeData > &a_charges)
adds content to the charge map
Definition: MDPP16DataStructures.cpp:79
void addPeakCharges(int a_channel, const vector< MDPP16ChargeData > &a_charges)
adds content to the peak charge map
Definition: MDPP16DataStructures.cpp:100
Definition: MesyDAQEvent.h:6
map< unsigned int, vector< MDPP16Event > > m_modules
Definition: MesyDAQEvent.h:8
Definition: MesyDaqParsingSupport.h:163
const char * get_vme_module_name(VMEModuleType moduleType)
Definition: MesyDaqParsingSupport.h:215
VMEModuleType
Definition: MesyDaqParsingSupport.h:185
@ MDPP32
Definition: MesyDaqParsingSupport.h:191
@ MADC32
Definition: MesyDaqParsingSupport.h:187
@ VHS4030p
Definition: MesyDaqParsingSupport.h:197
@ MesytecCounter
Definition: MesyDaqParsingSupport.h:196
@ MDPP16_SCP
Definition: MesyDaqParsingSupport.h:190
@ MTDC32
Definition: MesyDaqParsingSupport.h:189
@ MDPP16_RCP
Definition: MesyDaqParsingSupport.h:193
@ Invalid
Definition: MesyDaqParsingSupport.h:186
@ MDPP16_QDC
Definition: MesyDaqParsingSupport.h:194
@ VMMR
Definition: MesyDaqParsingSupport.h:195
@ MDI2
Definition: MesyDaqParsingSupport.h:192
@ MQDC32
Definition: MesyDaqParsingSupport.h:188
SectionType
Definition: MesyDaqParsingSupport.h:165
@ SectionType_End
Definition: MesyDaqParsingSupport.h:176
@ SectionType_Max
Definition: MesyDaqParsingSupport.h:181
@ SectionType_Config
Definition: MesyDaqParsingSupport.h:170
@ SectionType_Timetick
Definition: MesyDaqParsingSupport.h:179
@ SectionType_Event
Definition: MesyDaqParsingSupport.h:173
Definition: MesyDaqParsingSupport.h:78
static const int SectionMaxSize
Definition: MesyDaqParsingSupport.h:82
static const int Version
Definition: MesyDaqParsingSupport.h:79
static const int SectionTypeMask
Definition: MesyDaqParsingSupport.h:83
static const int SubEventSizeMask
Definition: MesyDaqParsingSupport.h:97
static const int SectionSizeShift
Definition: MesyDaqParsingSupport.h:86
static const int SectionTypeShift
Definition: MesyDaqParsingSupport.h:84
static const int ModuleIDMask
Definition: MesyDaqParsingSupport.h:93
static const int SubEventMaxWords
Definition: MesyDaqParsingSupport.h:95
static const int FirstSectionOffset
Definition: MesyDaqParsingSupport.h:80
static const int ModuleTypeMask
Definition: MesyDaqParsingSupport.h:90
static const int SubEventSizeShift
Definition: MesyDaqParsingSupport.h:98
static const int SectionMaxWords
Definition: MesyDaqParsingSupport.h:81
static const int EventTypeMask
Definition: MesyDaqParsingSupport.h:87
static const int ModuleTypeShift
Definition: MesyDaqParsingSupport.h:91
static const int EventTypeShift
Definition: MesyDaqParsingSupport.h:88
static const int ModuleIDShift
Definition: MesyDaqParsingSupport.h:94
static const int SectionSizeMask
Definition: MesyDaqParsingSupport.h:85
static const int SubEventMaxSize
Definition: MesyDaqParsingSupport.h:96
Definition: MesyDaqParsingSupport.h:139
static const int ModuleIDMask
Definition: MesyDaqParsingSupport.h:154
static const int SectionTypeShift
Definition: MesyDaqParsingSupport.h:145
static const int SectionMaxSize
Definition: MesyDaqParsingSupport.h:143
static const int FirstSectionOffset
Definition: MesyDaqParsingSupport.h:141
static const int SubEventSizeMask
Definition: MesyDaqParsingSupport.h:158
static const int ModuleIDShift
Definition: MesyDaqParsingSupport.h:155
static const int ModuleTypeShift
Definition: MesyDaqParsingSupport.h:152
static const int SectionTypeMask
Definition: MesyDaqParsingSupport.h:144
static const int SectionSizeShift
Definition: MesyDaqParsingSupport.h:147
static const int SubEventMaxSize
Definition: MesyDaqParsingSupport.h:157
static const int ModuleTypeMask
Definition: MesyDaqParsingSupport.h:151
static const int EventTypeShift
Definition: MesyDaqParsingSupport.h:149
static const int SectionMaxWords
Definition: MesyDaqParsingSupport.h:142
static const int SubEventMaxWords
Definition: MesyDaqParsingSupport.h:156
static const int SectionSizeMask
Definition: MesyDaqParsingSupport.h:146
static const int EventTypeMask
Definition: MesyDaqParsingSupport.h:148
static const int SubEventSizeShift
Definition: MesyDaqParsingSupport.h:159
static const int Version
Definition: MesyDaqParsingSupport.h:140