1111
1212#include " TOFBase/CalibTOFapi.h"
1313#include < fairlogger/Logger.h> // for LOG
14+ #include < TH2F.h>
1415
1516using namespace o2 ::tof;
1617
1718ClassImp (o2::tof::CalibTOFapi);
1819
20+ o2::tof::Diagnostic CalibTOFapi::doDRMerrCalibFromQCHisto (const TH2F* histo, const char * file_output_name)
21+ {
22+ // this is a method which translate the QC output in qc/TOF/MO/TaskRaw/DRMCounter (TH2F) into a Diagnotic object for DRM (patter(crate, error), frequency)
23+ // note that, differently from TRM errors, DRM ones are not stored in CTF by design (since very rare, as expected). Such an info is available only at the level of raw sync QC
24+ o2::tof::Diagnostic drmDia;
25+
26+ for (int j = 1 ; j <= Geo::kNCrate ; j++) {
27+ drmDia.fillDRM (j - 1 , histo->GetBinContent (1 , j));
28+ for (int i = 2 ; i <= histo->GetXaxis ()->GetNbins (); i++) {
29+ if (histo->GetBinContent (1 , j)) {
30+ if (histo->GetBinContent (i, j) > 0 ) {
31+ drmDia.fillDRMerror (j - 1 , i - 1 , histo->GetBinContent (i, j));
32+ }
33+ }
34+ }
35+ }
36+
37+ TFile* fo = new TFile (file_output_name, " RECREATE" );
38+ fo->WriteObjectAny (&drmDia, drmDia.Class_Name (), " ccdb_object" );
39+ fo->Close ();
40+ LOG (debug) << " DRM error ccdb object created in " << file_output_name << " with this content" ;
41+ drmDia.print (true );
42+
43+ return drmDia;
44+ }
45+
46+ // ______________________________________________________________________
47+
1948void CalibTOFapi::resetDia ()
2049{
2150 memset (mEmptyCrateProb , 0 ., Geo::kNCrate * 4 );
@@ -38,7 +67,7 @@ void CalibTOFapi::readActiveMap()
3867{
3968 auto & mgr = CcdbManager::instance ();
4069 long timems = long (mTimeStamp ) * 1000 ;
41- LOG (info ) << " TOF get active map with timestamp (ms) = " << timems;
70+ LOG (debug ) << " TOF get active map with timestamp (ms) = " << timems;
4271 auto fee = mgr.getForTimeStamp <TOFFEElightInfo>(" TOF/Calib/FEELIGHT" , timems);
4372 loadActiveMap (fee);
4473}
@@ -116,11 +145,23 @@ void CalibTOFapi::readDiagnosticFrequencies()
116145{
117146 auto & mgr = CcdbManager::instance ();
118147 long timems = long (mTimeStamp ) * 1000 ;
119- LOG (info) << " TOF get Diagnostics with timestamp (ms) = " << timems;
148+ LOG (info) << " TOF get TRM Diagnostics with timestamp (ms) = " << timems;
120149 mDiaFreq = mgr.getForTimeStamp <Diagnostic>(" TOF/Calib/Diagnostic" , timems);
121150
122151 loadDiagnosticFrequencies ();
123152}
153+
154+ // ______________________________________________________________________
155+
156+ void CalibTOFapi::readDiagnosticDRMFrequencies ()
157+ {
158+ auto & mgr = CcdbManager::instance ();
159+ long timems = long (mTimeStamp ) * 1000 ;
160+ LOG (info) << " TOF get DRM Diagnostics with timestamp (ms) = " << timems;
161+ mDiaFreq = mgr.getForTimeStamp <Diagnostic>(" TOF/Calib/TRMerrors" , timems);
162+
163+ loadDiagnosticDRMFrequencies ();
164+ }
124165// ______________________________________________________________________
125166
126167void CalibTOFapi::loadDiagnosticFrequencies ()
@@ -210,6 +251,37 @@ void CalibTOFapi::loadDiagnosticFrequencies()
210251
211252// ______________________________________________________________________
212253
254+ void CalibTOFapi::loadDiagnosticDRMFrequencies ()
255+ {
256+ mDiaDRMFreq ->print ();
257+
258+ for (int ic = 0 ; ic < Geo::kNCrate ; ic++) { // loop over crates
259+ float DRMcounters = mDiaDRMFreq ->getFrequencyDRM (ic);
260+
261+ if (DRMcounters < 1 ) {
262+ for (int ie = 0 ; ie < N_DRM_ERRORS; ie++) {
263+ mErrorInDRM [ic][ie] = 0 .;
264+ }
265+ continue ;
266+ }
267+
268+ for (int ie = 0 ; ie < N_DRM_ERRORS; ie++) { // loop over error types
269+ int ie_shifted = ie + DRM_ERRINDEX_SHIFT;
270+
271+ float frequency = mDiaDRMFreq ->getFrequencyDRMerror (ic, ie_shifted) * 1 . / DRMcounters; // error frequency
272+ if (frequency > 1 ) {
273+ frequency = 1 .;
274+ }
275+ if (frequency > 1E-6 ) {
276+ LOG (debug) << " DRMmap: Crate = " << ic << " - error = " << ie << " - frequency = " << frequency;
277+ }
278+ mErrorInDRM [ic][ie] = frequency;
279+ }
280+ }
281+ }
282+
283+ // ______________________________________________________________________
284+
213285void CalibTOFapi::writeLHCphase (LhcPhase* phase, std::map<std::string, std::string> metadataLHCphase, uint64_t minTimeStamp, uint64_t maxTimeStamp)
214286{
215287
@@ -330,6 +402,17 @@ void CalibTOFapi::resetTRMErrors()
330402
331403// ______________________________________________________________________
332404
405+ void CalibTOFapi::resetDRMErrors ()
406+ {
407+ for (auto index : mFillErrDRMChannel ) {
408+ mIsErrorDRMCh [index] = false ;
409+ }
410+
411+ mFillErrDRMChannel .clear ();
412+ }
413+
414+ // ______________________________________________________________________
415+
333416void CalibTOFapi::processError (int crate, int trm, int mask)
334417{
335418 if (checkTRMPolicy (mask)) { // check the policy of TRM -> true=good TRM
@@ -348,14 +431,58 @@ void CalibTOFapi::processError(int crate, int trm, int mask)
348431
349432// ______________________________________________________________________
350433
434+ void CalibTOFapi::processErrorDRM (int crate, int codeErr)
435+ {
436+ int mask = 1 << codeErr;
437+
438+ if (checkDRMPolicy (mask)) {
439+ return ;
440+ }
441+
442+ LOG (debug) << " DRMmask: crate = " << crate << " - mask = " << mask << " - critical mask = " << mDRMCriticalErrorMask ;
443+
444+ for (int trm = 3 ; trm < 13 ; trm++) {
445+ int ech = (crate << 12 ) + ((trm - 3 ) << 8 );
446+ for (int i = ech; i < ech + 256 ; i++) {
447+ int channel = Geo::getCHFromECH (i);
448+ if (channel == -1 || mIsErrorDRMCh [channel] == true ) {
449+ continue ;
450+ }
451+
452+ mIsErrorDRMCh [channel] = true ;
453+ mFillErrDRMChannel .push_back (channel);
454+ }
455+ }
456+ }
457+
458+ // ______________________________________________________________________
459+
351460bool CalibTOFapi::checkTRMPolicy (int mask) const
352461{
353462 return false ;
354463}
355464
356465// ______________________________________________________________________
357466
467+ bool CalibTOFapi::checkDRMPolicy (int mask) const
468+ {
469+ return !(mDRMCriticalErrorMask & mask);
470+ }
471+
472+ // ______________________________________________________________________
473+
358474bool CalibTOFapi::isChannelError (int channel) const
359475{
360476 return mIsErrorCh [channel];
361477}
478+
479+ // ______________________________________________________________________
480+
481+ bool CalibTOFapi::isChannelDRMError (int channel) const
482+ {
483+ if (mIsErrorDRMCh [channel]) {
484+ int detId[5 ];
485+ o2::tof::Geo::getVolumeIndices (channel, detId);
486+ }
487+ return mIsErrorDRMCh [channel];
488+ }
0 commit comments