37 #include <sys/types.h>
41 #include <arpa/inet.h>
44 #include <sys/socket.h>
45 #include <sys/unistd.h>
56 inputModuleLabel_(
pset.getParameter<
std::
string>(
"InputModuleLabel")),
57 inputModuleLabelAlt_(
pset.existsAs<
std::
string>(
"InputModuleLabelAlt")
60 inputModuleLabelSummary_(
pset.getParameter<
std::
string>(
"SummaryInputModuleLabel")),
69 taskConfigurable_(
pset.getUntrackedParameter<
std::
string>(
"CommissioningTask",
"UNDEFINED")),
75 updateFreq_(
pset.getUntrackedParameter<
int>(
"HistoUpdateFreq", 1)),
77 view_(
pset.getUntrackedParameter<
std::
string>(
"View",
"Default")),
94 <<
" Constructing object...";
96 tasks_.resize(1024,
VecOfTasks(96, static_cast<CommissioningTask*>(
nullptr)));
111 <<
" Destructing object...";
118 std::stringstream
ss;
120 ss <<
"[SiStripCommissioningSource::" <<
method <<
"]" << std::endl;
122 ss <<
"[SiStripCommissioningSource]" << std::endl;
124 ss <<
" NULL pointer to DQMStore";
138 <<
" Configuring..." << std::endl;
144 <<
" DQMStore service: " <<
dqm_;
149 std::stringstream
dir(
"");
155 fedCabling_ = const_cast<SiStripFedCabling*>(&fed_cabling);
157 <<
"Initialized FED cabling. Number of FEDs is " <<
fedCabling_->
fedIds().size();
160 std::stringstream
ss;
161 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
162 <<
" Empty std::vector returned by FEC cabling object!"
163 <<
" Check if database connection failed...";
183 <<
" Halting..." << std::endl;
189 itask->second->updateHistograms();
194 for (uint16_t partition = 0; partition < 4; ++partition) {
195 tasks_[0][partition]->updateHistograms();
198 tasks_[0][0]->updateHistograms();
206 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
207 if (!iconn->isConnected()) {
210 fed_id = iconn->fedId();
211 fed_ch = iconn->fedCh();
212 if (
tasks_[fed_id][fed_ch]) {
213 tasks_[fed_id][fed_ch]->updateHistograms();
214 delete tasks_[fed_id][fed_ch];
223 if (
filename_.find(
".root", 0) == std::string::npos) {
232 if (std::getenv(scratch.c_str()) !=
nullptr) {
233 dir = std::getenv(scratch.c_str());
237 std::stringstream
ss;
258 <<
" NULL value for RunNumber! No root file saved!";
262 <<
" NULL value for filename! No root file saved!";
266 <<
" Saved all histograms to file \"" <<
ss.str() <<
"\"";
298 <<
" Unknown/undefined RunType and NULL parameter values!"
299 <<
" It may be that the 'trigger FED' object was not found!";
307 run_ =
event.id().run();
313 std::stringstream
ss;
314 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
315 <<
" The last " <<
updateFreq_ <<
" events were processed at a rate of ";
353 std::stringstream
ss;
354 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
355 <<
" Requested DAQ_SCOPE_MODE but unknown FED"
356 <<
" readout mode retrieved from SiStripEventSummary: "
371 std::stringstream
ss;
372 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
374 <<
" Unable to establish FED readout mode and retrieve digi container!"
375 <<
" Check if SiStripEventSummary object is found/present in Event";
382 std::stringstream
ss;
383 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" << std::endl
384 <<
" NULL pointer to DetSetVector!" << std::endl
385 <<
" Unable to fill histograms!";
391 std::stringstream
ss;
392 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" << std::endl
393 <<
" NULL pointer to DetSetVector!" << std::endl
394 <<
" Unable to fill histograms!";
400 std::stringstream
ss;
401 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" << std::endl
402 <<
" NULL pointer to DetSetVector!" << std::endl
403 <<
" Unable to fill histograms!";
421 uint16_t lld_channel = (
summary->deviceId() & 0x3) + 1;
428 uint32_t fec_key = key_object.
key();
429 std::stringstream sss;
430 sss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
431 <<
" Found DcuId 0x" << std::hex << std::setw(8) << std::setfill(
'0') <<
summary->dcuId() <<
std::dec
432 <<
" with Crate/FEC/Ring/CCU/Module/LLD: " << module.
key().
fecCrate() <<
"/" << module.
key().
fecSlot() <<
"/"
440 std::stringstream
ss;
441 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
442 <<
" DcuId 0x" << std::hex << std::setw(8) << std::setfill(
'0') <<
summary->dcuId() <<
std::dec
443 <<
" in 'DAQ register' field not found in cabling map!"
444 <<
" (NULL values returned for FEC path)";
457 std::map<uint16_t, float> medians;
459 std::map<uint16_t, float> medians1;
463 for (uint16_t ichan = 0; ichan < 96; ichan++) {
467 std::vector<edm::DetSet<SiStripRawDigi> >::const_iterator digis = raw.
find(fed_key);
468 if (digis != raw.
end()) {
469 if (digis->data.empty()) {
474 for (uint16_t idigi = 0; idigi < digis->data.size(); idigi++) {
475 ave.add(static_cast<uint32_t>(digis->data[idigi].adc()));
479 medians[ichan] =
params.median_;
480 medians1[ichan] = digis->data[0].adc();
487 std::map<uint16_t, float>::const_iterator
ii = medians.begin();
488 for (;
ii != medians.end();
ii++) {
494 std::stringstream
ss;
495 ss <<
"FED Averages:" << std::endl
496 <<
" nChans: " << medians.size() << std::endl
497 <<
" num/mean/median/rms/max/min: " <<
tmp.num_ <<
"/" <<
tmp.mean_ <<
"/" <<
tmp.median_ <<
"/" <<
tmp.rms_
498 <<
"/" <<
tmp.max_ <<
"/" <<
tmp.min_ << std::endl;
503 std::map<uint16_t, float>::const_iterator
jj = medians.begin();
504 for (;
jj != medians.end();
jj++) {
505 if (
jj->second <
tmp.median_ +
tmp.rms_) {
506 truncated.add(
jj->second);
512 std::stringstream ss1;
513 ss1 <<
"Truncated Averages:" << std::endl
514 <<
" nChans: " << medians.size() << std::endl
515 <<
" num/mean/median/rms/max/min: " <<
params.num_ <<
"/" <<
params.mean_ <<
"/" <<
params.median_ <<
"/"
520 std::stringstream ss2;
521 std::stringstream ss3;
523 std::map<uint16_t, float>::const_iterator ichan = medians.begin();
524 for (; ichan != medians.end(); ichan++) {
525 if (ichan->second > 200.) {
526 LogTrace(
mlTest_) <<
"TEST FOUND SIGNAL HIGH: " << *ifed <<
" " << ichan->first <<
" " << ichan->second;
527 channels[ichan->first] = ichan->second;
530 << ichan->second <<
" ";
532 << medians1[ichan->first] <<
" ";
545 std::stringstream
ss;
546 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
547 <<
" Filled histogram for '" <<
cablingTasks_[fec_key]->myName() <<
"' object with FecKey: 0x" << std::hex
548 << std::setfill(
'0') << std::setw(8) << fec_key <<
std::dec
549 <<
" and Crate/FEC/ring/CCU/module/LLDchan: " <<
path.fecCrate() <<
"/" <<
path.fecSlot() <<
"/"
550 <<
path.fecRing() <<
"/" <<
path.ccuAddr() <<
"/" <<
path.ccuChan() <<
"/" <<
path.channel();
555 std::stringstream
ss;
556 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
557 <<
" Unable to find CommissioningTask object with FecKey: 0x" << std::hex << std::setfill(
'0') << std::setw(8)
558 << fec_key <<
std::dec <<
" and Crate/FEC/ring/CCU/module/LLDchan: " <<
path.fecCrate() <<
"/"
559 <<
path.fecSlot() <<
"/" <<
path.fecRing() <<
"/" <<
path.ccuAddr() <<
"/" <<
path.ccuChan() <<
"/"
574 std::vector<uint16_t> stripOnClusters;
579 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
583 if (!iconn->isConnected()) {
592 std::vector<edm::DetSet<SiStripRawDigi> >::const_iterator digis = raw.
find(fed_key);
595 std::vector<edm::DetSet<SiStripRawDigi> >::const_iterator digisAlt;
596 if (not rawAlt.
empty()) {
597 digisAlt = rawAlt.
find(fed_key);
598 if (digisAlt == rawAlt.
end())
603 stripOnClusters.clear();
607 if (DSViter->id() != iconn->detId())
611 if (DSiter->firstStrip() >= iconn->apvPairNumber() * 256 and
612 DSiter->firstStrip() < (1 + iconn->apvPairNumber()) * 256) {
613 for (
size_t istrip = 0; istrip < DSiter->amplitudes().size(); istrip++) {
614 stripOnClusters.push_back(DSiter->firstStrip() + istrip - iconn->apvPairNumber() * 256);
621 if (digis != raw.
end()) {
624 if (
tasks_[0][iconn->fecCrate() - 1]) {
625 tasks_[0][iconn->fecCrate() - 1]->fillHistograms(*
summary, *digis);
627 std::stringstream
ss;
628 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
629 <<
" Unable to find CommissioningTask for FEC crate " << iconn->fecCrate()
630 <<
". Unable to fill histograms!";
637 std::stringstream
ss;
638 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
639 <<
" Unable to find global CommissioningTask for FineDelay. Unable to fill histograms!";
643 if (
tasks_[iconn->fedId()][iconn->fedCh()]) {
644 if (not rawAlt.
empty()
or digisAlt == rawAlt.
end())
645 tasks_[iconn->fedId()][iconn->fedCh()]->fillHistograms(*
summary, *digis);
647 if (stripOnClusters.empty())
648 tasks_[iconn->fedId()][iconn->fedCh()]->fillHistograms(*
summary, *digis, *digisAlt);
650 tasks_[iconn->fedId()][iconn->fedCh()]->fillHistograms(*
summary, *digis, *digisAlt, stripOnClusters);
654 std::stringstream
ss;
655 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
656 <<
" Unable to find CommissioningTask object with FED key " << std::hex << std::setfill(
'0')
657 << std::setw(8) << fed_key <<
std::dec <<
" and FED id/ch " << iconn->fedId() <<
"/" << iconn->fedCh()
658 <<
" Unable to fill histograms!";
666 std::stringstream
ss;
667 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
668 <<
" Unable to find any DetSet containing digis for FED key " << std::hex << std::setfill(
'0')
669 << std::setw(8) << fed_key <<
std::dec <<
" and FED id/ch " << iconn->fedId() <<
"/" << iconn->fedCh();
683 <<
" NULL run number!";
689 std::stringstream
run;
703 std::stringstream
ss;
704 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
709 std::stringstream
ss;
710 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
711 <<
" NULL pointer to SiStripEventSummary!"
712 <<
" Check SiStripEventSummary is found/present in Event";
719 std::stringstream
ss;
720 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
724 task_ = configurable;
734 std::stringstream
ss;
735 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
736 <<
" Unexpected CommissioningTask found (" << static_cast<uint16_t>(
task_) <<
") \""
738 <<
" Unexpected value found in SiStripEventSummary and/or cfg file"
739 <<
" If SiStripEventSummary is not present in Event,"
740 <<
" check 'CommissioningTask' configurable in cfg file";
744 std::stringstream
ss;
745 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
757 std::stringstream
ss;
758 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
763 <<
" Creating CommissioningTask objects and booking histograms...";
770 <<
" Finished booking histograms!";
779 for (std::vector<SiStripFecCrate>::const_iterator icrate =
fecCabling_->
crates().begin();
782 for (std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++) {
783 for (std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end();
785 for (std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end();
787 for (std::vector<SiStripModule>::const_iterator imodule = iccu->modules().begin();
788 imodule != iccu->modules().end();
792 icrate->fecCrate(), ifec->fecSlot(), iring->fecRing(), iccu->ccuAddr(), imodule->ccuChan());
795 if (!
path.isValid()) {
804 for (uint16_t ipair = 0; ipair < imodule->nApvPairs(); ipair++) {
818 imodule->nApvPairs());
826 imodule->lldChannel(ipair))
832 <<
" Unexpected NULL value for FEC key!";
842 <<
" Undefined CommissioningTask"
843 <<
" Unable to create FedCablingTask object!";
846 <<
" Unknown CommissioningTask"
847 <<
" Unable to create FedCablingTask object!";
850 <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
852 <<
" Unable to create FedCablingTask object!";
861 std::stringstream
ss;
862 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
863 <<
" Booking histograms for '" <<
cablingTasks_[
key]->myName() <<
"' object with key 0x"
864 << std::hex << std::setfill(
'0') << std::setw(8) <<
key <<
std::dec <<
" in directory \"" <<
dir
868 std::stringstream
ss;
869 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
870 <<
" NULL pointer to CommissioningTask for key 0x" << std::hex << std::setfill(
'0')
871 << std::setw(8) <<
key <<
std::dec <<
" in directory " <<
dir <<
" Unable to book histograms!";
875 std::stringstream
ss;
876 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
877 <<
" Unable to find CommissioningTask for key 0x" << std::hex << std::setfill(
'0') << std::setw(8)
878 <<
key <<
std::dec <<
" in directory " <<
dir <<
" Unable to book histograms!";
883 std::stringstream
ss;
884 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
885 <<
" CommissioningTask object already exists for key 0x" << std::hex << std::setfill(
'0')
887 <<
" Unable to create FedCablingTask object!";
899 <<
" Created " << booked <<
" CommissioningTask objects and booked histograms";
909 for (uint16_t partition = 0; partition < 4; ++partition) {
916 tasks_[0][partition]->bookHistograms();
925 tasks_[0][0]->bookHistograms();
935 for (
auto iconn = conns.begin(); iconn != conns.end(); ++iconn) {
938 iconn->fecCrate(), iconn->fecSlot(), iconn->fecRing(), iconn->ccuAddr(), iconn->ccuChan());
942 if (!iconn->isConnected()) {
950 std::stringstream
dir;
952 if (
view_ ==
"Default") {
954 dir << fed_key.path();
956 dir << fec_key.path();
958 }
else if (
view_ ==
"FecView") {
959 dir << fec_key.path();
960 }
else if (
view_ ==
"FedView") {
961 dir << fed_key.path();
962 }
else if (
view_ ==
"DetView") {
967 <<
" Invalid view " <<
view_ << std::endl
968 <<
" Histograms will end up all in the top directory.";
973 if (!
tasks_[iconn->fedId()][iconn->fedCh()]) {
995 tasks_[iconn->fedId()][iconn->fedCh()] =
998 tasks_[iconn->fedId()][iconn->fedCh()] =
1002 <<
" Undefined CommissioningTask"
1003 <<
" Unable to create CommissioningTask object!";
1006 <<
" Unknown CommissioningTask"
1007 <<
" Unable to create CommissioningTask object!";
1011 if (
tasks_[iconn->fedId()][iconn->fedCh()]) {
1012 tasks_[iconn->fedId()][iconn->fedCh()]->eventSetup(&
setup);
1016 tasks_[iconn->fedId()][iconn->fedCh()]->bookHistograms();
1019 static_cast<CalibrationScanTask*>(
tasks_[iconn->fedId()][iconn->fedCh()])->setCurrentFolder(
dir.str());
1021 static_cast<CalibrationTask*>(
tasks_[iconn->fedId()][iconn->fedCh()])->setCurrentFolder(
dir.str());
1026 std::stringstream
ss;
1027 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
1028 <<
" NULL pointer to CommissioningTask for key 0x" << std::hex << std::setfill(
'0') << std::setw(8)
1029 << fed_key.key() <<
std::dec <<
" in directory " <<
dir.str() <<
" Unable to book histograms!";
1033 std::stringstream
ss;
1034 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
1035 <<
" CommissioningTask object already exists for key 0x" << std::hex << std::setfill(
'0') << std::setw(8)
1036 << fed_key.key() <<
std::dec <<
" in directory " <<
dir.str()
1037 <<
" Unable to create CommissioningTask object!";
1044 <<
" Created " << booked <<
" CommissioningTask objects and booked histograms";
1054 if (itask->second) {
1055 delete itask->second;
1067 VecOfVecOfTasks::iterator ifed =
tasks_.begin();
1068 for (; ifed !=
tasks_.end(); ifed++) {
1069 VecOfTasks::iterator ichan = ifed->begin();
1070 for (; ichan != ifed->end(); ichan++) {
1076 ifed->resize(96,
nullptr);
1092 gethostname(hn,
sizeof(hn));
1094 he = gethostbyname(hn);
1101 host_ip =
std::string(inet_ntoa(*(
struct in_addr*)(
he->h_addr)));
1103 host_name =
"unknown.cern.ch";
1104 host_ip =
"255.255.255.255";
1109 std::stringstream ip;
1111 while (
pos != std::string::npos) {
1113 if (
tmp != std::string::npos) {
1114 ip << std::setw(3) << std::setfill(
'0') << host_ip.substr(
pos,
tmp -
pos) <<
".";
1117 ip << std::setw(3) << std::setfill(
'0') << host_ip.substr(
pos);
1118 pos = std::string::npos;
1123 pid_t pid = getpid();
1127 dir << std::setw(8) << std::setfill(
'0') <<
run_number <<
"_";
1129 dir << ip.str() <<
"_" << std::setw(5) << std::setfill(
'0') << pid;