CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/DTMonitorModule/src/DTDataIntegrityTask.cc

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