39 #include <sys/types.h>
43 #include <arpa/inet.h>
46 #include <sys/socket.h>
47 #include <sys/unistd.h>
58 inputModuleLabel_(
pset.getParameter<
std::
string>(
"InputModuleLabel")),
59 inputModuleLabelAlt_(
pset.existsAs<
std::
string>(
"InputModuleLabelAlt")
62 inputModuleLabelSummary_(
pset.getParameter<
std::
string>(
"SummaryInputModuleLabel")),
71 taskConfigurable_(
pset.getUntrackedParameter<
std::
string>(
"CommissioningTask",
"UNDEFINED")),
77 updateFreq_(
pset.getUntrackedParameter<
int>(
"HistoUpdateFreq", 1)),
79 view_(
pset.getUntrackedParameter<
std::
string>(
"View",
"Default")),
96 <<
" Constructing object...";
98 tasks_.resize(1024,
VecOfTasks(96, static_cast<CommissioningTask*>(
nullptr)));
105 <<
" Destructing object...";
112 std::stringstream
ss;
114 ss <<
"[SiStripCommissioningSource::" <<
method <<
"]" << std::endl;
116 ss <<
"[SiStripCommissioningSource]" << std::endl;
118 ss <<
" NULL pointer to DQMStore";
132 <<
" Configuring..." << std::endl;
138 <<
" DQMStore service: " <<
dqm_;
143 std::stringstream
dir(
"");
152 <<
"Initialized FED cabling. Number of FEDs is " <<
fedCabling_->
fedIds().size();
155 std::stringstream
ss;
156 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
157 <<
" Empty std::vector returned by FEC cabling object!"
158 <<
" Check if database connection failed...";
178 <<
" Halting..." << std::endl;
184 itask->second->updateHistograms();
189 for (uint16_t partition = 0; partition < 4; ++partition) {
190 tasks_[0][partition]->updateHistograms();
193 tasks_[0][0]->updateHistograms();
201 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
202 if (!iconn->isConnected()) {
205 fed_id = iconn->fedId();
206 fed_ch = iconn->fedCh();
207 if (
tasks_[fed_id][fed_ch]) {
208 tasks_[fed_id][fed_ch]->updateHistograms();
209 delete tasks_[fed_id][fed_ch];
218 if (
filename_.find(
".root", 0) == std::string::npos) {
227 if (std::getenv(scratch.c_str()) !=
nullptr) {
228 dir = std::getenv(scratch.c_str());
232 std::stringstream
ss;
253 <<
" NULL value for RunNumber! No root file saved!";
257 <<
" NULL value for filename! No root file saved!";
261 <<
" Saved all histograms to file \"" <<
ss.str() <<
"\"";
293 <<
" Unknown/undefined RunType and NULL parameter values!"
294 <<
" It may be that the 'trigger FED' object was not found!";
302 run_ =
event.id().run();
308 std::stringstream
ss;
309 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
310 <<
" The last " <<
updateFreq_ <<
" events were processed at a rate of ";
348 std::stringstream
ss;
349 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
350 <<
" Requested DAQ_SCOPE_MODE but unknown FED"
351 <<
" readout mode retrieved from SiStripEventSummary: "
366 std::stringstream
ss;
367 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
369 <<
" Unable to establish FED readout mode and retrieve digi container!"
370 <<
" Check if SiStripEventSummary object is found/present in Event";
377 std::stringstream
ss;
378 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" << std::endl
379 <<
" NULL pointer to DetSetVector!" << std::endl
380 <<
" Unable to fill histograms!";
386 std::stringstream
ss;
387 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" << std::endl
388 <<
" NULL pointer to DetSetVector!" << std::endl
389 <<
" Unable to fill histograms!";
395 std::stringstream
ss;
396 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" << std::endl
397 <<
" NULL pointer to DetSetVector!" << std::endl
398 <<
" Unable to fill histograms!";
416 uint16_t lld_channel = (
summary->deviceId() & 0x3) + 1;
423 uint32_t fec_key = key_object.
key();
424 std::stringstream sss;
425 sss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
426 <<
" Found DcuId 0x" << std::hex << std::setw(8) << std::setfill(
'0') <<
summary->dcuId() <<
std::dec
427 <<
" with Crate/FEC/Ring/CCU/Module/LLD: " << module.
key().
fecCrate() <<
"/" << module.
key().
fecSlot() <<
"/"
435 std::stringstream
ss;
436 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
437 <<
" DcuId 0x" << std::hex << std::setw(8) << std::setfill(
'0') <<
summary->dcuId() <<
std::dec
438 <<
" in 'DAQ register' field not found in cabling map!"
439 <<
" (NULL values returned for FEC path)";
452 std::map<uint16_t, float> medians;
454 std::map<uint16_t, float> medians1;
458 for (uint16_t ichan = 0; ichan < 96; ichan++) {
462 std::vector<edm::DetSet<SiStripRawDigi> >::const_iterator digis = raw.
find(fed_key);
463 if (digis != raw.
end()) {
464 if (digis->data.empty()) {
469 for (uint16_t idigi = 0; idigi < digis->data.size(); idigi++) {
470 ave.add(static_cast<uint32_t>(digis->data[idigi].adc()));
474 medians[ichan] =
params.median_;
475 medians1[ichan] = digis->data[0].adc();
482 std::map<uint16_t, float>::const_iterator
ii = medians.begin();
483 for (;
ii != medians.end();
ii++) {
489 std::stringstream
ss;
490 ss <<
"FED Averages:" << std::endl
491 <<
" nChans: " << medians.size() << std::endl
492 <<
" num/mean/median/rms/max/min: " <<
tmp.num_ <<
"/" <<
tmp.mean_ <<
"/" <<
tmp.median_ <<
"/" <<
tmp.rms_
493 <<
"/" <<
tmp.max_ <<
"/" <<
tmp.min_ << std::endl;
498 std::map<uint16_t, float>::const_iterator
jj = medians.begin();
499 for (;
jj != medians.end();
jj++) {
500 if (
jj->second <
tmp.median_ +
tmp.rms_) {
501 truncated.add(
jj->second);
507 std::stringstream ss1;
508 ss1 <<
"Truncated Averages:" << std::endl
509 <<
" nChans: " << medians.size() << std::endl
510 <<
" num/mean/median/rms/max/min: " <<
params.num_ <<
"/" <<
params.mean_ <<
"/" <<
params.median_ <<
"/"
515 std::stringstream ss2;
516 std::stringstream ss3;
518 std::map<uint16_t, float>::const_iterator ichan = medians.begin();
519 for (; ichan != medians.end(); ichan++) {
520 if (ichan->second > 200.) {
521 LogTrace(
mlTest_) <<
"TEST FOUND SIGNAL HIGH: " << *ifed <<
" " << ichan->first <<
" " << ichan->second;
522 channels[ichan->first] = ichan->second;
525 << ichan->second <<
" ";
527 << medians1[ichan->first] <<
" ";
540 std::stringstream
ss;
541 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
542 <<
" Filled histogram for '" <<
cablingTasks_[fec_key]->myName() <<
"' object with FecKey: 0x" << std::hex
543 << std::setfill(
'0') << std::setw(8) << fec_key <<
std::dec
544 <<
" and Crate/FEC/ring/CCU/module/LLDchan: " <<
path.fecCrate() <<
"/" <<
path.fecSlot() <<
"/"
545 <<
path.fecRing() <<
"/" <<
path.ccuAddr() <<
"/" <<
path.ccuChan() <<
"/" <<
path.channel();
550 std::stringstream
ss;
551 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
552 <<
" Unable to find CommissioningTask object with FecKey: 0x" << std::hex << std::setfill(
'0') << std::setw(8)
553 << fec_key <<
std::dec <<
" and Crate/FEC/ring/CCU/module/LLDchan: " <<
path.fecCrate() <<
"/"
554 <<
path.fecSlot() <<
"/" <<
path.fecRing() <<
"/" <<
path.ccuAddr() <<
"/" <<
path.ccuChan() <<
"/"
569 std::vector<uint16_t> stripOnClusters;
574 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
578 if (!iconn->isConnected()) {
587 std::vector<edm::DetSet<SiStripRawDigi> >::const_iterator digis = raw.
find(fed_key);
590 std::vector<edm::DetSet<SiStripRawDigi> >::const_iterator digisAlt;
591 if (not rawAlt.
empty()) {
592 digisAlt = rawAlt.
find(fed_key);
593 if (digisAlt == rawAlt.
end())
598 stripOnClusters.clear();
602 if (DSViter->id() != iconn->detId())
606 if (DSiter->firstStrip() >= iconn->apvPairNumber() * 256 and
607 DSiter->firstStrip() < (1 + iconn->apvPairNumber()) * 256) {
608 for (
size_t istrip = 0; istrip < DSiter->amplitudes().size(); istrip++) {
609 stripOnClusters.push_back(DSiter->firstStrip() + istrip - iconn->apvPairNumber() * 256);
616 if (digis != raw.
end()) {
619 if (
tasks_[0][iconn->fecCrate() - 1]) {
620 tasks_[0][iconn->fecCrate() - 1]->fillHistograms(*
summary, *digis);
622 std::stringstream
ss;
623 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
624 <<
" Unable to find CommissioningTask for FEC crate " << iconn->fecCrate()
625 <<
". Unable to fill histograms!";
632 std::stringstream
ss;
633 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
634 <<
" Unable to find global CommissioningTask for FineDelay. Unable to fill histograms!";
638 if (
tasks_[iconn->fedId()][iconn->fedCh()]) {
639 if (not rawAlt.
empty()
or digisAlt == rawAlt.
end())
640 tasks_[iconn->fedId()][iconn->fedCh()]->fillHistograms(*
summary, *digis);
642 if (stripOnClusters.empty())
643 tasks_[iconn->fedId()][iconn->fedCh()]->fillHistograms(*
summary, *digis, *digisAlt);
645 tasks_[iconn->fedId()][iconn->fedCh()]->fillHistograms(*
summary, *digis, *digisAlt, stripOnClusters);
649 std::stringstream
ss;
650 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
651 <<
" Unable to find CommissioningTask object with FED key " << std::hex << std::setfill(
'0')
652 << std::setw(8) << fed_key <<
std::dec <<
" and FED id/ch " << iconn->fedId() <<
"/" << iconn->fedCh()
653 <<
" Unable to fill histograms!";
661 std::stringstream
ss;
662 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
663 <<
" Unable to find any DetSet containing digis for FED key " << std::hex << std::setfill(
'0')
664 << std::setw(8) << fed_key <<
std::dec <<
" and FED id/ch " << iconn->fedId() <<
"/" << iconn->fedCh();
678 <<
" NULL run number!";
684 std::stringstream
run;
698 std::stringstream
ss;
699 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
704 std::stringstream
ss;
705 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
706 <<
" NULL pointer to SiStripEventSummary!"
707 <<
" Check SiStripEventSummary is found/present in Event";
714 std::stringstream
ss;
715 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
719 task_ = configurable;
729 std::stringstream
ss;
730 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
731 <<
" Unexpected CommissioningTask found (" << static_cast<uint16_t>(
task_) <<
") \""
733 <<
" Unexpected value found in SiStripEventSummary and/or cfg file"
734 <<
" If SiStripEventSummary is not present in Event,"
735 <<
" check 'CommissioningTask' configurable in cfg file";
739 std::stringstream
ss;
740 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
752 std::stringstream
ss;
753 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
758 <<
" Creating CommissioningTask objects and booking histograms...";
765 <<
" Finished booking histograms!";
774 for (std::vector<SiStripFecCrate>::const_iterator icrate =
fecCabling_->
crates().begin();
777 for (std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++) {
778 for (std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end();
780 for (std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end();
782 for (std::vector<SiStripModule>::const_iterator imodule = iccu->modules().begin();
783 imodule != iccu->modules().end();
787 icrate->fecCrate(), ifec->fecSlot(), iring->fecRing(), iccu->ccuAddr(), imodule->ccuChan());
790 if (!
path.isValid()) {
799 for (uint16_t ipair = 0; ipair < imodule->nApvPairs(); ipair++) {
813 imodule->nApvPairs());
821 imodule->lldChannel(ipair))
827 <<
" Unexpected NULL value for FEC key!";
837 <<
" Undefined CommissioningTask"
838 <<
" Unable to create FedCablingTask object!";
841 <<
" Unknown CommissioningTask"
842 <<
" Unable to create FedCablingTask object!";
845 <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
847 <<
" Unable to create FedCablingTask object!";
856 std::stringstream
ss;
857 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
858 <<
" Booking histograms for '" <<
cablingTasks_[
key]->myName() <<
"' object with key 0x"
859 << std::hex << std::setfill(
'0') << std::setw(8) <<
key <<
std::dec <<
" in directory \"" <<
dir
863 std::stringstream
ss;
864 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
865 <<
" NULL pointer to CommissioningTask for key 0x" << std::hex << std::setfill(
'0')
866 << std::setw(8) <<
key <<
std::dec <<
" in directory " <<
dir <<
" Unable to book histograms!";
870 std::stringstream
ss;
871 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
872 <<
" Unable to find CommissioningTask for key 0x" << std::hex << std::setfill(
'0') << std::setw(8)
873 <<
key <<
std::dec <<
" in directory " <<
dir <<
" Unable to book histograms!";
878 std::stringstream
ss;
879 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
880 <<
" CommissioningTask object already exists for key 0x" << std::hex << std::setfill(
'0')
882 <<
" Unable to create FedCablingTask object!";
894 <<
" Created " << booked <<
" CommissioningTask objects and booked histograms";
904 for (uint16_t partition = 0; partition < 4; ++partition) {
911 tasks_[0][partition]->bookHistograms();
920 tasks_[0][0]->bookHistograms();
930 for (
auto iconn = conns.begin(); iconn != conns.end(); ++iconn) {
933 iconn->fecCrate(), iconn->fecSlot(), iconn->fecRing(), iconn->ccuAddr(), iconn->ccuChan());
937 if (!iconn->isConnected()) {
945 std::stringstream
dir;
947 if (
view_ ==
"Default") {
949 dir << fed_key.path();
951 dir << fec_key.path();
953 }
else if (
view_ ==
"FecView") {
954 dir << fec_key.path();
955 }
else if (
view_ ==
"FedView") {
956 dir << fed_key.path();
957 }
else if (
view_ ==
"DetView") {
962 <<
" Invalid view " <<
view_ << std::endl
963 <<
" Histograms will end up all in the top directory.";
968 if (!
tasks_[iconn->fedId()][iconn->fedCh()]) {
990 tasks_[iconn->fedId()][iconn->fedCh()] =
993 tasks_[iconn->fedId()][iconn->fedCh()] =
997 <<
" Undefined CommissioningTask"
998 <<
" Unable to create CommissioningTask object!";
1001 <<
" Unknown CommissioningTask"
1002 <<
" Unable to create CommissioningTask object!";
1006 if (
tasks_[iconn->fedId()][iconn->fedCh()]) {
1007 tasks_[iconn->fedId()][iconn->fedCh()]->eventSetup(&
setup);
1011 tasks_[iconn->fedId()][iconn->fedCh()]->bookHistograms();
1014 static_cast<CalibrationScanTask*>(
tasks_[iconn->fedId()][iconn->fedCh()])->setCurrentFolder(
dir.str());
1016 static_cast<CalibrationTask*>(
tasks_[iconn->fedId()][iconn->fedCh()])->setCurrentFolder(
dir.str());
1021 std::stringstream
ss;
1022 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
1023 <<
" NULL pointer to CommissioningTask for key 0x" << std::hex << std::setfill(
'0') << std::setw(8)
1024 << fed_key.key() <<
std::dec <<
" in directory " <<
dir.str() <<
" Unable to book histograms!";
1028 std::stringstream
ss;
1029 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]"
1030 <<
" CommissioningTask object already exists for key 0x" << std::hex << std::setfill(
'0') << std::setw(8)
1031 << fed_key.key() <<
std::dec <<
" in directory " <<
dir.str()
1032 <<
" Unable to create CommissioningTask object!";
1039 <<
" Created " << booked <<
" CommissioningTask objects and booked histograms";
1049 if (itask->second) {
1050 delete itask->second;
1062 VecOfVecOfTasks::iterator ifed =
tasks_.begin();
1063 for (; ifed !=
tasks_.end(); ifed++) {
1064 VecOfTasks::iterator ichan = ifed->begin();
1065 for (; ichan != ifed->end(); ichan++) {
1071 ifed->resize(96,
nullptr);
1087 gethostname(hn,
sizeof(hn));
1089 he = gethostbyname(hn);
1096 host_ip =
std::string(inet_ntoa(*(
struct in_addr*)(
he->h_addr)));
1098 host_name =
"unknown.cern.ch";
1099 host_ip =
"255.255.255.255";
1104 std::stringstream ip;
1106 while (
pos != std::string::npos) {
1108 if (
tmp != std::string::npos) {
1109 ip << std::setw(3) << std::setfill(
'0') << host_ip.substr(
pos,
tmp -
pos) <<
".";
1112 ip << std::setw(3) << std::setfill(
'0') << host_ip.substr(
pos);
1113 pos = std::string::npos;
1118 pid_t pid = getpid();
1122 dir << std::setw(8) << std::setfill(
'0') <<
run_number <<
"_";
1124 dir << ip.str() <<
"_" << std::setw(5) << std::setfill(
'0') << pid;