33 #define CHECKBYTEBIT(var, pos) ( (var) & (1<<pos) ) 34 #define DCBITFLAG 0x0 // 0x0 LSB -> 0x7 MSB 35 #define GETDCFLAG(info) (CHECKBYTEBIT(info, DCBITFLAG)>0) 41 #define EVDQFLAG(info) ( (info & 0x3F ) == EVCARD0 ) 51 void unpackCroData(
const char *buf,
size_t nb,
bool cflag,
52 unsigned nsa, adcbuf_t &
data )
59 const BYTE* start = buf;
60 const BYTE* stop = start +
nb;
67 uint16_t tmp1 = ((v1 << 4) + ((v2 >> 4) & 0xf)) & 0xfff;
68 uint16_t tmp2 = (((v2 & 0xf) << 8 ) + (v3 & 0xff)) & 0xfff;
82 data.back()[sz++] = (short)tmp1;
85 data.back()[sz++] = (short)tmp2;
93 mf::LogError(__FUNCTION__)<<
"The format for the compressed data is to be defined";
101 const T *ptr =
static_cast<const T*
>(in);
109 virtual const char* what()
const throw()
111 return "Bad file format";
114 static formatexception
fex;
127 __sourceHelper( pm ),
132 const std::string myname =
"PDDPRawInputDriver::ctor: ";
138 auto vecped_crps = pset.
get<std::vector<UIntVec>>(
"InvertBaseline", std::vector<UIntVec>());
139 auto select_crps = pset.
get<std::vector<unsigned>>(
"SelectCRPs", std::vector<unsigned>());
141 std::map<unsigned, unsigned> invped_crps;
142 if( !vecped_crps.empty() ){
143 for(
auto &v : vecped_crps ){
146 std::cerr<<myname<<
"Bad vector size for pedestal inversion parameters"<<
std::endl;
150 invped_crps[ v[0] ] = v[1];
156 std::cout << myname <<
" Configuration : " <<
std::endl;
158 std::cout << myname <<
" OutputLabelRawDigits : " << __outlbl_digits <<
std::endl;
159 std::cout << myname <<
" OutputLabelRDStatus : " << __outlbl_status <<
std::endl;
160 std::cout << myname <<
" OutputLabelRDtime : " << __outlbl_rdtime <<
std::endl;
161 std::cout << myname <<
" SelectCRPs : ";
162 if( select_crps.empty() ) std::cout<<
"all"<<std::endl;
165 std::ostringstream vstr;
166 std::copy(select_crps.begin(), select_crps.end()-1,
167 std::ostream_iterator<unsigned>(vstr,
", "));
168 vstr << select_crps.back();
171 std::cout << myname <<
" InvertBaseline : ";
172 if( invped_crps.empty() ) std::cout<<
"None"<<std::endl;
174 for(
auto const &
m : invped_crps )
175 std::cout<<
"[ "<<
m.first<<
", "<<
m.second<<
" ] ";
204 auto crpidx =
cmap->get_crpidx();
205 for(
auto c: crpidx )
207 std::vector<dune::DPChannelId> chidx =
cmap->find_by_crp(
c,
true );
211 if( !select_crps.empty() )
213 if( std::find( select_crps.begin(), select_crps.end(),
c ) == select_crps.end() )
219 std::cout<<myname<<
" CRP "<<
c<<
" selected "<<keep<<
std::endl;
223 if( !invped_crps.empty() ){
224 auto it = invped_crps.find(
c );
225 if( it != invped_crps.end() ){
230 std::cout<<myname<<
" CRP "<<
c<<
" baseline "<<invped<<
std::endl;
234 for(
auto id: chidx )
236 __daqch.push_back(
id.seqn() );
244 std::cout << myname <<
" Readout info : " <<
std::endl;
245 std::cout<<myname <<
" Number of CRPs from chmap : " <<
cmap->ncrps() <<
std::endl;
246 std::cout<<myname <<
" Total channels expected : " <<
__daqch.size() <<
std::endl;
269 __file.open( name.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
274 <<
"Error opening binary file " << name <<
std::endl;
281 __file.seekg(0, std::ios::beg);
288 <<
"File " << name <<
" does not have any events"<<
std::endl;
316 std::vector<BYTE> buf;
330 uint64_t sec =
event.trigstamp.tv_sec;
331 uint64_t nsec =
event.trigstamp.tv_nsec;
334 uint64_t tval = (sec << 32) + nsec;
358 event.evnum, tstamp );
361 std::unique_ptr< std::vector<raw::RawDigit> > cro_data (
new std::vector<raw::RawDigit> );
362 std::unique_ptr< std::vector<raw::RDTimeStamp> > cro_rdtm (
new std::vector<raw::RDTimeStamp> );
363 std::unique_ptr< std::vector<raw::RDStatus> > cro_stat (
new std::vector<raw::RDStatus> );
366 cro_data->reserve( event.crodata.size() );
371 for(
size_t i=0;i<
event.crodata.size();i++ )
375 mf::LogError(__FUNCTION__)<<
"The channel map appears to be wrong";
384 for(
auto &
e : event.crodata[daqch] ){
385 float v = (
float)invped -
e;
391 event.compression) );
394 cro_data->push_back(
raw::RawDigit(ch, 0, dummy, event.compression) );
404 unsigned int statword = 0;
405 bool discarded =
false;
412 if( discarded ) statword |= 1;
413 if( kept ) statword |= 2;
414 cro_stat->emplace_back( discarded, kept, statword );
417 uint16_t rdtsflags = 0xd;
432 size_t ipos = lbl.find(
":");
433 if ( ipos != std::string::npos ) {
434 res = lbl.substr(ipos + 1);
435 lbl = lbl.substr(0, ipos);
458 __file.read( &bytes[0], sz );
477 std::vector<BYTE> buf;
478 size_t msz = 2*
sizeof(uint32_t);
480 if( buf.size() != msz )
482 mf::LogError(__FUNCTION__)<<
"Could not read number of events";
488 __eventNum = ConvertToValue<uint32_t>(&buf[4]);
494 mf::LogError(__FUNCTION__)<<
"File does not contain any events";
500 size_t evtsz =
__eventNum * 4 *
sizeof(uint32_t);
514 for(
unsigned i=0;i<buf.size();i+=16 )
520 uint32_t sz = ConvertToValue<uint32_t>(&buf[i+o]);
529 for(
size_t i=0; i <
__evsz.size()-1; i++)
534 mf::LogError(__FUNCTION__)<<
"Event table does not match file size";
564 static const unsigned evskey = 0xFF;
565 if( !( ((k0 & 0xFF) == evskey) && ((k1 & 0xFF) == evskey) ) )
567 mf::LogError(__FUNCTION__)<<
"Event delimiting word could not be detected";
573 ei.
runnum = ConvertToValue<uint32_t>( buf+rval );
574 rval +=
sizeof( ei.
runnum );
580 ei.
ti = ConvertToValue<triginfo_t>( buf+rval );
581 rval +=
sizeof(ei.
ti);
584 ei.
evflag = (uint8_t)buf[rval++];
587 ei.
evnum = ConvertToValue<uint32_t>( buf+rval );
588 rval +=
sizeof( ei.
evnum );
591 ei.
evszlro = ConvertToValue<uint32_t>( buf+rval );
595 ei.
evszcro = ConvertToValue<uint32_t>( buf+rval );
611 std::vector<fragment_t> frags;
617 if( idx >= buf.size() )
break;
619 if( rval == 0 )
return false;
622 afrag.
bytes = &buf[idx];
628 if( frags.size() >= 1 )
630 if( frags[0].ei.runnum != afrag.
ei.
runnum )
632 mf::LogError(__FUNCTION__)<<
"run numbers do not match among event fragments";
635 if( frags[0].ei.evnum != afrag.
ei.
evnum )
637 mf::LogError(__FUNCTION__)<<
"event numbers do not match among event fragments";
638 mf::LogDebug(__FUNCTION__)<<
"event number "<< frags[0].ei.evnum;
645 frags.push_back( afrag );
651 std::vector<std::thread>
threads(frags.size() - 1);
654 for (
unsigned i = 1; i<frags.size(); ++i)
656 auto afrag = frags.begin() + i;
657 threads[i-1] = std::thread([&iomutex, i, nsa, afrag] {
659 std::lock_guard<std::mutex> iolock(iomutex);
662 if (i==100000) std::cout <<
"Unpack thread #" << i <<
" is running\n";
665 unpackCroData( afrag->bytes + afrag->ei.evszlro, afrag->ei.evszcro,
666 GETDCFLAG(afrag->ei.runflags), nsa, afrag->crodata);
671 auto f0 = frags.begin();
672 event.good =
EVDQFLAG( f0->ei.evflag );
673 event.runnum = f0->ei.runnum;
674 event.runflags = f0->ei.runflags;
676 event.evnum = f0->ei.evnum;
677 event.evflags.push_back( f0->ei.evflag );
679 event.trigtype = f0->ei.ti.type;
680 event.trignum = f0->ei.ti.num;
681 event.trigstamp = f0->ei.ti.ts;
684 unpackCroData( f0->bytes + f0->ei.evszlro, f0->ei.evszcro,
GETDCFLAG(f0->ei.runflags),
685 nsa, event.crodata );
697 for (
auto it = frags.begin() + 1; it != frags.end(); ++it )
699 event.good = (
event.good &&
EVDQFLAG( it->ei.evflag ) );
700 event.evflags.push_back( it->ei.evflag );
703 event.crodata.reserve(event.crodata.size() + it->crodata.size() );
705 std::back_inserter( event.crodata ));
720 std::regex
r(
"[[:digit:]]+_([[:digit:]]+)_[[:alnum:]]\\.[[:alnum:]]+");
723 if( !regex_search( s, m, r ) )
725 mf::LogWarning(__FUNCTION__) <<
"Unable to extract seqno from file name "<<
s;
733 rval = std::stoi( m.str(1) );
735 catch (
const std::invalid_argument& ia)
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
static constexpr double nb
Collection of charge vs time digitized from a single readout channel.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
TypeLabel const & reconstitutes(std::string const &modLabel, std::string const &instanceName={})
T get(std::string const &key) const
IDNumber_t< Level::SubRun > SubRunNumber_t
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
T ConvertToValue(const void *in)
std::enable_if_t<!detail::range_sets_supported(P::branch_type)> put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
Conversion of binary data to root files.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
cet::LibraryManager dummy("noplugin")
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::unique_ptr< History > &&history) const
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
SubRunNumber_t subRun() const
unsigned int ChannelID_t
Type representing the ID of a readout channel.
byte bytes
Alias for common language habits.
static formatexception fex
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
Event finding and building.
IDNumber_t< Level::Run > RunNumber_t