34 #include <boost/cstdint.hpp> 40 #include <sys/types.h> 44 #include <arpa/inet.h> 45 #include <sys/unistd.h> 46 #include <sys/socket.h> 59 inputModuleLabel_( pset.getParameter<
std::
string>(
"InputModuleLabel" ) ),
60 inputModuleLabelAlt_(pset.existsAs<
std::
string>(
"InputModuleLabelAlt")?pset.getParameter<
std::
string>(
"InputModuleLabelAlt" ):
""),
61 inputModuleLabelSummary_( pset.getParameter<
std::
string>(
"SummaryInputModuleLabel" ) ),
64 partitionName_(pset.existsAs<
std::
string>(
"PartitionName") ? pset.getParameter<
std::
string>(
"PartitionName") :
""),
66 isSpy_(pset.existsAs<
bool>(
"isSpy")?pset.getParameter<
bool>(
"isSpy"):
false),
67 taskConfigurable_( pset.getUntrackedParameter<
std::
string>(
"CommissioningTask",
"UNDEFINED") ),
73 updateFreq_( pset.getUntrackedParameter<
int>(
"HistoUpdateFreq",1) ),
75 view_( pset.getUntrackedParameter<
std::
string>(
"View",
"Default") ),
88 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 89 <<
" Constructing object...";
91 tasks_.resize( 1024,
VecOfTasks(96,static_cast<CommissioningTask*>(
nullptr)) );
98 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 99 <<
" Destructing object...";
106 std::stringstream ss;
107 if ( !method.empty() ) { ss <<
"[SiStripCommissioningSource::" << method <<
"]" << std::endl; }
108 else { ss <<
"[SiStripCommissioningSource]" << std::endl; }
109 ss <<
" NULL pointer to DQMStore";
112 }
else {
return dqm_; }
121 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 122 <<
" Configuring..." << std::endl;
128 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 129 <<
" DQMStore service: " 132 dqm()->setVerbose(0);
136 std::stringstream
dir(
"");
145 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 146 <<
"Initialized FED cabling. Number of FEDs is " <<
fedCabling_->
fedIds().size();
149 std::stringstream ss;
150 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 151 <<
" Empty std::vector returned by FEC cabling object!" 152 <<
" Check if database connection failed...";
173 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 174 <<
" Halting..." << std::endl;
180 if ( itask->second ) { itask->second->updateHistograms(); }
185 for (uint16_t partition = 0; partition < 4; ++partition) {
186 tasks_[0][partition]->updateHistograms();
189 tasks_[0][0]->updateHistograms();
197 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++ ) {
198 if ( !iconn->isConnected() ) {
continue; }
199 fed_id = iconn->fedId();
200 fed_ch = iconn->fedCh();
201 if (
tasks_[fed_id][fed_ch] ) {
202 tasks_[fed_id][fed_ch]->updateHistograms();
203 delete tasks_[fed_id][fed_ch];
217 if ( getenv(scratch.c_str()) !=
nullptr ) {
218 dir = getenv(scratch.c_str());
222 std::stringstream ss;
223 if ( !dir.empty() ) { ss << dir <<
"/"; }
224 else { ss <<
"/tmp/"; }
235 if (
run_ != 0 ) {
dqm()->save( ss.str() ); }
238 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 239 <<
" NULL value for RunNumber! No root file saved!";
243 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 244 <<
" NULL value for filename! No root file saved!";
248 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 249 <<
" Saved all histograms to file \"" 279 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 280 <<
" Unknown/undefined RunType and NULL parameter values!" 281 <<
" It may be that the 'trigger FED' object was not found!";
289 run_ =
event.id().run();
295 std::stringstream ss;
296 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 298 <<
" events were processed at a rate of ";
299 if (
time(
nullptr) ==
time_ ) { ss <<
">" << updateFreq_ <<
" Hz"; }
300 else { ss << (updateFreq_/(
time(
nullptr)-
time_)) <<
" Hz"; }
321 std::stringstream ss;
322 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 323 <<
" Requested DAQ_SCOPE_MODE but unknown FED" 324 <<
" readout mode retrieved from SiStripEventSummary: " 351 std::stringstream ss;
352 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 353 <<
" Unknown CommissioningTask: " 355 <<
" Unable to establish FED readout mode and retrieve digi container!" 356 <<
" Check if SiStripEventSummary object is found/present in Event";
362 if ( &(*raw) ==
nullptr ) {
363 std::stringstream ss;
364 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" << std::endl
365 <<
" NULL pointer to DetSetVector!" << std::endl
366 <<
" Unable to fill histograms!";
371 if(
isSpy_ and &(*rawAlt) ==
nullptr){
372 std::stringstream ss;
373 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" << std::endl
374 <<
" NULL pointer to DetSetVector!" << std::endl
375 <<
" Unable to fill histograms!";
392 uint16_t lld_channel = ( summary->
deviceId() & 0x3 ) + 1;
399 uint32_t fec_key = key_object.
key();
400 std::stringstream sss;
401 sss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 403 << std::hex << std::setw(8) << std::setfill(
'0') << summary->
dcuId() <<
std::dec 404 <<
" with Crate/FEC/Ring/CCU/Module/LLD: " 417 std::stringstream ss;
418 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 420 << std::hex << std::setw(8) << std::setfill(
'0') << summary->
dcuId() <<
std::dec 421 <<
" in 'DAQ register' field not found in cabling map!" 422 <<
" (NULL values returned for FEC path)";
434 std::map<uint16_t,float> medians; medians.clear();
435 std::map<uint16_t,float> medians1; medians1.clear();
438 for ( uint16_t ichan = 0; ichan < 96; ichan++ ) {
448 std::vector< edm::DetSet<SiStripRawDigi> >::const_iterator digis = raw.
find( fed_key );
449 if ( digis != raw.
end() ) {
450 if ( digis->data.empty() ) {
continue; }
461 for ( uint16_t idigi = 0; idigi < digis->data.size(); idigi++ ) {
462 ave.add( static_cast<uint32_t>(digis->data[idigi].adc()) );
466 medians[ichan] = params.
median_;
467 medians1[ichan] = digis->data[0].adc();
492 std::map<uint16_t,float>::const_iterator
ii = medians.begin();
493 for ( ; ii != medians.end(); ii++ ) { average.add( ii->second ); }
511 std::map<uint16_t,float>::const_iterator
jj = medians.begin();
512 for ( ; jj != medians.end(); jj++ ) {
514 truncated.add( jj->second );
518 truncated.calc(params);
533 std::stringstream ss2;
534 std::stringstream ss3;
537 std::map<uint16_t,float> channels;
538 std::map<uint16_t,float>::const_iterator ichan = medians.begin();
539 for ( ; ichan != medians.end(); ichan++ ) {
546 if ( ichan->second > 200. ) {
547 LogTrace(
mlTest_) <<
"TEST FOUND SIGNAL HIGH: " << *ifed <<
" " << ichan->first <<
" " << ichan->second;
548 channels[ichan->first] = ichan->second;
551 << ichan->second <<
" ";
553 << medians1[ichan->first] <<
" ";
581 if ( !channels.empty() ) {
582 cablingTasks_[fec_key]->fillHistograms( *summary, *ifed, channels );
584 std::stringstream ss;
585 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 586 <<
" Filled histogram for '" <<
cablingTasks_[fec_key]->myName()
587 <<
"' object with FecKey: 0x" 588 << std::hex << std::setfill(
'0') << std::setw(8) << fec_key <<
std::dec 589 <<
" and Crate/FEC/ring/CCU/module/LLDchan: " 600 std::stringstream ss;
601 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 602 <<
" Unable to find CommissioningTask object with FecKey: 0x" 603 << std::hex << std::setfill(
'0') << std::setw(8) << fec_key <<
std::dec 604 <<
" and Crate/FEC/ring/CCU/module/LLDchan: " 630 for (
auto iconn = conns.begin() ; iconn != conns.end(); iconn++ ) {
632 if ( !(iconn->fedId()) || iconn->fedId() >
sistrip::valid_ ) {
continue; }
633 if ( !iconn->isConnected() ) {
continue; }
641 std::vector< edm::DetSet<SiStripRawDigi> >::const_iterator digis = raw.
find( fed_key );
644 std::vector< edm::DetSet<SiStripRawDigi> >::const_iterator digisAlt;
645 if(rawAlt !=
nullptr and not (*rawAlt).
empty()){
646 digisAlt = (*rawAlt).find( fed_key );
647 if(digisAlt == (*rawAlt).end())
continue;
650 if ( digis != raw.
end() ) {
653 if (
tasks_[0][iconn->fecCrate()-1] ) {
654 tasks_[0][iconn->fecCrate()-1]->fillHistograms( *summary, *digis );
656 std::stringstream ss;
657 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 658 <<
" Unable to find CommissioningTask for FEC crate " 659 << iconn->fecCrate() <<
". Unable to fill histograms!";
664 tasks_[0][0]->fillHistograms( *summary, *digis );
666 std::stringstream ss;
667 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 668 <<
" Unable to find global CommissioningTask for FineDelay. Unable to fill histograms!";
673 if (
tasks_[iconn->fedId()][iconn->fedCh()] ) {
674 if(rawAlt ==
nullptr or digisAlt == (*rawAlt).end())
675 tasks_[iconn->fedId()][iconn->fedCh()]->fillHistograms( *summary, *digis );
677 tasks_[iconn->fedId()][iconn->fedCh()]->fillHistograms( *summary, *digis, *digisAlt);
679 std::stringstream ss;
680 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 681 <<
" Unable to find CommissioningTask object with FED key " 682 << std::hex << std::setfill(
'0') << std::setw(8) << fed_key <<
std::dec 684 << iconn->fedId() <<
"/" 686 <<
" Unable to fill histograms!";
695 std::stringstream ss;
696 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 697 <<
" Unable to find any DetSet containing digis for FED key " 698 << std::hex << std::setfill(
'0') << std::setw(8) << fed_key <<
std::dec 700 << iconn->fedId() <<
"/" 716 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 717 <<
" NULL run number!";
723 std::stringstream
run;
739 std::stringstream ss;
740 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 741 <<
" Identified CommissioningTask from EventSummary to be \"" 747 std::stringstream ss;
748 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 749 <<
" NULL pointer to SiStripEventSummary!" 750 <<
" Check SiStripEventSummary is found/present in Event";
758 std::stringstream ss;
759 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 760 <<
" Overriding CommissioningTask from EventSummary (\"" 762 <<
"\") with value retrieved from .cfg file (\"" 766 task_ = configurable;
777 std::stringstream ss;
778 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 779 <<
" Unexpected CommissioningTask found (" 780 <<
static_cast<uint16_t
>(
task_) <<
") \"" 782 <<
" Unexpected value found in SiStripEventSummary and/or cfg file" 783 <<
" If SiStripEventSummary is not present in Event," 784 <<
" check 'CommissioningTask' configurable in cfg file";
788 std::stringstream ss;
789 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 790 <<
" Identified CommissioningTask to be \"" 800 std::stringstream ss;
801 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 802 <<
" CommissioningTask: " 807 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 808 <<
" Creating CommissioningTask objects and booking histograms...";
812 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 813 <<
" Finished booking histograms!";
825 for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++ ) {
826 for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); iring++ ) {
827 for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); iccu++ ) {
828 for ( std::vector<SiStripModule>::const_iterator imodule = iccu->modules().begin(); imodule != iccu->modules().end(); imodule++ ) {
835 imodule->ccuChan() );
838 if ( !
path.isValid() ) {
continue; }
842 dqm()->setCurrentFolder( dir );
845 for ( uint16_t ipair = 0; ipair < imodule->nApvPairs(); ipair++ ) {
860 imodule->nApvPairs() );
868 imodule->lldChannel(ipair) ).
key();
873 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 874 <<
" Unexpected NULL value for FEC key!";
885 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 886 <<
" Undefined CommissioningTask" 887 <<
" Unable to create FedCablingTask object!";
890 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 891 <<
" Unknown CommissioningTask" 892 <<
" Unable to create FedCablingTask object!";
895 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 896 <<
" Unexpected CommissioningTask: " 898 <<
" Unable to create FedCablingTask object!";
914 std::stringstream ss;
915 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 916 <<
" NULL pointer to CommissioningTask for key 0x" 917 << std::hex << std::setfill(
'0') << std::setw(8) << key <<
std::dec 918 <<
" in directory " << dir
919 <<
" Unable to book histograms!";
923 std::stringstream ss;
924 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 925 <<
" Unable to find CommissioningTask for key 0x" 926 << std::hex << std::setfill(
'0') << std::setw(8) << key <<
std::dec 927 <<
" in directory " << dir
928 <<
" Unable to book histograms!";
933 std::stringstream ss;
934 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 935 <<
" CommissioningTask object already exists for key 0x" 936 << std::hex << std::setfill(
'0') << std::setw(8) << key <<
std::dec 937 <<
" in directory " << dir
938 <<
" Unable to create FedCablingTask object!";
950 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 951 <<
" Created " << booked
952 <<
" CommissioningTask objects and booked histograms";
965 for (uint16_t partition = 0; partition < 4; ++partition) {
968 tasks_[0][partition]->eventSetup( &setup );
969 tasks_[0][partition]->bookHistograms();
978 tasks_[0][0]->eventSetup( &setup );
979 tasks_[0][0]->bookHistograms();
992 for (
auto iconn = conns.begin() ; iconn != conns.end(); ++iconn ) {
1004 if ( !iconn->isConnected() ) {
continue; }
1010 std::stringstream
dir;
1012 if (
view_ ==
"Default") {
1014 dir << fed_key.path();
1016 dir << fec_key.path();
1018 }
else if (
view_ ==
"FecView") {
1019 dir << fec_key.path();
1020 }
else if (
view_ ==
"FedView") {
1021 dir << fed_key.path();
1022 }
else if (
view_ ==
"DetView") {
1029 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 1030 <<
" Invalid view " <<
view_ << std::endl
1031 <<
" Histograms will end up all in the top directory.";
1033 dqm()->setCurrentFolder( dir.str() );
1036 if ( !
tasks_[iconn->fedId()][iconn->fedCh()] ) {
1075 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 1076 <<
" Undefined CommissioningTask" 1077 <<
" Unable to create CommissioningTask object!";
1080 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 1081 <<
" Unknown CommissioningTask" 1082 <<
" Unable to create CommissioningTask object!";
1088 if (
tasks_[iconn->fedId()][iconn->fedCh()] ) {
1089 tasks_[iconn->fedId()][iconn->fedCh()]->eventSetup( &setup );
1092 tasks_[iconn->fedId()][iconn->fedCh()]->bookHistograms();
1103 std::stringstream ss;
1104 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 1105 <<
" NULL pointer to CommissioningTask for key 0x" 1106 << std::hex << std::setfill(
'0') << std::setw(8) << fed_key.key() <<
std::dec 1107 <<
" in directory " << dir.str()
1108 <<
" Unable to book histograms!";
1113 std::stringstream ss;
1114 ss <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 1115 <<
" CommissioningTask object already exists for key 0x" 1116 << std::hex << std::setfill(
'0') << std::setw(8) << fed_key.key() <<
std::dec 1117 <<
" in directory " << dir.str()
1118 <<
" Unable to create CommissioningTask object!";
1127 <<
"[SiStripCommissioningSource::" << __func__ <<
"]" 1128 <<
" Created " << booked
1129 <<
" CommissioningTask objects and booked histograms";
1137 if ( itask->second ) {
delete itask->second; }
1145 if (
tasks_.empty() ) {
return; }
1146 VecOfVecOfTasks::iterator ifed =
tasks_.begin();
1147 for ( ; ifed !=
tasks_.end(); ifed++ ) {
1148 VecOfTasks::iterator ichan = ifed->begin();
1149 for ( ; ichan != ifed->end(); ichan++ ) {
1150 if ( *ichan ) {
delete *ichan; *ichan =
nullptr; }
1152 ifed->resize(96,
nullptr);
1161 dqm()->removeContents();
1171 uint32_t run_number ) {
1175 gethostname( hn,
sizeof(hn) );
1177 he = gethostbyname(hn);
1184 host_ip =
std::string( inet_ntoa( *(
struct in_addr*)(he->h_addr) ) );
1186 host_name =
"unknown.cern.ch";
1187 host_ip =
"255.255.255.255";
1192 std::stringstream ip;
1194 while ( pos != std::string::npos ) {
1196 if ( tmp != std::string::npos ) {
1198 << std::setfill(
'0')
1199 << host_ip.substr( pos, tmp-pos )
1204 << std::setfill(
'0')
1205 << host_ip.substr( pos );
1206 pos = std::string::npos;
1211 pid_t
pid = getpid();
1216 << std::setfill(
'0')
1223 << std::setfill(
'0')
static const char runNumber_[]
Device and connection information at the level of a front-end module.
EventNumber_t event() const
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > digiReorderedToken_
void createCablingTasks()
iterator find(det_id_type id)
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > digiVirginRawToken_
const uint16_t & fecRing() const
void createTask(const SiStripEventSummary *const, const edm::EventSetup &)
A container class for generic run and event-related info, information required by the commissioning a...
const SiStripModule & module(const FedChannelConnection &conn) const
DQMStore *const dqm(std::string method="") const
const SiStripFecKey & key() const
static const char mlDqmSource_[]
SiStripCommissioningSource()=delete
void createTasks(sistrip::RunType, const edm::EventSetup &)
const std::vector< SiStripFecCrate > & crates() const
def setup(process, global_tag, zero_tesla=False)
const uint16_t & fecSlot() const
static const uint16_t valid_
static const char detectorView_[]
void analyze(const edm::Event &, const edm::EventSetup &) override
std::string inputModuleLabel_
void directory(std::stringstream &, uint32_t run_number=0)
const uint32_t & key() const
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
void beginRun(edm::Run const &, const edm::EventSetup &) override
static std::string runType(const sistrip::RunType &)
const sistrip::RunType & runType() const
std::vector< CommissioningTask * > VecOfTasks
Class containning control, module, detector and connection information, at the level of a FED channel...
std::string inputModuleLabelAlt_
FedsConstIterRange fedIds() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
static const char taskId_[]
void fillCablingHistos(const SiStripEventSummary *const, const edm::DetSetVector< SiStripRawDigi > &)
static const char dqmSourceFileName_[]
const uint32_t & dcuId() const
static const char mlTest_[]
SiStripFecCabling * fecCabling_
edm::ParameterSet parameters_
iterator end()
Return the off-the-end iterator.
std::string partitionName_
const uint16_t & fecCrate() const
const uint32_t & deviceId() const
const uint16_t & feUnit() const
T const * product() const
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > digiFineDelaySelectionToken_
const uint16_t & channel() const
~SiStripCommissioningSource() override
bool empty() const
Return true if we contain no DetSets.
const uint16_t & ccuAddr() const
static const uint16_t invalid_
std::pair< uint16_t, uint16_t > PairOfU16
std::string inputModuleLabelSummary_
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
const sistrip::FedReadoutMode & fedReadoutMode() const
std::vector< std::vector< double > > tmp
edm::EDGetTokenT< SiStripEventSummary > inputModuleSummaryToken_
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > digiScopeModeToken_
std::string taskConfigurable_
SiStripFedCabling * fedCabling_
const uint16_t & feChan() const
static const char root_[]
const uint16_t & ccuChan() const
T const * product() const
void fillHistos(const SiStripEventSummary *const, const edm::DetSetVector< SiStripRawDigi > &, const edm::DetSetVector< SiStripRawDigi > *=0)
static std::string fedReadoutMode(const sistrip::FedReadoutMode &)