CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DQM/DTMonitorModule/src/DTDataIntegrityTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file DTDataIntegrityTask.cc
00003  * 
00004  * $Date: 2011/06/10 13:23:26 $
00005  * $Revision: 1.74 $
00006  * \author M. Zanetti (INFN Padova), S. Bolognesi (INFN Torino), G. Cerminara (INFN Torino)
00007  *
00008  */
00009 
00010 #include <DQM/DTMonitorModule/interface/DTDataIntegrityTask.h>
00011 #include "FWCore/Framework/interface/Frameworkfwd.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "EventFilter/DTRawToDigi/interface/DTDataMonitorInterface.h"
00015 #include "EventFilter/DTRawToDigi/interface/DTControlData.h"
00016 #include "EventFilter/DTRawToDigi/interface/DTDDUWords.h"
00017 #include "DQMServices/Core/interface/DQMStore.h"
00018 #include "DQMServices/Core/interface/MonitorElement.h"
00019 #include "FWCore/ServiceRegistry/interface/Service.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
00022 #include "FWCore/Utilities/interface/Exception.h"
00023 
00024 #include <math.h>
00025 #include <fstream>
00026 #include <map>
00027 #include <string>
00028 #include <vector>
00029 
00030 using namespace std;
00031 using namespace edm;
00032 int FirstRos=0,nevents=0,n,m;
00033 const unsigned long long max_bx = 59793997824ULL;
00034 #include "ROSDebugUtility.h"
00035 
00036 DTDataIntegrityTask::DTDataIntegrityTask(const edm::ParameterSet& ps,edm::ActivityRegistry& reg) : nevents(0) , dbe(0) {
00037 
00038   // Register the methods that we want to schedule
00039   //   reg.watchPostEndJob(this,&DTDataIntegrityTask::postEndJob);
00040   reg.watchPostBeginJob(this,&DTDataIntegrityTask::postBeginJob);
00041   reg.watchPreProcessEvent(this,&DTDataIntegrityTask::preProcessEvent);
00042   
00043   LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00044     << "[DTDataIntegrityTask]: Constructor" <<endl;
00045 
00046   neventsDDU = 0;
00047   neventsROS25 = 0;
00048 
00049 //   //If you want info VS time histos
00050 //   doTimeHisto =  ps.getUntrackedParameter<bool>("doTimeHisto", false);
00051   // Plot quantities about SC
00052   getSCInfo = ps.getUntrackedParameter<bool>("getSCInfo", false);
00053 
00054   fedIntegrityFolder    = ps.getUntrackedParameter<string>("fedIntegrityFolder","DT/FEDIntegrity"); 
00055   
00056   string processingMode = ps.getUntrackedParameter<string>("processingMode","Online");
00057 
00058   // processing mode flag to select plots to be produced and basedirs CB vedi se farlo meglio...
00059   if (processingMode == "Online") {
00060     mode = 0;
00061   } else if(processingMode == "SM") {
00062     mode = 1;
00063   } else if (processingMode == "Offline") {
00064     mode = 2;
00065   } else if (processingMode == "HLT") {
00066     mode = 3;
00067   } else {
00068     throw cms::Exception("MissingParameter")
00069       << "[DTDataIntegrityTask]: processingMode :" << processingMode 
00070       << " invalid! Must be Online, SM, Offline or HLT !" << endl;
00071   }
00072 
00073 }
00074 
00075 
00076 
00077 DTDataIntegrityTask::~DTDataIntegrityTask() {
00078   LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00079     <<"[DTDataIntegrityTask]: Destructor. Analyzed "<< neventsDDU <<" events"<<endl;
00080 }
00081 
00082 
00083 
00084 /*
00085   Folder Structure:
00086   - One folder for each DDU, named FEDn
00087   - Inside each DDU folder the DDU histos and the ROSn folder
00088   - Inside each ROS folder the ROS histos and the ROBn folder
00089   - Inside each ROB folder one occupancy plot and the TimeBoxes
00090   with the chosen granularity (simply change the histo name)
00091 */
00092 
00093 void DTDataIntegrityTask::postEndJob(){
00094   LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00095     << "[DTDataIntegrityTask]: postEndJob called!" <<endl;
00096 
00097 //   if(doTimeHisto) TimeHistos("Event_word_vs_time");  
00098         
00099 }
00100 
00101 
00102 void DTDataIntegrityTask::bookHistos(const int fedMin, const int fedMax) {
00103 
00104   dbe->setCurrentFolder("DT/EventInfo/Counters");
00105   nEventMonitor = dbe->bookFloat("nProcessedEventsDataIntegrity");
00106 
00107   // Standard FED integrity histos
00108   dbe->setCurrentFolder(topFolder(true));
00109 
00110   int nFED = (fedMax - fedMin)+1;
00111 
00112   hFEDEntry = dbe->book1D("FEDEntries","# entries per DT FED",nFED,fedMin,fedMax+1);
00113   hFEDFatal = dbe->book1D("FEDFatal","# fatal errors DT FED",nFED,fedMin,fedMax+1);
00114   hFEDNonFatal = dbe->book1D("FEDNonFatal","# NON fatal errors DT FED",nFED,fedMin,fedMax+1);
00115 
00116 
00117   dbe->setCurrentFolder(topFolder(false));
00118   hTTSSummary = dbe->book2D("TTSSummary","Summary Status TTS",nFED,fedMin,fedMax+1,9,1,10);
00119   hTTSSummary->setAxisTitle("FED",1);
00120   hTTSSummary->setBinLabel(1,"ROS PAF",2);      
00121   hTTSSummary->setBinLabel(2,"DDU PAF",2);      
00122   hTTSSummary->setBinLabel(3,"ROS PAF",2);      
00123   hTTSSummary->setBinLabel(4,"DDU PAF",2);      
00124   hTTSSummary->setBinLabel(5,"DDU Full",2);     
00125   hTTSSummary->setBinLabel(6,"L1A Mism.",2);    
00126   hTTSSummary->setBinLabel(7,"ROS Error",2);    
00127   hTTSSummary->setBinLabel(8,"BX Mism.",2);     
00128   hTTSSummary->setBinLabel(9,"DDU Logic Err.",2);       
00129 
00130   // bookkeeping of the 
00131   
00132   hCorruptionSummary =  dbe->book2D("DataCorruptionSummary", "Data Corruption Sources",
00133                                    nFED,fedMin,fedMax+1, 8, 1, 9);
00134   hCorruptionSummary->setAxisTitle("FED",1);
00135   hCorruptionSummary->setBinLabel(1,"Miss Ch.",2);      
00136   hCorruptionSummary->setBinLabel(2,"ROS BX mism",2);   
00137   hCorruptionSummary->setBinLabel(3,"DDU BX mism",2);   
00138   hCorruptionSummary->setBinLabel(4,"ROS L1A mism",2);  
00139   hCorruptionSummary->setBinLabel(5,"Miss Payload",2);  
00140   hCorruptionSummary->setBinLabel(6,"FCRC bit",2);      
00141   hCorruptionSummary->setBinLabel(7,"Header check",2);  
00142   hCorruptionSummary->setBinLabel(8,"Triler Check",2);  
00143 
00144 }
00145 
00146 
00147 
00148 void DTDataIntegrityTask::bookHistos(string folder, DTROChainCoding code) {
00149 
00150   stringstream dduID_s; dduID_s << code.getDDU();
00151   stringstream rosID_s; rosID_s << code.getROS();
00152   stringstream robID_s; robID_s << code.getROB();
00153   int wheel = (code.getDDUID() - 770)%5 - 2;
00154   stringstream wheel_s; wheel_s << wheel;
00155 
00156   LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00157     << " Booking histos for FED: " << code.getDDU() << " ROS: " << code.getROS()
00158     << " ROB: " << code.getROB() << " folder: " << folder << endl;
00159 
00160   string histoType;
00161   string histoName;
00162   string histoTitle;
00163   MonitorElement* histo = 0;
00164 
00165   // DDU Histograms
00166   if (folder == "DDU") {
00167 
00168     dbe->setCurrentFolder(topFolder(false) + "FED" + dduID_s.str());
00169 
00170     histoType = "EventLenght";
00171     histoName = "FED" + dduID_s.str() + "_" + histoType;
00172     histoTitle = "Event Lenght (Bytes) FED " +  dduID_s.str();
00173     (dduHistos[histoType])[code.getDDUID()] = dbe->book1D(histoName,histoTitle,501,0,16032);
00174 
00175     if(mode > 2) return;
00176 
00177     histoType = "ROSStatus";
00178     histoName = "FED" + dduID_s.str() + "_" + histoType;
00179     (dduHistos[histoType])[code.getDDUID()] = dbe->book2D(histoName,histoName,12,0,12,12,0,12);
00180     histo = (dduHistos[histoType])[code.getDDUID()];
00181     histo->setBinLabel(1,"ch.enabled",1);       
00182     histo->setBinLabel(2,"timeout",1);  
00183     histo->setBinLabel(3,"ev.trailer lost",1);  
00184     histo->setBinLabel(4,"opt.fiber lost",1);   
00185     histo->setBinLabel(5,"tlk.prop.error",1);   
00186     histo->setBinLabel(6,"tlk.pattern error",1);        
00187     histo->setBinLabel(7,"tlk.sign.lost",1);    
00188     histo->setBinLabel(8,"error from ROS",1);
00189     histo->setBinLabel(9,"if ROS in events",1);
00190     histo->setBinLabel(10,"Miss. Evt.",1);
00191     histo->setBinLabel(11,"Evt. ID Mismatch",1);
00192     histo->setBinLabel(12,"BX Mismatch",1);
00193 
00194     histo->setBinLabel(1,"ROS 1",2);    
00195     histo->setBinLabel(2,"ROS 2",2);    
00196     histo->setBinLabel(3,"ROS 3",2);    
00197     histo->setBinLabel(4,"ROS 4",2);    
00198     histo->setBinLabel(5,"ROS 5",2);    
00199     histo->setBinLabel(6,"ROS 6",2);    
00200     histo->setBinLabel(7,"ROS 7",2);    
00201     histo->setBinLabel(8,"ROS 8",2);    
00202     histo->setBinLabel(9,"ROS 9",2);    
00203     histo->setBinLabel(10,"ROS 10",2);  
00204     histo->setBinLabel(11,"ROS 11",2);  
00205     histo->setBinLabel(12,"ROS 12",2);
00206 
00207     if(mode > 1) return;
00208 
00209     histoType = "TTSValues";
00210     histoName = "FED" + dduID_s.str() + "_" + histoType;
00211     (dduHistos[histoType])[code.getDDUID()] = dbe->book1D(histoName,histoName,8,0,8);
00212     histo = (dduHistos[histoType])[code.getDDUID()];
00213     histo->setBinLabel(1,"disconnected",1);     
00214     histo->setBinLabel(2,"warning overflow",1); 
00215     histo->setBinLabel(3,"out of synch",1);     
00216     histo->setBinLabel(4,"busy",1);     
00217     histo->setBinLabel(5,"ready",1);    
00218     histo->setBinLabel(6,"error",1);    
00219     histo->setBinLabel(7,"disconnected",1);     
00220     histo->setBinLabel(8,"unknown",1);  
00221     
00222     histoType = "EventType";
00223     histoName = "FED" + dduID_s.str() + "_" + histoType;
00224     (dduHistos[histoType])[code.getDDUID()] = dbe->book1D(histoName,histoName,2,1,3);
00225     histo = (dduHistos[histoType])[code.getDDUID()];
00226     histo->setBinLabel(1,"physics",1);  
00227     histo->setBinLabel(2,"calibration",1);      
00228   
00229     histoType = "ROSList";
00230     histoName = "FED" + dduID_s.str() + "_" + histoType;
00231     histoTitle = "# of ROS in the FED payload (FED" + dduID_s.str() + ")";
00232     (dduHistos[histoType])[code.getDDUID()] = dbe->book1D(histoName,histoTitle,13,0,13);
00233 
00234     histoType = "FIFOStatus";
00235     histoName = "FED" + dduID_s.str() + "_" + histoType;
00236     (dduHistos[histoType])[code.getDDUID()] = dbe->book2D(histoName,histoName,7,0,7,3,0,3);
00237     histo = (dduHistos[histoType])[code.getDDUID()];
00238     histo->setBinLabel(1,"Input ch1-4",1);      
00239     histo->setBinLabel(2,"Input ch5-8",1);      
00240     histo->setBinLabel(3,"Input ch9-12",1);     
00241     histo->setBinLabel(4,"Error/L1A ch1-4",1);  
00242     histo->setBinLabel(5,"Error/L1A ch5-8",1);  
00243     histo->setBinLabel(6,"Error/L1A ch9-12",1); 
00244     histo->setBinLabel(7,"Output",1);   
00245     histo->setBinLabel(1,"Full",2);     
00246     histo->setBinLabel(2,"Almost Full",2);      
00247     histo->setBinLabel(3,"Not Full",2); 
00248 
00249 
00250     histoType = "BXID";
00251     histoName = "FED" + dduID_s.str() + "_BXID";
00252     histoTitle = "Distrib. BX ID (FED" + dduID_s.str() + ")";
00253     (dduHistos[histoType])[code.getDDUID()] = dbe->book1D(histoName,histoTitle,3600,0,3600);
00254 
00255 
00256   }
00257 
00258   // ROS Histograms
00259   if ( folder == "ROS_S" ) { // The summary of the error of the ROS on the same FED
00260     dbe->setCurrentFolder(topFolder(false));
00261 
00262     histoType = "ROSSummary";
00263     histoName = "FED" + dduID_s.str() + "_ROSSummary";
00264     string histoTitle = "Summary Wheel" + wheel_s.str() + " (FED " + dduID_s.str() + ")";
00265 
00266     ((rosSHistos[histoType])[code.getDDUID()]) = dbe->book2D(histoName,histoTitle,20,0,20,12,1,13);
00267     MonitorElement *histo = ((rosSHistos[histoType])[code.getDDUID()]);
00268     // ROS error bins
00269     histo ->setBinLabel(1,"Link TimeOut",1);
00270     histo ->setBinLabel(2,"Ev.Id.Mis.",1);
00271     histo ->setBinLabel(3,"FIFO almost full",1);
00272     histo ->setBinLabel(4,"FIFO full",1);
00273     histo ->setBinLabel(5,"CEROS timeout",1);
00274     histo ->setBinLabel(6,"Max. wds",1);
00275     histo ->setBinLabel(7,"WO L1A FIFO",1);
00276     histo ->setBinLabel(8,"TDC parity err.",1);
00277     histo ->setBinLabel(9,"BX ID Mis.",1);
00278     histo ->setBinLabel(10,"TXP",1);
00279     histo ->setBinLabel(11,"L1A almost full",1);
00280     histo ->setBinLabel(12,"Ch. blocked",1);
00281     histo ->setBinLabel(13,"Ev. Id. Mis.",1);
00282     histo ->setBinLabel(14,"CEROS blocked",1);
00283     // TDC error bins
00284     histo ->setBinLabel(15,"TDC Fatal",1);
00285     histo ->setBinLabel(16,"TDC RO FIFO ov.",1);
00286     histo ->setBinLabel(17,"TDC L1 buf. ov.",1);
00287     histo ->setBinLabel(18,"TDC L1A FIFO ov.",1);
00288     histo ->setBinLabel(19,"TDC hit err.",1);
00289     histo ->setBinLabel(20,"TDC hit rej.",1);
00290 
00291     histo ->setBinLabel(1,"ROS1",2);
00292     histo ->setBinLabel(2,"ROS2",2);
00293     histo ->setBinLabel(3,"ROS3",2);
00294     histo ->setBinLabel(4,"ROS4",2);
00295     histo ->setBinLabel(5,"ROS5",2);
00296     histo ->setBinLabel(6,"ROS6",2);
00297     histo ->setBinLabel(7,"ROS7",2);
00298     histo ->setBinLabel(8,"ROS8",2);
00299     histo ->setBinLabel(9,"ROS9",2);
00300     histo ->setBinLabel(10,"ROS10",2);
00301     histo ->setBinLabel(11,"ROS11",2);
00302     histo ->setBinLabel(12,"ROS12",2);
00303   }
00304 
00305   if ( folder == "ROS" ) {
00306     dbe->setCurrentFolder(topFolder(false) + "FED" + dduID_s.str() + "/" + folder + rosID_s.str());
00307 
00308 
00309     histoType = "ROSError";
00310     histoName = "FED" + dduID_s.str() + "_" + folder + rosID_s.str() + "_ROSError";
00311     histoTitle = histoName + " (ROBID error summary)";
00312     if(mode <= 1)
00313       (rosHistos[histoType])[code.getROSID()] = dbe->book2D(histoName,histoTitle,17,0,17,26,0,26);
00314     else
00315       (rosHistos[histoType])[code.getROSID()] = dbe->book2D(histoName,histoTitle,11,0,11,26,0,26);
00316       
00317     MonitorElement* histo = (rosHistos[histoType])[code.getROSID()];
00318     // ROS error bins
00319     histo->setBinLabel(1,"Link TimeOut",1);
00320     histo->setBinLabel(2,"Ev.Id.Mis.",1);
00321     histo->setBinLabel(3,"FIFO almost full",1);
00322     histo->setBinLabel(4,"FIFO full",1);          
00323     histo->setBinLabel(5,"CEROS timeout",1);
00324     histo->setBinLabel(6,"Max. wds",1);
00325     histo->setBinLabel(7,"TDC parity err.",1);
00326     histo->setBinLabel(8,"BX ID Mis.",1);
00327     histo->setBinLabel(9,"Ch. blocked",1);
00328     histo->setBinLabel(10,"Ev. Id. Mis.",1);
00329     histo->setBinLabel(11,"CEROS blocked",1);
00330     if(mode <= 1) {
00331       // TDC error bins
00332       histo->setBinLabel(12,"TDC Fatal",1);
00333       histo->setBinLabel(13,"TDC RO FIFO ov.",1);
00334       histo->setBinLabel(14,"TDC L1 buf. ov.",1);
00335       histo->setBinLabel(15,"TDC L1A FIFO ov.",1);
00336       histo->setBinLabel(16,"TDC hit err.",1);
00337       histo->setBinLabel(17,"TDC hit rej.",1);
00338     }
00339     histo->setBinLabel(1,"ROB0",2);
00340     histo->setBinLabel(2,"ROB1",2);
00341     histo->setBinLabel(3,"ROB2",2);
00342     histo->setBinLabel(4,"ROB3",2);
00343     histo->setBinLabel(5,"ROB4",2);
00344     histo->setBinLabel(6,"ROB5",2);
00345     histo->setBinLabel(7,"ROB6",2);
00346     histo->setBinLabel(8,"ROB7",2);
00347     histo->setBinLabel(9,"ROB8",2);
00348     histo->setBinLabel(10,"ROB9",2);
00349     histo->setBinLabel(11,"ROB10",2);
00350     histo->setBinLabel(12,"ROB11",2);
00351     histo->setBinLabel(13,"ROB12",2);
00352     histo->setBinLabel(14,"ROB13",2);
00353     histo->setBinLabel(15,"ROB14",2);
00354     histo->setBinLabel(16,"ROB15",2);
00355     histo->setBinLabel(17,"ROB16",2);
00356     histo->setBinLabel(18,"ROB17",2);
00357     histo->setBinLabel(19,"ROB18",2);
00358     histo->setBinLabel(20,"ROB19",2);
00359     histo->setBinLabel(21,"ROB20",2);
00360     histo->setBinLabel(22,"ROB21",2);
00361     histo->setBinLabel(23,"ROB22",2);
00362     histo->setBinLabel(24,"ROB23",2);
00363     histo->setBinLabel(25,"ROB24",2);
00364     histo->setBinLabel(26,"SC",2);
00365 
00366     if(mode > 1) return;
00367 
00368     histoType = "ROSEventLenght";
00369     histoName = "FED" + dduID_s.str() + "_" + folder + rosID_s.str() + "_ROSEventLenght";
00370     histoTitle = "Event Lenght (Bytes) FED " +  dduID_s.str() + " ROS " + rosID_s.str();
00371     (rosHistos[histoType])[code.getROSID()] = dbe->book1D(histoName,histoTitle,101,0,1616);
00372 
00373 
00374     histoType = "TDCError";
00375     histoName = "FED" + dduID_s.str() + "_" + folder + rosID_s.str() + "_TDCError";
00376     histoTitle = histoName + " (ROBID error summary)";
00377     (rosHistos[histoType])[code.getROSID()] = dbe->book2D(histoName,histoTitle,24,0,24,25,0,25);
00378     histo = (rosHistos[histoType])[code.getROSID()];
00379     // TDC error bins
00380     histo->setBinLabel(1,"Fatal",1);
00381     histo->setBinLabel(2,"RO FIFO ov.",1);
00382     histo->setBinLabel(3,"L1 buf. ov.",1);
00383     histo->setBinLabel(4,"L1A FIFO ov.",1);
00384     histo->setBinLabel(5,"hit err.",1);
00385     histo->setBinLabel(6,"hit rej.",1);
00386     histo->setBinLabel(7,"Fatal",1);
00387     histo->setBinLabel(8,"RO FIFO ov.",1);
00388     histo->setBinLabel(9,"L1 buf. ov.",1);
00389     histo->setBinLabel(10,"L1A FIFO ov.",1);
00390     histo->setBinLabel(11,"hit err.",1);
00391     histo->setBinLabel(12,"hit rej.",1);
00392     histo->setBinLabel(13,"Fatal",1);
00393     histo->setBinLabel(14,"RO FIFO ov.",1);
00394     histo->setBinLabel(15,"L1 buf. ov.",1);
00395     histo->setBinLabel(16,"L1A FIFO ov.",1);
00396     histo->setBinLabel(17,"hit err.",1);
00397     histo->setBinLabel(18,"hit rej.",1);
00398     histo->setBinLabel(19,"Fatal",1);
00399     histo->setBinLabel(20,"RO FIFO ov.",1);
00400     histo->setBinLabel(21,"L1 buf. ov.",1);
00401     histo->setBinLabel(22,"L1A FIFO ov.",1);
00402     histo->setBinLabel(23,"hit err.",1);
00403     histo->setBinLabel(24,"hit rej.",1);
00404 
00405     histo->setBinLabel(1,"ROB0",2);
00406     histo->setBinLabel(2,"ROB1",2);
00407     histo->setBinLabel(3,"ROB2",2);
00408     histo->setBinLabel(4,"ROB3",2);
00409     histo->setBinLabel(5,"ROB4",2);
00410     histo->setBinLabel(6,"ROB5",2);
00411     histo->setBinLabel(7,"ROB6",2);
00412     histo->setBinLabel(8,"ROB7",2);
00413     histo->setBinLabel(9,"ROB8",2);
00414     histo->setBinLabel(10,"ROB9",2);
00415     histo->setBinLabel(11,"ROB10",2);
00416     histo->setBinLabel(12,"ROB11",2);
00417     histo->setBinLabel(13,"ROB12",2);
00418     histo->setBinLabel(14,"ROB13",2);
00419     histo->setBinLabel(15,"ROB14",2);
00420     histo->setBinLabel(16,"ROB15",2);
00421     histo->setBinLabel(17,"ROB16",2);
00422     histo->setBinLabel(18,"ROB17",2);
00423     histo->setBinLabel(19,"ROB18",2);
00424     histo->setBinLabel(20,"ROB19",2);
00425     histo->setBinLabel(21,"ROB20",2);
00426     histo->setBinLabel(22,"ROB21",2);
00427     histo->setBinLabel(23,"ROB22",2);
00428     histo->setBinLabel(24,"ROB23",2);
00429     histo->setBinLabel(25,"ROB24",2);
00430 
00431     histoType = "ROB_mean";
00432     histoName = "FED" + dduID_s.str() + "_" + "ROS" + rosID_s.str() + "_ROB_mean";
00433     string fullName = topFolder(false) + "FED" + dduID_s.str() + "/" + folder + rosID_s.str()+ "/" + histoName;    
00434     names.insert (pair<std::string,std::string> (histoType,string(fullName)));   
00435     (rosHistos[histoType])[code.getROSID()] = dbe->book2D(histoName,histoName,25,0,25,100,0,100);
00436     (rosHistos[histoType])[code.getROSID()]->setAxisTitle("ROB #",1);
00437     (rosHistos[histoType])[code.getROSID()]->setAxisTitle("ROB wordcounts",2);
00438 
00439     
00440 
00441 //     histoType = "Trigger_frequency";                
00442 //     histoName =  "FED" + dduID_s.str() + "_Trigger_frequency"; 
00443 //     (rosHistos[histoType])[code.getROSID()] = dbe->book1D(histoName,histoName,100,1,100);
00444   }
00445 
00446 
00447 //   if ( folder == "TDCError") {
00448 
00449 //     dbe->setCurrentFolder(topFolder(false) + "FED" + dduID_s.str()+"/ROS"+rosID_s.str()+"/ROB"+robID_s.str());
00450 
00451 //     histoType = "TDCError";
00452 //     histoName = "FED" + dduID_s.str() + "_ROS" + rosID_s.str() + "_ROB"+robID_s.str()+"_TDCError";
00453 //     string histoTitle = histoName + " (TDC Errors)";
00454 //     (robHistos[histoType])[code.getROBID()] = dbe->book2D(histoName,histoTitle,6,0,6,4,0,4);
00455 //     ((robHistos[histoType])[code.getROBID()]) ->setBinLabel(1,"TDC Fatal",1);
00456 //     ((robHistos[histoType])[code.getROBID()]) ->setBinLabel(2,"RO FIFO ov.",1);
00457 //     ((robHistos[histoType])[code.getROBID()]) ->setBinLabel(3,"L1 buffer ov.",1);
00458 //     ((robHistos[histoType])[code.getROBID()]) ->setBinLabel(4,"L1A FIFO ov.",1);
00459 //     ((robHistos[histoType])[code.getROBID()]) ->setBinLabel(5,"TDC hit err.",1);
00460 //     ((robHistos[histoType])[code.getROBID()]) ->setBinLabel(6,"TDC hit rej.",1);
00461 //     ((robHistos[histoType])[code.getROBID()]) ->setBinLabel(1,"TDC0",2);
00462 //     ((robHistos[histoType])[code.getROBID()]) ->setBinLabel(2,"TDC1",2);
00463 //     ((robHistos[histoType])[code.getROBID()]) ->setBinLabel(3,"TDC2",2);
00464 //     ((robHistos[histoType])[code.getROBID()]) ->setBinLabel(4,"TDC3",2);
00465 
00466 //   }
00467 
00468   // SC Histograms
00469   if ( folder == "SC" ) {
00470     // The plots are per wheel
00471     dbe->setCurrentFolder(topFolder(false) + "FED" + dduID_s.str());
00472 
00473     // SC data Size
00474     histoType = "SCSizeVsROSSize";
00475     histoName = "FED" + dduID_s.str() + "_SCSizeVsROSSize";
00476     histoTitle = "SC size - ROS size vs SC (FED " + dduID_s.str() + ")";
00477     rosHistos[histoType][code.getSCID()] = dbe->book2D(histoName,histoTitle,12,1,13,51,-1,50);
00478     rosHistos[histoType][code.getSCID()]->setAxisTitle("SC",1);
00479 
00480   }
00481 }
00482 
00483 void DTDataIntegrityTask::TimeHistos(string histoType){  
00484   
00485  if(histoType == "Event_word_vs_time"){   
00486 
00487   for (it = names.begin(); it != names.end(); it++) {    
00488 
00489     if ((*it).first==histoType){
00490      
00491      MonitorElement * h1 =dbe->get((*it).second);
00492 
00493  int first_bin = -1, last_bin=-1;
00494    for( int bin=1; bin < h1->getNbinsX()+1; bin++ ){
00495     for( int j=1; j < h1->getNbinsY(); j++ ){
00496      if( h1->getBinContent(bin,j) > 0 ) {    
00497       if( first_bin == -1 ) { first_bin = bin; }
00498       last_bin = bin;
00499    }
00500   }
00501  }
00502  
00503   if( first_bin > 1 ) { first_bin -= 1; }
00504   if( last_bin < h1-> getNbinsX() ){ last_bin += 1; }
00505     h1->setAxisRange(0,last_bin,1);
00506    }
00507   }
00508  }  
00509 }
00510 
00511 
00512 
00513 // void DTDataIntegrityTask::bookHistosFED() {
00514 //     bookHistos( string("ROS_S"), code);
00515 
00516 // }
00517 
00518 
00519 void DTDataIntegrityTask::bookHistosROS25(DTROChainCoding code) {
00520     bookHistos( string("ROS"), code);
00521 //     for(int robId = 0; robId != 25; ++robId) {
00522 //       code.setROB(robId);
00523 //       bookHistos( string("TDCError"), code);
00524 //     }
00525     if(mode <= 1)
00526       if(getSCInfo)
00527         bookHistos( string("SC"), code);
00528 }
00529 
00530 
00531 void DTDataIntegrityTask::processROS25(DTROS25Data & data, int ddu, int ros) {
00532   neventsROS25++; // FIXME: implement a counter which makes sense
00533 
00534 //   if (neventsROS25%1000 == 0)
00535       LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00536         << "[DTDataIntegrityTask]: " << neventsROS25 << " events analyzed by processROS25" << endl;
00537 
00538   // The ID of the RO board (used to map the histos)
00539   DTROChainCoding code;
00540   code.setDDU(ddu);
00541   code.setROS(ros);
00542 
00543   MonitorElement* ROSSummary = rosSHistos["ROSSummary"][code.getDDUID()];
00544 
00545   // Summary of all ROB errors
00546   MonitorElement* ROSError = 0;
00547   if(mode <= 2) ROSError = rosHistos["ROSError"][code.getROSID()];
00548 
00549   // L1A ids to be checked against FED one
00550   rosL1AIdsPerFED[ddu].insert(data.getROSHeader().TTCEventCounter());
00551 
00552   // ROS errors
00553 
00554 
00555   // check for TPX errors
00556   if (data.getROSTrailer().TPX() != 0) {
00557     LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask") << " TXP error en ROS "
00558                                                                       << code.getROS() << endl;
00559     ROSSummary->Fill(9,code.getROS());
00560   }
00561 
00562   // L1 Buffer almost full (non-critical error!)
00563   if(data.getROSTrailer().l1AFifoOccupancy() > 31) {
00564      ROSSummary->Fill(10,code.getROS());
00565    }
00566   
00567   // FIXME: what is this about???
00568   if (neventsROS25 == 1) FirstRos = code.getROSID();
00569   if (code.getROSID() == FirstRos) nevents++ ;
00570 
00571 
00572   for (vector<DTROSErrorWord>::const_iterator error_it = data.getROSErrors().begin();
00573        error_it != data.getROSErrors().end(); error_it++) { // Loop over ROS error words
00574     
00575     LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask") << " Error in ROS " << code.getROS()
00576                                                                       << " ROB Id " << (*error_it).robID()
00577                                                                       << " Error type " << (*error_it).errorType() << endl;
00578 
00579     // Fill the ROSSummary (1 per FED) histo
00580     ROSSummary->Fill((*error_it).errorType(), code.getROS());
00581     if((*error_it).errorType() <= 11) { // set error flag
00582        eventErrorFlag = true;
00583     }
00584     
00585     if(mode <= 2) {
00586       // Fill the ROB Summary (1 per ROS) histo
00587       if ((*error_it).robID() != 31) {
00588         ROSError->Fill((*error_it).errorType(),(*error_it).robID());
00589       }
00590       else if ((*error_it).errorType() == 4) {
00591         vector<int> channelBins;
00592         channelsInROS((*error_it).cerosID(),channelBins);
00593         vector<int>::const_iterator channelIt  = channelBins.begin();
00594         vector<int>::const_iterator channelEnd = channelBins.end();
00595         for(;channelIt!=channelEnd;++channelIt) {
00596           ROSError->Fill(4,(*channelIt));
00597         }
00598       }
00599     }
00600   }
00601 
00602 
00603   int ROSDebug_BunchNumber = -1;
00604   int ROSDebug_BcntResCntLow = 0;
00605   int ROSDebug_BcntResCntHigh = 0;
00606   int ROSDebug_BcntResCnt = 0;
00607   
00608   for (vector<DTROSDebugWord>::const_iterator debug_it = data.getROSDebugs().begin();
00609        debug_it != data.getROSDebugs().end(); debug_it++) { // Loop over ROS debug words
00610     
00611     int debugROSSummary = 0;
00612     int debugROSError   = 0;
00613     vector<int> debugBins;
00614     bool hasEvIdMis = false;
00615     vector<int> evIdMisBins;
00616 
00617     if ((*debug_it).debugType() == 0 ) {
00618       ROSDebug_BunchNumber = (*debug_it).debugMessage();
00619     } else if ((*debug_it).debugType() == 1 ) {
00620       ROSDebug_BcntResCntLow = (*debug_it).debugMessage();
00621     } else if ((*debug_it).debugType() == 2 ) {
00622       ROSDebug_BcntResCntHigh = (*debug_it).debugMessage();
00623     } else if ((*debug_it).debugType() == 3) {
00624       if ((*debug_it).dontRead()){  
00625         debugROSSummary = 11;
00626         debugROSError   = 8;
00627         if (mode <= 2) channelsInCEROS((*debug_it).cerosIdCerosStatus(),(*debug_it).dontRead(),debugBins);
00628       } if ((*debug_it).evIdMis()){
00629         hasEvIdMis = true;
00630         if (mode <= 2) channelsInCEROS((*debug_it).cerosIdCerosStatus(),(*debug_it).evIdMis(),evIdMisBins);
00631       }
00632     } else if ((*debug_it).debugType() == 4 &&
00633                (*debug_it).cerosIdRosStatus()){
00634       debugROSSummary = 13;
00635       debugROSError   = 10;
00636       if (mode <= 2) channelsInROS((*debug_it).cerosIdRosStatus(),debugBins);
00637     }
00638  
00639     if (debugROSSummary) {
00640       ROSSummary->Fill(debugROSSummary,code.getROS());
00641       if (mode <= 2) {
00642         vector<int>::const_iterator channelIt  = debugBins.begin();
00643         vector<int>::const_iterator channelEnd = debugBins.end();
00644         for (;channelIt!=channelEnd;++channelIt) {
00645           ROSError->Fill(debugROSError,(*channelIt));
00646         }
00647       }
00648     }
00649     
00650     if (hasEvIdMis) {
00651       ROSSummary->Fill(12,code.getROS());
00652       if (mode <= 2) {
00653         vector<int>::const_iterator channelIt  = evIdMisBins.begin();
00654         vector<int>::const_iterator channelEnd = evIdMisBins.end();
00655         for (;channelIt!=channelEnd;++channelIt) {
00656           ROSError->Fill(9,(*channelIt));
00657         }
00658       }
00659     }
00660         
00661   }
00662   
00663   ROSDebug_BcntResCnt = (ROSDebug_BcntResCntHigh << 15) + ROSDebug_BcntResCntLow;
00664   //   LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00665   //     << " ROS: " << code.getROS() << " ROSDebug_BunchNumber " << ROSDebug_BunchNumber
00666   //     << " ROSDebug_BcntResCnt " << ROSDebug_BcntResCnt << endl;
00667   
00668 
00669   //     Event words vs time
00670   // FIXME: what is this doing???
00671   ROSWords_t(ResetCount_unfolded,code.getROS(),ROSDebug_BcntResCnt,nevents);
00672 
00673   // fill hists it here
00674   //   histoType = "Event_word_vs_time";          
00675   //   if (rosHistos[histoType].find(code.getROSID()) != rosHistos[histoType].end()){
00676   //   (rosHistos.find(histoType)->second).find(code.getROSID())->second->
00677   //            Fill((ResetCount_unfolded),data.getROSTrailer().EventWordCount());
00678   //   (rosHistos.find(histoType)->second).find(code.getROSID())->second->setAxisTitle("Time(s)",1);
00679   //    }
00680   //   else {
00681   //      (rosHistos.find(histoType)->second).find(code.getROSID())->second->
00682   //                    Fill((ResetCount_unfolded),data.getROSTrailer().EventWordCount());}  
00683 
00684 
00685         
00686 
00687   // ROB Group Header
00688   // Check the BX of the ROB headers against the BX of the ROS
00689   for (vector<DTROBHeader>::const_iterator rob_it = data.getROBHeaders().begin();
00690        rob_it != data.getROBHeaders().end(); rob_it++) { // loop over ROB headers
00691     
00692     code.setROB((*rob_it).first);
00693     DTROBHeaderWord robheader = (*rob_it).second;  
00694 
00695     rosBxIdsPerFED[ddu].insert(ROSDebug_BunchNumber);
00696     
00697     if (robheader.bunchID() != ROSDebug_BunchNumber) {
00698       // fill ROS Summary plot
00699       ROSSummary->Fill(8,code.getROS());
00700       eventErrorFlag = true;
00701       
00702       // fill ROB Summary plot for that particular ROS
00703       if(mode <= 2) ROSError->Fill(7,robheader.robID());
00704     }
00705   }
00706 
00707 
00708   if(mode <= 1) { // produce only when not in HLT 
00709     // ROB Trailer
00710     for (vector<DTROBTrailerWord>::const_iterator robt_it = data.getROBTrailers().begin();
00711          robt_it != data.getROBTrailers().end(); robt_it++) { // loop over ROB trailers 
00712       float  wCount = (*robt_it).wordCount()<100. ? (*robt_it).wordCount() : 99.9; 
00713       rosHistos["ROB_mean"][code.getROSID()]->Fill((*robt_it).robID(),wCount);
00714     }
00715 
00716 //     // Trigger frequency 
00717 //     double frequency = 0;
00718 //     // FIXME: how is the frequency computed
00719 //     ROS_L1A_Frequency(code.getROS(),ROSDebug_BcntResCnt,neventsROS25,frequency,trigger_counter);
00720 //     rosHistos["Trigger_frequency"][code.getROSID()]->Fill(frequency);
00721 
00722     // Plot the event lenght //NOHLT
00723     int rosEventLenght = data.getROSTrailer().EventWordCount()*4;
00724     if(rosEventLenght > 1600) rosEventLenght = 1600;
00725     rosHistos["ROSEventLenght"][code.getROSID()]->Fill(rosEventLenght);
00726   }
00727 
00728    
00729   // TDC Data  
00730   for (vector<DTTDCData>::const_iterator tdc_it = data.getTDCData().begin();
00731        tdc_it != data.getTDCData().end(); tdc_it++) { // loop over TDC data
00732 
00733     DTTDCMeasurementWord tdcDatum = (*tdc_it).second;
00734 
00735     if ( tdcDatum.PC() !=0)  {
00736       LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00737         << " PC error in ROS " << code.getROS() << " TDC " << (*tdc_it).first << endl;
00738       //     fill ROS Summary plot
00739       ROSSummary->Fill(7,code.getROS());
00740 
00741       eventErrorFlag = true;
00742 
00743       // fill ROB Summary plot for that particular ROS
00744       if(mode <= 2) ROSError->Fill(6,(*tdc_it).first);
00745     }
00746   }
00747 
00748   // TDC Error  
00749   for (vector<DTTDCError>::const_iterator tdc_it = data.getTDCError().begin();
00750        tdc_it != data.getTDCError().end(); tdc_it++) { // loop over TDC errors
00751 
00752     code.setROB((*tdc_it).first);
00753 
00754     int tdcError_ROSSummary = 0;
00755     int tdcError_ROSError = 0;
00756     int tdcError_TDCHisto = 0;
00757 
00758     if(((*tdc_it).second).tdcError() & 0x4000 ) {
00759       LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00760         << " ROS " << code.getROS() << " ROB " << code.getROB()
00761         << " Internal fatal Error 4000 in TDC " << (*tdc_it).first << endl;
00762 
00763       tdcError_ROSSummary = 14;
00764       tdcError_ROSError   = 11;
00765       tdcError_TDCHisto   = 0;
00766 
00767     } else if ( ((*tdc_it).second).tdcError() & 0x0249 ) {
00768       LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00769         << " ROS " << code.getROS() << " ROB " << code.getROB()
00770         << " TDC FIFO overflow in TDC " << (*tdc_it).first << endl;
00771 
00772       tdcError_ROSSummary = 15;
00773       tdcError_ROSError   = 12;
00774       tdcError_TDCHisto   = 1;
00775 
00776     } else if ( ((*tdc_it).second).tdcError() & 0x0492 ) {
00777       LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00778         << " ROS " << code.getROS() << " ROB " << code.getROB()
00779         << " TDC L1 buffer overflow in TDC " << (*tdc_it).first << endl;
00780       
00781       tdcError_ROSSummary = 16;
00782       tdcError_ROSError   = 13;
00783       tdcError_TDCHisto   = 2;
00784 
00785     } else if ( ((*tdc_it).second).tdcError() & 0x2000 ) {
00786       LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00787         << " ROS " << code.getROS() << " ROB " << code.getROB()
00788         << " TDC L1A FIFO overflow in TDC " << (*tdc_it).first << endl;
00789       
00790       tdcError_ROSSummary = 17;
00791       tdcError_ROSError   = 14;
00792       tdcError_TDCHisto   = 3;
00793 
00794     } else if ( ((*tdc_it).second).tdcError() & 0x0924 ) {
00795       LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00796         << " ROS " << code.getROS() << " ROB " << code.getROB()
00797         << " TDC hit error in TDC " << (*tdc_it).first << endl;
00798       
00799       tdcError_ROSSummary = 18;
00800       tdcError_ROSError   = 15;
00801       tdcError_TDCHisto   = 4;
00802 
00803     } else if ( ((*tdc_it).second).tdcError() & 0x1000 ) {
00804       LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00805         << " ROS " << code.getROS() << " ROB " << code.getROB()
00806         << " TDC hit rejected in TDC " << (*tdc_it).first << endl;
00807       
00808       tdcError_ROSSummary = 19;
00809       tdcError_ROSError   = 16;
00810       tdcError_TDCHisto   = 5;
00811 
00812     } else {
00813       LogWarning("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00814         << " TDC error code not known " << ((*tdc_it).second).tdcError() << endl;
00815     }
00816     
00817     ROSSummary->Fill(tdcError_ROSSummary,code.getROS());
00818 
00819     if(tdcError_ROSSummary <= 15) {
00820       eventErrorFlag = true;
00821     }
00822 
00823     if(mode <= 2) {
00824       ROSError->Fill(tdcError_ROSError,(*tdc_it).first);
00825       if(mode <= 1)
00826         rosHistos["TDCError"][code.getROSID()]->Fill(tdcError_TDCHisto+6*((*tdc_it).second).tdcID(),(*tdc_it).first);
00827     }
00828   }
00829 
00830   // Read SC data
00831   if (mode <= 1 && getSCInfo) {
00832     // SC Data
00833 
00834     // NumberOf16bitWords counts the # of words + 1 subheader
00835     // the SC includes the SC "private header" and the ROS header and trailer (= NumberOf16bitWords +3)
00836     rosHistos["SCSizeVsROSSize"][code.getSCID()]->Fill(ros,data.getSCPrivHeader().NumberOf16bitWords()+3-data.getSCTrailer().wordCount());
00837     
00838   }
00839 
00840 
00841 
00842 
00843 }
00844 
00845 void DTDataIntegrityTask::processFED(DTDDUData & data, const std::vector<DTROS25Data> & rosData, int ddu) {
00846 
00847   neventsDDU++;
00848   if (neventsDDU%1000 == 0)
00849     LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00850       << "[DTDataIntegrityTask]: " << neventsDDU << " events analyzed by processFED" << endl;
00851 
00852 
00853   DTROChainCoding code;
00854   code.setDDU(ddu);
00855 
00856   hFEDEntry->Fill(code.getDDUID());
00857 
00858   FEDTrailer trailer = data.getDDUTrailer();
00859   FEDHeader header = data.getDDUHeader();
00860 
00861   // check consistency of header and trailer
00862   if(!header.check()) {
00863     // error code 7
00864     hFEDFatal->Fill(code.getDDUID());
00865     hCorruptionSummary->Fill(code.getDDUID(), 7);
00866   }
00867 
00868   if(!trailer.check()) {
00869     // error code 8
00870     hFEDFatal->Fill(code.getDDUID());
00871     hCorruptionSummary->Fill(code.getDDUID(), 8);
00872   }
00873 
00874   // check CRC error bit set by DAQ before sending data on SLink
00875   if(data.crcErrorBit()) {
00876     // error code 6
00877     hFEDFatal->Fill(code.getDDUID());
00878     hCorruptionSummary->Fill(code.getDDUID(), 6);
00879   }
00880 
00881   DTDDUSecondStatusWord secondWord = data.getSecondStatusWord();
00882 
00883   // Fill the status summary of the TTS
00884 
00885 
00886   //1D HISTO WITH TTS VALUES form trailer (7 bins = 7 values)
00887   int ttsCodeValue = -1;
00888   int ttsSummaryBin = -1;
00889 
00890   switch(trailer.ttsBits()) {
00891   case 0:{ //disconnected
00892     ttsCodeValue = 0;
00893     break;
00894   }
00895   case 1:{ //warning overflow
00896     ttsCodeValue = 1;
00897     if(secondWord.warningROSPAF()) { // ROS PAF
00898       ttsSummaryBin = 1;
00899     } else { // DDU PAF
00900       ttsSummaryBin = 2;
00901     }
00902     
00903     break;
00904   }
00905   case 2:{ //out of sinch
00906     ttsCodeValue = 2;
00907     bool knownOrigin = false;
00908     if(secondWord.outOfSynchROSError()) {// ROS Error
00909       ttsSummaryBin = 7;
00910       knownOrigin = true;
00911     }
00912     if(secondWord.l1AIDError()) {// L1A Mism.
00913       ttsSummaryBin = 6;
00914       knownOrigin = true;
00915     }
00916     if(secondWord.bxIDError()) {// BX Mism.
00917       ttsSummaryBin = 8;
00918       knownOrigin = true;
00919     }
00920     if(secondWord.outputFifoFull() || secondWord.inputFifoFull() || secondWord.fifoFull()) { // DDU Full
00921       ttsSummaryBin = 5;
00922       knownOrigin = true;
00923     }
00924     if(!knownOrigin) ttsSummaryBin = 9; // Error in DDU logic
00925 
00926     break;
00927   }
00928   case 4:{ //busy
00929     ttsCodeValue = 3;
00930     bool knownOrigin = false;
00931     if(secondWord.busyROSPAF()) { // ROS PAF
00932       ttsSummaryBin = 3;
00933       knownOrigin = true;
00934     } 
00935     if(secondWord.outputFifoAlmostFull() || secondWord.inputFifoAlmostFull() || secondWord.fifoAlmostFull() ){ // DDU PAF
00936       ttsSummaryBin = 4;
00937       knownOrigin = true;
00938     }
00939     if(!knownOrigin) ttsSummaryBin = 9; // Error in DDU logic
00940     break;
00941   }
00942   case 8:{ //ready
00943     ttsCodeValue = 4;
00944     break;
00945   }
00946   case 12:{ //error
00947     ttsCodeValue = 5;
00948     break;
00949   }
00950   case 16:{ //disconnected
00951     ttsCodeValue = 6;
00952     break;
00953   }
00954   default:{
00955     LogError("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
00956       <<"[DTDataIntegrityTask] DDU control: wrong TTS value "<<trailer.ttsBits()<<endl;
00957     ttsCodeValue = 7;
00958   }
00959   }
00960   if(mode <= 1) dduHistos["TTSValues"][code.getDDUID()]->Fill(ttsCodeValue);
00961   if(ttsSummaryBin != -1) {
00962     hTTSSummary->Fill(ddu, ttsSummaryBin);
00963   }
00964 
00965 
00966 
00967 
00968 
00969 
00970   //2D HISTO: ROS VS STATUS (8 BIT = 8 BIN) from 1st-2nd status words (9th BIN FROM LIST OF ROS in 2nd status word)
00971   MonitorElement* hROSStatus = dduHistos["ROSStatus"][code.getDDUID()];
00972   //1D HISTO: NUMBER OF ROS IN THE EVENTS from 2nd status word
00973 
00974   int rosList = secondWord.rosList();
00975   set<int> rosPositions;
00976   for(int i=0;i<12;i++) {
00977     if(rosList & 0x1) {
00978       rosPositions.insert(i);
00979       //9th BIN FROM LIST OF ROS in 2nd status word
00980       if(mode <= 2) hROSStatus->Fill(8,i,1);
00981     }
00982     rosList >>= 1;
00983   }
00984 
00985   int channel=0;
00986   for (vector<DTDDUFirstStatusWord>::const_iterator fsw_it = data.getFirstStatusWord().begin();
00987        fsw_it != data.getFirstStatusWord().end(); fsw_it++) {
00988     // assuming association one-to-one between DDU channel and ROS
00989     if(mode <= 2) {
00990       hROSStatus->Fill(0,channel,(*fsw_it).channelEnabled());
00991       hROSStatus->Fill(1,channel,(*fsw_it).timeout());
00992       hROSStatus->Fill(2,channel,(*fsw_it).eventTrailerLost());
00993       hROSStatus->Fill(3,channel,(*fsw_it).opticalFiberSignalLost());
00994       hROSStatus->Fill(4,channel,(*fsw_it).tlkPropagationError());
00995       hROSStatus->Fill(5,channel,(*fsw_it).tlkPatternError());
00996       hROSStatus->Fill(6,channel,(*fsw_it).tlkSignalLost());
00997       hROSStatus->Fill(7,channel,(*fsw_it).errorFromROS());
00998     }
00999     // check that the enabled channel was also in the read-out
01000     if((*fsw_it).channelEnabled() == 1 &&
01001        rosPositions.find(channel) == rosPositions.end()) {
01002       if(mode <= 2) hROSStatus->Fill(9,channel,1);
01003       // error code 1
01004       hFEDFatal->Fill(code.getDDUID());
01005       hCorruptionSummary->Fill(code.getDDUID(), 1);
01006     }
01007     channel++;
01008   }
01009 
01010 
01011   // ---------------------------------------------------------------------
01012   // cross checks between FED and ROS data
01013   // check the BX ID against the ROSs
01014   set<int> rosBXIds = rosBxIdsPerFED[ddu];
01015   if((rosBXIds.size() > 1 || rosBXIds.find(header.bxID()) == rosBXIds.end()) && rosBXIds.size() != 0) { // in this case look for faulty ROSs
01016     for(vector<DTROS25Data>::const_iterator rosControlData = rosData.begin();
01017         rosControlData != rosData.end(); ++rosControlData) { // loop over the ROS data
01018       for (vector<DTROSDebugWord>::const_iterator debug_it = (*rosControlData).getROSDebugs().begin();
01019            debug_it != (*rosControlData).getROSDebugs().end(); debug_it++) { // Loop over ROS debug words
01020         if ((*debug_it).debugType() == 0 && (*debug_it).debugMessage() != header.bxID()) { // check the BX
01021           int ros = (*rosControlData).getROSID();
01022           // fill the error bin
01023           if(mode <= 2) hROSStatus->Fill(11,ros-1);
01024           // error code 2
01025           hFEDFatal->Fill(code.getDDUID());
01026           hCorruptionSummary->Fill(code.getDDUID(), 2);
01027         }
01028       }
01029     }
01030   }
01031 
01032   // check the BX ID against other FEDs
01033   fedBXIds.insert(header.bxID());
01034   if(fedBXIds.size() != 1) {
01035     LogWarning("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
01036       << "ERROR: FED " << ddu << " BX ID different from other feds: " << header.bxID() << endl;
01037     // error code 3
01038     hFEDFatal->Fill(code.getDDUID());
01039     hCorruptionSummary->Fill(code.getDDUID(), 3);
01040   }
01041 
01042 
01043   // check the L1A ID against the ROSs 
01044   set<int> rosL1AIds = rosL1AIdsPerFED[ddu];
01045   if((rosL1AIds.size() > 1 || rosL1AIds.find(header.lvl1ID()-1) == rosL1AIds.end()) && rosL1AIds.size() != 0) { // in this case look for faulty ROSs
01046     //If L1A_ID error identify which ROS has wrong L1A 
01047     for (vector<DTROS25Data>::const_iterator rosControlData = rosData.begin();
01048          rosControlData != rosData.end(); rosControlData++) { // loop over the ROS data
01049       int ROSHeader_TTCCount = ((*rosControlData).getROSHeader().TTCEventCounter() + 1) % 0x1000000; // fix comparison in case of last counting bin in ROS /first one in DDU
01050       if( ROSHeader_TTCCount != header.lvl1ID() ) { 
01051         int ros = (*rosControlData).getROSID();
01052         if(mode <= 2) hROSStatus->Fill(10,ros-1);
01053         // error code 4
01054         hFEDFatal->Fill(code.getDDUID());
01055         hCorruptionSummary->Fill(code.getDDUID(), 4);
01056       }
01057     }
01058   }
01059 
01060   //1D HISTOS: EVENT LENGHT from trailer
01061   int fedEvtLenght = trailer.lenght()*8;
01062   //   if(fedEvtLenght > 16000) fedEvtLenght = 16000; // overflow bin
01063   dduHistos["EventLenght"][code.getDDUID()]->Fill(fedEvtLenght);
01064 
01065   if(mode > 1) return;
01066 
01067 
01068   // size of the list of ROS in the Read-Out
01069   dduHistos["ROSList"][code.getDDUID()]->Fill(rosPositions.size());
01070 
01071 
01072   //2D HISTO: FIFO STATUS from 2nd status word
01073   MonitorElement *hFIFOStatus = dduHistos["FIFOStatus"][code.getDDUID()];
01074   int inputFifoFull = secondWord.inputFifoFull();
01075   int inputFifoAlmostFull = secondWord.inputFifoAlmostFull();
01076   int fifoFull = secondWord.fifoFull();
01077   int fifoAlmostFull = secondWord.fifoAlmostFull();
01078   int outputFifoFull = secondWord.outputFifoFull();
01079   int outputFifoAlmostFull = secondWord.outputFifoAlmostFull();
01080   for(int i=0;i<3;i++){
01081     if(inputFifoFull & 0x1){
01082       hFIFOStatus->Fill(i,0);
01083     }
01084     if(inputFifoAlmostFull & 0x1){
01085       hFIFOStatus->Fill(i,1);
01086     }
01087     if(fifoFull & 0x1){
01088       hFIFOStatus->Fill(3+i,0);
01089     }
01090     if(fifoAlmostFull & 0x1){
01091       hFIFOStatus->Fill(3+i,1);
01092     }
01093     if(!(inputFifoFull & 0x1) && !(inputFifoAlmostFull & 0x1)){
01094       hFIFOStatus->Fill(i,2);
01095     }
01096     if(!(fifoFull & 0x1) && !(fifoAlmostFull & 0x1)){
01097       hFIFOStatus->Fill(3+i,2);
01098     }
01099     inputFifoFull >>= 1;
01100     inputFifoAlmostFull >>= 1;
01101     fifoFull >>= 1;
01102     fifoAlmostFull >>= 1;
01103   }
01104 
01105   if(outputFifoFull){
01106     hFIFOStatus->Fill(6,0);
01107   }
01108   if(outputFifoAlmostFull){
01109     hFIFOStatus->Fill(6,1);
01110   }
01111   if(!outputFifoFull && !outputFifoAlmostFull){
01112     hFIFOStatus->Fill(6,2);
01113   }
01114 
01115 
01116 
01117  
01118 
01119 
01120 
01121   //1D HISTO: EVENT TYPE from header
01122   dduHistos["EventType"][code.getDDUID()]->Fill(header.triggerType());
01123 
01124   // fill the distribution of the BX ids
01125   dduHistos["BXID"][code.getDDUID()]->Fill(header.bxID());
01126 
01127 
01128 }
01129 
01130   
01131 bool DTDataIntegrityTask::eventHasErrors() const {
01132   return eventErrorFlag;
01133 }
01134 
01135 
01136 
01137 // log number of times the payload of each fed is unpacked 
01138 void DTDataIntegrityTask::fedEntry(int dduID) {
01139   hFEDEntry->Fill(dduID);
01140 }
01141 
01142 
01143 
01144 // log number of times the payload of each fed is skipped (no ROS inside)
01145 void DTDataIntegrityTask::fedFatal(int dduID) {
01146   hFEDFatal->Fill(dduID);
01147 }
01148 
01149 
01150 
01151 // log number of times the payload of each fed is partially skipped (some ROS skipped)
01152 void DTDataIntegrityTask::fedNonFatal(int dduID) {
01153   hFEDNonFatal->Fill(dduID);
01154 }
01155 
01156 std::string DTDataIntegrityTask::topFolder(bool isFEDIntegrity) const {
01157 
01158   string folder = isFEDIntegrity ? fedIntegrityFolder : "DT/00-DataIntegrity";
01159   
01160   if (!isFEDIntegrity)
01161     folder += (mode==1) ? "_SM/" : (mode==3) ? "_EvF/" : "/";
01162 
01163   return folder;
01164 
01165 }
01166 
01167 void DTDataIntegrityTask::channelsInCEROS(int cerosId, int chMask, vector<int>& channels ){
01168   for (int iCh=0; iCh<6;++iCh) {
01169     if ((chMask >> iCh) & 0x1){
01170       channels.push_back(cerosId*6+iCh);
01171     }
01172   }
01173   return;
01174 }
01175 
01176 void DTDataIntegrityTask::channelsInROS(int cerosMask, vector<int>& channels){
01177   for (int iCeros=0; iCeros<5;++iCeros) {
01178     if ((cerosMask >> iCeros) & 0x1){
01179       for (int iCh=0; iCh<6;++iCh) {
01180         channels.push_back(iCeros*6+iCh);
01181       }
01182     }
01183   }
01184   return;
01185 }
01186 
01187 void DTDataIntegrityTask::preProcessEvent(const edm::EventID& iEvtid, const edm::Timestamp& iTime) {
01188 
01189   nevents++;
01190   nEventMonitor->Fill(nevents);
01191 
01192   LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask") << "[DTDataIntegrityTask]: preProcessEvent" <<endl;
01193   // clear the set of BXids from the ROSs
01194   for(map<int, set<int> >::iterator rosBxIds = rosBxIdsPerFED.begin();
01195       rosBxIds != rosBxIdsPerFED.end(); ++rosBxIds) {
01196     (*rosBxIds).second.clear();
01197   }
01198 
01199   fedBXIds.clear();
01200 
01201   for(map<int, set<int> >::iterator rosL1AIds = rosL1AIdsPerFED.begin();
01202       rosL1AIds != rosL1AIdsPerFED.end(); ++rosL1AIds) {
01203     (*rosL1AIds).second.clear();
01204   }
01205 
01206   // reset the error flag
01207   eventErrorFlag = false;
01208 
01209 }
01210 
01211 
01212 
01213 void DTDataIntegrityTask::postBeginJob() {
01214   LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask") << "[DTDataIntegrityTask]: postBeginJob" <<endl;
01215   // get the DQMStore service if needed
01216   dbe = edm::Service<DQMStore>().operator->();    
01217   LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask") << "[DTDataIntegrityTask] Get DQMStore service" << endl;
01218   
01219 
01220   
01221   // Loop over the DT FEDs
01222   int FEDIDmin = FEDNumbering::MINDTFEDID;
01223   int FEDIDMax = FEDNumbering::MAXDTFEDID;
01224 
01225   LogTrace("DTRawToDigi|DTDQM|DTMonitorModule|DTDataIntegrityTask")
01226     << " FEDS: " << FEDIDmin  << " to " <<  FEDIDMax << " in the RO" << endl;
01227 
01228   // book FED integrity histos
01229   bookHistos(FEDIDmin, FEDIDMax);
01230 
01231   // static booking of the histograms
01232   for(int fed = FEDIDmin; fed <= FEDIDMax; ++fed) { // loop over the FEDs in the readout
01233     DTROChainCoding code;
01234     code.setDDU(fed);
01235     
01236     bookHistos( string("ROS_S"), code);
01237 
01238     bookHistos( string("DDU"), code);
01239 
01240     for(int ros = 1; ros <= 12; ++ros) {// loop over all ROS
01241       code.setROS(ros);
01242       bookHistosROS25(code);
01243     }
01244   }
01245 
01246 }