CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CalibFormats/SiPixelObjects/src/PixelDetectorConfig.cc

Go to the documentation of this file.
00001 //
00002 // Implementation of the detector configuration
00003 //
00004 //
00005 //
00006 //
00007 
00008 #include "CalibFormats/SiPixelObjects/interface/PixelDetectorConfig.h"
00009 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
00010 #include <fstream>
00011 #include <iostream>
00012 #include <sstream>
00013 #include <ios>
00014 #include <stdexcept>
00015 #include <assert.h>
00016 #include <stdio.h>
00017 
00018 using namespace std;
00019 using namespace pos;
00020 
00021 
00022 PixelDetectorConfig::PixelDetectorConfig(std::vector< std::vector < std::string> > &tableMat):PixelConfigBase("","",""){
00023 
00024   std::string mthn = "]\t[PixelDetectorConfig::PixelDetectorConfig()]\t\t    " ;
00025   std::vector< std::string > ins = tableMat[0];
00026   std::map<std::string , int > colM;
00027   std::vector<std::string > colNames;
00028   /*
00029     EXTENSION_TABLE_NAME: PIXEL_DETECTOR_CONFIG (VIEW: CONF_KEY_DET_CONFIG_V)
00030     
00031     CONFIG_KEY                                NOT NULL VARCHAR2(80)
00032     KEY_TYPE                                  NOT NULL VARCHAR2(80)
00033     KEY_ALIAS                                 NOT NULL VARCHAR2(80)
00034     VERSION                                            VARCHAR2(40)
00035     KIND_OF_COND                              NOT NULL VARCHAR2(40)
00036     ROC_NAME                                  NOT NULL VARCHAR2(200)
00037     ROC_STATUS                                NOT NULL VARCHAR2(200)
00038   */
00039   colNames.push_back("CONFIG_KEY"  );
00040   colNames.push_back("KEY_TYPE"    );
00041   colNames.push_back("KEY_ALIAS"   );
00042   colNames.push_back("VERSION"     );
00043   colNames.push_back("KIND_OF_COND");
00044   colNames.push_back("ROC_NAME"    );
00045   colNames.push_back("ROC_STATUS"  );
00046 
00047   for(unsigned int c = 0 ; c < ins.size() ; c++){
00048     for(unsigned int n=0; n<colNames.size(); n++){
00049       if(tableMat[0][c] == colNames[n]){
00050         colM[colNames[n]] = c;
00051         break;
00052       }
00053     }
00054   }//end for
00055 
00056   /*
00057   for(unsigned int n=0; n<colNames.size(); n++){
00058     if(colM.find(colNames[n]) == colM.end()){
00059       std::cerr << __LINE__ << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
00060       assert(0);
00061     }
00062   }
00063   */
00064 
00065   modules_.clear();
00066   rocs_.clear() ;
00067   std::string module= "";
00068   for(unsigned int r = 1 ; r < tableMat.size() ; r++)
00069     {    //Goes to every row of the Matrix
00070       PixelROCName roc(tableMat[r][colM["ROC_NAME"]]) ; // see DACSettings!!!!
00071       PixelROCStatus rocstatus;
00072       std::string status = tableMat[r][colM["ROC_STATUS"]];
00073       // The following is due to the fact that enabled ROCs are 
00074       // labelled as ON in the DataBase, but have NO label in 
00075       // configuration files!!!
00076       if(status.find("on") != string::npos)
00077         {
00078           status = "" ;
00079         }
00080       if (status!=""){
00081         rocstatus.set(status);
00082       }
00083       rocs_[roc]=rocstatus;
00084       if (!rocstatus.get(PixelROCStatus::noInit)){
00085         PixelModuleName module(tableMat[r][colM["ROC_NAME"]]);
00086         if (!containsModule(module)) {
00087           modules_.push_back(module);
00088         }
00089       }
00090   }//end for r
00091 
00092 //   std::cout << __LINE__ << mthn << "Number of Modules in Detector Configuration Class: " << getNModules() << std::endl;
00093 
00094 }//end constructor
00095 
00096 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00097 
00098 PixelDetectorConfig::PixelDetectorConfig(std::string filename):
00099   PixelConfigBase("","",""){
00100 
00101   std::string mthn = "[PixelDetectorConfig::PixelDetectorConfig()]\t\t    " ;
00102 
00103   if (filename[filename.size()-1]=='t'){
00104 
00105     std::ifstream in(filename.c_str());
00106 
00107     if (!in.good()){
00108       std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
00109       throw std::runtime_error("Failed to open file "+filename);
00110     }
00111     else {
00112       std::cout << __LINE__ << "]\t" << mthn << "Opened: "         << filename << std::endl;
00113     }
00114         
00115     if (in.eof()){
00116       std::cout << __LINE__ << "]\t" << mthn << "EOF before reading anything!" << std::endl;
00117       throw std::runtime_error("File seems to be empty "+filename);
00118     }
00119 
00120         
00121     modules_.clear();
00122     rocs_.clear() ;
00123         
00124     std::string module;
00125         
00126     in >> module;
00127 
00128     if (module=="Rocs:") {
00129       std::cout << __LINE__ << "]\t" << mthn << "New format of detconfig"<<std::endl;
00130       //new format with list of ROCs.
00131       std::string rocname;
00132       in >> rocname;
00133       while (!in.eof()){
00134         //cout << __LINE__ << "]\t" << mthn << "Read rocname:"<<rocname<<endl;
00135         PixelROCName roc(rocname);
00136         std::string line;
00137         getline(in,line);
00138         //cout << __LINE__ << "]\t" << mthn << "Read line:'"<<line<<"'"<<endl;
00139         istringstream instring(line);
00140         PixelROCStatus rocstatus;
00141         std::string status;
00142         while (!instring.eof()) {
00143           instring >> status;
00144 //        cout << __LINE__ << "]\t" << mthn << "Read status:"<<status<<endl;
00145           if (status!=""){
00146             rocstatus.set(status);
00147           }
00148         }
00149         rocs_[roc]=rocstatus;
00150         if (!rocstatus.get(PixelROCStatus::noInit)){
00151           PixelModuleName module(rocname);
00152           if (!containsModule(module)) {
00153             modules_.push_back(module);
00154           }
00155         }
00156         in >> rocname;
00157       }
00158       return;
00159     }
00160         
00161 
00162     //std::cout << __LINE__ << "]\t" << mthn << "Read module:"<<module<<std::endl;
00163 
00164     if (in.eof()) std::cout << mthn << "EOF after reading first module name" << std::endl;
00165 
00166     std::cout << __LINE__ << "]\t" << mthn << "Old format of detconfig"<<std::endl;
00167     while (!in.eof()){
00168 
00169       //std::cout << __LINE__ << "]\t" << mthn << "Read module:"<<module<<std::endl;
00170 
00171       PixelModuleName moduleName(module);
00172 
00173       modules_.push_back(moduleName);
00174             
00175       in >> module;
00176             
00177       assert(modules_.size()<10000);
00178             
00179     }
00180         
00181     in.close();
00182 
00183   }
00184   else{
00185 
00186     assert(0);
00187 
00188     /*
00189       std::ifstream in(filename.c_str(),std::ios::binary);
00190 
00191       if (!in.good()){
00192       std::cout << __LINE__ << "]\t" << mthn << "Could not open:"<<filename<<std::endl;
00193       assert(0);
00194       }
00195       else {
00196       std::cout << __LINE__ << "]\t" << mthn << "Opened:"<<filename<<std::endl;
00197       }
00198 
00199       char nchar;
00200 
00201       in.read(&nchar,1);
00202         
00203       std::string s1;
00204 
00205       //wrote these lines of code without ref. needs to be fixed
00206       for(int i=0;i< nchar; i++){
00207       char c;
00208       in >>c;
00209       s1.push_back(c);
00210       }
00211 
00212       //std::cout << __LINE__ << "]\t" << mthn << "READ ROC name:"<<s1<<std::endl;
00213 
00214       dacsettings_.clear();
00215 
00216 
00217       while (!in.eof()){
00218 
00219       //std::cout << __LINE__ << "]\t" << mthn << "read s1:"<<s1<<std::endl;
00220 
00221       PixelROCName rocid(s1);
00222 
00223       //std::cout << __LINE__ << "]\t" << mthn << "read rocid:"<<rocid<<std::endl;
00224             
00225       PixelROCDetectorConfig tmp;
00226       
00227       tmp.readBinary(in, rocid);
00228 
00229       dacsettings_.push_back(tmp);
00230 
00231 
00232       in.read(&nchar,1);
00233 
00234       s1.clear();
00235 
00236       if (in.eof()) continue;
00237 
00238       //wrote these lines of code without ref. needs to be fixed
00239       for(int i=0;i< nchar; i++){
00240       char c;
00241       in >>c;
00242       s1.push_back(c);
00243       }
00244 
00245 
00246       }
00247 
00248       in.close();
00249 
00250     */
00251 
00252   }
00253 
00254 
00255   //std::cout << __LINE__ << "]\t" << mthn << "Read dac settings for "<<dacsettings_.size()<<" ROCs"<<std::endl;
00256 
00257 
00258 }
00259 
00260 unsigned int PixelDetectorConfig::getNModules() const {
00261 
00262   return modules_.size();
00263 
00264 }
00265  
00266 PixelModuleName PixelDetectorConfig::getModule(unsigned int i) const {
00267 
00268   return modules_[i];
00269 
00270 }
00271 
00272 std::set <unsigned int> PixelDetectorConfig::getFEDs(PixelNameTranslation* translation) const 
00273 {
00274 
00275   std::set <unsigned int> feds;
00276   assert(modules_.size()!=0);
00277   std::vector<PixelModuleName>::const_iterator imodule=modules_.begin();
00278         
00279   for (;imodule!=modules_.end();++imodule) {
00280   
00281                 std::set<PixelChannel> channelsOnThisModule = translation->getChannelsOnModule(*imodule);
00282                 for ( std::set<PixelChannel>::const_iterator channelsOnThisModule_itr = channelsOnThisModule.begin(); channelsOnThisModule_itr != channelsOnThisModule.end(); channelsOnThisModule_itr++ )
00283                 {
00284                         const PixelHdwAddress& channel_hdwaddress = translation->getHdwAddress(*channelsOnThisModule_itr);
00285                         unsigned int fednumber=channel_hdwaddress.fednumber();
00286                         feds.insert(fednumber);
00287                 }
00288 
00289   }
00290         
00291   return feds;
00292 }
00293 
00294 
00295 // Returns the FED numbers and channels within each FED that are used
00296 std::map <unsigned int, std::set<unsigned int> > PixelDetectorConfig::getFEDsAndChannels(PixelNameTranslation* translation) const
00297 {
00298   //      FED Number                channels
00299 
00300   std::map <unsigned int, std::set<unsigned int> > fedsChannels;
00301   assert(modules_.size()!=0);
00302   std::vector<PixelModuleName>::const_iterator imodule=modules_.begin();
00303 
00304   for (;imodule!=modules_.end();++imodule) {
00305   
00306                 std::set<PixelChannel> channelsOnThisModule = translation->getChannelsOnModule(*imodule);
00307                 for ( std::set<PixelChannel>::const_iterator channelsOnThisModule_itr = channelsOnThisModule.begin(); channelsOnThisModule_itr != channelsOnThisModule.end(); channelsOnThisModule_itr++ )
00308                 {
00309                         const PixelHdwAddress& channel_hdwaddress = translation->getHdwAddress(*channelsOnThisModule_itr);
00310                         unsigned int fednumber=channel_hdwaddress.fednumber();
00311                         unsigned int fedchannel=channel_hdwaddress.fedchannel();
00312                         fedsChannels[fednumber].insert(fedchannel);
00313                 }
00314   
00315   }
00316 
00317   return fedsChannels;
00318 }
00319  
00320 bool PixelDetectorConfig::containsModule(const PixelModuleName& moduleToFind) const
00321 {
00322   for ( std::vector<PixelModuleName>::const_iterator modules_itr = modules_.begin(); modules_itr != modules_.end(); modules_itr++ )
00323     {
00324       if ( *modules_itr == moduleToFind ) return true;
00325     }
00326   return false;
00327 }
00328 
00329 // modified by MR on 11-01-2008 15:06:51
00330 void PixelDetectorConfig::writeASCII(std::string dir) const {
00331 
00332   std::stringstream s ; s << __LINE__ << "]\t[PixelDetectorConfig::writeASCII()]\t\t    " ;
00333   std::string mthn = s.str() ;
00334 
00335   if (dir!="") dir+="/";
00336   std::string filename=dir+"detectconfig.dat";
00337 
00338   std::ofstream out(filename.c_str(), std::ios_base::out) ;
00339   if(!out) {
00340     std::cout << __LINE__ << "]\t" << mthn << "Could not open file " << filename << " for write" << std::endl ;
00341     exit(1);
00342   }
00343 
00344 
00345   if(rocs_.size() == 0) 
00346     {
00347       std::vector<PixelModuleName>::const_iterator imodule=modules_.begin();
00348       
00349       for (;imodule!=modules_.end();++imodule) 
00350         {
00351           out << *imodule << std::endl;
00352         }
00353     } 
00354   else 
00355     {
00356       out << "Rocs:" << endl ;
00357       std::map<PixelROCName, PixelROCStatus>::const_iterator irocs = rocs_.begin();
00358       for(; irocs != rocs_.end() ; irocs++)
00359         {
00360           out << (irocs->first).rocname() << " " << (irocs->second).statusName() << endl ;
00361         }
00362     }
00363   
00364   out.close();
00365 
00366 }
00367 
00368 //=============================================================================================
00369 void PixelDetectorConfig::writeXMLHeader(pos::PixelConfigKey key, 
00370                                          int version, 
00371                                          std::string path, 
00372                                          std::ofstream *outstream,
00373                                          std::ofstream *out1stream,
00374                                          std::ofstream *out2stream)  const
00375 {
00376   std::string mthn = "]\t[PixelDetectorConfig::writeXMLHeader()]\t\t\t    " ;
00377   std::stringstream fullPath ;
00378   fullPath << path << "/Pixel_DetectorConfig_" << PixelTimeFormatter::getmSecTime() << ".xml" ;
00379   cout << __LINE__ << mthn << "Writing to: " << fullPath.str() << endl ;
00380   
00381   outstream->open(fullPath.str().c_str()) ;
00382   
00383   if( !outstream->good() )
00384     {
00385       cout << __LINE__ << mthn << "FATAL: could not open file " << fullPath.str() << endl ;
00386       assert(0) ;
00387     }
00388   
00389   *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"                                    << std::endl ;
00390   *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"                               << std::endl ;
00391   *outstream << ""                                                                                           << std::endl ; 
00392   *outstream << " <!-- " << mthn << "-->"                                                                    << std::endl ; 
00393   *outstream << ""                                                                                           << std::endl ; 
00394   *outstream << " <HEADER>"                                                                                  << std::endl ;
00395   *outstream << "  <TYPE>"                                                                                   << std::endl ;
00396   *outstream << "   <EXTENSION_TABLE_NAME>PIXEL_DETECTOR_CONFIG</EXTENSION_TABLE_NAME>"                      << std::endl ;
00397   *outstream << "   <NAME>Pixel Detector Configuration</NAME>"                                               << std::endl ;
00398   *outstream << "  </TYPE>"                                                                                  << std::endl ;
00399   *outstream << "  <RUN>"                                                                                    << std::endl ;
00400   *outstream << "   <RUN_TYPE>Pixel Detector Configuration test</RUN_TYPE>"                                  << std::endl ;
00401   *outstream << "   <RUN_NUMBER>1</RUN_NUMBER>"                                                              << std::endl ;
00402   *outstream << "   <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
00403   *outstream << "   <LOCATION>CERN P5</LOCATION>"                                                            << std::endl ; 
00404   *outstream << "  </RUN>"                                                                                   << std::endl ;
00405   *outstream << " </HEADER>"                                                                                 << std::endl ;
00406   *outstream << ""                                                                                           << std::endl ;
00407   *outstream << "  <DATA_SET>"                                                                               << std::endl ;
00408   *outstream << " "                                                                                          << std::endl ;
00409   *outstream << "   <VERSION>" << version << "</VERSION>"                                                    << std::endl ;
00410   *outstream << "   <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>"                       << std::endl ;
00411   *outstream << "   <CREATED_BY_USER>"     << getAuthor()  << "</CREATED_BY_USER>"                           << std::endl ; 
00412   *outstream << " "                                                                                          << std::endl ;
00413   *outstream << "   <PART>"                                                                                  << std::endl ;
00414   *outstream << "    <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>"                                                << std::endl ;
00415   *outstream << "    <KIND_OF_PART>Detector ROOT</KIND_OF_PART>"                                             << std::endl ;
00416   *outstream << "   </PART>"                                                                                 << std::endl ;
00417 
00418 }
00419 
00420 //=============================================================================================
00421 void PixelDetectorConfig::writeXML( std::ofstream *outstream,
00422                                     std::ofstream *out1stream,
00423                                     std::ofstream *out2stream)  const
00424 {
00425   std::stringstream s ; s << __LINE__ << "]\t[PixelDetectorConfig::writeXML()]\t\t\t    " ;
00426   std::string mthn = s.str() ;
00427   if(rocs_.size() == 0) 
00428     {
00429       std::vector<PixelModuleName>::const_iterator imodule=modules_.begin();
00430       
00431       // This needs to be fixed: given a module name, actually loop over ROCs to write the XML data
00432       for (;imodule!=modules_.end();++imodule) 
00433         {
00434           *outstream << "  <DATA>"                                                                           << std::endl ;
00435 //---->          out << "   <ROC_NAME>" << (irocs->first).rocname() << "</ROC_NAME>"                         << std::endl ;
00436           *outstream << "   <ROC_STATUS>on</ROC_STATUS>"                                                     << std::endl ;
00437           *outstream << "  </DATA>"                                                                          << std::endl ;
00438           *outstream << " "                                                                                  << std::endl ;
00439         }
00440     } 
00441   else 
00442     {
00443       std::map<PixelROCName, PixelROCStatus>::const_iterator irocs = rocs_.begin();
00444       for(; irocs != rocs_.end() ; irocs++)
00445         {
00446           std::string sts = (irocs->second).statusName() ;
00447           if( sts == "" ) {sts = "on" ;}
00448           *outstream << " "                                                                                  << std::endl ;
00449           *outstream << "   <DATA>"                                                                          << std::endl ;
00450           *outstream << "    <ROC_NAME>" << (irocs->first).rocname() << "</ROC_NAME>"                        << std::endl ;
00451           *outstream << "    <ROC_STATUS>" << sts << "</ROC_STATUS>"                                         << std::endl ;
00452           *outstream << "   </DATA>"                                                                         << std::endl ;
00453         }
00454     }
00455 }
00456 
00457 //=============================================================================================
00458 void PixelDetectorConfig::writeXMLTrailer(std::ofstream *outstream,
00459                                           std::ofstream *out1stream,
00460                                           std::ofstream *out2stream) const
00461 {
00462   std::stringstream s ; s << __LINE__ << "]\t[PixelDetectorConfig::writeXMLTrailer()]\t\t\t    " ;
00463   std::string mthn = s.str() ;
00464   
00465   *outstream << " "                                                                                          << std::endl ;
00466   *outstream << " </DATA_SET>"                                                                               << std::endl ;
00467   *outstream << "</ROOT> "                                                                                   << std::endl ;
00468 
00469   outstream->close() ;
00470 }
00471 //=============================================================================================
00472 void PixelDetectorConfig::writeXML(pos::PixelConfigKey key, int version, std::string path) const 
00473 {
00474   std::stringstream s ; s << __LINE__ << "]\t[PixelDetectorConfig::writeXML()]\t\t\t    " ;
00475   std::string mthn = s.str() ;
00476 
00477   std::stringstream fullPath ;
00478 
00479   fullPath << path << "/Pixel_DetectorConfig.xml" ;
00480   cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str()                               << std::endl ;
00481   
00482   std::ofstream out(fullPath.str().c_str()) ;
00483   
00484   out << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"                                    << std::endl ;
00485   out << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"                               << std::endl ;
00486   out << " <HEADER>"                                                                                  << std::endl ;
00487   out << "  <TYPE>"                                                                                   << std::endl ;
00488   out << "   <EXTENSION_TABLE_NAME>PIXEL_DETECTOR_CONFIG</EXTENSION_TABLE_NAME>"                      << std::endl ;
00489   out << "   <NAME>Pixel Detector Configuration</NAME>"                                               << std::endl ;
00490   out << "  </TYPE>"                                                                                  << std::endl ;
00491   out << "  <RUN>"                                                                                    << std::endl ;
00492   out << "   <RUN_TYPE>Pixel Detector Configuration test</RUN_TYPE>"                                  << std::endl ;
00493   out << "   <RUN_NUMBER>1</RUN_NUMBER>"                                                              << std::endl ;
00494   out << "   <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
00495   out << "   <COMMENT_DESCRIPTION>Test of DetectorConfig xml</COMMENT_DESCRIPTION>"                   << std::endl ;
00496   out << "   <LOCATION>CERN TAC</LOCATION>"                                                           << std::endl ;
00497   out << "   <CREATED_BY_USER>Dario Menasce</CREATED_BY_USER>"                                        << std::endl ;
00498   out << "  </RUN>"                                                                                   << std::endl ;
00499   out << " </HEADER>"                                                                                 << std::endl ;
00500   out << ""                                                                                           << std::endl ;
00501   out << ""                                                                                           << std::endl ;
00502 
00503   if(rocs_.size() == 0) 
00504     {
00505       std::vector<PixelModuleName>::const_iterator imodule=modules_.begin();
00506       
00507       // This needs to be fixed: given a module name, actually loop over ROCs to write the XML data
00508       for (;imodule!=modules_.end();++imodule) 
00509         {
00510           out << "  <DATA>"                                                                           << std::endl ;
00511 //---->          out << "   <ROC_NAME>" << (irocs->first).rocname() << "</ROC_NAME>"                  << std::endl ;
00512           out << "   <ROC_STATUS>on</ROC_STATUS>"                                                     << std::endl ;
00513           out << "  </DATA>"                                                                          << std::endl ;
00514           out << " "                                                                                  << std::endl ;
00515         }
00516     } 
00517   else 
00518     {
00519       std::map<PixelROCName, PixelROCStatus>::const_iterator irocs = rocs_.begin();
00520       for(; irocs != rocs_.end() ; irocs++)
00521         {
00522           std::string sts = (irocs->second).statusName() ;
00523           if( sts == "" ) {sts = "on" ;}
00524           out << "  <DATA_SET>"                                                                       << std::endl ;
00525           out << "   <VERSION>" << version << "</VERSION>"                                            << std::endl ;
00526           out << "    <PART>"                                                                         << std::endl ;
00527           out << "     <NAME_LABEL>" << (irocs->first).rocname() << "</NAME_LABEL>"                   << std::endl ;
00528           out << "     <KIND_OF_PART>ROC</KIND_OF_PART>"                                              << std::endl ;
00529           out << "    </PART>"                                                                        << std::endl ;
00530           out << "   <DATA>"                                                                          << std::endl ;
00531           out << "    <ROC_NAME>" << (irocs->first).rocname() << "</ROC_NAME>"                        << std::endl ;
00532           out << "    <ROC_STATUS>" << sts << "</ROC_STATUS>"                                         << std::endl ;
00533           out << "   </DATA>"                                                                         << std::endl ;
00534           out << "  </DATA_SET>"                                                                      << std::endl ;
00535           out << " "                                                                                  << std::endl ;
00536         }
00537     }
00538   out << " </DATA_SET>"                                                                               << std::endl ;
00539   out << "</ROOT> "                                                                                   << std::endl ;
00540   out.close() ;
00541   assert(0) ;
00542 }
00543 
00544 //=============================================================================================
00545 void PixelDetectorConfig::addROC(   PixelROCName &theROC)  // Added by Dario (March 3, 2008)
00546 {
00547  std::stringstream s ; s << __LINE__ << "]\t[PixelDetectorConfig::addROC()]\t\t\t\t    " ;
00548  std::string mthn = s.str() ;
00549 
00550  std::map<PixelROCName, PixelROCStatus>::iterator theROCIt = rocs_.find(theROC) ;
00551  if( theROCIt == rocs_.end() ) // if theROC was not there, add it and turn it on
00552  {
00553   PixelROCStatus  theStatus ;
00554   theStatus.reset() ;
00555   rocs_[theROC] = theStatus ; 
00556 //  cout << __LINE__ << "]\t" << mthn << "Non existing ROC (" << theROC.rocname() << "): adding it"  << endl ;  
00557  } else {
00558   theROCIt->second.reset() ;  // otherwise just turn it on by resetting it to zero
00559 //  cout << __LINE__ << "]\t" << mthn << "Already existing ROC (" << theROC.rocname() << "): switching it on"  << endl ;  
00560  }
00561 }
00562 
00563 //=============================================================================================
00564 void PixelDetectorConfig::addROC(   PixelROCName &theROC, string statusLabel)  // modified by MR on 14-05-2008 11:29:51
00565 {
00566  std::stringstream s ; s << __LINE__ << "]\t[PixelDetectorConfig::addROC()]\t\t\t\t    " ;
00567  std::string mthn = s.str() ;
00568 
00569  std::map<PixelROCName, PixelROCStatus>::iterator theROCIt = rocs_.find(theROC) ;
00570  if( theROCIt == rocs_.end() ) // if theROC was not there, add it and turn it on
00571  {
00572   PixelROCStatus  theStatus ;
00573   theStatus.set(statusLabel) ;
00574   theStatus.reset() ;
00575   rocs_[theROC] = theStatus ; 
00576 //  cout << __LINE__ << "]\t" << mthn << "Non existing ROC (" << theROC.rocname() << "): adding it"  << endl ;  
00577  } else {
00578   theROCIt->second.set(statusLabel) ;  // otherwise just turn it on by resetting it to zero
00579 //  cout << __LINE__ << "]\t" << mthn << "Already existing ROC (" << theROC.rocname() << "): switching it on"  << endl ;  
00580  }
00581 }
00582 
00583 //=============================================================================================
00584 void PixelDetectorConfig::removeROC(PixelROCName &theROC)  // Added by Dario (March 3, 2008)
00585 {
00586  std::string mthn = "[PixelDetectorConfig::removeROC()]\t\t\t\t    " ;
00587 
00588  std::map<PixelROCName, PixelROCStatus>::iterator theROCIt = rocs_.find(theROC) ;
00589  if( theROCIt != rocs_.end() ) // if theROC was there remove it, otherwise ignore
00590  {
00591   theROCIt->second.set("noInit") ;  
00592 //  cout << __LINE__ << "]\t" << mthn << "Already existing ROC (" << theROC.rocname() << "): switching it off"  << endl ;  
00593  } else {
00594   PixelROCStatus  theStatus ;
00595   theStatus.set("noInit") ;
00596   rocs_[theROC] = theStatus ; 
00597 //  cout << __LINE__ << "]\t" << mthn << "ROC " << theROC.rocname() << " was not individually declared in the file: declare and switch off"  << endl ;  
00598  }
00599 }
00600 
00601 //std::ostream& operator<<(std::ostream& s, const PixelDetectorConfig& dacs){
00602 //
00603 //  s << dacs.getDetectorConfig(0) <<std::endl; 
00604 //
00605 //  return s;
00606 //
00607 //}
00608